Flutter Engine
embedded_view_params_unittests.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "flutter/flow/embedded_views.h"
6 #include "flutter/fml/logging.h"
7 #include "gtest/gtest.h"
8 
9 namespace flutter {
10 namespace testing {
11 
12 TEST(EmbeddedViewParams, GetBoundingRectAfterMutationsWithNoMutations) {
13  MutatorsStack stack;
14  SkMatrix matrix;
15 
16  EmbeddedViewParams params(matrix, SkSize::Make(1, 1), stack);
17  const SkRect& rect = params.finalBoundingRect();
18  ASSERT_TRUE(SkScalarNearlyEqual(rect.x(), 0));
19  ASSERT_TRUE(SkScalarNearlyEqual(rect.y(), 0));
20  ASSERT_TRUE(SkScalarNearlyEqual(rect.width(), 1));
21  ASSERT_TRUE(SkScalarNearlyEqual(rect.height(), 1));
22 }
23 
24 TEST(EmbeddedViewParams, GetBoundingRectAfterMutationsWithScale) {
25  MutatorsStack stack;
26  SkMatrix matrix = SkMatrix::Scale(2, 2);
27  stack.PushTransform(matrix);
28 
29  EmbeddedViewParams params(matrix, SkSize::Make(1, 1), stack);
30  const SkRect& rect = params.finalBoundingRect();
31  ASSERT_TRUE(SkScalarNearlyEqual(rect.x(), 0));
32  ASSERT_TRUE(SkScalarNearlyEqual(rect.y(), 0));
33  ASSERT_TRUE(SkScalarNearlyEqual(rect.width(), 2));
34  ASSERT_TRUE(SkScalarNearlyEqual(rect.height(), 2));
35 }
36 
37 TEST(EmbeddedViewParams, GetBoundingRectAfterMutationsWithTranslate) {
38  MutatorsStack stack;
39  SkMatrix matrix = SkMatrix::MakeTrans(1, 1);
40  stack.PushTransform(matrix);
41 
42  EmbeddedViewParams params(matrix, SkSize::Make(1, 1), stack);
43  const SkRect& rect = params.finalBoundingRect();
44  ASSERT_TRUE(SkScalarNearlyEqual(rect.x(), 1));
45  ASSERT_TRUE(SkScalarNearlyEqual(rect.y(), 1));
46  ASSERT_TRUE(SkScalarNearlyEqual(rect.width(), 1));
47  ASSERT_TRUE(SkScalarNearlyEqual(rect.height(), 1));
48 }
49 
50 TEST(EmbeddedViewParams, GetBoundingRectAfterMutationsWithRotation90) {
51  MutatorsStack stack;
52  SkMatrix matrix;
53  matrix.setRotate(90);
54  stack.PushTransform(matrix);
55 
56  EmbeddedViewParams params(matrix, SkSize::Make(1, 1), stack);
57  const SkRect& rect = params.finalBoundingRect();
58 
59  FML_DLOG(ERROR) << rect.x();
60  ASSERT_TRUE(SkScalarNearlyEqual(rect.x(), -1));
61  ASSERT_TRUE(SkScalarNearlyEqual(rect.y(), 0));
62  ASSERT_TRUE(SkScalarNearlyEqual(rect.width(), 1));
63  ASSERT_TRUE(SkScalarNearlyEqual(rect.height(), 1));
64 }
65 
66 TEST(EmbeddedViewParams, GetBoundingRectAfterMutationsWithRotation45) {
67  MutatorsStack stack;
68  SkMatrix matrix;
69  matrix.setRotate(45);
70  stack.PushTransform(matrix);
71 
72  EmbeddedViewParams params(matrix, SkSize::Make(1, 1), stack);
73  const SkRect& rect = params.finalBoundingRect();
74  ASSERT_TRUE(SkScalarNearlyEqual(rect.x(), -sqrt(2) / 2));
75  ASSERT_TRUE(SkScalarNearlyEqual(rect.y(), 0));
76  ASSERT_TRUE(SkScalarNearlyEqual(rect.width(), sqrt(2)));
77  ASSERT_TRUE(SkScalarNearlyEqual(rect.height(), sqrt(2)));
78 }
79 
81  GetBoundingRectAfterMutationsWithTranslateScaleAndRotation) {
82  SkMatrix matrix = SkMatrix::MakeTrans(2, 2);
83  matrix.preScale(3, 3);
84  matrix.preRotate(90);
85 
86  MutatorsStack stack;
87  stack.PushTransform(matrix);
88 
89  EmbeddedViewParams params(matrix, SkSize::Make(1, 1), stack);
90  const SkRect& rect = params.finalBoundingRect();
91  ASSERT_TRUE(SkScalarNearlyEqual(rect.x(), -1));
92  ASSERT_TRUE(SkScalarNearlyEqual(rect.y(), 2));
93  ASSERT_TRUE(SkScalarNearlyEqual(rect.width(), 3));
94  ASSERT_TRUE(SkScalarNearlyEqual(rect.height(), 3));
95 }
96 
97 } // namespace testing
98 } // namespace flutter
void PushTransform(const SkMatrix &matrix)
const SkRect & finalBoundingRect() const
#define FML_DLOG(severity)
Definition: logging.h:85
TEST(EmbeddedViewParams, GetBoundingRectAfterMutationsWithNoMutations)