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

Commit 7ea14b3

Browse files
dkwingsmtharryterkelsen
authored andcommitted
Revert "Reland: Enforce the rule of calling FlutterView.Render (#45300)" (#46919)
Reverts #45555 due to possible performance regression, b/304898239
1 parent 13f320b commit 7ea14b3

File tree

7 files changed

+23
-370
lines changed

7 files changed

+23
-370
lines changed

lib/ui/fixtures/ui_test.dart

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,45 +1100,3 @@ external void _callHook(
11001100
Object? arg20,
11011101
Object? arg21,
11021102
]);
1103-
1104-
Scene _createRedBoxScene(Size size) {
1105-
final SceneBuilder builder = SceneBuilder();
1106-
builder.pushOffset(0.0, 0.0);
1107-
final Paint paint = Paint()
1108-
..color = Color.fromARGB(255, 255, 0, 0)
1109-
..style = PaintingStyle.fill;
1110-
final PictureRecorder baseRecorder = PictureRecorder();
1111-
final Canvas canvas = Canvas(baseRecorder);
1112-
canvas.drawRect(Rect.fromLTRB(0.0, 0.0, size.width, size.height), paint);
1113-
final Picture picture = baseRecorder.endRecording();
1114-
builder.addPicture(Offset(0.0, 0.0), picture);
1115-
builder.pop();
1116-
return builder.build();
1117-
}
1118-
1119-
@pragma('vm:entry-point')
1120-
void incorrectImmediateRender() {
1121-
PlatformDispatcher.instance.views.first.render(_createRedBoxScene(Size(2, 2)));
1122-
_finish();
1123-
// Don't schedule a frame here. This test only checks if the
1124-
// [FlutterView.render] call is propagated to PlatformConfiguration.render
1125-
// and thus doesn't need anything from `Animator` or `Engine`, which,
1126-
// besides, are not even created in the native side at all.
1127-
}
1128-
1129-
@pragma('vm:entry-point')
1130-
void incorrectDoubleRender() {
1131-
PlatformDispatcher.instance.onBeginFrame = (Duration value) {
1132-
PlatformDispatcher.instance.views.first.render(_createRedBoxScene(Size(2, 2)));
1133-
PlatformDispatcher.instance.views.first.render(_createRedBoxScene(Size(3, 3)));
1134-
};
1135-
PlatformDispatcher.instance.onDrawFrame = () {
1136-
PlatformDispatcher.instance.views.first.render(_createRedBoxScene(Size(4, 4)));
1137-
PlatformDispatcher.instance.views.first.render(_createRedBoxScene(Size(5, 5)));
1138-
};
1139-
_finish();
1140-
// Don't schedule a frame here. This test only checks if the
1141-
// [FlutterView.render] call is propagated to PlatformConfiguration.render
1142-
// and thus doesn't need anything from `Animator` or `Engine`, which,
1143-
// besides, are not even created in the native side at all.
1144-
}

lib/ui/platform_dispatcher.dart

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -308,21 +308,6 @@ class PlatformDispatcher {
308308
_invoke(onMetricsChanged, _onMetricsChangedZone);
309309
}
310310

311-
// [FlutterView]s for which [FlutterView.render] has already been called
312-
// during the current [onBeginFrame]/[onDrawFrame] callback sequence.
313-
//
314-
// The field is null outside the scope of those callbacks indicating that
315-
// calls to [FlutterView.render] must be ignored. Furthermore, if a given
316-
// [FlutterView] is already present in this set when its [FlutterView.render]
317-
// is called again, that call must be ignored as a duplicate.
318-
//
319-
// Between [onBeginFrame] and [onDrawFrame] the properties value is
320-
// temporarily stored in `_renderedViewsBetweenCallbacks` so that it survives
321-
// the gap between the two callbacks.
322-
Set<FlutterView>? _renderedViews;
323-
// Temporary storage of the `_renderedViews` value between `_beginFrame` and
324-
// `_drawFrame`.
325-
Set<FlutterView>? _renderedViewsBetweenCallbacks;
326311

