Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 1950e72

Browse files
committed
Impl engine
1 parent e4a5acc commit 1950e72

14 files changed

+80
-0
lines changed

lib/ui/dart_ui.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ typedef CanvasPath Path;
9898
V(NativeStringAttribute::initSpellOutStringAttribute) \
9999
V(PlatformConfigurationNativeApi::DefaultRouteName) \
100100
V(PlatformConfigurationNativeApi::ScheduleFrame) \
101+
V(PlatformConfigurationNativeApi::ForceSyncFrame) \
101102
V(PlatformConfigurationNativeApi::Render) \
102103
V(PlatformConfigurationNativeApi::UpdateSemantics) \
103104
V(PlatformConfigurationNativeApi::SetNeedsReportTimings) \

lib/ui/platform_dispatcher.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,11 +801,36 @@ class PlatformDispatcher {
801801
///
802802
/// * [SchedulerBinding], the Flutter framework class which manages the
803803
/// scheduling of frames.
804+
/// * [forceSyncFrame], a similar method that is used in rare cases that
805+
/// a frame must be rendered immediately.
804806
void scheduleFrame() => _scheduleFrame();
805807

806808
@Native<Void Function()>(symbol: 'PlatformConfigurationNativeApi::ScheduleFrame')
807809
external static void _scheduleFrame();
808810

811+
/// Immediately render a frame by invoking the [onBeginFrame] and
812+
/// [onDrawFrame] callbacks synchronously.
813+
///
814+
/// This method performs the same computation for a frame as [scheduleFrame]
815+
/// does, but instead of doing so at an appropriate opportunity, the render is
816+
/// completed synchronously within this call.
817+
///
818+
/// Prefer [scheduleFrame] to update the display in normal operation. The
819+
/// [forceSyncFrame] method is designed for situations that require a frame is
820+
/// rendered as soon as possible, even at the cost of rendering quality. An
821+
/// example of using this method is [SchedulerBinding.scheduleWarmUpFrame],
822+
/// which is called during application startup so that the first frame can be
823+
/// presented to the screen a few extra milliseconds earlier.
824+
///
825+
/// See also:
826+
///
827+
/// * [SchedulerBinding.scheduleWarmUpFrame], which uses this method.
828+
/// * [scheduleFrame].
829+
void forceSyncFrame() => _forceSyncFrame();
830+
831+
@Native<Void Function()>(symbol: 'PlatformConfigurationNativeApi::ForceSyncFrame')
832+
external static void _forceSyncFrame();
833+
809834
/// Additional accessibility features that may be enabled by the platform.
810835
AccessibilityFeatures get accessibilityFeatures => _configuration.accessibilityFeatures;
811836

lib/ui/window/platform_configuration.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,11 @@ void PlatformConfigurationNativeApi::ScheduleFrame() {
589589
UIDartState::Current()->platform_configuration()->client()->ScheduleFrame();
590590
}
591591

592+
void PlatformConfigurationNativeApi::ForceSyncFrame() {
593+
UIDartState::ThrowIfUIOperationsProhibited();
594+
UIDartState::Current()->platform_configuration()->client()->ForceSyncFrame();
595+
}
596+
592597
void PlatformConfigurationNativeApi::UpdateSemantics(SemanticsUpdate* update) {
593598
UIDartState::ThrowIfUIOperationsProhibited();
594599
UIDartState::Current()->platform_configuration()->client()->UpdateSemantics(

lib/ui/window/platform_configuration.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ class PlatformConfigurationClient {
6565
///
6666
virtual void ScheduleFrame() = 0;
6767

68+
//--------------------------------------------------------------------------
69+
/// @brief
70+
///
71+
virtual void ForceSyncFrame() = 0;
72+
6873
//--------------------------------------------------------------------------
6974
/// @brief Updates the client's rendering on the GPU with the newly
7075
/// provided Scene.
@@ -557,6 +562,8 @@ class PlatformConfigurationNativeApi {
557562

558563
static void ScheduleFrame();
559564

565+
static void ForceSyncFrame();
566+
560567
static void Render(int64_t view_id,
561568
Scene* scene,
562569
double width,

lib/web_ui/lib/platform_dispatcher.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ abstract class PlatformDispatcher {
9090

9191
void scheduleFrame();
9292

93+
void forceSyncFrame();
94+
9395
Future<void> render(Scene scene, [FlutterView view]);
9496

9597
AccessibilityFeatures get accessibilityFeatures;

lib/web_ui/lib/src/engine/platform_dispatcher.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,12 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher {
771771
scheduleFrameCallback!();
772772
}
773773

774+
@override
775+
void forceSyncFrame() {
776+
// TODO(dkwingsmt): Call beginFrame and drawFrame, since the framework
777+
// will no longer call them once it switches to forceSyncFrame.
778+
}
779+
774780
/// Updates the application's rendering on the GPU with the newly provided
775781
/// [Scene]. This function must be called within the scope of the
776782
/// [onBeginFrame] or [onDrawFrame] callbacks being invoked. If this function

runtime/runtime_controller.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,11 @@ void RuntimeController::ScheduleFrame() {
340340
client_.ScheduleFrame();
341341
}
342342

343+
// |PlatformConfigurationClient|
344+
void RuntimeController::ForceSyncFrame() {
345+
client_.ForceSyncFrame();
346+
}
347+
343348
// |PlatformConfigurationClient|
344349
void RuntimeController::Render(Scene* scene, double width, double height) {
345350
// TODO(dkwingsmt): Currently only supports a single window.

runtime/runtime_controller.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,9 @@ class RuntimeController : public PlatformConfigurationClient {
657657
// |PlatformConfigurationClient|
658658
void ScheduleFrame() override;
659659

660+
// |PlatformConfigurationClient|
661+
void ForceSyncFrame() override;
662+
660663
// |PlatformConfigurationClient|
661664
void Render(Scene* scene, double width, double height) override;
662665

runtime/runtime_delegate.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class RuntimeDelegate {
2525

2626
virtual void ScheduleFrame(bool regenerate_layer_trees = true) = 0;
2727

28+
virtual void ForceSyncFrame() = 0;
29+
2830
virtual void Render(std::unique_ptr<flutter::LayerTree> layer_tree,
2931
float device_pixel_ratio) = 0;
3032

shell/common/animator.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,20 @@ void Animator::AwaitVSync() {
264264
}
265265
}
266266

267+
void Animator::ForceSyncFrame() {
268+
TRACE_EVENT_ASYNC_BEGIN0("flutter", "Forced Frame Request Pending",
269+
frame_request_number_);
270+
regenerate_layer_trees_ = true;
271+
272+
const fml::TimePoint frame_start_time = fml::TimePoint::Now();
273+
const fml::TimePoint frame_target_time = frame_start_time;
274+
275+
std::unique_ptr<FrameTimingsRecorder> frame_timings_recorder =
276+
std::make_unique<FrameTimingsRecorder>();
277+
frame_timings_recorder->RecordVsync(frame_start_time, frame_target_time);
278+
BeginFrame(std::move(frame_timings_recorder));
279+
}
280+
267281
void Animator::ScheduleSecondaryVsyncCallback(uintptr_t id,
268282
const fml::closure& callback) {
269283
waiter_->ScheduleSecondaryCallback(id, callback);

0 commit comments

Comments
 (0)