5#define FML_USED_ON_EMBEDDER
48#include "gmock/gmock.h"
51#include "third_party/rapidjson/include/rapidjson/writer.h"
52#include "third_party/skia/include/codec/SkCodecAnimation.h"
53#include "third_party/skia/include/gpu/ganesh/mock/GrMockTypes.h"
56#ifdef SHELL_ENABLE_VULKAN
69using ::testing::Return;
73std::unique_ptr<PlatformMessage> MakePlatformMessage(
75 const std::map<std::string, std::string>& values,
77 rapidjson::Document document;
78 auto&
allocator = document.GetAllocator();
81 for (
const auto& pair : values) {
82 rapidjson::Value
key(pair.first.c_str(), strlen(pair.first.c_str()),
84 rapidjson::Value
value(pair.second.c_str(), strlen(pair.second.c_str()),
89 rapidjson::StringBuffer buffer;
90 rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
91 document.Accept(writer);
92 const uint8_t*
data =
reinterpret_cast<const uint8_t*
>(buffer.GetString());
94 std::unique_ptr<PlatformMessage>
message = std::make_unique<PlatformMessage>(
99class MockPlatformViewDelegate :
public PlatformView::Delegate {
101 OnPlatformViewCreated,
102 (std::unique_ptr<Surface>
surface),
105 MOCK_METHOD(
void, OnPlatformViewDestroyed, (), (
override));
107 MOCK_METHOD(
void, OnPlatformViewScheduleFrame, (), (
override));
110 OnPlatformViewAddView,
112 const ViewportMetrics& viewport_metrics,
117 OnPlatformViewRemoveView,
122 OnPlatformViewSendViewFocusEvent,
123 (
const ViewFocusEvent& event),
127 OnPlatformViewSetNextFrameCallback,
132 OnPlatformViewSetViewportMetrics,
133 (int64_t
view_id,
const ViewportMetrics& metrics),
137 OnPlatformViewDispatchPlatformMessage,
138 (std::unique_ptr<PlatformMessage>
message),
142 OnPlatformViewDispatchPointerDataPacket,
143 (std::unique_ptr<PointerDataPacket> packet),
146 MOCK_METHOD(HitTestResponse,
147 OnPlatformViewHitTest,
152 OnPlatformViewDispatchSemanticsAction,
160 OnPlatformViewSetSemanticsEnabled,
165 OnPlatformViewSetAccessibilityFeatures,
170 OnPlatformViewRegisterTexture,
171 (std::shared_ptr<Texture>
texture),
175 OnPlatformViewUnregisterTexture,
180 OnPlatformViewMarkTextureFrameAvailable,
184 MOCK_METHOD(
const Settings&,
185 OnPlatformViewGetSettings,
191 (intptr_t loading_unit_id,
192 std::unique_ptr<const fml::Mapping> snapshot_data,
193 std::unique_ptr<const fml::Mapping> snapshot_instructions),
197 LoadDartDeferredLibraryError,
198 (intptr_t loading_unit_id,
199 const std::string error_message,
204 UpdateAssetResolverByType,
205 (std::unique_ptr<AssetResolver> updated_asset_resolver,
212 MOCK_METHOD(
bool, IsValid, (), (
override));
214 MOCK_METHOD(std::unique_ptr<SurfaceFrame>,
219 MOCK_METHOD(
DlMatrix, GetRootTransformation, (), (
const,
override));
221 MOCK_METHOD(GrDirectContext*, GetContext, (), (
override));
223 MOCK_METHOD(std::unique_ptr<GLContextResult>,
224 MakeRenderContextCurrent,
228 MOCK_METHOD(
bool, ClearRenderContext, (), (
override));
234 const TaskRunners& task_runners)
235 : PlatformView(delegate, task_runners) {}
236 MOCK_METHOD(std::unique_ptr<Surface>, CreateRenderingSurface, (), (
override));
237 MOCK_METHOD(std::shared_ptr<PlatformMessageHandler>,
238 GetPlatformMessageHandler,
243class TestPlatformView :
public PlatformView {
245 TestPlatformView(Shell& shell,
const TaskRunners& task_runners)
246 : PlatformView(shell, task_runners) {}
247 MOCK_METHOD(std::unique_ptr<Surface>, CreateRenderingSurface, (), (
override));
248 MOCK_METHOD(
void, ReleaseResourceContext, (), (
const,
override));
254 HandlePlatformMessage,
255 (std::unique_ptr<PlatformMessage>
message),
258 DoesHandlePlatformMessageOnPlatformThread,
263 (
int response_id, std::unique_ptr<fml::Mapping> mapping),
276 MOCK_METHOD(
void, Complete, (std::unique_ptr<fml::Mapping>
data), (
override));
277 MOCK_METHOD(
void, CompleteEmpty, (), (
override));
284 : valid_(valid), type_(
type) {}
286 bool IsValid()
const override {
return true; }
294 const std::string& asset_name)
const override {
299 const std::string& asset_pattern,
300 const std::optional<std::string>& subdir)
const override {
305 return this == &other;
316 std::shared_ptr<fml::ConcurrentMessageLoop> concurrent_loop)
317 : concurrent_loop_(
std::move(concurrent_loop)) {}
320 bool IsValid()
const override {
return true; }
332 const std::string& asset_name)
const override {
333 if (asset_name ==
"FontManifest.json" ||
334 asset_name ==
"NativeAssetsManifest.json") {
339 EXPECT_TRUE(concurrent_loop_->RunsTasksOnCurrentThread())
347 return this == &other;
351 std::shared_ptr<fml::ConcurrentMessageLoop> concurrent_loop_;
369 shell->GetPlatformView()->NotifyDestroyed();
380 bool is_torn_down =
false;
383 [shell, &latch, &is_torn_down]() {
384 is_torn_down = shell->GetRasterizer()->IsTornDown();
392 ASSERT_TRUE(shell !=
nullptr);
404 std::string flags_string = flags[0];
405 for (
size_t i = 1;
i < flags.size(); ++
i) {
407 flags_string += flags[
i];
414 const std::vector<fml::CommandLine::Option> options = {
418 EXPECT_EQ(settings.
dart_flags.size(), flags.size());
419 for (
size_t i = 0;
i < flags.size(); ++
i) {
438 return builder.
Build();
443 Settings settings = CreateSettingsForFixture();
444 TaskRunners task_runners(
"test",
nullptr,
nullptr,
nullptr,
nullptr);
445 auto shell = CreateShell(settings, task_runners);
452 Settings settings = CreateSettingsForFixture();
463 auto shell = CreateShell(settings, task_runners);
466 DestroyShell(std::move(shell), task_runners);
472 Settings settings = CreateSettingsForFixture();
476 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
478 auto shell = CreateShell(settings, task_runners);
481 DestroyShell(std::move(shell), task_runners);
487 Settings settings = CreateSettingsForFixture();
490 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
492 auto shell = CreateShell(settings, task_runners);
495 DestroyShell(std::move(shell), task_runners);
500 InitializeWithMultipleThreadButCallingThreadAsPlatformThread) {
502 Settings settings = CreateSettingsForFixture();
517 const auto vsync_clock = std::make_shared<ShellTestVsyncClock>();
522 return static_cast<std::unique_ptr<VsyncWaiter>>(
523 std::make_unique<VsyncWaiterFallback>(task_runners));
527 [](
Shell& shell) {
return std::make_unique<Rasterizer>(shell); });
530 DestroyShell(std::move(shell), task_runners);
536 Settings settings = CreateSettingsForFixture();
540 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
542 auto shell = CreateShell({
543 .settings = settings,
544 .task_runners = task_runners,
545 .is_gpu_disabled =
true,
550 bool is_disabled =
false;
551 shell->GetIsGpuDisabledSyncSwitch()->Execute(
553 ASSERT_TRUE(is_disabled);
555 DestroyShell(std::move(shell), task_runners);
561 Settings settings = CreateSettingsForFixture();
572 auto shell = CreateShell(settings, task_runners);
575 DestroyShell(std::move(shell), task_runners);
581 auto settings = CreateSettingsForFixture();
582 auto shell = CreateShell(settings);
586 ASSERT_TRUE(configuration.IsValid());
587 configuration.SetEntrypoint(
"fixturesAreFunctionalMain");
591 "SayHiFromFixturesAreFunctionalMain",
594 RunEngine(shell.get(), std::move(configuration));
597 DestroyShell(std::move(shell));
603 auto settings = CreateSettingsForFixture();
604 auto task_runner = CreateNewThread();
605 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
608 auto shell = CreateShell(settings, task_runners);
612 ASSERT_TRUE(configuration.IsValid());
614 configuration.SetEntrypoint(
"hitTestInsidePlatformViewMain");
615 RunEngine(shell.get(), std::move(configuration));
619 task_runner->PostTask([&shell, &latch]() {
626 HitTestResponse response = shell->GetPlatformView()->HitTest(0, {0.0, 0.0});
632 DestroyShell(std::move(shell), task_runners);
637 auto settings = CreateSettingsForFixture();
638 auto task_runner = CreateNewThread();
639 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
642 auto shell = CreateShell(settings, task_runners);
646 ASSERT_TRUE(configuration.IsValid());
648 configuration.SetEntrypoint(
"hitTestOutsidePlatformViewMain");
649 RunEngine(shell.get(), std::move(configuration));
653 task_runner->PostTask([&shell, &latch]() {
660 HitTestResponse response = shell->GetPlatformView()->HitTest(0, {0.0, 0.0});
666 DestroyShell(std::move(shell), task_runners);
671 auto settings = CreateSettingsForFixture();
672 auto shell = CreateShell(settings);
676 ASSERT_TRUE(configuration.IsValid());
677 configuration.SetEntrypoint(
"testCanLaunchSecondaryIsolate");
684 RunEngine(shell.get(), std::move(configuration));
689 DestroyShell(std::move(shell));
695 auto settings = CreateSettingsForFixture();
696 auto shell = CreateShell(settings);
700 ASSERT_TRUE(configuration.IsValid());
701 std::string entry_point =
"fixturesAreFunctionalMain";
702 configuration.SetEntrypoint(entry_point);
705 std::string last_entry_point;
708 last_entry_point = shell->GetEngine()->GetLastEntrypoint();
712 RunEngine(shell.get(), std::move(configuration));
714 EXPECT_EQ(entry_point, last_entry_point);
716 DestroyShell(std::move(shell));
722 auto settings = CreateSettingsForFixture();
723 auto shell = CreateShell(settings);
727 ASSERT_TRUE(configuration.IsValid());
728 std::string entry_point =
"fixturesAreFunctionalMain";
729 std::vector<std::string> entry_point_args = {
"arg1"};
730 configuration.SetEntrypoint(entry_point);
731 configuration.SetEntrypointArgs(entry_point_args);
734 std::vector<std::string> last_entry_point_args;
737 last_entry_point_args = shell->GetEngine()->GetLastEntrypointArgs();
741 RunEngine(shell.get(), std::move(configuration));
743#if (FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG)
744 EXPECT_EQ(last_entry_point_args, entry_point_args);
746 ASSERT_TRUE(last_entry_point_args.empty());
749 DestroyShell(std::move(shell));
754#if defined(OS_FUCHSIA)
755 GTEST_SKIP() <<
"This test flakes on Fuchsia. https://fxbug.dev/110006 ";
759 ::testing::FLAGS_gtest_death_test_style =
"threadsafe";
761 const std::vector<fml::CommandLine::Option> options = {
766 const char* expected =
767 "Encountered disallowed Dart VM flag: --verify_after_gc";
773 std::vector<const char*> flags = {
774 "--enable-isolate-groups",
775 "--no-enable-isolate-groups",
778 flags.push_back(
"--max_profile_depth 1");
779 flags.push_back(
"--random_seed 42");
780 flags.push_back(
"--max_subtype_cache_entries=22");
782 flags.push_back(
"--enable_mirrors");
790 auto settings = CreateSettingsForFixture();
791 std::unique_ptr<Shell> shell = CreateShell(settings);
794 PlatformViewNotifyCreated(shell.get());
797 configuration.SetEntrypoint(
"emptyMain");
799 RunEngine(shell.get(), std::move(configuration));
800 PumpOneFrame(shell.get());
801 ASSERT_FALSE(GetNeedsReportTimings(shell.get()));
813 ASSERT_EQ(UnreportedTimingsCount(shell.get()), 0);
814 DestroyShell(std::move(shell));
818 auto settings = CreateSettingsForFixture();
819 std::unique_ptr<Shell> shell = CreateShell(settings);
822 PlatformViewNotifyCreated(shell.get());
825 configuration.SetEntrypoint(
"dummyReportTimingsMain");
827 RunEngine(shell.get(), std::move(configuration));
828 PumpOneFrame(shell.get());
829 ASSERT_TRUE(GetNeedsReportTimings(shell.get()));
830 DestroyShell(std::move(shell));
837 for (
size_t i = 0;
i < timings.size();
i += 1) {
850 ASSERT_TRUE(timings[
i].Get(phase) >=
start);
851 ASSERT_TRUE(timings[
i].Get(phase) <= finish);
854 ASSERT_TRUE(last_phase_time <= timings[
i].Get(phase));
855 last_phase_time = timings[
i].Get(phase);
861 auto settings = CreateSettingsForFixture();
862 std::unique_ptr<Shell> shell = CreateShell(settings);
870 PlatformViewNotifyCreated(shell.get());
873 ASSERT_TRUE(configuration.IsValid());
874 configuration.SetEntrypoint(
"reportTimingsMain");
876 std::vector<int64_t> timestamps;
877 auto nativeTimingCallback = [&reportLatch,
878 ×tamps](Dart_NativeArguments
args) {
879 Dart_Handle exception =
nullptr;
880 ASSERT_EQ(timestamps.size(), 0ul);
885 AddNativeCallback(
"NativeReportTimingsCallback",
887 RunEngine(shell.get(), std::move(configuration));
891 for (
int i = 0;
i < 200;
i += 1) {
892 PumpOneFrame(shell.get());
896 DestroyShell(std::move(shell));
899 ASSERT_TRUE(!timestamps.empty());
915 auto settings = CreateSettingsForFixture();
919 settings.frame_rasterized_callback = [&timing,
925 std::unique_ptr<Shell> shell = CreateShell(settings);
928 using namespace std::chrono_literals;
929 std::this_thread::sleep_for(1ms);
940 ASSERT_TRUE(timing.
Get(phase) <
start);
944 PlatformViewNotifyCreated(shell.get());
947 configuration.SetEntrypoint(
"onBeginFrameMain");
949 int64_t frame_target_time;
950 auto nativeOnBeginFrame = [&frame_target_time](Dart_NativeArguments
args) {
951 Dart_Handle exception =
nullptr;
955 AddNativeCallback(
"NativeOnBeginFrame",
958 RunEngine(shell.get(), std::move(configuration));
959 PumpOneFrame(shell.get());
965 std::vector<FrameTiming> timings = {timing};
970 int64_t build_start =
972 ASSERT_GT(frame_target_time, build_start);
973 DestroyShell(std::move(shell));
977 auto settings = CreateSettingsForFixture();
979 bool end_frame_called =
false;
980 auto end_frame_callback =
981 [&](
bool should_resubmit_frame,
983 ASSERT_TRUE(raster_thread_merger.get() ==
nullptr);
984 ASSERT_FALSE(should_resubmit_frame);
985 end_frame_called =
true;
988 auto external_view_embedder = std::make_shared<ShellTestExternalViewEmbedder>(
990 auto shell = CreateShell({
991 .settings = settings,
993 .shell_test_external_view_embedder = external_view_embedder,
998 PlatformViewNotifyCreated(shell.get());
1001 configuration.SetEntrypoint(
"emptyMain");
1003 RunEngine(shell.get(), std::move(configuration));
1005 LayerTreeBuilder builder = [&](
const std::shared_ptr<ContainerLayer>& root) {
1006 auto display_list_layer = std::make_shared<DisplayListLayer>(
1008 root->Add(display_list_layer);
1012 end_frame_latch.
Wait();
1013 ASSERT_TRUE(end_frame_called);
1015 DestroyShell(std::move(shell));
1019#if defined(OS_FUCHSIA)
1020 GTEST_SKIP() <<
"RasterThreadMerger flakes on Fuchsia. "
1021 "https://github.com/flutter/flutter/issues/59816 ";
1024 auto settings = CreateSettingsForFixture();
1026 std::shared_ptr<ShellTestExternalViewEmbedder> external_view_embedder;
1029 bool end_frame_called =
false;
1030 std::vector<int64_t> visited_platform_views;
1033 auto end_frame_callback =
1034 [&](
bool should_resubmit_frame,
1036 if (end_frame_called) {
1039 ASSERT_TRUE(raster_thread_merger.get() ==
nullptr);
1040 ASSERT_FALSE(should_resubmit_frame);
1041 end_frame_called =
true;
1042 visited_platform_views =
1043 external_view_embedder->GetVisitedPlatformViews();
1044 stack_50 = external_view_embedder->GetStack(50);
1045 stack_75 = external_view_embedder->GetStack(75);
1046 end_frame_latch.
Signal();
1049 external_view_embedder = std::make_shared<ShellTestExternalViewEmbedder>(
1051 auto shell = CreateShell({
1052 .settings = settings,
1054 .shell_test_external_view_embedder = external_view_embedder,
1059 PlatformViewNotifyCreated(shell.get());
1062 configuration.SetEntrypoint(
"emptyMain");
1064 RunEngine(shell.get(), std::move(configuration));
1066 LayerTreeBuilder builder = [&](
const std::shared_ptr<ContainerLayer>& root) {
1067 auto platform_view_layer = std::make_shared<PlatformViewLayer>(
1069 root->Add(platform_view_layer);
1070 auto transform_layer = std::make_shared<TransformLayer>(
1072 root->Add(transform_layer);
1073 auto clip_rect_layer = std::make_shared<ClipRectLayer>(
1075 transform_layer->Add(clip_rect_layer);
1077 auto backdrop_filter_layer =
1078 std::make_shared<BackdropFilterLayer>(filter, DlBlendMode::kSrcOver);
1079 clip_rect_layer->Add(backdrop_filter_layer);
1080 auto platform_view_layer2 = std::make_shared<PlatformViewLayer>(
1082 backdrop_filter_layer->Add(platform_view_layer2);
1086 end_frame_latch.
Wait();
1087 ASSERT_EQ(visited_platform_views, (std::vector<int64_t>{50, 75}));
1092 auto mutator = *stack_50.
Begin();
1094 ASSERT_EQ(mutator->GetFilterMutation().GetFilter(), *filter);
1097 ASSERT_EQ(mutator->GetFilterMutation().GetFilterRect(),
1100 DestroyShell(std::move(shell));
1106 ExternalEmbedderEndFrameIsCalledWhenPostPrerollResultIsResubmit) {
1107#if defined(OS_FUCHSIA)
1108 GTEST_SKIP() <<
"RasterThreadMerger flakes on Fuchsia. "
1109 "https://github.com/flutter/flutter/issues/59816 ";
1112 auto settings = CreateSettingsForFixture();
1114 bool end_frame_called =
false;
1115 auto end_frame_callback =
1116 [&](
bool should_resubmit_frame,
1118 ASSERT_TRUE(raster_thread_merger.get() !=
nullptr);
1119 ASSERT_TRUE(should_resubmit_frame);
1120 end_frame_called =
true;
1121 end_frame_latch.
Signal();
1123 auto external_view_embedder = std::make_shared<ShellTestExternalViewEmbedder>(
1125 auto shell = CreateShell({
1126 .settings = settings,
1128 .shell_test_external_view_embedder = external_view_embedder,
1133 PlatformViewNotifyCreated(shell.get());
1136 configuration.SetEntrypoint(
"emptyMain");
1138 RunEngine(shell.get(), std::move(configuration));
1140 LayerTreeBuilder builder = [&](
const std::shared_ptr<ContainerLayer>& root) {
1141 auto display_list_layer = std::make_shared<DisplayListLayer>(
1143 root->Add(display_list_layer);
1147 end_frame_latch.
Wait();
1149 ASSERT_TRUE(end_frame_called);
1151 DestroyShell(std::move(shell));
1156#if defined(OS_FUCHSIA)
1157 GTEST_SKIP() <<
"RasterThreadMerger flakes on Fuchsia. "
1158 "https://github.com/flutter/flutter/issues/59816 ";
1161 auto settings = CreateSettingsForFixture();
1163 auto end_frame_callback =
1164 [&](
bool should_resubmit_frame,
1166 raster_thread_merger = std::move(thread_merger);
1168 auto external_view_embedder = std::make_shared<ShellTestExternalViewEmbedder>(
1171 auto shell = CreateShell({
1172 .settings = settings,
1174 .shell_test_external_view_embedder = external_view_embedder,
1179 PlatformViewNotifyCreated(shell.get());
1182 configuration.SetEntrypoint(
"emptyMain");
1184 RunEngine(shell.get(), std::move(configuration));
1186 LayerTreeBuilder builder = [&](
const std::shared_ptr<ContainerLayer>& root) {
1187 auto display_list_layer = std::make_shared<DisplayListLayer>(
1189 root->Add(display_list_layer);
1197 PostSync(shell->GetTaskRunners().GetRasterTaskRunner(), [] {});
1198 ASSERT_TRUE(result.ok()) <<
"Result: " <<
static_cast<int>(result.code())
1199 <<
": " << result.message();
1201 ASSERT_TRUE(raster_thread_merger->IsEnabled());
1204 ASSERT_TRUE(raster_thread_merger->IsEnabled());
1208 ASSERT_TRUE(raster_thread_merger->IsEnabled());
1209 DestroyShell(std::move(shell));
1214#if defined(OS_FUCHSIA)
1215 GTEST_SKIP() <<
"RasterThreadMerger flakes on Fuchsia. "
1216 "https://github.com/flutter/flutter/issues/59816 ";
1219 const int ThreadMergingLease = 10;
1220 auto settings = CreateSettingsForFixture();
1222 std::shared_ptr<ShellTestExternalViewEmbedder> external_view_embedder;
1224 auto end_frame_callback =
1225 [&](
bool should_resubmit_frame,
1227 if (should_resubmit_frame && !raster_thread_merger->IsMerged()) {
1228 raster_thread_merger->MergeWithLease(ThreadMergingLease);
1230 ASSERT_TRUE(raster_thread_merger->IsMerged());
1231 external_view_embedder->UpdatePostPrerollResult(
1234 end_frame_latch.
Signal();
1236 external_view_embedder = std::make_shared<ShellTestExternalViewEmbedder>(
1239 external_view_embedder->UpdatePostPrerollResult(
1241 auto shell = CreateShell({
1242 .settings = settings,
1244 .shell_test_external_view_embedder = external_view_embedder,
1249 PlatformViewNotifyCreated(shell.get());
1252 configuration.SetEntrypoint(
"emptyMain");
1254 RunEngine(shell.get(), std::move(configuration));
1256 LayerTreeBuilder builder = [&](
const std::shared_ptr<ContainerLayer>& root) {
1257 auto display_list_layer = std::make_shared<DisplayListLayer>(
1259 root->Add(display_list_layer);
1264 end_frame_latch.
Wait();
1271 shell->GetTaskRunners().GetRasterTaskRunner()->GetTaskQueueId(),
1272 shell->GetTaskRunners().GetPlatformTaskRunner()->GetTaskQueueId()));
1277 shell->GetTaskRunners().GetRasterTaskRunner()->GetTaskQueueId(),
1278 shell->GetTaskRunners().GetPlatformTaskRunner()->GetTaskQueueId()));
1283 DestroyShell(std::move(shell));
1288#if defined(OS_FUCHSIA)
1289 GTEST_SKIP() <<
"RasterThreadMerger flakes on Fuchsia. "
1290 "https://github.com/flutter/flutter/issues/59816 ";
1293 const int kThreadMergingLease = 10;
1294 auto settings = CreateSettingsForFixture();
1296 auto end_frame_callback =
1297 [&](
bool should_resubmit_frame,
1299 if (should_resubmit_frame && !raster_thread_merger->IsMerged()) {
1300 raster_thread_merger->MergeWithLease(kThreadMergingLease);
1302 end_frame_latch.
Signal();
1307 auto external_view_embedder = std::make_shared<ShellTestExternalViewEmbedder>(
1310 auto shell = CreateShell({
1311 .settings = settings,
1313 .shell_test_external_view_embedder = external_view_embedder,
1318 PlatformViewNotifyCreated(shell.get());
1321 configuration.SetEntrypoint(
"emptyMain");
1323 RunEngine(shell.get(), std::move(configuration));
1325 LayerTreeBuilder builder = [&](
const std::shared_ptr<ContainerLayer>& root) {
1326 auto display_list_layer = std::make_shared<DisplayListLayer>(
1328 root->Add(display_list_layer);
1333 end_frame_latch.
Wait();
1335 shell->GetTaskRunners().GetRasterTaskRunner()->GetTaskQueueId(),
1336 shell->GetTaskRunners().GetPlatformTaskRunner()->GetTaskQueueId()));
1340 external_view_embedder->UpdatePostPrerollResult(
1352 shell->GetTaskRunners().GetRasterTaskRunner()->GetTaskQueueId(),
1353 shell->GetTaskRunners().GetPlatformTaskRunner()->GetTaskQueueId()));
1358 DestroyShell(std::move(shell));
1363 OnPlatformViewDestroyWithThreadMergerWhileThreadsAreUnmerged) {
1364#if defined(OS_FUCHSIA)
1365 GTEST_SKIP() <<
"RasterThreadMerger flakes on Fuchsia. "
1366 "https://github.com/flutter/flutter/issues/59816 ";
1369 auto settings = CreateSettingsForFixture();
1371 auto end_frame_callback =
1372 [&](
bool should_resubmit_frame,
1374 end_frame_latch.
Signal();
1376 auto external_view_embedder = std::make_shared<ShellTestExternalViewEmbedder>(
1378 auto shell = CreateShell({
1379 .settings = settings,
1381 .shell_test_external_view_embedder = external_view_embedder,
1386 PlatformViewNotifyCreated(shell.get());
1389 configuration.SetEntrypoint(
"emptyMain");
1391 RunEngine(shell.get(), std::move(configuration));
1393 LayerTreeBuilder builder = [&](
const std::shared_ptr<ContainerLayer>& root) {
1394 auto display_list_layer = std::make_shared<DisplayListLayer>(
1396 root->Add(display_list_layer);
1399 end_frame_latch.
Wait();
1403 shell->GetTaskRunners().GetRasterTaskRunner()->GetTaskQueueId(),
1404 shell->GetTaskRunners().GetPlatformTaskRunner()->GetTaskQueueId()));
1409 shell->GetTaskRunners().GetRasterTaskRunner()->GetTaskQueueId(),
1410 shell->GetTaskRunners().GetPlatformTaskRunner()->GetTaskQueueId()));
1415 DestroyShell(std::move(shell));
1420 auto settings = CreateSettingsForFixture();
1422 auto shell = CreateShell(settings);
1425 PlatformViewNotifyCreated(shell.get());
1428 configuration.SetEntrypoint(
"emptyMain");
1430 RunEngine(shell.get(), std::move(configuration));
1432 LayerTreeBuilder builder = [&](
const std::shared_ptr<ContainerLayer>& root) {
1433 auto display_list_layer = std::make_shared<DisplayListLayer>(
1435 root->Add(display_list_layer);
1441 shell->GetTaskRunners().GetRasterTaskRunner()->GetTaskQueueId(),
1442 shell->GetTaskRunners().GetPlatformTaskRunner()->GetTaskQueueId()));
1447 shell->GetTaskRunners().GetRasterTaskRunner()->GetTaskQueueId(),
1448 shell->GetTaskRunners().GetPlatformTaskRunner()->GetTaskQueueId()));
1453 DestroyShell(std::move(shell));
1458#if defined(OS_FUCHSIA)
1459 GTEST_SKIP() <<
"RasterThreadMerger flakes on Fuchsia. "
1460 "https://github.com/flutter/flutter/issues/59816 ";
1463 auto settings = CreateSettingsForFixture();
1465 auto end_frame_callback =
1466 [&](
bool should_resubmit_frame,
1468 end_frame_latch.
Signal();
1470 auto external_view_embedder = std::make_shared<ShellTestExternalViewEmbedder>(
1482 auto shell = CreateShell({
1483 .settings = settings,
1484 .task_runners = task_runners,
1486 .shell_test_external_view_embedder = external_view_embedder,
1491 PlatformViewNotifyCreated(shell.get());
1494 configuration.SetEntrypoint(
"emptyMain");
1496 RunEngine(shell.get(), std::move(configuration));
1498 LayerTreeBuilder builder = [&](
const std::shared_ptr<ContainerLayer>& root) {
1499 auto display_list_layer = std::make_shared<DisplayListLayer>(
1501 root->Add(display_list_layer);
1504 end_frame_latch.
Wait();
1511 DestroyShell(std::move(shell), task_runners);
1516 auto settings = CreateSettingsForFixture();
1518 std::shared_ptr<ShellTestExternalViewEmbedder> external_view_embedder;
1519 bool used_this_frame =
true;
1520 auto end_frame_callback =
1521 [&](
bool should_resubmit_frame,
1524 used_this_frame = external_view_embedder->GetUsedThisFrame();
1525 end_frame_latch.
Signal();
1527 external_view_embedder = std::make_shared<ShellTestExternalViewEmbedder>(
1529 auto shell = CreateShell({
1530 .settings = settings,
1532 .shell_test_external_view_embedder = external_view_embedder,
1537 PlatformViewNotifyCreated(shell.get());
1540 configuration.SetEntrypoint(
"emptyMain");
1542 RunEngine(shell.get(), std::move(configuration));
1544 LayerTreeBuilder builder = [&](
const std::shared_ptr<ContainerLayer>& root) {
1545 auto display_list_layer = std::make_shared<DisplayListLayer>(
1547 root->Add(display_list_layer);
1550 end_frame_latch.
Wait();
1551 ASSERT_FALSE(used_this_frame);
1556 DestroyShell(std::move(shell));
1562#if defined(OS_FUCHSIA)
1563 GTEST_SKIP() <<
"RasterThreadMerger flakes on Fuchsia. "
1564 "https://github.com/flutter/flutter/issues/59816 ";
1567 auto settings = CreateSettingsForFixture();
1569 std::shared_ptr<ShellTestExternalViewEmbedder> external_view_embedder;
1571 auto end_frame_callback =
1572 [&](
bool should_resubmit_frame,
1574 if (should_resubmit_frame && !raster_thread_merger->IsMerged()) {
1575 raster_thread_merger->MergeWithLease(10);
1576 external_view_embedder->UpdatePostPrerollResult(
1579 end_frame_latch.
Signal();
1581 external_view_embedder = std::make_shared<ShellTestExternalViewEmbedder>(
1584 auto shell = CreateShell({
1585 .settings = settings,
1587 .shell_test_external_view_embedder = external_view_embedder,
1591 PlatformViewNotifyCreated(shell.get());
1594 configuration.SetEntrypoint(
"emptyMain");
1595 RunEngine(shell.get(), std::move(configuration));
1597 ASSERT_EQ(0, external_view_embedder->GetSubmittedFrameCount());
1599 PumpOneFrame(shell.get());
1602 end_frame_latch.
Wait();
1606 end_frame_latch.
Wait();
1609 ASSERT_EQ(1, external_view_embedder->GetSubmittedFrameCount());
1611 PlatformViewNotifyDestroyed(shell.get());
1612 DestroyShell(std::move(shell));
1616TEST(SettingsTest, FrameTimingSetsAndGetsProperly) {
1621 int lastPhaseIndex = -1;
1624 ASSERT_TRUE(phase > lastPhaseIndex);
1625 lastPhaseIndex = phase;
1628 timing.
Set(phase, fake_time);
1629 ASSERT_TRUE(timing.
Get(phase) == fake_time);
1634 auto settings = CreateSettingsForFixture();
1635 std::unique_ptr<Shell> shell = CreateShell(settings);
1638 PlatformViewNotifyCreated(shell.get());
1641 ASSERT_TRUE(configuration.IsValid());
1642 configuration.SetEntrypoint(
"reportTimingsMain");
1644 std::vector<int64_t> timestamps;
1645 auto nativeTimingCallback = [&reportLatch,
1646 ×tamps](Dart_NativeArguments
args) {
1647 Dart_Handle exception =
nullptr;
1648 ASSERT_EQ(timestamps.size(), 0ul);
1650 args, 0, exception);
1653 AddNativeCallback(
"NativeReportTimingsCallback",
1655 ASSERT_TRUE(configuration.IsValid());
1656 RunEngine(shell.get(), std::move(configuration));
1658 for (
int i = 0;
i < 10;
i += 1) {
1659 PumpOneFrame(shell.get());
1663 DestroyShell(std::move(shell));
1671 auto settings = CreateSettingsForFixture();
1672 std::unique_ptr<Shell> shell = CreateShell(settings);
1675 PlatformViewNotifyCreated(shell.get());
1678 configuration.SetEntrypoint(
"emptyMain");
1680 RunEngine(shell.get(), std::move(configuration));
1681 PumpOneFrame(shell.get());
1683 ASSERT_TRUE(result.
ok());
1685 DestroyShell(std::move(shell));
1689 auto settings = CreateSettingsForFixture();
1690 std::unique_ptr<Shell> shell = CreateShell(settings);
1693 PlatformViewNotifyCreated(shell.get());
1696 configuration.SetEntrypoint(
"emptyMain");
1698 RunEngine(shell.get(), std::move(configuration));
1701 EXPECT_FALSE(result.
ok());
1702 EXPECT_EQ(result.
message(),
"timeout");
1705 DestroyShell(std::move(shell));
1709 auto settings = CreateSettingsForFixture();
1710 std::unique_ptr<Shell> shell = CreateShell(settings);
1713 PlatformViewNotifyCreated(shell.get());
1716 configuration.SetEntrypoint(
"emptyMain");
1718 RunEngine(shell.get(), std::move(configuration));
1720 ASSERT_FALSE(result.
ok());
1723 DestroyShell(std::move(shell));
1727 auto settings = CreateSettingsForFixture();
1728 std::unique_ptr<Shell> shell = CreateShell(settings);
1731 PlatformViewNotifyCreated(shell.get());
1734 configuration.SetEntrypoint(
"emptyMain");
1736 RunEngine(shell.get(), std::move(configuration));
1737 PumpOneFrame(shell.get());
1739 ASSERT_TRUE(result.
ok());
1740 for (
int i = 0;
i < 100; ++
i) {
1742 ASSERT_TRUE(result.
ok());
1745 DestroyShell(std::move(shell));
1751 Settings settings = CreateSettingsForFixture();
1752 auto task_runner = CreateNewThread();
1753 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
1755 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
1758 PlatformViewNotifyCreated(shell.get());
1761 configuration.SetEntrypoint(
"emptyMain");
1763 RunEngine(shell.get(), std::move(configuration));
1764 PumpOneFrame(shell.get());
1766 task_runner->PostTask([&shell, &event] {
1768 ASSERT_FALSE(result.
ok());
1774 DestroyShell(std::move(shell), task_runners);
1782 if (auto rasterizer = shell.GetRasterizer()) {
1783 bytes = rasterizer->GetResourceCacheMaxBytes().value_or(0U);
1793 auto settings = CreateSettingsForFixture();
1794 settings.resource_cache_max_bytes_threshold = 4000000U;
1795 GrMockOptions main_context_options;
1796 sk_sp<GrDirectContext> main_context =
1797 GrDirectContext::MakeMock(&main_context_options);
1800 auto result = std::make_unique<TestPlatformView>(shell, task_runners);
1801 ON_CALL(*result, CreateRenderingSurface())
1802 .WillByDefault([main_context] {
1803 auto surface = std::make_unique<MockSurface>();
1804 ON_CALL(*
surface, GetContext())
1805 .WillByDefault(Return(main_context.get()));
1806 ON_CALL(*
surface, IsValid()).WillByDefault(Return(
true));
1807 ON_CALL(*
surface, MakeRenderContextCurrent()).WillByDefault([] {
1808 return std::make_unique<GLContextDefaultResult>(
true);
1815 auto shell = CreateShell({
1816 .settings = settings,
1817 .task_runners = task_runners,
1818 .platform_view_create_callback = platform_view_create_callback,
1822 PlatformViewNotifyCreated(shell.get());
1825 configuration.SetEntrypoint(
"emptyMain");
1827 RunEngine(shell.get(), std::move(configuration));
1828 PostSync(shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell]() {
1829 shell->GetPlatformView()->SetViewportMetrics(kImplicitViewId,
1830 {1.0, 100, 100, 22, 0});
1834 EXPECT_EQ(GetRasterizerResourceCacheBytesSync(*shell),
1835 static_cast<size_t>(480000U));
1837 auto shell_spawn_callback = [&]() {
1838 std::unique_ptr<Shell> spawn;
1840 shell->GetTaskRunners().GetPlatformTaskRunner(),
1841 [
this, &spawn, &spawner = shell, platform_view_create_callback]() {
1842 auto configuration =
1843 RunConfiguration::InferFromSettings(CreateSettingsForFixture());
1844 configuration.SetEntrypoint(
"emptyMain");
1845 spawn = spawner->Spawn(
1846 std::move(configuration),
"", platform_view_create_callback,
1847 [](Shell& shell) { return std::make_unique<Rasterizer>(shell); });
1848 ASSERT_NE(
nullptr, spawn.get());
1849 ASSERT_TRUE(ValidateShell(spawn.get()));
1854 std::unique_ptr<Shell> second_shell = shell_spawn_callback();
1855 PlatformViewNotifyCreated(second_shell.get());
1856 PostSync(second_shell->GetTaskRunners().GetPlatformTaskRunner(),
1858 second_shell->GetPlatformView()->SetViewportMetrics(
1859 kImplicitViewId, {1.0, 100, 100, 22, 0});
1863 static_cast<size_t>(960000U));
1865 PostSync(second_shell->GetTaskRunners().GetPlatformTaskRunner(),
1867 second_shell->GetPlatformView()->SetViewportMetrics(
1868 kImplicitViewId, {1.0, 100, 300, 22, 0});
1872 static_cast<size_t>(1920000U));
1874 std::unique_ptr<Shell> third_shell = shell_spawn_callback();
1875 PlatformViewNotifyCreated(third_shell.get());
1876 PostSync(third_shell->GetTaskRunners().GetPlatformTaskRunner(),
1878 third_shell->GetPlatformView()->SetViewportMetrics(
1879 kImplicitViewId, {1.0, 400, 100, 22, 0});
1883 static_cast<size_t>(3840000U));
1885 PostSync(third_shell->GetTaskRunners().GetPlatformTaskRunner(),
1887 third_shell->GetPlatformView()->SetViewportMetrics(
1888 kImplicitViewId, {1.0, 800, 100, 22, 0});
1892 static_cast<size_t>(4000000U));
1893 DestroyShell(std::move(third_shell), task_runners);
1896 static_cast<size_t>(4000000U));
1898 PostSync(second_shell->GetTaskRunners().GetPlatformTaskRunner(),
1900 second_shell->GetPlatformView()->SetViewportMetrics(
1901 kImplicitViewId, {1.0, 100, 100, 22, 0});
1905 static_cast<size_t>(960000U));
1907 DestroyShell(std::move(second_shell), task_runners);
1908 DestroyShell(std::move(shell), task_runners);
1912 Settings settings = CreateSettingsForFixture();
1913 auto task_runner = CreateNewThread();
1914 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
1916 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
1919 PlatformViewNotifyCreated(shell.get());
1921 auto configuration = RunConfiguration::InferFromSettings(settings);
1922 configuration.SetEntrypoint(
"emptyMain");
1924 RunEngine(shell.get(), std::move(configuration));
1925 PumpOneFrame(shell.get());
1932#if defined(SHELL_ENABLE_VULKAN) && !defined(SHELL_ENABLE_GL)
1935#elif defined(SHELL_ENABLE_METAL)
1937 static_cast<size_t>(256 * (1 << 20)));
1940 static_cast<size_t>(24 * (1 << 20)));
1944 shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell]() {
1945 shell->GetPlatformView()->SetViewportMetrics(kImplicitViewId,
1946 {1.0, 400, 200, 22, 0});
1948 PumpOneFrame(shell.get());
1950 EXPECT_EQ(GetRasterizerResourceCacheBytesSync(*shell), 3840000U);
1952 std::string request_json = R
"json({
1953 "method": "Skia.setResourceCacheMaxBytes",
1958 auto platform_message = std::make_unique<PlatformMessage>(
1959 "flutter/skia", std::move(data),
nullptr);
1960 SendEnginePlatformMessage(shell.get(), std::move(platform_message));
1961 PumpOneFrame(shell.get());
1962 EXPECT_EQ(GetRasterizerResourceCacheBytesSync(*shell), 10000U);
1965 shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell]() {
1966 shell->GetPlatformView()->SetViewportMetrics(kImplicitViewId,
1967 {1.0, 800, 400, 22, 0});
1969 PumpOneFrame(shell.get());
1971 EXPECT_EQ(GetRasterizerResourceCacheBytesSync(*shell), 10000U);
1972 DestroyShell(std::move(shell), task_runners);
1976 Settings settings = CreateSettingsForFixture();
1977 auto task_runner = CreateNewThread();
1978 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
1980 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
1983 shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell]() {
1984 shell->GetPlatformView()->SetViewportMetrics(kImplicitViewId,
1985 {1.0, 400, 200, 22, 0});
1987 PumpOneFrame(shell.get());
1990 PlatformViewNotifyCreated(shell.get());
1992 auto configuration = RunConfiguration::InferFromSettings(settings);
1993 configuration.SetEntrypoint(
"emptyMain");
1995 RunEngine(shell.get(), std::move(configuration));
1996 PumpOneFrame(shell.get());
1998 EXPECT_EQ(GetRasterizerResourceCacheBytesSync(*shell),
1999 static_cast<size_t>(3840000U));
2000 DestroyShell(std::move(shell), task_runners);
2004 Settings settings = CreateSettingsForFixture();
2005 auto task_runner = CreateNewThread();
2006 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
2008 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
2011 shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell]() {
2012 shell->GetPlatformView()->SetViewportMetrics(kImplicitViewId,
2013 {1.0, 400, 200, 22, 0});
2015 PumpOneFrame(shell.get());
2018 PlatformViewNotifyCreated(shell.get());
2020 auto configuration = RunConfiguration::InferFromSettings(settings);
2021 configuration.SetEntrypoint(
"testSkiaResourceCacheSendsResponse");
2023 EXPECT_EQ(GetRasterizerResourceCacheBytesSync(*shell),
2024 static_cast<size_t>(3840000U));
2031 RunEngine(shell.get(), std::move(configuration));
2032 PumpOneFrame(shell.get());
2036 EXPECT_EQ(GetRasterizerResourceCacheBytesSync(*shell),
2037 static_cast<size_t>(10000U));
2038 DestroyShell(std::move(shell), task_runners);
2042 Settings settings = CreateSettingsForFixture();
2043 auto task_runner = CreateNewThread();
2045 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
2048 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
2051 PlatformViewNotifyCreated(shell.get());
2053 auto configuration = RunConfiguration::InferFromSettings(settings);
2054 configuration.SetEntrypoint(
"canCreateImageFromDecompressedData");
2057 AddNativeCallback(
"NotifyWidthHeight",
2060 Dart_GetNativeArgument(
args, 0));
2062 Dart_GetNativeArgument(
args, 1));
2063 ASSERT_EQ(
width, 10);
2068 RunEngine(shell.get(), std::move(configuration));
2071 DestroyShell(std::move(shell), task_runners);
2074class MockTexture :
public Texture {
2077 std::shared_ptr<fml::AutoResetWaitableEvent> latch)
2078 :
Texture(textureId), latch_(
std::move(latch)) {}
2093 frames_available_++;
2098 unregistered_ =
true;
2106 bool unregistered_ =
false;
2107 int frames_available_ = 0;
2108 std::shared_ptr<fml::AutoResetWaitableEvent> latch_;
2112 Settings settings = CreateSettingsForFixture();
2113 auto configuration = RunConfiguration::InferFromSettings(settings);
2114 auto task_runner = CreateNewThread();
2115 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
2117 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
2120 PlatformViewNotifyCreated(shell.get());
2122 RunEngine(shell.get(), std::move(configuration));
2124 std::shared_ptr<fml::AutoResetWaitableEvent> latch =
2125 std::make_shared<fml::AutoResetWaitableEvent>();
2127 std::shared_ptr<MockTexture> mockTexture =
2128 std::make_shared<MockTexture>(0, latch);
2131 shell->GetTaskRunners().GetRasterTaskRunner(), [&]() {
2132 shell->GetPlatformView()->RegisterTexture(mockTexture);
2133 shell->GetPlatformView()->MarkTextureFrameAvailable(0);
2137 EXPECT_EQ(mockTexture->frames_available(), 1);
2140 shell->GetTaskRunners().GetRasterTaskRunner(),
2141 [&]() { shell->GetPlatformView()->UnregisterTexture(0); });
2144 EXPECT_EQ(mockTexture->unregistered(),
true);
2145 DestroyShell(std::move(shell), task_runners);
2149 const std::string
message =
"dummy isolate launch data.";
2151 Settings settings = CreateSettingsForFixture();
2153 std::make_shared<fml::DataMapping>(
message);
2155 GetCurrentTaskRunner(),
2162 AddNativeCallback(
"NotifyMessage",
2164 const auto message_from_dart =
2166 Dart_GetNativeArgument(
args, 0));
2167 ASSERT_EQ(
message, message_from_dart);
2171 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
2173 ASSERT_TRUE(shell->IsSetup());
2174 auto configuration = RunConfiguration::InferFromSettings(settings);
2175 configuration.SetEntrypoint(
"canAccessIsolateLaunchData");
2178 shell->RunEngine(std::move(configuration), [&](
auto result) {
2179 ASSERT_EQ(result, Engine::RunStatus::Success);
2182 message_latch.
Wait();
2183 DestroyShell(std::move(shell), task_runners);
2187 Settings settings = CreateSettingsForFixture();
2194 AddNativeCallback(
"NativeOnBeginFrame",
2198 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
2199 ASSERT_TRUE(shell->IsSetup());
2201 auto configuration = RunConfiguration::InferFromSettings(settings);
2202 configuration.SetEntrypoint(
"onBeginFrameWithNotifyNativeMain");
2203 RunEngine(shell.get(), std::move(configuration));
2209 shell->GetTaskRunners().GetPlatformTaskRunner(),
2210 [&shell]() { shell->GetPlatformView()->ScheduleFrame(); });
2212 DestroyShell(std::move(shell), task_runners);
2216 bool is_on_begin_frame_called =
false;
2217 bool is_secondary_callback_called =
false;
2218 bool test_started =
false;
2219 Settings settings = CreateSettingsForFixture();
2226 AddNativeCallback(
"NativeOnBeginFrame",
2228 if (!test_started) {
2231 EXPECT_FALSE(is_on_begin_frame_called);
2232 EXPECT_FALSE(is_secondary_callback_called);
2233 is_on_begin_frame_called =
true;
2236 std::unique_ptr<Shell> shell = CreateShell({
2237 .settings = settings,
2238 .task_runners = task_runners,
2240 ASSERT_TRUE(shell->IsSetup());
2242 auto configuration = RunConfiguration::InferFromSettings(settings);
2243 configuration.SetEntrypoint(
"onBeginFrameWithNotifyNativeMain");
2244 RunEngine(shell.get(), std::move(configuration));
2250 shell->GetTaskRunners().GetUITaskRunner(), [&]() {
2251 shell->GetEngine()->ScheduleSecondaryVsyncCallback(0, [&]() {
2252 if (!test_started) {
2255 EXPECT_TRUE(is_on_begin_frame_called);
2256 EXPECT_FALSE(is_secondary_callback_called);
2257 is_secondary_callback_called = true;
2258 count_down_latch.CountDown();
2260 shell->GetEngine()->ScheduleFrame();
2261 test_started =
true;
2263 count_down_latch.Wait();
2264 EXPECT_TRUE(is_on_begin_frame_called);
2265 EXPECT_TRUE(is_secondary_callback_called);
2266 DestroyShell(std::move(shell), task_runners);
2269static void LogSkData(
const sk_sp<SkData>& data,
const char* title) {
2270 FML_LOG(ERROR) <<
"---------- " << title;
2271 std::ostringstream ostr;
2272 for (
size_t i = 0;
i <
data->size();) {
2273 ostr << std::hex << std::setfill(
'0') << std::setw(2)
2274 <<
static_cast<int>(
data->bytes()[
i]) <<
" ";
2276 if (
i % 16 == 0 ||
i ==
data->size()) {
2285 auto settings = CreateSettingsForFixture();
2287 settings.frame_rasterized_callback =
2290 std::unique_ptr<Shell> shell = CreateShell(settings);
2293 PlatformViewNotifyCreated(shell.get());
2295 auto configuration = RunConfiguration::InferFromSettings(settings);
2296 configuration.SetEntrypoint(
"emptyMain");
2298 RunEngine(shell.get(), std::move(configuration));
2300 LayerTreeBuilder builder = [&](
const std::shared_ptr<ContainerLayer>& root) {
2301 auto display_list_layer = std::make_shared<DisplayListLayer>(
2303 root->Add(display_list_layer);
2306 PumpOneFrame(shell.get(), ViewContent::ImplicitView(100, 100, builder));
2307 firstFrameLatch.
Wait();
2309 std::promise<Rasterizer::Screenshot> screenshot_promise;
2310 auto screenshot_future = screenshot_promise.get_future();
2313 shell->GetTaskRunners().GetRasterTaskRunner(),
2314 [&screenshot_promise, &shell]() {
2315 auto rasterizer = shell->GetRasterizer();
2316 screenshot_promise.set_value(rasterizer->ScreenshotLastLayerTree(
2317 Rasterizer::ScreenshotType::CompressedImage, false));
2324 fixtures_dir,
"shelltest_screenshot.png");
2328 sk_sp<SkData> reference_data = SkData::MakeWithoutCopy(
2329 reference_png->GetMapping(), reference_png->GetSize());
2331 sk_sp<SkData> screenshot_data = screenshot_future.get().data;
2332 if (!reference_data->equals(screenshot_data.get())) {
2334 LogSkData(screenshot_data,
"screenshot");
2338 DestroyShell(std::move(shell));
2349 std::string dart_isolate_time_str;
2354 dart_isolate_time_str =
2356 Dart_GetNativeArgument(
args, 0));
2360 auto settings = CreateSettingsForFixture();
2361 auto configuration = RunConfiguration::InferFromSettings(settings);
2362 configuration.SetEntrypoint(
"localtimesMatch");
2363 std::unique_ptr<Shell> shell = CreateShell(settings);
2364 ASSERT_NE(shell.get(),
nullptr);
2365 RunEngine(shell.get(), std::move(configuration));
2369 const time_t timestamp = time(
nullptr);
2370 const struct tm* local_time = localtime(×tamp);
2371 ASSERT_NE(local_time,
nullptr)
2372 <<
"Could not get local time: errno=" << errno <<
": " << strerror(errno);
2374 const size_t format_size =
2375 strftime(timestr,
sizeof(timestr),
"%Y-%m-%d %H", local_time);
2376 ASSERT_NE(format_size, 0UL)
2377 <<
"strftime failed: host time: " << std::string(timestr)
2378 <<
" dart isolate time: " << dart_isolate_time_str;
2380 const std::string host_local_time_str = timestr;
2382 ASSERT_EQ(dart_isolate_time_str, host_local_time_str)
2383 <<
"Local times in the dart isolate and the local time seen by the test "
2384 <<
"differ by more than 1 hour, but are expected to be about equal";
2386 DestroyShell(std::move(shell));
2393 : info_(SkImageInfo::MakeN32(1, 1, SkAlphaType::kOpaque_SkAlphaType)) {};
2402 return {std::nullopt, 0, SkCodecAnimation::DisposalMethod::kKeep};
2406 return SkISize::Make(info_.width(), info_.height());
2412 unsigned int frame_index,
2413 std::optional<unsigned int> prior_frame) {
2414 assert(info.width() == 1);
2415 assert(info.height() == 1);
2416 assert(row_bytes == 4);
2418 reinterpret_cast<uint32_t*
>(pixels)[0] = 0x00ff00ff;
2430 Dart_GetNativeArgument(
args, 0));
2432 Dart_GetNativeArgument(
args, 1));
2433 ASSERT_EQ(
width, 1);
2438 auto settings = CreateSettingsForFixture();
2439 auto configuration = RunConfiguration::InferFromSettings(settings);
2440 configuration.SetEntrypoint(
"canRegisterImageDecoders");
2441 std::unique_ptr<Shell> shell = CreateShell(settings);
2442 ASSERT_NE(shell.get(),
nullptr);
2445 shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell]() {
2446 shell->RegisterImageDecoder(
2447 [](const sk_sp<SkData>& buffer) {
2448 return std::make_unique<SinglePixelImageGenerator>();
2453 RunEngine(shell.get(), std::move(configuration));
2455 DestroyShell(std::move(shell));
2461 PersistentCache::SetCacheDirectoryPath(base_dir.
path());
2462 PersistentCache::ResetCacheForProcess();
2466 std::vector<std::string> components = {
2468 PersistentCache::kSkSLSubdirName};
2471 const std::string x_key_str =
"A";
2472 const std::string x_value_str =
"x";
2473 sk_sp<SkData> x_key =
2474 SkData::MakeWithCopy(x_key_str.data(), x_key_str.size());
2475 sk_sp<SkData> x_value =
2476 SkData::MakeWithCopy(x_value_str.data(), x_value_str.size());
2477 auto x_data = PersistentCache::BuildCacheObject(*x_key, *x_value);
2479 const std::string y_key_str =
"B";
2480 const std::string y_value_str =
"y";
2481 sk_sp<SkData> y_key =
2482 SkData::MakeWithCopy(y_key_str.data(), y_key_str.size());
2483 sk_sp<SkData> y_value =
2484 SkData::MakeWithCopy(y_value_str.data(), y_value_str.size());
2485 auto y_data = PersistentCache::BuildCacheObject(*y_key, *y_value);
2490 Settings settings = CreateSettingsForFixture();
2491 std::unique_ptr<Shell> shell = CreateShell(settings);
2493 rapidjson::Document document;
2494 OnServiceProtocol(shell.get(), ServiceProtocolEnum::kGetSkSLs,
2495 shell->GetTaskRunners().GetIOTaskRunner(), empty_params,
2497 rapidjson::StringBuffer
buffer;
2498 rapidjson::Writer<rapidjson::StringBuffer> writer(
buffer);
2499 document.Accept(writer);
2500 DestroyShell(std::move(shell));
2502 const std::string expected_json1 =
2503 "{\"type\":\"GetSkSLs\",\"SkSLs\":{\"II\":\"eQ==\",\"IE\":\"eA==\"}}";
2504 const std::string expected_json2 =
2505 "{\"type\":\"GetSkSLs\",\"SkSLs\":{\"IE\":\"eA==\",\"II\":\"eQ==\"}}";
2506 bool json_is_expected = (expected_json1 ==
buffer.GetString()) ||
2507 (expected_json2 ==
buffer.GetString());
2508 ASSERT_TRUE(json_is_expected) <<
buffer.GetString() <<
" is not equal to "
2509 << expected_json1 <<
" or " << expected_json2;
2513 Settings settings = CreateSettingsForFixture();
2514 auto configuration = RunConfiguration::InferFromSettings(settings);
2515 auto task_runner = CreateNewThread();
2516 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
2518 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
2521 PlatformViewNotifyCreated(shell.get());
2523 RunEngine(shell.get(), std::move(configuration));
2525 auto latch = std::make_shared<fml::AutoResetWaitableEvent>();
2527 PumpOneFrame(shell.get());
2530 shell->GetTaskRunners().GetRasterTaskRunner(), [&shell, &latch]() {
2531 Rasterizer::Screenshot screenshot =
2532 shell->GetRasterizer()->ScreenshotLastLayerTree(
2533 Rasterizer::ScreenshotType::CompressedImage, true);
2534 EXPECT_NE(screenshot.data, nullptr);
2539 DestroyShell(std::move(shell), task_runners);
2543 Settings settings = CreateSettingsForFixture();
2544 auto configuration = RunConfiguration::InferFromSettings(settings);
2545 auto task_runner = CreateNewThread();
2546 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
2548 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
2551 PlatformViewNotifyCreated(shell.get());
2553 RunEngine(shell.get(), std::move(configuration));
2555 auto latch = std::make_shared<fml::AutoResetWaitableEvent>();
2557 PumpOneFrame(shell.get());
2560 shell->GetTaskRunners().GetRasterTaskRunner(), [&shell, &latch]() {
2561 SnapshotDelegate* delegate =
2562 reinterpret_cast<Rasterizer*>(shell->GetRasterizer().get());
2563 sk_sp<SkImage> image = delegate->MakeSkiaSnapshotSync(
2564 MakeSizedDisplayList(50, 50), DlISize(50, 50),
2565 SnapshotPixelFormat::kDontCare);
2566 EXPECT_NE(image, nullptr);
2571 DestroyShell(std::move(shell), task_runners);
2575 Settings settings = CreateSettingsForFixture();
2576 std::unique_ptr<Shell> shell = CreateShell(settings);
2580 auto display_list_layer = std::make_shared<DisplayListLayer>(
2582 display_list_layer->set_paint_bounds(DlRect::MakeWH(100, 100));
2585 std::promise<bool> rasterized;
2587 shell->GetTaskRunners().GetRasterTaskRunner()->PostTask(
2588 [&shell, &rasterized, &display_list, &display_list_layer] {
2589 std::vector<RasterCacheItem*> raster_cache_items;
2590 auto* compositor_context = shell->GetRasterizer()->compositor_context();
2591 auto& raster_cache = compositor_context->raster_cache();
2600 .gr_context =
nullptr,
2601 .dst_color_space =
nullptr,
2602 .view_embedder =
nullptr,
2603 .raster_time = raster_time,
2605 .texture_registry =
nullptr,
2606 .raster_cache = &raster_cache,
2612 .raster_cache = &raster_cache,
2614 .view_embedder =
nullptr,
2615 .state_stack = state_stack,
2616 .dst_color_space =
nullptr,
2617 .surface_needs_readback =
false,
2618 .raster_time = raster_time,
2620 .texture_registry =
nullptr,
2621 .has_platform_view =
false,
2622 .has_texture_layer =
false,
2623 .raster_cached_entries = &raster_cache_items,
2631 bool picture_cache_generated;
2633 display_list, SkPoint(),
true,
false);
2634 for (
int i = 0;
i < 4;
i += 1) {
2637 display_list_raster_cache_item.
PrerollSetup(&preroll_context, matrix);
2640 picture_cache_generated =
2644 display_list_raster_cache_item.
Draw(paint_context, &dummy_canvas,
2647 ASSERT_TRUE(picture_cache_generated);
2656 layer_raster_cache_item.
Draw(paint_context, &dummy_canvas, &paint);
2657 rasterized.set_value(
true);
2659 rasterized.get_future().wait();
2663 rapidjson::Document document;
2665 shell.get(), ServiceProtocolEnum::kEstimateRasterCacheMemory,
2666 shell->GetTaskRunners().GetRasterTaskRunner(), empty_params, &document);
2667 rapidjson::StringBuffer
buffer;
2668 rapidjson::Writer<rapidjson::StringBuffer> writer(
buffer);
2669 document.Accept(writer);
2670 std::string expected_json =
2671 "{\"type\":\"EstimateRasterCacheMemory\",\"layerBytes\":40024,\"picture"
2673 std::string actual_json =
buffer.GetString();
2674 ASSERT_EQ(actual_json, expected_json);
2676 DestroyShell(std::move(shell));
2684 auto settings = CreateSettingsForFixture();
2690 auto end_frame_callback =
2691 [&](
bool should_merge_thread,
2693 end_frame_latch.
Signal();
2695 auto external_view_embedder = std::make_shared<ShellTestExternalViewEmbedder>(
2696 std::move(end_frame_callback), PostPrerollResult::kSuccess,
false);
2697 std::unique_ptr<Shell> shell = CreateShell({
2698 .settings = settings,
2700 .shell_test_external_view_embedder = external_view_embedder,
2705 PlatformViewNotifyCreated(shell.get());
2708 shell->GetTaskRunners().GetPlatformTaskRunner(),
2709 [&shell, &expected_size]() {
2710 shell->GetPlatformView()->SetViewportMetrics(
2712 {1.0, static_cast<double>(expected_size.width),
2713 static_cast<double>(expected_size.height), 22, 0});
2716 auto configuration = RunConfiguration::InferFromSettings(settings);
2717 configuration.SetEntrypoint(
"emptyMain");
2719 RunEngine(shell.get(), std::move(configuration));
2721 PumpOneFrame(shell.get(),
2722 ViewContent::DummyView(
static_cast<double>(wrong_size.width),
2723 static_cast<double>(wrong_size.height)));
2724 end_frame_latch.Wait();
2726 ASSERT_EQ(0, external_view_embedder->GetSubmittedFrameCount());
2728 PumpOneFrame(shell.get(), ViewContent::DummyView(
2729 static_cast<double>(expected_size.width),
2730 static_cast<double>(expected_size.height)));
2731 end_frame_latch.Wait();
2733 ASSERT_EQ(1, external_view_embedder->GetSubmittedFrameCount());
2734 ASSERT_EQ(expected_size, external_view_embedder->GetLastSubmittedFrameSize());
2736 PlatformViewNotifyDestroyed(shell.get());
2737 DestroyShell(std::move(shell));
2745 auto settings = CreateSettingsForFixture();
2754 std::shared_ptr<ShellTestExternalViewEmbedder> external_view_embedder;
2756 auto end_frame_callback =
2757 [&](
bool should_merge_thread,
2759 if (!raster_thread_merger_ref) {
2760 raster_thread_merger_ref = raster_thread_merger;
2762 if (should_merge_thread) {
2763 raster_thread_merger->MergeWithLease(10);
2764 external_view_embedder->UpdatePostPrerollResult(
2765 PostPrerollResult::kSuccess);
2767 end_frame_latch.
Signal();
2769 if (should_merge_thread) {
2770 resize_latch.
Wait();
2774 external_view_embedder = std::make_shared<ShellTestExternalViewEmbedder>(
2775 std::move(end_frame_callback), PostPrerollResult::kResubmitFrame,
true);
2777 std::unique_ptr<Shell> shell = CreateShell({
2778 .settings = settings,
2780 .shell_test_external_view_embedder = external_view_embedder,
2785 PlatformViewNotifyCreated(shell.get());
2788 shell->GetTaskRunners().GetPlatformTaskRunner(),
2789 [&shell, &origin_size]() {
2790 shell->GetPlatformView()->SetViewportMetrics(
2791 kImplicitViewId, {1.0, static_cast<double>(origin_size.width),
2792 static_cast<double>(origin_size.height), 22, 0});
2795 auto configuration = RunConfiguration::InferFromSettings(settings);
2796 configuration.SetEntrypoint(
"emptyMain");
2798 RunEngine(shell.get(), std::move(configuration));
2800 PumpOneFrame(shell.get(),
2801 ViewContent::DummyView(
static_cast<double>(origin_size.width),
2802 static_cast<double>(origin_size.height)));
2804 end_frame_latch.Wait();
2805 ASSERT_EQ(0, external_view_embedder->GetSubmittedFrameCount());
2808 shell->GetTaskRunners().GetPlatformTaskRunner(),
2809 [&shell, &new_size, &resize_latch]() {
2810 shell->GetPlatformView()->SetViewportMetrics(
2811 kImplicitViewId, {1.0, static_cast<double>(new_size.width),
2812 static_cast<double>(new_size.height), 22, 0});
2813 resize_latch.Signal();
2816 end_frame_latch.Wait();
2820 ASSERT_EQ(0, external_view_embedder->GetSubmittedFrameCount());
2823 PumpOneFrame(shell.get(),
2824 ViewContent::DummyView(
static_cast<double>(new_size.width),
2825 static_cast<double>(new_size.height)));
2827 end_frame_latch.Wait();
2828 ASSERT_TRUE(raster_thread_merger_ref->IsMerged());
2829 ASSERT_EQ(1, external_view_embedder->GetSubmittedFrameCount());
2830 ASSERT_EQ(new_size, external_view_embedder->GetLastSubmittedFrameSize());
2832 PlatformViewNotifyDestroyed(shell.get());
2833 DestroyShell(std::move(shell));
2838 double last_device_pixel_ratio;
2841 auto native_report_device_pixel_ratio = [&](Dart_NativeArguments
args) {
2842 auto dpr_handle = Dart_GetNativeArgument(
args, 0);
2843 ASSERT_TRUE(Dart_IsDouble(dpr_handle));
2844 Dart_DoubleValue(dpr_handle, &last_device_pixel_ratio);
2845 ASSERT_FALSE(last_device_pixel_ratio == 0.0);
2847 auto width_handle = Dart_GetNativeArgument(
args, 1);
2848 ASSERT_TRUE(Dart_IsDouble(width_handle));
2849 Dart_DoubleValue(width_handle, &last_width);
2850 ASSERT_FALSE(last_width == 0.0);
2852 auto height_handle = Dart_GetNativeArgument(
args, 2);
2853 ASSERT_TRUE(Dart_IsDouble(height_handle));
2854 Dart_DoubleValue(height_handle, &last_height);
2855 ASSERT_FALSE(last_height == 0.0);
2860 Settings settings = CreateSettingsForFixture();
2861 auto task_runner = CreateNewThread();
2862 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
2865 AddNativeCallback(
"ReportMetrics",
2868 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
2870 auto configuration = RunConfiguration::InferFromSettings(settings);
2871 configuration.SetEntrypoint(
"reportMetrics");
2873 RunEngine(shell.get(), std::move(configuration));
2875 task_runner->PostTask([&]() {
2878 {0.0, 400, 200, 22, 0});
2879 task_runner->PostTask([&]() {
2882 {0.8, 0.0, 200, 22, 0});
2883 task_runner->PostTask([&]() {
2886 {0.8, 400, 0.0, 22, 0});
2887 task_runner->PostTask([&]() {
2889 shell->GetPlatformView()->SetViewportMetrics(
2896 ASSERT_EQ(last_device_pixel_ratio, 0.8);
2897 ASSERT_EQ(last_width, 400.0);
2898 ASSERT_EQ(last_height, 200.0);
2901 task_runner->PostTask([&]() {
2903 {1.2, 600, 300, 22, 0});
2906 ASSERT_EQ(last_device_pixel_ratio, 1.2);
2907 ASSERT_EQ(last_width, 600.0);
2908 ASSERT_EQ(last_height, 300.0);
2910 DestroyShell(std::move(shell), task_runners);
2915 double last_device_pixel_ratio;
2917 auto native_report_device_pixel_ratio = [&](Dart_NativeArguments
args) {
2919 auto dpr_handle = Dart_GetNativeArgument(
args, 0);
2920 ASSERT_TRUE(Dart_IsDouble(dpr_handle));
2921 Dart_DoubleValue(dpr_handle, &last_device_pixel_ratio);
2922 ASSERT_TRUE(last_device_pixel_ratio > 2.5);
2927 Settings settings = CreateSettingsForFixture();
2928 auto task_runner = CreateNewThread();
2929 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
2932 AddNativeCallback(
"ReportMetrics",
2935 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
2937 auto configuration = RunConfiguration::InferFromSettings(settings);
2938 configuration.SetEntrypoint(
"reportMetrics");
2940 RunEngine(shell.get(), std::move(configuration));
2942 task_runner->PostTask([&]() {
2945 shell->GetPlatformView()->SetViewportMetrics(2, {2.0, 400, 200, 22, 0});
2946 task_runner->PostTask([&]() {
2949 {3.0, 400, 200, 22, 0});
2953 ASSERT_EQ(last_device_pixel_ratio, 3.0);
2956 DestroyShell(std::move(shell), task_runners);
2960 Settings settings = CreateSettingsForFixture();
2961 std::unique_ptr<Shell> shell = CreateShell(settings);
2963 RunConfiguration::InferFromSettings(settings);
2964 configuration.
SetEntrypoint(
"canAccessResourceFromAssetDir");
2971 bool can_access_resource =
false;
2972 auto native_can_access_resource = [&can_access_resource,
2973 &latch](Dart_NativeArguments
args) {
2974 Dart_Handle exception =
nullptr;
2975 can_access_resource =
2979 AddNativeCallback(
"NotifyCanAccessResource",
2984 auto native_notify_set_asset_bundle_path =
2985 [&shell](Dart_NativeArguments
args) {
2988 params[
"assetDirectory"] =
"assetDirectory";
2989 rapidjson::Document document;
2990 OnServiceProtocol(shell.get(), ServiceProtocolEnum::kSetAssetBundlePath,
2991 shell->GetTaskRunners().GetUITaskRunner(),
params,
2993 rapidjson::StringBuffer
buffer;
2994 rapidjson::Writer<rapidjson::StringBuffer> writer(
buffer);
2995 document.Accept(writer);
2997 AddNativeCallback(
"NotifySetAssetBundlePath",
3000 RunEngine(shell.get(), std::move(configuration));
3003 ASSERT_TRUE(can_access_resource);
3005 DestroyShell(std::move(shell));
3009 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
3012 auto vm_settings = CreateSettingsForFixture();
3013 auto vm_ref = DartVMRef::Create(vm_settings);
3014 ASSERT_TRUE(DartVMRef::IsInstanceRunning());
3016 auto settings = vm_settings;
3018 settings.root_isolate_create_callback = [&](
const auto& isolate) {
3019 isolate_create_latch.
Signal();
3021 auto shell = CreateShell(settings);
3023 auto configuration = RunConfiguration::InferFromSettings(settings);
3024 ASSERT_TRUE(configuration.IsValid());
3025 RunEngine(shell.get(), std::move(configuration));
3026 ASSERT_TRUE(DartVMRef::IsInstanceRunning());
3027 DestroyShell(std::move(shell));
3028 isolate_create_latch.
Wait();
3036 std::string filename =
"test_name";
3037 std::string
content =
"test_content";
3041 ASSERT_TRUE(success);
3045 std::make_unique<DirectoryAssetBundle>(std::move(asset_dir_fd),
false));
3048 ASSERT_TRUE(mapping !=
nullptr);
3050 std::string result(
reinterpret_cast<const char*
>(mapping->GetMapping()),
3051 mapping->GetSize());
3053 ASSERT_TRUE(result ==
content);
3061 std::vector<std::string> filenames = {
3068 for (
const auto& filename : filenames) {
3071 ASSERT_TRUE(success);
3076 std::make_unique<DirectoryAssetBundle>(std::move(asset_dir_fd),
false));
3078 auto mappings = asset_manager.
GetAsMappings(
"(.*)", std::nullopt);
3079 EXPECT_EQ(mappings.size(), 4u);
3081 std::vector<std::string> expected_results = {
3086 mappings = asset_manager.
GetAsMappings(
"(.*)good(.*)", std::nullopt);
3087 ASSERT_EQ(mappings.size(), expected_results.size());
3089 for (
auto& mapping : mappings) {
3090 std::string result(
reinterpret_cast<const char*
>(mapping->GetMapping()),
3091 mapping->GetSize());
3093 std::find(expected_results.begin(), expected_results.end(), result),
3094 expected_results.end());
3098#if defined(OS_FUCHSIA)
3099TEST_F(ShellTest, AssetManagerMultiSubdir) {
3100 std::string subdir_path =
"subdir";
3109 std::vector<std::string> filenames = {
3115 std::vector<std::string> subdir_filenames = {
3121 for (
auto filename : filenames) {
3124 ASSERT_TRUE(success);
3127 for (
auto filename : subdir_filenames) {
3130 ASSERT_TRUE(success);
3133 AssetManager asset_manager;
3134 asset_manager.PushBack(
3135 std::make_unique<DirectoryAssetBundle>(std::move(asset_dir_fd),
false));
3137 auto mappings = asset_manager.GetAsMappings(
"(.*)", std::nullopt);
3138 EXPECT_EQ(mappings.size(), 5u);
3140 mappings = asset_manager.GetAsMappings(
"(.*)", subdir_path);
3141 EXPECT_EQ(mappings.size(), 3u);
3143 std::vector<std::string> expected_results = {
3148 mappings = asset_manager.GetAsMappings(
"(.*)good(.*)", subdir_path);
3149 ASSERT_EQ(mappings.size(), expected_results.size());
3151 for (
auto& mapping : mappings) {
3152 std::string result(
reinterpret_cast<const char*
>(mapping->GetMapping()),
3153 mapping->GetSize());
3155 std::find(expected_results.begin(), expected_results.end(), result),
3156 expected_results.end());
3162 auto settings = CreateSettingsForFixture();
3163 auto shell = CreateShell(settings);
3166 auto configuration = RunConfiguration::InferFromSettings(settings);
3167 ASSERT_TRUE(configuration.IsValid());
3168 configuration.SetEntrypoint(
"fixturesAreFunctionalMain");
3170 auto second_configuration = RunConfiguration::InferFromSettings(settings);
3171 ASSERT_TRUE(second_configuration.IsValid());
3172 second_configuration.SetEntrypoint(
"testCanLaunchSecondaryIsolate");
3174 const std::string initial_route(
"/foo");
3177 std::string last_entry_point;
3181 last_entry_point = shell->GetEngine()->GetLastEntrypoint();
3193 RunEngine(shell.get(), std::move(configuration));
3195 ASSERT_TRUE(DartVMRef::IsInstanceRunning());
3197 ASSERT_EQ(
"fixturesAreFunctionalMain", last_entry_point);
3200 shell->GetTaskRunners().GetPlatformTaskRunner(),
3201 [
this, &spawner = shell, &second_configuration, &second_latch,
3203 MockPlatformViewDelegate platform_view_delegate;
3204 auto spawn = spawner->Spawn(
3205 std::move(second_configuration), initial_route,
3206 [&platform_view_delegate](Shell& shell) {
3207 auto result = std::make_unique<MockPlatformView>(
3208 platform_view_delegate, shell.GetTaskRunners());
3209 ON_CALL(*result, CreateRenderingSurface()).WillByDefault([] {
3210 return std::make_unique<MockSurface>();
3214 [](
Shell& shell) { return std::make_unique<Rasterizer>(shell); });
3215 ASSERT_NE(
nullptr, spawn.get());
3218 PostSync(spawner->GetTaskRunners().GetUITaskRunner(), [&spawn, &spawner,
3221 ASSERT_EQ(
"testCanLaunchSecondaryIsolate",
3222 spawn->GetEngine()->GetLastEntrypoint());
3223 ASSERT_EQ(initial_route, spawn->GetEngine()->InitialRoute());
3225 ASSERT_NE(spawner->GetEngine()
3226 ->GetRuntimeController()
3227 ->GetRootIsolateGroup(),
3229 ASSERT_EQ(spawner->GetEngine()
3230 ->GetRuntimeController()
3231 ->GetRootIsolateGroup(),
3233 ->GetRuntimeController()
3234 ->GetRootIsolateGroup());
3235 auto spawner_snapshot_delegate = spawner->GetEngine()
3236 ->GetRuntimeController()
3237 ->GetSnapshotDelegate();
3238 auto spawn_snapshot_delegate =
3239 spawn->GetEngine()->GetRuntimeController()->GetSnapshotDelegate();
3240 PostSync(spawner->GetTaskRunners().GetRasterTaskRunner(),
3241 [spawner_snapshot_delegate, spawn_snapshot_delegate] {
3242 ASSERT_NE(spawner_snapshot_delegate.get(),
3243 spawn_snapshot_delegate.get());
3247 spawner->GetTaskRunners().GetIOTaskRunner(), [&spawner, &spawn] {
3248 ASSERT_EQ(spawner->GetIOManager()->GetResourceContext().get(),
3249 spawn->GetIOManager()->GetResourceContext().get());
3254 second_latch.Wait();
3256 DestroyShell(std::move(spawn));
3259 DestroyShell(std::move(shell));
3260 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
3264 auto settings = CreateSettingsForFixture();
3265 auto shell = CreateShell(settings);
3268 auto configuration = RunConfiguration::InferFromSettings(settings);
3269 ASSERT_TRUE(configuration.IsValid());
3270 configuration.SetEntrypoint(
"canReceiveArgumentsWhenEngineRun");
3271 const std::vector<std::string> entrypoint_args{
"foo",
"bar"};
3272 configuration.SetEntrypointArgs(entrypoint_args);
3274 auto second_configuration = RunConfiguration::InferFromSettings(settings);
3275 ASSERT_TRUE(second_configuration.IsValid());
3276 second_configuration.SetEntrypoint(
"canReceiveArgumentsWhenEngineSpawn");
3277 const std::vector<std::string> second_entrypoint_args{
"arg1",
"arg2"};
3278 second_configuration.SetEntrypointArgs(second_entrypoint_args);
3280 const std::string initial_route(
"/foo");
3283 std::string last_entry_point;
3285 AddNativeCallback(
"NotifyNativeWhenEngineRun",
3288 Dart_GetNativeArgument(
args, 0)));
3290 shell->GetEngine()->GetLastEntrypoint();
3296 AddNativeCallback(
"NotifyNativeWhenEngineSpawn",
3299 Dart_GetNativeArgument(
args, 0)));
3301 shell->GetEngine()->GetLastEntrypoint();
3302 second_latch.Signal();
3305 RunEngine(shell.get(), std::move(configuration));
3307 ASSERT_TRUE(DartVMRef::IsInstanceRunning());
3309 ASSERT_EQ(
"canReceiveArgumentsWhenEngineRun", last_entry_point);
3312 shell->GetTaskRunners().GetPlatformTaskRunner(),
3313 [
this, &spawner = shell, &second_configuration, &second_latch,
3315 MockPlatformViewDelegate platform_view_delegate;
3316 auto spawn = spawner->Spawn(
3317 std::move(second_configuration), initial_route,
3318 [&platform_view_delegate](Shell& shell) {
3319 auto result = std::make_unique<MockPlatformView>(
3320 platform_view_delegate, shell.GetTaskRunners());
3321 ON_CALL(*result, CreateRenderingSurface()).WillByDefault([] {
3322 return std::make_unique<MockSurface>();
3326 [](
Shell& shell) { return std::make_unique<Rasterizer>(shell); });
3327 ASSERT_NE(
nullptr, spawn.get());
3330 PostSync(spawner->GetTaskRunners().GetUITaskRunner(),
3331 [&spawn, &spawner, initial_route] {
3333 ASSERT_EQ(
"canReceiveArgumentsWhenEngineSpawn",
3334 spawn->GetEngine()->GetLastEntrypoint());
3335 ASSERT_EQ(initial_route, spawn->GetEngine()->InitialRoute());
3337 ASSERT_NE(spawner->GetEngine()
3338 ->GetRuntimeController()
3339 ->GetRootIsolateGroup(),
3341 ASSERT_EQ(spawner->GetEngine()
3342 ->GetRuntimeController()
3343 ->GetRootIsolateGroup(),
3345 ->GetRuntimeController()
3346 ->GetRootIsolateGroup());
3350 spawner->GetTaskRunners().GetIOTaskRunner(), [&spawner, &spawn] {
3351 ASSERT_EQ(spawner->GetIOManager()->GetResourceContext().get(),
3352 spawn->GetIOManager()->GetResourceContext().get());
3357 second_latch.Wait();
3359 DestroyShell(std::move(spawn));
3362 DestroyShell(std::move(shell));
3363 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
3367 auto settings = CreateSettingsForFixture();
3368 auto shell = CreateShell(settings);
3371 PostSync(shell->GetTaskRunners().GetPlatformTaskRunner(), [
this,
3374 auto second_configuration = RunConfiguration::InferFromSettings(settings);
3375 ASSERT_TRUE(second_configuration.IsValid());
3376 second_configuration.SetEntrypoint(
"emptyMain");
3377 const std::string initial_route(
"/foo");
3378 MockPlatformViewDelegate platform_view_delegate;
3379 auto spawn = spawner->Spawn(
3380 std::move(second_configuration), initial_route,
3381 [&platform_view_delegate](Shell& shell) {
3382 auto result = std::make_unique<MockPlatformView>(
3383 platform_view_delegate, shell.GetTaskRunners());
3384 ON_CALL(*result, CreateRenderingSurface()).WillByDefault([] {
3385 return std::make_unique<MockSurface>();
3389 [](
Shell& shell) { return std::make_unique<Rasterizer>(shell); });
3392 PostSync(spawner->GetTaskRunners().GetIOTaskRunner(), [&spawner, &spawn] {
3393 ASSERT_NE(spawner->GetIOManager().get(), nullptr);
3394 ASSERT_EQ(spawner->GetIOManager().get(), spawn->GetIOManager().get());
3398 DestroyShell(std::move(spawn));
3401 DestroyShell(std::move(shell));
3405 auto settings = CreateSettingsForFixture();
3406 auto shell = CreateShell(settings);
3409 PostSync(shell->GetTaskRunners().GetUITaskRunner(), [&shell] {
3411 auto runtime_controller = shell->GetEngine()->GetRuntimeController();
3412 PostSync(shell->GetTaskRunners().GetIOTaskRunner(),
3413 [&shell, &runtime_controller] {
3415 auto io_manager = runtime_controller->GetIOManager();
3417 ASSERT_NE(io_manager.get(), nullptr);
3418 ASSERT_NE(io_manager->GetSkiaUnrefQueue().get(), nullptr);
3420 ASSERT_NE(shell->GetIOManager().get(), nullptr);
3424 std::unique_ptr<Shell> spawn;
3426 PostSync(shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell, &settings,
3428 auto second_configuration = RunConfiguration::InferFromSettings(settings);
3429 ASSERT_TRUE(second_configuration.IsValid());
3430 second_configuration.SetEntrypoint(
"emptyMain");
3431 const std::string initial_route(
"/foo");
3432 MockPlatformViewDelegate platform_view_delegate;
3433 auto child = shell->Spawn(
3434 std::move(second_configuration), initial_route,
3435 [&platform_view_delegate](Shell& shell) {
3436 auto result = std::make_unique<MockPlatformView>(
3437 platform_view_delegate, shell.GetTaskRunners());
3438 ON_CALL(*result, CreateRenderingSurface()).WillByDefault([] {
3439 return std::make_unique<MockSurface>();
3443 [](
Shell& shell) { return std::make_unique<Rasterizer>(shell); });
3444 spawn = std::move(child);
3447 DestroyShell(std::move(shell));
3449 PostSync(spawn->GetTaskRunners().GetUITaskRunner(), [&spawn] {
3451 auto runtime_controller = spawn->GetEngine()->GetRuntimeController();
3452 PostSync(spawn->GetTaskRunners().GetIOTaskRunner(),
3453 [&spawn, &runtime_controller] {
3455 auto io_manager = runtime_controller->GetIOManager();
3457 ASSERT_NE(io_manager.get(), nullptr);
3458 ASSERT_NE(io_manager->GetSkiaUnrefQueue().get(), nullptr);
3460 ASSERT_NE(spawn->GetIOManager().get(), nullptr);
3464 DestroyShell(std::move(spawn));
3468 auto settings = CreateSettingsForFixture();
3469 auto shell = CreateShell(settings);
3472 std::unique_ptr<Shell> spawn;
3474 PostSync(shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell, &settings,
3476 auto second_configuration = RunConfiguration::InferFromSettings(settings);
3477 ASSERT_TRUE(second_configuration.IsValid());
3478 second_configuration.SetEntrypoint(
"emptyMain");
3479 const std::string initial_route(
"/foo");
3480 MockPlatformViewDelegate platform_view_delegate;
3481 auto child = shell->Spawn(
3482 std::move(second_configuration), initial_route,
3483 [&platform_view_delegate](Shell& shell) {
3484 auto result = std::make_unique<MockPlatformView>(
3485 platform_view_delegate, shell.GetTaskRunners());
3486 ON_CALL(*result, CreateRenderingSurface()).WillByDefault([] {
3487 return std::make_unique<MockSurface>();
3491 [](
Shell& shell) { return std::make_unique<Rasterizer>(shell); });
3492 spawn = std::move(child);
3495 PostSync(spawn->GetTaskRunners().GetUITaskRunner(), [&spawn] {
3496 std::shared_ptr<const DartIsolate> isolate =
3497 spawn->GetEngine()->GetRuntimeController()->GetRootIsolate().lock();
3498 ASSERT_TRUE(isolate);
3499 ASSERT_TRUE(isolate->GetImageGeneratorRegistry());
3503 DestroyShell(std::move(shell));
3505 PostSync(spawn->GetTaskRunners().GetUITaskRunner(), [&spawn] {
3506 std::shared_ptr<const DartIsolate> isolate =
3507 spawn->GetEngine()->GetRuntimeController()->GetRootIsolate().lock();
3508 ASSERT_TRUE(isolate);
3509 ASSERT_TRUE(isolate->GetImageGeneratorRegistry());
3512 DestroyShell(std::move(spawn));
3516 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
3517 Settings settings = CreateSettingsForFixture();
3521 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
3523 auto shell = CreateShell(settings, task_runners);
3524 ASSERT_TRUE(DartVMRef::IsInstanceRunning());
3527 auto configuration = RunConfiguration::InferFromSettings(settings);
3528 configuration.SetEntrypoint(
"emptyMain");
3529 auto asset_manager = configuration.GetAssetManager();
3531 shell->RunEngine(std::move(configuration), [&](
auto result) {
3532 ASSERT_EQ(result, Engine::RunStatus::Success);
3536 std::make_unique<PlatformView>(*shell.get(), task_runners);
3538 auto old_resolver = std::make_unique<TestAssetResolver>(
3539 true, AssetResolver::AssetResolverType::kApkAssetProvider);
3540 ASSERT_TRUE(old_resolver->IsValid());
3541 asset_manager->PushBack(std::move(old_resolver));
3543 auto updated_resolver = std::make_unique<TestAssetResolver>(
3544 false, AssetResolver::AssetResolverType::kApkAssetProvider);
3545 ASSERT_FALSE(updated_resolver->IsValidAfterAssetManagerChange());
3547 std::move(updated_resolver),
3548 AssetResolver::AssetResolverType::kApkAssetProvider);
3550 auto resolvers = asset_manager->TakeResolvers();
3551 ASSERT_EQ(resolvers.size(), 2ull);
3552 ASSERT_TRUE(resolvers[0]->IsValidAfterAssetManagerChange());
3554 ASSERT_FALSE(resolvers[1]->IsValidAfterAssetManagerChange());
3556 DestroyShell(std::move(shell), task_runners);
3557 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
3561 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
3562 Settings settings = CreateSettingsForFixture();
3566 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
3568 auto shell = CreateShell(settings, task_runners);
3569 ASSERT_TRUE(DartVMRef::IsInstanceRunning());
3572 auto configuration = RunConfiguration::InferFromSettings(settings);
3573 configuration.SetEntrypoint(
"emptyMain");
3574 auto asset_manager = configuration.GetAssetManager();
3576 shell->RunEngine(std::move(configuration), [&](
auto result) {
3577 ASSERT_EQ(result, Engine::RunStatus::Success);
3581 std::make_unique<PlatformView>(*shell.get(), task_runners);
3583 auto updated_resolver = std::make_unique<TestAssetResolver>(
3584 false, AssetResolver::AssetResolverType::kApkAssetProvider);
3585 ASSERT_FALSE(updated_resolver->IsValidAfterAssetManagerChange());
3587 std::move(updated_resolver),
3588 AssetResolver::AssetResolverType::kApkAssetProvider);
3590 auto resolvers = asset_manager->TakeResolvers();
3591 ASSERT_EQ(resolvers.size(), 2ull);
3592 ASSERT_TRUE(resolvers[0]->IsValidAfterAssetManagerChange());
3594 ASSERT_FALSE(resolvers[1]->IsValidAfterAssetManagerChange());
3596 DestroyShell(std::move(shell), task_runners);
3597 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
3601 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
3602 Settings settings = CreateSettingsForFixture();
3605 ThreadHost::Type::kPlatform));
3607 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
3609 auto shell = CreateShell(settings, task_runners);
3610 ASSERT_TRUE(DartVMRef::IsInstanceRunning());
3613 auto configuration = RunConfiguration::InferFromSettings(settings);
3614 configuration.SetEntrypoint(
"emptyMain");
3615 auto asset_manager = configuration.GetAssetManager();
3616 RunEngine(shell.get(), std::move(configuration));
3619 std::make_unique<PlatformView>(*shell.get(), task_runners);
3621 auto old_resolver = std::make_unique<TestAssetResolver>(
3622 true, AssetResolver::AssetResolverType::kApkAssetProvider);
3623 ASSERT_TRUE(old_resolver->IsValid());
3624 asset_manager->PushBack(std::move(old_resolver));
3627 nullptr, AssetResolver::AssetResolverType::kApkAssetProvider);
3629 auto resolvers = asset_manager->TakeResolvers();
3630 ASSERT_EQ(resolvers.size(), 2ull);
3631 ASSERT_TRUE(resolvers[0]->IsValidAfterAssetManagerChange());
3632 ASSERT_TRUE(resolvers[1]->IsValidAfterAssetManagerChange());
3634 DestroyShell(std::move(shell), task_runners);
3635 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
3639 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
3640 Settings settings = CreateSettingsForFixture();
3644 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
3646 auto shell = CreateShell(settings, task_runners);
3647 ASSERT_TRUE(DartVMRef::IsInstanceRunning());
3650 auto configuration = RunConfiguration::InferFromSettings(settings);
3651 configuration.SetEntrypoint(
"emptyMain");
3652 auto asset_manager = configuration.GetAssetManager();
3654 shell->RunEngine(std::move(configuration), [&](
auto result) {
3655 ASSERT_EQ(result, Engine::RunStatus::Success);
3659 std::make_unique<PlatformView>(*shell.get(), task_runners);
3661 auto old_resolver = std::make_unique<TestAssetResolver>(
3662 true, AssetResolver::AssetResolverType::kAssetManager);
3663 ASSERT_TRUE(old_resolver->IsValid());
3664 asset_manager->PushBack(std::move(old_resolver));
3666 auto updated_resolver = std::make_unique<TestAssetResolver>(
3667 false, AssetResolver::AssetResolverType::kApkAssetProvider);
3668 ASSERT_FALSE(updated_resolver->IsValidAfterAssetManagerChange());
3670 std::move(updated_resolver),
3671 AssetResolver::AssetResolverType::kApkAssetProvider);
3673 auto resolvers = asset_manager->TakeResolvers();
3674 ASSERT_EQ(resolvers.size(), 3ull);
3675 ASSERT_TRUE(resolvers[0]->IsValidAfterAssetManagerChange());
3677 ASSERT_TRUE(resolvers[1]->IsValidAfterAssetManagerChange());
3679 ASSERT_FALSE(resolvers[2]->IsValidAfterAssetManagerChange());
3681 DestroyShell(std::move(shell), task_runners);
3682 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
3690 auto settings = CreateSettingsForFixture();
3691 std::unique_ptr<Shell> shell = CreateShell({
3692 .settings = settings,
3694 .rendering_backend = ShellTestPlatformView::BackendType::kGLBackend,
3697 ASSERT_NE(shell,
nullptr);
3698 ASSERT_TRUE(shell->IsSetup());
3699 auto configuration = RunConfiguration::InferFromSettings(settings);
3700 PlatformViewNotifyCreated(shell.get());
3701 configuration.SetEntrypoint(
"emptyMain");
3702 RunEngine(shell.get(), std::move(configuration));
3703 PumpOneFrame(shell.get());
3704 PlatformViewNotifyDestroyed(shell.get());
3705 DestroyShell(std::move(shell));
3710#if !SHELL_ENABLE_VULKAN
3713 auto settings = CreateSettingsForFixture();
3714 std::unique_ptr<Shell> shell = CreateShell({
3715 .settings = settings,
3717 .rendering_backend =
3718 ShellTestPlatformView::BackendType::kVulkanBackend,
3721 ASSERT_NE(shell,
nullptr);
3722 ASSERT_TRUE(shell->IsSetup());
3723 auto configuration = RunConfiguration::InferFromSettings(settings);
3724 PlatformViewNotifyCreated(shell.get());
3725 configuration.SetEntrypoint(
"emptyMain");
3726 RunEngine(shell.get(), std::move(configuration));
3727 PumpOneFrame(shell.get());
3728 PlatformViewNotifyDestroyed(shell.get());
3729 DestroyShell(std::move(shell));
3734#if !SHELL_ENABLE_METAL
3737 auto settings = CreateSettingsForFixture();
3738 std::unique_ptr<Shell> shell = CreateShell({
3739 .settings = settings,
3741 .rendering_backend =
3742 ShellTestPlatformView::BackendType::kMetalBackend,
3745 ASSERT_NE(shell,
nullptr);
3746 ASSERT_TRUE(shell->IsSetup());
3747 auto configuration = RunConfiguration::InferFromSettings(settings);
3748 PlatformViewNotifyCreated(shell.get());
3749 configuration.SetEntrypoint(
"emptyMain");
3750 RunEngine(shell.get(), std::move(configuration));
3751 PumpOneFrame(shell.get());
3752 PlatformViewNotifyDestroyed(shell.get());
3753 DestroyShell(std::move(shell));
3758 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
3761 auto vm_settings = CreateSettingsForFixture();
3762 auto vm_ref = DartVMRef::Create(vm_settings);
3763 ASSERT_TRUE(DartVMRef::IsInstanceRunning());
3765 auto settings = vm_settings;
3769 settings.root_isolate_create_callback = [&](
const DartIsolate& isolate) {
3770 Dart_Handle current_tag = Dart_GetCurrentUserTag();
3771 Dart_Handle startup_tag = Dart_NewUserTag(
"AppStartUp");
3772 EXPECT_TRUE(Dart_IdentityEquals(current_tag, startup_tag));
3774 isolate_create_latch.
Signal();
3777 auto shell = CreateShell(settings);
3780 auto configuration = RunConfiguration::InferFromSettings(settings);
3781 ASSERT_TRUE(configuration.IsValid());
3783 RunEngine(shell.get(), std::move(configuration));
3784 ASSERT_TRUE(DartVMRef::IsInstanceRunning());
3786 DestroyShell(std::move(shell));
3787 isolate_create_latch.
Wait();
3791 auto settings = CreateSettingsForFixture();
3792 settings.prefetched_default_font_manager =
true;
3793 std::unique_ptr<Shell> shell;
3795 auto get_font_manager_count = [&] {
3797 size_t font_manager_count;
3799 shell->GetTaskRunners().GetUITaskRunner(),
3800 [
this, &shell, &latch, &font_manager_count]() {
3801 font_manager_count =
3802 GetFontCollection(shell.get())->GetFontManagersCount();
3806 return font_manager_count;
3808 size_t initial_font_manager_count = 0;
3809 settings.root_isolate_create_callback = [&](
const auto& isolate) {
3810 ASSERT_GT(initial_font_manager_count, 0ul);
3813 ASSERT_EQ(get_font_manager_count(), initial_font_manager_count);
3816 shell = CreateShell(settings);
3818 initial_font_manager_count = get_font_manager_count();
3820 auto configuration = RunConfiguration::InferFromSettings(settings);
3821 configuration.SetEntrypoint(
"emptyMain");
3822 RunEngine(shell.get(), std::move(configuration));
3826 ASSERT_EQ(get_font_manager_count(), initial_font_manager_count + 1);
3828 DestroyShell(std::move(shell));
3834 auto settings = CreateSettingsForFixture();
3835 auto shell = CreateShell(settings);
3839 [&latch]() { latch.Wait(); });
3841 ShellTest::PlatformViewNotifyCreated(shell.get());
3844 DestroyShell(std::move(shell));
3848 auto settings = CreateSettingsForFixture();
3849 auto shell = CreateShell(settings);
3850 auto configuration = RunConfiguration::InferFromSettings(settings);
3851 configuration.SetEntrypoint(
"drawFrames");
3856 notify_native_latch.
Signal();
3860 RunEngine(shell.get(), std::move(configuration));
3863 notify_native_latch.
Wait();
3865 ShellTest::PlatformViewNotifyCreated(shell.get());
3869 shell->GetTaskRunners().GetPlatformTaskRunner(),
3870 [&shell, &destroy_latch]() {
3871 shell->GetPlatformView()->NotifyDestroyed();
3872 destroy_latch.Signal();
3875 destroy_latch.
Wait();
3884 shell->GetTaskRunners().GetUITaskRunner(),
3885 [&ui_flush_latch]() { ui_flush_latch.Signal(); });
3886 ui_flush_latch.
Wait();
3887 DestroyShell(std::move(shell));
3892 auto settings = CreateSettingsForFixture();
3893 MockPlatformViewDelegate platform_view_delegate;
3894 auto platform_message_handler =
3895 std::make_shared<MockPlatformMessageHandler>();
3897 EXPECT_CALL(*platform_message_handler, HandlePlatformMessage(_));
3898 EXPECT_CALL(*platform_message_handler,
3899 InvokePlatformMessageEmptyResponseCallback(message_id));
3901 [&platform_view_delegate, task_runners,
3903 auto result = std::make_unique<MockPlatformView>(platform_view_delegate,
3905 EXPECT_CALL(*result, GetPlatformMessageHandler())
3906 .WillOnce(Return(platform_message_handler));
3909 auto shell = CreateShell({
3910 .settings = settings,
3911 .task_runners = task_runners,
3912 .platform_view_create_callback = platform_view_create_callback,
3915 EXPECT_EQ(platform_message_handler, shell->GetPlatformMessageHandler());
3917 size_t data_size = 4;
3918 fml::MallocMapping bytes =
3919 fml::MallocMapping(static_cast<uint8_t*>(malloc(data_size)), data_size);
3920 fml::RefPtr<MockPlatformMessageResponse> response =
3921 MockPlatformMessageResponse::Create();
3922 auto message = std::make_unique<PlatformMessage>(
3923 "foo", std::move(bytes), response);
3924 (static_cast<Engine::Delegate*>(shell.get()))
3925 ->OnEngineHandlePlatformMessage(std::move(message));
3927 shell->GetPlatformMessageHandler()
3928 ->InvokePlatformMessageEmptyResponseCallback(message_id);
3929 DestroyShell(std::move(shell));
3933 auto settings = CreateSettingsForFixture();
3934 auto shell = CreateShell(settings);
3937 auto configuration = RunConfiguration::InferFromSettings(settings);
3938 ASSERT_TRUE(configuration.IsValid());
3939 configuration.SetEntrypoint(
"onErrorA");
3941 auto second_configuration = RunConfiguration::InferFromSettings(settings);
3942 ASSERT_TRUE(second_configuration.IsValid());
3943 second_configuration.SetEntrypoint(
"onErrorB");
3949 auto string_handle = Dart_GetNativeArgument(
args, 0);
3951 Dart_StringToCString(string_handle, &c_str);
3952 EXPECT_STREQ(c_str,
"Exception: I should be coming from A");
3958 auto string_handle = Dart_GetNativeArgument(
args, 0);
3960 Dart_StringToCString(string_handle, &c_str);
3961 EXPECT_STREQ(c_str,
"Exception: I should be coming from B");
3965 RunEngine(shell.get(), std::move(configuration));
3967 ASSERT_TRUE(DartVMRef::IsInstanceRunning());
3970 shell->GetTaskRunners().GetPlatformTaskRunner(),
3971 [
this, &spawner = shell, &second_configuration, &latch]() {
3972 ::testing::NiceMock<MockPlatformViewDelegate> platform_view_delegate;
3973 auto spawn = spawner->Spawn(
3974 std::move(second_configuration),
"",
3975 [&platform_view_delegate](Shell& shell) {
3977 std::make_unique<::testing::NiceMock<MockPlatformView>>(
3978 platform_view_delegate, shell.GetTaskRunners());
3979 ON_CALL(*result, CreateRenderingSurface()).WillByDefault([] {
3980 return std::make_unique<::testing::NiceMock<MockSurface>>();
3984 [](
Shell& shell) { return std::make_unique<Rasterizer>(shell); });
3985 ASSERT_NE(
nullptr, spawn.get());
3992 DestroyShell(std::move(spawn));
3995 DestroyShell(std::move(shell));
3996 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
4000 Settings settings = CreateSettingsForFixture();
4001 auto task_runner = CreateNewThread();
4002 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
4004 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
4007 AddNativeCallback(
"NotifyNative",
4011 PlatformViewNotifyCreated(shell.get());
4013 auto configuration = RunConfiguration::InferFromSettings(settings);
4014 configuration.SetEntrypoint(
"testThatAssetLoadingHappensOnWorkerThread");
4015 auto asset_manager = configuration.GetAssetManager();
4016 auto test_resolver = std::make_unique<ThreadCheckingAssetResolver>(
4017 shell->GetDartVM()->GetConcurrentMessageLoop());
4018 auto leaked_resolver = test_resolver.get();
4019 asset_manager->PushBack(std::move(test_resolver));
4021 RunEngine(shell.get(), std::move(configuration));
4022 PumpOneFrame(shell.get());
4026 EXPECT_EQ(leaked_resolver->mapping_requests[0],
"DoesNotExist");
4028 PlatformViewNotifyDestroyed(shell.get());
4029 DestroyShell(std::move(shell), task_runners);
4037 auto settings = CreateSettingsForFixture();
4038 std::unique_ptr<Shell> shell = CreateShell({
4039 .settings = settings,
4041 .rendering_backend = ShellTestPlatformView::BackendType::kGLBackend,
4045 AddNativeCallback(
"NativeOnBeforeToImageSync",
4053 PlatformViewNotifyDestroyed(shell.get());
4054 PlatformViewNotifyCreated(shell.get());
4058 ASSERT_NE(shell,
nullptr);
4059 ASSERT_TRUE(shell->IsSetup());
4060 auto configuration = RunConfiguration::InferFromSettings(settings);
4061 PlatformViewNotifyCreated(shell.get());
4062 configuration.SetEntrypoint(
"toImageSync");
4063 RunEngine(shell.get(), std::move(configuration));
4064 PumpOneFrame(shell.get());
4068 PlatformViewNotifyDestroyed(shell.get());
4069 DestroyShell(std::move(shell));
4074#if !SHELL_ENABLE_METAL
4078 auto settings = CreateSettingsForFixture();
4079 settings.enable_impeller =
true;
4080 std::unique_ptr<Shell> shell = CreateShell({
4081 .settings = settings,
4083 .rendering_backend =
4084 ShellTestPlatformView::BackendType::kMetalBackend,
4088 AddNativeCallback(
"NativeOnBeforeToImageSync",
4096 PlatformViewNotifyDestroyed(shell.get());
4097 PlatformViewNotifyCreated(shell.get());
4101 ASSERT_NE(shell,
nullptr);
4102 ASSERT_TRUE(shell->IsSetup());
4103 auto configuration = RunConfiguration::InferFromSettings(settings);
4109 configuration.SetEntrypoint(
"toImageSync");
4110 RunEngine(shell.get(), std::move(configuration));
4111 PumpOneFrame(shell.get());
4115 PlatformViewNotifyDestroyed(shell.get());
4116 DestroyShell(std::move(shell));
4122TEST_F(ShellTest, PictureToImageSyncWithTrampledContext) {
4125 ThreadHost thread_host(
"io.flutter.test." + GetCurrentTestName() +
".",
4126 ThreadHost::Type::kPlatform);
4127 auto task_runner = thread_host.platform_thread->GetTaskRunner();
4128 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
4131 auto settings = CreateSettingsForFixture();
4132 std::unique_ptr<Shell> shell = CreateShell({
4133 .settings = settings,
4134 .task_runners = task_runners,
4135 .platform_view_create_callback = ShellTestPlatformViewBuilder({
4136 .rendering_backend = ShellTestPlatformView::BackendType::kGLBackend,
4145 ::eglMakeCurrent(::eglGetCurrentDisplay(), NULL, NULL, NULL);
4151 PlatformViewNotifyDestroyed(shell.get());
4152 PlatformViewNotifyCreated(shell.get());
4156 ASSERT_NE(shell,
nullptr);
4157 ASSERT_TRUE(shell->IsSetup());
4158 auto configuration = RunConfiguration::InferFromSettings(settings);
4159 PlatformViewNotifyCreated(shell.get());
4160 configuration.SetEntrypoint(
"toImageSync");
4161 RunEngine(shell.get(), std::move(configuration));
4162 PumpOneFrame(shell.get());
4166 PlatformViewNotifyDestroyed(shell.get());
4167 DestroyShell(std::move(shell), task_runners);
4172 auto settings = CreateSettingsForFixture();
4173 std::unique_ptr<Shell> shell = CreateShell(settings);
4178 Dart_Handle exception =
nullptr;
4180 args, 0, exception);
4184 ASSERT_NE(shell,
nullptr);
4185 ASSERT_TRUE(shell->IsSetup());
4186 auto configuration = RunConfiguration::InferFromSettings(settings);
4187 PlatformViewNotifyCreated(shell.get());
4188 configuration.SetEntrypoint(
"testPluginUtilitiesCallbackHandle");
4189 RunEngine(shell.get(), std::move(configuration));
4190 PumpOneFrame(shell.get());
4194 ASSERT_TRUE(test_passed);
4196 PlatformViewNotifyDestroyed(shell.get());
4197 DestroyShell(std::move(shell));
4201 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
4202 Settings settings = CreateSettingsForFixture();
4204 ThreadHost::Type::kPlatform | ThreadHost::kUi |
4205 ThreadHost::kIo | ThreadHost::kRaster);
4206 auto platform_task_runner = thread_host.
platform_thread->GetTaskRunner();
4210 thread_host.
io_thread->GetTaskRunner());
4211 auto shell = CreateShell(settings, task_runners);
4212 ASSERT_TRUE(DartVMRef::IsInstanceRunning());
4217 auto configuration = RunConfiguration::InferFromSettings(settings);
4218 configuration.SetEntrypoint(
"emptyMain");
4219 RunEngine(shell.get(), std::move(configuration));
4223 auto runtime_controller = const_cast<RuntimeController*>(
4224 shell->GetEngine()->GetRuntimeController());
4226 auto now = fml::TimeDelta::FromMicroseconds(Dart_TimelineGetMicros());
4228 EXPECT_FALSE(runtime_controller->NotifyIdle(
4229 now - fml::TimeDelta::FromMilliseconds(10)));
4230 EXPECT_FALSE(runtime_controller->NotifyIdle(now));
4231 EXPECT_FALSE(runtime_controller->NotifyIdle(
4232 now + fml::TimeDelta::FromNanoseconds(100)));
4234 EXPECT_TRUE(runtime_controller->NotifyIdle(
4235 now + fml::TimeDelta::FromMilliseconds(100)));
4241 DestroyShell(std::move(shell), task_runners);
4242 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
4246 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
4247 Settings settings = CreateSettingsForFixture();
4249 ThreadHost::Type::kPlatform | ThreadHost::kUi |
4250 ThreadHost::kIo | ThreadHost::kRaster);
4251 auto platform_task_runner = thread_host.
platform_thread->GetTaskRunner();
4255 thread_host.
io_thread->GetTaskRunner());
4256 auto shell = CreateShell(settings, task_runners);
4257 ASSERT_TRUE(DartVMRef::IsInstanceRunning());
4266 Dart_Handle exception =
nullptr;
4267 bool is_in_latency_mode =
4270 shell->GetEngine()->GetRuntimeController());
4273 Dart_TimelineGetMicros() + 100000));
4274 EXPECT_EQ(success, !is_in_latency_mode);
4278 auto configuration = RunConfiguration::InferFromSettings(settings);
4279 configuration.SetEntrypoint(
"performanceModeImpactsNotifyIdle");
4280 RunEngine(shell.get(), std::move(configuration));
4284 DestroyShell(std::move(shell), task_runners);
4285 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
4289#if FLUTTER_RUNTIME_MODE != FLUTTER_RUNTIME_MODE_DEBUG || OS_FUCHSIA
4290 GTEST_SKIP() <<
"Test is for debug mode only on non-fuchsia targets.";
4292 Settings settings = CreateSettingsForFixture();
4294 ThreadHost::Type::kPlatform);
4296 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
4298 auto shell = CreateShell(settings, task_runners);
4305 SendPlatformMessage(shell.get(), std::make_unique<PlatformMessage>(
4306 "com.test.plugin",
nullptr));
4310 ::testing::EndsWith(
4311 "The 'com.test.plugin' channel sent a message from native to "
4312 "Flutter on a non-platform thread. Platform channel messages "
4313 "must be sent on the platform thread. Failure to do so may "
4314 "result in data loss or crashes, and must be fixed in the "
4315 "plugin or application code creating that channel.\nSee "
4316 "https://docs.flutter.dev/platform-integration/"
4317 "platform-channels#channels-and-platform-threading for more "
4326 SendPlatformMessage(shell.get(), std::make_unique<PlatformMessage>(
4327 "com.test.plugin",
nullptr));
4329 EXPECT_EQ(log_capture.
str(),
"");
4332 DestroyShell(std::move(shell), task_runners);
4333 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
4338 Settings settings = CreateSettingsForFixture();
4340 ThreadHost::Type::kPlatform);
4342 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
4344 auto shell = CreateShell(settings, task_runners);
4346 auto latch = std::make_shared<fml::CountDownLatch>(1u);
4347 task_runner->PostTask([&]() {
4348 auto message = MakePlatformMessage(
4349 "flutter/navigation",
4350 {{
"method",
"setInitialRoute"}, {
"args",
"/testo"}},
nullptr);
4351 SendPlatformMessage(shell.get(), std::move(
message));
4352 EXPECT_EQ(shell->GetEngine()->InitialRoute(),
"/testo");
4358 DestroyShell(std::move(shell), task_runners);
4359 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
4364 Settings settings = CreateSettingsForFixture();
4366 ThreadHost::Type::kPlatform);
4368 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
4373 auto shell = CreateShell(settings, task_runners);
4374 auto configuration = RunConfiguration::InferFromSettings(settings);
4375 configuration.SetEntrypoint(
"testSemanticsActions");
4377 RunEngine(shell.get(), std::move(configuration));
4387 SendSemanticsAction(shell.get(), 456, 0, SemanticsAction::kTap,
4392 DestroyShell(std::move(shell), task_runners);
4393 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
4398 Settings settings = CreateSettingsForFixture();
4400 ThreadHost::Type::kPlatform);
4402 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
4407 auto shell = CreateShell(settings, task_runners);
4408 auto configuration = RunConfiguration::InferFromSettings(settings);
4409 configuration.SetEntrypoint(
"testPointerActions");
4411 RunEngine(shell.get(), std::move(configuration));
4420 DispatchFakePointerData(shell.get(), 23);
4423 DestroyShell(std::move(shell), task_runners);
4424 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
4429 Settings settings = CreateSettingsForFixture();
4431 ThreadHost::Type::kPlatform);
4433 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
4438 auto shell = CreateShell(settings, task_runners);
4439 auto configuration = RunConfiguration::InferFromSettings(settings);
4440 configuration.SetEntrypoint(
"testDispatchEvents");
4442 RunEngine(shell.get(), std::move(configuration));
4444 bool did_invoke_callback =
false;
4450 did_invoke_callback =
true;
4454 DispatchFakePointerData(shell.get(), 23);
4455 EXPECT_FALSE(did_invoke_callback);
4457 EXPECT_TRUE(did_invoke_callback);
4459 DestroyShell(std::move(shell), task_runners);
4460 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
4464#if defined(OS_FUCHSIA)
4465 GTEST_SKIP() <<
"Fuchsia";
4467 ::testing::FLAGS_gtest_death_test_style =
"threadsafe";
4468 Settings settings = CreateSettingsForFixture();
4472 ThreadHost::Type::kPlatform);
4474 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
4476 EXPECT_DEATH_IF_SUPPORTED(
4477 CreateShell(settings, task_runners),
4478 "Software rendering is incompatible with Impeller.");
4485 bool* hasImplicitView,
4486 std::vector<int64_t>* viewIds) {
4487 Dart_Handle exception =
nullptr;
4491 ASSERT_EQ(exception,
nullptr);
4493 args, 1, exception);
4494 ASSERT_EQ(exception,
nullptr);
4498 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
4499 Settings settings = CreateSettingsForFixture();
4500 auto task_runner = CreateNewThread();
4501 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
4503 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
4506 bool hasImplicitView;
4507 std::vector<int64_t> viewIds;
4509 auto nativeViewIdsCallback = [&reportLatch, &hasImplicitView,
4510 &viewIds](Dart_NativeArguments
args) {
4514 AddNativeCallback(
"NativeReportViewIdsCallback",
4517 PlatformViewNotifyCreated(shell.get());
4518 auto configuration = RunConfiguration::InferFromSettings(settings);
4519 configuration.SetEntrypoint(
"testReportViewIds");
4520 RunEngine(shell.get(), std::move(configuration));
4523 ASSERT_TRUE(hasImplicitView);
4524 ASSERT_EQ(viewIds.size(), 1u);
4525 ASSERT_EQ(viewIds[0], 0ll);
4527 PlatformViewNotifyDestroyed(shell.get());
4528 DestroyShell(std::move(shell), task_runners);
4533 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
4534 Settings settings = CreateSettingsForFixture();
4537 ThreadHost::Type::kPlatform | ThreadHost::Type::kRaster |
4538 ThreadHost::Type::kIo | ThreadHost::Type::kUi));
4542 thread_host.
io_thread->GetTaskRunner());
4543 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
4546 bool hasImplicitView;
4547 std::vector<int64_t> viewIds;
4549 auto nativeViewIdsCallback = [&reportLatch, &hasImplicitView,
4550 &viewIds](Dart_NativeArguments
args) {
4554 AddNativeCallback(
"NativeReportViewIdsCallback",
4557 PlatformViewNotifyCreated(shell.get());
4558 auto configuration = RunConfiguration::InferFromSettings(settings);
4559 configuration.SetEntrypoint(
"testReportViewIds");
4560 RunEngine(shell.get(), std::move(configuration));
4563 ASSERT_TRUE(hasImplicitView);
4564 ASSERT_EQ(viewIds.size(), 1u);
4565 ASSERT_EQ(viewIds[0], 0ll);
4567 PostSync(shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell] {
4568 shell->GetPlatformView()->AddView(2, ViewportMetrics{},
4569 [](
bool added) { EXPECT_TRUE(added); });
4572 ASSERT_TRUE(hasImplicitView);
4573 ASSERT_EQ(viewIds.size(), 2u);
4574 ASSERT_EQ(viewIds[1], 2ll);
4576 PostSync(shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell] {
4577 shell->GetPlatformView()->RemoveView(
4578 2, [](bool removed) { ASSERT_TRUE(removed); });
4581 ASSERT_TRUE(hasImplicitView);
4582 ASSERT_EQ(viewIds.size(), 1u);
4583 ASSERT_EQ(viewIds[0], 0ll);
4585 PostSync(shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell] {
4586 shell->GetPlatformView()->AddView(4, ViewportMetrics{},
4587 [](
bool added) { EXPECT_TRUE(added); });
4590 ASSERT_TRUE(hasImplicitView);
4591 ASSERT_EQ(viewIds.size(), 2u);
4592 ASSERT_EQ(viewIds[1], 4ll);
4594 PlatformViewNotifyDestroyed(shell.get());
4595 DestroyShell(std::move(shell), task_runners);
4600 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
4601 Settings settings = CreateSettingsForFixture();
4604 ThreadHost::Type::kPlatform | ThreadHost::Type::kRaster |
4605 ThreadHost::Type::kIo | ThreadHost::Type::kUi));
4609 thread_host.
io_thread->GetTaskRunner());
4610 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
4613 bool has_implicit_view;
4614 std::vector<int64_t> view_ids;
4616 AddNativeCallback(
"NativeReportViewIdsCallback",
4622 PlatformViewNotifyCreated(shell.get());
4623 auto configuration = RunConfiguration::InferFromSettings(settings);
4624 configuration.SetEntrypoint(
"testReportViewIds");
4625 RunEngine(shell.get(), std::move(configuration));
4627 report_latch.
Wait();
4628 ASSERT_TRUE(has_implicit_view);
4629 ASSERT_EQ(view_ids.size(), 1u);
4634 PostSync(shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell,
4636 shell->GetPlatformView()->AddView(123, ViewportMetrics{}, [&](
bool added) {
4644 report_latch.Wait();
4645 ASSERT_EQ(view_ids.size(), 2u);
4647 ASSERT_EQ(view_ids[1], 123);
4650 PostSync(shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell,
4652 shell->GetPlatformView()->AddView(123, ViewportMetrics{}, [&](
bool added) {
4653 EXPECT_FALSE(added);
4660 PlatformViewNotifyDestroyed(shell.get());
4661 DestroyShell(std::move(shell), task_runners);
4667 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
4668 Settings settings = CreateSettingsForFixture();
4671 ThreadHost::Type::kPlatform | ThreadHost::Type::kRaster |
4672 ThreadHost::Type::kIo | ThreadHost::Type::kUi));
4676 thread_host.
io_thread->GetTaskRunner());
4677 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
4680 bool has_implicit_view;
4681 std::vector<int64_t> view_ids;
4683 AddNativeCallback(
"NativeReportViewIdsCallback",
4689 PlatformViewNotifyCreated(shell.get());
4690 auto configuration = RunConfiguration::InferFromSettings(settings);
4691 configuration.SetEntrypoint(
"testReportViewIds");
4692 RunEngine(shell.get(), std::move(configuration));
4694 report_latch.
Wait();
4695 ASSERT_TRUE(has_implicit_view);
4696 ASSERT_EQ(view_ids.size(), 1u);
4701 PostSync(shell->GetTaskRunners().GetPlatformTaskRunner(),
4702 [&shell, &remove_latch] {
4703 shell->GetPlatformView()->RemoveView(123, [&](bool removed) {
4704 EXPECT_FALSE(removed);
4705 remove_latch.Signal();
4709 remove_latch.Wait();
4711 PlatformViewNotifyDestroyed(shell.get());
4712 DestroyShell(std::move(shell), task_runners);
4718 std::map<int64_t, int64_t>* viewWidths) {
4719 Dart_Handle exception =
nullptr;
4720 viewWidths->clear();
4721 std::vector<int64_t> viewWidthPacket =
4724 ASSERT_EQ(exception,
nullptr);
4725 ASSERT_EQ(viewWidthPacket.size() % 2, 0ul);
4726 for (
size_t packetIndex = 0; packetIndex < viewWidthPacket.size();
4728 (*viewWidths)[viewWidthPacket[packetIndex]] =
4729 viewWidthPacket[packetIndex + 1];
4737 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
4738 Settings settings = CreateSettingsForFixture();
4741 ThreadHost::Type::kPlatform | ThreadHost::Type::kRaster |
4742 ThreadHost::Type::kIo | ThreadHost::Type::kUi));
4746 thread_host.
io_thread->GetTaskRunner());
4747 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
4750 PostSync(shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell] {
4751 auto platform_view = shell->GetPlatformView();
4754 platform_view->SetViewportMetrics(0, ViewportMetrics{1, 10, 1, 0, 0});
4756 [](
bool added) { ASSERT_TRUE(added); });
4760 bool first_report =
true;
4761 std::map<int64_t, int64_t> viewWidths;
4763 auto nativeViewWidthsCallback = [&reportLatch, &viewWidths,
4764 &first_report](Dart_NativeArguments
args) {
4765 EXPECT_TRUE(first_report);
4766 first_report =
false;
4767 ParseViewWidthsCallback(
args, &viewWidths);
4770 AddNativeCallback(
"NativeReportViewWidthsCallback",
4773 PlatformViewNotifyCreated(shell.get());
4774 auto configuration = RunConfiguration::InferFromSettings(settings);
4775 configuration.SetEntrypoint(
"testReportViewWidths");
4776 RunEngine(shell.get(), std::move(configuration));
4779 EXPECT_EQ(viewWidths.size(), 2u);
4780 EXPECT_EQ(viewWidths[0], 20ll);
4781 EXPECT_EQ(viewWidths[1], 30ll);
4783 PlatformViewNotifyDestroyed(shell.get());
4784 DestroyShell(std::move(shell), task_runners);
4789 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
4790 Settings settings = CreateSettingsForFixture();
4793 ThreadHost::Type::kPlatform | ThreadHost::Type::kRaster |
4794 ThreadHost::Type::kIo | ThreadHost::Type::kUi));
4798 thread_host.
io_thread->GetTaskRunner());
4799 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
4802 PostSync(shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell] {
4803 auto platform_view = shell->GetPlatformView();
4808 shell->GetPlatformView()->AddView(123, ViewportMetrics{1, 30, 1, 0, 0},
4809 [](
bool added) { ASSERT_FALSE(added); });
4810 shell->GetPlatformView()->RemoveView(
4811 123, [](
bool removed) { ASSERT_FALSE(removed); });
4814 bool first_report =
true;
4815 std::map<int64_t, int64_t> view_widths;
4817 AddNativeCallback(
"NativeReportViewWidthsCallback",
4819 EXPECT_TRUE(first_report);
4820 first_report =
false;
4821 ParseViewWidthsCallback(
args, &view_widths);
4825 PlatformViewNotifyCreated(shell.get());
4826 auto configuration = RunConfiguration::InferFromSettings(settings);
4827 configuration.SetEntrypoint(
"testReportViewWidths");
4828 RunEngine(shell.get(), std::move(configuration));
4830 report_latch.
Wait();
4831 EXPECT_EQ(view_widths.size(), 1u);
4833 PlatformViewNotifyDestroyed(shell.get());
4834 DestroyShell(std::move(shell), task_runners);
4840 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
4841 Settings settings = CreateSettingsForFixture();
4844 ThreadHost::Type::kPlatform | ThreadHost::Type::kRaster |
4845 ThreadHost::Type::kIo | ThreadHost::Type::kUi));
4849 thread_host.
io_thread->GetTaskRunner());
4850 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
4853 PostSync(shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell] {
4854 auto platform_view = shell->GetPlatformView();
4857 shell->GetPlatformView()->AddView(123, ViewportMetrics{1, 100, 1, 0, 0},
4858 [](
bool added) { ASSERT_TRUE(added); });
4860 shell->GetPlatformView()->AddView(123,
ViewportMetrics{1, 200, 1, 0, 0},
4861 [](
bool added) { ASSERT_FALSE(added); });
4864 shell->GetPlatformView()->AddView(456,
ViewportMetrics{1, 300, 1, 0, 0},
4865 [](
bool added) { ASSERT_TRUE(added); });
4868 bool first_report =
true;
4869 std::map<int64_t, int64_t> view_widths;
4871 AddNativeCallback(
"NativeReportViewWidthsCallback",
4873 EXPECT_TRUE(first_report);
4874 first_report =
false;
4875 ParseViewWidthsCallback(
args, &view_widths);
4879 PlatformViewNotifyCreated(shell.get());
4880 auto configuration = RunConfiguration::InferFromSettings(settings);
4881 configuration.SetEntrypoint(
"testReportViewWidths");
4882 RunEngine(shell.get(), std::move(configuration));
4884 report_latch.
Wait();
4885 EXPECT_EQ(view_widths.size(), 3u);
4886 EXPECT_EQ(view_widths[0], 0);
4887 EXPECT_EQ(view_widths[123], 100);
4888 EXPECT_EQ(view_widths[456], 300);
4890 PlatformViewNotifyDestroyed(shell.get());
4891 DestroyShell(std::move(shell), task_runners);
4895#if !IMPELLER_SUPPORTS_RENDERING
4896 GTEST_SKIP() <<
"This platform doesn't support Impeller.";
4898 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
4899 Settings settings = CreateSettingsForFixture();
4905 TaskRunners task_runners(
"test", runner, runner, runner, runner);
4906 std::ostringstream stream;
4908 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
4910 stream.str().find(
"[Action Required]: Impeller opt-out deprecated.") !=
4913 DestroyShell(std::move(shell), task_runners);
4917 Settings settings = CreateSettingsForFixture();
4920 std::string last_event;
4926 AddNativeCallback(
"NotifyMessage",
4928 const auto message_from_dart =
4930 Dart_GetNativeArgument(
args, 0));
4931 last_event = message_from_dart;
4936 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
4937 ASSERT_TRUE(shell->IsSetup());
4939 auto configuration = RunConfiguration::InferFromSettings(settings);
4941 configuration.SetEntrypoint(
"testSendViewFocusEvent");
4942 RunEngine(shell.get(), std::move(configuration));
4946 PostSync(shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell]() {
4947 shell->GetPlatformView()->SendViewFocusEvent(ViewFocusEvent(
4948 1, ViewFocusState::kFocused, ViewFocusDirection::kUndefined));
4951 ASSERT_EQ(last_event,
4952 "1 ViewFocusState.focused ViewFocusDirection.undefined");
4955 PostSync(shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell]() {
4956 shell->GetPlatformView()->SendViewFocusEvent(ViewFocusEvent(
4957 2, ViewFocusState::kUnfocused, ViewFocusDirection::kBackward));
4960 ASSERT_EQ(last_event,
4961 "2 ViewFocusState.unfocused ViewFocusDirection.backward");
4962 DestroyShell(std::move(shell), task_runners);
4966 Settings settings = CreateSettingsForFixture();
4970 std::optional<int> reported_handle = std::nullopt;
4974 Dart_Handle arg = Dart_GetNativeArgument(
args, 0);
4975 if (Dart_IsNull(arg)) {
4976 reported_handle = std::nullopt;
4984 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
4985 ASSERT_TRUE(shell->IsSetup());
4987 auto configuration = RunConfiguration::InferFromSettings(settings);
4988 configuration.SetEngineId(99);
4989 configuration.SetEntrypoint(
"providesEngineId");
4990 RunEngine(shell.get(), std::move(configuration));
4993 ASSERT_EQ(reported_handle, 99);
4998 shell->GetTaskRunners().GetUITaskRunner(), [&]() {
4999 ASSERT_EQ(shell->GetEngine()->GetLastEngineId(), 99);
5003 DestroyShell(std::move(shell), task_runners);
5007 Settings settings = CreateSettingsForFixture();
5011 std::optional<int> reported_handle = std::nullopt;
5015 Dart_Handle arg = Dart_GetNativeArgument(
args, 0);
5016 if (Dart_IsNull(arg)) {
5017 reported_handle = std::nullopt;
5025 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
5026 ASSERT_TRUE(shell->IsSetup());
5028 auto configuration = RunConfiguration::InferFromSettings(settings);
5029 configuration.SetEntrypoint(
"providesEngineId");
5030 RunEngine(shell.get(), std::move(configuration));
5033 ASSERT_EQ(reported_handle, std::nullopt);
5034 DestroyShell(std::move(shell), task_runners);
5038 Settings settings = CreateSettingsForFixture();
5040 Settings::MergedPlatformUIThread::kMergeAfterLaunch;
5043 ThreadHost::Type::kPlatform | ThreadHost::Type::kRaster |
5044 ThreadHost::Type::kIo | ThreadHost::Type::kUi));
5048 thread_host.
io_thread->GetTaskRunner());
5050 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
5065 auto configuration = RunConfiguration::InferFromSettings(settings);
5066 configuration.SetEntrypoint(
"mainNotifyNative");
5067 RunEngine(shell.get(), std::move(configuration));
5075 DestroyShell(std::move(shell), task_runners);
5080 auto settings = CreateSettingsForFixture();
5081 bool called_release_resource_context =
false;
5083 [task_runners, &called_release_resource_context](
flutter::Shell& shell) {
5084 auto result = std::make_unique<::testing::NiceMock<TestPlatformView>>(
5085 shell, task_runners);
5086 ON_CALL(*result, ReleaseResourceContext())
5088 ::testing::Assign(&called_release_resource_context,
true));
5092 auto parent_shell = CreateShell({
5093 .settings = settings,
5094 .task_runners = task_runners,
5095 .platform_view_create_callback = platform_view_create_callback,
5098 std::unique_ptr<Shell> child_shell;
5100 parent_shell->GetTaskRunners().GetPlatformTaskRunner(),
5101 [&parent_shell, &settings, &child_shell, platform_view_create_callback] {
5102 auto configuration = RunConfiguration::InferFromSettings(settings);
5103 configuration.SetEntrypoint(
"emptyMain");
5104 auto child = parent_shell->Spawn(
5105 std::move(configuration),
"", platform_view_create_callback,
5106 [](Shell& shell) { return std::make_unique<Rasterizer>(shell); });
5107 child_shell = std::move(child);
5110 DestroyShell(std::move(parent_shell), task_runners);
5111 ASSERT_FALSE(called_release_resource_context);
5113 DestroyShell(std::move(child_shell), task_runners);
5114 ASSERT_TRUE(called_release_resource_context);
5118 Settings settings = CreateSettingsForFixture();
5119 auto task_runner = CreateNewThread();
5120 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
5122 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
5125 shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell]() {
5126 shell->GetPlatformView()->SetViewportMetrics(
5159 PumpOneFrame(shell.get());
5162 std::make_unique<LayerTree>(
nullptr,
5164 ASSERT_FALSE(ShellTest::ShouldDiscardLayerTree(shell.get(),
kImplicitViewId,
5167 std::make_unique<LayerTree>(
nullptr,
5169 ASSERT_TRUE(ShellTest::ShouldDiscardLayerTree(shell.get(),
kImplicitViewId,
5172 std::make_unique<LayerTree>(
nullptr,
5174 ASSERT_TRUE(ShellTest::ShouldDiscardLayerTree(shell.get(),
kImplicitViewId,
5176 auto min_width = std::make_unique<LayerTree>(
nullptr,
5178 ASSERT_TRUE(ShellTest::ShouldDiscardLayerTree(shell.get(),
kImplicitViewId,
5180 auto min_height = std::make_unique<LayerTree>(
nullptr,
5182 ASSERT_TRUE(ShellTest::ShouldDiscardLayerTree(shell.get(),
kImplicitViewId,
5184 DestroyShell(std::move(shell), task_runners);
TEST_F(FlutterDisplayLinkTest, ViewAddedToWindowFirst)
std::vector< std::unique_ptr< fml::Mapping > > GetAsMappings(const std::string &asset_pattern, const std::optional< std::string > &subdir) const override
Same as GetAsMapping() but returns mappings for all files who's name matches a given pattern....
std::unique_ptr< fml::Mapping > GetAsMapping(const std::string &asset_name) const override
bool PushBack(std::unique_ptr< AssetResolver > resolver)
Adds an asset resolver to the end of the resolver queue. Assets would be loaded from this resolver af...
AssetResolverType
Identifies the type of AssetResolver an instance is.
Represents an instance of a live isolate. An isolate is a separate Dart execution context....
static bool IsRunningPrecompiledCode()
Checks if VM instances in the process can run precompiled code. This call can be made at any time and...
static bool IsInstanceRunning()
sk_sp< DisplayList > Build()
void DrawRect(const DlRect &rect, const DlPaint &paint) override
void PrerollSetup(PrerollContext *context, const DlMatrix &matrix) override
void PrerollFinalize(PrerollContext *context, const DlMatrix &matrix) override
bool TryToPrepareRasterCache(const PaintContext &context, bool parent_cached=false) const override
bool Draw(const PaintContext &context, const DlPaint *paint) const override
static std::shared_ptr< DlImageFilter > MakeBlur(DlScalar sigma_x, DlScalar sigma_y, DlTileMode tile_mode)
Used for fixed refresh rate cases.
static constexpr Phase kPhases[kCount]
fml::TimePoint Set(Phase phase, fml::TimePoint value)
fml::TimePoint Get(Phase phase) const
The minimal interface necessary for defining a decoder that can be used for both single and multi-fra...
void PrerollSetup(PrerollContext *context, const DlMatrix &matrix) override
void PrerollFinalize(PrerollContext *context, const DlMatrix &matrix) override
bool Draw(const PaintContext &context, const DlPaint *paint) const override
bool TryToPrepareRasterCache(const PaintContext &context, bool parent_cached=false) const override
void set_delegate(DlCanvas *canvas)
void set_preroll_delegate(const DlRect &cull_rect, const DlMatrix &matrix)
const std::vector< std::shared_ptr< Mutator > >::const_iterator Begin() const
bool need_caching() const
Specifies all the configuration required by the runtime library to launch the root isolate....
void SetEntrypoint(std::string entrypoint)
Updates the main application entrypoint. If this is not set, the "main" method is used as the entrypo...
static RunConfiguration InferFromSettings(const Settings &settings, const fml::RefPtr< fml::TaskRunner > &io_worker=nullptr, IsolateLaunchType launch_type=IsolateLaunchType::kNewGroup)
Attempts to infer a run configuration from the settings object. This tries to create a run configurat...
virtual bool NotifyIdle(fml::TimeDelta deadline)
Notify the Dart VM that no frame workloads are expected on the UI task runner till the specified dead...
std::map< std::string_view, std::string_view > ServiceProtocolMap
static std::unique_ptr< Shell > Create(const PlatformData &platform_data, const TaskRunners &task_runners, Settings settings, const CreateCallback< PlatformView > &on_create_platform_view, const CreateCallback< Rasterizer > &on_create_rasterizer, bool is_gpu_disabled=false)
Creates a shell instance using the provided settings. The callbacks to create the various shell subco...
const TaskRunners & GetTaskRunners() const override
If callers wish to interact directly with any shell subcomponents, they must (on the platform thread)...
std::shared_ptr< const fml::SyncSwitch > GetIsGpuDisabledSyncSwitch() const override
Accessor for the disable GPU SyncSwitch.
std::function< std::unique_ptr< T >(Shell &)> CreateCallback
bool IsSetup() const
Used by embedders to check if all shell subcomponents are initialized. It is the embedder's responsib...
fml::RefPtr< fml::TaskRunner > GetRasterTaskRunner() const
fml::RefPtr< fml::TaskRunner > GetUITaskRunner() const
fml::RefPtr< fml::TaskRunner > GetPlatformTaskRunner() const
void OnGrContextDestroyed() override
void OnGrContextCreated() override
~MockTexture() override=default
MockTexture(int64_t textureId, std::shared_ptr< fml::AutoResetWaitableEvent > latch)
void OnTextureUnregistered() override
void MarkNewFrameAvailable() override
void Paint(PaintContext &context, const DlRect &bounds, bool freeze, const DlImageSampling) override
static void PlatformViewNotifyDestroyed(Shell *shell)
static void PlatformViewNotifyCreated(Shell *shell)
An image generator that always creates a 1x1 single-frame green image.
unsigned int GetFrameCount() const
Get the number of frames that the encoded image stores. This method is always expected to be called b...
const SkImageInfo & GetInfo()
Returns basic information about the contents of the encoded image. This information can almost always...
const ImageGenerator::FrameInfo GetFrameInfo(unsigned int frame_index)
Get information about a single frame in the context of a multi-frame image, useful for animation and ...
bool GetPixels(const SkImageInfo &info, void *pixels, size_t row_bytes, unsigned int frame_index, std::optional< unsigned int > prior_frame)
Decode the image into a given buffer. This method is currently always used for sub-pixel image decodi...
SinglePixelImageGenerator()
~SinglePixelImageGenerator()=default
SkISize GetScaledDimensions(float scale)
Given a scale value, find the closest image size that can be used for efficiently decoding the image....
unsigned int GetPlayCount() const
The number of times an animated image should play through before playback stops.
TestAssetResolver(bool valid, AssetResolver::AssetResolverType type)
bool IsValidAfterAssetManagerChange() const override
Certain asset resolvers are still valid after the asset manager is replaced before a hot reload,...
bool IsValid() const override
std::unique_ptr< fml::Mapping > GetAsMapping(const std::string &asset_name) const override
bool operator==(const AssetResolver &other) const override
AssetResolver::AssetResolverType GetType() const override
Gets the type of AssetResolver this is. Types are defined in AssetResolverType.
std::vector< std::unique_ptr< fml::Mapping > > GetAsMappings(const std::string &asset_pattern, const std::optional< std::string > &subdir) const override
Same as GetAsMapping() but returns mappings for all files who's name matches a given pattern....
bool IsValid() const override
std::unique_ptr< fml::Mapping > GetAsMapping(const std::string &asset_name) const override
bool operator==(const AssetResolver &other) const override
bool IsValidAfterAssetManagerChange() const override
Certain asset resolvers are still valid after the asset manager is replaced before a hot reload,...
ThreadCheckingAssetResolver(std::shared_ptr< fml::ConcurrentMessageLoop > concurrent_loop)
AssetResolverType GetType() const
Gets the type of AssetResolver this is. Types are defined in AssetResolverType.
std::vector< std::string > mapping_requests
bool WaitWithTimeout(TimeDelta timeout)
static std::unique_ptr< FileMapping > CreateReadOnly(const std::string &path)
static void CaptureNextLog(std::ostringstream *stream)
A Mapping like NonOwnedMapping, but uses Free as its release proc.
static MallocMapping Copy(const T *begin, const T *end)
static void EnsureInitializedForCurrentThread()
fml::RefPtr< fml::TaskRunner > GetTaskRunner() const
static FML_EMBEDDER_ONLY MessageLoop & GetCurrent()
const std::string & path() const
fml::StatusCode code() const
std::string_view message() const
static bool RunsOnTheSameThread(TaskQueueId queue_a, TaskQueueId queue_b)
static void RunNowOrPostTask(const fml::RefPtr< fml::TaskRunner > &runner, const fml::closure &task)
virtual void PostTask(const fml::closure &task) override
virtual bool RunsTasksOnCurrentThread()
virtual TaskQueueId GetTaskQueueId()
static void DisableNextThreadCheckFailure()
constexpr int64_t ToMicroseconds() const
static constexpr TimeDelta Max()
static constexpr TimeDelta FromMicroseconds(int64_t micros)
static constexpr TimeDelta Zero()
constexpr TimeDelta ToEpochDelta() const
static constexpr TimePoint FromEpochDelta(TimeDelta ticks)
const EmbeddedViewParams * params
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
G_BEGIN_DECLS FlutterViewId view_id
FlutterDesktopBinaryReply callback
#define FML_LOG(severity)
static constexpr FlutterViewId kImplicitViewId
std::shared_ptr< ImpellerAllocator > allocator
union flutter::testing::@2883::KeyboardChange::@77 content
static void LogSkData(const sk_sp< SkData > &data, const char *title)
std::string GetCurrentTestName()
Gets the name of the currently running test. This is useful in generating logs or assets based on tes...
TEST_F(DisplayListTest, Defaults)
const char * GetFixturesPath()
Returns the directory containing the test fixture for the target if this target has fixtures configur...
static void ParseViewIdsCallback(const Dart_NativeArguments &args, bool *hasImplicitView, std::vector< int64_t > *viewIds)
static void TestDartVmFlags(std::vector< const char * > &flags)
static sk_sp< DisplayList > MakeSizedDisplayList(int width, int height)
TaskRunners GetTaskRunnersForFixture()
std::function< void(std::shared_ptr< ContainerLayer > root)> LayerTreeBuilder
static void PostSync(const fml::RefPtr< fml::TaskRunner > &task_runner, const fml::closure &task)
static void ParseViewWidthsCallback(const Dart_NativeArguments &args, std::map< int64_t, int64_t > *viewWidths)
static bool ValidateShell(Shell *shell)
static std::string CreateFlagsString(std::vector< const char * > &flags)
TEST(NativeAssetsManagerTest, NoAvailableAssets)
static void CheckFrameTimings(const std::vector< FrameTiming > &timings, fml::TimePoint start, fml::TimePoint finish)
static size_t GetRasterizerResourceCacheBytesSync(const Shell &shell)
static void ValidateDestroyPlatformView(Shell *shell)
static bool RasterizerIsTornDown(Shell *shell)
constexpr int64_t kImplicitViewId
const char * GetSkiaVersion()
static void InvokePlatformMessageResponseCallback(JNIEnv *env, jobject jcaller, jlong shell_holder, jint responseId, jobject message, jint position)
static void InvokePlatformMessageEmptyResponseCallback(JNIEnv *env, jobject jcaller, jlong shell_holder, jint responseId)
impeller::Matrix DlMatrix
impeller::ISize32 DlISize
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
const char * GetFlutterEngineVersion()
static void LoadDartDeferredLibrary(JNIEnv *env, jobject obj, jlong shell_holder, jint jLoadingUnitId, jobjectArray jSearchPaths)
static void SetViewportMetrics(JNIEnv *env, jobject jcaller, jlong shell_holder, jfloat devicePixelRatio, jint physicalWidth, jint physicalHeight, jint physicalPaddingTop, jint physicalPaddingRight, jint physicalPaddingBottom, jint physicalPaddingLeft, jint physicalViewInsetTop, jint physicalViewInsetRight, jint physicalViewInsetBottom, jint physicalViewInsetLeft, jint systemGestureInsetTop, jint systemGestureInsetRight, jint systemGestureInsetBottom, jint systemGestureInsetLeft, jint physicalTouchSlop, jintArray javaDisplayFeaturesBounds, jintArray javaDisplayFeaturesType, jintArray javaDisplayFeaturesState, jint physicalMinWidth, jint physicalMaxWidth, jint physicalMinHeight, jint physicalMaxHeight, jint physicalDisplayCornerRadiusTopLeft, jint physicalDisplayCornerRadiusTopRight, jint physicalDisplayCornerRadiusBottomRight, jint physicalDisplayCornerRadiusBottomLeft)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Settings SettingsFromCommandLine(const fml::CommandLine &command_line, bool require_merged_platform_ui_thread)
TEST_F(EngineAnimatorTest, AnimatorAcceptsMultipleRenders)
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
bool WriteAtomically(const fml::UniqueFD &base_directory, const char *file_name, const Mapping &mapping)
std::string BacktraceHere(size_t offset)
fml::UniqueFD OpenDirectory(const char *path, bool create_if_necessary, FilePermission permission)
RefPtr< T > AdoptRef(T *ptr)
static fml::UniqueFD CreateDirectory(const fml::UniqueFD &base_directory, const std::vector< std::string > &components, FilePermission permission, size_t index)
std::function< void()> closure
static const size_t kGrCacheMaxByteSize
impeller::ShaderType type
static constexpr DlColor kRed()
Info about a single frame in the context of a multi-frame image, useful for animation and blending.
LayerStateStack & state_stack
GrDirectContext * gr_context
bool enable_software_rendering
MergedPlatformUIThread merged_platform_ui_thread
std::shared_ptr< const fml::Mapping > persistent_isolate_data
std::vector< std::string > dart_flags
bool warn_on_impeller_opt_out
The collection of all the threads used by the engine.
std::unique_ptr< fml::Thread > io_thread
std::unique_ptr< fml::Thread > platform_thread
std::unique_ptr< fml::Thread > raster_thread
std::unique_ptr< fml::Thread > ui_thread
double device_pixel_ratio
static FrameContent ImplicitView(double width, double height, LayerTreeBuilder builder)
static FrameContent DummyView(double width=1, double height=1)
Represents the 2 code paths available when calling |SyncSwitchExecute|.
A 4x4 matrix using column-major storage.
static constexpr Matrix MakeTranslation(const Vector3 &t)
static constexpr TRect MakeXYWH(Type x, Type y, Type width, Type height)
static constexpr TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
#define CREATE_NATIVE_ENTRY(native_entry)