Skip to content

Commit

Permalink
Remove single view assumption from TestViewConfiguration (flutter#122352
Browse files Browse the repository at this point in the history
)

Remove single view assumption from TestViewConfiguration
  • Loading branch information
goderbauer committed Mar 10, 2023
1 parent 4792297 commit 927289f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
8 changes: 4 additions & 4 deletions dev/benchmarks/microbenchmarks/lib/stocks/layout_bench.dart
Expand Up @@ -31,13 +31,13 @@ Future<void> main() async {
await tester.pump(); // Start drawer animation
await tester.pump(const Duration(seconds: 1)); // Complete drawer animation

final TestViewConfiguration big = TestViewConfiguration(
final TestViewConfiguration big = TestViewConfiguration.fromView(
size: const Size(360.0, 640.0),
window: tester.view,
view: tester.view,
);
final TestViewConfiguration small = TestViewConfiguration(
final TestViewConfiguration small = TestViewConfiguration.fromView(
size: const Size(355.0, 635.0),
window: tester.view,
view: tester.view,
);
final RenderView renderView = WidgetsBinding.instance.renderView;
binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.benchmark;
Expand Down
29 changes: 20 additions & 9 deletions packages/flutter_test/lib/src/binding.dart
Expand Up @@ -1919,9 +1919,9 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {

@override
ViewConfiguration createViewConfiguration() {
return TestViewConfiguration(
return TestViewConfiguration.fromView(
size: _surfaceSize ?? _kDefaultTestViewportSize,
window: window,
view: window,
);
}

Expand All @@ -1945,20 +1945,31 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
/// size is in logical pixels. The resulting ViewConfiguration maps the given
/// size onto the actual display using the [BoxFit.contain] algorithm.
class TestViewConfiguration extends ViewConfiguration {
/// Creates a [TestViewConfiguration] with the given size. Defaults to 800x600.
/// Deprecated. Will be removed in a future version of Flutter.
///
/// This property has been deprecated to prepare for Flutter's upcoming
/// support for multiple views and multiple windows.
///
/// If a [window] instance is not provided it defaults to [ui.window].
/// Use [TestViewConfiguration.fromView] instead.
@Deprecated(
'Use TestViewConfiguration.fromView instead. '
'Deprecated to prepare for the upcoming multi-window support. '
'This feature was deprecated after v3.7.0-32.0.pre.'
)
factory TestViewConfiguration({
Size size = _kDefaultTestViewportSize,
ui.FlutterView? window,
}) {
return TestViewConfiguration._(size, window ?? ui.window);
return TestViewConfiguration.fromView(size: size, view: window ?? ui.window);
}

TestViewConfiguration._(Size size, ui.FlutterView window)
: _paintMatrix = _getMatrix(size, window.devicePixelRatio, window),
_hitTestMatrix = _getMatrix(size, 1.0, window),
super(size: size, devicePixelRatio: window.devicePixelRatio);
/// Creates a [TestViewConfiguration] with the given size and view.
///
/// The [size] defaults to 800x600.
TestViewConfiguration.fromView({required ui.FlutterView view, super.size = _kDefaultTestViewportSize})
: _paintMatrix = _getMatrix(size, view.devicePixelRatio, view),
_hitTestMatrix = _getMatrix(size, 1.0, view),
super(devicePixelRatio: view.devicePixelRatio);

static Matrix4 _getMatrix(Size size, double devicePixelRatio, ui.FlutterView window) {
final double inverseRatio = devicePixelRatio / window.devicePixelRatio;
Expand Down
4 changes: 2 additions & 2 deletions packages/integration_test/lib/integration_test.dart
Expand Up @@ -120,9 +120,9 @@ https://flutter.dev/docs/testing/integration-tests#testing-on-firebase-test-lab
ViewConfiguration createViewConfiguration() {
final double devicePixelRatio = window.devicePixelRatio;
final Size size = _surfaceSize ?? window.physicalSize / devicePixelRatio;
return TestViewConfiguration(
return TestViewConfiguration.fromView(
size: size,
window: window,
view: window,
);
}

Expand Down

0 comments on commit 927289f

Please sign in to comment.