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 explicit CheckerContentLayerClient(const gfx::Size& bounds) |
| 288 : bounds_(bounds) {} |
| 289 ~CheckerContentLayerClient() override {} |
| 290 bool FillsBoundsCompletely() const override { return false; } |
| 291 void PaintContents(SkCanvas* canvas, |
| 292 const gfx::Rect& rect, |
| 293 PaintingControlSetting picture_control) override { |
| 294 SkPaint paint; |
| 295 paint.setStyle(SkPaint::kStroke_Style); |
| 296 paint.setStrokeWidth(SkIntToScalar(3)); |
| 297 paint.setColor(SK_ColorGREEN); |
| 298 canvas->clear(SK_ColorTRANSPARENT); |
| 299 for (int i = 0; i < bounds_.width(); i += 11) { |
| 300 canvas->drawLine(i, 0, i, bounds_.height(), paint); |
| 301 } |
| 302 } |
| 303 scoped_refptr<DisplayItemList> PaintContentsToDisplayList( |
| 304 const gfx::Rect& clip, |
| 305 PaintingControlSetting picture_control) override { |
| 306 NOTIMPLEMENTED(); |
| 307 return DisplayItemList::Create(); |
| 308 } |
| 309 |
| 310 private: |
| 311 gfx::Size bounds_; |
| 312 }; |
| 313 |
| 314 class CircleContentLayerClient : public ContentLayerClient { |
| 315 public: |
| 316 explicit CircleContentLayerClient(const gfx::Size& bounds) |
| 317 : bounds_(bounds) {} |
| 318 ~CircleContentLayerClient() override {} |
| 319 bool FillsBoundsCompletely() const override { return false; } |
| 320 void PaintContents(SkCanvas* canvas, |
| 321 const gfx::Rect& rect, |
| 322 PaintingControlSetting picture_control) override { |
| 323 SkPaint paint; |
| 324 paint.setStyle(SkPaint::kFill_Style); |
| 325 paint.setColor(SK_ColorWHITE); |
| 326 canvas->clear(SK_ColorTRANSPARENT); |
| 327 canvas->drawCircle(bounds_.width() / 2, |
| 328 bounds_.height() / 2, |
| 329 bounds_.width() / 4, |
| 330 paint); |
| 331 } |
| 332 scoped_refptr<DisplayItemList> PaintContentsToDisplayList( |
| 333 const gfx::Rect& clip, |
| 334 PaintingControlSetting picture_control) override { |
| 335 NOTIMPLEMENTED(); |
| 336 return DisplayItemList::Create(); |
| 337 } |
| 338 |
| 339 private: |
| 340 gfx::Size bounds_; |
| 341 }; |
| 342 |
| 343 using LayerTreeHostMasksForBackgroundFiltersPixelTest = |
| 344 ParameterizedPixelResourceTest; |
| 345 |
| 346 INSTANTIATE_TEST_CASE_P( |
| 347 PixelResourceTest, |
| 348 LayerTreeHostMasksForBackgroundFiltersPixelTest, |
| 349 ::testing::Values( |
| 350 // SOFTWARE, Background filters aren't implemented in software |
| 351 // GL_GPU_RASTER_2D_DRAW, Gpu rasterisation has errors in accuracy |
| 352 GL_ONE_COPY_2D_STAGING_2D_DRAW, |
| 353 GL_ONE_COPY_RECT_STAGING_2D_DRAW, |
| 354 GL_ONE_COPY_EXTERNAL_STAGING_2D_DRAW, |
| 355 GL_ZERO_COPY_2D_DRAW, |
| 356 GL_ZERO_COPY_RECT_DRAW, |
| 357 GL_ZERO_COPY_EXTERNAL_DRAW, |
| 358 GL_ASYNC_UPLOAD_2D_DRAW)); |
| 359 |
| 360 TEST_P(LayerTreeHostMasksForBackgroundFiltersPixelTest, |
| 361 MaskOfLayerWithBackgroundFilter) { |
| 362 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( |
| 363 gfx::Rect(200, 200), SK_ColorWHITE); |
| 364 |
| 365 gfx::Size picture_bounds(200, 200); |
| 366 CheckerContentLayerClient picture_client(picture_bounds); |
| 367 scoped_refptr<PictureLayer> picture = PictureLayer::Create(&picture_client); |
| 368 picture->SetBounds(picture_bounds); |
| 369 picture->SetIsDrawable(true); |
| 370 |
| 371 scoped_refptr<SolidColorLayer> blur = CreateSolidColorLayer( |
| 372 gfx::Rect(200, 200), SK_ColorTRANSPARENT); |
| 373 background->AddChild(picture); |
| 374 background->AddChild(blur); |
| 375 |
| 376 FilterOperations filters; |
| 377 filters.Append(FilterOperation::CreateBlurFilter(2.f)); |
| 378 blur->SetBackgroundFilters(filters); |
| 379 |
| 380 gfx::Size mask_bounds(200, 200); |
| 381 CircleContentLayerClient mask_client(mask_bounds); |
| 382 scoped_refptr<PictureLayer> mask = PictureLayer::Create(&mask_client); |
| 383 mask->SetBounds(mask_bounds); |
| 384 mask->SetIsDrawable(true); |
| 385 mask->SetIsMask(true); |
| 386 blur->SetMaskLayer(mask.get()); |
| 387 |
| 388 RunPixelResourceTest(background, |
| 389 base::FilePath( |
| 390 FILE_PATH_LITERAL("mask_of_background_filter.png"))); |
| 391 } |
| 392 |
285 } // namespace | 393 } // namespace |
286 } // namespace cc | 394 } // namespace cc |
287 | 395 |
288 #endif // OS_ANDROID | 396 #endif // OS_ANDROID |
OLD | NEW |