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