-
Notifications
You must be signed in to change notification settings - Fork 6k
Add GetBoundingRectAfterMutations to EmbeddedViewParams to calculate the final bounding rect for platform view
#19170
Changes from 6 commits
86ba0b1
2752b19
617ead7
60d9b7b
9eb1d3a
822d11c
ff81b85
15056ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| #include "flutter/flow/embedded_views.h" | ||
| #include "flutter/fml/logging.h" | ||
| #include "gtest/gtest.h" | ||
|
|
||
| namespace flutter { | ||
| namespace testing { | ||
|
|
||
| TEST(EmbeddedViewParams, GetBoundingRectAfterMutationsWithNoMutations) { | ||
| MutatorsStack stack; | ||
| SkMatrix matrix; | ||
|
|
||
| EmbeddedViewParams params(matrix, SkSize::Make(1, 1), stack); | ||
| const SkRect& rect = params.finalBoundingRect(); | ||
| ASSERT_TRUE(SkScalarNearlyEqual(rect.x(), 0)); | ||
| ASSERT_TRUE(SkScalarNearlyEqual(rect.y(), 0)); | ||
| ASSERT_TRUE(SkScalarNearlyEqual(rect.width(), 1)); | ||
| ASSERT_TRUE(SkScalarNearlyEqual(rect.height(), 1)); | ||
| } | ||
|
|
||
| TEST(EmbeddedViewParams, GetBoundingRectAfterMutationsWithScale) { | ||
| MutatorsStack stack; | ||
| SkMatrix matrix = SkMatrix::Scale(2, 2); | ||
| stack.PushTransform(matrix); | ||
|
|
||
| EmbeddedViewParams params(matrix, SkSize::Make(1, 1), stack); | ||
| const SkRect& rect = params.finalBoundingRect(); | ||
| ASSERT_TRUE(SkScalarNearlyEqual(rect.x(), 0)); | ||
| ASSERT_TRUE(SkScalarNearlyEqual(rect.y(), 0)); | ||
| ASSERT_TRUE(SkScalarNearlyEqual(rect.width(), 2)); | ||
| ASSERT_TRUE(SkScalarNearlyEqual(rect.height(), 2)); | ||
| } | ||
|
|
||
| TEST(EmbeddedViewParams, GetBoundingRectAfterMutationsWithTranslate) { | ||
| MutatorsStack stack; | ||
| SkMatrix matrix = SkMatrix::MakeTrans(1, 1); | ||
| stack.PushTransform(matrix); | ||
|
|
||
| EmbeddedViewParams params(matrix, SkSize::Make(1, 1), stack); | ||
| const SkRect& rect = params.finalBoundingRect(); | ||
| ASSERT_TRUE(SkScalarNearlyEqual(rect.x(), 1)); | ||
| ASSERT_TRUE(SkScalarNearlyEqual(rect.y(), 1)); | ||
| ASSERT_TRUE(SkScalarNearlyEqual(rect.width(), 1)); | ||
| ASSERT_TRUE(SkScalarNearlyEqual(rect.height(), 1)); | ||
| } | ||
|
|
||
| TEST(EmbeddedViewParams, GetBoundingRectAfterMutationsWithRotation90) { | ||
| MutatorsStack stack; | ||
| SkMatrix matrix; | ||
| matrix.setRotate(90); | ||
| stack.PushTransform(matrix); | ||
|
|
||
| EmbeddedViewParams params(matrix, SkSize::Make(1, 1), stack); | ||
| const SkRect& rect = params.finalBoundingRect(); | ||
|
|
||
| FML_DLOG(ERROR) << rect.x(); | ||
| ASSERT_TRUE(SkScalarNearlyEqual(rect.x(), -1)); | ||
| ASSERT_TRUE(SkScalarNearlyEqual(rect.y(), 0)); | ||
| ASSERT_TRUE(SkScalarNearlyEqual(rect.width(), 1)); | ||
| ASSERT_TRUE(SkScalarNearlyEqual(rect.height(), 1)); | ||
| } | ||
|
|
||
| TEST(EmbeddedViewParams, GetBoundingRectAfterMutationsWithRotation45) { | ||
| MutatorsStack stack; | ||
| SkMatrix matrix; | ||
| matrix.setRotate(45); | ||
| stack.PushTransform(matrix); | ||
|
|
||
| EmbeddedViewParams params(matrix, SkSize::Make(1, 1), stack); | ||
| const SkRect& rect = params.finalBoundingRect(); | ||
| ASSERT_TRUE(SkScalarNearlyEqual(rect.x(), -sqrt(2) / 2)); | ||
| ASSERT_TRUE(SkScalarNearlyEqual(rect.y(), 0)); | ||
| ASSERT_TRUE(SkScalarNearlyEqual(rect.width(), sqrt(2))); | ||
| ASSERT_TRUE(SkScalarNearlyEqual(rect.height(), sqrt(2))); | ||
| } | ||
|
|
||
| TEST(EmbeddedViewParams, | ||
| GetBoundingRectAfterMutationsWithTranslateScaleAndRotation) { | ||
| SkMatrix matrix = SkMatrix::MakeTrans(2, 2); | ||
| matrix.preScale(3, 3); | ||
| matrix.preRotate(90); | ||
|
|
||
| MutatorsStack stack; | ||
| stack.PushTransform(matrix); | ||
|
|
||
| EmbeddedViewParams params(matrix, SkSize::Make(1, 1), stack); | ||
| const SkRect& rect = params.finalBoundingRect(); | ||
| ASSERT_TRUE(SkScalarNearlyEqual(rect.x(), -1)); | ||
| ASSERT_TRUE(SkScalarNearlyEqual(rect.y(), 2)); | ||
| ASSERT_TRUE(SkScalarNearlyEqual(rect.width(), 3)); | ||
| ASSERT_TRUE(SkScalarNearlyEqual(rect.height(), 3)); | ||
| } | ||
|
|
||
| } // namespace testing | ||
| } // namespace flutter |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -108,7 +108,7 @@ void EmbedderLayers::PushPlatformViewLayer( | |
| view.struct_size = sizeof(FlutterPlatformView); | ||
| view.identifier = identifier; | ||
|
|
||
| const auto& mutators = params.mutatorsStack; | ||
| const auto& mutators = params.mutatorsStack(); | ||
|
|
||
| std::vector<const FlutterPlatformViewMutation*> mutations_array; | ||
|
|
||
|
|
@@ -180,10 +180,10 @@ void EmbedderLayers::PushPlatformViewLayer( | |
| layer.platform_view = platform_views_referenced_.back().get(); | ||
|
|
||
| const auto layer_bounds = | ||
| SkRect::MakeXYWH(params.offsetPixels.x(), // | ||
| params.offsetPixels.y(), // | ||
| params.sizePoints.width() * device_pixel_ratio_, // | ||
| params.sizePoints.height() * device_pixel_ratio_ // | ||
| SkRect::MakeXYWH(params.offsetPixels().x(), // | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this just
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the size is not the same as the bounding rect. The size points are the original size before applying mutation.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @chinmaygarde I thought params.sizePoints did not consider scaling and rotation at all? Does embedder free from scaling and rotation layers?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe the embedder is supposed to apply the scaling and rotation themselves from the data present in the mutator stack to get the final width and height. I believe there is a test for this in the embedder unit-tests harness and this should be documented in the header.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I meant this rect returned from this method does not include rotation and scaling. Want to make sure if the original size used here is intended.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. It is. |
||
| params.offsetPixels().y(), // | ||
| params.sizePoints().width() * device_pixel_ratio_, // | ||
| params.sizePoints().height() * device_pixel_ratio_ // | ||
| ); | ||
|
|
||
| const auto transformed_layer_bounds = | ||
|
|
||
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.
nit: could we document these methods?
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