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

Conversation

@ferhatb
Copy link
Contributor

@ferhatb ferhatb commented Mar 19, 2020

  • This enabled image loading for multi dpi assets and fixes correctness issues in framework due to incorrectly using logical browser pixels at 1.0 dpr.
  • Adds integration test for image loading of higher resolution.
  • Adds missing platform replymessage calls.

Related issues:
flutter/flutter#46186
flutter/flutter#41328
material-components/material-components-flutter-gallery#310

Fixes: flutter/flutter#52929

/// This is useful in tests to emulate screens of different dimensions
/// including integration tests.
void overrideDevicePixelRatio(double value) {
_debugDevicePixelRatio = value;
Copy link
Contributor

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.

Copy link
Contributor Author

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).

Copy link
Contributor

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 :)

Copy link
Contributor

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?

Copy link
Contributor

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

Copy link
Contributor

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.

/// This is useful in tests to emulate screens of different dimensions
/// including integration tests.
void overrideDevicePixelRatio(double value) {
_debugDevicePixelRatio = value;
Copy link
Contributor

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?

@yjbanov
Copy link
Contributor

yjbanov commented Mar 20, 2020

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);
Copy link
Contributor

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.

Copy link
Contributor Author

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).

@ferhatb ferhatb requested a review from yjbanov March 25, 2020 17:48

/// Decodes the message coming from the 'flutter/accessibility' channel.
void handleMessage(ByteData data) {
void handleMessage(StandardMessageCodec codec, ByteData data) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary extra leading space

Copy link
Contributor Author

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;
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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;
}


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert?

Copy link
Contributor Author

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(() {
Copy link
Contributor

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.

Copy link
Contributor Author

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);
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@ferhatb
Copy link
Contributor Author

ferhatb commented Mar 25, 2020

merging on luci-engine infra fail.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Web engine does not respond to all platform messages

6 participants