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/paint/paint_canvas.h" |
| 10 #include "cc/paint/paint_recorder.h" |
9 #include "cc/playback/clip_display_item.h" | 11 #include "cc/playback/clip_display_item.h" |
10 #include "cc/playback/drawing_display_item.h" | 12 #include "cc/playback/drawing_display_item.h" |
11 #include "cc/playback/transform_display_item.h" | 13 #include "cc/playback/transform_display_item.h" |
12 #include "third_party/skia/include/core/SkCanvas.h" | |
13 #include "third_party/skia/include/core/SkPictureRecorder.h" | |
14 #include "ui/gfx/geometry/rect_conversions.h" | 14 #include "ui/gfx/geometry/rect_conversions.h" |
15 #include "ui/gfx/skia_util.h" | 15 #include "ui/gfx/skia_util.h" |
16 | 16 |
17 namespace cc { | 17 namespace cc { |
18 | 18 |
19 FakeContentLayerClient::ImageData::ImageData(sk_sp<const SkImage> img, | 19 FakeContentLayerClient::ImageData::ImageData(sk_sp<const SkImage> img, |
20 const gfx::Point& point, | 20 const gfx::Point& point, |
21 const SkPaint& paint) | 21 const PaintFlags& paint) |
22 : image(std::move(img)), point(point), paint(paint) {} | 22 : image(std::move(img)), point(point), paint(paint) {} |
23 | 23 |
24 FakeContentLayerClient::ImageData::ImageData(sk_sp<const SkImage> img, | 24 FakeContentLayerClient::ImageData::ImageData(sk_sp<const SkImage> img, |
25 const gfx::Transform& transform, | 25 const gfx::Transform& transform, |
26 const SkPaint& paint) | 26 const PaintFlags& paint) |
27 : image(std::move(img)), transform(transform), paint(paint) {} | 27 : image(std::move(img)), transform(transform), paint(paint) {} |
28 | 28 |
29 FakeContentLayerClient::ImageData::ImageData(const ImageData& other) = default; | 29 FakeContentLayerClient::ImageData::ImageData(const ImageData& other) = default; |
30 | 30 |
31 FakeContentLayerClient::ImageData::~ImageData() {} | 31 FakeContentLayerClient::ImageData::~ImageData() {} |
32 | 32 |
33 FakeContentLayerClient::FakeContentLayerClient() | 33 FakeContentLayerClient::FakeContentLayerClient() |
34 : fill_with_nonsolid_color_(false), | 34 : fill_with_nonsolid_color_(false), |
35 last_canvas_(nullptr), | 35 last_canvas_(nullptr), |
36 last_painting_control_(PAINTING_BEHAVIOR_NORMAL), | 36 last_painting_control_(PAINTING_BEHAVIOR_NORMAL), |
37 reported_memory_usage_(0), | 37 reported_memory_usage_(0), |
38 bounds_set_(false) {} | 38 bounds_set_(false) {} |
39 | 39 |
40 FakeContentLayerClient::~FakeContentLayerClient() { | 40 FakeContentLayerClient::~FakeContentLayerClient() { |
41 } | 41 } |
42 | 42 |
43 gfx::Rect FakeContentLayerClient::PaintableRegion() { | 43 gfx::Rect FakeContentLayerClient::PaintableRegion() { |
44 CHECK(bounds_set_); | 44 CHECK(bounds_set_); |
45 return gfx::Rect(bounds_); | 45 return gfx::Rect(bounds_); |
46 } | 46 } |
47 | 47 |
48 scoped_refptr<DisplayItemList> | 48 scoped_refptr<DisplayItemList> |
49 FakeContentLayerClient::PaintContentsToDisplayList( | 49 FakeContentLayerClient::PaintContentsToDisplayList( |
50 PaintingControlSetting painting_control) { | 50 PaintingControlSetting painting_control) { |
51 // Cached picture is used because unit tests expect to be able to | 51 // Cached picture is used because unit tests expect to be able to |
52 // use GatherPixelRefs. | 52 // use GatherPixelRefs. |
53 auto display_list = make_scoped_refptr(new DisplayItemList); | 53 auto display_list = make_scoped_refptr(new DisplayItemList); |
54 display_list->SetRetainVisualRectsForTesting(true); | 54 display_list->SetRetainVisualRectsForTesting(true); |
55 SkPictureRecorder recorder; | 55 PaintRecorder recorder; |
56 | 56 |
57 for (RectPaintVector::const_iterator it = draw_rects_.begin(); | 57 for (RectPaintVector::const_iterator it = draw_rects_.begin(); |
58 it != draw_rects_.end(); ++it) { | 58 it != draw_rects_.end(); ++it) { |
59 const gfx::RectF& draw_rect = it->first; | 59 const gfx::RectF& draw_rect = it->first; |
60 const SkPaint& paint = it->second; | 60 const PaintFlags& paint = it->second; |
61 SkCanvas* canvas = recorder.beginRecording(gfx::RectFToSkRect(draw_rect)); | 61 PaintCanvas* canvas = |
| 62 recorder.beginRecording(gfx::RectFToSkRect(draw_rect)); |
62 canvas->drawRect(gfx::RectFToSkRect(draw_rect), paint); | 63 canvas->drawRect(gfx::RectFToSkRect(draw_rect), paint); |
63 display_list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 64 display_list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
64 ToEnclosingRect(draw_rect), recorder.finishRecordingAsPicture()); | 65 ToEnclosingRect(draw_rect), recorder.finishRecordingAsPicture()); |
65 } | 66 } |
66 | 67 |
67 for (ImageVector::const_iterator it = draw_images_.begin(); | 68 for (ImageVector::const_iterator it = draw_images_.begin(); |
68 it != draw_images_.end(); ++it) { | 69 it != draw_images_.end(); ++it) { |
69 if (!it->transform.IsIdentity()) { | 70 if (!it->transform.IsIdentity()) { |
70 display_list->CreateAndAppendPairedBeginItem<TransformDisplayItem>( | 71 display_list->CreateAndAppendPairedBeginItem<TransformDisplayItem>( |
71 it->transform); | 72 it->transform); |
72 } | 73 } |
73 SkCanvas* canvas = | 74 PaintCanvas* canvas = |
74 recorder.beginRecording(it->image->width(), it->image->height()); | 75 recorder.beginRecording(it->image->width(), it->image->height()); |
75 canvas->drawImage(it->image.get(), it->point.x(), it->point.y(), | 76 canvas->drawImage(it->image.get(), it->point.x(), it->point.y(), |
76 &it->paint); | 77 &it->paint); |
77 display_list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 78 display_list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
78 PaintableRegion(), recorder.finishRecordingAsPicture()); | 79 PaintableRegion(), recorder.finishRecordingAsPicture()); |
79 if (!it->transform.IsIdentity()) { | 80 if (!it->transform.IsIdentity()) { |
80 display_list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>(); | 81 display_list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>(); |
81 } | 82 } |
82 } | 83 } |
83 | 84 |
84 if (fill_with_nonsolid_color_) { | 85 if (fill_with_nonsolid_color_) { |
85 gfx::Rect draw_rect = PaintableRegion(); | 86 gfx::Rect draw_rect = PaintableRegion(); |
86 bool red = true; | 87 bool red = true; |
87 while (!draw_rect.IsEmpty()) { | 88 while (!draw_rect.IsEmpty()) { |
88 SkPaint paint; | 89 PaintFlags paint; |
89 paint.setColor(red ? SK_ColorRED : SK_ColorBLUE); | 90 paint.setColor(red ? SK_ColorRED : SK_ColorBLUE); |
90 SkCanvas* canvas = recorder.beginRecording(gfx::RectToSkRect(draw_rect)); | 91 PaintCanvas* canvas = |
| 92 recorder.beginRecording(gfx::RectToSkRect(draw_rect)); |
91 canvas->drawIRect(gfx::RectToSkIRect(draw_rect), paint); | 93 canvas->drawIRect(gfx::RectToSkIRect(draw_rect), paint); |
92 display_list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 94 display_list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
93 draw_rect, recorder.finishRecordingAsPicture()); | 95 draw_rect, recorder.finishRecordingAsPicture()); |
94 draw_rect.Inset(1, 1); | 96 draw_rect.Inset(1, 1); |
95 } | 97 } |
96 } | 98 } |
97 | 99 |
98 display_list->Finalize(); | 100 display_list->Finalize(); |
99 return display_list; | 101 return display_list; |
100 } | 102 } |
101 | 103 |
102 bool FakeContentLayerClient::FillsBoundsCompletely() const { return false; } | 104 bool FakeContentLayerClient::FillsBoundsCompletely() const { return false; } |
103 | 105 |
104 size_t FakeContentLayerClient::GetApproximateUnsharedMemoryUsage() const { | 106 size_t FakeContentLayerClient::GetApproximateUnsharedMemoryUsage() const { |
105 return reported_memory_usage_; | 107 return reported_memory_usage_; |
106 } | 108 } |
107 | 109 |
108 } // namespace cc | 110 } // namespace cc |
OLD | NEW |