-
Notifications
You must be signed in to change notification settings - Fork 6k
Switch ui.window.devicePixelRatio from browser logical to physical. #17209
Conversation
| /// This is useful in tests to emulate screens of different dimensions | ||
| /// including integration tests. | ||
| void overrideDevicePixelRatio(double value) { | ||
| _debugDevicePixelRatio = value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change? It's still used only in tests, so the "debug" prefix and assert seem appropriate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is now also used in integration test (the one that loads an image at framework level).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but that's still a test :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do integration tests strip out asserts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If they don't, we should add the option to enable them. dart2js supports asserts (we use dart2js for engine unit-test with assertions enabled).
/cc @nturgut
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My comment is non-blocking though. I don't think there's major risk. It just doesn't feel right for a method that's not annotated as "debug" to manipulate a "debug" field without an assertion.
e2etests/web/regular_integration_tests/test_driver/image_loading_e2e_test.dart
Outdated
Show resolved
Hide resolved
e2etests/web/regular_integration_tests/lib/image_loading_main.dart
Outdated
Show resolved
Hide resolved
| /// This is useful in tests to emulate screens of different dimensions | ||
| /// including integration tests. | ||
| void overrideDevicePixelRatio(double value) { | ||
| _debugDevicePixelRatio = value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do integration tests strip out asserts?
|
LGTM if LGT @mdebbar |
| // scene to devicepixelratio. Use identity instead since CSS uses | ||
| // logical device pixels. | ||
| assert(matrix4[0] == EngineWindow.browserDevicePixelRatio && | ||
| matrix4[5] == EngineWindow.browserDevicePixelRatio); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assertion error would be visible to developers and Flutter contributors writing tests. It would be very confusing without a good error message. Consider moving the comment into the assertion error message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the check for test environment since there are many SceneBuilder raw tests outside the context of an app that pushes root transform for now (we really need a ui.Window level debugDevicePixelRatio, i noticed some hacked in TestWindow.devicePixelRatioTestValue etc in the code base used for viewport_test).
|
|
||
| /// Decodes the message coming from the 'flutter/accessibility' channel. | ||
| void handleMessage(ByteData data) { | ||
| void handleMessage(StandardMessageCodec codec, ByteData data) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary extra leading space
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
| assert(matrix4[0] == window.devicePixelRatio && | ||
| matrix4[5] == window.devicePixelRatio); | ||
| } | ||
| matrix4 = Matrix4.identity().storage; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, now that I think about it, the correct fix would be to inject a transform that scales by 1/DPR. This way we don't have to rely on a particular framework behavior. To avoid extra div nodes we can do something like:
if (the scene contains a root transform) {
reuse the root transform by scale it by 1/DPR.
} else {
apply 1/DPR to the `<flt-scene>` element.
}
In most cases we'll hit the if branch, not the else branch. Also in most cases the root transform will be scale by DPR. So the resulting root transform will automatically become identity and we won't apply any transform at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The framework itself injects pushTransform using ViewConfiguration. Ideally this code would not live in framework but in engine. See view.dart:39. Or instead of calling pushTransform , framework would call SceneBuilder.setViewConfiguration in engine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but you can use dart:ui without the Flutter framework where you can paint a scene without a root transform. This typically happens in tests and benchmarks. I don't expect there to be many apps that don't use the framework.
| return (ratio == null || ratio == 0.0) ? 1.0 : ratio; | ||
| } | ||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
| engine.window.debugOverrideDevicePixelRatio(devicePixelRatio); | ||
| engine.window.webOnlyDebugPhysicalSizeOverride = | ||
| Size(800 * devicePixelRatio, 600 * devicePixelRatio); | ||
| assert(() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this assert necessary? This code emulates the flutter test environment (it sets debugEmulateFlutterTesterEnvironment to true below). So it shouldn't affect e2e tests. Those should not hit this code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reverted
|
|
||
| builder.pushTransform(Matrix4.diagonal3Values( | ||
| EngineWindow.browserDevicePixelRatio, | ||
| EngineWindow.browserDevicePixelRatio, 1.0).storage); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change wouldn't be necessary if we applied 1/DPR to <flt-scene> when the root transform is missing.
I think some of our benchmarks will fail for the same reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Would like to change ViewConfiguration so we don't have to do this in the first place on the framework side.
|
merging on luci-engine infra fail. |
Related issues:
flutter/flutter#46186
flutter/flutter#41328
material-components/material-components-flutter-gallery#310
Fixes: flutter/flutter#52929