Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit c2685a2

Browse files
committed
Store text context in AiksPlayground
1 parent 68b57bb commit c2685a2

15 files changed

+84
-61
lines changed

impeller/aiks/aiks_context.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace impeller {
1111

1212
AiksContext::AiksContext(std::shared_ptr<Context> context,
13-
std::unique_ptr<TextRenderContext> text_render_context)
13+
std::shared_ptr<TextRenderContext> text_render_context)
1414
: context_(std::move(context)) {
1515
if (!context_ || !context_->IsValid()) {
1616
return;

impeller/aiks/aiks_context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class AiksContext {
2929
/// text with Aiks will result in validation
3030
/// errors.
3131
AiksContext(std::shared_ptr<Context> context,
32-
std::unique_ptr<TextRenderContext> text_render_context);
32+
std::shared_ptr<TextRenderContext> text_render_context);
3333

3434
~AiksContext();
3535

impeller/aiks/aiks_playground.cc

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,38 @@
44

55
#include "impeller/aiks/aiks_playground.h"
66

7-
#include "impeller/aiks/aiks_context.h"
7+
#include <memory>
88

9+
#include "impeller/aiks/aiks_context.h"
910
#include "impeller/typographer/backends/skia/text_render_context_skia.h"
11+
#include "impeller/typographer/text_render_context.h"
1012
#include "third_party/imgui/imgui.h"
1113

1214
namespace impeller {
1315

14-
AiksPlayground::AiksPlayground() = default;
16+
AiksPlayground::AiksPlayground()
17+
: text_render_context_(TextRenderContextSkia::Make()) {}
1518

1619
AiksPlayground::~AiksPlayground() = default;
1720

18-
bool AiksPlayground::OpenPlaygroundHere(
19-
const Picture& picture,
20-
std::unique_ptr<TextRenderContext> text_render_context_override) {
21-
auto text_context = text_render_context_override
22-
? std::move(text_render_context_override)
23-
: TextRenderContextSkia::Make();
21+
void AiksPlayground::SetTextRenderContext(
22+
std::shared_ptr<TextRenderContext> text_render_context) {
23+
text_render_context_ = std::move(text_render_context);
24+
}
25+
26+
bool AiksPlayground::OpenPlaygroundHere(const Picture& picture) {
2427
return OpenPlaygroundHere(
2528
[&picture](AiksContext& renderer, RenderTarget& render_target) -> bool {
2629
return renderer.Render(picture, render_target);
27-
},
28-
std::move(text_context));
30+
});
2931
}
3032

31-
bool AiksPlayground::OpenPlaygroundHere(
32-
AiksPlaygroundCallback callback,
33-
std::unique_ptr<TextRenderContext> text_render_context_override) {
33+
bool AiksPlayground::OpenPlaygroundHere(AiksPlaygroundCallback callback) {
3434
if (!switches_.enable_playground) {
3535
return true;
3636
}
3737

38-
auto text_context = text_render_context_override
39-
? std::move(text_render_context_override)
40-
: TextRenderContextSkia::Make();
41-
AiksContext renderer(GetContext(), std::move(text_context));
38+
AiksContext renderer(GetContext(), text_render_context_);
4239

4340
if (!renderer.IsValid()) {
4441
return false;

impeller/aiks/aiks_playground.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "impeller/aiks/aiks_context.h"
99
#include "impeller/aiks/picture.h"
1010
#include "impeller/playground/playground_test.h"
11+
#include "impeller/typographer/text_render_context.h"
1112

1213
namespace impeller {
1314

@@ -20,15 +21,16 @@ class AiksPlayground : public PlaygroundTest {
2021

2122
~AiksPlayground();
2223

23-
bool OpenPlaygroundHere(const Picture& picture,
24-
std::unique_ptr<TextRenderContext>
25-
text_render_context_override = nullptr);
24+
void SetTextRenderContext(
25+
std::shared_ptr<TextRenderContext> text_render_context);
2626

27-
bool OpenPlaygroundHere(AiksPlaygroundCallback callback,
28-
std::unique_ptr<TextRenderContext>
29-
text_render_context_override = nullptr);
27+
bool OpenPlaygroundHere(const Picture& picture);
28+
29+
bool OpenPlaygroundHere(AiksPlaygroundCallback callback);
3030

3131
private:
32+
std::shared_ptr<TextRenderContext> text_render_context_;
33+
3234
FML_DISALLOW_COPY_AND_ASSIGN(AiksPlayground);
3335
};
3436

impeller/entity/contents/content_context.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ static std::unique_ptr<PipelineT> CreateDefaultPipeline(
162162

163163
ContentContext::ContentContext(
164164
std::shared_ptr<Context> context,
165-
std::unique_ptr<TextRenderContext> text_render_context)
165+
std::shared_ptr<TextRenderContext> text_render_context)
166166
: context_(std::move(context)),
167167
lazy_glyph_atlas_(
168168
std::make_shared<LazyGlyphAtlas>(std::move(text_render_context))),

impeller/entity/contents/content_context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ class ContentContext {
342342
public:
343343
explicit ContentContext(
344344
std::shared_ptr<Context> context,
345-
std::unique_ptr<TextRenderContext> text_render_context);
345+
std::shared_ptr<TextRenderContext> text_render_context);
346346

347347
~ContentContext();
348348

impeller/entity/entity_playground.cc

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,22 @@
1010

1111
namespace impeller {
1212

13-
EntityPlayground::EntityPlayground() = default;
13+
EntityPlayground::EntityPlayground()
14+
: text_render_context_(TextRenderContextSkia::Make()) {}
1415

1516
EntityPlayground::~EntityPlayground() = default;
1617

18+
void EntityPlayground::SetTextRenderContext(
19+
std::shared_ptr<TextRenderContext> text_render_context) {
20+
text_render_context_ = std::move(text_render_context);
21+
}
22+
1723
bool EntityPlayground::OpenPlaygroundHere(EntityPass& entity_pass) {
1824
if (!switches_.enable_playground) {
1925
return true;
2026
}
2127

22-
ContentContext content_context(GetContext(), TextRenderContextSkia::Make());
28+
ContentContext content_context(GetContext(), text_render_context_);
2329
if (!content_context.IsValid()) {
2430
return false;
2531
}
@@ -35,7 +41,7 @@ bool EntityPlayground::OpenPlaygroundHere(Entity entity) {
3541
return true;
3642
}
3743

38-
ContentContext content_context(GetContext(), TextRenderContextSkia::Make());
44+
ContentContext content_context(GetContext(), text_render_context_);
3945
if (!content_context.IsValid()) {
4046
return false;
4147
}
@@ -50,7 +56,7 @@ bool EntityPlayground::OpenPlaygroundHere(EntityPlaygroundCallback callback) {
5056
return true;
5157
}
5258

53-
ContentContext content_context(GetContext(), TextRenderContextSkia::Make());
59+
ContentContext content_context(GetContext(), text_render_context_);
5460
if (!content_context.IsValid()) {
5561
return false;
5662
}

impeller/entity/entity_playground.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44

55
#pragma once
66

7+
#include "impeller/playground/playground_test.h"
8+
79
#include "flutter/fml/macros.h"
810
#include "impeller/entity/contents/content_context.h"
911
#include "impeller/entity/entity.h"
1012
#include "impeller/entity/entity_pass.h"
11-
12-
#include "impeller/playground/playground_test.h"
13+
#include "impeller/typographer/text_render_context.h"
1314

1415
namespace impeller {
1516

@@ -22,13 +23,18 @@ class EntityPlayground : public PlaygroundTest {
2223

2324
~EntityPlayground();
2425

26+
void SetTextRenderContext(
27+
std::shared_ptr<TextRenderContext> text_render_context);
28+
2529
bool OpenPlaygroundHere(Entity entity);
2630

2731
bool OpenPlaygroundHere(EntityPass& entity_pass);
2832

2933
bool OpenPlaygroundHere(EntityPlaygroundCallback callback);
3034

3135
private:
36+
std::shared_ptr<TextRenderContext> text_render_context_;
37+
3238
FML_DISALLOW_COPY_AND_ASSIGN(EntityPlayground);
3339
};
3440

impeller/golden_tests/golden_playground_test.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "flutter/impeller/playground/playground.h"
1212
#include "flutter/impeller/renderer/render_target.h"
1313
#include "flutter/testing/testing.h"
14+
#include "impeller/typographer/text_render_context.h"
1415

1516
#if FML_OS_MACOSX
1617
#include "flutter/fml/platform/darwin/scoped_nsautorelease_pool.h"
@@ -26,19 +27,20 @@ class GoldenPlaygroundTest
2627

2728
GoldenPlaygroundTest();
2829

30+
~GoldenPlaygroundTest() override;
31+
2932
void SetUp();
3033

3134
void TearDown();
3235

3336
PlaygroundBackend GetBackend() const;
3437

35-
bool OpenPlaygroundHere(const Picture& picture,
36-
std::unique_ptr<TextRenderContext>
37-
text_render_context_override = nullptr);
38+
void SetTextRenderContext(
39+
std::shared_ptr<TextRenderContext> text_render_context);
40+
41+
bool OpenPlaygroundHere(const Picture& picture);
3842

39-
bool OpenPlaygroundHere(const AiksPlaygroundCallback& callback,
40-
std::unique_ptr<TextRenderContext>
41-
text_render_context_override = nullptr);
43+
bool OpenPlaygroundHere(const AiksPlaygroundCallback& callback);
4244

4345
std::shared_ptr<Texture> CreateTextureForFixture(
4446
const char* fixture_name,
@@ -62,6 +64,8 @@ class GoldenPlaygroundTest
6264
fml::ScopedNSAutoreleasePool autorelease_pool_;
6365
#endif
6466

67+
std::shared_ptr<TextRenderContext> text_render_context_;
68+
6569
struct GoldenPlaygroundTestImpl;
6670
// This is only a shared_ptr so it can work with a forward declared type.
6771
std::shared_ptr<GoldenPlaygroundTestImpl> pimpl_;

impeller/golden_tests/golden_playground_test_mac.cc

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44

55
#include <dlfcn.h>
66
#include <filesystem>
7+
#include <memory>
78

89
#include "flutter/impeller/golden_tests/golden_playground_test.h"
910

1011
#include "flutter/impeller/aiks/picture.h"
1112
#include "flutter/impeller/golden_tests/golden_digest.h"
1213
#include "flutter/impeller/golden_tests/metal_screenshoter.h"
1314
#include "impeller/typographer/backends/skia/text_render_context_skia.h"
15+
#include "impeller/typographer/text_render_context.h"
1416

1517
namespace impeller {
1618

@@ -86,7 +88,15 @@ struct GoldenPlaygroundTest::GoldenPlaygroundTestImpl {
8688
};
8789

8890
GoldenPlaygroundTest::GoldenPlaygroundTest()
89-
: pimpl_(new GoldenPlaygroundTest::GoldenPlaygroundTestImpl()) {}
91+
: text_render_context_(TextRenderContextSkia::Make()),
92+
pimpl_(new GoldenPlaygroundTest::GoldenPlaygroundTestImpl()) {}
93+
94+
GoldenPlaygroundTest::~GoldenPlaygroundTest() = default;
95+
96+
void GoldenPlaygroundTest::SetTextRenderContext(
97+
std::shared_ptr<TextRenderContext> text_render_context) {
98+
text_render_context_ = std::move(text_render_context);
99+
};
90100

91101
void GoldenPlaygroundTest::TearDown() {
92102
ASSERT_FALSE(dlopen("/usr/local/lib/libMoltenVK.dylib", RTLD_NOLOAD));
@@ -124,22 +134,16 @@ PlaygroundBackend GoldenPlaygroundTest::GetBackend() const {
124134
return GetParam();
125135
}
126136

127-
bool GoldenPlaygroundTest::OpenPlaygroundHere(
128-
const Picture& picture,
129-
std::unique_ptr<TextRenderContext> text_render_context_override) {
130-
auto text_context = text_render_context_override
131-
? std::move(text_render_context_override)
132-
: TextRenderContextSkia::Make();
133-
AiksContext renderer(GetContext(), std::move(text_context));
137+
bool GoldenPlaygroundTest::OpenPlaygroundHere(const Picture& picture) {
138+
AiksContext renderer(GetContext(), text_render_context_);
134139

135140
auto screenshot = pimpl_->screenshoter->MakeScreenshot(renderer, picture,
136141
pimpl_->window_size);
137142
return SaveScreenshot(std::move(screenshot));
138143
}
139144

140145
bool GoldenPlaygroundTest::OpenPlaygroundHere(
141-
const AiksPlaygroundCallback& callback,
142-
std::unique_ptr<TextRenderContext> text_render_context_override) {
146+
const AiksPlaygroundCallback& callback) {
143147
return false;
144148
}
145149

0 commit comments

Comments
 (0)