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" |
11 #include "cc/layers/solid_color_layer.h" | 11 #include "cc/layers/solid_color_layer.h" |
12 #include "cc/paint/paint_flags.h" | |
13 #include "cc/paint/paint_recorder.h" | |
14 #include "cc/paint/paint_surface.h" | |
12 #include "cc/playback/display_item_list_settings.h" | 15 #include "cc/playback/display_item_list_settings.h" |
13 #include "cc/playback/drawing_display_item.h" | 16 #include "cc/playback/drawing_display_item.h" |
14 #include "cc/test/layer_tree_pixel_resource_test.h" | 17 #include "cc/test/layer_tree_pixel_resource_test.h" |
15 #include "cc/test/pixel_comparator.h" | 18 #include "cc/test/pixel_comparator.h" |
16 #include "cc/test/solid_color_content_layer_client.h" | 19 #include "cc/test/solid_color_content_layer_client.h" |
17 #include "third_party/skia/include/core/SkImage.h" | 20 #include "third_party/skia/include/core/SkImage.h" |
18 #include "third_party/skia/include/core/SkPictureRecorder.h" | |
19 #include "third_party/skia/include/core/SkSurface.h" | |
20 | 21 |
21 #if !defined(OS_ANDROID) | 22 #if !defined(OS_ANDROID) |
22 | 23 |
23 namespace cc { | 24 namespace cc { |
24 namespace { | 25 namespace { |
25 | 26 |
26 typedef ParameterizedPixelResourceTest LayerTreeHostMasksPixelTest; | 27 typedef ParameterizedPixelResourceTest LayerTreeHostMasksPixelTest; |
27 | 28 |
28 INSTANTIATE_PIXEL_RESOURCE_TEST_CASE_P(LayerTreeHostMasksPixelTest); | 29 INSTANTIATE_PIXEL_RESOURCE_TEST_CASE_P(LayerTreeHostMasksPixelTest); |
29 | 30 |
30 class MaskContentLayerClient : public ContentLayerClient { | 31 class MaskContentLayerClient : public ContentLayerClient { |
31 public: | 32 public: |
32 explicit MaskContentLayerClient(const gfx::Size& bounds) : bounds_(bounds) {} | 33 explicit MaskContentLayerClient(const gfx::Size& bounds) : bounds_(bounds) {} |
33 ~MaskContentLayerClient() override {} | 34 ~MaskContentLayerClient() override {} |
34 | 35 |
35 bool FillsBoundsCompletely() const override { return false; } | 36 bool FillsBoundsCompletely() const override { return false; } |
36 size_t GetApproximateUnsharedMemoryUsage() const override { return 0; } | 37 size_t GetApproximateUnsharedMemoryUsage() const override { return 0; } |
37 | 38 |
38 gfx::Rect PaintableRegion() override { return gfx::Rect(bounds_); } | 39 gfx::Rect PaintableRegion() override { return gfx::Rect(bounds_); } |
39 | 40 |
40 scoped_refptr<DisplayItemList> PaintContentsToDisplayList( | 41 scoped_refptr<DisplayItemList> PaintContentsToDisplayList( |
41 PaintingControlSetting picture_control) override { | 42 PaintingControlSetting picture_control) override { |
42 SkPictureRecorder recorder; | 43 PaintRecorder recorder; |
43 SkCanvas* canvas = | 44 PaintCanvas* canvas = |
44 recorder.beginRecording(gfx::RectToSkRect(gfx::Rect(bounds_))); | 45 recorder.beginRecording(gfx::RectToSkRect(gfx::Rect(bounds_))); |
45 | 46 |
46 SkPaint paint; | 47 PaintFlags paint; |
47 paint.setStyle(SkPaint::kStroke_Style); | 48 paint.setStyle(PaintFlags::kStroke_Style); |
48 paint.setStrokeWidth(SkIntToScalar(2)); | 49 paint.setStrokeWidth(SkIntToScalar(2)); |
49 paint.setColor(SK_ColorWHITE); | 50 paint.setColor(SK_ColorWHITE); |
50 | 51 |
51 canvas->clear(SK_ColorTRANSPARENT); | 52 canvas->clear(SK_ColorTRANSPARENT); |
52 gfx::Rect inset_rect(bounds_); | 53 gfx::Rect inset_rect(bounds_); |
53 while (!inset_rect.IsEmpty()) { | 54 while (!inset_rect.IsEmpty()) { |
54 inset_rect.Inset(3, 3, 2, 2); | 55 inset_rect.Inset(3, 3, 2, 2); |
55 canvas->drawRect( | 56 canvas->drawRect( |
56 SkRect::MakeXYWH(inset_rect.x(), inset_rect.y(), | 57 SkRect::MakeXYWH(inset_rect.x(), inset_rect.y(), |
57 inset_rect.width(), inset_rect.height()), | 58 inset_rect.width(), inset_rect.height()), |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 gfx::Rect(100, 100), SK_ColorWHITE); | 98 gfx::Rect(100, 100), SK_ColorWHITE); |
98 | 99 |
99 gfx::Size mask_bounds(50, 50); | 100 gfx::Size mask_bounds(50, 50); |
100 | 101 |
101 scoped_refptr<PictureImageLayer> mask = PictureImageLayer::Create(); | 102 scoped_refptr<PictureImageLayer> mask = PictureImageLayer::Create(); |
102 mask->SetIsDrawable(true); | 103 mask->SetIsDrawable(true); |
103 mask->SetIsMask(true); | 104 mask->SetIsMask(true); |
104 mask->SetBounds(mask_bounds); | 105 mask->SetBounds(mask_bounds); |
105 | 106 |
106 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(200, 200); | 107 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(200, 200); |
107 SkCanvas* canvas = surface->getCanvas(); | 108 PaintCanvas* canvas = surface->getCanvas(); |
danakj
2017/01/20 23:34:14
SkSurface can't return a PaintCanvas
| |
108 canvas->scale(SkIntToScalar(4), SkIntToScalar(4)); | 109 canvas->scale(SkIntToScalar(4), SkIntToScalar(4)); |
109 MaskContentLayerClient client(mask_bounds); | 110 MaskContentLayerClient client(mask_bounds); |
110 scoped_refptr<DisplayItemList> mask_display_list = | 111 scoped_refptr<DisplayItemList> mask_display_list = |
111 client.PaintContentsToDisplayList( | 112 client.PaintContentsToDisplayList( |
112 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); | 113 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); |
113 mask_display_list->Raster(canvas, nullptr); | 114 mask_display_list->Raster(canvas, nullptr); |
114 mask->SetImage(surface->makeImageSnapshot()); | 115 mask->SetImage(surface->makeImageSnapshot()); |
115 | 116 |
116 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayerWithBorder( | 117 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayerWithBorder( |
117 gfx::Rect(25, 25, 50, 50), kCSSGreen, 1, SK_ColorBLACK); | 118 gfx::Rect(25, 25, 50, 50), kCSSGreen, 1, SK_ColorBLACK); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 CheckerContentLayerClient(const gfx::Size& bounds, | 156 CheckerContentLayerClient(const gfx::Size& bounds, |
156 SkColor color, | 157 SkColor color, |
157 bool vertical) | 158 bool vertical) |
158 : bounds_(bounds), color_(color), vertical_(vertical) {} | 159 : bounds_(bounds), color_(color), vertical_(vertical) {} |
159 ~CheckerContentLayerClient() override {} | 160 ~CheckerContentLayerClient() override {} |
160 bool FillsBoundsCompletely() const override { return false; } | 161 bool FillsBoundsCompletely() const override { return false; } |
161 size_t GetApproximateUnsharedMemoryUsage() const override { return 0; } | 162 size_t GetApproximateUnsharedMemoryUsage() const override { return 0; } |
162 gfx::Rect PaintableRegion() override { return gfx::Rect(bounds_); } | 163 gfx::Rect PaintableRegion() override { return gfx::Rect(bounds_); } |
163 scoped_refptr<DisplayItemList> PaintContentsToDisplayList( | 164 scoped_refptr<DisplayItemList> PaintContentsToDisplayList( |
164 PaintingControlSetting picture_control) override { | 165 PaintingControlSetting picture_control) override { |
165 SkPictureRecorder recorder; | 166 PaintRecorder recorder; |
166 SkCanvas* canvas = | 167 PaintCanvas* canvas = |
167 recorder.beginRecording(gfx::RectToSkRect(gfx::Rect(bounds_))); | 168 recorder.beginRecording(gfx::RectToSkRect(gfx::Rect(bounds_))); |
168 | 169 |
169 SkPaint paint; | 170 PaintFlags paint; |
170 paint.setStyle(SkPaint::kStroke_Style); | 171 paint.setStyle(PaintFlags::kStroke_Style); |
171 paint.setStrokeWidth(SkIntToScalar(4)); | 172 paint.setStrokeWidth(SkIntToScalar(4)); |
172 paint.setColor(color_); | 173 paint.setColor(color_); |
173 canvas->clear(SK_ColorTRANSPARENT); | 174 canvas->clear(SK_ColorTRANSPARENT); |
174 if (vertical_) { | 175 if (vertical_) { |
175 for (int i = 4; i < bounds_.width(); i += 16) { | 176 for (int i = 4; i < bounds_.width(); i += 16) { |
176 canvas->drawLine(i, 0, i, bounds_.height(), paint); | 177 canvas->drawLine(i, 0, i, bounds_.height(), paint); |
177 } | 178 } |
178 } else { | 179 } else { |
179 for (int i = 4; i < bounds_.height(); i += 16) { | 180 for (int i = 4; i < bounds_.height(); i += 16) { |
180 canvas->drawLine(0, i, bounds_.width(), i, paint); | 181 canvas->drawLine(0, i, bounds_.width(), i, paint); |
(...skipping 18 matching lines...) Expand all Loading... | |
199 class CircleContentLayerClient : public ContentLayerClient { | 200 class CircleContentLayerClient : public ContentLayerClient { |
200 public: | 201 public: |
201 explicit CircleContentLayerClient(const gfx::Size& bounds) | 202 explicit CircleContentLayerClient(const gfx::Size& bounds) |
202 : bounds_(bounds) {} | 203 : bounds_(bounds) {} |
203 ~CircleContentLayerClient() override {} | 204 ~CircleContentLayerClient() override {} |
204 bool FillsBoundsCompletely() const override { return false; } | 205 bool FillsBoundsCompletely() const override { return false; } |
205 size_t GetApproximateUnsharedMemoryUsage() const override { return 0; } | 206 size_t GetApproximateUnsharedMemoryUsage() const override { return 0; } |
206 gfx::Rect PaintableRegion() override { return gfx::Rect(bounds_); } | 207 gfx::Rect PaintableRegion() override { return gfx::Rect(bounds_); } |
207 scoped_refptr<DisplayItemList> PaintContentsToDisplayList( | 208 scoped_refptr<DisplayItemList> PaintContentsToDisplayList( |
208 PaintingControlSetting picture_control) override { | 209 PaintingControlSetting picture_control) override { |
209 SkPictureRecorder recorder; | 210 PaintRecorder recorder; |
210 SkCanvas* canvas = | 211 PaintCanvas* canvas = |
211 recorder.beginRecording(gfx::RectToSkRect(gfx::Rect(bounds_))); | 212 recorder.beginRecording(gfx::RectToSkRect(gfx::Rect(bounds_))); |
212 | 213 |
213 SkPaint paint; | 214 PaintFlags paint; |
214 paint.setStyle(SkPaint::kFill_Style); | 215 paint.setStyle(PaintFlags::kFill_Style); |
215 paint.setColor(SK_ColorWHITE); | 216 paint.setColor(SK_ColorWHITE); |
216 canvas->clear(SK_ColorTRANSPARENT); | 217 canvas->clear(SK_ColorTRANSPARENT); |
217 canvas->drawCircle(bounds_.width() / 2, | 218 canvas->drawCircle(bounds_.width() / 2, |
218 bounds_.height() / 2, | 219 bounds_.height() / 2, |
219 bounds_.width() / 4, | 220 bounds_.width() / 4, |
220 paint); | 221 paint); |
221 | 222 |
222 scoped_refptr<DisplayItemList> display_list = | 223 scoped_refptr<DisplayItemList> display_list = |
223 DisplayItemList::Create(DisplayItemListSettings()); | 224 DisplayItemList::Create(DisplayItemListSettings()); |
224 display_list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 225 display_list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
340 | 341 |
341 RunPixelResourceTest(background, | 342 RunPixelResourceTest(background, |
342 base::FilePath( | 343 base::FilePath( |
343 FILE_PATH_LITERAL("mask_of_layer_with_blend.png"))); | 344 FILE_PATH_LITERAL("mask_of_layer_with_blend.png"))); |
344 } | 345 } |
345 | 346 |
346 } // namespace | 347 } // namespace |
347 } // namespace cc | 348 } // namespace cc |
348 | 349 |
349 #endif // !defined(OS_ANDROID) | 350 #endif // !defined(OS_ANDROID) |
OLD | NEW |