This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
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
Merged
cyanglaz
merged 8 commits into
flutter-team-archive:master
from
cyanglaz:mutator_stack_get_rect
Jun 22, 2020
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
86ba0b1
GetBoundingRectAfterMutations
2752b19
link todo to issue
617ead7
fix typo
60d9b7b
fix unittest typo
9eb1d3a
cache make bounding rect
822d11c
fix license golden
ff81b85
add docs
15056ff
formatting
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| // 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 "gtest/gtest.h" | ||
| #include "flutter/fml/logging.h" | ||
|
|
||
|
|
||
| namespace flutter { | ||
| namespace testing { | ||
|
|
||
| TEST(EmbeddedViewParams, GetBoundingRectWithNoMutations) { | ||
| MutatorsStack stack; | ||
| EmbeddedViewParams params; | ||
| params.sizePoints = SkSize::Make(1, 1);; | ||
| params.offsetPixels = SkPoint::Make(0, 0); | ||
| params.mutatorsStack = stack; | ||
|
|
||
| SkRect rect = params.GetBoundingRect(); | ||
| 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, GetBoundingRectWithScale) { | ||
| MutatorsStack stack; | ||
| SkMatrix scale = SkMatrix::Scale(2, 2); | ||
| stack.PushTransform(scale); | ||
|
|
||
| EmbeddedViewParams params; | ||
| params.sizePoints = SkSize::Make(1, 1);; | ||
| params.offsetPixels = SkPoint::Make(0, 0); | ||
| params.mutatorsStack = stack; | ||
|
|
||
| SkRect rect = params.GetBoundingRect(); | ||
| 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, GetBoundingRectWithTranslate) { | ||
| MutatorsStack stack; | ||
| SkMatrix trans = SkMatrix::MakeTrans(1, 1); | ||
| stack.PushTransform(trans); | ||
|
|
||
| EmbeddedViewParams params; | ||
| params.sizePoints = SkSize::Make(1, 1);; | ||
| params.offsetPixels = SkPoint::Make(0, 0); | ||
| params.mutatorsStack = stack; | ||
|
|
||
| SkRect rect = params.GetBoundingRect(); | ||
| 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, GetBoundingRectWithRotation90) { | ||
| MutatorsStack stack; | ||
| SkMatrix rotate; | ||
| rotate.setRotate(90); | ||
| stack.PushTransform(rotate); | ||
|
|
||
| EmbeddedViewParams params; | ||
| params.sizePoints = SkSize::Make(1, 1);; | ||
| params.offsetPixels = SkPoint::Make(0, 0); | ||
| params.mutatorsStack = stack; | ||
|
|
||
| SkRect rect = params.GetBoundingRect(); | ||
| 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, GetBoundingRectWithRotation45) { | ||
| MutatorsStack stack; | ||
| SkMatrix rotate; | ||
| rotate.setRotate(45); | ||
| stack.PushTransform(rotate); | ||
|
|
||
| EmbeddedViewParams params; | ||
| params.sizePoints = SkSize::Make(1, 1);; | ||
| params.offsetPixels = SkPoint::Make(0, 0); | ||
| params.mutatorsStack = stack; | ||
|
|
||
| SkRect rect = params.GetBoundingRect(); | ||
| 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, GetBoundingRectWithTranslateScalingAndRotation) { | ||
| MutatorsStack stack; | ||
| SkMatrix translate = SkMatrix::MakeTrans(2, 2); | ||
| SkMatrix scale = SkMatrix::MakeScale(3, 3); | ||
| SkMatrix rotate; | ||
| rotate.setRotate(90); | ||
| stack.PushTransform(translate); | ||
| stack.PushTransform(scale); | ||
| stack.PushTransform(rotate); | ||
|
|
||
| EmbeddedViewParams params; | ||
| params.sizePoints = SkSize::Make(1, 1);; | ||
| params.offsetPixels = SkPoint::Make(0, 0); | ||
| params.mutatorsStack = stack; | ||
|
|
||
| SkRect rect = params.GetBoundingRect(); | ||
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
does it still need the
offsetPixels?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.
I think mutator stack should contain all the offset informations already, By querying through the stack, we have the final offset