Ensure that the device pixel ratio is taken into account with window metrics in physical pixels. (flutter/engine#13708)
This was originally patched in https://github.com/flutter/engine/pull/13193 but the unit-tests were written under the mistaken assumption (that has been documented already) that the Flutter window metrics used logical pixel coordinates. That mistake has been corrected and additional tests to verify rendering intent has been added. Fixes https://github.com/flutter/flutter/issues/43906 Fixes https://b.corp.google.com/issues/143529469
This commit is contained in:
@@ -869,6 +869,8 @@ FILE: ../../../flutter/shell/platform/embedder/fixtures/compositor_root_surface_
|
||||
FILE: ../../../flutter/shell/platform/embedder/fixtures/compositor_software.png
|
||||
FILE: ../../../flutter/shell/platform/embedder/fixtures/compositor_with_platform_layer_on_bottom.png
|
||||
FILE: ../../../flutter/shell/platform/embedder/fixtures/compositor_with_root_layer_only.png
|
||||
FILE: ../../../flutter/shell/platform/embedder/fixtures/dpr_noxform.png
|
||||
FILE: ../../../flutter/shell/platform/embedder/fixtures/dpr_xform.png
|
||||
FILE: ../../../flutter/shell/platform/embedder/fixtures/gradient.png
|
||||
FILE: ../../../flutter/shell/platform/embedder/fixtures/gradient_xform.png
|
||||
FILE: ../../../flutter/shell/platform/embedder/fixtures/main.dart
|
||||
|
||||
@@ -87,15 +87,17 @@ test_fixtures("fixtures") {
|
||||
dart_main = "fixtures/main.dart"
|
||||
fixtures = [
|
||||
"fixtures/compositor.png",
|
||||
"fixtures/gradient.png",
|
||||
"fixtures/verifyb143464703.png",
|
||||
"fixtures/gradient_xform.png",
|
||||
"fixtures/compositor_root_surface_xformation.png",
|
||||
"fixtures/compositor_software.png",
|
||||
"fixtures/compositor_with_platform_layer_on_bottom.png",
|
||||
"fixtures/compositor_with_root_layer_only.png",
|
||||
"fixtures/compositor_root_surface_xformation.png",
|
||||
"fixtures/dpr_noxform.png",
|
||||
"fixtures/dpr_xform.png",
|
||||
"fixtures/gradient.png",
|
||||
"fixtures/gradient_xform.png",
|
||||
"fixtures/scene_without_custom_compositor.png",
|
||||
"fixtures/scene_without_custom_compositor_with_xform.png",
|
||||
"fixtures/verifyb143464703.png",
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@@ -148,8 +148,7 @@ SkCanvas* EmbedderExternalViewEmbedder::CompositeEmbeddedView(int view_id) {
|
||||
static FlutterLayer MakeBackingStoreLayer(
|
||||
const SkISize& frame_size,
|
||||
const FlutterBackingStore* store,
|
||||
const SkMatrix& surface_transformation,
|
||||
double device_pixel_ratio) {
|
||||
const SkMatrix& surface_transformation) {
|
||||
FlutterLayer layer = {};
|
||||
|
||||
layer.struct_size = sizeof(layer);
|
||||
@@ -160,9 +159,7 @@ static FlutterLayer MakeBackingStoreLayer(
|
||||
SkRect::MakeWH(frame_size.width(), frame_size.height());
|
||||
|
||||
const auto transformed_layer_bounds =
|
||||
SkMatrix::Concat(surface_transformation,
|
||||
SkMatrix::MakeScale(device_pixel_ratio))
|
||||
.mapRect(layer_bounds);
|
||||
surface_transformation.mapRect(layer_bounds);
|
||||
|
||||
layer.offset.x = transformed_layer_bounds.x();
|
||||
layer.offset.y = transformed_layer_bounds.y();
|
||||
@@ -231,6 +228,8 @@ bool EmbedderExternalViewEmbedder::SubmitFrame(GrContext* context) {
|
||||
// while making sure to take into account any surface transformations.
|
||||
if (auto root_canvas = root_render_target_->GetRenderSurface()->getCanvas()) {
|
||||
root_canvas->setMatrix(pending_surface_transformation_);
|
||||
root_canvas->scale(pending_device_pixel_ratio_,
|
||||
pending_device_pixel_ratio_);
|
||||
root_canvas->clear(SK_ColorTRANSPARENT);
|
||||
root_canvas->drawPicture(
|
||||
root_picture_recorder_->finishRecordingAsPicture());
|
||||
@@ -243,8 +242,7 @@ bool EmbedderExternalViewEmbedder::SubmitFrame(GrContext* context) {
|
||||
presented_layers.push_back(MakeBackingStoreLayer(
|
||||
pending_frame_size_, // frame size
|
||||
root_render_target_->GetBackingStore(), // backing store
|
||||
pending_surface_transformation_, // surface transformation
|
||||
pending_device_pixel_ratio_ // device pixel ratio
|
||||
pending_surface_transformation_ // surface transformation
|
||||
));
|
||||
}
|
||||
|
||||
@@ -318,6 +316,8 @@ bool EmbedderExternalViewEmbedder::SubmitFrame(GrContext* context) {
|
||||
}
|
||||
|
||||
render_canvas->setMatrix(pending_surface_transformation_);
|
||||
render_canvas->scale(pending_device_pixel_ratio_,
|
||||
pending_device_pixel_ratio_);
|
||||
render_canvas->clear(SK_ColorTRANSPARENT);
|
||||
render_canvas->drawPicture(picture);
|
||||
render_canvas->flush();
|
||||
@@ -326,8 +326,7 @@ bool EmbedderExternalViewEmbedder::SubmitFrame(GrContext* context) {
|
||||
presented_layers.push_back(MakeBackingStoreLayer(
|
||||
pending_frame_size_, // frame size
|
||||
render_target->GetBackingStore(), // backing store
|
||||
pending_surface_transformation_, // surface transformation
|
||||
pending_device_pixel_ratio_ // device pixel ratio
|
||||
pending_surface_transformation_ // surface transformation
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 36 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 125 KiB |
@@ -437,10 +437,13 @@ void verify_b141980393() {
|
||||
void can_display_platform_view_with_pixel_ratio() {
|
||||
window.onBeginFrame = (Duration duration) {
|
||||
SceneBuilder builder = SceneBuilder();
|
||||
builder.pushOffset(0.0, 20.0);
|
||||
builder.pushOffset(0.0, 0.0); // base
|
||||
builder.addPicture(Offset(0.0, 0.0), CreateGradientBox(Size(400.0, 300.0)));
|
||||
builder.pushOffset(0.0, 20.0); // offset
|
||||
builder.addPlatformView(42, width: 400.0, height: 280.0);
|
||||
builder.addPicture(Offset(0.0, 0.0), CreateSimplePicture());
|
||||
builder.pop();
|
||||
builder.pop(); // offset
|
||||
builder.addPicture(Offset(0.0, 0.0), CreateColoredBox(Color.fromARGB(128, 255, 0, 0), Size(400.0, 300.0)));
|
||||
builder.pop(); // base
|
||||
window.render(builder.build());
|
||||
};
|
||||
window.scheduleFrame();
|
||||
|
||||
@@ -2587,7 +2587,14 @@ TEST_F(EmbedderTest,
|
||||
context.GetCompositor().SetRenderTargetType(
|
||||
EmbedderTestCompositor::RenderTargetType::kOpenGLTexture);
|
||||
|
||||
fml::AutoResetWaitableEvent latch;
|
||||
sk_sp<SkImage> renderered_scene;
|
||||
fml::CountDownLatch latch(2);
|
||||
|
||||
context.SetNextSceneCallback([&](auto image) {
|
||||
renderered_scene = std::move(image);
|
||||
latch.CountDown();
|
||||
});
|
||||
|
||||
context.GetCompositor().SetNextPresentCallback(
|
||||
[&](const FlutterLayer** layers, size_t layers_count) {
|
||||
ASSERT_EQ(layers_count, 3u);
|
||||
@@ -2642,7 +2649,7 @@ TEST_F(EmbedderTest,
|
||||
ASSERT_EQ(*layers[2], layer);
|
||||
}
|
||||
|
||||
latch.Signal();
|
||||
latch.CountDown();
|
||||
});
|
||||
|
||||
auto engine = builder.LaunchEngine();
|
||||
@@ -2650,14 +2657,16 @@ TEST_F(EmbedderTest,
|
||||
// Send a window metrics events so frames may be scheduled.
|
||||
FlutterWindowMetricsEvent event = {};
|
||||
event.struct_size = sizeof(event);
|
||||
event.width = 400;
|
||||
event.height = 300;
|
||||
event.width = 400 * 2.0;
|
||||
event.height = 300 * 2.0;
|
||||
event.pixel_ratio = 2.0;
|
||||
ASSERT_EQ(FlutterEngineSendWindowMetricsEvent(engine.get(), &event),
|
||||
kSuccess);
|
||||
ASSERT_TRUE(engine.is_valid());
|
||||
|
||||
latch.Wait();
|
||||
|
||||
ASSERT_TRUE(ImageMatchesFixture("dpr_noxform.png", renderered_scene));
|
||||
}
|
||||
|
||||
TEST_F(
|
||||
@@ -2677,8 +2686,14 @@ TEST_F(
|
||||
SkMatrix().preTranslate(0, 800).preRotate(-90, 0, 0);
|
||||
|
||||
context.SetRootSurfaceTransformation(root_surface_transformation);
|
||||
sk_sp<SkImage> renderered_scene;
|
||||
fml::CountDownLatch latch(2);
|
||||
|
||||
context.SetNextSceneCallback([&](auto image) {
|
||||
renderered_scene = std::move(image);
|
||||
latch.CountDown();
|
||||
});
|
||||
|
||||
fml::AutoResetWaitableEvent latch;
|
||||
context.GetCompositor().SetNextPresentCallback(
|
||||
[&](const FlutterLayer** layers, size_t layers_count) {
|
||||
ASSERT_EQ(layers_count, 3u);
|
||||
@@ -2733,7 +2748,7 @@ TEST_F(
|
||||
ASSERT_EQ(*layers[2], layer);
|
||||
}
|
||||
|
||||
latch.Signal();
|
||||
latch.CountDown();
|
||||
});
|
||||
|
||||
auto engine = builder.LaunchEngine();
|
||||
@@ -2741,14 +2756,16 @@ TEST_F(
|
||||
// Send a window metrics events so frames may be scheduled.
|
||||
FlutterWindowMetricsEvent event = {};
|
||||
event.struct_size = sizeof(event);
|
||||
event.width = 400;
|
||||
event.height = 300;
|
||||
event.width = 400 * 2.0;
|
||||
event.height = 300 * 2.0;
|
||||
event.pixel_ratio = 2.0;
|
||||
ASSERT_EQ(FlutterEngineSendWindowMetricsEvent(engine.get(), &event),
|
||||
kSuccess);
|
||||
ASSERT_TRUE(engine.is_valid());
|
||||
|
||||
latch.Wait();
|
||||
|
||||
ASSERT_TRUE(ImageMatchesFixture("dpr_xform.png", renderered_scene));
|
||||
}
|
||||
|
||||
TEST_F(EmbedderTest, CanUpdateLocales) {
|
||||
|
||||
Reference in New Issue
Block a user