Skip to content

Commit

Permalink
Revert flutter#47323
Browse files Browse the repository at this point in the history
  • Loading branch information
dkwingsmt committed Jan 2, 2024
1 parent e95e123 commit d2df0d0
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 23 deletions.
58 changes: 39 additions & 19 deletions lib/ui/platform_dispatcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,9 @@ class PlatformDispatcher {
_invoke(onMetricsChanged, _onMetricsChangedZone);
}

// The [FlutterView]s for which [FlutterView.render] has already been called
// during the current [onBeginFrame]/[onDrawFrame] callback sequence.
// A debug-only variable that stores the [FlutterView]s for which
// [FlutterView.render] has already been called during the current
// [onBeginFrame]/[onDrawFrame] callback sequence.
//
// It is null outside the scope of those callbacks indicating that calls to
// [FlutterView.render] must be ignored. Furthermore, if a given [FlutterView]
Expand All @@ -319,9 +320,16 @@ class PlatformDispatcher {
// Between [onBeginFrame] and [onDrawFrame] the properties value is
// temporarily stored in `_renderedViewsBetweenCallbacks` so that it survives
// the gap between the two callbacks.
Set<FlutterView>? _renderedViews;
// The `_renderedViews` value between `_beginFrame` and `_drawFrame`.
Set<FlutterView>? _renderedViewsBetweenCallbacks;
//
// In release build, this variable is null, and therefore the calling rule is
// not enforced. This is because the check might hurt cold startup delay;
// see https://github.com/flutter/engine/pull/46919.
Set<FlutterView>? _debugRenderedViews;
// A debug-only variable that temporarily stores the `_renderedViews` value
// between `_beginFrame` and `_drawFrame`.
//
// In release build, this variable is null.
Set<FlutterView>? _debugRenderedViewsBetweenCallbacks;

/// A callback invoked when any view begins a frame.
///
Expand All @@ -343,20 +351,26 @@ class PlatformDispatcher {

// Called from the engine, via hooks.dart
void _beginFrame(int microseconds) {
assert(_renderedViews == null);
assert(_renderedViewsBetweenCallbacks == null);
_renderedViews = <FlutterView>{};
assert(_debugRenderedViews == null);
assert(_debugRenderedViewsBetweenCallbacks == null);
assert(() {
_debugRenderedViews = <FlutterView>{};
return true;
}());

_invoke1<Duration>(
onBeginFrame,
_onBeginFrameZone,
Duration(microseconds: microseconds),
);

assert(_renderedViews != null);
assert(_renderedViewsBetweenCallbacks == null);
_renderedViewsBetweenCallbacks = _renderedViews;
_renderedViews = null;
assert(_debugRenderedViews != null);
assert(_debugRenderedViewsBetweenCallbacks == null);
assert(() {
_debugRenderedViewsBetweenCallbacks = _debugRenderedViews;
_debugRenderedViews = null;
return true;
}());
}

/// A callback that is invoked for each frame after [onBeginFrame] has
Expand All @@ -374,16 +388,22 @@ class PlatformDispatcher {

// Called from the engine, via hooks.dart
void _drawFrame() {
assert(_renderedViews == null);
assert(_renderedViewsBetweenCallbacks != null);
_renderedViews = _renderedViewsBetweenCallbacks;
_renderedViewsBetweenCallbacks = null;
assert(_debugRenderedViews == null);
assert(_debugRenderedViewsBetweenCallbacks != null);
assert(() {
_debugRenderedViews = _debugRenderedViewsBetweenCallbacks;
_debugRenderedViewsBetweenCallbacks = null;
return true;
}());

_invoke(onDrawFrame, _onDrawFrameZone);

assert(_renderedViews != null);
assert(_renderedViewsBetweenCallbacks == null);
_renderedViews = null;
assert(_debugRenderedViews != null);
assert(_debugRenderedViewsBetweenCallbacks == null);
assert(() {
_debugRenderedViews = null;
return true;
}());
}

/// A callback that is invoked when pointer data is available.
Expand Down
10 changes: 8 additions & 2 deletions lib/ui/window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,14 @@ class FlutterView {
/// painting.
void render(Scene scene, {Size? size}) {
// Duplicated calls or calls outside of onBeginFrame/onDrawFrame (indicated
// by _renderedViews being null) are ignored. See _renderedViews.
final bool validRender = platformDispatcher._renderedViews?.add(this) ?? false;
// by _debugRenderedViews being null) are ignored. See _debugRenderedViews.
// TODO(dkwingsmt): We should change this skip into an assertion.
// https://github.com/flutter/flutter/issues/137073
bool validRender = true;
assert(() {
validRender = platformDispatcher._debugRenderedViews?.add(this) ?? false;
return true;
}());
if (validRender) {
_render(scene as _NativeScene, size?.width ?? physicalSize.width, size?.height ?? physicalSize.height);
}
Expand Down
1 change: 1 addition & 0 deletions shell/common/animator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ void Animator::Render(std::unique_ptr<flutter::LayerTree> layer_tree,
if (frame_timings_recorder_ == nullptr) {
return;
}

has_rendered_ = true;

TRACE_EVENT_WITH_FRAME_NUMBER(frame_timings_recorder_, "flutter",
Expand Down
3 changes: 1 addition & 2 deletions shell/common/animator.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ class Animator final {
///
/// This method must be called during a vsync callback, or
/// technically, between Animator::BeginFrame and Animator::EndFrame
/// (both private methods). Otherwise, an assertion will be
/// triggered.
/// (both private methods). Otherwise, this call will be ignored.
///
void Render(std::unique_ptr<flutter::LayerTree> layer_tree,
float device_pixel_ratio);
Expand Down

0 comments on commit d2df0d0

Please sign in to comment.