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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 #include "cc/layers/content_layer_client.h" | 8 #include "cc/layers/content_layer_client.h" |
9 #include "cc/layers/picture_image_layer.h" | 9 #include "cc/layers/picture_image_layer.h" |
10 #include "cc/layers/picture_layer.h" | 10 #include "cc/layers/picture_layer.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 ~MaskContentLayerClient() override {} | 32 ~MaskContentLayerClient() override {} |
33 | 33 |
34 bool FillsBoundsCompletely() const override { return false; } | 34 bool FillsBoundsCompletely() const override { return false; } |
35 size_t GetApproximateUnsharedMemoryUsage() const override { return 0; } | 35 size_t GetApproximateUnsharedMemoryUsage() const override { return 0; } |
36 | 36 |
37 gfx::Rect PaintableRegion() override { return gfx::Rect(bounds_); } | 37 gfx::Rect PaintableRegion() override { return gfx::Rect(bounds_); } |
38 | 38 |
39 scoped_refptr<DisplayItemList> PaintContentsToDisplayList( | 39 scoped_refptr<DisplayItemList> PaintContentsToDisplayList( |
40 PaintingControlSetting picture_control) override { | 40 PaintingControlSetting picture_control) override { |
41 SkPictureRecorder recorder; | 41 SkPictureRecorder recorder; |
42 skia::RefPtr<SkCanvas> canvas = skia::SharePtr( | 42 sk_sp<SkCanvas> canvas = sk_ref_sp( |
43 recorder.beginRecording(gfx::RectToSkRect(gfx::Rect(bounds_)))); | 43 recorder.beginRecording(gfx::RectToSkRect(gfx::Rect(bounds_)))); |
44 | 44 |
45 SkPaint paint; | 45 SkPaint paint; |
46 paint.setStyle(SkPaint::kStroke_Style); | 46 paint.setStyle(SkPaint::kStroke_Style); |
47 paint.setStrokeWidth(SkIntToScalar(2)); | 47 paint.setStrokeWidth(SkIntToScalar(2)); |
48 paint.setColor(SK_ColorWHITE); | 48 paint.setColor(SK_ColorWHITE); |
49 | 49 |
50 canvas->clear(SK_ColorTRANSPARENT); | 50 canvas->clear(SK_ColorTRANSPARENT); |
51 gfx::Rect inset_rect(bounds_); | 51 gfx::Rect inset_rect(bounds_); |
52 while (!inset_rect.IsEmpty()) { | 52 while (!inset_rect.IsEmpty()) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 mask->SetBounds(mask_bounds); | 103 mask->SetBounds(mask_bounds); |
104 | 104 |
105 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(200, 200); | 105 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(200, 200); |
106 SkCanvas* canvas = surface->getCanvas(); | 106 SkCanvas* canvas = surface->getCanvas(); |
107 canvas->scale(SkIntToScalar(4), SkIntToScalar(4)); | 107 canvas->scale(SkIntToScalar(4), SkIntToScalar(4)); |
108 MaskContentLayerClient client(mask_bounds); | 108 MaskContentLayerClient client(mask_bounds); |
109 scoped_refptr<DisplayItemList> mask_display_list = | 109 scoped_refptr<DisplayItemList> mask_display_list = |
110 client.PaintContentsToDisplayList( | 110 client.PaintContentsToDisplayList( |
111 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); | 111 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); |
112 mask_display_list->Raster(canvas, nullptr, gfx::Rect(mask_bounds), 1.0f); | 112 mask_display_list->Raster(canvas, nullptr, gfx::Rect(mask_bounds), 1.0f); |
113 skia::RefPtr<const SkImage> image = | 113 mask->SetImage(surface->makeImageSnapshot()); |
114 skia::AdoptRef(surface->newImageSnapshot()); | |
115 mask->SetImage(std::move(image)); | |
116 | 114 |
117 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayerWithBorder( | 115 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayerWithBorder( |
118 gfx::Rect(25, 25, 50, 50), kCSSGreen, 1, SK_ColorBLACK); | 116 gfx::Rect(25, 25, 50, 50), kCSSGreen, 1, SK_ColorBLACK); |
119 green->SetMaskLayer(mask.get()); | 117 green->SetMaskLayer(mask.get()); |
120 background->AddChild(green); | 118 background->AddChild(green); |
121 | 119 |
122 RunPixelResourceTest( | 120 RunPixelResourceTest( |
123 background, base::FilePath(FILE_PATH_LITERAL("image_mask_of_layer.png"))); | 121 background, base::FilePath(FILE_PATH_LITERAL("image_mask_of_layer.png"))); |
124 } | 122 } |
125 | 123 |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 SkColor color, | 298 SkColor color, |
301 bool vertical) | 299 bool vertical) |
302 : bounds_(bounds), color_(color), vertical_(vertical) {} | 300 : bounds_(bounds), color_(color), vertical_(vertical) {} |
303 ~CheckerContentLayerClient() override {} | 301 ~CheckerContentLayerClient() override {} |
304 bool FillsBoundsCompletely() const override { return false; } | 302 bool FillsBoundsCompletely() const override { return false; } |
305 size_t GetApproximateUnsharedMemoryUsage() const override { return 0; } | 303 size_t GetApproximateUnsharedMemoryUsage() const override { return 0; } |
306 gfx::Rect PaintableRegion() override { return gfx::Rect(bounds_); } | 304 gfx::Rect PaintableRegion() override { return gfx::Rect(bounds_); } |
307 scoped_refptr<DisplayItemList> PaintContentsToDisplayList( | 305 scoped_refptr<DisplayItemList> PaintContentsToDisplayList( |
308 PaintingControlSetting picture_control) override { | 306 PaintingControlSetting picture_control) override { |
309 SkPictureRecorder recorder; | 307 SkPictureRecorder recorder; |
310 skia::RefPtr<SkCanvas> canvas = skia::SharePtr( | 308 sk_sp<SkCanvas> canvas = sk_ref_sp( |
311 recorder.beginRecording(gfx::RectToSkRect(gfx::Rect(bounds_)))); | 309 recorder.beginRecording(gfx::RectToSkRect(gfx::Rect(bounds_)))); |
312 | 310 |
313 SkPaint paint; | 311 SkPaint paint; |
314 paint.setStyle(SkPaint::kStroke_Style); | 312 paint.setStyle(SkPaint::kStroke_Style); |
315 paint.setStrokeWidth(SkIntToScalar(4)); | 313 paint.setStrokeWidth(SkIntToScalar(4)); |
316 paint.setColor(color_); | 314 paint.setColor(color_); |
317 canvas->clear(SK_ColorTRANSPARENT); | 315 canvas->clear(SK_ColorTRANSPARENT); |
318 if (vertical_) { | 316 if (vertical_) { |
319 for (int i = 4; i < bounds_.width(); i += 16) { | 317 for (int i = 4; i < bounds_.width(); i += 16) { |
320 canvas->drawLine(i, 0, i, bounds_.height(), paint); | 318 canvas->drawLine(i, 0, i, bounds_.height(), paint); |
(...skipping 23 matching lines...) Expand all Loading... |
344 public: | 342 public: |
345 explicit CircleContentLayerClient(const gfx::Size& bounds) | 343 explicit CircleContentLayerClient(const gfx::Size& bounds) |
346 : bounds_(bounds) {} | 344 : bounds_(bounds) {} |
347 ~CircleContentLayerClient() override {} | 345 ~CircleContentLayerClient() override {} |
348 bool FillsBoundsCompletely() const override { return false; } | 346 bool FillsBoundsCompletely() const override { return false; } |
349 size_t GetApproximateUnsharedMemoryUsage() const override { return 0; } | 347 size_t GetApproximateUnsharedMemoryUsage() const override { return 0; } |
350 gfx::Rect PaintableRegion() override { return gfx::Rect(bounds_); } | 348 gfx::Rect PaintableRegion() override { return gfx::Rect(bounds_); } |
351 scoped_refptr<DisplayItemList> PaintContentsToDisplayList( | 349 scoped_refptr<DisplayItemList> PaintContentsToDisplayList( |
352 PaintingControlSetting picture_control) override { | 350 PaintingControlSetting picture_control) override { |
353 SkPictureRecorder recorder; | 351 SkPictureRecorder recorder; |
354 skia::RefPtr<SkCanvas> canvas = skia::SharePtr( | 352 sk_sp<SkCanvas> canvas = sk_ref_sp( |
355 recorder.beginRecording(gfx::RectToSkRect(gfx::Rect(bounds_)))); | 353 recorder.beginRecording(gfx::RectToSkRect(gfx::Rect(bounds_)))); |
356 | 354 |
357 SkPaint paint; | 355 SkPaint paint; |
358 paint.setStyle(SkPaint::kFill_Style); | 356 paint.setStyle(SkPaint::kFill_Style); |
359 paint.setColor(SK_ColorWHITE); | 357 paint.setColor(SK_ColorWHITE); |
360 canvas->clear(SK_ColorTRANSPARENT); | 358 canvas->clear(SK_ColorTRANSPARENT); |
361 canvas->drawCircle(bounds_.width() / 2, | 359 canvas->drawCircle(bounds_.width() / 2, |
362 bounds_.height() / 2, | 360 bounds_.height() / 2, |
363 bounds_.width() / 4, | 361 bounds_.width() / 4, |
364 paint); | 362 paint); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 | 482 |
485 RunPixelResourceTest(background, | 483 RunPixelResourceTest(background, |
486 base::FilePath( | 484 base::FilePath( |
487 FILE_PATH_LITERAL("mask_of_layer_with_blend.png"))); | 485 FILE_PATH_LITERAL("mask_of_layer_with_blend.png"))); |
488 } | 486 } |
489 | 487 |
490 } // namespace | 488 } // namespace |
491 } // namespace cc | 489 } // namespace cc |
492 | 490 |
493 #endif // !defined(OS_ANDROID) | 491 #endif // !defined(OS_ANDROID) |
OLD | NEW |