-
Notifications
You must be signed in to change notification settings - Fork 6k
Add scheduleWarmUpFrame #50570
Add scheduleWarmUpFrame #50570
Changes from 22 commits
1950e72
f55dfdf
7f76c5f
31a5ea3
590287d
40b269b
2d70a0f
4af9f06
bfe5570
21439c4
1bd21db
4f41658
eeac064
9c5bce4
cdcf71a
7ab7d8e
afbcfae
7381087
05d3d2d
06957bb
68953c0
a9b7511
8731e47
cdeffd9
5d9f48b
1589c59
556984f
2b6d3b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -801,11 +801,46 @@ class PlatformDispatcher { | |
/// | ||
/// * [SchedulerBinding], the Flutter framework class which manages the | ||
/// scheduling of frames. | ||
/// * [scheduleWarmUpFrame], which should only be used to schedule warm up | ||
/// frames. | ||
void scheduleFrame() => _scheduleFrame(); | ||
|
||
@Native<Void Function()>(symbol: 'PlatformConfigurationNativeApi::ScheduleFrame') | ||
external static void _scheduleFrame(); | ||
|
||
/// Schedule a frame to run as soon as possible, rather than waiting for the | ||
/// engine to request a frame in response to a system "Vsync" signal. | ||
/// | ||
/// This method is used during application startup so that the first frame | ||
/// (which is likely to be quite expensive) can start a few extra milliseconds | ||
/// earlier. Using it in other situations might lead to unintended results, | ||
/// such as screen tearing. Depending on platforms and situations, the warm up | ||
/// frame might or might not be actually rendered onto the screen. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we also want to use this when rendering the first frame in a new There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good point, although I imagine this would require more work. Can I open an issue to leave the optimization for later? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this optimization works for individual views. Because of the unified widget tree we can only produce frames for all views at once and cannot target individual views. This optimization only works for the app as a whole. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope, I was just hypothesizing. If we don't need it, then we don't need it. My gut feeling is that we don't need any of this on the web. So I'm actually a little sad that this API even exists. |
||
/// | ||
/// For more introduction to the warm up frame, see | ||
/// [SchedulerBinding.scheduleWarmUpFrame]. | ||
/// | ||
/// This method uses the provided callbacks as the begin frame callback and | ||
/// the draw frame callback instead of [onBeginFrame] and [onDrawFrame]. | ||
/// | ||
/// See also: | ||
/// | ||
/// * [SchedulerBinding.scheduleWarmUpFrame], which uses this method, and | ||
/// introduces the warm up frame in more details. | ||
/// * [scheduleFrame], which schedules the frame at the next appropriate | ||
/// opportunity and should be used to render regular frames. | ||
void scheduleWarmUpFrame({required VoidCallback beginFrame, required VoidCallback drawFrame}) { | ||
dkwingsmt marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is meant for first frame only, why not call it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The biggest reason, in my opinion, is that this frame is not guaranteed to be rendered, for example if Besides, I don't want to give developers the impression that scheduling the first frame using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In addition to what Tong said: The warmup frame is also used in hot reload scenarios where it isn't the first frame of the app. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The semantics of this method sound pretty complicated. I guess warm up is fine then. Should we have some assertions in the engine for this method? For example, should we make sure it's only called for the first frame, and is never called after a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if it's possible, since |
||
// We use timers here to ensure that microtasks flush in between. | ||
Timer.run(beginFrame); | ||
Timer.run(() { | ||
drawFrame(); | ||
_endWarmUpFrame(); | ||
}); | ||
} | ||
|
||
@Native<Void Function()>(symbol: 'PlatformConfigurationNativeApi::EndWarmUpFrame') | ||
external static void _endWarmUpFrame(); | ||
|
||
/// Additional accessibility features that may be enabled by the platform. | ||
AccessibilityFeatures get accessibilityFeatures => _configuration.accessibilityFeatures; | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.