OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "build/build_config.h" | 5 #include "build/build_config.h" |
6 #include "cc/layers/content_layer_client.h" | 6 #include "cc/layers/content_layer_client.h" |
7 #include "cc/layers/picture_image_layer.h" | 7 #include "cc/layers/picture_image_layer.h" |
8 #include "cc/layers/picture_layer.h" | 8 #include "cc/layers/picture_layer.h" |
9 #include "cc/layers/solid_color_layer.h" | 9 #include "cc/layers/solid_color_layer.h" |
10 #include "cc/test/layer_tree_pixel_resource_test.h" | 10 #include "cc/test/layer_tree_pixel_resource_test.h" |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
275 replica->SetMaskLayer(mask.get()); | 275 replica->SetMaskLayer(mask.get()); |
276 green->SetReplicaLayer(replica.get()); | 276 green->SetReplicaLayer(replica.get()); |
277 | 277 |
278 RunPixelResourceTest(background, | 278 RunPixelResourceTest(background, |
279 base::FilePath(FILE_PATH_LITERAL( | 279 base::FilePath(FILE_PATH_LITERAL( |
280 "mask_of_replica_of_clipped_layer.png"))); | 280 "mask_of_replica_of_clipped_layer.png"))); |
281 } | 281 } |
282 | 282 |
283 #endif // !defined(OS_WIN) | 283 #endif // !defined(OS_WIN) |
284 | 284 |
285 class CheckerContentLayerClient : public ContentLayerClient { | |
286 public: | |
287 CheckerContentLayerClient(const gfx::Size& bounds, | |
288 SkColor color, | |
289 bool vertical) | |
290 : bounds_(bounds), color_(color), vertical_(vertical) {} | |
291 ~CheckerContentLayerClient() override {} | |
292 bool FillsBoundsCompletely() const override { return false; } | |
293 void PaintContents(SkCanvas* canvas, | |
294 const gfx::Rect& rect, | |
295 PaintingControlSetting picture_control) override { | |
296 SkPaint paint; | |
297 paint.setStyle(SkPaint::kStroke_Style); | |
298 paint.setStrokeWidth(SkIntToScalar(3)); | |
299 paint.setColor(color_); | |
300 canvas->clear(SK_ColorTRANSPARENT); | |
301 if (vertical_) { | |
302 for (int i = 0; i < bounds_.width(); i += 11) { | |
303 canvas->drawLine(i, 0, i, bounds_.height(), paint); | |
304 } | |
305 } else { | |
306 for (int i = 0; i < bounds_.height(); i += 11) { | |
307 canvas->drawLine(0, i, bounds_.width(), i, paint); | |
308 } | |
309 } | |
310 } | |
311 scoped_refptr<DisplayItemList> PaintContentsToDisplayList( | |
312 const gfx::Rect& clip, | |
313 PaintingControlSetting picture_control) override { | |
314 NOTIMPLEMENTED(); | |
315 return DisplayItemList::Create(); | |
316 } | |
317 | |
318 private: | |
319 gfx::Size bounds_; | |
320 SkColor color_; | |
321 bool vertical_; | |
322 }; | |
323 | |
324 class CircleContentLayerClient : public ContentLayerClient { | |
325 public: | |
326 explicit CircleContentLayerClient(const gfx::Size& bounds) | |
327 : bounds_(bounds) {} | |
328 ~CircleContentLayerClient() override {} | |
329 bool FillsBoundsCompletely() const override { return false; } | |
330 void PaintContents(SkCanvas* canvas, | |
331 const gfx::Rect& rect, | |
332 PaintingControlSetting picture_control) override { | |
333 SkPaint paint; | |
334 paint.setStyle(SkPaint::kFill_Style); | |
335 paint.setColor(SK_ColorWHITE); | |
336 canvas->clear(SK_ColorTRANSPARENT); | |
337 canvas->drawCircle(bounds_.width() / 2, | |
338 bounds_.height() / 2, | |
339 bounds_.width() / 4, | |
340 paint); | |
341 } | |
342 scoped_refptr<DisplayItemList> PaintContentsToDisplayList( | |
343 const gfx::Rect& clip, | |
344 PaintingControlSetting picture_control) override { | |
345 NOTIMPLEMENTED(); | |
346 return DisplayItemList::Create(); | |
347 } | |
348 | |
349 private: | |
350 gfx::Size bounds_; | |
351 }; | |
352 | |
353 using LayerTreeHostMasksForBackgroundFiltersPixelTest = | |
354 ParameterizedPixelResourceTest; | |
355 | |
356 INSTANTIATE_TEST_CASE_P( | |
357 PixelResourceTest, | |
358 LayerTreeHostMasksForBackgroundFiltersPixelTest, | |
359 ::testing::Values( | |
360 // SOFTWARE, Background filters aren't implemented in software | |
361 // GL_GPU_RASTER_2D_DRAW, Gpu rasterisation has errors in accuracy | |
enne (OOO)
2015/03/04 19:58:44
Can you use a fuzzy pixel comparator? How inaccura
| |
362 GL_ONE_COPY_2D_STAGING_2D_DRAW, | |
363 GL_ONE_COPY_RECT_STAGING_2D_DRAW, | |
364 GL_ONE_COPY_EXTERNAL_STAGING_2D_DRAW, | |
365 GL_ZERO_COPY_2D_DRAW, | |
366 GL_ZERO_COPY_RECT_DRAW, | |
367 GL_ZERO_COPY_EXTERNAL_DRAW, | |
368 GL_ASYNC_UPLOAD_2D_DRAW)); | |
369 | |
370 TEST_P(LayerTreeHostMasksForBackgroundFiltersPixelTest, | |
371 MaskOfLayerWithBackgroundFilter) { | |
372 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( | |
373 gfx::Rect(200, 200), SK_ColorWHITE); | |
374 | |
375 gfx::Size picture_bounds(200, 200); | |
376 CheckerContentLayerClient picture_client(picture_bounds, SK_ColorGREEN, true); | |
377 scoped_refptr<PictureLayer> picture = PictureLayer::Create(&picture_client); | |
378 picture->SetBounds(picture_bounds); | |
379 picture->SetIsDrawable(true); | |
380 | |
381 scoped_refptr<SolidColorLayer> blur = CreateSolidColorLayer( | |
382 gfx::Rect(200, 200), SK_ColorTRANSPARENT); | |
383 background->AddChild(picture); | |
384 background->AddChild(blur); | |
385 | |
386 FilterOperations filters; | |
387 filters.Append(FilterOperation::CreateBlurFilter(2.f)); | |
388 blur->SetBackgroundFilters(filters); | |
389 | |
390 gfx::Size mask_bounds(200, 200); | |
391 CircleContentLayerClient mask_client(mask_bounds); | |
392 scoped_refptr<PictureLayer> mask = PictureLayer::Create(&mask_client); | |
393 mask->SetBounds(mask_bounds); | |
394 mask->SetIsDrawable(true); | |
395 mask->SetIsMask(true); | |
396 blur->SetMaskLayer(mask.get()); | |
397 | |
398 RunPixelResourceTest(background, | |
399 base::FilePath( | |
400 FILE_PATH_LITERAL("mask_of_background_filter.png"))); | |
401 } | |
402 | |
403 TEST_P(LayerTreeHostMasksForBackgroundFiltersPixelTest, | |
404 MaskOfLayerWithBlend) { | |
405 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( | |
406 gfx::Rect(200, 200), SK_ColorWHITE); | |
407 | |
408 gfx::Size picture_bounds(200, 200); | |
409 CheckerContentLayerClient picture_client_vertical( | |
410 picture_bounds, SK_ColorGREEN, true); | |
411 scoped_refptr<PictureLayer> picture_vertical = | |
412 PictureLayer::Create(&picture_client_vertical); | |
413 picture_vertical->SetBounds(picture_bounds); | |
414 picture_vertical->SetIsDrawable(true); | |
415 | |
416 CheckerContentLayerClient picture_client_horizontal( | |
417 picture_bounds, SK_ColorMAGENTA, false); | |
418 scoped_refptr<PictureLayer> picture_horizontal = | |
419 PictureLayer::Create(&picture_client_horizontal); | |
420 picture_horizontal->SetBounds(picture_bounds); | |
421 picture_horizontal->SetIsDrawable(true); | |
422 picture_horizontal->SetContentsOpaque(false); | |
423 picture_horizontal->SetBlendMode(SkXfermode::kMultiply_Mode); | |
424 | |
425 background->AddChild(picture_vertical); | |
426 background->AddChild(picture_horizontal); | |
427 | |
428 gfx::Size mask_bounds(200, 200); | |
429 CircleContentLayerClient mask_client(mask_bounds); | |
430 scoped_refptr<PictureLayer> mask = PictureLayer::Create(&mask_client); | |
431 mask->SetBounds(mask_bounds); | |
432 mask->SetIsDrawable(true); | |
433 mask->SetIsMask(true); | |
434 picture_horizontal->SetMaskLayer(mask.get()); | |
435 | |
436 RunPixelResourceTest(background, | |
437 base::FilePath( | |
438 FILE_PATH_LITERAL("mask_of_layer_with_blend.png"))); | |
439 } | |
440 | |
285 } // namespace | 441 } // namespace |
286 } // namespace cc | 442 } // namespace cc |
287 | 443 |
288 #endif // OS_ANDROID | 444 #endif // OS_ANDROID |
OLD | NEW |