Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ FILE: ../../../flutter/shell/common/canvas_spy_unittests.cc
FILE: ../../../flutter/shell/common/engine.cc
FILE: ../../../flutter/shell/common/engine.h
FILE: ../../../flutter/shell/common/fixtures/shell_test.dart
FILE: ../../../flutter/shell/common/input_events_unittests.cc
FILE: ../../../flutter/shell/common/isolate_configuration.cc
FILE: ../../../flutter/shell/common/isolate_configuration.h
FILE: ../../../flutter/shell/common/persistent_cache.cc
Expand All @@ -494,6 +495,8 @@ FILE: ../../../flutter/shell/common/pipeline.h
FILE: ../../../flutter/shell/common/pipeline_unittests.cc
FILE: ../../../flutter/shell/common/platform_view.cc
FILE: ../../../flutter/shell/common/platform_view.h
FILE: ../../../flutter/shell/common/pointer_data_dispatcher.cc
FILE: ../../../flutter/shell/common/pointer_data_dispatcher.h
FILE: ../../../flutter/shell/common/rasterizer.cc
FILE: ../../../flutter/shell/common/rasterizer.h
FILE: ../../../flutter/shell/common/run_configuration.cc
Expand Down
3 changes: 3 additions & 0 deletions shell/common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ source_set("common") {
"pipeline.h",
"platform_view.cc",
"platform_view.h",
"pointer_data_dispatcher.cc",
"pointer_data_dispatcher.h",
"rasterizer.cc",
"rasterizer.h",
"run_configuration.cc",
Expand Down Expand Up @@ -156,6 +158,7 @@ if (current_toolchain == host_toolchain) {
shell_host_executable("shell_unittests") {
sources = [
"canvas_spy_unittests.cc",
"input_events_unittests.cc",
"pipeline_unittests.cc",
"shell_test.cc",
"shell_test.h",
Expand Down
20 changes: 15 additions & 5 deletions shell/common/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ static constexpr char kSettingsChannel[] = "flutter/settings";
static constexpr char kIsolateChannel[] = "flutter/isolate";

Engine::Engine(Delegate& delegate,
PointerDataDispatcherMaker& dispatcher_maker,
DartVM& vm,
fml::RefPtr<const DartSnapshot> isolate_snapshot,
fml::RefPtr<const DartSnapshot> shared_snapshot,
Expand All @@ -46,11 +47,13 @@ Engine::Engine(Delegate& delegate,
: delegate_(delegate),
settings_(std::move(settings)),
animator_(std::move(animator)),
dispatcher_maker_(std::move(dispatcher_maker)),
activity_running_(true),
have_surface_(false),
image_decoder_(task_runners,
vm.GetConcurrentWorkerTaskRunner(),
io_manager),
task_runners_(std::move(task_runners)),
weak_factory_(this) {
// Runtime controller is initialized here because it takes a reference to this
// object as its delegate. The delegate may be called in the constructor and
Expand All @@ -60,7 +63,7 @@ Engine::Engine(Delegate& delegate,
&vm, // VM
std::move(isolate_snapshot), // isolate snapshot
std::move(shared_snapshot), // shared snapshot
std::move(task_runners), // task runners
task_runners_, // task runners
std::move(io_manager), // io manager
image_decoder_.GetWeakPtr(), // image decoder
settings_.advisory_script_uri, // advisory script uri
Expand All @@ -69,6 +72,9 @@ Engine::Engine(Delegate& delegate,
settings_.isolate_create_callback, // isolate create callback
settings_.isolate_shutdown_callback // isolate shutdown callback
);

pointer_data_dispatcher_ =
dispatcher_maker_(*animator_, *runtime_controller_, task_runners_);
}

Engine::~Engine() = default;
Expand Down Expand Up @@ -111,6 +117,8 @@ bool Engine::Restart(RunConfiguration configuration) {
}
delegate_.OnPreEngineRestart();
runtime_controller_ = runtime_controller_->Clone();
pointer_data_dispatcher_ =
dispatcher_maker_(*animator_, *runtime_controller_, task_runners_);
UpdateAssetManager(nullptr);
return Run(std::move(configuration)) == Engine::RunStatus::Success;
}
Expand Down Expand Up @@ -381,12 +389,12 @@ void Engine::HandleSettingsPlatformMessage(PlatformMessage* message) {
}
}

void Engine::DispatchPointerDataPacket(const PointerDataPacket& packet,
uint64_t trace_flow_id) {
void Engine::DispatchPointerDataPacket(
std::unique_ptr<PointerDataPacket> packet,
uint64_t trace_flow_id) {
TRACE_EVENT0("flutter", "Engine::DispatchPointerDataPacket");
TRACE_FLOW_STEP("flutter", "PointerEvent", trace_flow_id);
animator_->EnqueueTraceFlowId(trace_flow_id);
runtime_controller_->DispatchPointerDataPacket(packet);
pointer_data_dispatcher_->DispatchPacket(std::move(packet), trace_flow_id);
}

void Engine::DispatchSemanticsAction(int id,
Expand Down Expand Up @@ -434,6 +442,8 @@ void Engine::Render(std::unique_ptr<flutter::LayerTree> layer_tree) {

layer_tree->set_frame_size(frame_size);
animator_->Render(std::move(layer_tree));

pointer_data_dispatcher_->OnFrameLayerTreeReceived();
}

void Engine::UpdateSemantics(SemanticsNodeUpdates update,
Expand Down
14 changes: 13 additions & 1 deletion shell/common/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include "flutter/runtime/runtime_controller.h"
#include "flutter/runtime/runtime_delegate.h"
#include "flutter/shell/common/animator.h"
#include "flutter/shell/common/platform_view.h"
#include "flutter/shell/common/pointer_data_dispatcher.h"
#include "flutter/shell/common/rasterizer.h"
#include "flutter/shell/common/run_configuration.h"
#include "flutter/shell/common/shell_io_manager.h"
Expand Down Expand Up @@ -234,6 +236,12 @@ class Engine final : public RuntimeDelegate {
/// tasks that require access to components
/// that cannot be safely accessed by the
/// engine. This is the shell.
/// @param dispatcher_maker The `std::function` provided by
/// `PlatformView` for engine to create the
/// pointer data dispatcher. Similar to other
/// engine resources, this dispatcher_maker and
/// its returned dispatcher is only safe to be
/// called from the UI thread.
/// @param vm An instance of the running Dart VM.
/// @param[in] isolate_snapshot The snapshot used to create the root
/// isolate. Even though the isolate is not
Expand Down Expand Up @@ -265,6 +273,7 @@ class Engine final : public RuntimeDelegate {
/// GPU.
///
Engine(Delegate& delegate,
PointerDataDispatcherMaker& dispatcher_maker,
DartVM& vm,
fml::RefPtr<const DartSnapshot> isolate_snapshot,
fml::RefPtr<const DartSnapshot> shared_snapshot,
Expand Down Expand Up @@ -649,7 +658,7 @@ class Engine final : public RuntimeDelegate {
/// timeline and allow grouping frames and input
/// events into logical chunks.
///
void DispatchPointerDataPacket(const PointerDataPacket& packet,
void DispatchPointerDataPacket(std::unique_ptr<PointerDataPacket> packet,
uint64_t trace_flow_id);

//----------------------------------------------------------------------------
Expand Down Expand Up @@ -705,13 +714,16 @@ class Engine final : public RuntimeDelegate {
const Settings settings_;
std::unique_ptr<Animator> animator_;
std::unique_ptr<RuntimeController> runtime_controller_;
std::unique_ptr<PointerDataDispatcher> pointer_data_dispatcher_;
PointerDataDispatcherMaker dispatcher_maker_; // stored for restart
std::string initial_route_;
ViewportMetrics viewport_metrics_;
std::shared_ptr<AssetManager> asset_manager_;
bool activity_running_;
bool have_surface_;
FontCollection font_collection_;
ImageDecoder image_decoder_;
TaskRunners task_runners_;
fml::WeakPtrFactory<Engine> weak_factory_;

// |RuntimeDelegate|
Expand Down
11 changes: 11 additions & 0 deletions shell/common/fixtures/shell_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ void main() {}

void nativeReportTimingsCallback(List<int> timings) native 'NativeReportTimingsCallback';
void nativeOnBeginFrame(int microseconds) native 'NativeOnBeginFrame';
void nativeOnPointerDataPacket() native 'NativeOnPointerDataPacket';

@pragma('vm:entry-point')
void reportTimingsMain() {
Expand All @@ -32,6 +33,16 @@ void onBeginFrameMain() {
};
}

@pragma('vm:entry-point')
void onPointerDataPacketMain() {
window.onPointerDataPacket = (PointerDataPacket packet) {
nativeOnPointerDataPacket();
};
window.onBeginFrame = (Duration beginTime) {
nativeOnBeginFrame(beginTime.inMicroseconds);
};
}

@pragma('vm:entry-point')
void emptyMain() {}

Expand Down
Loading