@@ -66,7 +66,7 @@ TEST_F(PhysicalShapeLayerTest, NonEmptyLayer) {
66
66
0 , MockCanvas::DrawPathData{layer_path, layer_paint}}}));
67
67
}
68
68
69
- TEST_F (PhysicalShapeLayerTest, ChildrenLargerThanPath ) {
69
+ TEST_F (PhysicalShapeLayerTest, ChildrenLargerThanPathClip ) {
70
70
SkPath layer_path;
71
71
layer_path.addRect (5 .0f , 6 .0f , 20 .5f , 21 .5f );
72
72
SkPath child1_path;
@@ -83,18 +83,74 @@ TEST_F(PhysicalShapeLayerTest, ChildrenLargerThanPath) {
83
83
auto layer =
84
84
std::make_shared<PhysicalShapeLayer>(SK_ColorGREEN, SK_ColorBLACK,
85
85
0 .0f , // elevation
86
- layer_path, Clip::none );
86
+ layer_path, Clip::hardEdge );
87
87
layer->Add (child1);
88
88
layer->Add (child2);
89
89
90
- SkRect child_paint_bounds;
90
+ SkRect child_paint_bounds = SkRect::MakeEmpty () ;
91
91
layer->Preroll (preroll_context (), SkMatrix ());
92
92
child_paint_bounds.join (child1->paint_bounds ());
93
93
child_paint_bounds.join (child2->paint_bounds ());
94
94
EXPECT_EQ (layer->paint_bounds (), layer_path.getBounds ());
95
95
EXPECT_NE (layer->paint_bounds (), child_paint_bounds);
96
96
EXPECT_TRUE (layer->needs_painting (paint_context ()));
97
97
98
+ SkPaint layer_paint;
99
+ layer_paint.setColor (SK_ColorGREEN);
100
+ layer_paint.setAntiAlias (true );
101
+ SkPaint child1_paint;
102
+ child1_paint.setColor (SK_ColorRED);
103
+ child1_paint.setAntiAlias (true );
104
+ SkPaint child2_paint;
105
+ child2_paint.setColor (SK_ColorBLUE);
106
+ child2_paint.setAntiAlias (true );
107
+ layer->Paint (paint_context ());
108
+ EXPECT_EQ (mock_canvas ().draw_calls (),
109
+ std::vector ({
110
+ MockCanvas::DrawCall{
111
+ 0 , MockCanvas::DrawPathData{layer_path, layer_paint}},
112
+ MockCanvas::DrawCall{0 , MockCanvas::SaveData{1 }},
113
+ MockCanvas::DrawCall{
114
+ 1 , MockCanvas::ClipRectData{layer_path.getBounds (),
115
+ SkClipOp::kIntersect }},
116
+ MockCanvas::DrawCall{
117
+ 1 , MockCanvas::DrawPathData{child1_path, child1_paint}},
118
+ MockCanvas::DrawCall{
119
+ 1 , MockCanvas::DrawPathData{child2_path, child2_paint}},
120
+ MockCanvas::DrawCall{1 , MockCanvas::RestoreData{0 }},
121
+ }));
122
+ }
123
+
124
+ TEST_F (PhysicalShapeLayerTest, ChildrenLargerThanPathNoClip) {
125
+ SkPath layer_path;
126
+ layer_path.addRect (5 .0f , 6 .0f , 20 .5f , 21 .5f );
127
+ SkPath child1_path;
128
+ child1_path.addRect (4 , 0 , 12 , 12 ).close ();
129
+ SkPath child2_path;
130
+ child2_path.addRect (3 , 2 , 5 , 15 ).close ();
131
+ auto child1 = std::make_shared<PhysicalShapeLayer>(SK_ColorRED, SK_ColorBLACK,
132
+ 0 .0f , // elevation
133
+ child1_path, Clip::none);
134
+ auto child2 =
135
+ std::make_shared<PhysicalShapeLayer>(SK_ColorBLUE, SK_ColorBLACK,
136
+ 0 .0f , // elevation
137
+ child2_path, Clip::none);
138
+ auto layer =
139
+ std::make_shared<PhysicalShapeLayer>(SK_ColorGREEN, SK_ColorBLACK,
140
+ 0 .0f , // elevation
141
+ layer_path, Clip::none);
142
+ layer->Add (child1);
143
+ layer->Add (child2);
144
+
145
+ SkRect total_bounds = SkRect::MakeEmpty ();
146
+ layer->Preroll (preroll_context (), SkMatrix ());
147
+ total_bounds.join (child1->paint_bounds ());
148
+ total_bounds.join (child2->paint_bounds ());
149
+ total_bounds.join (layer_path.getBounds ());
150
+ EXPECT_NE (layer->paint_bounds (), layer_path.getBounds ());
151
+ EXPECT_EQ (layer->paint_bounds (), total_bounds);
152
+ EXPECT_TRUE (layer->needs_painting (paint_context ()));
153
+
98
154
SkPaint layer_paint;
99
155
layer_paint.setColor (SK_ColorGREEN);
100
156
layer_paint.setAntiAlias (true );
@@ -174,10 +230,14 @@ TEST_F(PhysicalShapeLayerTest, ElevationComplex) {
174
230
// On Fuchsia, the system compositor handles all elevated
175
231
// PhysicalShapeLayers and their shadows , so we do not do any painting
176
232
// there.
177
- EXPECT_EQ (layers[i]->paint_bounds (),
178
- (DisplayListCanvasDispatcher::ComputeShadowBounds (
179
- layer_path, initial_elevations[i], 1 .0f /* pixel_ratio */ ,
180
- SkMatrix ())));
233
+ SkRect paint_bounds = DisplayListCanvasDispatcher::ComputeShadowBounds (
234
+ layer_path, initial_elevations[i], 1 .0f /* pixel_ratio */ , SkMatrix ());
235
+
236
+ // Without clipping the children will be painted as well
237
+ for (auto layer : layers[i]->layers ()) {
238
+ paint_bounds.join (layer->paint_bounds ());
239
+ }
240
+ EXPECT_EQ (layers[i]->paint_bounds (), paint_bounds);
181
241
EXPECT_TRUE (layers[i]->needs_painting (paint_context ()));
182
242
}
183
243
0 commit comments