327312
/// A callback invoked when any view begins a frame.
328313
///
@@ -344,20 +329,11 @@ class PlatformDispatcher {
344329

345330
// Called from the engine, via hooks.dart
346331
void _beginFrame(int microseconds) {
347-
assert(_renderedViews == null);
348-
assert(_renderedViewsBetweenCallbacks == null);
349-
350-
_renderedViews = <FlutterView>{};
351332
_invoke1<Duration>(
352333
onBeginFrame,
353334
_onBeginFrameZone,
354335
Duration(microseconds: microseconds),
355336
);
356-
_renderedViewsBetweenCallbacks = _renderedViews;
357-
_renderedViews = null;
358-
359-
assert(_renderedViews == null);
360-
assert(_renderedViewsBetweenCallbacks != null);
361337
}
362338

363339
/// A callback that is invoked for each frame after [onBeginFrame] has
@@ -375,16 +351,7 @@ class PlatformDispatcher {
375351

376352
// Called from the engine, via hooks.dart
377353
void _drawFrame() {
378-
assert(_renderedViews == null);
379-
assert(_renderedViewsBetweenCallbacks != null);
380-
381-
_renderedViews = _renderedViewsBetweenCallbacks;
382-
_renderedViewsBetweenCallbacks = null;
383354
_invoke(onDrawFrame, _onDrawFrameZone);
384-
_renderedViews = null;
385-
386-
assert(_renderedViews == null);
387-
assert(_renderedViewsBetweenCallbacks == null);
388355
}
389356

390357
/// A callback that is invoked when pointer data is available.

lib/ui/window.dart

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -327,21 +327,14 @@ class FlutterView {
327327

328328
/// Updates the view's rendering on the GPU with the newly provided [Scene].
329329
///
330-
/// ## Requirement for calling this method
331-
///
332-
/// This method must be called within the synchronous scope of the
330+
/// This function must be called within the scope of the
333331
/// [PlatformDispatcher.onBeginFrame] or [PlatformDispatcher.onDrawFrame]
334-
/// callbacks. Calls out of this scope will be ignored. To use this method,
335-
/// create a callback that calls this method instead, and assign it to either
336-
/// of the fields above; then schedule a frame, which is done typically with
337-
/// [PlatformDispatcher.scheduleFrame]. Also, make sure the callback does not
338-
/// have `await` before the `FlutterWindow.render` call.
339-
///
340-
/// Additionally, this method can only be called once for each view during a
341-
/// single [PlatformDispatcher.onBeginFrame]/[PlatformDispatcher.onDrawFrame]
342-
/// callback sequence. Duplicate calls will be ignored in production.
332+
/// callbacks being invoked.
343333
///
344-
/// ## How to record a scene
334+
/// If this function is called a second time during a single
335+
/// [PlatformDispatcher.onBeginFrame]/[PlatformDispatcher.onDrawFrame]
336+
/// callback sequence or called outside the scope of those callbacks, the call
337+
/// will be ignored.
345338
///
346339
/// To record graphical operations, first create a [PictureRecorder], then
347340
/// construct a [Canvas], passing that [PictureRecorder] to its constructor.
@@ -360,14 +353,7 @@ class FlutterView {
360353
/// scheduling of frames.
361354
/// * [RendererBinding], the Flutter framework class which manages layout and
362355
/// painting.
363-
void render(Scene scene) {
364-
if (platformDispatcher._renderedViews?.add(this) != true) {
365-
// Duplicated calls or calls outside of onBeginFrame/onDrawFrame
366-
// (indicated by _renderedViews being null) are ignored, as documented.
367-
return;
368-
}
369-
_render(scene as _NativeScene);
370-
}
356+
void render(Scene scene) => _render(scene as _NativeScene);
371357

372358
@Native<Void Function(Pointer<Void>)>(symbol: 'PlatformConfigurationNativeApi::Render')
373359
external static void _render(_NativeScene scene);

0 commit comments

Comments
 (0)