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>(),
195 [&latch,
engine = shell->weak_engine_, viewport_metrics]() {
197 engine->SetViewportMetrics(kImplicitViewId, viewport_metrics);
198 const auto frame_begin_time = fml::TimePoint::Now();
199 const auto frame_end_time =
200 frame_begin_time + fml::TimeDelta::FromSecondsF(1.0 / 60.0);
201 std::unique_ptr<FrameTimingsRecorder> recorder =
202 std::make_unique<FrameTimingsRecorder>();
203 recorder->RecordVsync(frame_begin_time, frame_end_time);
204 engine->animator_->BeginFrame(std::move(recorder));
205 engine->animator_->EndFrame();
215 [&latch,
engine = shell->weak_engine_, deadline]() {
217 engine->NotifyIdle(deadline);
224void ShellTest::PumpOneFrame(
Shell* shell) {
225 PumpOneFrame(shell, ViewContent::DummyView());
236 [&latch,
engine = shell->weak_engine_, &frame_content,
237 runtime_delegate]() {
238 for (auto& [view_id, view_content] : frame_content) {
239 engine->SetViewportMetrics(view_id, view_content.viewport_metrics);
242 const auto frame_end_time =
244 std::unique_ptr<FrameTimingsRecorder> recorder =
245 std::make_unique<FrameTimingsRecorder>();
246 recorder->RecordVsync(frame_begin_time, frame_end_time);
247 engine->animator_->BeginFrame(std::move(recorder));
253 for (
auto& [
view_id, view_content] : frame_content) {
254 auto root_layer = std::make_shared<TransformLayer>(
DlMatrix());
255 auto layer_tree = std::make_unique<LayerTree>(
257 DlISize(view_content.viewport_metrics.physical_width,
258 view_content.viewport_metrics.physical_height));
259 float device_pixel_ratio =
static_cast<float>(
260 view_content.viewport_metrics.device_pixel_ratio);
261 if (view_content.builder) {
262 view_content.builder(root_layer);
264 runtime_delegate->Render(
view_id, std::move(layer_tree),
267 engine->animator_->EndFrame();
273void ShellTest::DispatchFakePointerData(
Shell* shell,
double x) {
274 auto packet = std::make_unique<PointerDataPacket>(1);
276 .
change = PointerData::Change::kHover,
279 DispatchPointerData(shell, std::move(packet));
282void ShellTest::DispatchPointerData(
Shell* shell,
283 std::unique_ptr<PointerDataPacket> packet) {
286 [&latch, shell, &packet]() {
288 shell->
GetPlatformView()->DispatchPointerDataPacket(std::move(packet));
294int ShellTest::UnreportedTimingsCount(
Shell* shell) {
295 return shell->unreported_timings_.size();
298void ShellTest::SetNeedsReportTimings(
Shell* shell,
bool value) {
299 shell->SetNeedsReportTimings(
value);
302bool ShellTest::GetNeedsReportTimings(
Shell* shell) {
303 return shell->needs_report_timings_;
308 const SkData& value) {
312void ShellTest::OnServiceProtocol(
317 rapidjson::Document* response) {
318 std::promise<bool> finished;
320 task_runner, [shell, some_protocol,
params, response, &finished]() {
321 switch (some_protocol) {
322 case ServiceProtocolEnum::kGetSkSLs:
323 shell->OnServiceProtocolGetSkSLs(
params, response);
325 case ServiceProtocolEnum::kEstimateRasterCacheMemory:
326 shell->OnServiceProtocolEstimateRasterCacheMemory(
params, response);
328 case ServiceProtocolEnum::kSetAssetBundlePath:
329 shell->OnServiceProtocolSetAssetBundlePath(
params, response);
331 case ServiceProtocolEnum::kRunInView:
332 shell->OnServiceProtocolRunInView(
params, response);
335 finished.set_value(
true);
337 finished.get_future().wait();
340std::shared_ptr<txt::FontCollection> ShellTest::GetFontCollection(
342 return shell->weak_engine_->GetFontCollection().GetFontCollection();
359 native_resolver_->SetNativeResolverForIsolate();
364 SetSnapshotsAndAssets(settings);
379 return shell->GetLatestFrameTargetTime();
382std::unique_ptr<Shell> ShellTest::CreateShell(
384 std::optional<TaskRunners> task_runners) {
386 .settings = settings,
387 .task_runners = std::move(task_runners),
391std::unique_ptr<Shell> ShellTest::CreateShell(
const Config& config) {
397 if (!platform_view_create_callback) {
402 [](
Shell& shell) {
return std::make_unique<Rasterizer>(shell); };
407 platform_view_create_callback,
408 rasterizer_create_callback,
413void ShellTest::DestroyShell(std::unique_ptr<Shell> shell) {
417void ShellTest::DestroyShell(std::unique_ptr<Shell> shell,
421 [&shell, &latch]()
mutable {
428void ShellTest::TurnOffGPU(
Shell* shell,
bool value) {
429 shell->is_gpu_disabled_sync_switch_->SetSwitch(
value);
432bool ShellTest::ShouldDiscardLayerTree(
Shell* shell,
435 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 GBytes * message
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.