5#include "flutter/flow/layers/backdrop_filter_layer.h"
6#include "flutter/flow/layers/clip_rect_layer.h"
8#include "flutter/flow/layers/clip_rect_layer.h"
9#include "flutter/flow/layers/transform_layer.h"
10#include "flutter/flow/testing/diff_context_test.h"
11#include "flutter/flow/testing/layer_test.h"
12#include "flutter/flow/testing/mock_layer.h"
13#include "flutter/fml/macros.h"
23 auto layer = std::make_shared<BackdropFilterLayer>(filter.shared(),
28 parent->Preroll(preroll_context());
30 EXPECT_EQ(layer->child_paint_bounds(),
kEmptyRect);
31 EXPECT_FALSE(layer->needs_painting(paint_context()));
33 EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()),
34 "needs_painting\\(context\\)");
40 auto mock_layer = std::make_shared<MockLayer>(child_path);
42 auto layer = std::make_shared<BackdropFilterLayer>(filter.shared(),
44 layer->Add(mock_layer);
47 EXPECT_EQ(layer->child_paint_bounds(),
kEmptyRect);
48 EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()),
49 "needs_painting\\(context\\)");
58 auto mock_layer = std::make_shared<MockLayer>(child_path, child_paint);
61 layer->Add(mock_layer);
62 auto parent = std::make_shared<ClipRectLayer>(child_bounds,
Clip::kHardEdge);
65 preroll_context()->state_stack.set_preroll_delegate(initial_transform);
66 parent->Preroll(preroll_context());
67 EXPECT_EQ(layer->paint_bounds(), child_bounds);
68 EXPECT_EQ(layer->child_paint_bounds(), child_bounds);
69 EXPECT_TRUE(layer->needs_painting(paint_context()));
70 EXPECT_EQ(mock_layer->parent_matrix(), initial_transform);
72 parent->Paint(display_list_paint_context());
75 expected_builder.
Save();
80 expected_builder.
Save();
82 expected_builder.
SaveLayer(&child_bounds,
nullptr,
nullptr);
85 expected_builder.
DrawPath(child_path, child_paint);
105 auto mock_layer = std::make_shared<MockLayer>(child_path, child_paint);
106 auto layer = std::make_shared<BackdropFilterLayer>(layer_filter,
108 layer->Add(mock_layer);
109 auto parent = std::make_shared<ClipRectLayer>(child_bounds,
Clip::kHardEdge);
112 preroll_context()->state_stack.set_preroll_delegate(initial_transform);
113 parent->Preroll(preroll_context());
114 EXPECT_EQ(layer->paint_bounds(), child_bounds);
115 EXPECT_EQ(layer->child_paint_bounds(), child_bounds);
116 EXPECT_TRUE(layer->needs_painting(paint_context()));
117 EXPECT_EQ(mock_layer->parent_matrix(), initial_transform);
119 parent->Paint(display_list_paint_context());
122 expected_builder.
Save();
127 expected_builder.
Save();
129 expected_builder.
SaveLayer(&child_bounds,
nullptr,
133 expected_builder.
DrawPath(child_path, child_paint);
153 auto mock_layer = std::make_shared<MockLayer>(child_path, child_paint);
156 layer->Add(mock_layer);
157 auto parent = std::make_shared<ClipRectLayer>(child_bounds,
Clip::kHardEdge);
160 preroll_context()->state_stack.set_preroll_delegate(initial_transform);
161 parent->Preroll(preroll_context());
162 EXPECT_EQ(layer->paint_bounds(), child_bounds);
163 EXPECT_EQ(layer->child_paint_bounds(), child_bounds);
164 EXPECT_TRUE(layer->needs_painting(paint_context()));
165 EXPECT_EQ(mock_layer->parent_matrix(), initial_transform);
170 parent->Paint(display_list_paint_context());
173 expected_builder.
Save();
178 expected_builder.
Save();
181 expected_builder.
SaveLayer(&child_bounds, &save_paint,
185 expected_builder.
DrawPath(child_path, child_paint);
202 const SkPath child_path2 =
210 auto mock_layer1 = std::make_shared<MockLayer>(child_path1, child_paint1);
211 auto mock_layer2 = std::make_shared<MockLayer>(child_path2, child_paint2);
212 auto layer = std::make_shared<BackdropFilterLayer>(layer_filter,
214 layer->Add(mock_layer1);
215 layer->Add(mock_layer2);
220 preroll_context()->state_stack.set_preroll_delegate(initial_transform);
221 parent->Preroll(preroll_context());
222 EXPECT_EQ(mock_layer1->paint_bounds(), child_path1.
getBounds());
223 EXPECT_EQ(mock_layer2->paint_bounds(), child_path2.
getBounds());
224 EXPECT_EQ(layer->paint_bounds(), children_bounds);
225 EXPECT_EQ(layer->child_paint_bounds(), children_bounds);
226 EXPECT_TRUE(mock_layer1->needs_painting(paint_context()));
227 EXPECT_TRUE(mock_layer2->needs_painting(paint_context()));
228 EXPECT_TRUE(layer->needs_painting(paint_context()));
229 EXPECT_EQ(mock_layer1->parent_matrix(), initial_transform);
230 EXPECT_EQ(mock_layer2->parent_matrix(), initial_transform);
232 parent->Paint(display_list_paint_context());
235 expected_builder.
Save();
240 expected_builder.
Save();
242 expected_builder.
SaveLayer(&children_bounds,
nullptr,
246 expected_builder.
DrawPath(child_path1, child_paint1);
249 expected_builder.
DrawPath(child_path2, child_paint2);
266 const SkPath child_path2 =
276 auto mock_layer1 = std::make_shared<MockLayer>(child_path1, child_paint1);
277 auto mock_layer2 = std::make_shared<MockLayer>(child_path2, child_paint2);
278 auto layer1 = std::make_shared<BackdropFilterLayer>(layer_filter1,
280 auto layer2 = std::make_shared<BackdropFilterLayer>(layer_filter2,
282 layer2->Add(mock_layer2);
283 layer1->Add(mock_layer1);
289 preroll_context()->state_stack.set_preroll_delegate(initial_transform);
290 parent->Preroll(preroll_context());
292 EXPECT_EQ(mock_layer1->paint_bounds(), child_path1.
getBounds());
293 EXPECT_EQ(mock_layer2->paint_bounds(), child_path2.
getBounds());
294 EXPECT_EQ(layer1->paint_bounds(), children_bounds);
295 EXPECT_EQ(layer2->paint_bounds(), children_bounds);
296 EXPECT_TRUE(mock_layer1->needs_painting(paint_context()));
297 EXPECT_TRUE(mock_layer2->needs_painting(paint_context()));
298 EXPECT_TRUE(layer1->needs_painting(paint_context()));
299 EXPECT_TRUE(layer2->needs_painting(paint_context()));
300 EXPECT_EQ(mock_layer1->parent_matrix(), initial_transform);
301 EXPECT_EQ(mock_layer2->parent_matrix(), initial_transform);
303 parent->Paint(display_list_paint_context());
306 expected_builder.
Save();
311 expected_builder.
Save();
313 expected_builder.
SaveLayer(&children_bounds,
nullptr,
314 layer_filter1.get());
317 expected_builder.
DrawPath(child_path1, child_paint1);
320 expected_builder.
Save();
322 expected_builder.
SaveLayer(&children_bounds,
nullptr,
323 layer_filter2.get());
326 expected_builder.
DrawPath(child_path2, child_paint2);
345 std::shared_ptr<DlImageFilter> no_filter;
347 auto initial_transform =
SkMatrix();
350 auto layer1 = std::make_shared<BackdropFilterLayer>(layer_filter.shared(),
352 preroll_context()->surface_needs_readback =
false;
353 preroll_context()->state_stack.set_preroll_delegate(initial_transform);
354 layer1->Preroll(preroll_context());
355 EXPECT_TRUE(preroll_context()->surface_needs_readback);
360 preroll_context()->surface_needs_readback =
false;
361 layer2->Preroll(preroll_context());
362 EXPECT_FALSE(preroll_context()->surface_needs_readback);
365 preroll_context()->surface_needs_readback =
true;
366 layer2->Preroll(preroll_context());
367 EXPECT_TRUE(preroll_context()->surface_needs_readback);
370 auto mock_layer = std::make_shared<MockLayer>(
SkPath(),
DlPaint());
371 mock_layer->set_fake_reads_surface(
true);
372 layer2->Add(mock_layer);
373 preroll_context()->surface_needs_readback =
false;
374 layer2->Preroll(preroll_context());
375 EXPECT_FALSE(preroll_context()->surface_needs_readback);
385 auto parent = std::make_shared<OpacityLayer>(128,
SkPoint::Make(0, 0));
386 auto layer = std::make_shared<BackdropFilterLayer>(backdrop_filter.shared(),
388 auto child = std::make_shared<MockLayer>(mock_path, mock_paint);
393 clip->Preroll(preroll_context());
395 clip->Paint(display_list_paint_context());
399 expected_builder.
Save();
407 expected_builder.
SaveLayer(&clip_rect, &save_paint, &backdrop_filter);
412 expected_builder.
DrawPath(mock_path, child_paint);
439 l1.
root()->
Add(std::make_shared<BackdropFilterLayer>(filter.shared(),
450 clip->Add(std::make_shared<BackdropFilterLayer>(filter.shared(),
471 damage = DiffLayerTree(l4, l3);
480 damage = DiffLayerTree(l5, l4);
492 clip->Add(std::make_shared<BackdropFilterLayer>(filter.shared(),
505 damage = DiffLayerTree(l2, l1);
526 auto transform_layer = std::make_shared<TransformLayer>(
transform);
527 l1.
root()->
Add(transform_layer);
528 transform_layer->Add(std::make_shared<BackdropFilterLayer>(
static void readback(const SkBitmap &src, int *result, int resultCount)
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
static SkMatrix Scale(SkScalar sx, SkScalar sy)
static SkMatrix Translate(SkScalar dx, SkScalar dy)
static const SkMatrix & I()
const SkRect & getBounds() const
SkPath & addRect(const SkRect &rect, SkPathDirection dir, unsigned start)
virtual void Add(std::shared_ptr< Layer > layer)
void DrawPath(const SkPath &path, const DlPaint &paint) override
void SaveLayer(const SkRect *bounds, const DlPaint *paint=nullptr, const DlImageFilter *backdrop=nullptr) override
sk_sp< DisplayList > Build()
void ClipRect(const SkRect &rect, ClipOp clip_op=ClipOp::kIntersect, bool is_aa=false) override
DlPaint & setColor(DlColor color)
DlPaint & setAlpha(uint8_t alpha)
DlPaint & setBlendMode(DlBlendMode mode)
TEST_F(DisplayListTest, Defaults)
LayerTestBase<::testing::Test > LayerTest
bool DisplayListsEQ_Verbose(const DisplayList *a, const DisplayList *b)
static constexpr SkRect kEmptyRect
@ kSrcOver
r = s + (1-sa)*d
static SkColor4f transform(SkColor4f c, SkColorSpace *src, SkColorSpace *dst)
static constexpr SkIRect MakeLTRB(int32_t l, int32_t t, int32_t r, int32_t b)
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
static constexpr SkISize Make(int32_t w, int32_t h)
static constexpr SkPoint Make(float x, float y)
constexpr SkRect makeOffset(float dx, float dy) const
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
void join(const SkRect &r)
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
static constexpr DlColor kYellow()
static constexpr DlColor kRed()
static constexpr DlColor kCyan()
#define EXPECT_TRUE(handle)