5#define FML_USED_ON_EMBEDDER
7#include "flutter/shell/common/shell_test.h"
9#include "flutter/flow/frame_timings.h"
10#include "flutter/flow/layers/layer_tree.h"
11#include "flutter/flow/layers/transform_layer.h"
12#include "flutter/fml/build_config.h"
13#include "flutter/fml/make_copyable.h"
14#include "flutter/fml/mapping.h"
15#include "flutter/runtime/dart_vm.h"
16#include "flutter/shell/common/shell_test_platform_view.h"
17#include "flutter/shell/common/vsync_waiter_fallback.h"
18#include "flutter/testing/testing.h"
26 return std::map<int64_t, ViewContent>();
64 std::unique_ptr<PlatformMessage>
message) {
65 shell->OnPlatformViewDispatchPlatformMessage(std::move(
message));
70 std::unique_ptr<PlatformMessage>
message) {
73 shell->GetTaskRunners().GetPlatformTaskRunner(),
76 if (auto engine = shell->weak_engine_) {
77 engine->HandlePlatformMessage(std::move(message));
84void ShellTest::PlatformViewNotifyCreated(
Shell* shell) {
87 shell->GetTaskRunners().GetPlatformTaskRunner(), [shell, &latch]() {
88 shell->GetPlatformView()->NotifyCreated();
94void ShellTest::PlatformViewNotifyDestroyed(
Shell* shell) {
97 shell->GetTaskRunners().GetPlatformTaskRunner(), [shell, &latch]() {
98 shell->GetPlatformView()->NotifyDestroyed();
107 shell->GetTaskRunners().GetPlatformTaskRunner(),
108 [shell, &latch, &configuration]() {
109 shell->RunEngine(std::move(configuration),
110 [&latch](Engine::RunStatus run_status) {
111 ASSERT_EQ(run_status, Engine::RunStatus::Success);
119 std::promise<bool> restarted;
121 shell->GetTaskRunners().GetUITaskRunner(),
122 [shell, &restarted, &configuration]() {
123 restarted.set_value(shell->engine_->Restart(std::move(configuration)));
125 ASSERT_TRUE(restarted.get_future().get());
128void ShellTest::VSyncFlush(
Shell* shell,
bool* will_draw_new_frame) {
131 shell->GetTaskRunners().GetPlatformTaskRunner(),
132 [shell, will_draw_new_frame, &latch] {
134 fml::AutoResetWaitableEvent ui_latch;
135 shell->GetTaskRunners().GetUITaskRunner()->PostTask(
136 [&ui_latch, will_draw_new_frame]() {
137 if (will_draw_new_frame != nullptr) {
138 *will_draw_new_frame = true;
172 std::vector<double>(),
181 shell->GetTaskRunners().GetUITaskRunner()->PostTask(
182 [&latch,
engine = shell->weak_engine_, viewport_metrics]() {
184 engine->SetViewportMetrics(kImplicitViewId, viewport_metrics);
185 const auto frame_begin_time = fml::TimePoint::Now();
186 const auto frame_end_time =
187 frame_begin_time + fml::TimeDelta::FromSecondsF(1.0 / 60.0);
188 std::unique_ptr<FrameTimingsRecorder> recorder =
189 std::make_unique<FrameTimingsRecorder>();
190 recorder->RecordVsync(frame_begin_time, frame_end_time);
191 engine->animator_->BeginFrame(std::move(recorder));
192 engine->animator_->EndFrame();
201 shell->GetTaskRunners().GetUITaskRunner()->PostTask(
202 [&latch,
engine = shell->weak_engine_, deadline]() {
204 engine->NotifyIdle(deadline);
211void ShellTest::PumpOneFrame(
Shell* shell) {
212 PumpOneFrame(shell, ViewContent::DummyView());
221 shell->GetTaskRunners().GetUITaskRunner()->PostTask(
222 [&latch,
engine = shell->weak_engine_, &frame_content,
223 runtime_delegate]() {
224 for (auto& [view_id, view_content] : frame_content) {
225 engine->SetViewportMetrics(view_id, view_content.viewport_metrics);
228 const auto frame_end_time =
230 std::unique_ptr<FrameTimingsRecorder> recorder =
231 std::make_unique<FrameTimingsRecorder>();
232 recorder->RecordVsync(frame_begin_time, frame_end_time);
233 engine->animator_->BeginFrame(std::move(recorder));
239 for (
auto& [view_id, view_content] : frame_content) {
241 identity.setIdentity();
242 auto root_layer = std::make_shared<TransformLayer>(identity);
243 auto layer_tree = std::make_unique<LayerTree>(
246 view_content.viewport_metrics.physical_height));
247 float device_pixel_ratio =
static_cast<float>(
248 view_content.viewport_metrics.device_pixel_ratio);
249 if (view_content.builder) {
250 view_content.builder(root_layer);
252 runtime_delegate->Render(view_id, std::move(layer_tree),
255 engine->animator_->EndFrame();
261void ShellTest::DispatchFakePointerData(
Shell* shell) {
262 auto packet = std::make_unique<PointerDataPacket>(1);
263 DispatchPointerData(shell, std::move(packet));
266void ShellTest::DispatchPointerData(
Shell* shell,
267 std::unique_ptr<PointerDataPacket> packet) {
269 shell->GetTaskRunners().GetPlatformTaskRunner()->PostTask(
270 [&latch, shell, &packet]() {
272 shell->GetPlatformView()->DispatchPointerDataPacket(std::move(packet));
278int ShellTest::UnreportedTimingsCount(
Shell* shell) {
279 return shell->unreported_timings_.size();
282void ShellTest::SetNeedsReportTimings(
Shell* shell,
bool value) {
283 shell->SetNeedsReportTimings(
value);
286bool ShellTest::GetNeedsReportTimings(
Shell* shell) {
287 return shell->needs_report_timings_;
296void ShellTest::OnServiceProtocol(
301 rapidjson::Document* response) {
302 std::promise<bool> finished;
304 response, &finished]() {
305 switch (some_protocol) {
306 case ServiceProtocolEnum::kGetSkSLs:
307 shell->OnServiceProtocolGetSkSLs(
params, response);
309 case ServiceProtocolEnum::kEstimateRasterCacheMemory:
310 shell->OnServiceProtocolEstimateRasterCacheMemory(
params, response);
312 case ServiceProtocolEnum::kSetAssetBundlePath:
313 shell->OnServiceProtocolSetAssetBundlePath(
params, response);
315 case ServiceProtocolEnum::kRunInView:
316 shell->OnServiceProtocolRunInView(
params, response);
318 case ServiceProtocolEnum::kRenderFrameWithRasterStats:
319 shell->OnServiceProtocolRenderFrameWithRasterStats(
params, response);
322 finished.set_value(
true);
324 finished.get_future().wait();
327std::shared_ptr<txt::FontCollection> ShellTest::GetFontCollection(
329 return shell->weak_engine_->GetFontCollection().GetFontCollection();
334 settings.leak_vm =
false;
335 settings.task_observer_add = [](intptr_t
key,
const fml::closure& handler) {
338 settings.task_observer_remove = [](intptr_t
key) {
341 settings.isolate_create_callback = [
this]() {
342 native_resolver_->SetNativeResolverForIsolate();
345 settings.verbose_logging =
true;
347 SetSnapshotsAndAssets(settings);
362 return shell->GetLatestFrameTargetTime();
365std::unique_ptr<Shell> ShellTest::CreateShell(
367 std::optional<TaskRunners> task_runners) {
369 .settings = settings,
370 .task_runners = std::move(task_runners),
374std::unique_ptr<Shell> ShellTest::CreateShell(
const Config& config) {
380 if (!platform_view_create_callback) {
385 [](
Shell& shell) {
return std::make_unique<Rasterizer>(shell); };
390 platform_view_create_callback,
391 rasterizer_create_callback,
396void ShellTest::DestroyShell(std::unique_ptr<Shell> shell) {
400void ShellTest::DestroyShell(std::unique_ptr<Shell> shell,
404 [&shell, &latch]()
mutable {
411size_t ShellTest::GetLiveTrackedPathCount(
412 const std::shared_ptr<VolatilePathTracker>& tracker) {
413 return std::count_if(
414 tracker->paths_.begin(), tracker->paths_.end(),
415 [](
const std::weak_ptr<VolatilePathTracker::TrackedPath>&
path) {
420void ShellTest::TurnOffGPU(
Shell* shell,
bool value) {
421 shell->is_gpu_disabled_sync_switch_->SetSwitch(
value);
Specifies all the configuration required by the runtime library to launch the root isolate....
std::map< std::string_view, std::string_view > ServiceProtocolMap
std::function< std::unique_ptr< T >(Shell &)> CreateCallback
fml::RefPtr< fml::TaskRunner > GetPlatformTaskRunner() const
void SendPlatformMessage(Shell *shell, std::unique_ptr< PlatformMessage > message)
void SendEnginePlatformMessage(Shell *shell, std::unique_ptr< PlatformMessage > message)
void RemoveTaskObserver(intptr_t key)
void AddTaskObserver(intptr_t key, const fml::closure &callback)
static FML_EMBEDDER_ONLY MessageLoop & GetCurrent()
static void RunNowOrPostTask(const fml::RefPtr< fml::TaskRunner > &runner, const fml::closure &task)
static constexpr TimeDelta FromSecondsF(double seconds)
static constexpr TimeDelta FromMilliseconds(int64_t millis)
@ kRaster
Suitable for thread which raster data.
const EmbeddedViewParams * params
std::string GetCurrentTestName()
Gets the name of the currently running test. This is useful in generating logs or assets based on tes...
TaskRunners GetTaskRunnersForFixture()
std::function< void(std::shared_ptr< ContainerLayer > root)> LayerTreeBuilder
std::map< int64_t, ViewContent > FrameContent
constexpr int64_t kImplicitViewId
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 vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets Path to the Flutter assets directory enable service port Allow the VM service to fallback to automatic port selection if binding to a specified port fails trace Trace early application lifecycle Automatically switches to an endless trace buffer trace skia Filters out all Skia trace event categories except those that are specified in this comma separated list dump skp on shader Automatically dump the skp that triggers new shader compilations This is useful for writing custom ShaderWarmUp to reduce jank By this is not enabled to reduce the overhead purge persistent cache
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
internal::CopyableLambda< T > MakeCopyable(T lambda)
std::function< void()> closure
static constexpr SkISize Make(int32_t w, int32_t h)
std::shared_ptr< Layer > root_layer
The collection of all the threads used by the engine.
const Settings & settings
Shell::CreateCallback< PlatformView > platform_view_create_callback
std::optional< TaskRunners > task_runners
static FrameContent ImplicitView(double width, double height, LayerTreeBuilder builder)
static FrameContent DummyView(double width=1, double height=1)
flutter::ViewportMetrics viewport_metrics
static FrameContent NoViews()