Flutter Engine
The Flutter Engine
mock_layer_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/testing/mock_layer.h"
6
7#include "flutter/flow/testing/layer_test.h"
8#include "flutter/fml/macros.h"
9#include "flutter/testing/mock_canvas.h"
10
11namespace flutter {
12namespace testing {
13
15
16#ifndef NDEBUG
17TEST_F(MockLayerTest, PaintBeforePrerollDies) {
18 SkPath path = SkPath().addRect(5.0f, 6.0f, 20.5f, 21.5f);
19 auto layer = std::make_shared<MockLayer>(path, DlPaint());
20
21 EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()),
22 "needs_painting\\(context\\)");
23}
24
25TEST_F(MockLayerTest, PaintingEmptyLayerDies) {
26 auto layer = std::make_shared<MockLayer>(SkPath(), DlPaint());
27
28 layer->Preroll(preroll_context());
29 EXPECT_EQ(layer->paint_bounds(), SkPath().getBounds());
30
31 EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()),
32 "needs_painting\\(context\\)");
33}
34#endif
35
36TEST_F(MockLayerTest, SimpleParams) {
37 const SkPath path = SkPath().addRect(5.0f, 6.0f, 20.5f, 21.5f);
39 const SkMatrix start_matrix = SkMatrix::Translate(1.0f, 2.0f);
40 const SkMatrix scale_matrix = SkMatrix::Scale(0.5f, 0.5f);
41 const SkMatrix combined_matrix = SkMatrix::Concat(start_matrix, scale_matrix);
42 const SkRect local_cull_rect = SkRect::MakeWH(5.0f, 5.0f);
43 const SkRect device_cull_rect = combined_matrix.mapRect(local_cull_rect);
44 const bool parent_has_platform_view = true;
45 auto layer = std::make_shared<MockLayer>(path, paint);
46
47 preroll_context()->state_stack.set_preroll_delegate(device_cull_rect,
48 start_matrix);
49 auto mutator = preroll_context()->state_stack.save();
50 mutator.transform(scale_matrix);
51 preroll_context()->has_platform_view = parent_has_platform_view;
52 layer->Preroll(preroll_context());
53 EXPECT_EQ(preroll_context()->has_platform_view, false);
54 EXPECT_EQ(layer->paint_bounds(), path.getBounds());
55 EXPECT_TRUE(layer->needs_painting(paint_context()));
56 EXPECT_EQ(layer->parent_mutators(), std::vector{Mutator(scale_matrix)});
57 EXPECT_EQ(layer->parent_matrix(), combined_matrix);
58 EXPECT_EQ(layer->parent_cull_rect(), local_cull_rect);
59 EXPECT_EQ(layer->parent_has_platform_view(), parent_has_platform_view);
60
61 layer->Paint(paint_context());
62 EXPECT_EQ(mock_canvas().draw_calls(),
63 std::vector({MockCanvas::DrawCall{
65}
66
67TEST_F(MockLayerTest, FakePlatformView) {
68 auto layer = std::make_shared<MockLayer>(SkPath(), DlPaint());
69 layer->set_fake_has_platform_view(true);
70 EXPECT_EQ(preroll_context()->has_platform_view, false);
71
72 layer->Preroll(preroll_context());
73 EXPECT_EQ(preroll_context()->has_platform_view, true);
74}
75
76TEST_F(MockLayerTest, SaveLayerOnLeafNodesCanvas) {
77 auto layer = std::make_shared<MockLayer>(SkPath(), DlPaint());
78 layer->set_fake_has_platform_view(true);
79 EXPECT_EQ(preroll_context()->has_platform_view, false);
80
81 layer->Preroll(preroll_context());
82 EXPECT_EQ(preroll_context()->has_platform_view, true);
83}
84
85TEST_F(MockLayerTest, OpacityInheritance) {
86 auto path1 = SkPath().addRect({10, 10, 30, 30});
87 PrerollContext* context = preroll_context();
88
89 auto mock1 = std::make_shared<MockLayer>(path1);
90 mock1->Preroll(context);
91 EXPECT_EQ(context->renderable_state_flags, 0);
92
94 mock2->Preroll(context);
95 EXPECT_EQ(context->renderable_state_flags,
97}
98
99TEST_F(MockLayerTest, FlagGetSet) {
100 auto mock_layer = std::make_shared<MockLayer>(SkPath());
101
102 EXPECT_EQ(mock_layer->parent_has_platform_view(), false);
103 mock_layer->set_parent_has_platform_view(true);
104 EXPECT_EQ(mock_layer->parent_has_platform_view(), true);
105
106 EXPECT_EQ(mock_layer->parent_has_texture_layer(), false);
107 mock_layer->set_parent_has_texture_layer(true);
108 EXPECT_EQ(mock_layer->parent_has_texture_layer(), true);
109
110 EXPECT_EQ(mock_layer->fake_has_platform_view(), false);
111 mock_layer->set_fake_has_platform_view(true);
112 EXPECT_EQ(mock_layer->fake_has_platform_view(), true);
113
114 EXPECT_EQ(mock_layer->fake_reads_surface(), false);
115 mock_layer->set_fake_reads_surface(true);
116 EXPECT_EQ(mock_layer->fake_reads_surface(), true);
117
118 EXPECT_EQ(mock_layer->fake_opacity_compatible(), false);
119 mock_layer->set_fake_opacity_compatible(true);
120 EXPECT_EQ(mock_layer->fake_opacity_compatible(), true);
121
122 EXPECT_EQ(mock_layer->fake_has_texture_layer(), false);
123 mock_layer->set_fake_has_texture_layer(true);
124 EXPECT_EQ(mock_layer->fake_has_texture_layer(), true);
125}
126
127} // namespace testing
128} // namespace flutter
static SkPath path1()
static SkMatrix Scale(SkScalar sx, SkScalar sy)
Definition: SkMatrix.h:75
static SkMatrix Translate(SkScalar dx, SkScalar dy)
Definition: SkMatrix.h:91
static SkMatrix Concat(const SkMatrix &a, const SkMatrix &b)
Definition: SkMatrix.h:1775
bool mapRect(SkRect *dst, const SkRect &src, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
Definition: SkMatrix.cpp:1141
Definition: SkPath.h:59
SkPath & addRect(const SkRect &rect, SkPathDirection dir, unsigned start)
Definition: SkPath.cpp:864
static constexpr int kCallerCanApplyOpacity
static std::shared_ptr< MockLayer > MakeOpacityCompatible(const SkPath &path)
Definition: mock_layer.h:35
const Paint & paint
Definition: color_source.cc:38
TEST_F(DisplayListTest, Defaults)
LayerTestBase<::testing::Test > LayerTest
Definition: layer_test.h:210
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
flutter::DlPaint DlPaint
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609
static constexpr DlColor kBlue()
Definition: dl_color.h:26
#define EXPECT_TRUE(handle)
Definition: unit_test.h:678