From 9e54a5ded01000bc19ca1b06bf5e974a55320c3b Mon Sep 17 00:00:00 2001 From: Michael Goderbauer Date: Wed, 8 Mar 2023 16:37:47 -0800 Subject: [PATCH] Remove single-window assumption from scenario_app (flutter/engine#40156) Remove single-window assumption from scenario_app --- .../ios/Runner/GeneratedPluginRegistrant.h | 2 + .../ios/Runner/GeneratedPluginRegistrant.m | 2 + .../testing/scenario_app/lib/main.dart | 15 +- .../lib/src/animated_color_square.dart | 25 +- .../scenario_app/lib/src/bogus_font_text.dart | 9 +- .../lib/src/get_bitmap_scenario.dart | 13 +- .../lib/src/initial_route_reply.dart | 11 +- .../lib/src/locale_initialization.dart | 13 +- .../lib/src/platform_echo_mixin.dart | 2 +- .../scenario_app/lib/src/platform_view.dart | 280 ++++++++---------- .../scenario_app/lib/src/poppable_screen.dart | 19 +- .../scenario_app/lib/src/scenario.dart | 10 +- .../scenario_app/lib/src/scenarios.dart | 92 +++--- .../testing/scenario_app/lib/src/texture.dart | 11 +- .../lib/src/touches_scenario.dart | 6 +- .../flutter/testing/scenario_app/pubspec.yaml | 2 +- 16 files changed, 236 insertions(+), 276 deletions(-) diff --git a/engine/src/flutter/testing/scenario_app/ios/Runner/GeneratedPluginRegistrant.h b/engine/src/flutter/testing/scenario_app/ios/Runner/GeneratedPluginRegistrant.h index ed9a5c6169..7a89092719 100644 --- a/engine/src/flutter/testing/scenario_app/ios/Runner/GeneratedPluginRegistrant.h +++ b/engine/src/flutter/testing/scenario_app/ios/Runner/GeneratedPluginRegistrant.h @@ -2,6 +2,8 @@ // Generated file. Do not edit. // +// clang-format off + #ifndef GeneratedPluginRegistrant_h #define GeneratedPluginRegistrant_h diff --git a/engine/src/flutter/testing/scenario_app/ios/Runner/GeneratedPluginRegistrant.m b/engine/src/flutter/testing/scenario_app/ios/Runner/GeneratedPluginRegistrant.m index 60dfa42b32..efe65ecccf 100644 --- a/engine/src/flutter/testing/scenario_app/ios/Runner/GeneratedPluginRegistrant.m +++ b/engine/src/flutter/testing/scenario_app/ios/Runner/GeneratedPluginRegistrant.m @@ -2,6 +2,8 @@ // Generated file. Do not edit. // +// clang-format off + #import "GeneratedPluginRegistrant.h" @implementation GeneratedPluginRegistrant diff --git a/engine/src/flutter/testing/scenario_app/lib/main.dart b/engine/src/flutter/testing/scenario_app/lib/main.dart index 6650eba314..f7a9e61fd1 100644 --- a/engine/src/flutter/testing/scenario_app/lib/main.dart +++ b/engine/src/flutter/testing/scenario_app/lib/main.dart @@ -12,7 +12,11 @@ import 'dart:ui'; import 'src/scenarios.dart'; void main() { - window + // TODO(goderbauer): Create a window if embedder doesn't provide an implicit + // view to draw into once we have a windowing API and set the window's + // FlutterView to the _view property. + assert(PlatformDispatcher.instance.implicitView != null); + PlatformDispatcher.instance ..onPlatformMessage = _handlePlatformMessage ..onBeginFrame = _onBeginFrame ..onDrawFrame = _onDrawFrame @@ -22,15 +26,18 @@ void main() { final ByteData data = ByteData(1); data.setUint8(0, 1); - window.sendPlatformMessage('waiting_for_status', data, null); + PlatformDispatcher.instance.sendPlatformMessage('waiting_for_status', data, null); } +/// The FlutterView into which the [Scenario]s will be rendered. +FlutterView get _view => PlatformDispatcher.instance.implicitView!; + void _handleDriverMessage(Map call) { final String? methodName = call['method'] as String?; switch (methodName) { case 'set_scenario': assert(call['args'] != null); - loadScenario(call['args'] as Map); + loadScenario(call['args'] as Map, _view); break; default: throw 'Unimplemented method: $methodName.'; @@ -86,7 +93,7 @@ void _onBeginFrame(Duration duration) { if (currentScenario == null) { final SceneBuilder builder = SceneBuilder(); final Scene scene = builder.build(); - window.render(scene); + _view.render(scene); scene.dispose(); return; } diff --git a/engine/src/flutter/testing/scenario_app/lib/src/animated_color_square.dart b/engine/src/flutter/testing/scenario_app/lib/src/animated_color_square.dart index 24afd96224..90096168c1 100644 --- a/engine/src/flutter/testing/scenario_app/lib/src/animated_color_square.dart +++ b/engine/src/flutter/testing/scenario_app/lib/src/animated_color_square.dart @@ -14,21 +14,18 @@ import 'scenario.dart'; /// that are constantly changing. class AnimatedColorSquareScenario extends Scenario { /// Creates the AnimatedColorSquare scenario. - /// - /// The [dispatcher] parameter must not be null. - AnimatedColorSquareScenario(PlatformDispatcher dispatcher) - : super(dispatcher); + AnimatedColorSquareScenario(super.view); static const double _squareSize = 200; /// Used to animate the red value in the color of the square. final _NumberSwinger _r = _NumberSwinger(0, 255); - _NumberSwinger _top = _NumberSwinger( + late _NumberSwinger _top = _NumberSwinger( 0, - window.physicalSize.height - _squareSize, + view.physicalSize.height - _squareSize, ); - _NumberSwinger _left = _NumberSwinger( + late _NumberSwinger _left = _NumberSwinger( 0, - window.physicalSize.width - _squareSize, + view.physicalSize.width - _squareSize, ); @override @@ -50,26 +47,26 @@ class AnimatedColorSquareScenario extends Scenario { willChangeHint: true, ); final Scene scene = builder.build(); - window.render(scene); + view.render(scene); scene.dispose(); } @override void onDrawFrame() { - window.scheduleFrame(); + view.platformDispatcher.scheduleFrame(); } @override void onMetricsChanged() { _top = _NumberSwinger( 0, - window.physicalSize.height - _squareSize, - math.min(_top.current, window.physicalSize.height - _squareSize), + view.physicalSize.height - _squareSize, + math.min(_top.current, view.physicalSize.height - _squareSize), ); _left = _NumberSwinger( 0, - window.physicalSize.width - _squareSize, - math.min(_left.current, window.physicalSize.width - _squareSize), + view.physicalSize.width - _squareSize, + math.min(_left.current, view.physicalSize.width - _squareSize), ); } } diff --git a/engine/src/flutter/testing/scenario_app/lib/src/bogus_font_text.dart b/engine/src/flutter/testing/scenario_app/lib/src/bogus_font_text.dart index cee63ce7b9..57061c0f8c 100644 --- a/engine/src/flutter/testing/scenario_app/lib/src/bogus_font_text.dart +++ b/engine/src/flutter/testing/scenario_app/lib/src/bogus_font_text.dart @@ -11,10 +11,7 @@ import 'scenario.dart'; /// system default font. class BogusFontText extends Scenario { /// Creates the BogusFontText scenario. - /// - /// The [dispatcher] parameter must not be null. - BogusFontText(PlatformDispatcher dispatcher) - : super(dispatcher); + BogusFontText(super.view); // Semi-arbitrary. final double _screenWidth = 700; @@ -43,11 +40,11 @@ class BogusFontText extends Scenario { willChangeHint: true, ); final Scene scene = builder.build(); - window.render(scene); + view.render(scene); scene.dispose(); sendJsonMessage( - dispatcher: dispatcher, + dispatcher: view.platformDispatcher, channel: 'display_data', json: { 'data': 'ready', diff --git a/engine/src/flutter/testing/scenario_app/lib/src/get_bitmap_scenario.dart b/engine/src/flutter/testing/scenario_app/lib/src/get_bitmap_scenario.dart index 01fb99c5e9..73c7ed03c6 100644 --- a/engine/src/flutter/testing/scenario_app/lib/src/get_bitmap_scenario.dart +++ b/engine/src/flutter/testing/scenario_app/lib/src/get_bitmap_scenario.dart @@ -9,26 +9,23 @@ import 'scenario.dart'; /// A scenario with red on top and blue on the bottom. class GetBitmapScenario extends Scenario { /// Creates the GetBitmap scenario. - /// - /// The [dispatcher] parameter must not be null. - GetBitmapScenario(PlatformDispatcher dispatcher) - : super(dispatcher); + GetBitmapScenario(super.view); @override void onBeginFrame(Duration duration) { final PictureRecorder recorder = PictureRecorder(); final Canvas canvas = Canvas(recorder); - canvas.drawRect(Rect.fromLTWH(0, 0, window.physicalSize.width, 300), + canvas.drawRect(Rect.fromLTWH(0, 0, view.physicalSize.width, 300), Paint()..color = const Color(0xFFFF0000)); canvas.drawRect( - Rect.fromLTWH(0, window.physicalSize.height - 300, - window.physicalSize.width, 300), + Rect.fromLTWH(0, view.physicalSize.height - 300, + view.physicalSize.width, 300), Paint()..color = const Color(0xFF0000FF)); final Picture picture = recorder.endRecording(); final SceneBuilder builder = SceneBuilder(); builder.addPicture(Offset.zero, picture); final Scene scene = builder.build(); - window.render(scene); + view.render(scene); picture.dispose(); scene.dispose(); } diff --git a/engine/src/flutter/testing/scenario_app/lib/src/initial_route_reply.dart b/engine/src/flutter/testing/scenario_app/lib/src/initial_route_reply.dart index 171ab998e3..cd4da1cd8e 100644 --- a/engine/src/flutter/testing/scenario_app/lib/src/initial_route_reply.dart +++ b/engine/src/flutter/testing/scenario_app/lib/src/initial_route_reply.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:ui'; - import 'channel_util.dart'; import 'scenario.dart'; @@ -11,17 +9,14 @@ import 'scenario.dart'; /// route is. class InitialRouteReply extends Scenario { /// Creates the InitialRouteReply. - /// - /// The [window] parameter must not be null. - InitialRouteReply(PlatformDispatcher dispatcher) - : super(dispatcher); + InitialRouteReply(super.view); @override void onBeginFrame(Duration duration) { sendJsonMethodCall( - dispatcher: dispatcher, + dispatcher: view.platformDispatcher, channel: 'initial_route_test_channel', - method: window.defaultRouteName, + method: view.platformDispatcher.defaultRouteName, ); } } diff --git a/engine/src/flutter/testing/scenario_app/lib/src/locale_initialization.dart b/engine/src/flutter/testing/scenario_app/lib/src/locale_initialization.dart index 93f6d2af3a..1185d9b8ef 100644 --- a/engine/src/flutter/testing/scenario_app/lib/src/locale_initialization.dart +++ b/engine/src/flutter/testing/scenario_app/lib/src/locale_initialization.dart @@ -12,8 +12,7 @@ import 'scenario.dart'; /// Sends the received locale data back as semantics information. class LocaleInitialization extends Scenario { /// Constructor - LocaleInitialization(PlatformDispatcher dispatcher) - : super(dispatcher); + LocaleInitialization(super.view); int _tapCount = 0; @@ -26,7 +25,7 @@ class LocaleInitialization extends Scenario { final Canvas canvas = Canvas(recorder); canvas.drawRect( - Rect.fromLTWH(0, 0, window.physicalSize.width, window.physicalSize.height), + Rect.fromLTWH(0, 0, view.physicalSize.width, view.physicalSize.height), Paint()..color = const Color.fromARGB(255, 255, 255, 255), ); final Picture picture = recorder.endRecording(); @@ -36,7 +35,7 @@ class LocaleInitialization extends Scenario { picture, ); final Scene scene = builder.build(); - window.render(scene); + view.render(scene); scene.dispose(); // On the first frame, pretend that it drew a text field. Send the @@ -50,7 +49,7 @@ class LocaleInitialization extends Scenario { // SemanticsAction.tap. actions: 1, rect: const Rect.fromLTRB(0.0, 0.0, 414.0, 48.0), - label: window.locales.toString(), + label: view.platformDispatcher.locales.toString(), labelAttributes: [], textDirection: TextDirection.ltr, textSelectionBase: -1, @@ -82,7 +81,7 @@ class LocaleInitialization extends Scenario { final SemanticsUpdate semanticsUpdate = semanticsUpdateBuilder.build(); - dispatcher.views.first.updateSemantics(semanticsUpdate); + view.updateSemantics(semanticsUpdate); } /// Handle taps. @@ -140,7 +139,7 @@ class LocaleInitialization extends Scenario { final SemanticsUpdate semanticsUpdate = semanticsUpdateBuilder.build(); - dispatcher.views.first.updateSemantics(semanticsUpdate); + view.updateSemantics(semanticsUpdate); _tapCount++; } diff --git a/engine/src/flutter/testing/scenario_app/lib/src/platform_echo_mixin.dart b/engine/src/flutter/testing/scenario_app/lib/src/platform_echo_mixin.dart index 2567fa1cd2..9e80929012 100644 --- a/engine/src/flutter/testing/scenario_app/lib/src/platform_echo_mixin.dart +++ b/engine/src/flutter/testing/scenario_app/lib/src/platform_echo_mixin.dart @@ -16,6 +16,6 @@ mixin PlatformEchoMixin on Scenario { ByteData? data, PlatformMessageResponseCallback? callback, ) { - window.sendPlatformMessage(name, data, null); + view.platformDispatcher.sendPlatformMessage(name, data, null); } } diff --git a/engine/src/flutter/testing/scenario_app/lib/src/platform_view.dart b/engine/src/flutter/testing/scenario_app/lib/src/platform_view.dart index 3a6a29946b..75ccd39520 100644 --- a/engine/src/flutter/testing/scenario_app/lib/src/platform_view.dart +++ b/engine/src/flutter/testing/scenario_app/lib/src/platform_view.dart @@ -39,12 +39,10 @@ List _encodeString(String value) { class PlatformViewScenario extends Scenario with _BasePlatformViewScenarioMixin { /// Creates the PlatformView scenario. - /// - /// The [dispatcher] parameter must not be null. PlatformViewScenario( - PlatformDispatcher dispatcher, { + super.view, { required this.id, - }) : super(dispatcher); + }); /// The platform view identifier. final int id; @@ -54,7 +52,7 @@ class PlatformViewScenario extends Scenario final SceneBuilder builder = SceneBuilder(); addPlatformView( id, - dispatcher: dispatcher, + dispatcher: view.platformDispatcher, sceneBuilder: builder, ); finishBuilder(builder); @@ -65,12 +63,10 @@ class PlatformViewScenario extends Scenario class NonFullScreenFlutterViewPlatformViewScenario extends Scenario with _BasePlatformViewScenarioMixin { /// Creates the PlatformView scenario. - /// - /// The [dispatcher] parameter must not be null. NonFullScreenFlutterViewPlatformViewScenario( - PlatformDispatcher dispatcher, { + super.view, { required this.id, - }) : super(dispatcher); + }); /// The platform view identifier. final int id; @@ -80,7 +76,7 @@ class NonFullScreenFlutterViewPlatformViewScenario extends Scenario final SceneBuilder builder = SceneBuilder(); addPlatformView( id, - dispatcher: dispatcher, + dispatcher: view.platformDispatcher, sceneBuilder: builder, ); finishBuilder(builder); @@ -91,12 +87,10 @@ class NonFullScreenFlutterViewPlatformViewScenario extends Scenario class PlatformViewNoOverlayIntersectionScenario extends Scenario with _BasePlatformViewScenarioMixin { /// Creates the PlatformView scenario. - /// - /// The [dispatcher] parameter must not be null. PlatformViewNoOverlayIntersectionScenario( - PlatformDispatcher dispatcher, { + super.view, { required this.id, - }) : super(dispatcher); + }); /// The platform view identifier. final int id; @@ -107,7 +101,7 @@ class PlatformViewNoOverlayIntersectionScenario extends Scenario addPlatformView( id, - dispatcher: dispatcher, + dispatcher: view.platformDispatcher, sceneBuilder: builder, ); @@ -125,12 +119,10 @@ class PlatformViewNoOverlayIntersectionScenario extends Scenario class PlatformViewLargerThanDisplaySize extends Scenario with _BasePlatformViewScenarioMixin { /// Creates the PlatformView scenario. - /// - /// The [dispatcher] parameter must not be null. PlatformViewLargerThanDisplaySize( - PlatformDispatcher dispatcher, { + super.view, { required this.id, - }) : super(dispatcher); + }); /// The platform view identifier. final int id; @@ -141,7 +133,7 @@ class PlatformViewLargerThanDisplaySize extends Scenario addPlatformView( id, - dispatcher: dispatcher, + dispatcher: view.platformDispatcher, sceneBuilder: builder, width: 15000, height: 60000, @@ -157,12 +149,10 @@ class PlatformViewLargerThanDisplaySize extends Scenario class PlatformViewPartialIntersectionScenario extends Scenario with _BasePlatformViewScenarioMixin { /// Creates the PlatformView scenario. - /// - /// The [dispatcher] parameter must not be null. PlatformViewPartialIntersectionScenario( - PlatformDispatcher dispatcher, { + super.view, { required this.id, - }) : super(dispatcher); + }); /// The platform view identifier . final int id; @@ -173,7 +163,7 @@ class PlatformViewPartialIntersectionScenario extends Scenario addPlatformView( id, - dispatcher: dispatcher, + dispatcher: view.platformDispatcher, sceneBuilder: builder, ); @@ -188,12 +178,10 @@ class PlatformViewPartialIntersectionScenario extends Scenario class PlatformViewTwoIntersectingOverlaysScenario extends Scenario with _BasePlatformViewScenarioMixin { /// Creates the PlatformView scenario. - /// - /// The [dispatcher] parameter must not be null. PlatformViewTwoIntersectingOverlaysScenario( - PlatformDispatcher dispatcher, { + super.view, { required this.id, - }) : super(dispatcher); + }); /// The platform view identifier. final int id; @@ -204,7 +192,7 @@ class PlatformViewTwoIntersectingOverlaysScenario extends Scenario addPlatformView( id, - dispatcher: dispatcher, + dispatcher: view.platformDispatcher, sceneBuilder: builder, ); final PictureRecorder recorder = PictureRecorder(); @@ -222,7 +210,7 @@ class PlatformViewTwoIntersectingOverlaysScenario extends Scenario final Picture picture = recorder.endRecording(); builder.addPicture(const Offset(300, 300), picture); final Scene scene = builder.build(); - window.render(scene); + view.render(scene); scene.dispose(); } } @@ -231,12 +219,10 @@ class PlatformViewTwoIntersectingOverlaysScenario extends Scenario class PlatformViewOneOverlayTwoIntersectingOverlaysScenario extends Scenario with _BasePlatformViewScenarioMixin { /// Creates the PlatformView scenario. - /// - /// The [dispatcher] parameter must not be null. PlatformViewOneOverlayTwoIntersectingOverlaysScenario( - PlatformDispatcher dispatcher, { + super.view, { required this.id, - }) : super(dispatcher); + }); /// The platform view identifier. final int id; @@ -247,7 +233,7 @@ class PlatformViewOneOverlayTwoIntersectingOverlaysScenario extends Scenario addPlatformView( id, - dispatcher: dispatcher, + dispatcher: view.platformDispatcher, sceneBuilder: builder, ); @@ -271,7 +257,7 @@ class PlatformViewOneOverlayTwoIntersectingOverlaysScenario extends Scenario final Picture picture = recorder.endRecording(); builder.addPicture(const Offset(300, 300), picture); final Scene scene = builder.build(); - window.render(scene); + view.render(scene); scene.dispose(); } } @@ -280,13 +266,11 @@ class PlatformViewOneOverlayTwoIntersectingOverlaysScenario extends Scenario class MultiPlatformViewWithoutOverlaysScenario extends Scenario with _BasePlatformViewScenarioMixin { /// Creates the PlatformView scenario. - /// - /// The [dispatcher] parameter must not be null. MultiPlatformViewWithoutOverlaysScenario( - PlatformDispatcher dispatcher, { + super.view, { required this.firstId, required this.secondId, - }) : super(dispatcher); + }); /// The platform view identifier to use for the first platform view. final int firstId; @@ -302,7 +286,7 @@ class MultiPlatformViewWithoutOverlaysScenario extends Scenario addPlatformView( firstId, - dispatcher: dispatcher, + dispatcher: view.platformDispatcher, sceneBuilder: builder, text: 'platform view 1', ); @@ -311,7 +295,7 @@ class MultiPlatformViewWithoutOverlaysScenario extends Scenario addPlatformView( secondId, - dispatcher: dispatcher, + dispatcher: view.platformDispatcher, sceneBuilder: builder, text: 'platform view 2', ); @@ -327,7 +311,7 @@ class MultiPlatformViewWithoutOverlaysScenario extends Scenario builder.pop(); final Scene scene = builder.build(); - window.render(scene); + view.render(scene); scene.dispose(); } } @@ -336,12 +320,10 @@ class MultiPlatformViewWithoutOverlaysScenario extends Scenario class PlatformViewMaxOverlaysScenario extends Scenario with _BasePlatformViewScenarioMixin { /// Creates the PlatformView scenario. - /// - /// The [dispatcher] parameter must not be null. PlatformViewMaxOverlaysScenario( - PlatformDispatcher dispatcher, { + super.view, { required this.id, - }) : super(dispatcher); + }); /// The platform view identifier. final int id; @@ -352,7 +334,7 @@ class PlatformViewMaxOverlaysScenario extends Scenario addPlatformView( id, - dispatcher: dispatcher, + dispatcher: view.platformDispatcher, sceneBuilder: builder, ); final PictureRecorder recorder = PictureRecorder(); @@ -380,7 +362,7 @@ class PlatformViewMaxOverlaysScenario extends Scenario final Picture picture = recorder.endRecording(); builder.addPicture(const Offset(300, 300), picture); final Scene scene = builder.build(); - window.render(scene); + view.render(scene); scene.dispose(); } } @@ -389,13 +371,11 @@ class PlatformViewMaxOverlaysScenario extends Scenario class MultiPlatformViewScenario extends Scenario with _BasePlatformViewScenarioMixin { /// Creates the PlatformView scenario. - /// - /// The [dispatcher] parameter must not be null. MultiPlatformViewScenario( - PlatformDispatcher dispatcher, { + super.view, { required this.firstId, required this.secondId, - }) : super(dispatcher); + }); /// The platform view identifier to use for the first platform view. final int firstId; @@ -411,7 +391,7 @@ class MultiPlatformViewScenario extends Scenario addPlatformView( firstId, - dispatcher: dispatcher, + dispatcher: view.platformDispatcher, sceneBuilder: builder, text: 'platform view 1', ); @@ -420,7 +400,7 @@ class MultiPlatformViewScenario extends Scenario addPlatformView( secondId, - dispatcher: dispatcher, + dispatcher: view.platformDispatcher, sceneBuilder: builder, text: 'platform view 2', ); @@ -437,13 +417,11 @@ class MultiPlatformViewScenario extends Scenario class MultiPlatformViewBackgroundForegroundScenario extends Scenario with _BasePlatformViewScenarioMixin { /// Creates the PlatformView scenario. - /// - /// The [dispatcher] parameter must not be null. MultiPlatformViewBackgroundForegroundScenario( - PlatformDispatcher dispatcher, { + super.view, { required this.firstId, required this.secondId, - }) : super(dispatcher) { + }) { _nextFrame = _firstFrame; } @@ -467,7 +445,7 @@ class MultiPlatformViewBackgroundForegroundScenario extends Scenario addPlatformView( firstId, - dispatcher: dispatcher, + dispatcher: view.platformDispatcher, sceneBuilder: builder, text: 'platform view 1', ); @@ -478,7 +456,7 @@ class MultiPlatformViewBackgroundForegroundScenario extends Scenario addPlatformView( secondId, - dispatcher: dispatcher, + dispatcher: view.platformDispatcher, sceneBuilder: builder, text: 'platform view 2', ); @@ -495,7 +473,7 @@ class MultiPlatformViewBackgroundForegroundScenario extends Scenario builder.addPicture(Offset.zero, picture); final Scene scene = builder.build(); - window.render(scene); + view.render(scene); scene.dispose(); } @@ -506,7 +484,7 @@ class MultiPlatformViewBackgroundForegroundScenario extends Scenario addPlatformView( firstId, - dispatcher: dispatcher, + dispatcher: view.platformDispatcher, sceneBuilder: builder, text: 'platform view 1', ); @@ -515,13 +493,13 @@ class MultiPlatformViewBackgroundForegroundScenario extends Scenario addPlatformView( secondId, - dispatcher: dispatcher, + dispatcher: view.platformDispatcher, sceneBuilder: builder, text: 'platform view 2', ); final Scene scene = builder.build(); - window.render(scene); + view.render(scene); scene.dispose(); } @@ -540,7 +518,7 @@ class MultiPlatformViewBackgroundForegroundScenario extends Scenario if (_lastLifecycleState == 'AppLifecycleState.inactive' && message == 'AppLifecycleState.resumed') { _nextFrame = _secondFrame; - window.scheduleFrame(); + view.platformDispatcher.scheduleFrame(); } _lastLifecycleState = message; @@ -551,9 +529,9 @@ class MultiPlatformViewBackgroundForegroundScenario extends Scenario class PlatformViewClipRectScenario extends Scenario with _BasePlatformViewScenarioMixin { /// Constructs a platform view with clip rect scenario. PlatformViewClipRectScenario( - PlatformDispatcher dispatcher, { + super.view, { required this.id, - }) : super(dispatcher); + }); /// The platform view identifier. final int id; @@ -565,7 +543,7 @@ class PlatformViewClipRectScenario extends Scenario with _BasePlatformViewScenar addPlatformView( id, - dispatcher: dispatcher, + dispatcher: view.platformDispatcher, sceneBuilder: builder, ); @@ -579,9 +557,9 @@ class PlatformViewClipRectScenario extends Scenario with _BasePlatformViewScenar class PlatformViewClipRectAfterMovedScenario extends Scenario with _BasePlatformViewScenarioMixin { /// Constructs a platform view with clip rect scenario. PlatformViewClipRectAfterMovedScenario( - PlatformDispatcher dispatcher, { + super.view, { required this.id, - }) : super(dispatcher); + }); /// The platform view identifier. final int id; @@ -599,7 +577,7 @@ class PlatformViewClipRectAfterMovedScenario extends Scenario with _BasePlatform addPlatformView( _numberOfFrames == 10? 10000:id, - dispatcher: dispatcher, + dispatcher: view.platformDispatcher, sceneBuilder: builder, ); @@ -622,7 +600,7 @@ class PlatformViewClipRectAfterMovedScenario extends Scenario with _BasePlatform if (_numberOfFrames < 10) { _numberOfFrames ++; _y -= 10; - window.scheduleFrame(); + view.platformDispatcher.scheduleFrame(); } super.onDrawFrame(); } @@ -632,9 +610,9 @@ class PlatformViewClipRectAfterMovedScenario extends Scenario with _BasePlatform class PlatformViewClipRRectScenario extends PlatformViewScenario { /// Constructs a platform view with clip rrect scenario. PlatformViewClipRRectScenario( - PlatformDispatcher dispatcher, { - int id = 0, - }) : super(dispatcher, id: id); + super.view, { + super.id = 0, + }); @override void onBeginFrame(Duration duration) { @@ -653,7 +631,7 @@ class PlatformViewClipRRectScenario extends PlatformViewScenario { addPlatformView( id, - dispatcher: dispatcher, + dispatcher: view.platformDispatcher, sceneBuilder: builder, ); @@ -667,9 +645,9 @@ class PlatformViewClipRRectScenario extends PlatformViewScenario { class PlatformViewLargeClipRRectScenario extends PlatformViewScenario { /// Constructs a platform view with large clip rrect scenario. PlatformViewLargeClipRRectScenario( - PlatformDispatcher dispatcher, { - int id = 0, - }) : super(dispatcher, id: id); + super.view, { + super.id = 0, + }); @override void onBeginFrame(Duration duration) { @@ -688,7 +666,7 @@ class PlatformViewLargeClipRRectScenario extends PlatformViewScenario { addPlatformView( id, - dispatcher: dispatcher, + dispatcher: view.platformDispatcher, sceneBuilder: builder, ); @@ -700,9 +678,9 @@ class PlatformViewLargeClipRRectScenario extends PlatformViewScenario { class PlatformViewClipPathScenario extends PlatformViewScenario { /// Constructs a platform view with clip path scenario. PlatformViewClipPathScenario( - PlatformDispatcher dispatcher, { - int id = 0, - }) : super(dispatcher, id: id); + super.view, { + super.id = 0, + }); @override void onBeginFrame(Duration duration) { @@ -716,7 +694,7 @@ class PlatformViewClipPathScenario extends PlatformViewScenario { final SceneBuilder builder = SceneBuilder()..pushClipPath(path); addPlatformView( id, - dispatcher: dispatcher, + dispatcher: view.platformDispatcher, sceneBuilder: builder, ); finishBuilder(builder); @@ -727,9 +705,9 @@ class PlatformViewClipPathScenario extends PlatformViewScenario { class PlatformViewClipRectWithTransformScenario extends PlatformViewScenario { /// Constructs a platform view with clip rect with transform scenario. PlatformViewClipRectWithTransformScenario( - PlatformDispatcher dispatcher, { - int id = 0, - }) : super(dispatcher, id: id); + super.view, { + super.id = 0, + }); @override void onBeginFrame(Duration duration) { @@ -743,7 +721,7 @@ class PlatformViewClipRectWithTransformScenario extends PlatformViewScenario { addPlatformView( id, - dispatcher: dispatcher, + dispatcher: view.platformDispatcher, sceneBuilder: builder, ); @@ -765,9 +743,9 @@ class PlatformViewClipRectWithTransformScenario extends PlatformViewScenario { class PlatformViewClipRRectWithTransformScenario extends PlatformViewScenario { /// Constructs a platform view with clip rrect with transform scenario. PlatformViewClipRRectWithTransformScenario( - PlatformDispatcher dispatcher, { - int id = 0, - }) : super(dispatcher, id: id); + super.view, { + super.id = 0, + }); @override void onBeginFrame(Duration duration) { @@ -790,7 +768,7 @@ class PlatformViewClipRRectWithTransformScenario extends PlatformViewScenario { ); addPlatformView( id, - dispatcher: dispatcher, + dispatcher: view.platformDispatcher, sceneBuilder: builder, ); @@ -813,9 +791,9 @@ class PlatformViewClipRRectWithTransformScenario extends PlatformViewScenario { class PlatformViewLargeClipRRectWithTransformScenario extends PlatformViewScenario { /// Constructs a platform view with large clip rrect with transform scenario. PlatformViewLargeClipRRectWithTransformScenario( - PlatformDispatcher dispatcher, { - int id = 0, - }) : super(dispatcher, id: id); + super.view, { + super.id = 0, + }); @override void onBeginFrame(Duration duration) { @@ -838,7 +816,7 @@ class PlatformViewLargeClipRRectWithTransformScenario extends PlatformViewScenar ); addPlatformView( id, - dispatcher: dispatcher, + dispatcher: view.platformDispatcher, sceneBuilder: builder, ); @@ -860,9 +838,9 @@ class PlatformViewLargeClipRRectWithTransformScenario extends PlatformViewScenar class PlatformViewClipPathWithTransformScenario extends PlatformViewScenario { /// Constructs a platform view with clip path with transform scenario. PlatformViewClipPathWithTransformScenario( - PlatformDispatcher dispatcher, { - int id = 0, - }) : super(dispatcher, id: id); + super.view, { + super.id = 0, + }); @override void onBeginFrame(Duration duration) { @@ -882,7 +860,7 @@ class PlatformViewClipPathWithTransformScenario extends PlatformViewScenario { builder.pushClipPath(path); addPlatformView( id, - dispatcher: dispatcher, + dispatcher: view.platformDispatcher, sceneBuilder: builder, ); @@ -904,9 +882,9 @@ class PlatformViewClipPathWithTransformScenario extends PlatformViewScenario { class PlatformViewTransformScenario extends PlatformViewScenario { /// Constructs a platform view with transform scenario. PlatformViewTransformScenario( - PlatformDispatcher dispatcher, { - int id = 0, - }) : super(dispatcher, id: id); + super.view, { + super.id = 0, + }); @override void onBeginFrame(Duration duration) { @@ -918,7 +896,7 @@ class PlatformViewTransformScenario extends PlatformViewScenario { final SceneBuilder builder = SceneBuilder()..pushTransform(matrix4.storage); addPlatformView( id, - dispatcher: dispatcher, + dispatcher: view.platformDispatcher, sceneBuilder: builder, ); finishBuilder(builder); @@ -929,16 +907,16 @@ class PlatformViewTransformScenario extends PlatformViewScenario { class PlatformViewOpacityScenario extends PlatformViewScenario { /// Constructs a platform view with transform scenario. PlatformViewOpacityScenario( - PlatformDispatcher dispatcher, { - int id = 0, - }) : super(dispatcher, id: id); + super.view, { + super.id = 0, + }); @override void onBeginFrame(Duration duration) { final SceneBuilder builder = SceneBuilder()..pushOpacity(150); addPlatformView( id, - dispatcher: dispatcher, + dispatcher: view.platformDispatcher, sceneBuilder: builder, ); finishBuilder(builder); @@ -949,14 +927,12 @@ class PlatformViewOpacityScenario extends PlatformViewScenario { class PlatformViewForTouchIOSScenario extends Scenario with _BasePlatformViewScenarioMixin { /// Creates the PlatformView scenario. - /// - /// The [dispatcher] parameter must not be null. PlatformViewForTouchIOSScenario( - PlatformDispatcher dispatcher, { + super.view, { this.id = 0, this.rejectUntilTouchesEnded = false, required this.accept, - }) : super(dispatcher) { + }) { _nextFrame = _firstFrame; } @@ -983,7 +959,7 @@ class PlatformViewForTouchIOSScenario extends Scenario // See https://github.com/flutter/flutter/issues/66044 if (_nextFrame == _firstFrame) { _nextFrame = _secondFrame; - window.scheduleFrame(); + view.platformDispatcher.scheduleFrame(); } super.onDrawFrame(); } @@ -1008,7 +984,7 @@ class PlatformViewForTouchIOSScenario extends Scenario valueInt32, ..._to32(id), ]); - window.sendPlatformMessage( + view.platformDispatcher.sendPlatformMessage( 'flutter/platform_views', message.buffer.asByteData(), (ByteData? response) {}, @@ -1022,14 +998,14 @@ class PlatformViewForTouchIOSScenario extends Scenario if (rejectUntilTouchesEnded) { addPlatformView( id, - dispatcher: dispatcher, + dispatcher: view.platformDispatcher, sceneBuilder: builder, viewType: 'scenarios/textPlatformView_blockPolicyUntilTouchesEnded', ); } else { addPlatformView( id, - dispatcher: dispatcher, + dispatcher: view.platformDispatcher, sceneBuilder: builder, ); } @@ -1041,14 +1017,14 @@ class PlatformViewForTouchIOSScenario extends Scenario if (rejectUntilTouchesEnded) { addPlatformView( id, - dispatcher: dispatcher, + dispatcher: view.platformDispatcher, sceneBuilder: builder, viewType: 'scenarios/textPlatformView_blockPolicyUntilTouchesEnded', ); } else { addPlatformView( id, - dispatcher: dispatcher, + dispatcher: view.platformDispatcher, sceneBuilder: builder, ); } @@ -1067,13 +1043,11 @@ class PlatformViewForOverlappingPlatformViewsScenario extends Scenario with _BasePlatformViewScenarioMixin { /// Creates the PlatformViewForOverlappingPlatformViewsScenario. - /// - /// The [dispatcher] parameter must not be null. PlatformViewForOverlappingPlatformViewsScenario( - PlatformDispatcher dispatcher, { + super.view, { required this.foregroundId, required this.backgroundId, - }) : super(dispatcher) { + }) { _nextFrame = _firstFrame; } @@ -1099,14 +1073,14 @@ class PlatformViewForOverlappingPlatformViewsScenario extends Scenario foregroundId, width: 100, height: 100, - dispatcher: dispatcher, + dispatcher: view.platformDispatcher, sceneBuilder: builder, text: 'Foreground', ); builder.pop(); final Scene scene = builder.build(); - window.render(scene); + view.render(scene); scene.dispose(); } @@ -1118,7 +1092,7 @@ class PlatformViewForOverlappingPlatformViewsScenario extends Scenario backgroundId, width: 300, height: 300, - dispatcher: dispatcher, + dispatcher: view.platformDispatcher, sceneBuilder: builder, text: 'Background', ); @@ -1129,14 +1103,14 @@ class PlatformViewForOverlappingPlatformViewsScenario extends Scenario foregroundId, width: 100, height: 100, - dispatcher: dispatcher, + dispatcher: view.platformDispatcher, sceneBuilder: builder, text: 'Foreground', ); builder.pop(); final Scene scene = builder.build(); - window.render(scene); + view.render(scene); scene.dispose(); } @@ -1151,7 +1125,7 @@ class PlatformViewForOverlappingPlatformViewsScenario extends Scenario if (_nextFrame == _firstFrame && _frameCount == 60) { _nextFrame = _secondFrame; } - window.scheduleFrame(); + view.platformDispatcher.scheduleFrame(); super.onDrawFrame(); } @@ -1174,7 +1148,7 @@ class PlatformViewForOverlappingPlatformViewsScenario extends Scenario valueInt32, ..._to32(foregroundId), ]); - window.sendPlatformMessage( + view.platformDispatcher.sendPlatformMessage( 'flutter/platform_views', message.buffer.asByteData(), (ByteData? response) {}, @@ -1188,9 +1162,9 @@ class PlatformViewForOverlappingPlatformViewsScenario extends Scenario class PlatformViewWithContinuousTexture extends PlatformViewScenario { /// Constructs a platform view with continuous texture layer. PlatformViewWithContinuousTexture( - PlatformDispatcher dispatcher, { - int id = 0, - }) : super(dispatcher, id: id); + super.view, { + super.id = 0, + }); @override void onBeginFrame(Duration duration) { @@ -1201,7 +1175,7 @@ class PlatformViewWithContinuousTexture extends PlatformViewScenario { addPlatformView( id, - dispatcher: dispatcher, + dispatcher: view.platformDispatcher, sceneBuilder: builder, ); @@ -1218,9 +1192,9 @@ class PlatformViewWithContinuousTexture extends PlatformViewScenario { class PlatformViewWithOtherBackDropFilter extends PlatformViewScenario { /// Constructs the scenario. PlatformViewWithOtherBackDropFilter( - PlatformDispatcher dispatcher, { - int id = 0, - }) : super(dispatcher, id: id); + super.view, { + super.id = 0, + }); @override void onBeginFrame(Duration duration) { @@ -1261,7 +1235,7 @@ class PlatformViewWithOtherBackDropFilter extends PlatformViewScenario { addPlatformView( id, - dispatcher: dispatcher, + dispatcher: view.platformDispatcher, sceneBuilder: builder, ); @@ -1280,7 +1254,7 @@ class PlatformViewWithOtherBackDropFilter extends PlatformViewScenario { builder.addPicture(const Offset(100, 100), picture3); final Scene scene = builder.build(); - window.render(scene); + view.render(scene); scene.dispose(); } } @@ -1294,12 +1268,11 @@ class TwoPlatformViewsWithOtherBackDropFilter extends Scenario with _BasePlatformViewScenarioMixin { /// Constructs the scenario. TwoPlatformViewsWithOtherBackDropFilter( - PlatformDispatcher dispatcher, { + super.view, { required int firstId, required int secondId, }) : _firstId = firstId, - _secondId = secondId, - super(dispatcher); + _secondId = secondId; final int _firstId; final int _secondId; @@ -1327,7 +1300,7 @@ class TwoPlatformViewsWithOtherBackDropFilter extends Scenario addPlatformView( _firstId, - dispatcher: dispatcher, + dispatcher: view.platformDispatcher, sceneBuilder: builder, width: 100, height: 100, @@ -1352,7 +1325,7 @@ class TwoPlatformViewsWithOtherBackDropFilter extends Scenario addPlatformView( _secondId, - dispatcher: dispatcher, + dispatcher: view.platformDispatcher, sceneBuilder: builder, text: 'platform view 2', ); @@ -1374,7 +1347,7 @@ class TwoPlatformViewsWithOtherBackDropFilter extends Scenario builder.addPicture(const Offset(100, 100), picture3); final Scene scene = builder.build(); - window.render(scene); + view.render(scene); scene.dispose(); } } @@ -1383,15 +1356,12 @@ class TwoPlatformViewsWithOtherBackDropFilter extends Scenario class PlatformViewScrollingUnderWidget extends Scenario with _BasePlatformViewScenarioMixin { /// Creates the PlatformView scenario. - /// - /// The [dispatcher] parameter must not be null. PlatformViewScrollingUnderWidget( - PlatformDispatcher dispatcher, { + super.view, { required int firstPlatformViewId, required int lastPlatformViewId, }) : _firstPlatformViewId = firstPlatformViewId, - _lastPlatformViewId = lastPlatformViewId, - super(dispatcher); + _lastPlatformViewId = lastPlatformViewId; final int _firstPlatformViewId; @@ -1420,7 +1390,7 @@ class PlatformViewScrollingUnderWidget extends Scenario } else { _offset += 100; } - window.scheduleFrame(); + view.platformDispatcher.scheduleFrame(); super.onDrawFrame(); } @@ -1434,7 +1404,7 @@ class PlatformViewScrollingUnderWidget extends Scenario builder.pushOffset(0, localOffset); addPlatformView( i, - dispatcher: dispatcher, + dispatcher: view.platformDispatcher, sceneBuilder: builder, text: 'platform view $i', width: cellWidth, @@ -1455,7 +1425,7 @@ class PlatformViewScrollingUnderWidget extends Scenario builder.addPicture(const Offset(0, 20), picture); final Scene scene = builder.build(); - window.render(scene); + view.render(scene); scene.dispose(); } } @@ -1634,7 +1604,7 @@ mixin _BasePlatformViewScenarioMixin on Scenario { final Picture picture = recorder.endRecording(); sceneBuilder.addPicture(const Offset(300, 300), picture); final Scene scene = sceneBuilder.build(); - window.render(scene); + view.render(scene); scene.dispose(); } } diff --git a/engine/src/flutter/testing/scenario_app/lib/src/poppable_screen.dart b/engine/src/flutter/testing/scenario_app/lib/src/poppable_screen.dart index 6e6b7f7f79..394aaaa247 100644 --- a/engine/src/flutter/testing/scenario_app/lib/src/poppable_screen.dart +++ b/engine/src/flutter/testing/scenario_app/lib/src/poppable_screen.dart @@ -12,10 +12,7 @@ import 'scenario.dart'; /// A blank page with a button that pops the page when tapped. class PoppableScreenScenario extends Scenario with PlatformEchoMixin { /// Creates the PoppableScreenScenario. - /// - /// The [dispatcher] parameter must not be null. - PoppableScreenScenario(PlatformDispatcher dispatcher) - : super(dispatcher); + PoppableScreenScenario(super.view); // Rect for the pop button. Only defined once onMetricsChanged is called. Rect? _buttonRect; @@ -39,7 +36,7 @@ class PoppableScreenScenario extends Scenario with PlatformEchoMixin { builder.pushOffset(0, 0); builder.addPicture(Offset.zero, picture); final Scene scene = builder.build(); - window.render(scene); + view.render(scene); scene.dispose(); } @@ -51,12 +48,12 @@ class PoppableScreenScenario extends Scenario with PlatformEchoMixin { @override void onMetricsChanged() { _buttonRect = Rect.fromLTRB( - window.physicalSize.width / 4, - window.physicalSize.height * 2 / 5, - window.physicalSize.width * 3 / 4, - window.physicalSize.height * 3 / 5, + view.physicalSize.width / 4, + view.physicalSize.height * 2 / 5, + view.physicalSize.width * 3 / 4, + view.physicalSize.height * 3 / 5, ); - window.scheduleFrame(); + view.platformDispatcher.scheduleFrame(); } @override @@ -72,7 +69,7 @@ class PoppableScreenScenario extends Scenario with PlatformEchoMixin { void _pop() { sendJsonMethodCall( - dispatcher: dispatcher, + dispatcher: view.platformDispatcher, // 'flutter/platform' is the hardcoded name of the 'platform' // `SystemChannel` from the `SystemNavigator` API. // https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/services/system_navigator.dart. diff --git a/engine/src/flutter/testing/scenario_app/lib/src/scenario.dart b/engine/src/flutter/testing/scenario_app/lib/src/scenario.dart index 68c5d6506f..6c3611b6f4 100644 --- a/engine/src/flutter/testing/scenario_app/lib/src/scenario.dart +++ b/engine/src/flutter/testing/scenario_app/lib/src/scenario.dart @@ -8,10 +8,10 @@ import 'dart:ui'; /// A scenario to run for testing. abstract class Scenario { /// Creates a new scenario using a specific FlutterView instance. - Scenario(this.dispatcher); + Scenario(this.view); - /// The window used by this scenario. May be mocked. - final PlatformDispatcher dispatcher; + /// The FlutterView used by this scenario. May be mocked. + final FlutterView view; /// [true] if a screenshot is taken in the next frame. bool _didScheduleScreenshot = false; @@ -27,12 +27,12 @@ abstract class Scenario { /// See [PlatformDispatcher.onDrawFrame] for more details. void onDrawFrame() { if (_didScheduleScreenshot) { - dispatcher.sendPlatformMessage('take_screenshot', null, null); + view.platformDispatcher.sendPlatformMessage('take_screenshot', null, null); return; } Future.delayed(const Duration(seconds: 2), () { _didScheduleScreenshot = true; - dispatcher.scheduleFrame(); + view.platformDispatcher.scheduleFrame(); }); } diff --git a/engine/src/flutter/testing/scenario_app/lib/src/scenarios.dart b/engine/src/flutter/testing/scenario_app/lib/src/scenarios.dart index d07f933eee..ff71e609e0 100644 --- a/engine/src/flutter/testing/scenario_app/lib/src/scenarios.dart +++ b/engine/src/flutter/testing/scenario_app/lib/src/scenarios.dart @@ -15,52 +15,52 @@ import 'scenario.dart'; import 'texture.dart'; import 'touches_scenario.dart'; -typedef ScenarioFactory = Scenario Function(); // ignore: public_member_api_docs +typedef _ScenarioFactory = Scenario Function(FlutterView view); int _viewId = 0; -Map _scenarios = { - 'animated_color_square': () => AnimatedColorSquareScenario(PlatformDispatcher.instance), - 'locale_initialization': () => LocaleInitialization(PlatformDispatcher.instance), - 'platform_view': () => PlatformViewScenario(PlatformDispatcher.instance, id: _viewId++), - 'platform_view_no_overlay_intersection': () => PlatformViewNoOverlayIntersectionScenario(PlatformDispatcher.instance, id: _viewId++), - 'platform_view_larger_than_display_size': () => PlatformViewLargerThanDisplaySize(PlatformDispatcher.instance, id: _viewId++), - 'platform_view_partial_intersection': () => PlatformViewPartialIntersectionScenario(PlatformDispatcher.instance, id: _viewId++), - 'platform_view_two_intersecting_overlays': () => PlatformViewTwoIntersectingOverlaysScenario(PlatformDispatcher.instance, id: _viewId++), - 'platform_view_one_overlay_two_intersecting_overlays': () => PlatformViewOneOverlayTwoIntersectingOverlaysScenario(PlatformDispatcher.instance, id: _viewId++), - 'platform_view_multiple_without_overlays': () => MultiPlatformViewWithoutOverlaysScenario(PlatformDispatcher.instance, firstId: _viewId++, secondId: _viewId++), - 'platform_view_max_overlays': () => PlatformViewMaxOverlaysScenario(PlatformDispatcher.instance, id: _viewId++), - 'platform_view_cliprect': () => PlatformViewClipRectScenario(PlatformDispatcher.instance, id: _viewId++), - 'platform_view_cliprect_with_transform': () => PlatformViewClipRectWithTransformScenario(PlatformDispatcher.instance, id: _viewId++), - 'platform_view_cliprect_after_moved': () => PlatformViewClipRectAfterMovedScenario(PlatformDispatcher.instance, id: _viewId++), - 'platform_view_cliprrect': () => PlatformViewClipRRectScenario(PlatformDispatcher.instance, id: _viewId++), - 'platform_view_large_cliprrect': () => PlatformViewLargeClipRRectScenario(PlatformDispatcher.instance, id: _viewId++), - 'platform_view_cliprrect_with_transform': () => PlatformViewClipRRectWithTransformScenario(PlatformDispatcher.instance, id: _viewId++), - 'platform_view_large_cliprrect_with_transform': () => PlatformViewLargeClipRRectWithTransformScenario(PlatformDispatcher.instance, id: _viewId++), - 'platform_view_clippath': () => PlatformViewClipPathScenario(PlatformDispatcher.instance, id: _viewId++), - 'platform_view_clippath_with_transform': () => PlatformViewClipPathWithTransformScenario(PlatformDispatcher.instance, id: _viewId++), - 'platform_view_transform': () => PlatformViewTransformScenario(PlatformDispatcher.instance, id: _viewId++), - 'platform_view_opacity': () => PlatformViewOpacityScenario(PlatformDispatcher.instance, id: _viewId++), - 'platform_view_with_other_backdrop_filter': () => PlatformViewWithOtherBackDropFilter(PlatformDispatcher.instance, id: _viewId++), - 'two_platform_views_with_other_backdrop_filter': () => TwoPlatformViewsWithOtherBackDropFilter(PlatformDispatcher.instance, firstId: _viewId++, secondId: _viewId++), - 'platform_view_multiple': () => MultiPlatformViewScenario(PlatformDispatcher.instance, firstId: _viewId++, secondId: _viewId++), - 'platform_view_multiple_background_foreground': () => MultiPlatformViewBackgroundForegroundScenario(PlatformDispatcher.instance, firstId: _viewId++, secondId: _viewId++), - 'non_full_screen_flutter_view_platform_view': () => NonFullScreenFlutterViewPlatformViewScenario(PlatformDispatcher.instance, id: _viewId++), - 'poppable_screen': () => PoppableScreenScenario(PlatformDispatcher.instance), - 'platform_view_rotate': () => PlatformViewScenario(PlatformDispatcher.instance, id: _viewId++), - 'platform_view_gesture_reject_eager': () => PlatformViewForTouchIOSScenario(PlatformDispatcher.instance, id: _viewId++, accept: false), - 'platform_view_gesture_accept': () => PlatformViewForTouchIOSScenario(PlatformDispatcher.instance, id: _viewId++, accept: true), - 'platform_view_gesture_reject_after_touches_ended': () => PlatformViewForTouchIOSScenario(PlatformDispatcher.instance, id: _viewId++, accept: false, rejectUntilTouchesEnded: true), - 'platform_view_gesture_accept_with_overlapping_platform_views': () => PlatformViewForOverlappingPlatformViewsScenario(PlatformDispatcher.instance, foregroundId: _viewId++, backgroundId: _viewId++), - 'platform_view_scrolling_under_widget':()=>PlatformViewScrollingUnderWidget(PlatformDispatcher.instance, firstPlatformViewId: _viewId++, lastPlatformViewId: _viewId+=16), - 'tap_status_bar': () => TouchesScenario(PlatformDispatcher.instance), - 'initial_route_reply': () => InitialRouteReply(PlatformDispatcher.instance), - 'platform_view_with_continuous_texture': () => PlatformViewWithContinuousTexture(PlatformDispatcher.instance, id: _viewId++), - 'bogus_font_text': () => BogusFontText(PlatformDispatcher.instance), - 'spawn_engine_works' : () => BogusFontText(PlatformDispatcher.instance), - 'pointer_events': () => TouchesScenario(PlatformDispatcher.instance), - 'display_texture': () => DisplayTexture(PlatformDispatcher.instance), - 'get_bitmap': () => GetBitmapScenario(PlatformDispatcher.instance), +Map _scenarios = { + 'animated_color_square': (FlutterView view) => AnimatedColorSquareScenario(view), + 'locale_initialization': (FlutterView view) => LocaleInitialization(view), + 'platform_view': (FlutterView view) => PlatformViewScenario(view, id: _viewId++), + 'platform_view_no_overlay_intersection': (FlutterView view) => PlatformViewNoOverlayIntersectionScenario(view, id: _viewId++), + 'platform_view_larger_than_display_size': (FlutterView view) => PlatformViewLargerThanDisplaySize(view, id: _viewId++), + 'platform_view_partial_intersection': (FlutterView view) => PlatformViewPartialIntersectionScenario(view, id: _viewId++), + 'platform_view_two_intersecting_overlays': (FlutterView view) => PlatformViewTwoIntersectingOverlaysScenario(view, id: _viewId++), + 'platform_view_one_overlay_two_intersecting_overlays': (FlutterView view) => PlatformViewOneOverlayTwoIntersectingOverlaysScenario(view, id: _viewId++), + 'platform_view_multiple_without_overlays': (FlutterView view) => MultiPlatformViewWithoutOverlaysScenario(view, firstId: _viewId++, secondId: _viewId++), + 'platform_view_max_overlays': (FlutterView view) => PlatformViewMaxOverlaysScenario(view, id: _viewId++), + 'platform_view_cliprect': (FlutterView view) => PlatformViewClipRectScenario(view, id: _viewId++), + 'platform_view_cliprect_with_transform': (FlutterView view) => PlatformViewClipRectWithTransformScenario(view, id: _viewId++), + 'platform_view_cliprect_after_moved': (FlutterView view) => PlatformViewClipRectAfterMovedScenario(view, id: _viewId++), + 'platform_view_cliprrect': (FlutterView view) => PlatformViewClipRRectScenario(view, id: _viewId++), + 'platform_view_large_cliprrect': (FlutterView view) => PlatformViewLargeClipRRectScenario(view, id: _viewId++), + 'platform_view_cliprrect_with_transform': (FlutterView view) => PlatformViewClipRRectWithTransformScenario(view, id: _viewId++), + 'platform_view_large_cliprrect_with_transform': (FlutterView view) => PlatformViewLargeClipRRectWithTransformScenario(view, id: _viewId++), + 'platform_view_clippath': (FlutterView view) => PlatformViewClipPathScenario(view, id: _viewId++), + 'platform_view_clippath_with_transform': (FlutterView view) => PlatformViewClipPathWithTransformScenario(view, id: _viewId++), + 'platform_view_transform': (FlutterView view) => PlatformViewTransformScenario(view, id: _viewId++), + 'platform_view_opacity': (FlutterView view) => PlatformViewOpacityScenario(view, id: _viewId++), + 'platform_view_with_other_backdrop_filter': (FlutterView view) => PlatformViewWithOtherBackDropFilter(view, id: _viewId++), + 'two_platform_views_with_other_backdrop_filter': (FlutterView view) => TwoPlatformViewsWithOtherBackDropFilter(view, firstId: _viewId++, secondId: _viewId++), + 'platform_view_multiple': (FlutterView view) => MultiPlatformViewScenario(view, firstId: _viewId++, secondId: _viewId++), + 'platform_view_multiple_background_foreground': (FlutterView view) => MultiPlatformViewBackgroundForegroundScenario(view, firstId: _viewId++, secondId: _viewId++), + 'non_full_screen_flutter_view_platform_view': (FlutterView view) => NonFullScreenFlutterViewPlatformViewScenario(view, id: _viewId++), + 'poppable_screen': (FlutterView view) => PoppableScreenScenario(view), + 'platform_view_rotate': (FlutterView view) => PlatformViewScenario(view, id: _viewId++), + 'platform_view_gesture_reject_eager': (FlutterView view) => PlatformViewForTouchIOSScenario(view, id: _viewId++, accept: false), + 'platform_view_gesture_accept': (FlutterView view) => PlatformViewForTouchIOSScenario(view, id: _viewId++, accept: true), + 'platform_view_gesture_reject_after_touches_ended': (FlutterView view) => PlatformViewForTouchIOSScenario(view, id: _viewId++, accept: false, rejectUntilTouchesEnded: true), + 'platform_view_gesture_accept_with_overlapping_platform_views': (FlutterView view) => PlatformViewForOverlappingPlatformViewsScenario(view, foregroundId: _viewId++, backgroundId: _viewId++), + 'platform_view_scrolling_under_widget':(FlutterView view) => PlatformViewScrollingUnderWidget(view, firstPlatformViewId: _viewId++, lastPlatformViewId: _viewId+=16), + 'tap_status_bar': (FlutterView view) => TouchesScenario(view), + 'initial_route_reply': (FlutterView view) => InitialRouteReply(view), + 'platform_view_with_continuous_texture': (FlutterView view) => PlatformViewWithContinuousTexture(view, id: _viewId++), + 'bogus_font_text': (FlutterView view) => BogusFontText(view), + 'spawn_engine_works' : (FlutterView view) => BogusFontText(view), + 'pointer_events': (FlutterView view) => TouchesScenario(view), + 'display_texture': (FlutterView view) => DisplayTexture(view), + 'get_bitmap': (FlutterView view) => GetBitmapScenario(view), }; Map _currentScenarioParams = {}; @@ -69,7 +69,7 @@ Scenario? _currentScenarioInstance; /// Loads an scenario. /// The map must contain a `name` entry, which equals to the name of the scenario. -void loadScenario(Map scenario) { +void loadScenario(Map scenario, FlutterView view) { final String scenarioName = scenario['name'] as String; assert(_scenarios[scenarioName] != null); _currentScenarioParams = scenario; @@ -78,8 +78,8 @@ void loadScenario(Map scenario) { _currentScenarioInstance!.unmount(); } - _currentScenarioInstance = _scenarios[scenario['name']]!(); - window.scheduleFrame(); + _currentScenarioInstance = _scenarios[scenario['name']]!(view); + view.platformDispatcher.scheduleFrame(); print('Loading scenario $scenarioName'); } diff --git a/engine/src/flutter/testing/scenario_app/lib/src/texture.dart b/engine/src/flutter/testing/scenario_app/lib/src/texture.dart index 162fb968d9..c03628cb7d 100644 --- a/engine/src/flutter/testing/scenario_app/lib/src/texture.dart +++ b/engine/src/flutter/testing/scenario_app/lib/src/texture.dart @@ -11,10 +11,7 @@ import 'scenarios.dart'; /// Displays a platform texture with the given width and height. class DisplayTexture extends Scenario { /// Creates the DisplayTexture scenario. - /// - /// The [dispatcher] parameter must not be null. - DisplayTexture(PlatformDispatcher dispatcher) - : super(dispatcher); + DisplayTexture(super.view); int get _textureId => scenarioParams['texture_id'] as int; double get _textureWidth => @@ -28,18 +25,18 @@ class DisplayTexture extends Scenario { builder.addTexture( _textureId, offset: Offset( - (window.physicalSize.width / 2.0) - (_textureWidth / 2.0), + (view.physicalSize.width / 2.0) - (_textureWidth / 2.0), 0.0, ), width: _textureWidth, height: _textureHeight, ); final Scene scene = builder.build(); - window.render(scene); + view.render(scene); scene.dispose(); sendJsonMessage( - dispatcher: dispatcher, + dispatcher: view.platformDispatcher, channel: 'display_data', json: { 'data': 'ready', diff --git a/engine/src/flutter/testing/scenario_app/lib/src/touches_scenario.dart b/engine/src/flutter/testing/scenario_app/lib/src/touches_scenario.dart index 00d11da79f..139f2cf6df 100644 --- a/engine/src/flutter/testing/scenario_app/lib/src/touches_scenario.dart +++ b/engine/src/flutter/testing/scenario_app/lib/src/touches_scenario.dart @@ -10,7 +10,7 @@ import 'scenario.dart'; /// A scenario that sends back messages when touches are received. class TouchesScenario extends Scenario { /// Constructor for `TouchesScenario`. - TouchesScenario(PlatformDispatcher dispatcher) : super(dispatcher); + TouchesScenario(super.view); final Map _knownDevices = {}; int _sequenceNo = 0; @@ -19,7 +19,7 @@ class TouchesScenario extends Scenario { void onBeginFrame(Duration duration) { // It is necessary to render frames for touch events to work properly on iOS final Scene scene = SceneBuilder().build(); - window.render(scene); + view.render(scene); scene.dispose(); } @@ -29,7 +29,7 @@ class TouchesScenario extends Scenario { final int deviceId = _knownDevices.putIfAbsent(datum.device, () => _knownDevices.length); sendJsonMessage( - dispatcher: dispatcher, + dispatcher: view.platformDispatcher, channel: 'display_data', json: { 'data': '$_sequenceNo,${datum.change},device=$deviceId,buttons=${datum.buttons},signalKind=${datum.signalKind}', diff --git a/engine/src/flutter/testing/scenario_app/pubspec.yaml b/engine/src/flutter/testing/scenario_app/pubspec.yaml index 00b4a2b1cb..696d387158 100644 --- a/engine/src/flutter/testing/scenario_app/pubspec.yaml +++ b/engine/src/flutter/testing/scenario_app/pubspec.yaml @@ -5,7 +5,7 @@ name: scenario_app publish_to: none environment: - sdk: '>=2.12.0 <3.0.0' + sdk: '>=2.17.0 <3.0.0' # Do not add any dependencies that require more than what is provided in # //third_party/dart/pkg, //third_party/dart/third_party/pkg, or