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,
189 MOCK_METHOD(std::shared_ptr<fml::BasicTaskRunner>,
190 OnPlatformViewGetShutdownSafeIOTaskRunner,
196 (intptr_t loading_unit_id,
197 std::unique_ptr<const fml::Mapping> snapshot_data,
198 std::unique_ptr<const fml::Mapping> snapshot_instructions),
202 LoadDartDeferredLibraryError,
203 (intptr_t loading_unit_id,
204 const std::string error_message,
209 UpdateAssetResolverByType,
210 (std::unique_ptr<AssetResolver> updated_asset_resolver,
217 MOCK_METHOD(
bool, IsValid, (), (
override));
219 MOCK_METHOD(std::unique_ptr<SurfaceFrame>,
224 MOCK_METHOD(
DlMatrix, GetRootTransformation, (), (
const,
override));
226 MOCK_METHOD(GrDirectContext*, GetContext, (), (
override));
228 MOCK_METHOD(std::unique_ptr<GLContextResult>,
229 MakeRenderContextCurrent,
233 MOCK_METHOD(
bool, ClearRenderContext, (), (
override));
239 const TaskRunners& task_runners)
240 : PlatformView(delegate, task_runners) {}
241 MOCK_METHOD(std::unique_ptr<Surface>, CreateRenderingSurface, (), (
override));
242 MOCK_METHOD(std::shared_ptr<PlatformMessageHandler>,
243 GetPlatformMessageHandler,
248class TestPlatformView :
public PlatformView {
250 TestPlatformView(Shell& shell,
const TaskRunners& task_runners)
251 : PlatformView(shell, task_runners) {}
252 MOCK_METHOD(std::unique_ptr<Surface>, CreateRenderingSurface, (), (
override));
253 MOCK_METHOD(
void, ReleaseResourceContext, (), (
const,
override));
259 HandlePlatformMessage,
260 (std::unique_ptr<PlatformMessage>
message),
263 DoesHandlePlatformMessageOnPlatformThread,
268 (
int response_id, std::unique_ptr<fml::Mapping> mapping),
281 MOCK_METHOD(
void, Complete, (std::unique_ptr<fml::Mapping>
data), (
override));
282 MOCK_METHOD(
void, CompleteEmpty, (), (
override));
289 : valid_(valid), type_(
type) {}
291 bool IsValid()
const override {
return true; }
299 const std::string& asset_name)
const override {
304 const std::string& asset_pattern,
305 const std::optional<std::string>& subdir)
const override {
310 return this == &other;
321 std::shared_ptr<fml::ConcurrentMessageLoop> concurrent_loop)
322 : concurrent_loop_(
std::move(concurrent_loop)) {}
325 bool IsValid()
const override {
return true; }
337 const std::string& asset_name)
const override {
338 if (asset_name ==
"FontManifest.json" ||
339 asset_name ==
"NativeAssetsManifest.json") {
344 EXPECT_TRUE(concurrent_loop_->RunsTasksOnCurrentThread())
352 return this == &other;
356 std::shared_ptr<fml::ConcurrentMessageLoop> concurrent_loop_;
374 shell->GetPlatformView()->NotifyDestroyed();
385 bool is_torn_down =
false;
388 [shell, &latch, &is_torn_down]() {
389 is_torn_down = shell->GetRasterizer()->IsTornDown();
397 ASSERT_TRUE(shell !=
nullptr);
409 std::string flags_string = flags[0];
410 for (
size_t i = 1;
i < flags.size(); ++
i) {
412 flags_string += flags[
i];
419 const std::vector<fml::CommandLine::Option> options = {
423 EXPECT_EQ(settings.
dart_flags.size(), flags.size());
424 for (
size_t i = 0;
i < flags.size(); ++
i) {
443 return builder.
Build();
448 Settings settings = CreateSettingsForFixture();
449 TaskRunners task_runners(
"test",
nullptr,
nullptr,
nullptr,
nullptr);
450 auto shell = CreateShell(settings, task_runners);
457 Settings settings = CreateSettingsForFixture();
468 auto shell = CreateShell(settings, task_runners);
471 DestroyShell(std::move(shell), task_runners);
477 Settings settings = CreateSettingsForFixture();
481 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
483 auto shell = CreateShell(settings, task_runners);
486 DestroyShell(std::move(shell), task_runners);
492 Settings settings = CreateSettingsForFixture();
495 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
497 auto shell = CreateShell(settings, task_runners);
500 DestroyShell(std::move(shell), task_runners);
505 InitializeWithMultipleThreadButCallingThreadAsPlatformThread) {
507 Settings settings = CreateSettingsForFixture();
522 const auto vsync_clock = std::make_shared<ShellTestVsyncClock>();
527 return static_cast<std::unique_ptr<VsyncWaiter>>(
528 std::make_unique<VsyncWaiterFallback>(task_runners));
532 [](
Shell& shell) {
return std::make_unique<Rasterizer>(shell); });
535 DestroyShell(std::move(shell), task_runners);
541 Settings settings = CreateSettingsForFixture();
545 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
547 auto shell = CreateShell({
548 .settings = settings,
549 .task_runners = task_runners,
550 .is_gpu_disabled =
true,
555 bool is_disabled =
false;
556 shell->GetIsGpuDisabledSyncSwitch()->Execute(
558 ASSERT_TRUE(is_disabled);
560 DestroyShell(std::move(shell), task_runners);
566 Settings settings = CreateSettingsForFixture();
577 auto shell = CreateShell(settings, task_runners);
580 DestroyShell(std::move(shell), task_runners);
586 auto settings = CreateSettingsForFixture();
587 auto shell = CreateShell(settings);
591 ASSERT_TRUE(configuration.IsValid());
592 configuration.SetEntrypoint(
"fixturesAreFunctionalMain");
596 "SayHiFromFixturesAreFunctionalMain",
599 RunEngine(shell.get(), std::move(configuration));
602 DestroyShell(std::move(shell));
608 auto settings = CreateSettingsForFixture();
609 auto task_runner = CreateNewThread();
610 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
613 auto shell = CreateShell(settings, task_runners);
617 ASSERT_TRUE(configuration.IsValid());
619 configuration.SetEntrypoint(
"hitTestInsidePlatformViewMain");
620 RunEngine(shell.get(), std::move(configuration));
624 task_runner->PostTask([&shell, &latch]() {
631 HitTestResponse response = shell->GetPlatformView()->HitTest(0, {0.0, 0.0});
637 DestroyShell(std::move(shell), task_runners);
642 auto settings = CreateSettingsForFixture();
643 auto task_runner = CreateNewThread();
644 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
647 auto shell = CreateShell(settings, task_runners);
651 ASSERT_TRUE(configuration.IsValid());
653 configuration.SetEntrypoint(
"hitTestOutsidePlatformViewMain");
654 RunEngine(shell.get(), std::move(configuration));
658 task_runner->PostTask([&shell, &latch]() {
665 HitTestResponse response = shell->GetPlatformView()->HitTest(0, {0.0, 0.0});
671 DestroyShell(std::move(shell), task_runners);
676 auto settings = CreateSettingsForFixture();
677 auto shell = CreateShell(settings);
681 ASSERT_TRUE(configuration.IsValid());
682 configuration.SetEntrypoint(
"testCanLaunchSecondaryIsolate");
689 RunEngine(shell.get(), std::move(configuration));
694 DestroyShell(std::move(shell));
700 auto settings = CreateSettingsForFixture();
701 auto shell = CreateShell(settings);
705 ASSERT_TRUE(configuration.IsValid());
706 std::string entry_point =
"fixturesAreFunctionalMain";
707 configuration.SetEntrypoint(entry_point);
710 std::string last_entry_point;
713 last_entry_point = shell->GetEngine()->GetLastEntrypoint();
717 RunEngine(shell.get(), std::move(configuration));
719 EXPECT_EQ(entry_point, last_entry_point);
721 DestroyShell(std::move(shell));
727 auto settings = CreateSettingsForFixture();
728 auto shell = CreateShell(settings);
732 ASSERT_TRUE(configuration.IsValid());
733 std::string entry_point =
"fixturesAreFunctionalMain";
734 std::vector<std::string> entry_point_args = {
"arg1"};
735 configuration.SetEntrypoint(entry_point);
736 configuration.SetEntrypointArgs(entry_point_args);
739 std::vector<std::string> last_entry_point_args;
742 last_entry_point_args = shell->GetEngine()->GetLastEntrypointArgs();
746 RunEngine(shell.get(), std::move(configuration));
748#if (FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG)
749 EXPECT_EQ(last_entry_point_args, entry_point_args);
751 ASSERT_TRUE(last_entry_point_args.empty());
754 DestroyShell(std::move(shell));
759#if defined(OS_FUCHSIA)
760 GTEST_SKIP() <<
"This test flakes on Fuchsia. https://fxbug.dev/110006 ";
764 ::testing::FLAGS_gtest_death_test_style =
"threadsafe";
766 const std::vector<fml::CommandLine::Option> options = {
771 const char* expected =
772 "Encountered disallowed Dart VM flag: --verify_after_gc";
778 std::vector<const char*> flags = {
779 "--enable-isolate-groups",
780 "--no-enable-isolate-groups",
783 flags.push_back(
"--max_profile_depth 1");
784 flags.push_back(
"--random_seed 42");
785 flags.push_back(
"--max_subtype_cache_entries=22");
787 flags.push_back(
"--enable_mirrors");
795 auto settings = CreateSettingsForFixture();
796 std::unique_ptr<Shell> shell = CreateShell(settings);
799 PlatformViewNotifyCreated(shell.get());
802 configuration.SetEntrypoint(
"emptyMain");
804 RunEngine(shell.get(), std::move(configuration));
805 PumpOneFrame(shell.get());
806 ASSERT_FALSE(GetNeedsReportTimings(shell.get()));
818 ASSERT_EQ(UnreportedTimingsCount(shell.get()), 0);
819 DestroyShell(std::move(shell));
823 auto settings = CreateSettingsForFixture();
824 std::unique_ptr<Shell> shell = CreateShell(settings);
827 PlatformViewNotifyCreated(shell.get());
830 configuration.SetEntrypoint(
"dummyReportTimingsMain");
832 RunEngine(shell.get(), std::move(configuration));
833 PumpOneFrame(shell.get());
834 ASSERT_TRUE(GetNeedsReportTimings(shell.get()));
835 DestroyShell(std::move(shell));
842 for (
size_t i = 0;
i < timings.size();
i += 1) {
855 ASSERT_TRUE(timings[
i].Get(phase) >=
start);
856 ASSERT_TRUE(timings[
i].Get(phase) <= finish);
859 ASSERT_TRUE(last_phase_time <= timings[
i].Get(phase));
860 last_phase_time = timings[
i].Get(phase);
866 auto settings = CreateSettingsForFixture();
867 std::unique_ptr<Shell> shell = CreateShell(settings);
875 PlatformViewNotifyCreated(shell.get());
878 ASSERT_TRUE(configuration.IsValid());
879 configuration.SetEntrypoint(
"reportTimingsMain");
881 std::vector<int64_t> timestamps;
882 auto nativeTimingCallback = [&reportLatch,
883 ×tamps](Dart_NativeArguments
args) {
884 Dart_Handle exception =
nullptr;
885 ASSERT_EQ(timestamps.size(), 0ul);
890 AddNativeCallback(
"NativeReportTimingsCallback",
892 RunEngine(shell.get(), std::move(configuration));
896 for (
int i = 0;
i < 200;
i += 1) {
897 PumpOneFrame(shell.get());
901 DestroyShell(std::move(shell));
904 ASSERT_TRUE(!timestamps.empty());
920 auto settings = CreateSettingsForFixture();
924 settings.frame_rasterized_callback = [&timing,
930 std::unique_ptr<Shell> shell = CreateShell(settings);
933 using namespace std::chrono_literals;
934 std::this_thread::sleep_for(1ms);
945 ASSERT_TRUE(timing.
Get(phase) <
start);
949 PlatformViewNotifyCreated(shell.get());
952 configuration.SetEntrypoint(
"onBeginFrameMain");
954 int64_t frame_target_time;
955 auto nativeOnBeginFrame = [&frame_target_time](Dart_NativeArguments
args) {
956 Dart_Handle exception =
nullptr;
960 AddNativeCallback(
"NativeOnBeginFrame",
963 RunEngine(shell.get(), std::move(configuration));
964 PumpOneFrame(shell.get());
970 std::vector<FrameTiming> timings = {timing};
975 int64_t build_start =
977 ASSERT_GT(frame_target_time, build_start);
978 DestroyShell(std::move(shell));
982 auto settings = CreateSettingsForFixture();
984 bool end_frame_called =
false;
985 auto end_frame_callback =
986 [&](
bool should_resubmit_frame,
988 ASSERT_TRUE(raster_thread_merger.get() ==
nullptr);
989 ASSERT_FALSE(should_resubmit_frame);
990 end_frame_called =
true;
993 auto external_view_embedder = std::make_shared<ShellTestExternalViewEmbedder>(
995 auto shell = CreateShell({
996 .settings = settings,
998 .shell_test_external_view_embedder = external_view_embedder,
1003 PlatformViewNotifyCreated(shell.get());
1006 configuration.SetEntrypoint(
"emptyMain");
1008 RunEngine(shell.get(), std::move(configuration));
1010 LayerTreeBuilder builder = [&](
const std::shared_ptr<ContainerLayer>& root) {
1011 auto display_list_layer = std::make_shared<DisplayListLayer>(
1013 root->Add(display_list_layer);
1017 end_frame_latch.
Wait();
1018 ASSERT_TRUE(end_frame_called);
1020 DestroyShell(std::move(shell));
1024#if defined(OS_FUCHSIA)
1025 GTEST_SKIP() <<
"RasterThreadMerger flakes on Fuchsia. "
1026 "https://github.com/flutter/flutter/issues/59816 ";
1029 auto settings = CreateSettingsForFixture();
1031 std::shared_ptr<ShellTestExternalViewEmbedder> external_view_embedder;
1034 bool end_frame_called =
false;
1035 std::vector<int64_t> visited_platform_views;
1038 auto end_frame_callback =
1039 [&](
bool should_resubmit_frame,
1041 if (end_frame_called) {
1044 ASSERT_TRUE(raster_thread_merger.get() ==
nullptr);
1045 ASSERT_FALSE(should_resubmit_frame);
1046 end_frame_called =
true;
1047 visited_platform_views =
1048 external_view_embedder->GetVisitedPlatformViews();
1049 stack_50 = external_view_embedder->GetStack(50);
1050 stack_75 = external_view_embedder->GetStack(75);
1051 end_frame_latch.
Signal();
1054 external_view_embedder = std::make_shared<ShellTestExternalViewEmbedder>(
1056 auto shell = CreateShell({
1057 .settings = settings,
1059 .shell_test_external_view_embedder = external_view_embedder,
1064 PlatformViewNotifyCreated(shell.get());
1067 configuration.SetEntrypoint(
"emptyMain");
1069 RunEngine(shell.get(), std::move(configuration));
1071 LayerTreeBuilder builder = [&](
const std::shared_ptr<ContainerLayer>& root) {
1072 auto platform_view_layer = std::make_shared<PlatformViewLayer>(
1074 root->Add(platform_view_layer);
1075 auto transform_layer = std::make_shared<TransformLayer>(
1077 root->Add(transform_layer);
1078 auto clip_rect_layer = std::make_shared<ClipRectLayer>(
1080 transform_layer->Add(clip_rect_layer);
1082 auto backdrop_filter_layer =
1083 std::make_shared<BackdropFilterLayer>(filter, DlBlendMode::kSrcOver);
1084 clip_rect_layer->Add(backdrop_filter_layer);
1085 auto platform_view_layer2 = std::make_shared<PlatformViewLayer>(
1087 backdrop_filter_layer->Add(platform_view_layer2);
1091 end_frame_latch.
Wait();
1092 ASSERT_EQ(visited_platform_views, (std::vector<int64_t>{50, 75}));
1097 auto mutator = *stack_50.
Begin();
1099 ASSERT_EQ(mutator->GetFilterMutation().GetFilter(), *filter);
1102 ASSERT_EQ(mutator->GetFilterMutation().GetFilterRect(),
1105 DestroyShell(std::move(shell));
1111 ExternalEmbedderEndFrameIsCalledWhenPostPrerollResultIsResubmit) {
1112#if defined(OS_FUCHSIA)
1113 GTEST_SKIP() <<
"RasterThreadMerger flakes on Fuchsia. "
1114 "https://github.com/flutter/flutter/issues/59816 ";
1117 auto settings = CreateSettingsForFixture();
1119 bool end_frame_called =
false;
1120 auto end_frame_callback =
1121 [&](
bool should_resubmit_frame,
1123 ASSERT_TRUE(raster_thread_merger.get() !=
nullptr);
1124 ASSERT_TRUE(should_resubmit_frame);
1125 end_frame_called =
true;
1126 end_frame_latch.
Signal();
1128 auto external_view_embedder = std::make_shared<ShellTestExternalViewEmbedder>(
1130 auto shell = CreateShell({
1131 .settings = settings,
1133 .shell_test_external_view_embedder = external_view_embedder,
1138 PlatformViewNotifyCreated(shell.get());
1141 configuration.SetEntrypoint(
"emptyMain");
1143 RunEngine(shell.get(), std::move(configuration));
1145 LayerTreeBuilder builder = [&](
const std::shared_ptr<ContainerLayer>& root) {
1146 auto display_list_layer = std::make_shared<DisplayListLayer>(
1148 root->Add(display_list_layer);
1152 end_frame_latch.
Wait();
1154 ASSERT_TRUE(end_frame_called);
1156 DestroyShell(std::move(shell));
1161#if defined(OS_FUCHSIA)
1162 GTEST_SKIP() <<
"RasterThreadMerger flakes on Fuchsia. "
1163 "https://github.com/flutter/flutter/issues/59816 ";
1166 auto settings = CreateSettingsForFixture();
1168 auto end_frame_callback =
1169 [&](
bool should_resubmit_frame,
1171 raster_thread_merger = std::move(thread_merger);
1173 auto external_view_embedder = std::make_shared<ShellTestExternalViewEmbedder>(
1176 auto shell = CreateShell({
1177 .settings = settings,
1179 .shell_test_external_view_embedder = external_view_embedder,
1184 PlatformViewNotifyCreated(shell.get());
1187 configuration.SetEntrypoint(
"emptyMain");
1189 RunEngine(shell.get(), std::move(configuration));
1191 LayerTreeBuilder builder = [&](
const std::shared_ptr<ContainerLayer>& root) {
1192 auto display_list_layer = std::make_shared<DisplayListLayer>(
1194 root->Add(display_list_layer);
1202 PostSync(shell->GetTaskRunners().GetRasterTaskRunner(), [] {});
1203 ASSERT_TRUE(result.ok()) <<
"Result: " <<
static_cast<int>(result.code())
1204 <<
": " << result.message();
1206 ASSERT_TRUE(raster_thread_merger->IsEnabled());
1209 ASSERT_TRUE(raster_thread_merger->IsEnabled());
1213 ASSERT_TRUE(raster_thread_merger->IsEnabled());
1214 DestroyShell(std::move(shell));
1219#if defined(OS_FUCHSIA)
1220 GTEST_SKIP() <<
"RasterThreadMerger flakes on Fuchsia. "
1221 "https://github.com/flutter/flutter/issues/59816 ";
1224 const int ThreadMergingLease = 10;
1225 auto settings = CreateSettingsForFixture();
1227 std::shared_ptr<ShellTestExternalViewEmbedder> external_view_embedder;
1229 auto end_frame_callback =
1230 [&](
bool should_resubmit_frame,
1232 if (should_resubmit_frame && !raster_thread_merger->IsMerged()) {
1233 raster_thread_merger->MergeWithLease(ThreadMergingLease);
1235 ASSERT_TRUE(raster_thread_merger->IsMerged());
1236 external_view_embedder->UpdatePostPrerollResult(
1239 end_frame_latch.
Signal();
1241 external_view_embedder = std::make_shared<ShellTestExternalViewEmbedder>(
1244 external_view_embedder->UpdatePostPrerollResult(
1246 auto shell = CreateShell({
1247 .settings = settings,
1249 .shell_test_external_view_embedder = external_view_embedder,
1254 PlatformViewNotifyCreated(shell.get());
1257 configuration.SetEntrypoint(
"emptyMain");
1259 RunEngine(shell.get(), std::move(configuration));
1261 LayerTreeBuilder builder = [&](
const std::shared_ptr<ContainerLayer>& root) {
1262 auto display_list_layer = std::make_shared<DisplayListLayer>(
1264 root->Add(display_list_layer);
1269 end_frame_latch.
Wait();
1276 shell->GetTaskRunners().GetRasterTaskRunner()->GetTaskQueueId(),
1277 shell->GetTaskRunners().GetPlatformTaskRunner()->GetTaskQueueId()));
1282 shell->GetTaskRunners().GetRasterTaskRunner()->GetTaskQueueId(),
1283 shell->GetTaskRunners().GetPlatformTaskRunner()->GetTaskQueueId()));
1288 DestroyShell(std::move(shell));
1293#if defined(OS_FUCHSIA)
1294 GTEST_SKIP() <<
"RasterThreadMerger flakes on Fuchsia. "
1295 "https://github.com/flutter/flutter/issues/59816 ";
1298 const int kThreadMergingLease = 10;
1299 auto settings = CreateSettingsForFixture();
1301 auto end_frame_callback =
1302 [&](
bool should_resubmit_frame,
1304 if (should_resubmit_frame && !raster_thread_merger->IsMerged()) {
1305 raster_thread_merger->MergeWithLease(kThreadMergingLease);
1307 end_frame_latch.
Signal();
1312 auto external_view_embedder = std::make_shared<ShellTestExternalViewEmbedder>(
1315 auto shell = CreateShell({
1316 .settings = settings,
1318 .shell_test_external_view_embedder = external_view_embedder,
1323 PlatformViewNotifyCreated(shell.get());
1326 configuration.SetEntrypoint(
"emptyMain");
1328 RunEngine(shell.get(), std::move(configuration));
1330 LayerTreeBuilder builder = [&](
const std::shared_ptr<ContainerLayer>& root) {
1331 auto display_list_layer = std::make_shared<DisplayListLayer>(
1333 root->Add(display_list_layer);
1338 end_frame_latch.
Wait();
1340 shell->GetTaskRunners().GetRasterTaskRunner()->GetTaskQueueId(),
1341 shell->GetTaskRunners().GetPlatformTaskRunner()->GetTaskQueueId()));
1345 external_view_embedder->UpdatePostPrerollResult(
1357 shell->GetTaskRunners().GetRasterTaskRunner()->GetTaskQueueId(),
1358 shell->GetTaskRunners().GetPlatformTaskRunner()->GetTaskQueueId()));
1363 DestroyShell(std::move(shell));
1368 OnPlatformViewDestroyWithThreadMergerWhileThreadsAreUnmerged) {
1369#if defined(OS_FUCHSIA)
1370 GTEST_SKIP() <<
"RasterThreadMerger flakes on Fuchsia. "
1371 "https://github.com/flutter/flutter/issues/59816 ";
1374 auto settings = CreateSettingsForFixture();
1376 auto end_frame_callback =
1377 [&](
bool should_resubmit_frame,
1379 end_frame_latch.
Signal();
1381 auto external_view_embedder = std::make_shared<ShellTestExternalViewEmbedder>(
1383 auto shell = CreateShell({
1384 .settings = settings,
1386 .shell_test_external_view_embedder = external_view_embedder,
1391 PlatformViewNotifyCreated(shell.get());
1394 configuration.SetEntrypoint(
"emptyMain");
1396 RunEngine(shell.get(), std::move(configuration));
1398 LayerTreeBuilder builder = [&](
const std::shared_ptr<ContainerLayer>& root) {
1399 auto display_list_layer = std::make_shared<DisplayListLayer>(
1401 root->Add(display_list_layer);
1404 end_frame_latch.
Wait();
1408 shell->GetTaskRunners().GetRasterTaskRunner()->GetTaskQueueId(),
1409 shell->GetTaskRunners().GetPlatformTaskRunner()->GetTaskQueueId()));
1414 shell->GetTaskRunners().GetRasterTaskRunner()->GetTaskQueueId(),
1415 shell->GetTaskRunners().GetPlatformTaskRunner()->GetTaskQueueId()));
1420 DestroyShell(std::move(shell));
1425 auto settings = CreateSettingsForFixture();
1427 auto shell = CreateShell(settings);
1430 PlatformViewNotifyCreated(shell.get());
1433 configuration.SetEntrypoint(
"emptyMain");
1435 RunEngine(shell.get(), std::move(configuration));
1437 LayerTreeBuilder builder = [&](
const std::shared_ptr<ContainerLayer>& root) {
1438 auto display_list_layer = std::make_shared<DisplayListLayer>(
1440 root->Add(display_list_layer);
1446 shell->GetTaskRunners().GetRasterTaskRunner()->GetTaskQueueId(),
1447 shell->GetTaskRunners().GetPlatformTaskRunner()->GetTaskQueueId()));
1452 shell->GetTaskRunners().GetRasterTaskRunner()->GetTaskQueueId(),
1453 shell->GetTaskRunners().GetPlatformTaskRunner()->GetTaskQueueId()));
1458 DestroyShell(std::move(shell));
1463#if defined(OS_FUCHSIA)
1464 GTEST_SKIP() <<
"RasterThreadMerger flakes on Fuchsia. "
1465 "https://github.com/flutter/flutter/issues/59816 ";
1468 auto settings = CreateSettingsForFixture();
1470 auto end_frame_callback =
1471 [&](
bool should_resubmit_frame,
1473 end_frame_latch.
Signal();
1475 auto external_view_embedder = std::make_shared<ShellTestExternalViewEmbedder>(
1487 auto shell = CreateShell({
1488 .settings = settings,
1489 .task_runners = task_runners,
1491 .shell_test_external_view_embedder = external_view_embedder,
1496 PlatformViewNotifyCreated(shell.get());
1499 configuration.SetEntrypoint(
"emptyMain");
1501 RunEngine(shell.get(), std::move(configuration));
1503 LayerTreeBuilder builder = [&](
const std::shared_ptr<ContainerLayer>& root) {
1504 auto display_list_layer = std::make_shared<DisplayListLayer>(
1506 root->Add(display_list_layer);
1509 end_frame_latch.
Wait();
1516 DestroyShell(std::move(shell), task_runners);
1521 auto settings = CreateSettingsForFixture();
1523 std::shared_ptr<ShellTestExternalViewEmbedder> external_view_embedder;
1524 bool used_this_frame =
true;
1525 auto end_frame_callback =
1526 [&](
bool should_resubmit_frame,
1529 used_this_frame = external_view_embedder->GetUsedThisFrame();
1530 end_frame_latch.
Signal();
1532 external_view_embedder = std::make_shared<ShellTestExternalViewEmbedder>(
1534 auto shell = CreateShell({
1535 .settings = settings,
1537 .shell_test_external_view_embedder = external_view_embedder,
1542 PlatformViewNotifyCreated(shell.get());
1545 configuration.SetEntrypoint(
"emptyMain");
1547 RunEngine(shell.get(), std::move(configuration));
1549 LayerTreeBuilder builder = [&](
const std::shared_ptr<ContainerLayer>& root) {
1550 auto display_list_layer = std::make_shared<DisplayListLayer>(
1552 root->Add(display_list_layer);
1555 end_frame_latch.
Wait();
1556 ASSERT_FALSE(used_this_frame);
1561 DestroyShell(std::move(shell));
1567#if defined(OS_FUCHSIA)
1568 GTEST_SKIP() <<
"RasterThreadMerger flakes on Fuchsia. "
1569 "https://github.com/flutter/flutter/issues/59816 ";
1572 auto settings = CreateSettingsForFixture();
1574 std::shared_ptr<ShellTestExternalViewEmbedder> external_view_embedder;
1576 auto end_frame_callback =
1577 [&](
bool should_resubmit_frame,
1579 if (should_resubmit_frame && !raster_thread_merger->IsMerged()) {
1580 raster_thread_merger->MergeWithLease(10);
1581 external_view_embedder->UpdatePostPrerollResult(
1584 end_frame_latch.
Signal();
1586 external_view_embedder = std::make_shared<ShellTestExternalViewEmbedder>(
1589 auto shell = CreateShell({
1590 .settings = settings,
1592 .shell_test_external_view_embedder = external_view_embedder,
1596 PlatformViewNotifyCreated(shell.get());
1599 configuration.SetEntrypoint(
"emptyMain");
1600 RunEngine(shell.get(), std::move(configuration));
1602 ASSERT_EQ(0, external_view_embedder->GetSubmittedFrameCount());
1604 PumpOneFrame(shell.get());
1607 end_frame_latch.
Wait();
1611 end_frame_latch.
Wait();
1614 ASSERT_EQ(1, external_view_embedder->GetSubmittedFrameCount());
1616 PlatformViewNotifyDestroyed(shell.get());
1617 DestroyShell(std::move(shell));
1621TEST(SettingsTest, FrameTimingSetsAndGetsProperly) {
1626 int lastPhaseIndex = -1;
1629 ASSERT_TRUE(phase > lastPhaseIndex);
1630 lastPhaseIndex = phase;
1633 timing.
Set(phase, fake_time);
1634 ASSERT_TRUE(timing.
Get(phase) == fake_time);
1639 auto settings = CreateSettingsForFixture();
1640 std::unique_ptr<Shell> shell = CreateShell(settings);
1643 PlatformViewNotifyCreated(shell.get());
1646 ASSERT_TRUE(configuration.IsValid());
1647 configuration.SetEntrypoint(
"reportTimingsMain");
1649 std::vector<int64_t> timestamps;
1650 auto nativeTimingCallback = [&reportLatch,
1651 ×tamps](Dart_NativeArguments
args) {
1652 Dart_Handle exception =
nullptr;
1653 ASSERT_EQ(timestamps.size(), 0ul);
1655 args, 0, exception);
1658 AddNativeCallback(
"NativeReportTimingsCallback",
1660 ASSERT_TRUE(configuration.IsValid());
1661 RunEngine(shell.get(), std::move(configuration));
1663 for (
int i = 0;
i < 10;
i += 1) {
1664 PumpOneFrame(shell.get());
1668 DestroyShell(std::move(shell));
1676 auto settings = CreateSettingsForFixture();
1677 std::unique_ptr<Shell> shell = CreateShell(settings);
1680 PlatformViewNotifyCreated(shell.get());
1683 configuration.SetEntrypoint(
"emptyMain");
1685 RunEngine(shell.get(), std::move(configuration));
1686 PumpOneFrame(shell.get());
1688 ASSERT_TRUE(result.
ok());
1690 DestroyShell(std::move(shell));
1694 auto settings = CreateSettingsForFixture();
1695 std::unique_ptr<Shell> shell = CreateShell(settings);
1698 PlatformViewNotifyCreated(shell.get());
1701 configuration.SetEntrypoint(
"emptyMain");
1703 RunEngine(shell.get(), std::move(configuration));
1706 EXPECT_FALSE(result.
ok());
1707 EXPECT_EQ(result.
message(),
"timeout");
1710 DestroyShell(std::move(shell));
1714 auto settings = CreateSettingsForFixture();
1715 std::unique_ptr<Shell> shell = CreateShell(settings);
1718 PlatformViewNotifyCreated(shell.get());
1721 configuration.SetEntrypoint(
"emptyMain");
1723 RunEngine(shell.get(), std::move(configuration));
1725 ASSERT_FALSE(result.
ok());
1728 DestroyShell(std::move(shell));
1732 auto settings = CreateSettingsForFixture();
1733 std::unique_ptr<Shell> shell = CreateShell(settings);
1736 PlatformViewNotifyCreated(shell.get());
1739 configuration.SetEntrypoint(
"emptyMain");
1741 RunEngine(shell.get(), std::move(configuration));
1742 PumpOneFrame(shell.get());
1744 ASSERT_TRUE(result.
ok());
1745 for (
int i = 0;
i < 100; ++
i) {
1747 ASSERT_TRUE(result.
ok());
1750 DestroyShell(std::move(shell));
1756 Settings settings = CreateSettingsForFixture();
1757 auto task_runner = CreateNewThread();
1758 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
1760 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
1763 PlatformViewNotifyCreated(shell.get());
1766 configuration.SetEntrypoint(
"emptyMain");
1768 RunEngine(shell.get(), std::move(configuration));
1769 PumpOneFrame(shell.get());
1771 task_runner->PostTask([&shell, &event] {
1773 ASSERT_FALSE(result.
ok());
1779 DestroyShell(std::move(shell), task_runners);
1787 if (auto rasterizer = shell.GetRasterizer()) {
1788 bytes = rasterizer->GetResourceCacheMaxBytes().value_or(0U);
1798 auto settings = CreateSettingsForFixture();
1799 settings.resource_cache_max_bytes_threshold = 4000000U;
1800 GrMockOptions main_context_options;
1801 sk_sp<GrDirectContext> main_context =
1802 GrDirectContext::MakeMock(&main_context_options);
1805 auto result = std::make_unique<TestPlatformView>(shell, task_runners);
1806 ON_CALL(*result, CreateRenderingSurface())
1807 .WillByDefault([main_context] {
1808 auto surface = std::make_unique<MockSurface>();
1809 ON_CALL(*
surface, GetContext())
1810 .WillByDefault(Return(main_context.get()));
1811 ON_CALL(*
surface, IsValid()).WillByDefault(Return(
true));
1812 ON_CALL(*
surface, MakeRenderContextCurrent()).WillByDefault([] {
1813 return std::make_unique<GLContextDefaultResult>(
true);
1820 auto shell = CreateShell({
1821 .settings = settings,
1822 .task_runners = task_runners,
1823 .platform_view_create_callback = platform_view_create_callback,
1827 PlatformViewNotifyCreated(shell.get());
1830 configuration.SetEntrypoint(
"emptyMain");
1832 RunEngine(shell.get(), std::move(configuration));
1833 PostSync(shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell]() {
1834 shell->GetPlatformView()->SetViewportMetrics(kImplicitViewId,
1835 {1.0, 100, 100, 22, 0});
1839 EXPECT_EQ(GetRasterizerResourceCacheBytesSync(*shell),
1840 static_cast<size_t>(480000U));
1842 auto shell_spawn_callback = [&]() {
1843 std::unique_ptr<Shell> spawn;
1845 shell->GetTaskRunners().GetPlatformTaskRunner(),
1846 [
this, &spawn, &spawner = shell, platform_view_create_callback]() {
1847 auto configuration =
1848 RunConfiguration::InferFromSettings(CreateSettingsForFixture());
1849 configuration.SetEntrypoint(
"emptyMain");
1850 spawn = spawner->Spawn(
1851 std::move(configuration),
"", platform_view_create_callback,
1852 [](Shell& shell) { return std::make_unique<Rasterizer>(shell); });
1853 ASSERT_NE(
nullptr, spawn.get());
1854 ASSERT_TRUE(ValidateShell(spawn.get()));
1859 std::unique_ptr<Shell> second_shell = shell_spawn_callback();
1860 PlatformViewNotifyCreated(second_shell.get());
1861 PostSync(second_shell->GetTaskRunners().GetPlatformTaskRunner(),
1863 second_shell->GetPlatformView()->SetViewportMetrics(
1864 kImplicitViewId, {1.0, 100, 100, 22, 0});
1868 static_cast<size_t>(960000U));
1870 PostSync(second_shell->GetTaskRunners().GetPlatformTaskRunner(),
1872 second_shell->GetPlatformView()->SetViewportMetrics(
1873 kImplicitViewId, {1.0, 100, 300, 22, 0});
1877 static_cast<size_t>(1920000U));
1879 std::unique_ptr<Shell> third_shell = shell_spawn_callback();
1880 PlatformViewNotifyCreated(third_shell.get());
1881 PostSync(third_shell->GetTaskRunners().GetPlatformTaskRunner(),
1883 third_shell->GetPlatformView()->SetViewportMetrics(
1884 kImplicitViewId, {1.0, 400, 100, 22, 0});
1888 static_cast<size_t>(3840000U));
1890 PostSync(third_shell->GetTaskRunners().GetPlatformTaskRunner(),
1892 third_shell->GetPlatformView()->SetViewportMetrics(
1893 kImplicitViewId, {1.0, 800, 100, 22, 0});
1897 static_cast<size_t>(4000000U));
1898 DestroyShell(std::move(third_shell), task_runners);
1901 static_cast<size_t>(4000000U));
1903 PostSync(second_shell->GetTaskRunners().GetPlatformTaskRunner(),
1905 second_shell->GetPlatformView()->SetViewportMetrics(
1906 kImplicitViewId, {1.0, 100, 100, 22, 0});
1910 static_cast<size_t>(960000U));
1912 DestroyShell(std::move(second_shell), task_runners);
1913 DestroyShell(std::move(shell), task_runners);
1917 Settings settings = CreateSettingsForFixture();
1918 auto task_runner = CreateNewThread();
1919 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
1921 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
1924 PlatformViewNotifyCreated(shell.get());
1926 auto configuration = RunConfiguration::InferFromSettings(settings);
1927 configuration.SetEntrypoint(
"emptyMain");
1929 RunEngine(shell.get(), std::move(configuration));
1930 PumpOneFrame(shell.get());
1937#if defined(SHELL_ENABLE_VULKAN) && !defined(SHELL_ENABLE_GL)
1940#elif defined(SHELL_ENABLE_METAL)
1942 static_cast<size_t>(256 * (1 << 20)));
1945 static_cast<size_t>(24 * (1 << 20)));
1949 shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell]() {
1950 shell->GetPlatformView()->SetViewportMetrics(kImplicitViewId,
1951 {1.0, 400, 200, 22, 0});
1953 PumpOneFrame(shell.get());
1955 EXPECT_EQ(GetRasterizerResourceCacheBytesSync(*shell), 3840000U);
1957 std::string request_json = R
"json({
1958 "method": "Skia.setResourceCacheMaxBytes",
1963 auto platform_message = std::make_unique<PlatformMessage>(
1964 "flutter/skia", std::move(data),
nullptr);
1965 SendEnginePlatformMessage(shell.get(), std::move(platform_message));
1966 PumpOneFrame(shell.get());
1967 EXPECT_EQ(GetRasterizerResourceCacheBytesSync(*shell), 10000U);
1970 shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell]() {
1971 shell->GetPlatformView()->SetViewportMetrics(kImplicitViewId,
1972 {1.0, 800, 400, 22, 0});
1974 PumpOneFrame(shell.get());
1976 EXPECT_EQ(GetRasterizerResourceCacheBytesSync(*shell), 10000U);
1977 DestroyShell(std::move(shell), task_runners);
1981 Settings settings = CreateSettingsForFixture();
1982 auto task_runner = CreateNewThread();
1983 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
1985 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
1988 shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell]() {
1989 shell->GetPlatformView()->SetViewportMetrics(kImplicitViewId,
1990 {1.0, 400, 200, 22, 0});
1992 PumpOneFrame(shell.get());
1995 PlatformViewNotifyCreated(shell.get());
1997 auto configuration = RunConfiguration::InferFromSettings(settings);
1998 configuration.SetEntrypoint(
"emptyMain");
2000 RunEngine(shell.get(), std::move(configuration));
2001 PumpOneFrame(shell.get());
2003 EXPECT_EQ(GetRasterizerResourceCacheBytesSync(*shell),
2004 static_cast<size_t>(3840000U));
2005 DestroyShell(std::move(shell), task_runners);
2009 Settings settings = CreateSettingsForFixture();
2010 auto task_runner = CreateNewThread();
2011 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
2013 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
2016 shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell]() {
2017 shell->GetPlatformView()->SetViewportMetrics(kImplicitViewId,
2018 {1.0, 400, 200, 22, 0});
2020 PumpOneFrame(shell.get());
2023 PlatformViewNotifyCreated(shell.get());
2025 auto configuration = RunConfiguration::InferFromSettings(settings);
2026 configuration.SetEntrypoint(
"testSkiaResourceCacheSendsResponse");
2028 EXPECT_EQ(GetRasterizerResourceCacheBytesSync(*shell),
2029 static_cast<size_t>(3840000U));
2036 RunEngine(shell.get(), std::move(configuration));
2037 PumpOneFrame(shell.get());
2041 EXPECT_EQ(GetRasterizerResourceCacheBytesSync(*shell),
2042 static_cast<size_t>(10000U));
2043 DestroyShell(std::move(shell), task_runners);
2047 Settings settings = CreateSettingsForFixture();
2048 auto task_runner = CreateNewThread();
2050 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
2053 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
2056 PlatformViewNotifyCreated(shell.get());
2058 auto configuration = RunConfiguration::InferFromSettings(settings);
2059 configuration.SetEntrypoint(
"canCreateImageFromDecompressedData");
2062 AddNativeCallback(
"NotifyWidthHeight",
2065 Dart_GetNativeArgument(
args, 0));
2067 Dart_GetNativeArgument(
args, 1));
2068 ASSERT_EQ(
width, 10);
2073 RunEngine(shell.get(), std::move(configuration));
2076 DestroyShell(std::move(shell), task_runners);
2079class MockTexture :
public Texture {
2082 std::shared_ptr<fml::AutoResetWaitableEvent> latch)
2083 :
Texture(textureId), latch_(
std::move(latch)) {}
2098 frames_available_++;
2103 unregistered_ =
true;
2111 bool unregistered_ =
false;
2112 int frames_available_ = 0;
2113 std::shared_ptr<fml::AutoResetWaitableEvent> latch_;
2117 Settings settings = CreateSettingsForFixture();
2118 auto configuration = RunConfiguration::InferFromSettings(settings);
2119 auto task_runner = CreateNewThread();
2120 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
2122 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
2125 PlatformViewNotifyCreated(shell.get());
2127 RunEngine(shell.get(), std::move(configuration));
2129 std::shared_ptr<fml::AutoResetWaitableEvent> latch =
2130 std::make_shared<fml::AutoResetWaitableEvent>();
2132 std::shared_ptr<MockTexture> mockTexture =
2133 std::make_shared<MockTexture>(0, latch);
2136 shell->GetTaskRunners().GetRasterTaskRunner(), [&]() {
2137 shell->GetPlatformView()->RegisterTexture(mockTexture);
2138 shell->GetPlatformView()->MarkTextureFrameAvailable(0);
2142 EXPECT_EQ(mockTexture->frames_available(), 1);
2145 shell->GetTaskRunners().GetRasterTaskRunner(),
2146 [&]() { shell->GetPlatformView()->UnregisterTexture(0); });
2149 EXPECT_EQ(mockTexture->unregistered(),
true);
2150 DestroyShell(std::move(shell), task_runners);
2154 const std::string
message =
"dummy isolate launch data.";
2156 Settings settings = CreateSettingsForFixture();
2158 std::make_shared<fml::DataMapping>(
message);
2160 GetCurrentTaskRunner(),
2167 AddNativeCallback(
"NotifyMessage",
2169 const auto message_from_dart =
2171 Dart_GetNativeArgument(
args, 0));
2172 ASSERT_EQ(
message, message_from_dart);
2176 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
2178 ASSERT_TRUE(shell->IsSetup());
2179 auto configuration = RunConfiguration::InferFromSettings(settings);
2180 configuration.SetEntrypoint(
"canAccessIsolateLaunchData");
2183 shell->RunEngine(std::move(configuration), [&](
auto result) {
2184 ASSERT_EQ(result, Engine::RunStatus::Success);
2187 message_latch.
Wait();
2188 DestroyShell(std::move(shell), task_runners);
2192 Settings settings = CreateSettingsForFixture();
2199 AddNativeCallback(
"NativeOnBeginFrame",
2203 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
2204 ASSERT_TRUE(shell->IsSetup());
2206 auto configuration = RunConfiguration::InferFromSettings(settings);
2207 configuration.SetEntrypoint(
"onBeginFrameWithNotifyNativeMain");
2208 RunEngine(shell.get(), std::move(configuration));
2214 shell->GetTaskRunners().GetPlatformTaskRunner(),
2215 [&shell]() { shell->GetPlatformView()->ScheduleFrame(); });
2217 DestroyShell(std::move(shell), task_runners);
2221 bool is_on_begin_frame_called =
false;
2222 bool is_secondary_callback_called =
false;
2223 bool test_started =
false;
2224 Settings settings = CreateSettingsForFixture();
2231 AddNativeCallback(
"NativeOnBeginFrame",
2233 if (!test_started) {
2236 EXPECT_FALSE(is_on_begin_frame_called);
2237 EXPECT_FALSE(is_secondary_callback_called);
2238 is_on_begin_frame_called =
true;
2241 std::unique_ptr<Shell> shell = CreateShell({
2242 .settings = settings,
2243 .task_runners = task_runners,
2245 ASSERT_TRUE(shell->IsSetup());
2247 auto configuration = RunConfiguration::InferFromSettings(settings);
2248 configuration.SetEntrypoint(
"onBeginFrameWithNotifyNativeMain");
2249 RunEngine(shell.get(), std::move(configuration));
2255 shell->GetTaskRunners().GetUITaskRunner(), [&]() {
2256 shell->GetEngine()->ScheduleSecondaryVsyncCallback(0, [&]() {
2257 if (!test_started) {
2260 EXPECT_TRUE(is_on_begin_frame_called);
2261 EXPECT_FALSE(is_secondary_callback_called);
2262 is_secondary_callback_called = true;
2263 count_down_latch.CountDown();
2265 shell->GetEngine()->ScheduleFrame();
2266 test_started =
true;
2268 count_down_latch.Wait();
2269 EXPECT_TRUE(is_on_begin_frame_called);
2270 EXPECT_TRUE(is_secondary_callback_called);
2271 DestroyShell(std::move(shell), task_runners);
2274static void LogSkData(
const sk_sp<SkData>& data,
const char* title) {
2275 FML_LOG(ERROR) <<
"---------- " << title;
2276 std::ostringstream ostr;
2277 for (
size_t i = 0;
i <
data->size();) {
2278 ostr << std::hex << std::setfill(
'0') << std::setw(2)
2279 <<
static_cast<int>(
data->bytes()[
i]) <<
" ";
2281 if (
i % 16 == 0 ||
i ==
data->size()) {
2290 auto settings = CreateSettingsForFixture();
2292 settings.frame_rasterized_callback =
2295 std::unique_ptr<Shell> shell = CreateShell(settings);
2298 PlatformViewNotifyCreated(shell.get());
2300 auto configuration = RunConfiguration::InferFromSettings(settings);
2301 configuration.SetEntrypoint(
"emptyMain");
2303 RunEngine(shell.get(), std::move(configuration));
2305 LayerTreeBuilder builder = [&](
const std::shared_ptr<ContainerLayer>& root) {
2306 auto display_list_layer = std::make_shared<DisplayListLayer>(
2308 root->Add(display_list_layer);
2311 PumpOneFrame(shell.get(), ViewContent::ImplicitView(100, 100, builder));
2312 firstFrameLatch.
Wait();
2314 std::promise<Rasterizer::Screenshot> screenshot_promise;
2315 auto screenshot_future = screenshot_promise.get_future();
2318 shell->GetTaskRunners().GetRasterTaskRunner(),
2319 [&screenshot_promise, &shell]() {
2320 auto rasterizer = shell->GetRasterizer();
2321 screenshot_promise.set_value(rasterizer->ScreenshotLastLayerTree(
2322 Rasterizer::ScreenshotType::CompressedImage, false));
2329 fixtures_dir,
"shelltest_screenshot.png");
2333 sk_sp<SkData> reference_data = SkData::MakeWithoutCopy(
2334 reference_png->GetMapping(), reference_png->GetSize());
2336 sk_sp<SkData> screenshot_data = screenshot_future.get().data;
2337 if (!reference_data->equals(screenshot_data.get())) {
2339 LogSkData(screenshot_data,
"screenshot");
2343 DestroyShell(std::move(shell));
2354 std::string dart_isolate_time_str;
2359 dart_isolate_time_str =
2361 Dart_GetNativeArgument(
args, 0));
2365 auto settings = CreateSettingsForFixture();
2366 auto configuration = RunConfiguration::InferFromSettings(settings);
2367 configuration.SetEntrypoint(
"localtimesMatch");
2368 std::unique_ptr<Shell> shell = CreateShell(settings);
2369 ASSERT_NE(shell.get(),
nullptr);
2370 RunEngine(shell.get(), std::move(configuration));
2374 const time_t timestamp = time(
nullptr);
2375 const struct tm* local_time = localtime(×tamp);
2376 ASSERT_NE(local_time,
nullptr)
2377 <<
"Could not get local time: errno=" << errno <<
": " << strerror(errno);
2379 const size_t format_size =
2380 strftime(timestr,
sizeof(timestr),
"%Y-%m-%d %H", local_time);
2381 ASSERT_NE(format_size, 0UL)
2382 <<
"strftime failed: host time: " << std::string(timestr)
2383 <<
" dart isolate time: " << dart_isolate_time_str;
2385 const std::string host_local_time_str = timestr;
2387 ASSERT_EQ(dart_isolate_time_str, host_local_time_str)
2388 <<
"Local times in the dart isolate and the local time seen by the test "
2389 <<
"differ by more than 1 hour, but are expected to be about equal";
2391 DestroyShell(std::move(shell));
2398 : info_(SkImageInfo::MakeN32(1, 1, SkAlphaType::kOpaque_SkAlphaType)) {};
2407 return {std::nullopt, 0, SkCodecAnimation::DisposalMethod::kKeep};
2411 return SkISize::Make(info_.width(), info_.height());
2417 unsigned int frame_index,
2418 std::optional<unsigned int> prior_frame) {
2419 assert(info.width() == 1);
2420 assert(info.height() == 1);
2421 assert(row_bytes == 4);
2423 reinterpret_cast<uint32_t*
>(pixels)[0] = 0x00ff00ff;
2435 Dart_GetNativeArgument(
args, 0));
2437 Dart_GetNativeArgument(
args, 1));
2438 ASSERT_EQ(
width, 1);
2443 auto settings = CreateSettingsForFixture();
2444 auto configuration = RunConfiguration::InferFromSettings(settings);
2445 configuration.SetEntrypoint(
"canRegisterImageDecoders");
2446 std::unique_ptr<Shell> shell = CreateShell(settings);
2447 ASSERT_NE(shell.get(),
nullptr);
2450 shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell]() {
2451 shell->RegisterImageDecoder(
2452 [](const sk_sp<SkData>& buffer) {
2453 return std::make_unique<SinglePixelImageGenerator>();
2458 RunEngine(shell.get(), std::move(configuration));
2460 DestroyShell(std::move(shell));
2466 PersistentCache::SetCacheDirectoryPath(base_dir.
path());
2467 PersistentCache::ResetCacheForProcess();
2471 std::vector<std::string> components = {
2473 PersistentCache::kSkSLSubdirName};
2476 const std::string x_key_str =
"A";
2477 const std::string x_value_str =
"x";
2478 sk_sp<SkData> x_key =
2479 SkData::MakeWithCopy(x_key_str.data(), x_key_str.size());
2480 sk_sp<SkData> x_value =
2481 SkData::MakeWithCopy(x_value_str.data(), x_value_str.size());
2482 auto x_data = PersistentCache::BuildCacheObject(*x_key, *x_value);
2484 const std::string y_key_str =
"B";
2485 const std::string y_value_str =
"y";
2486 sk_sp<SkData> y_key =
2487 SkData::MakeWithCopy(y_key_str.data(), y_key_str.size());
2488 sk_sp<SkData> y_value =
2489 SkData::MakeWithCopy(y_value_str.data(), y_value_str.size());
2490 auto y_data = PersistentCache::BuildCacheObject(*y_key, *y_value);
2495 Settings settings = CreateSettingsForFixture();
2496 std::unique_ptr<Shell> shell = CreateShell(settings);
2498 rapidjson::Document document;
2499 OnServiceProtocol(shell.get(), ServiceProtocolEnum::kGetSkSLs,
2500 shell->GetTaskRunners().GetIOTaskRunner(), empty_params,
2502 rapidjson::StringBuffer
buffer;
2503 rapidjson::Writer<rapidjson::StringBuffer> writer(
buffer);
2504 document.Accept(writer);
2505 DestroyShell(std::move(shell));
2507 const std::string expected_json1 =
2508 "{\"type\":\"GetSkSLs\",\"SkSLs\":{\"II\":\"eQ==\",\"IE\":\"eA==\"}}";
2509 const std::string expected_json2 =
2510 "{\"type\":\"GetSkSLs\",\"SkSLs\":{\"IE\":\"eA==\",\"II\":\"eQ==\"}}";
2511 bool json_is_expected = (expected_json1 ==
buffer.GetString()) ||
2512 (expected_json2 ==
buffer.GetString());
2513 ASSERT_TRUE(json_is_expected) <<
buffer.GetString() <<
" is not equal to "
2514 << expected_json1 <<
" or " << expected_json2;
2518 Settings settings = CreateSettingsForFixture();
2519 auto configuration = RunConfiguration::InferFromSettings(settings);
2520 auto task_runner = CreateNewThread();
2521 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
2523 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
2526 PlatformViewNotifyCreated(shell.get());
2528 RunEngine(shell.get(), std::move(configuration));
2530 auto latch = std::make_shared<fml::AutoResetWaitableEvent>();
2532 PumpOneFrame(shell.get());
2535 shell->GetTaskRunners().GetRasterTaskRunner(), [&shell, &latch]() {
2536 Rasterizer::Screenshot screenshot =
2537 shell->GetRasterizer()->ScreenshotLastLayerTree(
2538 Rasterizer::ScreenshotType::CompressedImage, true);
2539 EXPECT_NE(screenshot.data, nullptr);
2544 DestroyShell(std::move(shell), task_runners);
2548 Settings settings = CreateSettingsForFixture();
2549 auto configuration = RunConfiguration::InferFromSettings(settings);
2550 auto task_runner = CreateNewThread();
2551 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
2553 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
2556 PlatformViewNotifyCreated(shell.get());
2558 RunEngine(shell.get(), std::move(configuration));
2560 auto latch = std::make_shared<fml::AutoResetWaitableEvent>();
2562 PumpOneFrame(shell.get());
2565 shell->GetTaskRunners().GetRasterTaskRunner(), [&shell, &latch]() {
2566 SnapshotDelegate* delegate =
2567 reinterpret_cast<Rasterizer*>(shell->GetRasterizer().get());
2568 sk_sp<SkImage> image = delegate->MakeSkiaSnapshotSync(
2569 MakeSizedDisplayList(50, 50), DlISize(50, 50),
2570 SnapshotPixelFormat::kDontCare);
2571 EXPECT_NE(image, nullptr);
2576 DestroyShell(std::move(shell), task_runners);
2580 Settings settings = CreateSettingsForFixture();
2581 std::unique_ptr<Shell> shell = CreateShell(settings);
2585 auto display_list_layer = std::make_shared<DisplayListLayer>(
2587 display_list_layer->set_paint_bounds(DlRect::MakeWH(100, 100));
2590 std::promise<bool> rasterized;
2592 shell->GetTaskRunners().GetRasterTaskRunner()->PostTask(
2593 [&shell, &rasterized, &display_list, &display_list_layer] {
2594 std::vector<RasterCacheItem*> raster_cache_items;
2595 auto* compositor_context = shell->GetRasterizer()->compositor_context();
2596 auto& raster_cache = compositor_context->raster_cache();
2605 .gr_context =
nullptr,
2606 .dst_color_space =
nullptr,
2607 .view_embedder =
nullptr,
2608 .raster_time = raster_time,
2610 .texture_registry =
nullptr,
2611 .raster_cache = &raster_cache,
2617 .raster_cache = &raster_cache,
2619 .view_embedder =
nullptr,
2620 .state_stack = state_stack,
2621 .dst_color_space =
nullptr,
2622 .surface_needs_readback =
false,
2623 .raster_time = raster_time,
2625 .texture_registry =
nullptr,
2626 .has_platform_view =
false,
2627 .has_texture_layer =
false,
2628 .raster_cached_entries = &raster_cache_items,
2636 bool picture_cache_generated;
2638 display_list, SkPoint(),
true,
false);
2639 for (
int i = 0;
i < 4;
i += 1) {
2642 display_list_raster_cache_item.
PrerollSetup(&preroll_context, matrix);
2645 picture_cache_generated =
2649 display_list_raster_cache_item.
Draw(paint_context, &dummy_canvas,
2652 ASSERT_TRUE(picture_cache_generated);
2661 layer_raster_cache_item.
Draw(paint_context, &dummy_canvas, &paint);
2662 rasterized.set_value(
true);
2664 rasterized.get_future().wait();
2668 rapidjson::Document document;
2670 shell.get(), ServiceProtocolEnum::kEstimateRasterCacheMemory,
2671 shell->GetTaskRunners().GetRasterTaskRunner(), empty_params, &document);
2672 rapidjson::StringBuffer
buffer;
2673 rapidjson::Writer<rapidjson::StringBuffer> writer(
buffer);
2674 document.Accept(writer);
2675 std::string expected_json =
2676 "{\"type\":\"EstimateRasterCacheMemory\",\"layerBytes\":40024,\"picture"
2678 std::string actual_json =
buffer.GetString();
2679 ASSERT_EQ(actual_json, expected_json);
2681 DestroyShell(std::move(shell));
2689 auto settings = CreateSettingsForFixture();
2695 auto end_frame_callback =
2696 [&](
bool should_merge_thread,
2698 end_frame_latch.
Signal();
2700 auto external_view_embedder = std::make_shared<ShellTestExternalViewEmbedder>(
2701 std::move(end_frame_callback), PostPrerollResult::kSuccess,
false);
2702 std::unique_ptr<Shell> shell = CreateShell({
2703 .settings = settings,
2705 .shell_test_external_view_embedder = external_view_embedder,
2710 PlatformViewNotifyCreated(shell.get());
2713 shell->GetTaskRunners().GetPlatformTaskRunner(),
2714 [&shell, &expected_size]() {
2715 shell->GetPlatformView()->SetViewportMetrics(
2717 {1.0, static_cast<double>(expected_size.width),
2718 static_cast<double>(expected_size.height), 22, 0});
2721 auto configuration = RunConfiguration::InferFromSettings(settings);
2722 configuration.SetEntrypoint(
"emptyMain");
2724 RunEngine(shell.get(), std::move(configuration));
2726 PumpOneFrame(shell.get(),
2727 ViewContent::DummyView(
static_cast<double>(wrong_size.width),
2728 static_cast<double>(wrong_size.height)));
2729 end_frame_latch.Wait();
2731 ASSERT_EQ(0, external_view_embedder->GetSubmittedFrameCount());
2733 PumpOneFrame(shell.get(), ViewContent::DummyView(
2734 static_cast<double>(expected_size.width),
2735 static_cast<double>(expected_size.height)));
2736 end_frame_latch.Wait();
2738 ASSERT_EQ(1, external_view_embedder->GetSubmittedFrameCount());
2739 ASSERT_EQ(expected_size, external_view_embedder->GetLastSubmittedFrameSize());
2741 PlatformViewNotifyDestroyed(shell.get());
2742 DestroyShell(std::move(shell));
2750 auto settings = CreateSettingsForFixture();
2759 std::shared_ptr<ShellTestExternalViewEmbedder> external_view_embedder;
2761 auto end_frame_callback =
2762 [&](
bool should_merge_thread,
2764 if (!raster_thread_merger_ref) {
2765 raster_thread_merger_ref = raster_thread_merger;
2767 if (should_merge_thread) {
2768 raster_thread_merger->MergeWithLease(10);
2769 external_view_embedder->UpdatePostPrerollResult(
2770 PostPrerollResult::kSuccess);
2772 end_frame_latch.
Signal();
2774 if (should_merge_thread) {
2775 resize_latch.
Wait();
2779 external_view_embedder = std::make_shared<ShellTestExternalViewEmbedder>(
2780 std::move(end_frame_callback), PostPrerollResult::kResubmitFrame,
true);
2782 std::unique_ptr<Shell> shell = CreateShell({
2783 .settings = settings,
2785 .shell_test_external_view_embedder = external_view_embedder,
2790 PlatformViewNotifyCreated(shell.get());
2793 shell->GetTaskRunners().GetPlatformTaskRunner(),
2794 [&shell, &origin_size]() {
2795 shell->GetPlatformView()->SetViewportMetrics(
2796 kImplicitViewId, {1.0, static_cast<double>(origin_size.width),
2797 static_cast<double>(origin_size.height), 22, 0});
2800 auto configuration = RunConfiguration::InferFromSettings(settings);
2801 configuration.SetEntrypoint(
"emptyMain");
2803 RunEngine(shell.get(), std::move(configuration));
2805 PumpOneFrame(shell.get(),
2806 ViewContent::DummyView(
static_cast<double>(origin_size.width),
2807 static_cast<double>(origin_size.height)));
2809 end_frame_latch.Wait();
2810 ASSERT_EQ(0, external_view_embedder->GetSubmittedFrameCount());
2813 shell->GetTaskRunners().GetPlatformTaskRunner(),
2814 [&shell, &new_size, &resize_latch]() {
2815 shell->GetPlatformView()->SetViewportMetrics(
2816 kImplicitViewId, {1.0, static_cast<double>(new_size.width),
2817 static_cast<double>(new_size.height), 22, 0});
2818 resize_latch.Signal();
2821 end_frame_latch.Wait();
2825 ASSERT_EQ(0, external_view_embedder->GetSubmittedFrameCount());
2828 PumpOneFrame(shell.get(),
2829 ViewContent::DummyView(
static_cast<double>(new_size.width),
2830 static_cast<double>(new_size.height)));
2832 end_frame_latch.Wait();
2833 ASSERT_TRUE(raster_thread_merger_ref->IsMerged());
2834 ASSERT_EQ(1, external_view_embedder->GetSubmittedFrameCount());
2835 ASSERT_EQ(new_size, external_view_embedder->GetLastSubmittedFrameSize());
2837 PlatformViewNotifyDestroyed(shell.get());
2838 DestroyShell(std::move(shell));
2843 double last_device_pixel_ratio;
2846 auto native_report_device_pixel_ratio = [&](Dart_NativeArguments
args) {
2847 auto dpr_handle = Dart_GetNativeArgument(
args, 0);
2848 ASSERT_TRUE(Dart_IsDouble(dpr_handle));
2849 Dart_DoubleValue(dpr_handle, &last_device_pixel_ratio);
2850 ASSERT_FALSE(last_device_pixel_ratio == 0.0);
2852 auto width_handle = Dart_GetNativeArgument(
args, 1);
2853 ASSERT_TRUE(Dart_IsDouble(width_handle));
2854 Dart_DoubleValue(width_handle, &last_width);
2855 ASSERT_FALSE(last_width == 0.0);
2857 auto height_handle = Dart_GetNativeArgument(
args, 2);
2858 ASSERT_TRUE(Dart_IsDouble(height_handle));
2859 Dart_DoubleValue(height_handle, &last_height);
2860 ASSERT_FALSE(last_height == 0.0);
2865 Settings settings = CreateSettingsForFixture();
2866 auto task_runner = CreateNewThread();
2867 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
2870 AddNativeCallback(
"ReportMetrics",
2873 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
2875 auto configuration = RunConfiguration::InferFromSettings(settings);
2876 configuration.SetEntrypoint(
"reportMetrics");
2878 RunEngine(shell.get(), std::move(configuration));
2880 task_runner->PostTask([&]() {
2883 {0.0, 400, 200, 22, 0});
2884 task_runner->PostTask([&]() {
2887 {0.8, 0.0, 200, 22, 0});
2888 task_runner->PostTask([&]() {
2891 {0.8, 400, 0.0, 22, 0});
2892 task_runner->PostTask([&]() {
2894 shell->GetPlatformView()->SetViewportMetrics(
2901 ASSERT_EQ(last_device_pixel_ratio, 0.8);
2902 ASSERT_EQ(last_width, 400.0);
2903 ASSERT_EQ(last_height, 200.0);
2906 task_runner->PostTask([&]() {
2908 {1.2, 600, 300, 22, 0});
2911 ASSERT_EQ(last_device_pixel_ratio, 1.2);
2912 ASSERT_EQ(last_width, 600.0);
2913 ASSERT_EQ(last_height, 300.0);
2915 DestroyShell(std::move(shell), task_runners);
2920 double last_device_pixel_ratio;
2922 auto native_report_device_pixel_ratio = [&](Dart_NativeArguments
args) {
2924 auto dpr_handle = Dart_GetNativeArgument(
args, 0);
2925 ASSERT_TRUE(Dart_IsDouble(dpr_handle));
2926 Dart_DoubleValue(dpr_handle, &last_device_pixel_ratio);
2927 ASSERT_TRUE(last_device_pixel_ratio > 2.5);
2932 Settings settings = CreateSettingsForFixture();
2933 auto task_runner = CreateNewThread();
2934 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
2937 AddNativeCallback(
"ReportMetrics",
2940 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
2942 auto configuration = RunConfiguration::InferFromSettings(settings);
2943 configuration.SetEntrypoint(
"reportMetrics");
2945 RunEngine(shell.get(), std::move(configuration));
2947 task_runner->PostTask([&]() {
2950 shell->GetPlatformView()->SetViewportMetrics(2, {2.0, 400, 200, 22, 0});
2951 task_runner->PostTask([&]() {
2954 {3.0, 400, 200, 22, 0});
2958 ASSERT_EQ(last_device_pixel_ratio, 3.0);
2961 DestroyShell(std::move(shell), task_runners);
2965 Settings settings = CreateSettingsForFixture();
2966 std::unique_ptr<Shell> shell = CreateShell(settings);
2968 RunConfiguration::InferFromSettings(settings);
2969 configuration.
SetEntrypoint(
"canAccessResourceFromAssetDir");
2976 bool can_access_resource =
false;
2977 auto native_can_access_resource = [&can_access_resource,
2978 &latch](Dart_NativeArguments
args) {
2979 Dart_Handle exception =
nullptr;
2980 can_access_resource =
2984 AddNativeCallback(
"NotifyCanAccessResource",
2989 auto native_notify_set_asset_bundle_path =
2990 [&shell](Dart_NativeArguments
args) {
2993 params[
"assetDirectory"] =
"assetDirectory";
2994 rapidjson::Document document;
2995 OnServiceProtocol(shell.get(), ServiceProtocolEnum::kSetAssetBundlePath,
2996 shell->GetTaskRunners().GetUITaskRunner(),
params,
2998 rapidjson::StringBuffer
buffer;
2999 rapidjson::Writer<rapidjson::StringBuffer> writer(
buffer);
3000 document.Accept(writer);
3002 AddNativeCallback(
"NotifySetAssetBundlePath",
3005 RunEngine(shell.get(), std::move(configuration));
3008 ASSERT_TRUE(can_access_resource);
3010 DestroyShell(std::move(shell));
3014 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
3017 auto vm_settings = CreateSettingsForFixture();
3018 auto vm_ref = DartVMRef::Create(vm_settings);
3019 ASSERT_TRUE(DartVMRef::IsInstanceRunning());
3021 auto settings = vm_settings;
3023 settings.root_isolate_create_callback = [&](
const auto& isolate) {
3024 isolate_create_latch.
Signal();
3026 auto shell = CreateShell(settings);
3028 auto configuration = RunConfiguration::InferFromSettings(settings);
3029 ASSERT_TRUE(configuration.IsValid());
3030 RunEngine(shell.get(), std::move(configuration));
3031 ASSERT_TRUE(DartVMRef::IsInstanceRunning());
3032 DestroyShell(std::move(shell));
3033 isolate_create_latch.
Wait();
3041 std::string filename =
"test_name";
3042 std::string
content =
"test_content";
3046 ASSERT_TRUE(success);
3050 std::make_unique<DirectoryAssetBundle>(std::move(asset_dir_fd),
false));
3053 ASSERT_TRUE(mapping !=
nullptr);
3055 std::string result(
reinterpret_cast<const char*
>(mapping->GetMapping()),
3056 mapping->GetSize());
3058 ASSERT_TRUE(result ==
content);
3066 std::vector<std::string> filenames = {
3073 for (
const auto& filename : filenames) {
3076 ASSERT_TRUE(success);
3081 std::make_unique<DirectoryAssetBundle>(std::move(asset_dir_fd),
false));
3083 auto mappings = asset_manager.
GetAsMappings(
"(.*)", std::nullopt);
3084 EXPECT_EQ(mappings.size(), 4u);
3086 std::vector<std::string> expected_results = {
3091 mappings = asset_manager.
GetAsMappings(
"(.*)good(.*)", std::nullopt);
3092 ASSERT_EQ(mappings.size(), expected_results.size());
3094 for (
auto& mapping : mappings) {
3095 std::string result(
reinterpret_cast<const char*
>(mapping->GetMapping()),
3096 mapping->GetSize());
3098 std::find(expected_results.begin(), expected_results.end(), result),
3099 expected_results.end());
3103#if defined(OS_FUCHSIA)
3104TEST_F(ShellTest, AssetManagerMultiSubdir) {
3105 std::string subdir_path =
"subdir";
3114 std::vector<std::string> filenames = {
3120 std::vector<std::string> subdir_filenames = {
3126 for (
auto filename : filenames) {
3129 ASSERT_TRUE(success);
3132 for (
auto filename : subdir_filenames) {
3135 ASSERT_TRUE(success);
3138 AssetManager asset_manager;
3139 asset_manager.PushBack(
3140 std::make_unique<DirectoryAssetBundle>(std::move(asset_dir_fd),
false));
3142 auto mappings = asset_manager.GetAsMappings(
"(.*)", std::nullopt);
3143 EXPECT_EQ(mappings.size(), 5u);
3145 mappings = asset_manager.GetAsMappings(
"(.*)", subdir_path);
3146 EXPECT_EQ(mappings.size(), 3u);
3148 std::vector<std::string> expected_results = {
3153 mappings = asset_manager.GetAsMappings(
"(.*)good(.*)", subdir_path);
3154 ASSERT_EQ(mappings.size(), expected_results.size());
3156 for (
auto& mapping : mappings) {
3157 std::string result(
reinterpret_cast<const char*
>(mapping->GetMapping()),
3158 mapping->GetSize());
3160 std::find(expected_results.begin(), expected_results.end(), result),
3161 expected_results.end());
3167 auto settings = CreateSettingsForFixture();
3168 auto shell = CreateShell(settings);
3171 auto configuration = RunConfiguration::InferFromSettings(settings);
3172 ASSERT_TRUE(configuration.IsValid());
3173 configuration.SetEntrypoint(
"fixturesAreFunctionalMain");
3175 auto second_configuration = RunConfiguration::InferFromSettings(settings);
3176 ASSERT_TRUE(second_configuration.IsValid());
3177 second_configuration.SetEntrypoint(
"testCanLaunchSecondaryIsolate");
3179 const std::string initial_route(
"/foo");
3182 std::string last_entry_point;
3186 last_entry_point = shell->GetEngine()->GetLastEntrypoint();
3198 RunEngine(shell.get(), std::move(configuration));
3200 ASSERT_TRUE(DartVMRef::IsInstanceRunning());
3202 ASSERT_EQ(
"fixturesAreFunctionalMain", last_entry_point);
3205 shell->GetTaskRunners().GetPlatformTaskRunner(),
3206 [
this, &spawner = shell, &second_configuration, &second_latch,
3208 MockPlatformViewDelegate platform_view_delegate;
3209 auto spawn = spawner->Spawn(
3210 std::move(second_configuration), initial_route,
3211 [&platform_view_delegate](Shell& shell) {
3212 auto result = std::make_unique<MockPlatformView>(
3213 platform_view_delegate, shell.GetTaskRunners());
3214 ON_CALL(*result, CreateRenderingSurface()).WillByDefault([] {
3215 return std::make_unique<MockSurface>();
3219 [](
Shell& shell) { return std::make_unique<Rasterizer>(shell); });
3220 ASSERT_NE(
nullptr, spawn.get());
3223 PostSync(spawner->GetTaskRunners().GetUITaskRunner(), [&spawn, &spawner,
3226 ASSERT_EQ(
"testCanLaunchSecondaryIsolate",
3227 spawn->GetEngine()->GetLastEntrypoint());
3228 ASSERT_EQ(initial_route, spawn->GetEngine()->InitialRoute());
3230 ASSERT_NE(spawner->GetEngine()
3231 ->GetRuntimeController()
3232 ->GetRootIsolateGroup(),
3234 ASSERT_EQ(spawner->GetEngine()
3235 ->GetRuntimeController()
3236 ->GetRootIsolateGroup(),
3238 ->GetRuntimeController()
3239 ->GetRootIsolateGroup());
3240 auto spawner_snapshot_delegate = spawner->GetEngine()
3241 ->GetRuntimeController()
3242 ->GetSnapshotDelegate();
3243 auto spawn_snapshot_delegate =
3244 spawn->GetEngine()->GetRuntimeController()->GetSnapshotDelegate();
3245 PostSync(spawner->GetTaskRunners().GetRasterTaskRunner(),
3246 [spawner_snapshot_delegate, spawn_snapshot_delegate] {
3247 ASSERT_NE(spawner_snapshot_delegate.get(),
3248 spawn_snapshot_delegate.get());
3252 spawner->GetTaskRunners().GetIOTaskRunner(), [&spawner, &spawn] {
3253 ASSERT_EQ(spawner->GetIOManager()->GetResourceContext().get(),
3254 spawn->GetIOManager()->GetResourceContext().get());
3259 second_latch.Wait();
3261 DestroyShell(std::move(spawn));
3264 DestroyShell(std::move(shell));
3265 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
3269 auto settings = CreateSettingsForFixture();
3270 auto shell = CreateShell(settings);
3273 auto configuration = RunConfiguration::InferFromSettings(settings);
3274 ASSERT_TRUE(configuration.IsValid());
3275 configuration.SetEntrypoint(
"canReceiveArgumentsWhenEngineRun");
3276 const std::vector<std::string> entrypoint_args{
"foo",
"bar"};
3277 configuration.SetEntrypointArgs(entrypoint_args);
3279 auto second_configuration = RunConfiguration::InferFromSettings(settings);
3280 ASSERT_TRUE(second_configuration.IsValid());
3281 second_configuration.SetEntrypoint(
"canReceiveArgumentsWhenEngineSpawn");
3282 const std::vector<std::string> second_entrypoint_args{
"arg1",
"arg2"};
3283 second_configuration.SetEntrypointArgs(second_entrypoint_args);
3285 const std::string initial_route(
"/foo");
3288 std::string last_entry_point;
3290 AddNativeCallback(
"NotifyNativeWhenEngineRun",
3293 Dart_GetNativeArgument(
args, 0)));
3295 shell->GetEngine()->GetLastEntrypoint();
3301 AddNativeCallback(
"NotifyNativeWhenEngineSpawn",
3304 Dart_GetNativeArgument(
args, 0)));
3306 shell->GetEngine()->GetLastEntrypoint();
3307 second_latch.Signal();
3310 RunEngine(shell.get(), std::move(configuration));
3312 ASSERT_TRUE(DartVMRef::IsInstanceRunning());
3314 ASSERT_EQ(
"canReceiveArgumentsWhenEngineRun", last_entry_point);
3317 shell->GetTaskRunners().GetPlatformTaskRunner(),
3318 [
this, &spawner = shell, &second_configuration, &second_latch,
3320 MockPlatformViewDelegate platform_view_delegate;
3321 auto spawn = spawner->Spawn(
3322 std::move(second_configuration), initial_route,
3323 [&platform_view_delegate](Shell& shell) {
3324 auto result = std::make_unique<MockPlatformView>(
3325 platform_view_delegate, shell.GetTaskRunners());
3326 ON_CALL(*result, CreateRenderingSurface()).WillByDefault([] {
3327 return std::make_unique<MockSurface>();
3331 [](
Shell& shell) { return std::make_unique<Rasterizer>(shell); });
3332 ASSERT_NE(
nullptr, spawn.get());
3335 PostSync(spawner->GetTaskRunners().GetUITaskRunner(),
3336 [&spawn, &spawner, initial_route] {
3338 ASSERT_EQ(
"canReceiveArgumentsWhenEngineSpawn",
3339 spawn->GetEngine()->GetLastEntrypoint());
3340 ASSERT_EQ(initial_route, spawn->GetEngine()->InitialRoute());
3342 ASSERT_NE(spawner->GetEngine()
3343 ->GetRuntimeController()
3344 ->GetRootIsolateGroup(),
3346 ASSERT_EQ(spawner->GetEngine()
3347 ->GetRuntimeController()
3348 ->GetRootIsolateGroup(),
3350 ->GetRuntimeController()
3351 ->GetRootIsolateGroup());
3355 spawner->GetTaskRunners().GetIOTaskRunner(), [&spawner, &spawn] {
3356 ASSERT_EQ(spawner->GetIOManager()->GetResourceContext().get(),
3357 spawn->GetIOManager()->GetResourceContext().get());
3362 second_latch.Wait();
3364 DestroyShell(std::move(spawn));
3367 DestroyShell(std::move(shell));
3368 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
3372 auto settings = CreateSettingsForFixture();
3373 auto shell = CreateShell(settings);
3376 PostSync(shell->GetTaskRunners().GetPlatformTaskRunner(), [
this,
3379 auto second_configuration = RunConfiguration::InferFromSettings(settings);
3380 ASSERT_TRUE(second_configuration.IsValid());
3381 second_configuration.SetEntrypoint(
"emptyMain");
3382 const std::string initial_route(
"/foo");
3383 MockPlatformViewDelegate platform_view_delegate;
3384 auto spawn = spawner->Spawn(
3385 std::move(second_configuration), initial_route,
3386 [&platform_view_delegate](Shell& shell) {
3387 auto result = std::make_unique<MockPlatformView>(
3388 platform_view_delegate, shell.GetTaskRunners());
3389 ON_CALL(*result, CreateRenderingSurface()).WillByDefault([] {
3390 return std::make_unique<MockSurface>();
3394 [](
Shell& shell) { return std::make_unique<Rasterizer>(shell); });
3397 PostSync(spawner->GetTaskRunners().GetIOTaskRunner(), [&spawner, &spawn] {
3398 ASSERT_NE(spawner->GetIOManager().get(), nullptr);
3399 ASSERT_EQ(spawner->GetIOManager().get(), spawn->GetIOManager().get());
3403 DestroyShell(std::move(spawn));
3406 DestroyShell(std::move(shell));
3410 auto settings = CreateSettingsForFixture();
3411 auto shell = CreateShell(settings);
3414 PostSync(shell->GetTaskRunners().GetUITaskRunner(), [&shell] {
3416 auto runtime_controller = shell->GetEngine()->GetRuntimeController();
3417 PostSync(shell->GetTaskRunners().GetIOTaskRunner(),
3418 [&shell, &runtime_controller] {
3420 auto io_manager = runtime_controller->GetIOManager();
3422 ASSERT_NE(io_manager.get(), nullptr);
3423 ASSERT_NE(io_manager->GetSkiaUnrefQueue().get(), nullptr);
3425 ASSERT_NE(shell->GetIOManager().get(), nullptr);
3429 std::unique_ptr<Shell> spawn;
3431 PostSync(shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell, &settings,
3433 auto second_configuration = RunConfiguration::InferFromSettings(settings);
3434 ASSERT_TRUE(second_configuration.IsValid());
3435 second_configuration.SetEntrypoint(
"emptyMain");
3436 const std::string initial_route(
"/foo");
3437 MockPlatformViewDelegate platform_view_delegate;
3438 auto child = shell->Spawn(
3439 std::move(second_configuration), initial_route,
3440 [&platform_view_delegate](Shell& shell) {
3441 auto result = std::make_unique<MockPlatformView>(
3442 platform_view_delegate, shell.GetTaskRunners());
3443 ON_CALL(*result, CreateRenderingSurface()).WillByDefault([] {
3444 return std::make_unique<MockSurface>();
3448 [](
Shell& shell) { return std::make_unique<Rasterizer>(shell); });
3449 spawn = std::move(child);
3452 DestroyShell(std::move(shell));
3454 PostSync(spawn->GetTaskRunners().GetUITaskRunner(), [&spawn] {
3456 auto runtime_controller = spawn->GetEngine()->GetRuntimeController();
3457 PostSync(spawn->GetTaskRunners().GetIOTaskRunner(),
3458 [&spawn, &runtime_controller] {
3460 auto io_manager = runtime_controller->GetIOManager();
3462 ASSERT_NE(io_manager.get(), nullptr);
3463 ASSERT_NE(io_manager->GetSkiaUnrefQueue().get(), nullptr);
3465 ASSERT_NE(spawn->GetIOManager().get(), nullptr);
3469 DestroyShell(std::move(spawn));
3473 auto settings = CreateSettingsForFixture();
3474 auto shell = CreateShell(settings);
3477 std::unique_ptr<Shell> spawn;
3479 PostSync(shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell, &settings,
3481 auto second_configuration = RunConfiguration::InferFromSettings(settings);
3482 ASSERT_TRUE(second_configuration.IsValid());
3483 second_configuration.SetEntrypoint(
"emptyMain");
3484 const std::string initial_route(
"/foo");
3485 MockPlatformViewDelegate platform_view_delegate;
3486 auto child = shell->Spawn(
3487 std::move(second_configuration), initial_route,
3488 [&platform_view_delegate](Shell& shell) {
3489 auto result = std::make_unique<MockPlatformView>(
3490 platform_view_delegate, shell.GetTaskRunners());
3491 ON_CALL(*result, CreateRenderingSurface()).WillByDefault([] {
3492 return std::make_unique<MockSurface>();
3496 [](
Shell& shell) { return std::make_unique<Rasterizer>(shell); });
3497 spawn = std::move(child);
3500 PostSync(spawn->GetTaskRunners().GetUITaskRunner(), [&spawn] {
3501 std::shared_ptr<const DartIsolate> isolate =
3502 spawn->GetEngine()->GetRuntimeController()->GetRootIsolate().lock();
3503 ASSERT_TRUE(isolate);
3504 ASSERT_TRUE(isolate->GetImageGeneratorRegistry());
3508 DestroyShell(std::move(shell));
3510 PostSync(spawn->GetTaskRunners().GetUITaskRunner(), [&spawn] {
3511 std::shared_ptr<const DartIsolate> isolate =
3512 spawn->GetEngine()->GetRuntimeController()->GetRootIsolate().lock();
3513 ASSERT_TRUE(isolate);
3514 ASSERT_TRUE(isolate->GetImageGeneratorRegistry());
3517 DestroyShell(std::move(spawn));
3521 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
3522 Settings settings = CreateSettingsForFixture();
3526 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
3528 auto shell = CreateShell(settings, task_runners);
3529 ASSERT_TRUE(DartVMRef::IsInstanceRunning());
3532 auto configuration = RunConfiguration::InferFromSettings(settings);
3533 configuration.SetEntrypoint(
"emptyMain");
3534 auto asset_manager = configuration.GetAssetManager();
3536 shell->RunEngine(std::move(configuration), [&](
auto result) {
3537 ASSERT_EQ(result, Engine::RunStatus::Success);
3541 std::make_unique<PlatformView>(*shell.get(), task_runners);
3543 auto old_resolver = std::make_unique<TestAssetResolver>(
3544 true, AssetResolver::AssetResolverType::kApkAssetProvider);
3545 ASSERT_TRUE(old_resolver->IsValid());
3546 asset_manager->PushBack(std::move(old_resolver));
3548 auto updated_resolver = std::make_unique<TestAssetResolver>(
3549 false, AssetResolver::AssetResolverType::kApkAssetProvider);
3550 ASSERT_FALSE(updated_resolver->IsValidAfterAssetManagerChange());
3552 std::move(updated_resolver),
3553 AssetResolver::AssetResolverType::kApkAssetProvider);
3555 auto resolvers = asset_manager->TakeResolvers();
3556 ASSERT_EQ(resolvers.size(), 2ull);
3557 ASSERT_TRUE(resolvers[0]->IsValidAfterAssetManagerChange());
3559 ASSERT_FALSE(resolvers[1]->IsValidAfterAssetManagerChange());
3561 DestroyShell(std::move(shell), task_runners);
3562 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
3566 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
3567 Settings settings = CreateSettingsForFixture();
3571 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
3573 auto shell = CreateShell(settings, task_runners);
3574 ASSERT_TRUE(DartVMRef::IsInstanceRunning());
3577 auto configuration = RunConfiguration::InferFromSettings(settings);
3578 configuration.SetEntrypoint(
"emptyMain");
3579 auto asset_manager = configuration.GetAssetManager();
3581 shell->RunEngine(std::move(configuration), [&](
auto result) {
3582 ASSERT_EQ(result, Engine::RunStatus::Success);
3586 std::make_unique<PlatformView>(*shell.get(), task_runners);
3588 auto updated_resolver = std::make_unique<TestAssetResolver>(
3589 false, AssetResolver::AssetResolverType::kApkAssetProvider);
3590 ASSERT_FALSE(updated_resolver->IsValidAfterAssetManagerChange());
3592 std::move(updated_resolver),
3593 AssetResolver::AssetResolverType::kApkAssetProvider);
3595 auto resolvers = asset_manager->TakeResolvers();
3596 ASSERT_EQ(resolvers.size(), 2ull);
3597 ASSERT_TRUE(resolvers[0]->IsValidAfterAssetManagerChange());
3599 ASSERT_FALSE(resolvers[1]->IsValidAfterAssetManagerChange());
3601 DestroyShell(std::move(shell), task_runners);
3602 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
3606 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
3607 Settings settings = CreateSettingsForFixture();
3610 ThreadHost::Type::kPlatform));
3612 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
3614 auto shell = CreateShell(settings, task_runners);
3615 ASSERT_TRUE(DartVMRef::IsInstanceRunning());
3618 auto configuration = RunConfiguration::InferFromSettings(settings);
3619 configuration.SetEntrypoint(
"emptyMain");
3620 auto asset_manager = configuration.GetAssetManager();
3621 RunEngine(shell.get(), std::move(configuration));
3624 std::make_unique<PlatformView>(*shell.get(), task_runners);
3626 auto old_resolver = std::make_unique<TestAssetResolver>(
3627 true, AssetResolver::AssetResolverType::kApkAssetProvider);
3628 ASSERT_TRUE(old_resolver->IsValid());
3629 asset_manager->PushBack(std::move(old_resolver));
3632 nullptr, AssetResolver::AssetResolverType::kApkAssetProvider);
3634 auto resolvers = asset_manager->TakeResolvers();
3635 ASSERT_EQ(resolvers.size(), 2ull);
3636 ASSERT_TRUE(resolvers[0]->IsValidAfterAssetManagerChange());
3637 ASSERT_TRUE(resolvers[1]->IsValidAfterAssetManagerChange());
3639 DestroyShell(std::move(shell), task_runners);
3640 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
3644 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
3645 Settings settings = CreateSettingsForFixture();
3649 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
3651 auto shell = CreateShell(settings, task_runners);
3652 ASSERT_TRUE(DartVMRef::IsInstanceRunning());
3655 auto configuration = RunConfiguration::InferFromSettings(settings);
3656 configuration.SetEntrypoint(
"emptyMain");
3657 auto asset_manager = configuration.GetAssetManager();
3659 shell->RunEngine(std::move(configuration), [&](
auto result) {
3660 ASSERT_EQ(result, Engine::RunStatus::Success);
3664 std::make_unique<PlatformView>(*shell.get(), task_runners);
3666 auto old_resolver = std::make_unique<TestAssetResolver>(
3667 true, AssetResolver::AssetResolverType::kAssetManager);
3668 ASSERT_TRUE(old_resolver->IsValid());
3669 asset_manager->PushBack(std::move(old_resolver));
3671 auto updated_resolver = std::make_unique<TestAssetResolver>(
3672 false, AssetResolver::AssetResolverType::kApkAssetProvider);
3673 ASSERT_FALSE(updated_resolver->IsValidAfterAssetManagerChange());
3675 std::move(updated_resolver),
3676 AssetResolver::AssetResolverType::kApkAssetProvider);
3678 auto resolvers = asset_manager->TakeResolvers();
3679 ASSERT_EQ(resolvers.size(), 3ull);
3680 ASSERT_TRUE(resolvers[0]->IsValidAfterAssetManagerChange());
3682 ASSERT_TRUE(resolvers[1]->IsValidAfterAssetManagerChange());
3684 ASSERT_FALSE(resolvers[2]->IsValidAfterAssetManagerChange());
3686 DestroyShell(std::move(shell), task_runners);
3687 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
3695 auto settings = CreateSettingsForFixture();
3696 std::unique_ptr<Shell> shell = CreateShell({
3697 .settings = settings,
3699 .rendering_backend = ShellTestPlatformView::BackendType::kGLBackend,
3702 ASSERT_NE(shell,
nullptr);
3703 ASSERT_TRUE(shell->IsSetup());
3704 auto configuration = RunConfiguration::InferFromSettings(settings);
3705 PlatformViewNotifyCreated(shell.get());
3706 configuration.SetEntrypoint(
"emptyMain");
3707 RunEngine(shell.get(), std::move(configuration));
3708 PumpOneFrame(shell.get());
3709 PlatformViewNotifyDestroyed(shell.get());
3710 DestroyShell(std::move(shell));
3715#if !SHELL_ENABLE_VULKAN
3718 auto settings = CreateSettingsForFixture();
3719 std::unique_ptr<Shell> shell = CreateShell({
3720 .settings = settings,
3722 .rendering_backend =
3723 ShellTestPlatformView::BackendType::kVulkanBackend,
3726 ASSERT_NE(shell,
nullptr);
3727 ASSERT_TRUE(shell->IsSetup());
3728 auto configuration = RunConfiguration::InferFromSettings(settings);
3729 PlatformViewNotifyCreated(shell.get());
3730 configuration.SetEntrypoint(
"emptyMain");
3731 RunEngine(shell.get(), std::move(configuration));
3732 PumpOneFrame(shell.get());
3733 PlatformViewNotifyDestroyed(shell.get());
3734 DestroyShell(std::move(shell));
3739#if !SHELL_ENABLE_METAL
3742 auto settings = CreateSettingsForFixture();
3743 std::unique_ptr<Shell> shell = CreateShell({
3744 .settings = settings,
3746 .rendering_backend =
3747 ShellTestPlatformView::BackendType::kMetalBackend,
3750 ASSERT_NE(shell,
nullptr);
3751 ASSERT_TRUE(shell->IsSetup());
3752 auto configuration = RunConfiguration::InferFromSettings(settings);
3753 PlatformViewNotifyCreated(shell.get());
3754 configuration.SetEntrypoint(
"emptyMain");
3755 RunEngine(shell.get(), std::move(configuration));
3756 PumpOneFrame(shell.get());
3757 PlatformViewNotifyDestroyed(shell.get());
3758 DestroyShell(std::move(shell));
3763 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
3766 auto vm_settings = CreateSettingsForFixture();
3767 auto vm_ref = DartVMRef::Create(vm_settings);
3768 ASSERT_TRUE(DartVMRef::IsInstanceRunning());
3770 auto settings = vm_settings;
3774 settings.root_isolate_create_callback = [&](
const DartIsolate& isolate) {
3775 Dart_Handle current_tag = Dart_GetCurrentUserTag();
3776 Dart_Handle startup_tag = Dart_NewUserTag(
"AppStartUp");
3777 EXPECT_TRUE(Dart_IdentityEquals(current_tag, startup_tag));
3779 isolate_create_latch.
Signal();
3782 auto shell = CreateShell(settings);
3785 auto configuration = RunConfiguration::InferFromSettings(settings);
3786 ASSERT_TRUE(configuration.IsValid());
3788 RunEngine(shell.get(), std::move(configuration));
3789 ASSERT_TRUE(DartVMRef::IsInstanceRunning());
3791 DestroyShell(std::move(shell));
3792 isolate_create_latch.
Wait();
3796 auto settings = CreateSettingsForFixture();
3797 settings.prefetched_default_font_manager =
true;
3798 std::unique_ptr<Shell> shell;
3800 auto get_font_manager_count = [&] {
3802 size_t font_manager_count;
3804 shell->GetTaskRunners().GetUITaskRunner(),
3805 [
this, &shell, &latch, &font_manager_count]() {
3806 font_manager_count =
3807 GetFontCollection(shell.get())->GetFontManagersCount();
3811 return font_manager_count;
3813 size_t initial_font_manager_count = 0;
3814 settings.root_isolate_create_callback = [&](
const auto& isolate) {
3815 ASSERT_GT(initial_font_manager_count, 0ul);
3818 ASSERT_EQ(get_font_manager_count(), initial_font_manager_count);
3821 shell = CreateShell(settings);
3823 initial_font_manager_count = get_font_manager_count();
3825 auto configuration = RunConfiguration::InferFromSettings(settings);
3826 configuration.SetEntrypoint(
"emptyMain");
3827 RunEngine(shell.get(), std::move(configuration));
3831 ASSERT_EQ(get_font_manager_count(), initial_font_manager_count + 1);
3833 DestroyShell(std::move(shell));
3839 auto settings = CreateSettingsForFixture();
3840 auto shell = CreateShell(settings);
3844 [&latch]() { latch.Wait(); });
3846 ShellTest::PlatformViewNotifyCreated(shell.get());
3849 DestroyShell(std::move(shell));
3853 auto settings = CreateSettingsForFixture();
3854 auto shell = CreateShell(settings);
3855 auto configuration = RunConfiguration::InferFromSettings(settings);
3856 configuration.SetEntrypoint(
"drawFrames");
3861 notify_native_latch.
Signal();
3865 RunEngine(shell.get(), std::move(configuration));
3868 notify_native_latch.
Wait();
3870 ShellTest::PlatformViewNotifyCreated(shell.get());
3874 shell->GetTaskRunners().GetPlatformTaskRunner(),
3875 [&shell, &destroy_latch]() {
3876 shell->GetPlatformView()->NotifyDestroyed();
3877 destroy_latch.Signal();
3880 destroy_latch.
Wait();
3889 shell->GetTaskRunners().GetUITaskRunner(),
3890 [&ui_flush_latch]() { ui_flush_latch.Signal(); });
3891 ui_flush_latch.
Wait();
3892 DestroyShell(std::move(shell));
3897 auto settings = CreateSettingsForFixture();
3898 MockPlatformViewDelegate platform_view_delegate;
3899 auto platform_message_handler =
3900 std::make_shared<MockPlatformMessageHandler>();
3902 EXPECT_CALL(*platform_message_handler, HandlePlatformMessage(_));
3903 EXPECT_CALL(*platform_message_handler,
3904 InvokePlatformMessageEmptyResponseCallback(message_id));
3906 [&platform_view_delegate, task_runners,
3908 auto result = std::make_unique<MockPlatformView>(platform_view_delegate,
3910 EXPECT_CALL(*result, GetPlatformMessageHandler())
3911 .WillOnce(Return(platform_message_handler));
3914 auto shell = CreateShell({
3915 .settings = settings,
3916 .task_runners = task_runners,
3917 .platform_view_create_callback = platform_view_create_callback,
3920 EXPECT_EQ(platform_message_handler, shell->GetPlatformMessageHandler());
3922 size_t data_size = 4;
3923 fml::MallocMapping bytes =
3924 fml::MallocMapping(static_cast<uint8_t*>(malloc(data_size)), data_size);
3925 fml::RefPtr<MockPlatformMessageResponse> response =
3926 MockPlatformMessageResponse::Create();
3927 auto message = std::make_unique<PlatformMessage>(
3928 "foo", std::move(bytes), response);
3929 (static_cast<Engine::Delegate*>(shell.get()))
3930 ->OnEngineHandlePlatformMessage(std::move(message));
3932 shell->GetPlatformMessageHandler()
3933 ->InvokePlatformMessageEmptyResponseCallback(message_id);
3934 DestroyShell(std::move(shell));
3938 auto settings = CreateSettingsForFixture();
3939 auto shell = CreateShell(settings);
3942 auto configuration = RunConfiguration::InferFromSettings(settings);
3943 ASSERT_TRUE(configuration.IsValid());
3944 configuration.SetEntrypoint(
"onErrorA");
3946 auto second_configuration = RunConfiguration::InferFromSettings(settings);
3947 ASSERT_TRUE(second_configuration.IsValid());
3948 second_configuration.SetEntrypoint(
"onErrorB");
3954 auto string_handle = Dart_GetNativeArgument(
args, 0);
3956 Dart_StringToCString(string_handle, &c_str);
3957 EXPECT_STREQ(c_str,
"Exception: I should be coming from A");
3963 auto string_handle = Dart_GetNativeArgument(
args, 0);
3965 Dart_StringToCString(string_handle, &c_str);
3966 EXPECT_STREQ(c_str,
"Exception: I should be coming from B");
3970 RunEngine(shell.get(), std::move(configuration));
3972 ASSERT_TRUE(DartVMRef::IsInstanceRunning());
3975 shell->GetTaskRunners().GetPlatformTaskRunner(),
3976 [
this, &spawner = shell, &second_configuration, &latch]() {
3977 ::testing::NiceMock<MockPlatformViewDelegate> platform_view_delegate;
3978 auto spawn = spawner->Spawn(
3979 std::move(second_configuration),
"",
3980 [&platform_view_delegate](Shell& shell) {
3982 std::make_unique<::testing::NiceMock<MockPlatformView>>(
3983 platform_view_delegate, shell.GetTaskRunners());
3984 ON_CALL(*result, CreateRenderingSurface()).WillByDefault([] {
3985 return std::make_unique<::testing::NiceMock<MockSurface>>();
3989 [](
Shell& shell) { return std::make_unique<Rasterizer>(shell); });
3990 ASSERT_NE(
nullptr, spawn.get());
3997 DestroyShell(std::move(spawn));
4000 DestroyShell(std::move(shell));
4001 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
4005 Settings settings = CreateSettingsForFixture();
4006 auto task_runner = CreateNewThread();
4007 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
4009 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
4012 AddNativeCallback(
"NotifyNative",
4016 PlatformViewNotifyCreated(shell.get());
4018 auto configuration = RunConfiguration::InferFromSettings(settings);
4019 configuration.SetEntrypoint(
"testThatAssetLoadingHappensOnWorkerThread");
4020 auto asset_manager = configuration.GetAssetManager();
4021 auto test_resolver = std::make_unique<ThreadCheckingAssetResolver>(
4022 shell->GetDartVM()->GetConcurrentMessageLoop());
4023 auto leaked_resolver = test_resolver.get();
4024 asset_manager->PushBack(std::move(test_resolver));
4026 RunEngine(shell.get(), std::move(configuration));
4027 PumpOneFrame(shell.get());
4031 EXPECT_EQ(leaked_resolver->mapping_requests[0],
"DoesNotExist");
4033 PlatformViewNotifyDestroyed(shell.get());
4034 DestroyShell(std::move(shell), task_runners);
4042 auto settings = CreateSettingsForFixture();
4043 std::unique_ptr<Shell> shell = CreateShell({
4044 .settings = settings,
4046 .rendering_backend = ShellTestPlatformView::BackendType::kGLBackend,
4050 AddNativeCallback(
"NativeOnBeforeToImageSync",
4058 PlatformViewNotifyDestroyed(shell.get());
4059 PlatformViewNotifyCreated(shell.get());
4063 ASSERT_NE(shell,
nullptr);
4064 ASSERT_TRUE(shell->IsSetup());
4065 auto configuration = RunConfiguration::InferFromSettings(settings);
4066 PlatformViewNotifyCreated(shell.get());
4067 configuration.SetEntrypoint(
"toImageSync");
4068 RunEngine(shell.get(), std::move(configuration));
4069 PumpOneFrame(shell.get());
4073 PlatformViewNotifyDestroyed(shell.get());
4074 DestroyShell(std::move(shell));
4079#if !SHELL_ENABLE_METAL
4083 auto settings = CreateSettingsForFixture();
4084 settings.enable_impeller =
true;
4085 std::unique_ptr<Shell> shell = CreateShell({
4086 .settings = settings,
4088 .rendering_backend =
4089 ShellTestPlatformView::BackendType::kMetalBackend,
4093 AddNativeCallback(
"NativeOnBeforeToImageSync",
4101 PlatformViewNotifyDestroyed(shell.get());
4102 PlatformViewNotifyCreated(shell.get());
4106 ASSERT_NE(shell,
nullptr);
4107 ASSERT_TRUE(shell->IsSetup());
4108 auto configuration = RunConfiguration::InferFromSettings(settings);
4114 configuration.SetEntrypoint(
"toImageSync");
4115 RunEngine(shell.get(), std::move(configuration));
4116 PumpOneFrame(shell.get());
4120 PlatformViewNotifyDestroyed(shell.get());
4121 DestroyShell(std::move(shell));
4127TEST_F(ShellTest, PictureToImageSyncWithTrampledContext) {
4130 ThreadHost thread_host(
"io.flutter.test." + GetCurrentTestName() +
".",
4131 ThreadHost::Type::kPlatform);
4132 auto task_runner = thread_host.platform_thread->GetTaskRunner();
4133 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
4136 auto settings = CreateSettingsForFixture();
4137 std::unique_ptr<Shell> shell = CreateShell({
4138 .settings = settings,
4139 .task_runners = task_runners,
4140 .platform_view_create_callback = ShellTestPlatformViewBuilder({
4141 .rendering_backend = ShellTestPlatformView::BackendType::kGLBackend,
4150 ::eglMakeCurrent(::eglGetCurrentDisplay(), NULL, NULL, NULL);
4156 PlatformViewNotifyDestroyed(shell.get());
4157 PlatformViewNotifyCreated(shell.get());
4161 ASSERT_NE(shell,
nullptr);
4162 ASSERT_TRUE(shell->IsSetup());
4163 auto configuration = RunConfiguration::InferFromSettings(settings);
4164 PlatformViewNotifyCreated(shell.get());
4165 configuration.SetEntrypoint(
"toImageSync");
4166 RunEngine(shell.get(), std::move(configuration));
4167 PumpOneFrame(shell.get());
4171 PlatformViewNotifyDestroyed(shell.get());
4172 DestroyShell(std::move(shell), task_runners);
4177 auto settings = CreateSettingsForFixture();
4178 std::unique_ptr<Shell> shell = CreateShell(settings);
4183 Dart_Handle exception =
nullptr;
4185 args, 0, exception);
4189 ASSERT_NE(shell,
nullptr);
4190 ASSERT_TRUE(shell->IsSetup());
4191 auto configuration = RunConfiguration::InferFromSettings(settings);
4192 PlatformViewNotifyCreated(shell.get());
4193 configuration.SetEntrypoint(
"testPluginUtilitiesCallbackHandle");
4194 RunEngine(shell.get(), std::move(configuration));
4195 PumpOneFrame(shell.get());
4199 ASSERT_TRUE(test_passed);
4201 PlatformViewNotifyDestroyed(shell.get());
4202 DestroyShell(std::move(shell));
4206 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
4207 Settings settings = CreateSettingsForFixture();
4209 ThreadHost::Type::kPlatform | ThreadHost::kUi |
4210 ThreadHost::kIo | ThreadHost::kRaster);
4211 auto platform_task_runner = thread_host.
platform_thread->GetTaskRunner();
4215 thread_host.
io_thread->GetTaskRunner());
4216 auto shell = CreateShell(settings, task_runners);
4217 ASSERT_TRUE(DartVMRef::IsInstanceRunning());
4222 auto configuration = RunConfiguration::InferFromSettings(settings);
4223 configuration.SetEntrypoint(
"emptyMain");
4224 RunEngine(shell.get(), std::move(configuration));
4228 auto runtime_controller = const_cast<RuntimeController*>(
4229 shell->GetEngine()->GetRuntimeController());
4231 auto now = fml::TimeDelta::FromMicroseconds(Dart_TimelineGetMicros());
4233 EXPECT_FALSE(runtime_controller->NotifyIdle(
4234 now - fml::TimeDelta::FromMilliseconds(10)));
4235 EXPECT_FALSE(runtime_controller->NotifyIdle(now));
4236 EXPECT_FALSE(runtime_controller->NotifyIdle(
4237 now + fml::TimeDelta::FromNanoseconds(100)));
4239 EXPECT_TRUE(runtime_controller->NotifyIdle(
4240 now + fml::TimeDelta::FromMilliseconds(100)));
4246 DestroyShell(std::move(shell), task_runners);
4247 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
4251 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
4252 Settings settings = CreateSettingsForFixture();
4254 ThreadHost::Type::kPlatform | ThreadHost::kUi |
4255 ThreadHost::kIo | ThreadHost::kRaster);
4256 auto platform_task_runner = thread_host.
platform_thread->GetTaskRunner();
4260 thread_host.
io_thread->GetTaskRunner());
4261 auto shell = CreateShell(settings, task_runners);
4262 ASSERT_TRUE(DartVMRef::IsInstanceRunning());
4271 Dart_Handle exception =
nullptr;
4272 bool is_in_latency_mode =
4275 shell->GetEngine()->GetRuntimeController());
4278 Dart_TimelineGetMicros() + 100000));
4279 EXPECT_EQ(success, !is_in_latency_mode);
4283 auto configuration = RunConfiguration::InferFromSettings(settings);
4284 configuration.SetEntrypoint(
"performanceModeImpactsNotifyIdle");
4285 RunEngine(shell.get(), std::move(configuration));
4289 DestroyShell(std::move(shell), task_runners);
4290 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
4294#if FLUTTER_RUNTIME_MODE != FLUTTER_RUNTIME_MODE_DEBUG || OS_FUCHSIA
4295 GTEST_SKIP() <<
"Test is for debug mode only on non-fuchsia targets.";
4297 Settings settings = CreateSettingsForFixture();
4299 ThreadHost::Type::kPlatform);
4301 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
4303 auto shell = CreateShell(settings, task_runners);
4310 SendPlatformMessage(shell.get(), std::make_unique<PlatformMessage>(
4311 "com.test.plugin",
nullptr));
4315 ::testing::EndsWith(
4316 "The 'com.test.plugin' channel sent a message from native to "
4317 "Flutter on a non-platform thread. Platform channel messages "
4318 "must be sent on the platform thread. Failure to do so may "
4319 "result in data loss or crashes, and must be fixed in the "
4320 "plugin or application code creating that channel.\nSee "
4321 "https://docs.flutter.dev/platform-integration/"
4322 "platform-channels#channels-and-platform-threading for more "
4331 SendPlatformMessage(shell.get(), std::make_unique<PlatformMessage>(
4332 "com.test.plugin",
nullptr));
4334 EXPECT_EQ(log_capture.
str(),
"");
4337 DestroyShell(std::move(shell), task_runners);
4338 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
4343 Settings settings = CreateSettingsForFixture();
4345 ThreadHost::Type::kPlatform);
4347 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
4349 auto shell = CreateShell(settings, task_runners);
4351 auto latch = std::make_shared<fml::CountDownLatch>(1u);
4352 task_runner->PostTask([&]() {
4353 auto message = MakePlatformMessage(
4354 "flutter/navigation",
4355 {{
"method",
"setInitialRoute"}, {
"args",
"/testo"}},
nullptr);
4356 SendPlatformMessage(shell.get(), std::move(
message));
4357 EXPECT_EQ(shell->GetEngine()->InitialRoute(),
"/testo");
4363 DestroyShell(std::move(shell), task_runners);
4364 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
4369 Settings settings = CreateSettingsForFixture();
4371 ThreadHost::Type::kPlatform);
4373 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
4378 auto shell = CreateShell(settings, task_runners);
4379 auto configuration = RunConfiguration::InferFromSettings(settings);
4380 configuration.SetEntrypoint(
"testSemanticsActions");
4382 RunEngine(shell.get(), std::move(configuration));
4392 SendSemanticsAction(shell.get(), 456, 0, SemanticsAction::kTap,
4397 DestroyShell(std::move(shell), task_runners);
4398 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
4403 Settings settings = CreateSettingsForFixture();
4405 ThreadHost::Type::kPlatform);
4407 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
4412 auto shell = CreateShell(settings, task_runners);
4413 auto configuration = RunConfiguration::InferFromSettings(settings);
4414 configuration.SetEntrypoint(
"testPointerActions");
4416 RunEngine(shell.get(), std::move(configuration));
4425 DispatchFakePointerData(shell.get(), 23);
4428 DestroyShell(std::move(shell), task_runners);
4429 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
4434 Settings settings = CreateSettingsForFixture();
4436 ThreadHost::Type::kPlatform);
4438 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
4443 auto shell = CreateShell(settings, task_runners);
4444 auto configuration = RunConfiguration::InferFromSettings(settings);
4445 configuration.SetEntrypoint(
"testDispatchEvents");
4447 RunEngine(shell.get(), std::move(configuration));
4449 bool did_invoke_callback =
false;
4455 did_invoke_callback =
true;
4459 DispatchFakePointerData(shell.get(), 23);
4460 EXPECT_FALSE(did_invoke_callback);
4462 EXPECT_TRUE(did_invoke_callback);
4464 DestroyShell(std::move(shell), task_runners);
4465 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
4469#if defined(OS_FUCHSIA)
4470 GTEST_SKIP() <<
"Fuchsia";
4472 ::testing::FLAGS_gtest_death_test_style =
"threadsafe";
4473 Settings settings = CreateSettingsForFixture();
4477 ThreadHost::Type::kPlatform);
4479 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
4481 EXPECT_DEATH_IF_SUPPORTED(
4482 CreateShell(settings, task_runners),
4483 "Software rendering is incompatible with Impeller.");
4490 bool* hasImplicitView,
4491 std::vector<int64_t>* viewIds) {
4492 Dart_Handle exception =
nullptr;
4496 ASSERT_EQ(exception,
nullptr);
4498 args, 1, exception);
4499 ASSERT_EQ(exception,
nullptr);
4503 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
4504 Settings settings = CreateSettingsForFixture();
4505 auto task_runner = CreateNewThread();
4506 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
4508 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
4511 bool hasImplicitView;
4512 std::vector<int64_t> viewIds;
4514 auto nativeViewIdsCallback = [&reportLatch, &hasImplicitView,
4515 &viewIds](Dart_NativeArguments
args) {
4519 AddNativeCallback(
"NativeReportViewIdsCallback",
4522 PlatformViewNotifyCreated(shell.get());
4523 auto configuration = RunConfiguration::InferFromSettings(settings);
4524 configuration.SetEntrypoint(
"testReportViewIds");
4525 RunEngine(shell.get(), std::move(configuration));
4528 ASSERT_TRUE(hasImplicitView);
4529 ASSERT_EQ(viewIds.size(), 1u);
4530 ASSERT_EQ(viewIds[0], 0ll);
4532 PlatformViewNotifyDestroyed(shell.get());
4533 DestroyShell(std::move(shell), task_runners);
4538 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
4539 Settings settings = CreateSettingsForFixture();
4542 ThreadHost::Type::kPlatform | ThreadHost::Type::kRaster |
4543 ThreadHost::Type::kIo | ThreadHost::Type::kUi));
4547 thread_host.
io_thread->GetTaskRunner());
4548 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
4551 bool hasImplicitView;
4552 std::vector<int64_t> viewIds;
4554 auto nativeViewIdsCallback = [&reportLatch, &hasImplicitView,
4555 &viewIds](Dart_NativeArguments
args) {
4559 AddNativeCallback(
"NativeReportViewIdsCallback",
4562 PlatformViewNotifyCreated(shell.get());
4563 auto configuration = RunConfiguration::InferFromSettings(settings);
4564 configuration.SetEntrypoint(
"testReportViewIds");
4565 RunEngine(shell.get(), std::move(configuration));
4568 ASSERT_TRUE(hasImplicitView);
4569 ASSERT_EQ(viewIds.size(), 1u);
4570 ASSERT_EQ(viewIds[0], 0ll);
4572 PostSync(shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell] {
4573 shell->GetPlatformView()->AddView(2, ViewportMetrics{},
4574 [](
bool added) { EXPECT_TRUE(added); });
4577 ASSERT_TRUE(hasImplicitView);
4578 ASSERT_EQ(viewIds.size(), 2u);
4579 ASSERT_EQ(viewIds[1], 2ll);
4581 PostSync(shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell] {
4582 shell->GetPlatformView()->RemoveView(
4583 2, [](bool removed) { ASSERT_TRUE(removed); });
4586 ASSERT_TRUE(hasImplicitView);
4587 ASSERT_EQ(viewIds.size(), 1u);
4588 ASSERT_EQ(viewIds[0], 0ll);
4590 PostSync(shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell] {
4591 shell->GetPlatformView()->AddView(4, ViewportMetrics{},
4592 [](
bool added) { EXPECT_TRUE(added); });
4595 ASSERT_TRUE(hasImplicitView);
4596 ASSERT_EQ(viewIds.size(), 2u);
4597 ASSERT_EQ(viewIds[1], 4ll);
4599 PlatformViewNotifyDestroyed(shell.get());
4600 DestroyShell(std::move(shell), task_runners);
4605 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
4606 Settings settings = CreateSettingsForFixture();
4609 ThreadHost::Type::kPlatform | ThreadHost::Type::kRaster |
4610 ThreadHost::Type::kIo | ThreadHost::Type::kUi));
4614 thread_host.
io_thread->GetTaskRunner());
4615 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
4618 bool has_implicit_view;
4619 std::vector<int64_t> view_ids;
4621 AddNativeCallback(
"NativeReportViewIdsCallback",
4627 PlatformViewNotifyCreated(shell.get());
4628 auto configuration = RunConfiguration::InferFromSettings(settings);
4629 configuration.SetEntrypoint(
"testReportViewIds");
4630 RunEngine(shell.get(), std::move(configuration));
4632 report_latch.
Wait();
4633 ASSERT_TRUE(has_implicit_view);
4634 ASSERT_EQ(view_ids.size(), 1u);
4639 PostSync(shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell,
4641 shell->GetPlatformView()->AddView(123, ViewportMetrics{}, [&](
bool added) {
4649 report_latch.Wait();
4650 ASSERT_EQ(view_ids.size(), 2u);
4652 ASSERT_EQ(view_ids[1], 123);
4655 PostSync(shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell,
4657 shell->GetPlatformView()->AddView(123, ViewportMetrics{}, [&](
bool added) {
4658 EXPECT_FALSE(added);
4665 PlatformViewNotifyDestroyed(shell.get());
4666 DestroyShell(std::move(shell), task_runners);
4672 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
4673 Settings settings = CreateSettingsForFixture();
4676 ThreadHost::Type::kPlatform | ThreadHost::Type::kRaster |
4677 ThreadHost::Type::kIo | ThreadHost::Type::kUi));
4681 thread_host.
io_thread->GetTaskRunner());
4682 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
4685 bool has_implicit_view;
4686 std::vector<int64_t> view_ids;
4688 AddNativeCallback(
"NativeReportViewIdsCallback",
4694 PlatformViewNotifyCreated(shell.get());
4695 auto configuration = RunConfiguration::InferFromSettings(settings);
4696 configuration.SetEntrypoint(
"testReportViewIds");
4697 RunEngine(shell.get(), std::move(configuration));
4699 report_latch.
Wait();
4700 ASSERT_TRUE(has_implicit_view);
4701 ASSERT_EQ(view_ids.size(), 1u);
4706 PostSync(shell->GetTaskRunners().GetPlatformTaskRunner(),
4707 [&shell, &remove_latch] {
4708 shell->GetPlatformView()->RemoveView(123, [&](bool removed) {
4709 EXPECT_FALSE(removed);
4710 remove_latch.Signal();
4714 remove_latch.Wait();
4716 PlatformViewNotifyDestroyed(shell.get());
4717 DestroyShell(std::move(shell), task_runners);
4723 std::map<int64_t, int64_t>* viewWidths) {
4724 Dart_Handle exception =
nullptr;
4725 viewWidths->clear();
4726 std::vector<int64_t> viewWidthPacket =
4729 ASSERT_EQ(exception,
nullptr);
4730 ASSERT_EQ(viewWidthPacket.size() % 2, 0ul);
4731 for (
size_t packetIndex = 0; packetIndex < viewWidthPacket.size();
4733 (*viewWidths)[viewWidthPacket[packetIndex]] =
4734 viewWidthPacket[packetIndex + 1];
4742 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
4743 Settings settings = CreateSettingsForFixture();
4746 ThreadHost::Type::kPlatform | ThreadHost::Type::kRaster |
4747 ThreadHost::Type::kIo | ThreadHost::Type::kUi));
4751 thread_host.
io_thread->GetTaskRunner());
4752 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
4755 PostSync(shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell] {
4756 auto platform_view = shell->GetPlatformView();
4759 platform_view->SetViewportMetrics(0, ViewportMetrics{1, 10, 1, 0, 0});
4761 [](
bool added) { ASSERT_TRUE(added); });
4765 bool first_report =
true;
4766 std::map<int64_t, int64_t> viewWidths;
4768 auto nativeViewWidthsCallback = [&reportLatch, &viewWidths,
4769 &first_report](Dart_NativeArguments
args) {
4770 EXPECT_TRUE(first_report);
4771 first_report =
false;
4772 ParseViewWidthsCallback(
args, &viewWidths);
4775 AddNativeCallback(
"NativeReportViewWidthsCallback",
4778 PlatformViewNotifyCreated(shell.get());
4779 auto configuration = RunConfiguration::InferFromSettings(settings);
4780 configuration.SetEntrypoint(
"testReportViewWidths");
4781 RunEngine(shell.get(), std::move(configuration));
4784 EXPECT_EQ(viewWidths.size(), 2u);
4785 EXPECT_EQ(viewWidths[0], 20ll);
4786 EXPECT_EQ(viewWidths[1], 30ll);
4788 PlatformViewNotifyDestroyed(shell.get());
4789 DestroyShell(std::move(shell), task_runners);
4794 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
4795 Settings settings = CreateSettingsForFixture();
4798 ThreadHost::Type::kPlatform | ThreadHost::Type::kRaster |
4799 ThreadHost::Type::kIo | ThreadHost::Type::kUi));
4803 thread_host.
io_thread->GetTaskRunner());
4804 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
4807 PostSync(shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell] {
4808 auto platform_view = shell->GetPlatformView();
4813 shell->GetPlatformView()->AddView(123, ViewportMetrics{1, 30, 1, 0, 0},
4814 [](
bool added) { ASSERT_FALSE(added); });
4815 shell->GetPlatformView()->RemoveView(
4816 123, [](
bool removed) { ASSERT_FALSE(removed); });
4819 bool first_report =
true;
4820 std::map<int64_t, int64_t> view_widths;
4822 AddNativeCallback(
"NativeReportViewWidthsCallback",
4824 EXPECT_TRUE(first_report);
4825 first_report =
false;
4826 ParseViewWidthsCallback(
args, &view_widths);
4830 PlatformViewNotifyCreated(shell.get());
4831 auto configuration = RunConfiguration::InferFromSettings(settings);
4832 configuration.SetEntrypoint(
"testReportViewWidths");
4833 RunEngine(shell.get(), std::move(configuration));
4835 report_latch.
Wait();
4836 EXPECT_EQ(view_widths.size(), 1u);
4838 PlatformViewNotifyDestroyed(shell.get());
4839 DestroyShell(std::move(shell), task_runners);
4845 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
4846 Settings settings = CreateSettingsForFixture();
4849 ThreadHost::Type::kPlatform | ThreadHost::Type::kRaster |
4850 ThreadHost::Type::kIo | ThreadHost::Type::kUi));
4854 thread_host.
io_thread->GetTaskRunner());
4855 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
4858 PostSync(shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell] {
4859 auto platform_view = shell->GetPlatformView();
4862 shell->GetPlatformView()->AddView(123, ViewportMetrics{1, 100, 1, 0, 0},
4863 [](
bool added) { ASSERT_TRUE(added); });
4865 shell->GetPlatformView()->AddView(123,
ViewportMetrics{1, 200, 1, 0, 0},
4866 [](
bool added) { ASSERT_FALSE(added); });
4869 shell->GetPlatformView()->AddView(456,
ViewportMetrics{1, 300, 1, 0, 0},
4870 [](
bool added) { ASSERT_TRUE(added); });
4873 bool first_report =
true;
4874 std::map<int64_t, int64_t> view_widths;
4876 AddNativeCallback(
"NativeReportViewWidthsCallback",
4878 EXPECT_TRUE(first_report);
4879 first_report =
false;
4880 ParseViewWidthsCallback(
args, &view_widths);
4884 PlatformViewNotifyCreated(shell.get());
4885 auto configuration = RunConfiguration::InferFromSettings(settings);
4886 configuration.SetEntrypoint(
"testReportViewWidths");
4887 RunEngine(shell.get(), std::move(configuration));
4889 report_latch.
Wait();
4890 EXPECT_EQ(view_widths.size(), 3u);
4891 EXPECT_EQ(view_widths[0], 0);
4892 EXPECT_EQ(view_widths[123], 100);
4893 EXPECT_EQ(view_widths[456], 300);
4895 PlatformViewNotifyDestroyed(shell.get());
4896 DestroyShell(std::move(shell), task_runners);
4900#if !IMPELLER_SUPPORTS_RENDERING
4901 GTEST_SKIP() <<
"This platform doesn't support Impeller.";
4903 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
4904 Settings settings = CreateSettingsForFixture();
4910 TaskRunners task_runners(
"test", runner, runner, runner, runner);
4911 std::ostringstream stream;
4913 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
4915 stream.str().find(
"[Action Required]: Impeller opt-out deprecated.") !=
4918 DestroyShell(std::move(shell), task_runners);
4922 Settings settings = CreateSettingsForFixture();
4925 std::string last_event;
4931 AddNativeCallback(
"NotifyMessage",
4933 const auto message_from_dart =
4935 Dart_GetNativeArgument(
args, 0));
4936 last_event = message_from_dart;
4941 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
4942 ASSERT_TRUE(shell->IsSetup());
4944 auto configuration = RunConfiguration::InferFromSettings(settings);
4946 configuration.SetEntrypoint(
"testSendViewFocusEvent");
4947 RunEngine(shell.get(), std::move(configuration));
4951 PostSync(shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell]() {
4952 shell->GetPlatformView()->SendViewFocusEvent(ViewFocusEvent(
4953 1, ViewFocusState::kFocused, ViewFocusDirection::kUndefined));
4956 ASSERT_EQ(last_event,
4957 "1 ViewFocusState.focused ViewFocusDirection.undefined");
4960 PostSync(shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell]() {
4961 shell->GetPlatformView()->SendViewFocusEvent(ViewFocusEvent(
4962 2, ViewFocusState::kUnfocused, ViewFocusDirection::kBackward));
4965 ASSERT_EQ(last_event,
4966 "2 ViewFocusState.unfocused ViewFocusDirection.backward");
4967 DestroyShell(std::move(shell), task_runners);
4971 Settings settings = CreateSettingsForFixture();
4975 std::optional<int> reported_handle = std::nullopt;
4979 Dart_Handle arg = Dart_GetNativeArgument(
args, 0);
4980 if (Dart_IsNull(arg)) {
4981 reported_handle = std::nullopt;
4989 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
4990 ASSERT_TRUE(shell->IsSetup());
4992 auto configuration = RunConfiguration::InferFromSettings(settings);
4993 configuration.SetEngineId(99);
4994 configuration.SetEntrypoint(
"providesEngineId");
4995 RunEngine(shell.get(), std::move(configuration));
4998 ASSERT_EQ(reported_handle, 99);
5003 shell->GetTaskRunners().GetUITaskRunner(), [&]() {
5004 ASSERT_EQ(shell->GetEngine()->GetLastEngineId(), 99);
5008 DestroyShell(std::move(shell), task_runners);
5012 Settings settings = CreateSettingsForFixture();
5016 std::optional<int> reported_handle = std::nullopt;
5020 Dart_Handle arg = Dart_GetNativeArgument(
args, 0);
5021 if (Dart_IsNull(arg)) {
5022 reported_handle = std::nullopt;
5030 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
5031 ASSERT_TRUE(shell->IsSetup());
5033 auto configuration = RunConfiguration::InferFromSettings(settings);
5034 configuration.SetEntrypoint(
"providesEngineId");
5035 RunEngine(shell.get(), std::move(configuration));
5038 ASSERT_EQ(reported_handle, std::nullopt);
5039 DestroyShell(std::move(shell), task_runners);
5043 Settings settings = CreateSettingsForFixture();
5045 Settings::MergedPlatformUIThread::kMergeAfterLaunch;
5048 ThreadHost::Type::kPlatform | ThreadHost::Type::kRaster |
5049 ThreadHost::Type::kIo | ThreadHost::Type::kUi));
5053 thread_host.
io_thread->GetTaskRunner());
5055 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
5070 auto configuration = RunConfiguration::InferFromSettings(settings);
5071 configuration.SetEntrypoint(
"mainNotifyNative");
5072 RunEngine(shell.get(), std::move(configuration));
5080 DestroyShell(std::move(shell), task_runners);
5085 auto settings = CreateSettingsForFixture();
5086 bool called_release_resource_context =
false;
5088 [task_runners, &called_release_resource_context](
flutter::Shell& shell) {
5089 auto result = std::make_unique<::testing::NiceMock<TestPlatformView>>(
5090 shell, task_runners);
5091 ON_CALL(*result, ReleaseResourceContext())
5093 ::testing::Assign(&called_release_resource_context,
true));
5097 auto parent_shell = CreateShell({
5098 .settings = settings,
5099 .task_runners = task_runners,
5100 .platform_view_create_callback = platform_view_create_callback,
5103 std::unique_ptr<Shell> child_shell;
5105 parent_shell->GetTaskRunners().GetPlatformTaskRunner(),
5106 [&parent_shell, &settings, &child_shell, platform_view_create_callback] {
5107 auto configuration = RunConfiguration::InferFromSettings(settings);
5108 configuration.SetEntrypoint(
"emptyMain");
5109 auto child = parent_shell->Spawn(
5110 std::move(configuration),
"", platform_view_create_callback,
5111 [](Shell& shell) { return std::make_unique<Rasterizer>(shell); });
5112 child_shell = std::move(child);
5115 DestroyShell(std::move(parent_shell), task_runners);
5116 ASSERT_FALSE(called_release_resource_context);
5118 DestroyShell(std::move(child_shell), task_runners);
5119 ASSERT_TRUE(called_release_resource_context);
5123 Settings settings = CreateSettingsForFixture();
5124 auto task_runner = CreateNewThread();
5125 TaskRunners task_runners(
"test", task_runner, task_runner, task_runner,
5127 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
5130 shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell]() {
5131 shell->GetPlatformView()->SetViewportMetrics(
5164 PumpOneFrame(shell.get());
5167 std::make_unique<LayerTree>(
nullptr,
5169 ASSERT_FALSE(ShellTest::ShouldDiscardLayerTree(shell.get(),
kImplicitViewId,
5172 std::make_unique<LayerTree>(
nullptr,
5174 ASSERT_TRUE(ShellTest::ShouldDiscardLayerTree(shell.get(),
kImplicitViewId,
5177 std::make_unique<LayerTree>(
nullptr,
5179 ASSERT_TRUE(ShellTest::ShouldDiscardLayerTree(shell.get(),
kImplicitViewId,
5181 auto min_width = std::make_unique<LayerTree>(
nullptr,
5183 ASSERT_TRUE(ShellTest::ShouldDiscardLayerTree(shell.get(),
kImplicitViewId,
5185 auto min_height = std::make_unique<LayerTree>(
nullptr,
5187 ASSERT_TRUE(ShellTest::ShouldDiscardLayerTree(shell.get(),
kImplicitViewId,
5189 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::@2924::KeyboardChange::@78 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
std::shared_ptr< ContextGLES > context
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)