@@ -195,6 +195,90 @@ void testMain() {
195195 await matchSceneGolden ('canvaskit_dst_colorfilter.png' , builder.build (),
196196 region: region);
197197 });
198+
199+ test ('ColorFilter only applies to child bounds' , () async {
200+ final LayerSceneBuilder builder = LayerSceneBuilder ();
201+
202+ builder.pushOffset (0 , 0 );
203+
204+ // Draw a red circle and add it to the scene.
205+ final CkPictureRecorder recorder = CkPictureRecorder ();
206+ final CkCanvas canvas = recorder.beginRecording (region);
207+
208+ canvas.drawCircle (
209+ const ui.Offset (75 , 125 ),
210+ 50 ,
211+ CkPaint ()..color = const ui.Color .fromARGB (255 , 255 , 0 , 0 ),
212+ );
213+ final CkPicture redCircle = recorder.endRecording ();
214+
215+ builder.addPicture (ui.Offset .zero, redCircle);
216+
217+ // Apply a green color filter.
218+ builder.pushColorFilter (
219+ const ui.ColorFilter .mode (ui.Color (0xff00ff00 ), ui.BlendMode .color));
220+ // Draw another red circle and apply it to the scene.
221+ // This one should be green since we have the color filter.
222+ final CkPictureRecorder recorder2 = CkPictureRecorder ();
223+ final CkCanvas canvas2 = recorder2.beginRecording (region);
224+
225+ canvas2.drawCircle (
226+ const ui.Offset (425 , 125 ),
227+ 50 ,
228+ CkPaint ()..color = const ui.Color .fromARGB (255 , 255 , 0 , 0 ),
229+ );
230+ final CkPicture greenCircle = recorder2.endRecording ();
231+
232+ builder.addPicture (ui.Offset .zero, greenCircle);
233+
234+ await matchSceneGolden (
235+ 'canvaskit_colorfilter_bounds.png' ,
236+ builder.build (),
237+ region: region,
238+ );
239+ });
240+
241+ test ('ColorFilter works as an ImageFilter' , () async {
242+ final LayerSceneBuilder builder = LayerSceneBuilder ();
243+
244+ builder.pushOffset (0 , 0 );
245+
246+ // Draw a red circle and add it to the scene.
247+ final CkPictureRecorder recorder = CkPictureRecorder ();
248+ final CkCanvas canvas = recorder.beginRecording (region);
249+
250+ canvas.drawCircle (
251+ const ui.Offset (75 , 125 ),
252+ 50 ,
253+ CkPaint ()..color = const ui.Color .fromARGB (255 , 255 , 0 , 0 ),
254+ );
255+ final CkPicture redCircle = recorder.endRecording ();
256+
257+ builder.addPicture (ui.Offset .zero, redCircle);
258+
259+ // Apply a green color filter as an ImageFilter.
260+ builder.pushImageFilter (
261+ const ui.ColorFilter .mode (ui.Color (0xff00ff00 ), ui.BlendMode .color));
262+ // Draw another red circle and apply it to the scene.
263+ // This one should be green since we have the color filter.
264+ final CkPictureRecorder recorder2 = CkPictureRecorder ();
265+ final CkCanvas canvas2 = recorder2.beginRecording (region);
266+
267+ canvas2.drawCircle (
268+ const ui.Offset (425 , 125 ),
269+ 50 ,
270+ CkPaint ()..color = const ui.Color .fromARGB (255 , 255 , 0 , 0 ),
271+ );
272+ final CkPicture greenCircle = recorder2.endRecording ();
273+
274+ builder.addPicture (ui.Offset .zero, greenCircle);
275+
276+ await matchSceneGolden (
277+ 'canvaskit_colorfilter_as_imagefilter.png' ,
278+ builder.build (),
279+ region: region,
280+ );
281+ });
198282 // TODO(hterkelsen): https://github.com/flutter/flutter/issues/71520
199283 }, skip: isSafari || isFirefox);
200284}
0 commit comments