5#define FML_USED_ON_EMBEDDER
26 return std::map<int64_t, ViewContent>();
64 std::unique_ptr<PlatformMessage>
message) {
65 shell->OnPlatformViewDispatchPlatformMessage(std::move(
message));
73 shell->OnPlatformViewDispatchSemanticsAction(
view_id, node_id,
action,
79 std::unique_ptr<PlatformMessage>
message) {
85 if (auto engine = shell->weak_engine_) {
86 engine->HandlePlatformMessage(std::move(message));
93void ShellTest::PlatformViewNotifyCreated(
Shell* shell) {
97 shell->GetPlatformView()->NotifyCreated();
103void ShellTest::PlatformViewNotifyDestroyed(
Shell* shell) {
107 shell->GetPlatformView()->NotifyDestroyed();
117 [shell, &latch, &configuration]() {
118 shell->RunEngine(std::move(configuration),
119 [&latch](Engine::RunStatus run_status) {
120 ASSERT_EQ(run_status, Engine::RunStatus::Success);
128 std::promise<bool> restarted;
131 [shell, &restarted, &configuration]() {
132 restarted.set_value(shell->engine_->Restart(std::move(configuration)));
134 ASSERT_TRUE(restarted.get_future().get());
137void ShellTest::VSyncFlush(
Shell* shell,
bool* will_draw_new_frame) {
141 [shell, will_draw_new_frame, &latch] {
143 fml::AutoResetWaitableEvent ui_latch;
144 shell->GetTaskRunners().GetUITaskRunner()->PostTask(
145 [&ui_latch, will_draw_new_frame]() {
146 if (will_draw_new_frame != nullptr) {
147 *will_draw_new_frame = true;
185 std::vector<double>(),
199 [&latch,
engine = shell->weak_engine_, viewport_metrics]() {
201 engine->SetViewportMetrics(kImplicitViewId, viewport_metrics);
202 const auto frame_begin_time = fml::TimePoint::Now();
203 const auto frame_end_time =
204 frame_begin_time + fml::TimeDelta::FromSecondsF(1.0 / 60.0);
205 std::unique_ptr<FrameTimingsRecorder> recorder =
206 std::make_unique<FrameTimingsRecorder>();
207 recorder->RecordVsync(frame_begin_time, frame_end_time);
208 engine->animator_->BeginFrame(std::move(recorder));
209 engine->animator_->EndFrame();
219 [&latch,
engine = shell->weak_engine_, deadline]() {
221 engine->NotifyIdle(deadline);
228void ShellTest::PumpOneFrame(
Shell* shell) {
229 PumpOneFrame(shell, ViewContent::DummyView());
240 [&latch,
engine = shell->weak_engine_, &frame_content,
241 runtime_delegate]() {
242 for (auto& [view_id, view_content] : frame_content) {
243 engine->SetViewportMetrics(view_id, view_content.viewport_metrics);
246 const auto frame_end_time =
248 std::unique_ptr<FrameTimingsRecorder> recorder =
249 std::make_unique<FrameTimingsRecorder>();
250 recorder->RecordVsync(frame_begin_time, frame_end_time);
251 engine->animator_->BeginFrame(std::move(recorder));
257 for (
auto& [
view_id, view_content] : frame_content) {
258 auto root_layer = std::make_shared<TransformLayer>(
DlMatrix());
259 auto layer_tree = std::make_unique<LayerTree>(
261 DlISize(view_content.viewport_metrics.physical_width,
262 view_content.viewport_metrics.physical_height));
263 float device_pixel_ratio =
static_cast<float>(
264 view_content.viewport_metrics.device_pixel_ratio);
265 if (view_content.builder) {
266 view_content.builder(root_layer);
268 runtime_delegate->Render(
view_id, std::move(layer_tree),
271 engine->animator_->EndFrame();
277void ShellTest::DispatchFakePointerData(
Shell* shell,
double x) {
278 auto packet = std::make_unique<PointerDataPacket>(1);
280 .
change = PointerData::Change::kHover,
283 DispatchPointerData(shell, std::move(packet));
286void ShellTest::DispatchPointerData(
Shell* shell,
287 std::unique_ptr<PointerDataPacket> packet) {
290 [&latch, shell, &packet]() {
292 shell->
GetPlatformView()->DispatchPointerDataPacket(std::move(packet));
298int ShellTest::UnreportedTimingsCount(
Shell* shell) {
299 return shell->unreported_timings_.size();
302void ShellTest::SetNeedsReportTimings(
Shell* shell,
bool value) {
303 shell->SetNeedsReportTimings(
value);
306bool ShellTest::GetNeedsReportTimings(
Shell* shell) {
307 return shell->needs_report_timings_;
312 const SkData& value) {
316void ShellTest::OnServiceProtocol(
321 rapidjson::Document* response) {
322 std::promise<bool> finished;
324 task_runner, [shell, some_protocol,
params, response, &finished]() {
325 switch (some_protocol) {
326 case ServiceProtocolEnum::kGetSkSLs:
327 shell->OnServiceProtocolGetSkSLs(
params, response);
329 case ServiceProtocolEnum::kEstimateRasterCacheMemory:
330 shell->OnServiceProtocolEstimateRasterCacheMemory(
params, response);
332 case ServiceProtocolEnum::kSetAssetBundlePath:
333 shell->OnServiceProtocolSetAssetBundlePath(
params, response);
335 case ServiceProtocolEnum::kRunInView:
336 shell->OnServiceProtocolRunInView(
params, response);
339 finished.set_value(
true);
341 finished.get_future().wait();
344std::shared_ptr<txt::FontCollection> ShellTest::GetFontCollection(
346 return shell->weak_engine_->GetFontCollection().GetFontCollection();
363 native_resolver_->SetNativeResolverForIsolate();
368 SetSnapshotsAndAssets(settings);
383 return shell->GetLatestFrameTargetTime();
386std::unique_ptr<Shell> ShellTest::CreateShell(
388 std::optional<TaskRunners> task_runners) {
390 .settings = settings,
391 .task_runners = std::move(task_runners),
395std::unique_ptr<Shell> ShellTest::CreateShell(
const Config& config) {
401 if (!platform_view_create_callback) {
406 [](
Shell& shell) {
return std::make_unique<Rasterizer>(shell); };
411 platform_view_create_callback,
412 rasterizer_create_callback,
417void ShellTest::DestroyShell(std::unique_ptr<Shell> shell) {
421void ShellTest::DestroyShell(std::unique_ptr<Shell> shell,
425 [&shell, &latch]()
mutable {
432void ShellTest::TurnOffGPU(
Shell* shell,
bool value) {
433 shell->is_gpu_disabled_sync_switch_->SetSwitch(
value);
436bool ShellTest::ShouldDiscardLayerTree(
Shell* shell,
439 return shell->ShouldDiscardLayerTree(
view_id, tree);
Specifies all the configuration required by the runtime library to launch the root isolate....
std::map< std::string_view, std::string_view > ServiceProtocolMap
const TaskRunners & GetTaskRunners() const override
If callers wish to interact directly with any shell subcomponents, they must (on the platform thread)...
std::function< std::unique_ptr< T >(Shell &)> CreateCallback
fml::WeakPtr< PlatformView > GetPlatformView()
Platform views may only be accessed on the platform task runner.
fml::RefPtr< fml::TaskRunner > GetUITaskRunner() const
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 SendSemanticsAction(Shell *shell, int64_t view_id, int32_t node_id, SemanticsAction action, fml::MallocMapping args)
A Mapping like NonOwnedMapping, but uses Free as its release proc.
static TaskQueueId GetCurrentTaskQueueId()
static MessageLoopTaskQueues * GetInstance()
void AddTaskObserver(TaskQueueId queue_id, intptr_t key, const fml::closure &callback)
void RemoveTaskObserver(TaskQueueId queue_id, intptr_t key)
static void RunNowOrPostTask(const fml::RefPtr< fml::TaskRunner > &runner, const fml::closure &task)
virtual void PostTask(const fml::closure &task) override
static constexpr TimeDelta FromSecondsF(double seconds)
static constexpr TimeDelta FromMilliseconds(int64_t millis)
@ kRaster
Suitable for thread which raster data.
const EmbeddedViewParams * params
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
const gchar FlBinaryMessengerMessageHandler handler
G_BEGIN_DECLS FlutterViewId view_id
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
internal::CopyableLambda< T > MakeCopyable(T lambda)
std::function< void()> closure
TaskObserverRemove task_observer_remove
TaskObserverAdd task_observer_add
fml::closure isolate_create_callback
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()
A 4x4 matrix using column-major storage.