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 sk_sp<const SkImage> image = surface->makeImageSnapshot(); |
114 skia::AdoptRef(surface->newImageSnapshot()); | 114 mask->SetImage(skia::SharePtr(image)); |
danakj
2016/04/14 19:37:33
move image
| |
115 mask->SetImage(std::move(image)); | |
116 | 115 |
117 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayerWithBorder( | 116 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayerWithBorder( |
118 gfx::Rect(25, 25, 50, 50), kCSSGreen, 1, SK_ColorBLACK); | 117 gfx::Rect(25, 25, 50, 50), kCSSGreen, 1, SK_ColorBLACK); |
119 green->SetMaskLayer(mask.get()); | 118 green->SetMaskLayer(mask.get()); |
120 background->AddChild(green); | 119 background->AddChild(green); |
121 | 120 |
122 RunPixelResourceTest( | 121 RunPixelResourceTest( |
123 background, base::FilePath(FILE_PATH_LITERAL("image_mask_of_layer.png"))); | 122 background, base::FilePath(FILE_PATH_LITERAL("image_mask_of_layer.png"))); |
124 } | 123 } |
125 | 124 |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
300 SkColor color, | 299 SkColor color, |
301 bool vertical) | 300 bool vertical) |
302 : bounds_(bounds), color_(color), vertical_(vertical) {} | 301 : bounds_(bounds), color_(color), vertical_(vertical) {} |
303 ~CheckerContentLayerClient() override {} | 302 ~CheckerContentLayerClient() override {} |
304 bool FillsBoundsCompletely() const override { return false; } | 303 bool FillsBoundsCompletely() const override { return false; } |
305 size_t GetApproximateUnsharedMemoryUsage() const override { return 0; } | 304 size_t GetApproximateUnsharedMemoryUsage() const override { return 0; } |
306 gfx::Rect PaintableRegion() override { return gfx::Rect(bounds_); } | 305 gfx::Rect PaintableRegion() override { return gfx::Rect(bounds_); } |
307 scoped_refptr<DisplayItemList> PaintContentsToDisplayList( | 306 scoped_refptr<DisplayItemList> PaintContentsToDisplayList( |
308 PaintingControlSetting picture_control) override { | 307 PaintingControlSetting picture_control) override { |
309 SkPictureRecorder recorder; | 308 SkPictureRecorder recorder; |
310 skia::RefPtr<SkCanvas> canvas = skia::SharePtr( | 309 sk_sp<SkCanvas> canvas = sk_ref_sp( |
311 recorder.beginRecording(gfx::RectToSkRect(gfx::Rect(bounds_)))); | 310 recorder.beginRecording(gfx::RectToSkRect(gfx::Rect(bounds_)))); |
312 | 311 |
313 SkPaint paint; | 312 SkPaint paint; |
314 paint.setStyle(SkPaint::kStroke_Style); | 313 paint.setStyle(SkPaint::kStroke_Style); |
315 paint.setStrokeWidth(SkIntToScalar(4)); | 314 paint.setStrokeWidth(SkIntToScalar(4)); |
316 paint.setColor(color_); | 315 paint.setColor(color_); |
317 canvas->clear(SK_ColorTRANSPARENT); | 316 canvas->clear(SK_ColorTRANSPARENT); |
318 if (vertical_) { | 317 if (vertical_) { |
319 for (int i = 4; i < bounds_.width(); i += 16) { | 318 for (int i = 4; i < bounds_.width(); i += 16) { |
320 canvas->drawLine(i, 0, i, bounds_.height(), paint); | 319 canvas->drawLine(i, 0, i, bounds_.height(), paint); |
(...skipping 23 matching lines...) Expand all Loading... | |
344 public: | 343 public: |
345 explicit CircleContentLayerClient(const gfx::Size& bounds) | 344 explicit CircleContentLayerClient(const gfx::Size& bounds) |
346 : bounds_(bounds) {} | 345 : bounds_(bounds) {} |
347 ~CircleContentLayerClient() override {} | 346 ~CircleContentLayerClient() override {} |
348 bool FillsBoundsCompletely() const override { return false; } | 347 bool FillsBoundsCompletely() const override { return false; } |
349 size_t GetApproximateUnsharedMemoryUsage() const override { return 0; } | 348 size_t GetApproximateUnsharedMemoryUsage() const override { return 0; } |
350 gfx::Rect PaintableRegion() override { return gfx::Rect(bounds_); } | 349 gfx::Rect PaintableRegion() override { return gfx::Rect(bounds_); } |
351 scoped_refptr<DisplayItemList> PaintContentsToDisplayList( | 350 scoped_refptr<DisplayItemList> PaintContentsToDisplayList( |
352 PaintingControlSetting picture_control) override { | 351 PaintingControlSetting picture_control) override { |
353 SkPictureRecorder recorder; | 352 SkPictureRecorder recorder; |
354 skia::RefPtr<SkCanvas> canvas = skia::SharePtr( | 353 sk_sp<SkCanvas> canvas = sk_ref_sp( |
355 recorder.beginRecording(gfx::RectToSkRect(gfx::Rect(bounds_)))); | 354 recorder.beginRecording(gfx::RectToSkRect(gfx::Rect(bounds_)))); |
356 | 355 |
357 SkPaint paint; | 356 SkPaint paint; |
358 paint.setStyle(SkPaint::kFill_Style); | 357 paint.setStyle(SkPaint::kFill_Style); |
359 paint.setColor(SK_ColorWHITE); | 358 paint.setColor(SK_ColorWHITE); |
360 canvas->clear(SK_ColorTRANSPARENT); | 359 canvas->clear(SK_ColorTRANSPARENT); |
361 canvas->drawCircle(bounds_.width() / 2, | 360 canvas->drawCircle(bounds_.width() / 2, |
362 bounds_.height() / 2, | 361 bounds_.height() / 2, |
363 bounds_.width() / 4, | 362 bounds_.width() / 4, |
364 paint); | 363 paint); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
484 | 483 |
485 RunPixelResourceTest(background, | 484 RunPixelResourceTest(background, |
486 base::FilePath( | 485 base::FilePath( |
487 FILE_PATH_LITERAL("mask_of_layer_with_blend.png"))); | 486 FILE_PATH_LITERAL("mask_of_layer_with_blend.png"))); |
488 } | 487 } |
489 | 488 |
490 } // namespace | 489 } // namespace |
491 } // namespace cc | 490 } // namespace cc |
492 | 491 |
493 #endif // !defined(OS_ANDROID) | 492 #endif // !defined(OS_ANDROID) |
OLD | NEW |