Flutter Engine
 
Loading...
Searching...
No Matches
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
8
12#include "flutter/fml/macros.h"
13
14namespace flutter {
15namespace testing {
16
18
19TEST_F(PlatformViewLayerTest, NullViewEmbedderDoesntPrerollCompositeOrPaint) {
20 const DlPoint layer_offset = DlPoint();
21 const DlSize layer_size = DlSize(8.0f, 8.0f);
22 const int64_t view_id = 0;
23 auto layer =
24 std::make_shared<PlatformViewLayer>(layer_offset, layer_size, view_id);
25
26 layer->Preroll(preroll_context());
27 EXPECT_FALSE(preroll_context()->has_platform_view);
28 EXPECT_EQ(layer->paint_bounds(),
29 DlRect::MakeOriginSize(layer_offset, layer_size));
30 EXPECT_TRUE(layer->needs_painting(paint_context()));
31 EXPECT_FALSE(layer->subtree_has_platform_view());
32
33 layer->Paint(display_list_paint_context());
34
35 DisplayListBuilder expected_builder;
36 auto expected_dl = expected_builder.Build();
37
38 EXPECT_TRUE(DisplayListsEQ_Verbose(display_list(), expected_dl));
39}
40
41TEST_F(PlatformViewLayerTest, ClippedPlatformViewPrerollsAndPaintsNothing) {
42 const DlPoint layer_offset = DlPoint();
43 const DlSize layer_size = DlSize(8.0f, 8.0f);
44 const DlRect child_clip = DlRect::MakeLTRB(20.0f, 20.0f, 40.0f, 40.0f);
45 const DlRect parent_clip = DlRect::MakeLTRB(50.0f, 50.0f, 80.0f, 80.0f);
46 const int64_t view_id = 0;
47 auto layer =
48 std::make_shared<PlatformViewLayer>(layer_offset, layer_size, view_id);
49 auto child_clip_layer =
50 std::make_shared<ClipRectLayer>(child_clip, Clip::kHardEdge);
51 auto parent_clip_layer =
52 std::make_shared<ClipRectLayer>(parent_clip, Clip::kHardEdge);
53 parent_clip_layer->Add(child_clip_layer);
54 child_clip_layer->Add(layer);
55
56 auto embedder = MockViewEmbedder();
57 preroll_context()->view_embedder = &embedder;
58
59 parent_clip_layer->Preroll(preroll_context());
60 EXPECT_TRUE(preroll_context()->has_platform_view);
61 EXPECT_EQ(layer->paint_bounds(),
62 DlRect::MakeOriginSize(layer_offset, layer_size));
63 EXPECT_TRUE(layer->needs_painting(paint_context()));
64 EXPECT_TRUE(child_clip_layer->needs_painting(paint_context()));
65 EXPECT_TRUE(parent_clip_layer->needs_painting(paint_context()));
66 EXPECT_TRUE(layer->subtree_has_platform_view());
67 EXPECT_TRUE(child_clip_layer->subtree_has_platform_view());
68 EXPECT_TRUE(parent_clip_layer->subtree_has_platform_view());
69
70 parent_clip_layer->Paint(display_list_paint_context());
71
72 DisplayListBuilder expected_builder;
73 expected_builder.Save();
74 expected_builder.ClipRect(parent_clip, DlClipOp::kIntersect, false);
75
76 // In reality the following save/clip/restore are elided due to reaching
77 // a nop state (and the save is then unnecessary), but this is the order
78 // of operations that the layers will do...
79 expected_builder.Save();
80 expected_builder.ClipRect(child_clip, DlClipOp::kIntersect, false);
81 expected_builder.Restore();
82 // End of section that gets ignored during recording
83
84 expected_builder.Restore();
85 auto expected_dl = expected_builder.Build();
86
87 EXPECT_TRUE(DisplayListsEQ_Verbose(display_list(), expected_dl));
88}
89
90TEST_F(PlatformViewLayerTest, OpacityInheritance) {
91 const DlPoint layer_offset = DlPoint();
92 const DlSize layer_size = DlSize(8.0f, 8.0f);
93 const int64_t view_id = 0;
94 auto layer =
95 std::make_shared<PlatformViewLayer>(layer_offset, layer_size, view_id);
96
97 PrerollContext* context = preroll_context();
98 layer->Preroll(preroll_context());
99 EXPECT_EQ(context->renderable_state_flags, 0);
100}
101
103 const DlMatrix transform1 = DlMatrix::MakeTranslation({5.0f, 5.0f});
104 const DlMatrix transform2 = DlMatrix::MakeTranslation({15.0f, 15.0f});
105 const DlMatrix combined_transform = DlMatrix::MakeTranslation({20.0f, 20.0f});
106 const DlPoint layer_offset = DlPoint(0.0f, 0.0f);
107 const DlSize layer_size = DlSize(8.0f, 8.0f);
108 const int64_t view_id = 0;
109 const DlPath path1 = DlPath::MakeOvalLTRB(10, 10, 20, 20);
110 const DlPath path2 = DlPath::MakeOvalLTRB(15, 15, 30, 30);
111
112 // transform_layer1
113 // |- child1
114 // |- platform_layer
115 // |- transform_layer2
116 // |- child2
117 auto transform_layer1 = std::make_shared<TransformLayer>(transform1);
118 auto transform_layer2 = std::make_shared<TransformLayer>(transform2);
119 auto platform_layer =
120 std::make_shared<PlatformViewLayer>(layer_offset, layer_size, view_id);
121 auto child1 = std::make_shared<MockLayer>(path1);
122 child1->set_expected_paint_matrix(transform1);
123 auto child2 = std::make_shared<MockLayer>(path2);
124 child2->set_expected_paint_matrix(combined_transform);
125 transform_layer1->Add(child1);
126 transform_layer1->Add(platform_layer);
127 transform_layer1->Add(transform_layer2);
128 transform_layer2->Add(child2);
129
130 auto embedder = MockViewEmbedder();
131 DisplayListBuilder builder(DlRect::MakeWH(500, 500));
132 embedder.AddCanvas(&builder);
133
134 PrerollContext* preroll_ctx = preroll_context();
135 preroll_ctx->view_embedder = &embedder;
136 transform_layer1->Preroll(preroll_ctx);
137
138 PaintContext& paint_ctx = paint_context();
139 paint_ctx.view_embedder = &embedder;
140 transform_layer1->Paint(paint_ctx);
141}
142
143} // namespace testing
144} // namespace flutter
void ClipRect(const DlRect &rect, DlClipOp clip_op=DlClipOp::kIntersect, bool is_aa=false) override
sk_sp< DisplayList > Build()
Definition dl_builder.cc:66
static DlPath MakeOvalLTRB(DlScalar left, DlScalar top, DlScalar right, DlScalar bottom)
Definition dl_path.cc:61
G_BEGIN_DECLS FlutterViewId view_id
TEST_F(DisplayListTest, Defaults)
LayerTestBase<::testing::Test > LayerTest
Definition layer_test.h:177
bool DisplayListsEQ_Verbose(const DisplayList *a, const DisplayList *b)
@ kHardEdge
Definition layer.h:43
impeller::Size DlSize
impeller::Point DlPoint
ExternalViewEmbedder * view_embedder
Definition layer.h:101
ExternalViewEmbedder * view_embedder
Definition layer.h:48
A 4x4 matrix using column-major storage.
Definition matrix.h:37
static constexpr Matrix MakeTranslation(const Vector3 &t)
Definition matrix.h:95
static constexpr TRect MakeWH(Type width, Type height)
Definition rect.h:140
static constexpr TRect MakeOriginSize(const TPoint< Type > &origin, const TSize< Type > &size)
Definition rect.h:144
static constexpr TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition rect.h:129