[go: nahoru, domu]

Skip to content

Commit

Permalink
Remove single-window assumption from scenario_app (flutter#40156)
Browse files Browse the repository at this point in the history
Remove single-window assumption from scenario_app
  • Loading branch information
goderbauer committed Mar 9, 2023
1 parent 347a4f3 commit 7e0e65a
Show file tree
Hide file tree
Showing 16 changed files with 236 additions and 276 deletions.
2 changes: 2 additions & 0 deletions testing/scenario_app/ios/Runner/GeneratedPluginRegistrant.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Generated file. Do not edit.
//

// clang-format off

#ifndef GeneratedPluginRegistrant_h
#define GeneratedPluginRegistrant_h

Expand Down
2 changes: 2 additions & 0 deletions testing/scenario_app/ios/Runner/GeneratedPluginRegistrant.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Generated file. Do not edit.
//

// clang-format off

#import "GeneratedPluginRegistrant.h"

@implementation GeneratedPluginRegistrant
Expand Down
15 changes: 11 additions & 4 deletions testing/scenario_app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<String, dynamic> call) {
final String? methodName = call['method'] as String?;
switch (methodName) {
case 'set_scenario':
assert(call['args'] != null);
loadScenario(call['args'] as Map<String, dynamic>);
loadScenario(call['args'] as Map<String, dynamic>, _view);
break;
default:
throw 'Unimplemented method: $methodName.';
Expand Down Expand Up @@ -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;
}
Expand Down
25 changes: 11 additions & 14 deletions testing/scenario_app/lib/src/animated_color_square.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> _r = _NumberSwinger<int>(0, 255);
_NumberSwinger<double> _top = _NumberSwinger<double>(
late _NumberSwinger<double> _top = _NumberSwinger<double>(
0,
window.physicalSize.height - _squareSize,
view.physicalSize.height - _squareSize,
);
_NumberSwinger<double> _left = _NumberSwinger<double>(
late _NumberSwinger<double> _left = _NumberSwinger<double>(
0,
window.physicalSize.width - _squareSize,
view.physicalSize.width - _squareSize,
);

@override
Expand All @@ -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<double>(
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<double>(
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),
);
}
}
Expand Down
9 changes: 3 additions & 6 deletions testing/scenario_app/lib/src/bogus_font_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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: <String, dynamic>{
'data': 'ready',
Expand Down
13 changes: 5 additions & 8 deletions testing/scenario_app/lib/src/get_bitmap_scenario.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
11 changes: 3 additions & 8 deletions testing/scenario_app/lib/src/initial_route_reply.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,21 @@
// 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';

/// A blank page that just sends back to the platform what the set initial
/// 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,
);
}
}
13 changes: 6 additions & 7 deletions testing/scenario_app/lib/src/locale_initialization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
Expand All @@ -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
Expand All @@ -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: <StringAttribute>[],
textDirection: TextDirection.ltr,
textSelectionBase: -1,
Expand Down Expand Up @@ -82,7 +81,7 @@ class LocaleInitialization extends Scenario {

final SemanticsUpdate semanticsUpdate = semanticsUpdateBuilder.build();

dispatcher.views.first.updateSemantics(semanticsUpdate);
view.updateSemantics(semanticsUpdate);
}

/// Handle taps.
Expand Down Expand Up @@ -140,7 +139,7 @@ class LocaleInitialization extends Scenario {

final SemanticsUpdate semanticsUpdate = semanticsUpdateBuilder.build();

dispatcher.views.first.updateSemantics(semanticsUpdate);
view.updateSemantics(semanticsUpdate);

_tapCount++;
}
Expand Down
2 changes: 1 addition & 1 deletion testing/scenario_app/lib/src/platform_echo_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ mixin PlatformEchoMixin on Scenario {
ByteData? data,
PlatformMessageResponseCallback? callback,
) {
window.sendPlatformMessage(name, data, null);
view.platformDispatcher.sendPlatformMessage(name, data, null);
}
}
Loading

0 comments on commit 7e0e65a

Please sign in to comment.