6#include "flutter/flow/layers/layer_tree.h"
8#include "flutter/flow/compositor_context.h"
9#include "flutter/flow/layers/container_layer.h"
10#include "flutter/flow/raster_cache.h"
11#include "flutter/flow/testing/mock_layer.h"
12#include "flutter/fml/macros.h"
13#include "flutter/testing/canvas_test.h"
14#include "flutter/testing/mock_canvas.h"
15#include "gtest/gtest.h"
22 : root_transform_(
SkMatrix::Translate(1.0f, 1.0f)),
23 scoped_frame_(compositor_context_.AcquireFrame(nullptr,
36 const std::shared_ptr<Layer>& root_layer) {
37 return std::make_unique<LayerTree>(root_layer,
SkISize::Make(64, 64));
43 std::unique_ptr<CompositorContext::ScopedFrame> scoped_frame_;
47 auto layer = std::make_shared<ContainerLayer>();
48 auto layer_tree = BuildLayerTree(layer);
49 layer_tree->Preroll(
frame());
53 layer_tree->Paint(
frame());
59 child_path.
addRect(child_bounds);
60 auto mock_layer = std::make_shared<MockLayer>(child_path);
61 auto layer = std::make_shared<ContainerLayer>();
62 layer->Add(mock_layer);
64 auto layer_tree = BuildLayerTree(layer);
65 EXPECT_EQ(mock_layer->paint_bounds(),
kEmptyRect);
70 layer_tree->Paint(
frame());
71 EXPECT_EQ(mock_canvas().draw_calls(), std::vector<MockCanvas::DrawCall>());
78 auto mock_layer = std::make_shared<MockLayer>(child_path, child_paint);
79 auto layer = std::make_shared<ContainerLayer>();
80 layer->Add(mock_layer);
82 auto layer_tree = BuildLayerTree(layer);
83 layer_tree->Preroll(
frame());
84 EXPECT_EQ(mock_layer->paint_bounds(), child_bounds);
85 EXPECT_EQ(layer->paint_bounds(), mock_layer->paint_bounds());
86 EXPECT_FALSE(mock_layer->is_empty());
87 EXPECT_FALSE(layer->is_empty());
88 EXPECT_EQ(mock_layer->parent_matrix(), root_transform());
90 layer_tree->Paint(
frame());
91 EXPECT_EQ(mock_canvas().draw_calls(),
101 auto mock_layer1 = std::make_shared<MockLayer>(child_path1, child_paint1);
102 mock_layer1->set_fake_has_platform_view(
true);
103 auto mock_layer2 = std::make_shared<MockLayer>(child_path2, child_paint2);
104 auto layer = std::make_shared<ContainerLayer>();
105 layer->Add(mock_layer1);
106 layer->Add(mock_layer2);
110 auto layer_tree = BuildLayerTree(layer);
111 layer_tree->Preroll(
frame());
112 EXPECT_EQ(mock_layer1->paint_bounds(), child_path1.
getBounds());
113 EXPECT_EQ(mock_layer2->paint_bounds(), child_path2.
getBounds());
114 EXPECT_EQ(layer->paint_bounds(), expected_total_bounds);
115 EXPECT_FALSE(mock_layer1->is_empty());
116 EXPECT_FALSE(mock_layer2->is_empty());
117 EXPECT_FALSE(layer->is_empty());
118 EXPECT_EQ(mock_layer1->parent_matrix(), root_transform());
119 EXPECT_EQ(mock_layer2->parent_matrix(), root_transform());
120 EXPECT_EQ(mock_layer1->parent_cull_rect(),
kGiantRect);
121 EXPECT_EQ(mock_layer2->parent_cull_rect(),
124 layer_tree->Paint(
frame());
126 mock_canvas().draw_calls(),
130 child_path2, child_paint2}}}));
137 auto mock_layer1 = std::make_shared<MockLayer>(child_path1, child_paint1);
138 auto mock_layer2 = std::make_shared<MockLayer>(
SkPath(), child_paint2);
139 auto layer = std::make_shared<ContainerLayer>();
140 layer->Add(mock_layer1);
141 layer->Add(mock_layer2);
143 auto layer_tree = BuildLayerTree(layer);
144 layer_tree->Preroll(
frame());
145 EXPECT_EQ(mock_layer1->paint_bounds(), child_path1.
getBounds());
146 EXPECT_EQ(mock_layer2->paint_bounds(),
SkPath().getBounds());
147 EXPECT_EQ(layer->paint_bounds(), child_path1.
getBounds());
148 EXPECT_FALSE(mock_layer1->is_empty());
150 EXPECT_FALSE(layer->is_empty());
151 EXPECT_EQ(mock_layer1->parent_matrix(), root_transform());
152 EXPECT_EQ(mock_layer2->parent_matrix(), root_transform());
153 EXPECT_EQ(mock_layer1->parent_cull_rect(),
kGiantRect);
154 EXPECT_EQ(mock_layer2->parent_cull_rect(),
kGiantRect);
156 layer_tree->Paint(
frame());
157 EXPECT_EQ(mock_canvas().draw_calls(),
167 auto mock_layer1 = std::make_shared<MockLayer>(child_path1, child_paint1);
168 auto mock_layer2 = std::make_shared<MockLayer>(child_path2, child_paint2);
169 auto layer = std::make_shared<ContainerLayer>();
170 layer->Add(mock_layer1);
171 layer->Add(mock_layer2);
175 auto layer_tree = BuildLayerTree(layer);
176 layer_tree->Preroll(
frame());
177 EXPECT_EQ(mock_layer1->paint_bounds(), child_path1.
getBounds());
178 EXPECT_EQ(mock_layer2->paint_bounds(), child_path2.
getBounds());
179 EXPECT_EQ(layer->paint_bounds(), expected_total_bounds);
180 EXPECT_FALSE(mock_layer1->is_empty());
181 EXPECT_FALSE(mock_layer2->is_empty());
182 EXPECT_FALSE(layer->is_empty());
183 EXPECT_EQ(mock_layer1->parent_matrix(), root_transform());
184 EXPECT_EQ(mock_layer2->parent_matrix(), root_transform());
185 EXPECT_EQ(mock_layer1->parent_cull_rect(),
kGiantRect);
186 EXPECT_EQ(mock_layer2->parent_cull_rect(),
kGiantRect);
188 layer_tree->Paint(
frame());
190 mock_canvas().draw_calls(),
194 child_path2, child_paint2}}}));
202 std::shared_ptr<TextureRegistry> mock_registry;
204 auto expect_defaults = [&state_stack, &mock_raster_time, &mock_ui_time,
206 EXPECT_EQ(context.raster_cache,
nullptr);
207 EXPECT_EQ(context.gr_context,
nullptr);
208 EXPECT_EQ(context.view_embedder,
nullptr);
209 EXPECT_EQ(&context.state_stack, &state_stack);
210 EXPECT_EQ(context.dst_color_space,
nullptr);
211 EXPECT_EQ(context.state_stack.device_cull_rect(),
kGiantRect);
212 EXPECT_EQ(context.state_stack.transform_3x3(),
SkMatrix::I());
213 EXPECT_EQ(context.state_stack.transform_4x4(),
SkM44());
214 EXPECT_EQ(context.surface_needs_readback,
false);
216 EXPECT_EQ(&context.raster_time, &mock_raster_time);
217 EXPECT_EQ(&context.ui_time, &mock_ui_time);
218 EXPECT_EQ(context.texture_registry.get(), mock_registry.get());
220 EXPECT_EQ(context.has_platform_view,
false);
221 EXPECT_EQ(context.has_texture_layer,
false);
223 EXPECT_EQ(context.renderable_state_flags, 0);
224 EXPECT_EQ(context.raster_cached_entries,
nullptr);
230 .raster_time = mock_raster_time,
231 .ui_time = mock_ui_time,
232 .texture_registry = mock_registry,
234 expect_defaults(context);
241 std::shared_ptr<TextureRegistry> mock_registry;
243 auto expect_defaults = [&state_stack, &mock_raster_time, &mock_ui_time,
245 EXPECT_EQ(&context.state_stack, &state_stack);
246 EXPECT_EQ(context.canvas,
nullptr);
247 EXPECT_EQ(context.gr_context,
nullptr);
248 EXPECT_EQ(context.view_embedder,
nullptr);
249 EXPECT_EQ(&context.raster_time, &mock_raster_time);
250 EXPECT_EQ(&context.ui_time, &mock_ui_time);
251 EXPECT_EQ(context.texture_registry.get(), mock_registry.get());
252 EXPECT_EQ(context.raster_cache,
nullptr);
254 EXPECT_EQ(context.enable_leaf_layer_tracing,
false);
255 EXPECT_EQ(context.layer_snapshot_store,
nullptr);
261 .raster_time = mock_raster_time,
262 .ui_time = mock_ui_time,
263 .texture_registry = mock_registry,
265 expect_defaults(context);
static const SkMatrix & I()
const SkRect & getBounds() const
SkPath & addRect(const SkRect &rect, SkPathDirection dir, unsigned start)
Used for fixed refresh rate cases.
void set_preroll_delegate(const SkRect &cull_rect, const SkMatrix &matrix)
MockCanvas & mock_canvas()
CompositorContext::ScopedFrame & frame()
std::unique_ptr< LayerTree > BuildLayerTree(const std::shared_ptr< Layer > &root_layer)
const SkMatrix & root_transform()
TEST_F(DisplayListTest, Defaults)
static constexpr SkRect kEmptyRect
static constexpr SkRect kGiantRect
static constexpr SkISize Make(int32_t w, int32_t h)
static constexpr SkRect MakeEmpty()
void join(const SkRect &r)
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
static constexpr DlColor kMidGrey()
static constexpr DlColor kGreen()
static constexpr DlColor kCyan()
LayerStateStack & state_stack
LayerStateStack & state_stack
#define EXPECT_TRUE(handle)