Flutter Engine
The Flutter Engine
platform_view_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/layers/clip_rect_layer.h"
6#include "flutter/flow/layers/platform_view_layer.h"
7#include "flutter/flow/layers/transform_layer.h"
8
9#include "flutter/flow/testing/layer_test.h"
10#include "flutter/flow/testing/mock_embedder.h"
11#include "flutter/flow/testing/mock_layer.h"
12#include "flutter/fml/macros.h"
13#include "flutter/testing/mock_canvas.h"
14
15namespace flutter {
16namespace testing {
17
19
21
22TEST_F(PlatformViewLayerTest, NullViewEmbedderDoesntPrerollCompositeOrPaint) {
23 const SkPoint layer_offset = SkPoint::Make(0.0f, 0.0f);
24 const SkSize layer_size = SkSize::Make(8.0f, 8.0f);
25 const int64_t view_id = 0;
26 auto layer =
27 std::make_shared<PlatformViewLayer>(layer_offset, layer_size, view_id);
28
29 layer->Preroll(preroll_context());
30 EXPECT_FALSE(preroll_context()->has_platform_view);
31 EXPECT_EQ(layer->paint_bounds(),
32 SkRect::MakeSize(layer_size)
33 .makeOffset(layer_offset.fX, layer_offset.fY));
34 EXPECT_TRUE(layer->needs_painting(paint_context()));
35 EXPECT_FALSE(layer->subtree_has_platform_view());
36
37 layer->Paint(paint_context());
38 EXPECT_EQ(paint_context().canvas, &mock_canvas());
39 EXPECT_EQ(mock_canvas().draw_calls(), std::vector<MockCanvas::DrawCall>());
40}
41
42TEST_F(PlatformViewLayerTest, ClippedPlatformViewPrerollsAndPaintsNothing) {
43 const SkPoint layer_offset = SkPoint::Make(0.0f, 0.0f);
44 const SkSize layer_size = SkSize::Make(8.0f, 8.0f);
45 const SkRect child_clip = SkRect::MakeLTRB(20.0f, 20.0f, 40.0f, 40.0f);
46 const SkRect parent_clip = SkRect::MakeLTRB(50.0f, 50.0f, 80.0f, 80.0f);
47 const int64_t view_id = 0;
48 auto layer =
49 std::make_shared<PlatformViewLayer>(layer_offset, layer_size, view_id);
50 auto child_clip_layer =
51 std::make_shared<ClipRectLayer>(child_clip, Clip::kHardEdge);
52 auto parent_clip_layer =
53 std::make_shared<ClipRectLayer>(parent_clip, Clip::kHardEdge);
54 parent_clip_layer->Add(child_clip_layer);
55 child_clip_layer->Add(layer);
56
57 auto embedder = MockViewEmbedder();
58 preroll_context()->view_embedder = &embedder;
59
60 parent_clip_layer->Preroll(preroll_context());
61 EXPECT_TRUE(preroll_context()->has_platform_view);
62 EXPECT_EQ(layer->paint_bounds(),
63 SkRect::MakeSize(layer_size)
64 .makeOffset(layer_offset.fX, layer_offset.fY));
65 EXPECT_TRUE(layer->needs_painting(paint_context()));
66 EXPECT_TRUE(child_clip_layer->needs_painting(paint_context()));
67 EXPECT_TRUE(parent_clip_layer->needs_painting(paint_context()));
68 EXPECT_TRUE(layer->subtree_has_platform_view());
69 EXPECT_TRUE(child_clip_layer->subtree_has_platform_view());
70 EXPECT_TRUE(parent_clip_layer->subtree_has_platform_view());
71
72 parent_clip_layer->Paint(paint_context());
73 EXPECT_EQ(paint_context().canvas, &mock_canvas());
74 EXPECT_EQ(
75 mock_canvas().draw_calls(),
76 std::vector(
87}
88
89TEST_F(PlatformViewLayerTest, OpacityInheritance) {
90 const SkPoint layer_offset = SkPoint::Make(0.0f, 0.0f);
91 const SkSize layer_size = SkSize::Make(8.0f, 8.0f);
92 const int64_t view_id = 0;
93 auto layer =
94 std::make_shared<PlatformViewLayer>(layer_offset, layer_size, view_id);
95
96 PrerollContext* context = preroll_context();
97 layer->Preroll(preroll_context());
98 EXPECT_EQ(context->renderable_state_flags, 0);
99}
100
102 const SkMatrix transform1 = SkMatrix::Translate(5, 5);
103 const SkMatrix transform2 = SkMatrix::Translate(15, 15);
104 const SkMatrix combined_transform = SkMatrix::Translate(20, 20);
105 const SkPoint layer_offset = SkPoint::Make(0.0f, 0.0f);
106 const SkSize layer_size = SkSize::Make(8.0f, 8.0f);
107 const int64_t view_id = 0;
108 const SkPath path1 = SkPath().addOval({10, 10, 20, 20});
109 const SkPath path2 = SkPath().addOval({15, 15, 30, 30});
110
111 // transform_layer1
112 // |- child1
113 // |- platform_layer
114 // |- transform_layer2
115 // |- child2
116 auto transform_layer1 = std::make_shared<TransformLayer>(transform1);
117 auto transform_layer2 = std::make_shared<TransformLayer>(transform2);
118 auto platform_layer =
119 std::make_shared<PlatformViewLayer>(layer_offset, layer_size, view_id);
120 auto child1 = std::make_shared<MockLayer>(path1);
121 child1->set_expected_paint_matrix(transform1);
122 auto child2 = std::make_shared<MockLayer>(path2);
123 child2->set_expected_paint_matrix(combined_transform);
124 transform_layer1->Add(child1);
125 transform_layer1->Add(platform_layer);
126 transform_layer1->Add(transform_layer2);
127 transform_layer2->Add(child2);
128
129 auto embedder = MockViewEmbedder();
130 DisplayListBuilder builder({0, 0, 500, 500});
131 embedder.AddCanvas(&builder);
132
133 PrerollContext* preroll_ctx = preroll_context();
134 preroll_ctx->view_embedder = &embedder;
135 transform_layer1->Preroll(preroll_ctx);
136
137 PaintContext& paint_ctx = paint_context();
138 paint_ctx.view_embedder = &embedder;
139 transform_layer1->Paint(paint_ctx);
140}
141
142} // namespace testing
143} // namespace flutter
static SkPath path1()
static SkPath path2()
static SkMatrix Translate(SkScalar dx, SkScalar dy)
Definition: SkMatrix.h:91
Definition: SkPath.h:59
SkPath & addOval(const SkRect &oval, SkPathDirection dir=SkPathDirection::kCW)
Definition: SkPath.cpp:1106
TEST_F(DisplayListTest, Defaults)
LayerTestBase<::testing::Test > LayerTest
Definition: layer_test.h:210
@ kHardEdge
Definition: layer.h:53
float fX
x-axis value
Definition: SkPoint_impl.h:164
static constexpr SkPoint Make(float x, float y)
Definition: SkPoint_impl.h:173
float fY
y-axis value
Definition: SkPoint_impl.h:165
constexpr SkRect makeOffset(float dx, float dy) const
Definition: SkRect.h:965
static constexpr SkRect MakeSize(const SkSize &size)
Definition: SkRect.h:633
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646
Definition: SkSize.h:52
static constexpr SkSize Make(SkScalar w, SkScalar h)
Definition: SkSize.h:56
ExternalViewEmbedder * view_embedder
Definition: layer.h:111
int renderable_state_flags
Definition: layer.h:83
ExternalViewEmbedder * view_embedder
Definition: layer.h:58
#define EXPECT_TRUE(handle)
Definition: unit_test.h:678