6#define FML_USED_ON_EMBEDDER
37#include "third_party/skia/include/core/SkSurface.h"
48 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
52 ASSERT_TRUE(
engine.is_valid());
61 MustPreventEngineLaunchWhenRequiredCompositorArgsAreAbsent) {
62 auto& context = GetEmbedderContext<EmbedderTestContextSoftware>();
66 builder.
GetCompositor().create_backing_store_callback =
nullptr;
67 builder.
GetCompositor().collect_backing_store_callback =
nullptr;
71 ASSERT_FALSE(
engine.is_valid());
80 auto& context = GetEmbedderContext<EmbedderTestContextSoftware>();
91 ASSERT_FALSE(
engine.is_valid());
99 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
110 context.GetCompositor().SetNextPresentCallback(
128 .rects = paint_region_rects,
132 .paint_region = &paint_region,
143 ASSERT_EQ(*
layers[0], layer);
158 ASSERT_EQ(*
layers[1], layer);
174 .rects = paint_region_rects,
178 .paint_region = &paint_region,
189 ASSERT_EQ(*
layers[2], layer);
195 context.AddNativeCallback(
198 [&latch](Dart_NativeArguments
args) { latch.
CountDown(); }));
207 event.pixel_ratio = 1.0;
210 ASSERT_TRUE(
engine.is_valid());
219 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
232 context.GetCompositor().SetNextPresentCallback(
250 .rects = paint_region_rects,
254 .paint_region = &paint_region,
265 ASSERT_EQ(*
layers[0], layer);
280 ASSERT_EQ(*
layers[1], layer);
296 .rects = paint_region_rects,
300 .paint_region = &paint_region,
311 ASSERT_EQ(*
layers[2], layer);
317 context.AddNativeCallback(
320 [&setup](Dart_NativeArguments
args) { setup.
CountDown(); }));
329 event.pixel_ratio = 1.0;
332 ASSERT_TRUE(
engine.is_valid());
352 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
365 context.GetCompositor().SetNextPresentCallback(
383 .rects = paint_region_rects,
387 .paint_region = &paint_region,
398 ASSERT_EQ(*
layers[0], layer);
404 context.AddNativeCallback(
407 [&setup](Dart_NativeArguments
args) { setup.
CountDown(); }));
416 event.pixel_ratio = 1.0;
419 ASSERT_TRUE(
engine.is_valid());
438 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
449 context.GetCompositor().SetNextPresentCallback(
467 .rects = paint_region_rects,
471 .paint_region = &paint_region,
482 ASSERT_EQ(*
layers[0], layer);
497 ASSERT_EQ(*
layers[1], layer);
513 .rects = paint_region_rects,
517 .paint_region = &paint_region,
528 ASSERT_EQ(*
layers[2], layer);
534 context.AddNativeCallback(
537 [&latch](Dart_NativeArguments
args) { latch.
CountDown(); }));
546 event.pixel_ratio = 1.0;
549 ASSERT_TRUE(
engine.is_valid());
559 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
570 context.GetCompositor().SetNextPresentCallback(
590 .rects = paint_region_rects,
594 .paint_region = &paint_region,
605 ASSERT_EQ(*
layers[0], layer);
620 ASSERT_EQ(*
layers[1], layer);
635 .rects = paint_region_rects,
639 .paint_region = &paint_region,
650 ASSERT_EQ(*
layers[2], layer);
656 context.AddNativeCallback(
659 [&latch](Dart_NativeArguments
args) { latch.
CountDown(); }));
668 event.pixel_ratio = 1.0;
671 ASSERT_TRUE(
engine.is_valid());
680 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
692 auto scene_image = context.GetNextSceneImage();
694 context.GetCompositor().SetNextPresentCallback(
712 .rects = paint_region_rects,
716 .paint_region = &paint_region,
727 ASSERT_EQ(*
layers[0], layer);
743 ASSERT_EQ(*
layers[1], layer);
759 .rects = paint_region_rects,
763 .paint_region = &paint_region,
774 ASSERT_EQ(*
layers[2], layer);
790 ASSERT_EQ(*
layers[3], layer);
806 .rects = paint_region_rects,
810 .paint_region = &paint_region,
821 ASSERT_EQ(*
layers[4], layer);
827 context.GetCompositor().SetPlatformViewRendererCallback(
829 GrDirectContext* context) -> sk_sp<SkImage> {
831 auto canvas =
surface->getCanvas();
838 paint.setColor(SK_ColorGREEN);
842 canvas->drawRect(rect, paint);
848 paint.setColor(SK_ColorMAGENTA);
852 canvas->drawRect(rect, paint);
858 <<
"Test was asked to composite an unknown platform view.";
861 return surface->makeImageSnapshot();
864 context.AddNativeCallback(
867 [&latch](Dart_NativeArguments
args) { latch.
CountDown(); }));
876 event.pixel_ratio = 1.0;
879 ASSERT_TRUE(
engine.is_valid());
886 ASSERT_EQ(context.GetSurfacePresentCount(), 0u);
894 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
902 auto platform_task_runner = CreateNewThread(
"test_platform_thread");
903 static std::mutex engine_mutex;
909 std::scoped_lock lock(engine_mutex);
920 context.GetCompositor().SetNextPresentCallback(
938 .rects = paint_region_rects,
942 .paint_region = &paint_region,
953 ASSERT_EQ(*
layers[0], layer);
967 .rects = paint_region_rects,
971 .paint_region = &paint_region,
982 ASSERT_EQ(*
layers[1], layer);
998 .rects = paint_region_rects,
1002 .paint_region = &paint_region,
1013 ASSERT_EQ(*
layers[2], layer);
1019 const auto task_runner_description =
1020 test_task_runner.GetFlutterTaskRunnerDescription();
1024 context.AddNativeCallback(
1027 [&latch](Dart_NativeArguments
args) { latch.
CountDown(); }));
1029 platform_task_runner->PostTask([&]() {
1030 std::scoped_lock lock(engine_mutex);
1032 ASSERT_TRUE(
engine.is_valid());
1039 event.pixel_ratio = 1.0;
1042 ASSERT_TRUE(
engine.is_valid());
1049 platform_task_runner->PostTask([&]() {
1050 std::scoped_lock lock(engine_mutex);
1062 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
1068 "can_composite_platform_views_with_root_layer_only");
1075 auto scene_image = context.GetNextSceneImage();
1077 context.GetCompositor().SetNextPresentCallback(
1095 .rects = paint_region_rects,
1099 .paint_region = &paint_region,
1110 ASSERT_EQ(*
layers[0], layer);
1116 context.AddNativeCallback(
1119 [&latch](Dart_NativeArguments
args) { latch.
CountDown(); }));
1128 event.pixel_ratio = 1.0;
1131 ASSERT_TRUE(
engine.is_valid());
1144 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
1150 "can_composite_platform_views_with_platform_layer_on_bottom");
1157 auto scene_image = context.GetNextSceneImage();
1159 context.GetCompositor().SetNextPresentCallback(
1177 .rects = paint_region_rects,
1181 .paint_region = &paint_region,
1192 ASSERT_EQ(*
layers[0], layer);
1208 ASSERT_EQ(*
layers[1], layer);
1214 context.GetCompositor().SetPlatformViewRendererCallback(
1216 GrDirectContext* context) -> sk_sp<SkImage> {
1218 auto canvas =
surface->getCanvas();
1225 paint.setColor(SK_ColorGREEN);
1226 paint.setAlpha(127);
1229 canvas->drawRect(rect, paint);
1235 <<
"Test was asked to composite an unknown platform view.";
1238 return surface->makeImageSnapshot();
1241 context.AddNativeCallback(
1244 [&latch](Dart_NativeArguments
args) { latch.
CountDown(); }));
1253 event.pixel_ratio = 1.0;
1256 ASSERT_TRUE(
engine.is_valid());
1261 "compositor_with_platform_layer_on_bottom.png", scene_image));
1263 ASSERT_EQ(context.GetCompositor().GetPendingBackingStoresCount(), 1u);
1271 CompositorMustBeAbleToRenderKnownSceneWithRootSurfaceTransformation) {
1272 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
1285 const auto root_surface_transformation =
1289 context.SetRootSurfaceTransformation(root_surface_transformation);
1293 auto scene_image = context.GetNextSceneImage();
1295 context.GetCompositor().SetNextPresentCallback(
1313 .rects = paint_region_rects,
1317 .paint_region = &paint_region,
1328 ASSERT_EQ(*
layers[0], layer);
1344 ASSERT_EQ(*
layers[1], layer);
1360 .rects = paint_region_rects,
1364 .paint_region = &paint_region,
1375 ASSERT_EQ(*
layers[2], layer);
1391 ASSERT_EQ(*
layers[3], layer);
1407 .rects = paint_region_rects,
1411 .paint_region = &paint_region,
1422 ASSERT_EQ(*
layers[4], layer);
1428 context.GetCompositor().SetPlatformViewRendererCallback(
1430 GrDirectContext* context) -> sk_sp<SkImage> {
1432 auto canvas =
surface->getCanvas();
1439 paint.setColor(SK_ColorGREEN);
1440 paint.setAlpha(127);
1443 canvas->drawRect(rect, paint);
1449 paint.setColor(SK_ColorMAGENTA);
1450 paint.setAlpha(127);
1453 canvas->drawRect(rect, paint);
1459 <<
"Test was asked to composite an unknown platform view.";
1462 return surface->makeImageSnapshot();
1465 context.AddNativeCallback(
1468 [&latch](Dart_NativeArguments
args) { latch.
CountDown(); }));
1478 event.pixel_ratio = 1.0;
1481 ASSERT_TRUE(
engine.is_valid());
1490 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
1497 auto rendered_scene = context.GetNextSceneImage();
1500 ASSERT_TRUE(
engine.is_valid());
1507 event.pixel_ratio = 1.0;
1516 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
1518 const auto root_surface_transformation =
1522 context.SetRootSurfaceTransformation(root_surface_transformation);
1529 auto rendered_scene = context.GetNextSceneImage();
1532 ASSERT_TRUE(
engine.is_valid());
1541 event.pixel_ratio = 1.0;
1546 "scene_without_custom_compositor_with_xform.png", rendered_scene));
1551 auto& context = GetEmbedderContext(backend);
1556 auto rendered_scene = context.GetNextSceneImage();
1559 ASSERT_TRUE(
engine.is_valid());
1566 event.pixel_ratio = 1.0;
1575 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
1577 const auto root_surface_transformation =
1581 context.SetRootSurfaceTransformation(root_surface_transformation);
1585 const auto surface_size =
DlISize(600, 800);
1590 auto rendered_scene = context.GetNextSceneImage();
1593 ASSERT_TRUE(
engine.is_valid());
1601 event.pixel_ratio = 1.0;
1610 auto& context = GetEmbedderContext(backend);
1618 auto rendered_scene = context.GetNextSceneImage();
1621 ASSERT_TRUE(
engine.is_valid());
1628 event.pixel_ratio = 1.0;
1637 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
1642 const auto root_surface_transformation =
1646 context.SetRootSurfaceTransformation(root_surface_transformation);
1656 auto rendered_scene = context.GetNextSceneImage();
1659 ASSERT_TRUE(
engine.is_valid());
1667 event.pixel_ratio = 1.0;
1675 CanRenderGradientWithCompositorOnNonRootLayer) {
1677 auto& context = GetEmbedderContext(backend);
1685 context.GetCompositor().SetNextPresentCallback(
1702 .rects = paint_region_rects,
1706 .paint_region = &paint_region,
1717 ASSERT_EQ(*
layers[0], layer);
1733 ASSERT_EQ(*
layers[1], layer);
1748 .rects = paint_region_rects,
1752 .paint_region = &paint_region,
1763 ASSERT_EQ(*
layers[2], layer);
1767 context.GetCompositor().SetPlatformViewRendererCallback(
1769 GrDirectContext* context) -> sk_sp<SkImage> {
1771 auto canvas =
surface->getCanvas();
1783 <<
"Test was asked to composite an unknown platform view.";
1786 return surface->makeImageSnapshot();
1789 auto rendered_scene = context.GetNextSceneImage();
1792 ASSERT_TRUE(
engine.is_valid());
1799 event.pixel_ratio = 1.0;
1808 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
1813 const auto root_surface_transformation =
1817 context.SetRootSurfaceTransformation(root_surface_transformation);
1827 context.GetCompositor().SetNextPresentCallback(
1845 .rects = paint_region_rects,
1849 .paint_region = &paint_region,
1860 ASSERT_EQ(*
layers[0], layer);
1876 ASSERT_EQ(*
layers[1], layer);
1892 .rects = paint_region_rects,
1896 .paint_region = &paint_region,
1907 ASSERT_EQ(*
layers[2], layer);
1911 context.GetCompositor().SetPlatformViewRendererCallback(
1913 GrDirectContext* context) -> sk_sp<SkImage> {
1915 auto canvas =
surface->getCanvas();
1927 <<
"Test was asked to composite an unknown platform view.";
1930 return surface->makeImageSnapshot();
1933 auto rendered_scene = context.GetNextSceneImage();
1936 ASSERT_TRUE(
engine.is_valid());
1944 event.pixel_ratio = 1.0;
1952 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
1958 const auto root_surface_transformation =
1962 const auto root_surface_rect =
1963 flutter_application_rect.TransformAndClipBounds(
1964 root_surface_transformation);
1966 ASSERT_FLOAT_EQ(root_surface_rect.GetWidth(), 600.0f);
1967 ASSERT_FLOAT_EQ(root_surface_rect.GetHeight(), 800.0f);
1970 context.SetRootSurfaceTransformation(root_surface_transformation);
1974 DlISize(root_surface_rect.GetWidth(), root_surface_rect.GetHeight()));
1985 context.GetCompositor().SetNextPresentCallback(
2003 const double unxformed_top_margin = 31.0;
2004 const double unxformed_bottom_margin = 37.0;
2007 unxformed_top_margin,
2009 600 - unxformed_top_margin - unxformed_bottom_margin
2016 const auto xformed_platform_view_rect =
2017 unxformed_platform_view_rect.TransformAndClipBounds(
2018 root_surface_transformation);
2022 ASSERT_EQ(xformed_platform_view_rect,
2031 xformed_platform_view_rect.GetY());
2033 xformed_platform_view_rect.GetHeight());
2035 ASSERT_EQ(*
layers[0], layer);
2049 event.width = flutter_application_rect.GetWidth();
2050 event.height = flutter_application_rect.GetHeight();
2051 event.pixel_ratio = 1.0;
2054 ASSERT_TRUE(
engine.is_valid());
2063 std::mutex engine_mutex;
2066 bool task_executed =
false;
2068 CreateNewThread(
"custom_render_thread"), [&](
FlutterTask task) {
2069 std::scoped_lock engine_lock(engine_mutex);
2072 task_executed =
true;
2076 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
2081 &render_task_runner.GetFlutterTaskRunnerDescription());
2084 std::scoped_lock lock(engine_mutex);
2090 ASSERT_TRUE(
engine.is_valid());
2096 event.pixel_ratio = 1.0;
2100 ASSERT_TRUE(task_executed);
2104 std::scoped_lock engine_lock(engine_mutex);
2114 CanCreateEmbedderWithCustomRenderTaskRunnerTheSameAsPlatformTaskRunner) {
2118 auto platform_task_runner = CreateNewThread(
"platform_thread");
2120 static std::mutex engine_mutex;
2123 bool task_executed =
false;
2126 std::scoped_lock engine_lock(engine_mutex);
2129 task_executed =
true;
2134 platform_task_runner->PostTask([&]() {
2136 auto& context = GetEmbedderContext(backend);
2141 &common_task_runner.GetFlutterTaskRunnerDescription());
2143 &common_task_runner.GetFlutterTaskRunnerDescription());
2146 std::scoped_lock lock(engine_mutex);
2152 ASSERT_TRUE(
engine.is_valid());
2158 event.pixel_ratio = 1.0;
2169 platform_task_runner->PostTask([&]() {
2170 ASSERT_TRUE(task_executed);
2174 std::scoped_lock engine_lock(engine_mutex);
2180 shutdown_latch.
Wait();
2183 std::scoped_lock engine_lock(engine_mutex);
2185 ASSERT_FALSE(
engine.is_valid());
2190 CompositorMustBeAbleToRenderKnownScenePixelRatioOnSurface) {
2192 auto& context = GetEmbedderContext(backend);
2203 auto rendered_scene = context.GetNextSceneImage();
2205 context.GetCompositor().SetNextPresentCallback(
2222 .rects = paint_region_rects,
2226 .paint_region = &paint_region,
2237 ASSERT_EQ(*
layers[0], layer);
2253 ASSERT_EQ(*
layers[1], layer);
2268 .rects = paint_region_rects,
2272 .paint_region = &paint_region,
2283 ASSERT_EQ(*
layers[2], layer);
2294 event.width = 400 * 2.0;
2295 event.height = 300 * 2.0;
2296 event.pixel_ratio = 2.0;
2299 ASSERT_TRUE(
engine.is_valid());
2309 CompositorMustBeAbleToRenderKnownScenePixelRatioOnSurfaceWithRootSurfaceXformation) {
2310 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
2320 const auto root_surface_transformation =
2324 context.SetRootSurfaceTransformation(root_surface_transformation);
2326 auto rendered_scene = context.GetNextSceneImage();
2329 context.GetCompositor().SetNextPresentCallback(
2347 .rects = paint_region_rects,
2351 .paint_region = &paint_region,
2362 ASSERT_EQ(*
layers[0], layer);
2378 ASSERT_EQ(*
layers[1], layer);
2394 .rects = paint_region_rects,
2398 .paint_region = &paint_region,
2409 ASSERT_EQ(*
layers[2], layer);
2420 event.width = 400 * 2.0;
2421 event.height = 300 * 2.0;
2422 event.pixel_ratio = 2.0;
2425 ASSERT_TRUE(
engine.is_valid());
2433 PushingMutlipleFramesSetsUpNewRecordingCanvasWithCustomCompositor) {
2434 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
2444 const auto root_surface_transformation =
2448 context.SetRootSurfaceTransformation(root_surface_transformation);
2457 event.pixel_ratio = 1.0;
2460 ASSERT_TRUE(
engine.is_valid());
2462 constexpr size_t frames_expected = 10;
2464 std::atomic_size_t frames_seen = 0;
2465 context.AddNativeCallback(
"SignalNativeTest",
2472 ASSERT_GE(frames_seen, frames_expected);
2478 PushingMutlipleFramesSetsUpNewRecordingCanvasWithoutCustomCompositor) {
2479 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
2485 const auto root_surface_transformation =
2489 context.SetRootSurfaceTransformation(root_surface_transformation);
2498 event.pixel_ratio = 1.0;
2501 ASSERT_TRUE(
engine.is_valid());
2503 constexpr size_t frames_expected = 10;
2505 std::atomic_size_t frames_seen = 0;
2506 context.AddNativeCallback(
"SignalNativeTest",
2513 ASSERT_GE(frames_seen, frames_expected);
2520 auto& context = GetEmbedderContext(backend);
2530 context.GetCompositor().SetNextPresentCallback(
2547 .rects = paint_region_rects,
2551 .paint_region = &paint_region,
2562 ASSERT_EQ(*
layers[0], layer);
2579 ASSERT_EQ(*
layers[1], layer);
2584 switch (mutation.
type) {
2588 SkRect::MakeLTRB(10.0, 10.0, 800.0 - 10.0,
2599 mutation.
opacity = 128.0 / 255.0;
2603 <<
"There should be no transformation in the test.";
2620 event.pixel_ratio = 1.0;
2623 ASSERT_TRUE(
engine.is_valid());
2629 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
2640 context.GetCompositor().SetNextPresentCallback(
2658 .rects = paint_region_rects,
2662 .paint_region = &paint_region,
2673 ASSERT_EQ(*
layers[0], layer);
2690 ASSERT_EQ(*
layers[1], layer);
2695 switch (mutation.
type) {
2699 SkRect::MakeLTRB(5.0, 5.0, 400.0 - 5.0, 300.0 - 5.0),
2709 mutation.
opacity = 128.0 / 255.0;
2731 event.pixel_ratio = 2.0;
2734 ASSERT_TRUE(
engine.is_valid());
2740 PlatformViewMutatorsAreValidWithPixelRatioAndRootSurfaceTransformation) {
2741 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
2751 static const auto root_surface_transformation =
2755 context.SetRootSurfaceTransformation(root_surface_transformation);
2758 context.GetCompositor().SetNextPresentCallback(
2776 .rects = paint_region_rects,
2780 .paint_region = &paint_region,
2791 ASSERT_EQ(*
layers[0], layer);
2808 ASSERT_EQ(*
layers[1], layer);
2813 switch (mutation.
type) {
2817 SkRect::MakeLTRB(5.0, 5.0, 400.0 - 5.0, 300.0 - 5.0),
2827 mutation.
opacity = 128.0 / 255.0;
2850 event.pixel_ratio = 2.0;
2853 ASSERT_TRUE(
engine.is_valid());
2859 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
2866 context.AddNativeCallback(
2872 ASSERT_TRUE(
engine.is_valid());
2878 event.pixel_ratio = 1.0;
2885 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
2894 context.AddNativeCallback(
2900 ASSERT_TRUE(
engine.is_valid());
2906 event.pixel_ratio = 1.0;
2915 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
2924 const auto root_surface_transformation =
2929 context.SetRootSurfaceTransformation(root_surface_transformation);
2933 auto scene_image = context.GetNextSceneImage();
2935 ASSERT_TRUE(
engine.is_valid());
2940 event.height = 1024;
2941 event.pixel_ratio = 1.0;
2949 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
2958 const auto root_surface_transformation =
2962 context.SetRootSurfaceTransformation(root_surface_transformation);
2965 context.GetCompositor().SetNextPresentCallback(
2982 ASSERT_EQ(*
layers[0], layer);
2984 bool clip_assertions_checked =
false;
2987 const auto total_xformation =
2993 [&](
const auto& mutation) {
2998 const auto rect_to_compare =
3003 ASSERT_TRUE(total_xformation.IsAligned2D());
3007 clip_assertions_checked =
true;
3010 ASSERT_TRUE(clip_assertions_checked);
3017 ASSERT_TRUE(
engine.is_valid());
3023 event.pixel_ratio = 1.0;
3031 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
3040 const auto root_surface_transformation =
3044 context.SetRootSurfaceTransformation(root_surface_transformation);
3047 context.GetCompositor().SetNextPresentCallback(
3064 ASSERT_EQ(*
layers[0], layer);
3068 ASSERT_EQ(mutations[0]->
type,
3071 root_surface_transformation);
3073 ASSERT_EQ(mutations[1]->
type,
3075 ASSERT_EQ(
SkRectMake(mutations[1]->clip_rect),
3076 SkRect::MakeLTRB(0.0, 0.0, 1024.0, 600.0));
3078 ASSERT_EQ(mutations[2]->
type,
3083 ASSERT_EQ(mutations[3]->
type,
3085 ASSERT_EQ(
SkRectMake(mutations[3]->clip_rect),
3086 SkRect::MakeLTRB(0.0, 0.0, 512.0, 600.0));
3088 ASSERT_EQ(mutations[4]->
type,
3093 ASSERT_EQ(mutations[5]->
type,
3095 ASSERT_EQ(
SkRectMake(mutations[5]->clip_rect),
3096 SkRect::MakeLTRB(0.0, 0.0, 1024.0, 600.0));
3103 ASSERT_TRUE(
engine.is_valid());
3109 event.pixel_ratio = 1.0;
3117 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
3127 context.AddNativeCallback(
"SignalNativeCount",
3130 Dart_GetNativeArgument(
args, 0));
3134 ASSERT_TRUE(
engine.is_valid());
3138 using Trampoline = std::function<void(Dart_Handle
message)>;
3139 Trampoline trampoline;
3141 context.AddNativeCallback(
"SendObjectToNativeCode",
3144 auto trampoline_copy = trampoline;
3145 trampoline =
nullptr;
3146 trampoline_copy(Dart_GetNativeArgument(
args, 0));
3153 trampoline = [&](Dart_Handle handle) {
3154 ASSERT_TRUE(Dart_IsNull(handle));
3166 object.bool_value =
true;
3167 trampoline = [&](Dart_Handle handle) {
3180 object.int32_value = 1988;
3181 trampoline = [&](Dart_Handle handle) {
3194 object.int64_value = 1988;
3195 trampoline = [&](Dart_Handle handle) {
3208 object.double_value = 1988.0;
3209 trampoline = [&](Dart_Handle handle) {
3220 const char*
message =
"Hello. My name is Inigo Montoya.";
3223 object.string_value =
message;
3224 trampoline = [&](Dart_Handle handle) {
3245 buffer.user_data =
nullptr;
3246 buffer.buffer_collect_callback =
nullptr;
3252 object.buffer_value = &
buffer;
3253 trampoline = [&](Dart_Handle handle) {
3255 Dart_ListLength(handle, &
length);
3281 buffer.user_data = &buffer_released_latch;
3290 object.buffer_value = &
buffer;
3291 trampoline = [&](Dart_Handle handle) {
3293 Dart_ListLength(handle, &
length);
3312 buffer_released_latch.
Wait();
3316 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
3327 context.GetCompositor().SetNextPresentCallback(
3340 event.pixel_ratio = 1.0;
3343 ASSERT_TRUE(
engine.is_valid());
3346 ASSERT_EQ(context.GetCompositor().GetPendingBackingStoresCount(), 0u);
3350 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
3361 context.GetCompositor().SetNextPresentCallback(
3378 ASSERT_EQ(*
layers[0], layer);
3393 ASSERT_EQ(*
layers[1], layer);
3404 event.pixel_ratio = 1.0;
3407 ASSERT_TRUE(
engine.is_valid());
3410 ASSERT_EQ(context.GetCompositor().GetPendingBackingStoresCount(), 0u);
3414 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
3425 context.AddNativeCallback(
"SignalNativeTest",
3430 context.GetCompositor().SetNextPresentCallback(
3438 ASSERT_TRUE(
engine.is_valid());
3444 event.pixel_ratio = 1.0;
3449 ASSERT_EQ(context.GetCompositor().GetPendingBackingStoresCount(), 10u);
3450 ASSERT_EQ(context.GetCompositor().GetBackingStoresCreatedCount(), 10u);
3451 ASSERT_EQ(context.GetCompositor().GetBackingStoresCollectedCount(), 0u);
3454 ASSERT_EQ(context.GetCompositor().GetPendingBackingStoresCount(), 0u);
3455 ASSERT_EQ(context.GetCompositor().GetBackingStoresCreatedCount(), 10u);
3456 ASSERT_EQ(context.GetCompositor().GetBackingStoresCollectedCount(), 10u);
3460 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
3471 context.AddNativeCallback(
"SignalNativeTest",
3476 size_t frame_count = 0;
3477 std::vector<void*> first_frame_backing_store_user_data;
3478 context.GetCompositor().SetPresentCallback(
3483 if (first_frame_backing_store_user_data.empty()) {
3486 first_frame_backing_store_user_data.push_back(
3487 layers[
i]->backing_store->user_data);
3493 ASSERT_EQ(first_frame_backing_store_user_data.size(), 10u);
3496 std::vector<void*> backing_store_user_data;
3499 backing_store_user_data.push_back(
3500 layers[
i]->backing_store->user_data);
3504 ASSERT_EQ(backing_store_user_data.size(), 10u);
3506 ASSERT_EQ(first_frame_backing_store_user_data, backing_store_user_data);
3508 if (frame_count == 20) {
3516 ASSERT_TRUE(
engine.is_valid());
3522 event.pixel_ratio = 1.0;
3530 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
3531 const auto root_surface_transformation =
3534 context.SetRootSurfaceTransformation(root_surface_transformation);
3546 event.pixel_ratio = 1.0;
3549 ASSERT_TRUE(
engine.is_valid());
3553 context.AddNativeCallback(
"SignalNativeTest",
3560 ASSERT_EQ(frame_info.
size.
width, event.height);
3561 ASSERT_EQ(frame_info.
size.
height, event.width);
3570 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
3571 context.SetOpenGLFBOCallBack();
3577 ASSERT_FALSE(
engine.is_valid());
3581 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
3582 context.SetOpenGLPresentCallBack();
3588 ASSERT_FALSE(
engine.is_valid());
3592 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
3593 context.GetRendererConfig().open_gl.populate_existing_damage =
nullptr;
3599 ASSERT_TRUE(
engine.is_valid());
3603 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
3604 context.GetRendererConfig().open_gl.populate_existing_damage =
3605 [](
void* context,
const intptr_t
id,
3608 ->GLPopulateExistingDamage(
id, existing_damage);
3614 ASSERT_TRUE(
engine.is_valid());
3618 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
3619 context.GetRendererConfig().open_gl.fbo_callback =
3620 [](
void* context) -> uint32_t {
return 0; };
3621 context.GetRendererConfig().open_gl.fbo_with_frame_info_callback =
nullptr;
3622 context.GetRendererConfig().open_gl.populate_existing_damage =
3623 [](
void* context,
const intptr_t
id,
3626 ->GLPopulateExistingDamage(
id, existing_damage);
3632 ASSERT_TRUE(
engine.is_valid());
3636 MustNotRunWhenPopulateExistingDamageButNoOtherFBOCallback) {
3637 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
3638 context.GetRendererConfig().open_gl.fbo_callback =
nullptr;
3639 context.GetRendererConfig().open_gl.fbo_with_frame_info_callback =
nullptr;
3640 context.GetRendererConfig().open_gl.populate_existing_damage =
3641 [](
void* context,
const intptr_t
id,
3644 ->GLPopulateExistingDamage(
id, existing_damage);
3650 ASSERT_FALSE(
engine.is_valid());
3654 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
3655 const auto root_surface_transformation =
3658 context.SetRootSurfaceTransformation(root_surface_transformation);
3671 event.pixel_ratio = 1.0;
3674 ASSERT_TRUE(
engine.is_valid());
3678 context.AddNativeCallback(
"SignalNativeTest",
3683 const uint32_t window_fbo_id = context.GetWindowFBOId();
3684 context.SetGLPresentCallback(
3686 ASSERT_EQ(present_info.
fbo_id, window_fbo_id);
3695 PresentInfoReceivesFullDamageWhenExistingDamageIsWholeScreen) {
3696 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
3697 context.GetRendererConfig().open_gl.populate_existing_damage =
3698 [](
void* context,
const intptr_t
id,
3701 ->GLPopulateExistingDamage(
id, existing_damage);
3706 const size_t num_rects = 1;
3708 static FlutterRect existing_damage_rects[num_rects] = {
3710 existing_damage_ptr->
num_rects = num_rects;
3711 existing_damage_ptr->
damage = existing_damage_rects;
3718 ASSERT_TRUE(
engine.is_valid());
3724 const size_t num_rects = 1;
3745 event.pixel_ratio = 1.0;
3754 const size_t num_rects = 1;
3776 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
3777 context.GetRendererConfig().open_gl.populate_existing_damage =
3778 [](
void* context,
const intptr_t
id,
3781 ->GLPopulateExistingDamage(
id, existing_damage);
3786 const size_t num_rects = 1;
3788 static FlutterRect existing_damage_rects[num_rects] = {
3790 existing_damage_ptr->
num_rects = num_rects;
3791 existing_damage_ptr->
damage = existing_damage_rects;
3798 ASSERT_TRUE(
engine.is_valid());
3804 const size_t num_rects = 1;
3825 event.pixel_ratio = 1.0;
3833 const size_t num_rects = 1;
3855 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
3856 context.GetRendererConfig().open_gl.populate_existing_damage =
3857 [](
void* context,
const intptr_t
id,
3860 ->GLPopulateExistingDamage(
id, existing_damage);
3864 [&](
const intptr_t
id,
FlutterDamage* existing_damage_ptr) {
3865 const size_t num_rects = 1;
3867 static FlutterRect existing_damage_rects[num_rects] = {
3869 existing_damage_ptr->
num_rects = num_rects;
3870 existing_damage_ptr->
damage = existing_damage_rects;
3877 ASSERT_TRUE(
engine.is_valid());
3883 const size_t num_rects = 1;
3904 event.pixel_ratio = 1.0;
3913 const size_t num_rects = 1;
3935 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
3936 context.GetRendererConfig().open_gl.populate_existing_damage =
3937 [](
void* context,
const intptr_t
id,
3940 ->GLPopulateExistingDamage(
id, existing_damage);
3947 ASSERT_TRUE(
engine.is_valid());
3949 const uint32_t window_fbo_id = context.GetWindowFBOId();
3950 context.SetGLPopulateExistingDamageCallback(
3951 [window_fbo_id = window_fbo_id](intptr_t
id,
3953 ASSERT_EQ(
id, window_fbo_id);
3955 existing_damage->
damage =
nullptr;
3963 event.pixel_ratio = 1.0;
3969 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
3970 context.GetRendererConfig().open_gl.populate_existing_damage =
3971 [](
void* context,
const intptr_t
id,
3974 ->GLPopulateExistingDamage(
id, existing_damage);
3986 ASSERT_TRUE(
engine.is_valid());
3988 context.AddNativeCallback(
"SignalNativeTest",
3993 const uint32_t window_fbo_id = context.GetWindowFBOId();
3994 context.SetGLPopulateExistingDamageCallback(
3995 [window_fbo_id = window_fbo_id](intptr_t
id,
3997 ASSERT_NE(
id, window_fbo_id);
3999 existing_damage->
damage =
nullptr;
4007 event.pixel_ratio = 1.0;
4013 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
4020 context.AddNativeCallback(
4026 ASSERT_TRUE(
engine.is_valid());
4033 std::vector<FlutterEngineDisplay>
displays = {display};
4047 event.pixel_ratio = 1.0;
4055 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
4062 context.AddNativeCallback(
4068 ASSERT_TRUE(
engine.is_valid());
4075 std::vector<FlutterEngineDisplay>
displays = {display};
4089 event.pixel_ratio = 1.0;
4097 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
4104 context.AddNativeCallback(
4110 ASSERT_TRUE(
engine.is_valid());
4124 std::vector<FlutterEngineDisplay>
displays = {display_1, display_2};
4138 event.pixel_ratio = 1.0;
4146 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
4153 context.AddNativeCallback(
4159 ASSERT_TRUE(
engine.is_valid());
4173 std::vector<FlutterEngineDisplay>
displays = {display_1, display_2};
4184 event.pixel_ratio = 1.0;
4192 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
4199 context.AddNativeCallback(
4205 ASSERT_TRUE(
engine.is_valid());
4219 std::vector<FlutterEngineDisplay>
displays = {display_1, display_2};
4230 event.pixel_ratio = 1.0;
4238 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
4247 const unsigned num_frames = 8;
4248 const unsigned num_engine_layers = 10;
4249 const unsigned num_backing_stores = num_frames * num_engine_layers;
4252 context.AddNativeCallback(
"SignalNativeTest",
4257 context.GetCompositor().SetPresentCallback(
4266 ASSERT_TRUE(
engine.is_valid());
4272 event.pixel_ratio = 1.0;
4278 ASSERT_EQ(context.GetCompositor().GetBackingStoresCreatedCount(),
4279 num_backing_stores);
4282 ASSERT_EQ(context.GetCompositor().GetPendingBackingStoresCount(), 0u);
4286 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
4292 auto max_size = context.GetCompositor().GetGrContext()->maxRenderTargetSize();
4294 context.AddIsolateCreateCallback([&]() {
4295 Dart_Handle snapshot_large_scene = Dart_GetField(
4301 context.AddNativeCallback(
4303 auto get_arg = [&
args](
int index) {
4304 Dart_Handle dart_image = Dart_GetNativeArgument(
args, index);
4305 Dart_Handle internal_image =
4312 ASSERT_EQ(big_image->
width(), max_size);
4313 ASSERT_EQ(big_image->
height(), max_size / 2);
4317 "snapshot_large_scene.png",
4318 small_image->
image()->asSkiaImage()->skia_image()));
4324 ASSERT_TRUE(
engine.is_valid());
4330 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
4340 context.AddNativeCallback(
"SignalNativeCount",
4343 Dart_GetNativeArgument(
args, 0));
4347 ASSERT_TRUE(
engine.is_valid());
4351 using Trampoline = std::function<void(Dart_Handle
message)>;
4352 Trampoline trampoline;
4354 context.AddNativeCallback(
"SendObjectToNativeCode",
4357 auto trampoline_copy = trampoline;
4358 trampoline =
nullptr;
4359 trampoline_copy(Dart_GetNativeArgument(
args, 0));
4366 object.bool_value =
true;
4367 trampoline = [&](Dart_Handle handle) {
4380 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
4388 class TestCollectOnce {
4392 ASSERT_FALSE(collected_);
4397 bool collected_ =
false;
4408 backing_store_out->user_data =
nullptr;
4410 backing_store_out->open_gl.texture.target = 0;
4411 backing_store_out->open_gl.texture.name = 0;
4412 backing_store_out->open_gl.texture.format = 0;
4413 static TestCollectOnce collect_once_user_data;
4414 collect_once_user_data = {};
4415 backing_store_out->open_gl.texture.user_data = &collect_once_user_data;
4416 backing_store_out->open_gl.texture.destruction_callback =
4418 reinterpret_cast<TestCollectOnce*
>(
user_data)->Collect();
4423 context.AddNativeCallback(
4426 [&latch](Dart_NativeArguments
args) { latch.
Signal(); }));
4435 event.pixel_ratio = 1.0;
4438 ASSERT_TRUE(
engine.is_valid());
4443 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
4451 class TestCollectOnce {
4455 ASSERT_FALSE(collected_);
4460 bool collected_ =
false;
4471 backing_store_out->user_data =
nullptr;
4473 backing_store_out->open_gl.framebuffer.target = 0;
4474 backing_store_out->open_gl.framebuffer.name = 0;
4475 static TestCollectOnce collect_once_user_data;
4476 collect_once_user_data = {};
4477 backing_store_out->open_gl.framebuffer.user_data =
4478 &collect_once_user_data;
4479 backing_store_out->open_gl.framebuffer.destruction_callback =
4481 reinterpret_cast<TestCollectOnce*
>(
user_data)->Collect();
4486 context.AddNativeCallback(
4489 [&latch](Dart_NativeArguments
args) { latch.
Signal(); }));
4498 event.pixel_ratio = 1.0;
4501 ASSERT_TRUE(
engine.is_valid());
4506 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
4522 backing_store_out->user_data =
user_data;
4524 backing_store_out->open_gl.surface.user_data =
user_data;
4526 backing_store_out->open_gl.surface.format = 0;
4527 backing_store_out->open_gl.surface.make_current_callback = [](
void*,
4529 ADD_FAILURE() <<
"make_current_callback method should not be called";
4532 backing_store_out->open_gl.surface.clear_current_callback = [](
void*,
4534 ADD_FAILURE() <<
"clear_current_callback method should not be called";
4537 backing_store_out->open_gl.surface.destruction_callback =
4539 FAIL() <<
"destruction_callback method should not be called";
4545 context.AddNativeCallback(
4548 [&latch](Dart_NativeArguments
args) { latch.
Signal(); }));
4557 event.pixel_ratio = 1.0;
4560 ASSERT_TRUE(
engine.is_valid());
4566 auto context =
surface.GetGrContext();
4568 typedef void (*glGenTexturesProc)(uint32_t n, uint32_t* textures);
4569 typedef void (*glFinishProc)();
4571 glGenTexturesProc glGenTextures;
4572 glFinishProc glFinish;
4574 glGenTextures =
reinterpret_cast<glGenTexturesProc
>(
4575 surface.GetProcAddress(
"glGenTextures"));
4576 glFinish =
reinterpret_cast<glFinishProc
>(
surface.GetProcAddress(
"glFinish"));
4579 glGenTextures(1, &
name);
4581 bool resolve_called =
false;
4584 [&](int64_t,
size_t,
size_t) {
4585 resolve_called =
true;
4586 auto res = std::make_unique<FlutterOpenGLTexture>();
4587 res->target = GL_TEXTURE_2D;
4589 res->format = GL_RGBA8;
4590 res->user_data =
nullptr;
4591 res->destruction_callback = [](
void*) {};
4592 res->width = res->height = 100;
4597 auto skia_surface =
surface.GetOnscreenSurface();
4603 .gr_context = context.get(),
4608 EXPECT_TRUE(resolve_called);
4609 resolve_called =
false;
4614 EXPECT_FALSE(resolve_called);
4620 EXPECT_TRUE(resolve_called);
4627 PresentInfoReceivesFullScreenDamageWhenPopulateExistingDamageIsNotProvided) {
4628 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
4629 context.GetRendererConfig().open_gl.populate_existing_damage =
nullptr;
4635 ASSERT_TRUE(
engine.is_valid());
4641 const size_t num_rects = 1;
4662 event.pixel_ratio = 1.0;
4671 const size_t num_rects = 1;
4693 PresentInfoReceivesJoinedDamageWhenExistingDamageContainsMultipleRects) {
4694 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
4695 context.GetRendererConfig().open_gl.populate_existing_damage =
4696 [](
void* context,
const intptr_t
id,
4699 ->GLPopulateExistingDamage(
id, existing_damage);
4704 const size_t num_rects = 2;
4706 static FlutterRect existing_damage_rects[num_rects] = {
4710 existing_damage_ptr->
num_rects = num_rects;
4711 existing_damage_ptr->
damage = existing_damage_rects;
4718 ASSERT_TRUE(
engine.is_valid());
4724 const size_t num_rects = 1;
4745 event.pixel_ratio = 1.0;
4754 const size_t num_rects = 1;
4776 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
4779 bool present_called =
false;
4780 context.SetGLPresentCallback(
4782 present_called =
true;
4792 auto rendered_scene = context.GetNextSceneImage();
4795 ASSERT_TRUE(
engine.is_valid());
4799 typedef void (*glGenFramebuffersProc)(GLsizei n, GLuint* ids);
4800 typedef void (*glBindFramebufferProc)(GLenum
target, GLuint framebuffer);
4801 auto glGenFramebuffers =
reinterpret_cast<glGenFramebuffersProc
>(
4802 context.GLGetProcAddress(
"glGenFramebuffers"));
4803 auto glBindFramebuffer =
reinterpret_cast<glBindFramebufferProc
>(
4804 context.GLGetProcAddress(
"glBindFramebuffer"));
4809 glGenFramebuffers(1, &fbo);
4810 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
4813 raster_event.
Wait();
4820 event.pixel_ratio = 1.0;
4826 "impeller_test.png"),
4831 ASSERT_FALSE(present_called);
4835 constexpr int kWidth = 800;
4836 constexpr int kHeight = 600;
4837 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
4840 context.SetGLPresentCallback(
4845 typedef void (*glGenTexturesProc)(GLsizei n, GLuint* textures);
4846 typedef void (*glBindTextureProc)(GLenum n, GLuint
texture);
4847 typedef void (*glTexImage2DProc)(GLenum
target, GLint level,
4848 GLint internalformat, GLsizei
width,
4850 GLenum
type,
const void* pixels);
4851 static glGenTexturesProc glGenTextures =
reinterpret_cast<glGenTexturesProc
>(
4852 context.GLGetProcAddress(
"glGenTextures"));
4853 static glBindTextureProc glBindTexture =
reinterpret_cast<glBindTextureProc
>(
4854 context.GLGetProcAddress(
"glBindTexture"));
4855 static glTexImage2DProc glTexImage2D =
reinterpret_cast<glTexImage2DProc
>(
4856 context.GLGetProcAddress(
"glTexImage2D"));
4858 static GLuint gl_texture = 0;
4859 auto rendered_scene = context.GetNextSceneImage();
4860 context.GetRendererConfig().open_gl.gl_external_texture_frame_callback =
4863 std::vector<uint8_t>
buffer(kWidth * kHeight * 4);
4864 for (
int i = 0;
i < kWidth * kHeight / 2; ++
i) {
4871 for (
int i = kWidth * kHeight / 2;
i < kWidth * kHeight; ++
i) {
4878 if (gl_texture == 0) {
4879 glGenTextures(1, &gl_texture);
4881 glBindTexture(GL_TEXTURE_2D, gl_texture);
4882 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, kWidth, kHeight, 0, GL_RGBA,
4883 GL_UNSIGNED_BYTE,
buffer.data());
4884 texture->target = GL_TEXTURE_2D;
4887 texture->destruction_callback =
nullptr;
4896 ASSERT_TRUE(
engine.is_valid());
4906 event.width = kWidth;
4907 event.height = kHeight;
4908 event.pixel_ratio = 1.0;
4914 constexpr int kFrameCount = 5;
4915 for (
int i = 0;
i < kFrameCount;
i++) {
4916 rendered_scene = context.GetNextSceneImage();
4925 constexpr int kWidth = 800;
4926 constexpr int kHeight = 600;
4927 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
4930 context.SetGLPresentCallback(
4935 typedef void (*glGenTexturesProc)(GLsizei n, GLuint* textures);
4936 typedef void (*glBindTextureProc)(GLenum n, GLuint
texture);
4937 typedef void (*glTexImage2DProc)(GLenum
target, GLint level,
4938 GLint internalformat, GLsizei
width,
4940 GLenum
type,
const void* pixels);
4941 static glGenTexturesProc glGenTextures =
reinterpret_cast<glGenTexturesProc
>(
4942 context.GLGetProcAddress(
"glGenTextures"));
4943 static glBindTextureProc glBindTexture =
reinterpret_cast<glBindTextureProc
>(
4944 context.GLGetProcAddress(
"glBindTexture"));
4945 static glTexImage2DProc glTexImage2D =
reinterpret_cast<glTexImage2DProc
>(
4946 context.GLGetProcAddress(
"glTexImage2D"));
4948 auto rendered_scene = context.GetNextSceneImage();
4950 static bool destruction_callback_called =
false;
4951 static auto destruction_callback = [](
void*
user_data) {
4953 static_cast<GLuint
>(
reinterpret_cast<uintptr_t
>(
user_data));
4954 glDeleteTextures(1, &gl_texture);
4955 destruction_callback_called =
true;
4957 context.GetRendererConfig().open_gl.gl_external_texture_frame_callback =
4960 std::vector<uint8_t>
buffer(kWidth * kHeight * 4);
4961 for (
int i = 0;
i < kWidth * kHeight / 2; ++
i) {
4968 for (
int i = kWidth * kHeight / 2;
i < kWidth * kHeight; ++
i) {
4976 glGenTextures(1, &gl_texture);
4977 glBindTexture(GL_TEXTURE_2D, gl_texture);
4978 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, kWidth, kHeight, 0, GL_RGBA,
4979 GL_UNSIGNED_BYTE,
buffer.data());
4980 texture->target = GL_TEXTURE_2D;
4983 texture->destruction_callback = destruction_callback;
4984 texture->user_data =
reinterpret_cast<void*
>(gl_texture);
4992 ASSERT_TRUE(
engine.is_valid());
5002 event.width = kWidth;
5003 event.height = kHeight;
5004 event.pixel_ratio = 1.0;
5017 ASSERT_TRUE(destruction_callback_called);
5021 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
5023 bool result =
false;
5025 context.AddNativeCallback(
"NotifyBoolValue",
5028 Dart_GetNativeArgument(
args, 0));
5041 ASSERT_TRUE(
engine.is_valid());
5044 ASSERT_TRUE(result);
5048 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
5059 context.GetCompositor().SetNextPresentCallback(
5066 backing_store.
struct_size =
sizeof(backing_store);
5077 .rects = paint_region_rects,
5081 .paint_region = &paint_region,
5091 ASSERT_EQ(*
layers[0], layer);
5106 ASSERT_EQ(*
layers[1], layer);
5111 backing_store.
struct_size =
sizeof(backing_store);
5122 .rects = paint_region_rects,
5126 .paint_region = &paint_region,
5137 ASSERT_EQ(*
layers[2], layer);
5143 context.AddNativeCallback(
5146 [&latch](Dart_NativeArguments
args) { latch.
CountDown(); }));
5155 event.pixel_ratio = 1.0;
5158 ASSERT_TRUE(
engine.is_valid());
5164 auto& context = GetEmbedderContext<EmbedderTestContextGL>();
5176 auto scene_image = context.GetNextSceneImage();
5178 context.GetCompositor().SetNextPresentCallback(
5196 .rects = paint_region_rects,
5200 .paint_region = &paint_region,
5211 ASSERT_EQ(*
layers[0], layer);
5227 ASSERT_EQ(*
layers[1], layer);
5243 .rects = paint_region_rects,
5247 .paint_region = &paint_region,
5258 ASSERT_EQ(*
layers[2], layer);
5274 ASSERT_EQ(*
layers[3], layer);
5290 .rects = paint_region_rects,
5294 .paint_region = &paint_region,
5305 ASSERT_EQ(*
layers[4], layer);
5311 context.GetCompositor().SetPlatformViewRendererCallback(
5313 GrDirectContext* context) -> sk_sp<SkImage> {
5315 auto canvas =
surface->getCanvas();
5322 paint.setColor(SK_ColorGREEN);
5323 paint.setAlpha(127);
5326 canvas->drawRect(rect, paint);
5332 paint.setColor(SK_ColorMAGENTA);
5333 paint.setAlpha(127);
5336 canvas->drawRect(rect, paint);
5342 <<
"Test was asked to composite an unknown platform view.";
5345 return surface->makeImageSnapshot();
5348 context.AddNativeCallback(
5351 [&latch](Dart_NativeArguments
args) { latch.
CountDown(); }));
5360 event.pixel_ratio = 1.0;
5363 ASSERT_TRUE(
engine.is_valid());
5370 ASSERT_EQ(context.GetSurfacePresentCount(), 0u);
sk_sp< DlImage > image() const
Backend implementation of |DlCanvas| for |SkCanvas|.
bool MarkTextureFrameAvailable(int64_t texture)
bool RegisterTexture(int64_t texture)
std::function< std::unique_ptr< FlutterOpenGLTexture >(int64_t, size_t, size_t)> ExternalTextureCallback
size_t GetCachedEntriesCount() const
fml::TaskRunnerAffineWeakPtr< Rasterizer > GetRasterizer() const
Rasterizers may only be accessed on the raster task runner.
const TaskRunners & GetTaskRunners() const override
If callers wish to interact directly with any shell subcomponents, they must (on the platform thread)...
double GetMainDisplayRefreshRate()
Queries the DisplayManager for the main display refresh rate.
fml::RefPtr< fml::TaskRunner > GetRasterTaskRunner() const
virtual void MarkNewFrameAvailable()=0
virtual void Paint(PaintContext &context, const DlRect &bounds, bool freeze, const DlImageSampling sampling)=0
void SetPlatformTaskRunner(const FlutterTaskRunnerDescription *runner)
void SetSurface(DlISize surface_size)
void SetRenderTargetType(EmbedderTestBackingStoreProducer::RenderTargetType type, FlutterSoftwarePixelFormat software_pixfmt=kFlutterSoftwarePixelFormatNative32)
void SetDartEntrypoint(std::string entrypoint)
void AddCommandLineArgument(std::string arg)
void SetRenderTaskRunner(const FlutterTaskRunnerDescription *runner)
FlutterCompositor & GetCompositor()
UniqueEngine LaunchEngine() const
void SetCompositor(bool avoid_backing_store_cache=false, bool use_present_layers_callback=false)
UniqueEngine InitializeEngine() const
void SetGLPopulateExistingDamageCallback(GLPopulateExistingDamageCallback callback)
FlutterRendererConfig & GetRendererConfig()
A task runner that we expect the embedder to provide but whose implementation is a real FML task runn...
static TaskSourceGrade GetCurrentTaskSourceGrade()
virtual void PostTask(const fml::closure &task) override
FlutterEngineResult FlutterEngineRunTask(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterTask *task)
Inform the engine to run the specified task. This task has been given to the embedder via the Flutter...
FlutterEngineResult FlutterEngineSendWindowMetricsEvent(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterWindowMetricsEvent *flutter_metrics)
FlutterEngineResult FlutterEnginePostDartObject(FLUTTER_API_SYMBOL(FlutterEngine) engine, FlutterEngineDartPort port, const FlutterEngineDartObject *object)
Posts a Dart object to specified send port. The corresponding receive port for send port can be in an...
FLUTTER_EXPORT FlutterEngineResult FlutterEngineDeinitialize(FLUTTER_API_SYMBOL(FlutterEngine) engine)
Stops running the Flutter engine instance. After this call, the embedder is also guaranteed that no m...
FlutterEngineResult FlutterEngineShutdown(FLUTTER_API_SYMBOL(FlutterEngine) engine)
Shuts down a Flutter engine instance. The engine handle is no longer valid for any calls in the embed...
FlutterEngineResult FlutterEngineNotifyDisplayUpdate(FLUTTER_API_SYMBOL(FlutterEngine) raw_engine, const FlutterEngineDisplaysUpdateType update_type, const FlutterEngineDisplay *embedder_displays, size_t display_count)
Posts updates corresponding to display changes to a running engine instance.
FlutterEngineResult FlutterEngineRunInitialized(FLUTTER_API_SYMBOL(FlutterEngine) engine)
Runs an initialized engine instance. An engine can be initialized via FlutterEngineInitialize....
@ kFlutterLayerContentTypePlatformView
Indicates that the contents of this layer are determined by the embedder.
@ kFlutterLayerContentTypeBackingStore
@ kFlutterPlatformViewMutationTypeClipRoundedRect
@ kFlutterPlatformViewMutationTypeClipRect
@ kFlutterPlatformViewMutationTypeTransformation
@ kFlutterPlatformViewMutationTypeOpacity
@ kFlutterEngineDartObjectTypeString
@ kFlutterEngineDartObjectTypeBool
@ kFlutterEngineDartObjectTypeDouble
@ kFlutterEngineDartObjectTypeInt32
@ kFlutterEngineDartObjectTypeBuffer
@ kFlutterEngineDartObjectTypeInt64
@ kFlutterEngineDartObjectTypeNull
@ kFlutterEngineDisplaysUpdateTypeStartup
int64_t FlutterEngineDartPort
@ kFlutterOpenGLTargetTypeFramebuffer
@ kFlutterOpenGLTargetTypeSurface
@ kFlutterOpenGLTargetTypeTexture
@ kFlutterBackingStoreTypeSoftware
Specified an software allocation for Flutter to render into using the CPU.
@ kFlutterBackingStoreTypeOpenGL
flutter::DlMatrix DlMatrixMake(const FlutterTransformation &xformation)
FlutterSize FlutterSizeMake(double width, double height)
FlutterRect FlutterRectMake(const SkRect &rect)
FlutterRect FlutterRectMakeLTRB(double l, double t, double r, double b)
FlutterPoint FlutterPointMake(double x, double y)
FlutterTransformation FlutterTransformationMake(const flutter::DlMatrix &matrix)
SkRect SkRectMake(const FlutterRect &rect)
flutter::EmbedderEngine * ToEmbedderEngine(const FlutterEngine &engine)
FlutterRoundedRect FlutterRoundedRectMake(const SkRRect &rect)
const FlutterLayer size_t layers_count
const FlutterLayer ** layers
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
uint32_t uint32_t * format
G_BEGIN_DECLS FlutterViewId view_id
FlutterDesktopBinaryReply callback
#define FML_CHECK(condition)
TEST_F(DisplayListTest, Defaults)
sk_sp< SkSurface > CreateRenderSurface(const FlutterLayer &layer, GrDirectContext *context)
bool MemsetPatternSetOrCheck(uint8_t *buffer, size_t size, MemsetPatternOp op)
Depending on the operation, either scribbles a known pattern into the buffer or checks if that patter...
void FilterMutationsByType(const FlutterPlatformViewMutation **mutations, size_t count, FlutterPlatformViewMutationType type, const std::function< void(const FlutterPlatformViewMutation &mutation)> &handler)
@ kMemsetPatternOpSetBuffer
bool ImageMatchesFixture(const std::string &fixture_file_name, const sk_sp< SkImage > &scene_image, int allowable_different_pixels)
void ConfigureBackingStore(FlutterBackingStore &backing_store, EmbedderTestContextType backend, bool opengl_framebuffer)
Configures per-backend properties for a given backing store.
INSTANTIATE_TEST_SUITE_P(EmbedderTestGlVk, EmbedderTestMultiBackend, ::testing::Values(EmbedderTestContextType::kOpenGLContext, EmbedderTestContextType::kVulkanContext))
TEST_P(DlGoldenTest, TextBlurMaskFilterRespectCTM)
std::string FixtureNameForBackend(EmbedderTestContextType backend, const std::string &name)
Prepends a prefix to the name which is unique to the test context type. This is useful for tests that...
EmbedderTestBackingStoreProducer::RenderTargetType GetRenderTargetFromBackend(EmbedderTestContextType backend, bool opengl_framebuffer)
Resolves a render target type for a given backend description. This is useful for tests that use Embe...
DlMatrix GetTotalMutationTransformationMatrix(const FlutterPlatformViewMutation **mutations, size_t count)
impeller::ISize32 DlISize
impeller::Degrees DlDegrees
DEF_SWITCHES_START aot vmservice shared library name
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set profile Make the profiler discard new samples once the profiler sample buffer is full When this flag is not the profiler sample buffer is used as a ring buffer
Dart_Handle ToDart(const T &object)
Dart_Handle DartInvoke(Dart_Handle closure, std::initializer_list< Dart_Handle > args)
impeller::ShaderType type
FlutterBackingStoreType type
Specifies the type of backing store.
FlutterOpenGLBackingStore open_gl
The description of the OpenGL backing store.
FlutterSoftwareBackingStore software
The description of the software backing store.
size_t struct_size
The size of this struct. Must be sizeof(FlutterBackingStore).
size_t struct_size
The size of this struct. Must be sizeof(FlutterBackingStorePresentInfo).
A structure to represent a damage region.
size_t num_rects
The number of rectangles within the damage region.
FlutterRect * damage
The actual damage region(s) in question.
FlutterEngineDartObjectType type
size_t struct_size
The size of this struct. Must be sizeof(FlutterEngineDisplay).
FlutterEngineDisplayId display_id
FlutterUIntSize size
The size of the surface that will be backed by the fbo.
FlutterLayerContentType type
const FlutterBackingStore * backing_store
FlutterBackingStorePresentInfo * backing_store_present_info
const FlutterPlatformView * platform_view
size_t struct_size
This size of this struct. Must be sizeof(FlutterLayer).
FlutterSize size
The size of the layer (in physical pixels).
FlutterOpenGLTargetType type
UIntFrameInfoCallback fbo_with_frame_info_callback
uint32_t fbo_id
Id of the fbo backing the surface that was presented.
FlutterDamage frame_damage
Damage representing the area that the compositor needs to render.
FlutterDamage buffer_damage
Damage used to set the buffer's damage region.
A structure to represent a rectangle.
A region represented by a collection of non-overlapping rectangles.
size_t struct_size
The size of this struct. Must be sizeof(FlutterRegion).
FlutterOpenGLRendererConfig open_gl
size_t row_bytes
The number of bytes in a single row of the allocation.
size_t height
The number of rows in the allocation.
size_t struct_size
The size of this struct. Must be sizeof(FlutterWindowMetricsEvent).
static constexpr Matrix MakeTranslation(const Vector3 &t)
static Matrix MakeRotationZ(Radians r)
static constexpr Matrix MakeScale(const Vector3 &s)
static constexpr TRect MakeWH(Type width, Type height)
static constexpr TRect MakeXYWH(Type x, Type y, Type width, Type height)
constexpr TRect TransformAndClipBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle, clipped against the near clippin...
static constexpr TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
#define CREATE_NATIVE_ENTRY(native_entry)