Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "cc/test/fake_content_layer_client.h" | 5 #include "cc/test/fake_content_layer_client.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "cc/playback/clip_display_item.h" | 9 #include "cc/playback/clip_display_item.h" |
| 10 #include "cc/playback/display_item_list_settings.h" | 10 #include "cc/playback/display_item_list_settings.h" |
| 11 #include "cc/playback/drawing_display_item.h" | 11 #include "cc/playback/drawing_display_item.h" |
| 12 #include "cc/playback/transform_display_item.h" | 12 #include "cc/playback/transform_display_item.h" |
| 13 #include "third_party/skia/include/core/SkCanvas.h" | 13 #include "third_party/skia/include/core/SkCanvas.h" |
| 14 #include "third_party/skia/include/core/SkPictureRecorder.h" | 14 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 15 #include "ui/gfx/geometry/rect_conversions.h" | 15 #include "ui/gfx/geometry/rect_conversions.h" |
| 16 #include "ui/gfx/skia_util.h" | 16 #include "ui/gfx/skia_util.h" |
| 17 | 17 |
| 18 namespace cc { | 18 namespace cc { |
| 19 | 19 |
| 20 FakeContentLayerClient::ImageData::ImageData(const SkImage* img, | 20 FakeContentLayerClient::ImageData::ImageData(const SkImage* img, |
|
danakj
2016/04/14 19:37:32
can you make this an sk_sp?
tomhudson
2016/04/25 20:48:14
Done.
| |
| 21 const gfx::Point& point, | 21 const gfx::Point& point, |
| 22 const SkPaint& paint) | 22 const SkPaint& paint) |
| 23 : image(skia::SharePtr(img)), point(point), paint(paint) {} | 23 : image(sk_ref_sp(img)), point(point), paint(paint) {} |
| 24 | 24 |
| 25 FakeContentLayerClient::ImageData::ImageData(const SkImage* img, | 25 FakeContentLayerClient::ImageData::ImageData(const SkImage* img, |
|
danakj
2016/04/14 19:37:32
and this?
tomhudson
2016/04/25 20:48:15
Done.
| |
| 26 const gfx::Transform& transform, | 26 const gfx::Transform& transform, |
| 27 const SkPaint& paint) | 27 const SkPaint& paint) |
| 28 : image(skia::SharePtr(img)), transform(transform), paint(paint) {} | 28 : image(sk_ref_sp(img)), transform(transform), paint(paint) {} |
| 29 | 29 |
| 30 FakeContentLayerClient::ImageData::ImageData(const ImageData& other) = default; | 30 FakeContentLayerClient::ImageData::ImageData(const ImageData& other) = default; |
| 31 | 31 |
| 32 FakeContentLayerClient::ImageData::~ImageData() {} | 32 FakeContentLayerClient::ImageData::~ImageData() {} |
| 33 | 33 |
| 34 FakeContentLayerClient::FakeContentLayerClient() | 34 FakeContentLayerClient::FakeContentLayerClient() |
| 35 : display_list_use_cached_picture_(true), | 35 : display_list_use_cached_picture_(true), |
| 36 fill_with_nonsolid_color_(false), | 36 fill_with_nonsolid_color_(false), |
| 37 last_canvas_(nullptr), | 37 last_canvas_(nullptr), |
| 38 last_painting_control_(PAINTING_BEHAVIOR_NORMAL), | 38 last_painting_control_(PAINTING_BEHAVIOR_NORMAL), |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 50 scoped_refptr<DisplayItemList> | 50 scoped_refptr<DisplayItemList> |
| 51 FakeContentLayerClient::PaintContentsToDisplayList( | 51 FakeContentLayerClient::PaintContentsToDisplayList( |
| 52 PaintingControlSetting painting_control) { | 52 PaintingControlSetting painting_control) { |
| 53 // Cached picture is used because unit tests expect to be able to | 53 // Cached picture is used because unit tests expect to be able to |
| 54 // use GatherPixelRefs. | 54 // use GatherPixelRefs. |
| 55 DisplayItemListSettings settings; | 55 DisplayItemListSettings settings; |
| 56 settings.use_cached_picture = display_list_use_cached_picture_; | 56 settings.use_cached_picture = display_list_use_cached_picture_; |
| 57 scoped_refptr<DisplayItemList> display_list = | 57 scoped_refptr<DisplayItemList> display_list = |
| 58 DisplayItemList::Create(PaintableRegion(), settings); | 58 DisplayItemList::Create(PaintableRegion(), settings); |
| 59 SkPictureRecorder recorder; | 59 SkPictureRecorder recorder; |
| 60 skia::RefPtr<SkCanvas> canvas; | 60 sk_sp<SkCanvas> canvas; |
| 61 | 61 |
| 62 for (RectPaintVector::const_iterator it = draw_rects_.begin(); | 62 for (RectPaintVector::const_iterator it = draw_rects_.begin(); |
| 63 it != draw_rects_.end(); ++it) { | 63 it != draw_rects_.end(); ++it) { |
| 64 const gfx::RectF& draw_rect = it->first; | 64 const gfx::RectF& draw_rect = it->first; |
| 65 const SkPaint& paint = it->second; | 65 const SkPaint& paint = it->second; |
| 66 canvas = | 66 canvas = sk_ref_sp(recorder.beginRecording(gfx::RectFToSkRect(draw_rect))); |
| 67 skia::SharePtr(recorder.beginRecording(gfx::RectFToSkRect(draw_rect))); | |
| 68 canvas->drawRect(gfx::RectFToSkRect(draw_rect), paint); | 67 canvas->drawRect(gfx::RectFToSkRect(draw_rect), paint); |
| 69 display_list->CreateAndAppendItem<DrawingDisplayItem>( | 68 display_list->CreateAndAppendItem<DrawingDisplayItem>( |
| 70 ToEnclosingRect(draw_rect), recorder.finishRecordingAsPicture()); | 69 ToEnclosingRect(draw_rect), recorder.finishRecordingAsPicture()); |
| 71 } | 70 } |
| 72 | 71 |
| 73 for (ImageVector::const_iterator it = draw_images_.begin(); | 72 for (ImageVector::const_iterator it = draw_images_.begin(); |
| 74 it != draw_images_.end(); ++it) { | 73 it != draw_images_.end(); ++it) { |
| 75 if (!it->transform.IsIdentity()) { | 74 if (!it->transform.IsIdentity()) { |
| 76 display_list->CreateAndAppendItem<TransformDisplayItem>(PaintableRegion(), | 75 display_list->CreateAndAppendItem<TransformDisplayItem>(PaintableRegion(), |
| 77 it->transform); | 76 it->transform); |
| 78 } | 77 } |
| 79 canvas = skia::SharePtr( | 78 canvas = sk_ref_sp( |
| 80 recorder.beginRecording(it->image->width(), it->image->height())); | 79 recorder.beginRecording(it->image->width(), it->image->height())); |
| 81 canvas->drawImage(it->image.get(), it->point.x(), it->point.y(), | 80 canvas->drawImage(it->image.get(), it->point.x(), it->point.y(), |
| 82 &it->paint); | 81 &it->paint); |
| 83 display_list->CreateAndAppendItem<DrawingDisplayItem>( | 82 display_list->CreateAndAppendItem<DrawingDisplayItem>( |
| 84 PaintableRegion(), recorder.finishRecordingAsPicture()); | 83 PaintableRegion(), recorder.finishRecordingAsPicture()); |
| 85 if (!it->transform.IsIdentity()) { | 84 if (!it->transform.IsIdentity()) { |
| 86 display_list->CreateAndAppendItem<EndTransformDisplayItem>( | 85 display_list->CreateAndAppendItem<EndTransformDisplayItem>( |
| 87 PaintableRegion()); | 86 PaintableRegion()); |
| 88 } | 87 } |
| 89 } | 88 } |
| 90 | 89 |
| 91 if (fill_with_nonsolid_color_) { | 90 if (fill_with_nonsolid_color_) { |
| 92 gfx::Rect draw_rect = PaintableRegion(); | 91 gfx::Rect draw_rect = PaintableRegion(); |
| 93 bool red = true; | 92 bool red = true; |
| 94 while (!draw_rect.IsEmpty()) { | 93 while (!draw_rect.IsEmpty()) { |
| 95 SkPaint paint; | 94 SkPaint paint; |
| 96 paint.setColor(red ? SK_ColorRED : SK_ColorBLUE); | 95 paint.setColor(red ? SK_ColorRED : SK_ColorBLUE); |
| 97 canvas = | 96 canvas = sk_ref_sp(recorder.beginRecording(gfx::RectToSkRect(draw_rect))); |
| 98 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(draw_rect))); | |
| 99 canvas->drawIRect(gfx::RectToSkIRect(draw_rect), paint); | 97 canvas->drawIRect(gfx::RectToSkIRect(draw_rect), paint); |
| 100 display_list->CreateAndAppendItem<DrawingDisplayItem>( | 98 display_list->CreateAndAppendItem<DrawingDisplayItem>( |
| 101 draw_rect, recorder.finishRecordingAsPicture()); | 99 draw_rect, recorder.finishRecordingAsPicture()); |
| 102 draw_rect.Inset(1, 1); | 100 draw_rect.Inset(1, 1); |
| 103 } | 101 } |
| 104 } | 102 } |
| 105 | 103 |
| 106 | |
| 107 display_list->Finalize(); | 104 display_list->Finalize(); |
| 108 return display_list; | 105 return display_list; |
| 109 } | 106 } |
| 110 | 107 |
| 111 bool FakeContentLayerClient::FillsBoundsCompletely() const { return false; } | 108 bool FakeContentLayerClient::FillsBoundsCompletely() const { return false; } |
| 112 | 109 |
| 113 size_t FakeContentLayerClient::GetApproximateUnsharedMemoryUsage() const { | 110 size_t FakeContentLayerClient::GetApproximateUnsharedMemoryUsage() const { |
| 114 return reported_memory_usage_; | 111 return reported_memory_usage_; |
| 115 } | 112 } |
| 116 | 113 |
| 117 } // namespace cc | 114 } // namespace cc |
| OLD | NEW |