From 1ef3bbf8039cd695922252cfbd21a1f949f20e69 Mon Sep 17 00:00:00 2001 From: Brandon DeRosier Date: Fri, 13 Sep 2024 17:39:10 -0700 Subject: [PATCH 1/3] [Impeller] macos: Add missing dispatch for TextFrameDispatcher in embedder view. --- shell/platform/embedder/embedder_external_view.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/shell/platform/embedder/embedder_external_view.cc b/shell/platform/embedder/embedder_external_view.cc index 8aa524359d08b..1111e8a7a8375 100644 --- a/shell/platform/embedder/embedder_external_view.cc +++ b/shell/platform/embedder/embedder_external_view.cc @@ -137,6 +137,7 @@ bool EmbedderExternalView::Render(const EmbedderRenderTarget& render_target, impeller::TextFrameDispatcher collector(aiks_context->GetContentContext(), impeller::Matrix()); + display_list->Dispatch(collector, sk_cull_rect); impeller::ExperimentalDlDispatcher impeller_dispatcher( aiks_context->GetContentContext(), *impeller_target, From ad06d8344f8188da7ae6cc9779d5457048635daf Mon Sep 17 00:00:00 2001 From: Brandon DeRosier Date: Fri, 13 Sep 2024 18:14:19 -0700 Subject: [PATCH 2/3] Add macos embedder test. --- shell/platform/embedder/BUILD.gn | 2 +- ...impeller_gl_test.png => impeller_test.png} | Bin shell/platform/embedder/fixtures/main.dart | 2 +- .../embedder/tests/embedder_gl_unittests.cc | 4 +-- .../tests/embedder_metal_unittests.mm | 25 ++++++++++++++++++ 5 files changed, 29 insertions(+), 4 deletions(-) rename shell/platform/embedder/fixtures/{impeller_gl_test.png => impeller_test.png} (100%) diff --git a/shell/platform/embedder/BUILD.gn b/shell/platform/embedder/BUILD.gn index 39ca8dc757ae7..87f0d22574cd5 100644 --- a/shell/platform/embedder/BUILD.gn +++ b/shell/platform/embedder/BUILD.gn @@ -242,7 +242,7 @@ test_fixtures("fixtures") { "fixtures/dpr_noxform.png", "fixtures/dpr_xform.png", "fixtures/gradient.png", - "fixtures/impeller_gl_test.png", + "fixtures/impeller_test.png", "fixtures/vk_dpr_noxform.png", "fixtures/vk_gradient.png", "fixtures/gradient_metal.png", diff --git a/shell/platform/embedder/fixtures/impeller_gl_test.png b/shell/platform/embedder/fixtures/impeller_test.png similarity index 100% rename from shell/platform/embedder/fixtures/impeller_gl_test.png rename to shell/platform/embedder/fixtures/impeller_test.png diff --git a/shell/platform/embedder/fixtures/main.dart b/shell/platform/embedder/fixtures/main.dart index 6f3986b5eb1b9..c918d2e85cc53 100644 --- a/shell/platform/embedder/fixtures/main.dart +++ b/shell/platform/embedder/fixtures/main.dart @@ -1553,7 +1553,7 @@ void render_gradient_retained() { @pragma('vm:entry-point') // ignore: non_constant_identifier_names -void render_impeller_gl_test() { +void render_impeller_test() { PlatformDispatcher.instance.onBeginFrame = (Duration duration) { final SceneBuilder builder = SceneBuilder(); builder.pushOffset(0.0, 0.0); diff --git a/shell/platform/embedder/tests/embedder_gl_unittests.cc b/shell/platform/embedder/tests/embedder_gl_unittests.cc index 54ca779ebfa18..4eccb64b888bb 100644 --- a/shell/platform/embedder/tests/embedder_gl_unittests.cc +++ b/shell/platform/embedder/tests/embedder_gl_unittests.cc @@ -4758,7 +4758,7 @@ TEST_F(EmbedderTest, CanRenderWithImpellerOpenGL) { }); builder.AddCommandLineArgument("--enable-impeller"); - builder.SetDartEntrypoint("render_impeller_gl_test"); + builder.SetDartEntrypoint("render_impeller_test"); builder.SetOpenGLRendererConfig(SkISize::Make(800, 600)); builder.SetCompositor(); builder.SetRenderTargetType( @@ -4798,7 +4798,7 @@ TEST_F(EmbedderTest, CanRenderWithImpellerOpenGL) { ASSERT_TRUE(ImageMatchesFixture( FixtureNameForBackend(EmbedderTestContextType::kOpenGLContext, - "impeller_gl_test.png"), + "impeller_test.png"), rendered_scene)); // The scene will be rendered by the compositor, and the surface present diff --git a/shell/platform/embedder/tests/embedder_metal_unittests.mm b/shell/platform/embedder/tests/embedder_metal_unittests.mm index 6b2bead2aa673..ee8eb6b0c3537 100644 --- a/shell/platform/embedder/tests/embedder_metal_unittests.mm +++ b/shell/platform/embedder/tests/embedder_metal_unittests.mm @@ -614,6 +614,31 @@ void Collect() { EXPECT_TRUE(resolve_called); } +TEST_F(EmbedderTest, CanRenderWithImpellerMetal) { + auto& context = GetEmbedderContext(EmbedderTestContextType::kMetalContext); + + EmbedderConfigBuilder builder(context); + + builder.AddCommandLineArgument("--enable-impeller"); + builder.SetDartEntrypoint("render_impeller_test"); + builder.SetMetalRendererConfig(SkISize::Make(800, 600)); + + auto rendered_scene = context.GetNextSceneImage(); + + auto engine = builder.LaunchEngine(); + ASSERT_TRUE(engine.is_valid()); + + // Send a window metrics events so frames may be scheduled. + FlutterWindowMetricsEvent event = {}; + event.struct_size = sizeof(event); + event.width = 800; + event.height = 600; + event.pixel_ratio = 1.0; + ASSERT_EQ(FlutterEngineSendWindowMetricsEvent(engine.get(), &event), kSuccess); + + ASSERT_TRUE(ImageMatchesFixture("impeller_test.png", rendered_scene)); +} + } // namespace testing } // namespace flutter From b81cf566b1483b22fbe8773a284758a91d494163 Mon Sep 17 00:00:00 2001 From: Brandon DeRosier Date: Fri, 13 Sep 2024 20:03:04 -0700 Subject: [PATCH 3/3] Add test for rendering text with and without compositor. --- shell/platform/embedder/BUILD.gn | 1 + shell/platform/embedder/fixtures/README.md | 4 +- .../embedder/fixtures/impeller_text_test.png | Bin 0 -> 3325 bytes shell/platform/embedder/fixtures/main.dart | 26 +++++++++ .../tests/embedder_metal_unittests.mm | 53 ++++++++++++++++++ 5 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 shell/platform/embedder/fixtures/impeller_text_test.png diff --git a/shell/platform/embedder/BUILD.gn b/shell/platform/embedder/BUILD.gn index 87f0d22574cd5..38c7e2db98e87 100644 --- a/shell/platform/embedder/BUILD.gn +++ b/shell/platform/embedder/BUILD.gn @@ -243,6 +243,7 @@ test_fixtures("fixtures") { "fixtures/dpr_xform.png", "fixtures/gradient.png", "fixtures/impeller_test.png", + "fixtures/impeller_text_test.png", "fixtures/vk_dpr_noxform.png", "fixtures/vk_gradient.png", "fixtures/gradient_metal.png", diff --git a/shell/platform/embedder/fixtures/README.md b/shell/platform/embedder/fixtures/README.md index b68fc603cd73d..eed3fe6b865a1 100644 --- a/shell/platform/embedder/fixtures/README.md +++ b/shell/platform/embedder/fixtures/README.md @@ -71,9 +71,9 @@ $ $ENGINE/out/$TARGET/embedder_unittests --gtest_filter="EmbedderTest.VerifyB143 # Or, a suite of tests: $ $ENGINE/out/$TARGET/embedder_unittests --gtest_filter="EmbedderTest.*" -# 3. Now, copy the output to the golden file: +# 3. Now, copy the output to the golden file (notice the "actual_" prefix): $ cp \ - $ENGINE/out/$TARGET/gen/flutter/shell/platform/embedder/assets/expectation_verifyb143464703_soft_noxform.png \ + $ENGINE/out/$TARGET/gen/flutter/shell/platform/embedder/assets/actual_verifyb143464703_soft_noxform.png \ $ENGINE/flutter/shell/platform/embedder/fixtures/verifyb143464703_soft_noxform.png ``` diff --git a/shell/platform/embedder/fixtures/impeller_text_test.png b/shell/platform/embedder/fixtures/impeller_text_test.png new file mode 100644 index 0000000000000000000000000000000000000000..72ee258c101a2e84c4b2f92f0758b4bb87ce7ad4 GIT binary patch literal 3325 zcmeH{{a4a=8^^!RO*_knbFyh^=DkAc96h-#rS1?P=F>M*ob!W58dEGYrYx8bh{TpH zYtC9h;s~;f51_E{m$!2?gUMbIaaV@AmTBxAry%c%|)pzLmP=qiTEVwX{pIG10T} zTHi~l_r3}KYWKMbO7x~}&xT!dFb7veKY+m62i70%W?mhkhm2GCh7TL(Fy8eG_@RITSlN@_8^DT3T6y(-TWpd7pFYAK zy^56#L7ANxkCSJQv8}f;hJ%;v9f`)Tj|u{Y*@dG^7vj1j-@l8|vAMq2KM?VJ`r?+k zIf(SiW5Tt(h4gGs=!-S~C&V08DM>Oy6{teG_&QW81*Xbvg1dKw<}!qdYDcSI=8BpB zb?YWc*sWSxrHltm*T-*oLeP!ULfsyBLErNi80vRQEvneoC7( z`})jf<=Oy7>b~;J_tO4QF_EXh1z4nJX+Fl9h&aJ>h=P}AJ72Oidyu?=l@QXDWYlAH z&iZTE-usjnpCHG0c+QY4yJ;q=e{hxea%=0pGuz9pW;;P$Zk-Lw)NK8ws?_wl2HtVA z)`3({!XDgUJ%w#*QL_;R zfuug4i9A`YSzdAxT*1mI*p#U5(P7Sk4ZSV=x7+5`>OeWZMPHVptHP~ClzccCpVam9 zb;H(Lx=s-0*>UC`zdTr{euCh?ovGfmy-MHz<{eu_95MnwT~Pb`Q1pq$=NOkCYkVOn z`1kt?C*z{*_{G7--)I07YDL*_yr6VK;5)z1#dP-b%^W2F20mJ8qvcxCB^Ix%Q;T&T zB#9iD9-@-Fb=$HF|sR|{BUySG-b3aD2 z1hCG4{`+XRC3#NOhDsaqiXPpvG*?Q4R$t|F(o%tG3N3$#x+iN4bgG)@N_cYr#Tc0# zEVgof>k^^^Szz#RSFh0g`n=B8iH6>Gg&?n&=_yfO+Ct}u!IVxZ_L!8E9ppayHJ&UDxA{DdvnL% zP}Hv1NVARu^+;K+EJ*Y;L=zMw{NhYzwkR;82S^Ix<7vPHNKOEgL|O80G}v&l;UtL~)#8A#{P1`?hx+njsv z3owI@jJj(n&v2Dk@#Bwkz0Gd&UF?Kg0=5mqTKGm$b!)6iiW~Fr=d(4n-PoD^vhxEu zsrgA)YQnpl#&Odg{8!p-)Y7HDL_5?-RwOBZ@<7{Rqb6FOMUih4W=E9WS#)84YMF(2iJ=UdH?_b literal 0 HcmV?d00001 diff --git a/shell/platform/embedder/fixtures/main.dart b/shell/platform/embedder/fixtures/main.dart index c918d2e85cc53..adc7bb417b05c 100644 --- a/shell/platform/embedder/fixtures/main.dart +++ b/shell/platform/embedder/fixtures/main.dart @@ -1569,3 +1569,29 @@ void render_impeller_test() { }; PlatformDispatcher.instance.scheduleFrame(); } + +@pragma('vm:entry-point') +// ignore: non_constant_identifier_names +void render_impeller_text_test() { + PlatformDispatcher.instance.onBeginFrame = (Duration duration) { + final SceneBuilder builder = SceneBuilder(); + builder.pushOffset(0.0, 0.0); + final Paint paint = Paint(); + paint.color = const Color.fromARGB(255, 0, 0, 255); + final PictureRecorder baseRecorder = PictureRecorder(); + final Canvas canvas = Canvas(baseRecorder); + + final ParagraphBuilder paragraphBuilder = ParagraphBuilder(ParagraphStyle( + fontFamily: 'sans-serif' + )) + ..addText('Flutter is the best!'); + final Paragraph paragraph = paragraphBuilder.build() + ..layout(const ParagraphConstraints(width: 400)); + canvas.drawParagraph(paragraph, const Offset(20, 20)); + + builder.addPicture(Offset.zero, baseRecorder.endRecording()); + builder.pop(); + PlatformDispatcher.instance.views.first.render(builder.build()); + }; + PlatformDispatcher.instance.scheduleFrame(); +} diff --git a/shell/platform/embedder/tests/embedder_metal_unittests.mm b/shell/platform/embedder/tests/embedder_metal_unittests.mm index ee8eb6b0c3537..3f5ec9e549daf 100644 --- a/shell/platform/embedder/tests/embedder_metal_unittests.mm +++ b/shell/platform/embedder/tests/embedder_metal_unittests.mm @@ -639,6 +639,59 @@ void Collect() { ASSERT_TRUE(ImageMatchesFixture("impeller_test.png", rendered_scene)); } +TEST_F(EmbedderTest, CanRenderTextWithImpellerMetal) { + auto& context = GetEmbedderContext(EmbedderTestContextType::kMetalContext); + + EmbedderConfigBuilder builder(context); + + builder.AddCommandLineArgument("--enable-impeller"); + builder.SetDartEntrypoint("render_impeller_text_test"); + builder.SetMetalRendererConfig(SkISize::Make(800, 600)); + + auto rendered_scene = context.GetNextSceneImage(); + + auto engine = builder.LaunchEngine(); + ASSERT_TRUE(engine.is_valid()); + + // Send a window metrics events so frames may be scheduled. + FlutterWindowMetricsEvent event = {}; + event.struct_size = sizeof(event); + event.width = 800; + event.height = 600; + event.pixel_ratio = 1.0; + ASSERT_EQ(FlutterEngineSendWindowMetricsEvent(engine.get(), &event), kSuccess); + + ASSERT_TRUE(ImageMatchesFixture("impeller_text_test.png", rendered_scene)); +} + +TEST_F(EmbedderTest, CanRenderTextWithImpellerAndCompositorMetal) { + auto& context = GetEmbedderContext(EmbedderTestContextType::kMetalContext); + + EmbedderConfigBuilder builder(context); + + builder.AddCommandLineArgument("--enable-impeller"); + builder.SetDartEntrypoint("render_impeller_text_test"); + builder.SetMetalRendererConfig(SkISize::Make(800, 600)); + builder.SetCompositor(); + + builder.SetRenderTargetType(EmbedderTestBackingStoreProducer::RenderTargetType::kMetalTexture); + + auto rendered_scene = context.GetNextSceneImage(); + + auto engine = builder.LaunchEngine(); + ASSERT_TRUE(engine.is_valid()); + + // Send a window metrics events so frames may be scheduled. + FlutterWindowMetricsEvent event = {}; + event.struct_size = sizeof(event); + event.width = 800; + event.height = 600; + event.pixel_ratio = 1.0; + ASSERT_EQ(FlutterEngineSendWindowMetricsEvent(engine.get(), &event), kSuccess); + + ASSERT_TRUE(ImageMatchesFixture("impeller_text_test.png", rendered_scene)); +} + } // namespace testing } // namespace flutter