Flutter Engine
The 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
9namespace flutter {
10namespace testing {
11
12TEST(EmbeddedViewParams, GetBoundingRectAfterMutationsWithNoMutations) {
13 MutatorsStack stack;
15
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
24TEST(EmbeddedViewParams, GetBoundingRectAfterMutationsWithScale) {
25 MutatorsStack stack;
27 stack.PushTransform(matrix);
28
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
37TEST(EmbeddedViewParams, GetBoundingRectAfterMutationsWithTranslate) {
38 MutatorsStack stack;
40 stack.PushTransform(matrix);
41
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
50TEST(EmbeddedViewParams, GetBoundingRectAfterMutationsWithRotation90) {
51 MutatorsStack stack;
53 matrix.setRotate(90);
54 stack.PushTransform(matrix);
55
57 const SkRect& rect = params.finalBoundingRect();
58
59 ASSERT_TRUE(SkScalarNearlyEqual(rect.x(), -1));
60 ASSERT_TRUE(SkScalarNearlyEqual(rect.y(), 0));
61 ASSERT_TRUE(SkScalarNearlyEqual(rect.width(), 1));
62 ASSERT_TRUE(SkScalarNearlyEqual(rect.height(), 1));
63}
64
65TEST(EmbeddedViewParams, GetBoundingRectAfterMutationsWithRotation45) {
66 MutatorsStack stack;
68 matrix.setRotate(45);
69 stack.PushTransform(matrix);
70
72 const SkRect& rect = params.finalBoundingRect();
73 ASSERT_TRUE(SkScalarNearlyEqual(rect.x(), -sqrt(2) / 2));
74 ASSERT_TRUE(SkScalarNearlyEqual(rect.y(), 0));
75 ASSERT_TRUE(SkScalarNearlyEqual(rect.width(), sqrt(2)));
76 ASSERT_TRUE(SkScalarNearlyEqual(rect.height(), sqrt(2)));
77}
78
80 GetBoundingRectAfterMutationsWithTranslateScaleAndRotation) {
82 matrix.preScale(3, 3);
83 matrix.preRotate(90);
84
85 MutatorsStack stack;
86 stack.PushTransform(matrix);
87
89 const SkRect& rect = params.finalBoundingRect();
90 ASSERT_TRUE(SkScalarNearlyEqual(rect.x(), -1));
91 ASSERT_TRUE(SkScalarNearlyEqual(rect.y(), 2));
92 ASSERT_TRUE(SkScalarNearlyEqual(rect.width(), 3));
93 ASSERT_TRUE(SkScalarNearlyEqual(rect.height(), 3));
94}
95
96} // namespace testing
97} // namespace flutter
static bool SkScalarNearlyEqual(SkScalar x, SkScalar y, SkScalar tolerance=SK_ScalarNearlyZero)
Definition: SkScalar.h:107
static SkMatrix Scale(SkScalar sx, SkScalar sy)
Definition: SkMatrix.h:75
static SkMatrix Translate(SkScalar dx, SkScalar dy)
Definition: SkMatrix.h:91
void PushTransform(const SkMatrix &matrix)
const EmbeddedViewParams * params
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
TEST(DisplayListComplexity, EmptyDisplayList)
SIN Vec< N, float > sqrt(const Vec< N, float > &x)
Definition: SkVx.h:706
static constexpr SkSize Make(SkScalar w, SkScalar h)
Definition: SkSize.h:56