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