| 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/playback/display_item_list_settings.h" | 10 #include "cc/playback/display_item_list_settings.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 INSTANTIATE_PIXEL_RESOURCE_TEST_CASE_P(LayerTreeHostMasksPixelTest); | 25 INSTANTIATE_PIXEL_RESOURCE_TEST_CASE_P(LayerTreeHostMasksPixelTest); |
| 26 | 26 |
| 27 class MaskContentLayerClient : public ContentLayerClient { | 27 class MaskContentLayerClient : public ContentLayerClient { |
| 28 public: | 28 public: |
| 29 explicit MaskContentLayerClient(const gfx::Size& bounds) : bounds_(bounds) {} | 29 explicit MaskContentLayerClient(const gfx::Size& bounds) : bounds_(bounds) {} |
| 30 ~MaskContentLayerClient() override {} | 30 ~MaskContentLayerClient() override {} |
| 31 | 31 |
| 32 bool FillsBoundsCompletely() const override { return false; } | 32 bool FillsBoundsCompletely() const override { return false; } |
| 33 size_t GetApproximateUnsharedMemoryUsage() const override { return 0; } | 33 size_t GetApproximateUnsharedMemoryUsage() const override { return 0; } |
| 34 | 34 |
| 35 // TODO(pdr): Remove PaintContents as all calls should go through | |
| 36 // PaintContentsToDisplayList. | |
| 37 void PaintContents(SkCanvas* canvas, | |
| 38 const gfx::Rect& rect, | |
| 39 PaintingControlSetting picture_control) override { | |
| 40 scoped_refptr<DisplayItemList> contents = | |
| 41 PaintContentsToDisplayList(rect, picture_control); | |
| 42 contents->Raster(canvas, nullptr, rect, 1.0f); | |
| 43 } | |
| 44 | |
| 45 scoped_refptr<DisplayItemList> PaintContentsToDisplayList( | 35 scoped_refptr<DisplayItemList> PaintContentsToDisplayList( |
| 46 const gfx::Rect& clip, | 36 const gfx::Rect& clip, |
| 47 PaintingControlSetting picture_control) override { | 37 PaintingControlSetting picture_control) override { |
| 48 SkPictureRecorder recorder; | 38 SkPictureRecorder recorder; |
| 49 skia::RefPtr<SkCanvas> canvas = skia::SharePtr( | 39 skia::RefPtr<SkCanvas> canvas = skia::SharePtr( |
| 50 recorder.beginRecording(gfx::RectToSkRect(gfx::Rect(bounds_)))); | 40 recorder.beginRecording(gfx::RectToSkRect(gfx::Rect(bounds_)))); |
| 51 | 41 |
| 52 SkPaint paint; | 42 SkPaint paint; |
| 53 paint.setStyle(SkPaint::kStroke_Style); | 43 paint.setStyle(SkPaint::kStroke_Style); |
| 54 paint.setStrokeWidth(SkIntToScalar(2)); | 44 paint.setStrokeWidth(SkIntToScalar(2)); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 PictureImageLayer::Create(layer_settings()); | 102 PictureImageLayer::Create(layer_settings()); |
| 113 mask->SetIsDrawable(true); | 103 mask->SetIsDrawable(true); |
| 114 mask->SetIsMask(true); | 104 mask->SetIsMask(true); |
| 115 mask->SetBounds(mask_bounds); | 105 mask->SetBounds(mask_bounds); |
| 116 | 106 |
| 117 skia::RefPtr<SkSurface> surface = | 107 skia::RefPtr<SkSurface> surface = |
| 118 skia::AdoptRef(SkSurface::NewRasterN32Premul(200, 200)); | 108 skia::AdoptRef(SkSurface::NewRasterN32Premul(200, 200)); |
| 119 SkCanvas* canvas = surface->getCanvas(); | 109 SkCanvas* canvas = surface->getCanvas(); |
| 120 canvas->scale(SkIntToScalar(4), SkIntToScalar(4)); | 110 canvas->scale(SkIntToScalar(4), SkIntToScalar(4)); |
| 121 MaskContentLayerClient client(mask_bounds); | 111 MaskContentLayerClient client(mask_bounds); |
| 122 client.PaintContents(canvas, gfx::Rect(mask_bounds), | 112 scoped_refptr<DisplayItemList> mask_display_list = |
| 123 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); | 113 client.PaintContentsToDisplayList( |
| 114 gfx::Rect(mask_bounds), ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); |
| 115 mask_display_list->Raster(canvas, nullptr, gfx::Rect(mask_bounds), 1.0f); |
| 124 skia::RefPtr<const SkImage> image = | 116 skia::RefPtr<const SkImage> image = |
| 125 skia::AdoptRef(surface->newImageSnapshot()); | 117 skia::AdoptRef(surface->newImageSnapshot()); |
| 126 mask->SetImage(image.Pass()); | 118 mask->SetImage(image.Pass()); |
| 127 | 119 |
| 128 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayerWithBorder( | 120 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayerWithBorder( |
| 129 gfx::Rect(25, 25, 50, 50), kCSSGreen, 1, SK_ColorBLACK); | 121 gfx::Rect(25, 25, 50, 50), kCSSGreen, 1, SK_ColorBLACK); |
| 130 green->SetMaskLayer(mask.get()); | 122 green->SetMaskLayer(mask.get()); |
| 131 background->AddChild(green); | 123 background->AddChild(green); |
| 132 | 124 |
| 133 RunPixelResourceTest( | 125 RunPixelResourceTest( |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 | 304 |
| 313 class CheckerContentLayerClient : public ContentLayerClient { | 305 class CheckerContentLayerClient : public ContentLayerClient { |
| 314 public: | 306 public: |
| 315 CheckerContentLayerClient(const gfx::Size& bounds, | 307 CheckerContentLayerClient(const gfx::Size& bounds, |
| 316 SkColor color, | 308 SkColor color, |
| 317 bool vertical) | 309 bool vertical) |
| 318 : bounds_(bounds), color_(color), vertical_(vertical) {} | 310 : bounds_(bounds), color_(color), vertical_(vertical) {} |
| 319 ~CheckerContentLayerClient() override {} | 311 ~CheckerContentLayerClient() override {} |
| 320 bool FillsBoundsCompletely() const override { return false; } | 312 bool FillsBoundsCompletely() const override { return false; } |
| 321 size_t GetApproximateUnsharedMemoryUsage() const override { return 0; } | 313 size_t GetApproximateUnsharedMemoryUsage() const override { return 0; } |
| 322 // TODO(pdr): Remove PaintContents as all calls should go through | |
| 323 // PaintContentsToDisplayList. | |
| 324 void PaintContents(SkCanvas* canvas, | |
| 325 const gfx::Rect& rect, | |
| 326 PaintingControlSetting picture_control) override { | |
| 327 scoped_refptr<DisplayItemList> contents = | |
| 328 PaintContentsToDisplayList(rect, picture_control); | |
| 329 contents->Raster(canvas, nullptr, rect, 1.0f); | |
| 330 } | |
| 331 scoped_refptr<DisplayItemList> PaintContentsToDisplayList( | 314 scoped_refptr<DisplayItemList> PaintContentsToDisplayList( |
| 332 const gfx::Rect& clip, | 315 const gfx::Rect& clip, |
| 333 PaintingControlSetting picture_control) override { | 316 PaintingControlSetting picture_control) override { |
| 334 SkPictureRecorder recorder; | 317 SkPictureRecorder recorder; |
| 335 skia::RefPtr<SkCanvas> canvas = skia::SharePtr( | 318 skia::RefPtr<SkCanvas> canvas = skia::SharePtr( |
| 336 recorder.beginRecording(gfx::RectToSkRect(gfx::Rect(bounds_)))); | 319 recorder.beginRecording(gfx::RectToSkRect(gfx::Rect(bounds_)))); |
| 337 | 320 |
| 338 SkPaint paint; | 321 SkPaint paint; |
| 339 paint.setStyle(SkPaint::kStroke_Style); | 322 paint.setStyle(SkPaint::kStroke_Style); |
| 340 paint.setStrokeWidth(SkIntToScalar(4)); | 323 paint.setStrokeWidth(SkIntToScalar(4)); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 368 bool vertical_; | 351 bool vertical_; |
| 369 }; | 352 }; |
| 370 | 353 |
| 371 class CircleContentLayerClient : public ContentLayerClient { | 354 class CircleContentLayerClient : public ContentLayerClient { |
| 372 public: | 355 public: |
| 373 explicit CircleContentLayerClient(const gfx::Size& bounds) | 356 explicit CircleContentLayerClient(const gfx::Size& bounds) |
| 374 : bounds_(bounds) {} | 357 : bounds_(bounds) {} |
| 375 ~CircleContentLayerClient() override {} | 358 ~CircleContentLayerClient() override {} |
| 376 bool FillsBoundsCompletely() const override { return false; } | 359 bool FillsBoundsCompletely() const override { return false; } |
| 377 size_t GetApproximateUnsharedMemoryUsage() const override { return 0; } | 360 size_t GetApproximateUnsharedMemoryUsage() const override { return 0; } |
| 378 // TODO(pdr): Remove PaintContents as all calls should go through | |
| 379 // PaintContentsToDisplayList. | |
| 380 void PaintContents(SkCanvas* canvas, | |
| 381 const gfx::Rect& rect, | |
| 382 PaintingControlSetting picture_control) override { | |
| 383 scoped_refptr<DisplayItemList> contents = | |
| 384 PaintContentsToDisplayList(rect, picture_control); | |
| 385 contents->Raster(canvas, nullptr, rect, 1.0f); | |
| 386 } | |
| 387 scoped_refptr<DisplayItemList> PaintContentsToDisplayList( | 361 scoped_refptr<DisplayItemList> PaintContentsToDisplayList( |
| 388 const gfx::Rect& clip, | 362 const gfx::Rect& clip, |
| 389 PaintingControlSetting picture_control) override { | 363 PaintingControlSetting picture_control) override { |
| 390 SkPictureRecorder recorder; | 364 SkPictureRecorder recorder; |
| 391 skia::RefPtr<SkCanvas> canvas = skia::SharePtr( | 365 skia::RefPtr<SkCanvas> canvas = skia::SharePtr( |
| 392 recorder.beginRecording(gfx::RectToSkRect(gfx::Rect(bounds_)))); | 366 recorder.beginRecording(gfx::RectToSkRect(gfx::Rect(bounds_)))); |
| 393 | 367 |
| 394 SkPaint paint; | 368 SkPaint paint; |
| 395 paint.setStyle(SkPaint::kFill_Style); | 369 paint.setStyle(SkPaint::kFill_Style); |
| 396 paint.setColor(SK_ColorWHITE); | 370 paint.setColor(SK_ColorWHITE); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 | 500 |
| 527 RunPixelResourceTest(background, | 501 RunPixelResourceTest(background, |
| 528 base::FilePath( | 502 base::FilePath( |
| 529 FILE_PATH_LITERAL("mask_of_layer_with_blend.png"))); | 503 FILE_PATH_LITERAL("mask_of_layer_with_blend.png"))); |
| 530 } | 504 } |
| 531 | 505 |
| 532 } // namespace | 506 } // namespace |
| 533 } // namespace cc | 507 } // namespace cc |
| 534 | 508 |
| 535 #endif // !defined(OS_ANDROID) | 509 #endif // !defined(OS_ANDROID) |
| OLD | NEW |