OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/playback/display_item_list.h" | 5 #include "cc/playback/display_item_list.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "cc/output/filter_operation.h" | 12 #include "cc/output/filter_operation.h" |
13 #include "cc/output/filter_operations.h" | 13 #include "cc/output/filter_operations.h" |
| 14 #include "cc/paint/paint_canvas.h" |
| 15 #include "cc/paint/paint_flags.h" |
| 16 #include "cc/paint/paint_recorder.h" |
14 #include "cc/playback/clip_display_item.h" | 17 #include "cc/playback/clip_display_item.h" |
15 #include "cc/playback/clip_path_display_item.h" | 18 #include "cc/playback/clip_path_display_item.h" |
16 #include "cc/playback/compositing_display_item.h" | 19 #include "cc/playback/compositing_display_item.h" |
17 #include "cc/playback/display_item_list_settings.h" | 20 #include "cc/playback/display_item_list_settings.h" |
18 #include "cc/playback/drawing_display_item.h" | 21 #include "cc/playback/drawing_display_item.h" |
19 #include "cc/playback/filter_display_item.h" | 22 #include "cc/playback/filter_display_item.h" |
20 #include "cc/playback/float_clip_display_item.h" | 23 #include "cc/playback/float_clip_display_item.h" |
21 #include "cc/playback/transform_display_item.h" | 24 #include "cc/playback/transform_display_item.h" |
22 #include "cc/test/geometry_test_utils.h" | 25 #include "cc/test/geometry_test_utils.h" |
23 #include "cc/test/skia_common.h" | 26 #include "cc/test/skia_common.h" |
24 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
26 #include "third_party/skia/include/core/SkBitmap.h" | 29 #include "third_party/skia/include/core/SkBitmap.h" |
27 #include "third_party/skia/include/core/SkCanvas.h" | |
28 #include "third_party/skia/include/core/SkColor.h" | 30 #include "third_party/skia/include/core/SkColor.h" |
29 #include "third_party/skia/include/core/SkPictureRecorder.h" | |
30 #include "third_party/skia/include/core/SkSurface.h" | 31 #include "third_party/skia/include/core/SkSurface.h" |
31 | 32 |
32 #include "third_party/skia/include/effects/SkColorMatrixFilter.h" | 33 #include "third_party/skia/include/effects/SkColorMatrixFilter.h" |
33 #include "third_party/skia/include/effects/SkImageSource.h" | 34 #include "third_party/skia/include/effects/SkImageSource.h" |
34 #include "third_party/skia/include/utils/SkPictureUtils.h" | |
35 #include "ui/gfx/geometry/rect.h" | 35 #include "ui/gfx/geometry/rect.h" |
36 #include "ui/gfx/geometry/rect_conversions.h" | 36 #include "ui/gfx/geometry/rect_conversions.h" |
37 #include "ui/gfx/skia_util.h" | 37 #include "ui/gfx/skia_util.h" |
38 | 38 |
39 namespace cc { | 39 namespace cc { |
40 | 40 |
41 namespace { | 41 namespace { |
42 | 42 |
43 const gfx::Rect kVisualRect(0, 0, 42, 42); | 43 const gfx::Rect kVisualRect(0, 0, 42, 42); |
44 | 44 |
45 scoped_refptr<DisplayItemList> CreateDefaultList() { | 45 scoped_refptr<DisplayItemList> CreateDefaultList() { |
46 return DisplayItemList::Create(DisplayItemListSettings()); | 46 return DisplayItemList::Create(DisplayItemListSettings()); |
47 } | 47 } |
48 | 48 |
49 sk_sp<const SkPicture> CreateRectPicture(const gfx::Rect& bounds) { | 49 sk_sp<const PaintRecord> CreateRectPicture(const gfx::Rect& bounds) { |
50 SkPictureRecorder recorder; | 50 PaintRecorder recorder; |
51 SkCanvas* canvas = recorder.beginRecording(bounds.width(), bounds.height()); | 51 PaintCanvas* canvas = |
| 52 recorder.beginRecording(bounds.width(), bounds.height()); |
52 canvas->drawRect( | 53 canvas->drawRect( |
53 SkRect::MakeXYWH(bounds.x(), bounds.y(), bounds.width(), bounds.height()), | 54 SkRect::MakeXYWH(bounds.x(), bounds.y(), bounds.width(), bounds.height()), |
54 SkPaint()); | 55 PaintFlags()); |
55 return recorder.finishRecordingAsPicture(); | 56 return recorder.finishRecordingAsPicture(); |
56 } | 57 } |
57 | 58 |
58 void AppendFirstSerializationTestPicture(scoped_refptr<DisplayItemList> list, | 59 void AppendFirstSerializationTestPicture(scoped_refptr<DisplayItemList> list, |
59 const gfx::Size& layer_size) { | 60 const gfx::Size& layer_size) { |
60 gfx::PointF offset(2.f, 3.f); | 61 gfx::PointF offset(2.f, 3.f); |
61 SkPictureRecorder recorder; | 62 PaintRecorder recorder; |
62 | 63 |
63 SkPaint red_paint; | 64 PaintFlags red_paint; |
64 red_paint.setColor(SK_ColorRED); | 65 red_paint.setColor(SK_ColorRED); |
65 | 66 |
66 SkCanvas* canvas = recorder.beginRecording(SkRect::MakeXYWH( | 67 PaintCanvas* canvas = recorder.beginRecording(SkRect::MakeXYWH( |
67 offset.x(), offset.y(), layer_size.width(), layer_size.height())); | 68 offset.x(), offset.y(), layer_size.width(), layer_size.height())); |
68 canvas->translate(offset.x(), offset.y()); | 69 canvas->translate(offset.x(), offset.y()); |
69 canvas->drawRectCoords(0.f, 0.f, 4.f, 4.f, red_paint); | 70 canvas->drawRectCoords(0.f, 0.f, 4.f, 4.f, red_paint); |
70 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 71 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
71 kVisualRect, recorder.finishRecordingAsPicture()); | 72 kVisualRect, recorder.finishRecordingAsPicture()); |
72 } | 73 } |
73 | 74 |
74 } // namespace | 75 } // namespace |
75 | 76 |
76 TEST(DisplayItemListTest, SingleDrawingItem) { | 77 TEST(DisplayItemListTest, SingleDrawingItem) { |
77 gfx::Rect layer_rect(100, 100); | 78 gfx::Rect layer_rect(100, 100); |
78 SkPictureRecorder recorder; | 79 PaintRecorder recorder; |
79 SkPaint blue_paint; | 80 PaintFlags blue_paint; |
80 blue_paint.setColor(SK_ColorBLUE); | 81 blue_paint.setColor(SK_ColorBLUE); |
81 SkPaint red_paint; | 82 PaintFlags red_paint; |
82 red_paint.setColor(SK_ColorRED); | 83 red_paint.setColor(SK_ColorRED); |
83 unsigned char pixels[4 * 100 * 100] = {0}; | 84 unsigned char pixels[4 * 100 * 100] = {0}; |
84 DisplayItemListSettings settings; | 85 DisplayItemListSettings settings; |
85 settings.use_cached_picture = true; | 86 settings.use_cached_picture = true; |
86 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings); | 87 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings); |
87 | 88 |
88 gfx::PointF offset(8.f, 9.f); | 89 gfx::PointF offset(8.f, 9.f); |
89 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size())); | 90 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size())); |
90 SkCanvas* canvas = | 91 PaintCanvas* canvas = |
91 recorder.beginRecording(gfx::RectFToSkRect(recording_rect)); | 92 recorder.beginRecording(gfx::RectFToSkRect(recording_rect)); |
92 canvas->translate(offset.x(), offset.y()); | 93 canvas->translate(offset.x(), offset.y()); |
93 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); | 94 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); |
94 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); | 95 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); |
95 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 96 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
96 kVisualRect, recorder.finishRecordingAsPicture()); | 97 kVisualRect, recorder.finishRecordingAsPicture()); |
97 list->Finalize(); | 98 list->Finalize(); |
98 DrawDisplayList(pixels, layer_rect, list); | 99 DrawDisplayList(pixels, layer_rect, list); |
99 | 100 |
100 SkBitmap expected_bitmap; | 101 SkBitmap expected_bitmap; |
101 unsigned char expected_pixels[4 * 100 * 100] = {0}; | 102 unsigned char expected_pixels[4 * 100 * 100] = {0}; |
102 SkImageInfo info = | 103 SkImageInfo info = |
103 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); | 104 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); |
104 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); | 105 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); |
105 SkCanvas expected_canvas(expected_bitmap); | 106 SkCanvas expected_canvas(expected_bitmap); |
106 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect)); | 107 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect)); |
107 expected_canvas.drawRectCoords(0.f + offset.x(), 0.f + offset.y(), | 108 expected_canvas.drawRectCoords(0.f + offset.x(), 0.f + offset.y(), |
108 60.f + offset.x(), 60.f + offset.y(), | 109 60.f + offset.x(), 60.f + offset.y(), |
109 red_paint); | 110 red_paint); |
110 expected_canvas.drawRectCoords(50.f + offset.x(), 50.f + offset.y(), | 111 expected_canvas.drawRectCoords(50.f + offset.x(), 50.f + offset.y(), |
111 75.f + offset.x(), 75.f + offset.y(), | 112 75.f + offset.x(), 75.f + offset.y(), |
112 blue_paint); | 113 blue_paint); |
113 | 114 |
114 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); | 115 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); |
115 } | 116 } |
116 | 117 |
117 TEST(DisplayItemListTest, ClipItem) { | 118 TEST(DisplayItemListTest, ClipItem) { |
118 gfx::Rect layer_rect(100, 100); | 119 gfx::Rect layer_rect(100, 100); |
119 SkPictureRecorder recorder; | 120 PaintRecorder recorder; |
120 SkPaint blue_paint; | 121 PaintFlags blue_paint; |
121 blue_paint.setColor(SK_ColorBLUE); | 122 blue_paint.setColor(SK_ColorBLUE); |
122 SkPaint red_paint; | 123 PaintFlags red_paint; |
123 red_paint.setColor(SK_ColorRED); | 124 red_paint.setColor(SK_ColorRED); |
124 unsigned char pixels[4 * 100 * 100] = {0}; | 125 unsigned char pixels[4 * 100 * 100] = {0}; |
125 DisplayItemListSettings settings; | 126 DisplayItemListSettings settings; |
126 settings.use_cached_picture = true; | 127 settings.use_cached_picture = true; |
127 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings); | 128 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings); |
128 | 129 |
129 gfx::PointF first_offset(8.f, 9.f); | 130 gfx::PointF first_offset(8.f, 9.f); |
130 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); | 131 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); |
131 SkCanvas* canvas = | 132 PaintCanvas* canvas = |
132 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect)); | 133 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect)); |
133 canvas->translate(first_offset.x(), first_offset.y()); | 134 canvas->translate(first_offset.x(), first_offset.y()); |
134 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); | 135 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); |
135 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 136 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
136 kVisualRect, recorder.finishRecordingAsPicture()); | 137 kVisualRect, recorder.finishRecordingAsPicture()); |
137 | 138 |
138 gfx::Rect clip_rect(60, 60, 10, 10); | 139 gfx::Rect clip_rect(60, 60, 10, 10); |
139 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>( | 140 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>( |
140 clip_rect, std::vector<SkRRect>(), true); | 141 clip_rect, std::vector<SkRRect>(), true); |
141 | 142 |
(...skipping 24 matching lines...) Expand all Loading... |
166 expected_canvas.clipRect(gfx::RectToSkRect(clip_rect)); | 167 expected_canvas.clipRect(gfx::RectToSkRect(clip_rect)); |
167 expected_canvas.drawRectCoords( | 168 expected_canvas.drawRectCoords( |
168 50.f + second_offset.x(), 50.f + second_offset.y(), | 169 50.f + second_offset.x(), 50.f + second_offset.y(), |
169 75.f + second_offset.x(), 75.f + second_offset.y(), blue_paint); | 170 75.f + second_offset.x(), 75.f + second_offset.y(), blue_paint); |
170 | 171 |
171 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); | 172 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); |
172 } | 173 } |
173 | 174 |
174 TEST(DisplayItemListTest, TransformItem) { | 175 TEST(DisplayItemListTest, TransformItem) { |
175 gfx::Rect layer_rect(100, 100); | 176 gfx::Rect layer_rect(100, 100); |
176 SkPictureRecorder recorder; | 177 PaintRecorder recorder; |
177 SkPaint blue_paint; | 178 PaintFlags blue_paint; |
178 blue_paint.setColor(SK_ColorBLUE); | 179 blue_paint.setColor(SK_ColorBLUE); |
179 SkPaint red_paint; | 180 PaintFlags red_paint; |
180 red_paint.setColor(SK_ColorRED); | 181 red_paint.setColor(SK_ColorRED); |
181 unsigned char pixels[4 * 100 * 100] = {0}; | 182 unsigned char pixels[4 * 100 * 100] = {0}; |
182 DisplayItemListSettings settings; | 183 DisplayItemListSettings settings; |
183 settings.use_cached_picture = true; | 184 settings.use_cached_picture = true; |
184 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings); | 185 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings); |
185 | 186 |
186 gfx::PointF first_offset(8.f, 9.f); | 187 gfx::PointF first_offset(8.f, 9.f); |
187 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); | 188 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); |
188 SkCanvas* canvas = | 189 PaintCanvas* canvas = |
189 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect)); | 190 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect)); |
190 canvas->translate(first_offset.x(), first_offset.y()); | 191 canvas->translate(first_offset.x(), first_offset.y()); |
191 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); | 192 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); |
192 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 193 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
193 kVisualRect, recorder.finishRecordingAsPicture()); | 194 kVisualRect, recorder.finishRecordingAsPicture()); |
194 | 195 |
195 gfx::Transform transform; | 196 gfx::Transform transform; |
196 transform.Rotate(45.0); | 197 transform.Rotate(45.0); |
197 list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(transform); | 198 list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(transform); |
198 | 199 |
(...skipping 30 matching lines...) Expand all Loading... |
229 } | 230 } |
230 | 231 |
231 TEST(DisplayItemListTest, FilterItem) { | 232 TEST(DisplayItemListTest, FilterItem) { |
232 gfx::Rect layer_rect(100, 100); | 233 gfx::Rect layer_rect(100, 100); |
233 FilterOperations filters; | 234 FilterOperations filters; |
234 unsigned char pixels[4 * 100 * 100] = {0}; | 235 unsigned char pixels[4 * 100 * 100] = {0}; |
235 scoped_refptr<DisplayItemList> list = | 236 scoped_refptr<DisplayItemList> list = |
236 DisplayItemList::Create(DisplayItemListSettings()); | 237 DisplayItemList::Create(DisplayItemListSettings()); |
237 | 238 |
238 sk_sp<SkSurface> source_surface = SkSurface::MakeRasterN32Premul(50, 50); | 239 sk_sp<SkSurface> source_surface = SkSurface::MakeRasterN32Premul(50, 50); |
239 SkCanvas* source_canvas = source_surface->getCanvas(); | 240 PaintCanvas* source_canvas = source_surface->getCanvas(); |
240 source_canvas->clear(SkColorSetRGB(128, 128, 128)); | 241 source_canvas->clear(SkColorSetRGB(128, 128, 128)); |
241 sk_sp<SkImage> source_image = source_surface->makeImageSnapshot(); | 242 sk_sp<SkImage> source_image = source_surface->makeImageSnapshot(); |
242 | 243 |
243 // For most SkImageFilters, the |dst| bounds computed by computeFastBounds are | 244 // For most SkImageFilters, the |dst| bounds computed by computeFastBounds are |
244 // dependent on the provided |src| bounds. This means, for example, that | 245 // dependent on the provided |src| bounds. This means, for example, that |
245 // translating |src| results in a corresponding translation of |dst|. But this | 246 // translating |src| results in a corresponding translation of |dst|. But this |
246 // is not the case for all SkImageFilters; for some of them (e.g. | 247 // is not the case for all SkImageFilters; for some of them (e.g. |
247 // SkImageSource), the computation of |dst| in computeFastBounds doesn't | 248 // SkImageSource), the computation of |dst| in computeFastBounds doesn't |
248 // involve |src| at all. Incorrectly assuming such a relationship (e.g. by | 249 // involve |src| at all. Incorrectly assuming such a relationship (e.g. by |
249 // translating |dst| after it is computed by computeFastBounds, rather than | 250 // translating |dst| after it is computed by computeFastBounds, rather than |
250 // translating |src| before it provided to computedFastBounds) can cause | 251 // translating |src| before it provided to computedFastBounds) can cause |
251 // incorrect clipping of filter output. To test for this, we include an | 252 // incorrect clipping of filter output. To test for this, we include an |
252 // SkImageSource filter in |filters|. Here, |src| is |filter_bounds|, defined | 253 // SkImageSource filter in |filters|. Here, |src| is |filter_bounds|, defined |
253 // below. | 254 // below. |
254 sk_sp<SkImageFilter> image_filter = SkImageSource::Make(source_image); | 255 sk_sp<SkImageFilter> image_filter = SkImageSource::Make(source_image); |
255 filters.Append(FilterOperation::CreateReferenceFilter(image_filter)); | 256 filters.Append(FilterOperation::CreateReferenceFilter(image_filter)); |
256 filters.Append(FilterOperation::CreateBrightnessFilter(0.5f)); | 257 filters.Append(FilterOperation::CreateBrightnessFilter(0.5f)); |
257 gfx::RectF filter_bounds(10.f, 10.f, 50.f, 50.f); | 258 gfx::RectF filter_bounds(10.f, 10.f, 50.f, 50.f); |
258 list->CreateAndAppendPairedBeginItem<FilterDisplayItem>( | 259 list->CreateAndAppendPairedBeginItem<FilterDisplayItem>( |
259 filters, filter_bounds, filter_bounds.origin()); | 260 filters, filter_bounds, filter_bounds.origin()); |
260 | 261 |
261 // Include a rect drawing so that filter is actually applied to something. | 262 // Include a rect drawing so that filter is actually applied to something. |
262 { | 263 { |
263 SkPictureRecorder recorder; | 264 PaintRecorder recorder; |
264 | 265 |
265 SkPaint red_paint; | 266 PaintFlags red_paint; |
266 red_paint.setColor(SK_ColorRED); | 267 red_paint.setColor(SK_ColorRED); |
267 | 268 |
268 SkCanvas* canvas = recorder.beginRecording( | 269 PaintCanvas* canvas = recorder.beginRecording( |
269 SkRect::MakeXYWH(0, 0, layer_rect.width(), layer_rect.height())); | 270 SkRect::MakeXYWH(0, 0, layer_rect.width(), layer_rect.height())); |
270 canvas->drawRectCoords(filter_bounds.x(), filter_bounds.y(), | 271 canvas->drawRectCoords(filter_bounds.x(), filter_bounds.y(), |
271 filter_bounds.right(), filter_bounds.bottom(), | 272 filter_bounds.right(), filter_bounds.bottom(), |
272 red_paint); | 273 red_paint); |
273 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 274 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
274 ToNearestRect(filter_bounds), recorder.finishRecordingAsPicture()); | 275 ToNearestRect(filter_bounds), recorder.finishRecordingAsPicture()); |
275 } | 276 } |
276 | 277 |
277 list->CreateAndAppendPairedEndItem<EndFilterDisplayItem>(); | 278 list->CreateAndAppendPairedEndItem<EndFilterDisplayItem>(); |
278 list->Finalize(); | 279 list->Finalize(); |
279 | 280 |
280 DrawDisplayList(pixels, layer_rect, list); | 281 DrawDisplayList(pixels, layer_rect, list); |
281 | 282 |
282 SkBitmap expected_bitmap; | 283 SkBitmap expected_bitmap; |
283 unsigned char expected_pixels[4 * 100 * 100] = {0}; | 284 unsigned char expected_pixels[4 * 100 * 100] = {0}; |
284 SkPaint paint; | 285 PaintFlags paint; |
285 paint.setColor(SkColorSetRGB(64, 64, 64)); | 286 paint.setColor(SkColorSetRGB(64, 64, 64)); |
286 SkImageInfo info = | 287 SkImageInfo info = |
287 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); | 288 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); |
288 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); | 289 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); |
289 SkCanvas expected_canvas(expected_bitmap); | 290 SkCanvas expected_canvas(expected_bitmap); |
290 expected_canvas.drawRect(RectFToSkRect(filter_bounds), paint); | 291 expected_canvas.drawRect(RectFToSkRect(filter_bounds), paint); |
291 | 292 |
292 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); | 293 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); |
293 } | 294 } |
294 | 295 |
295 TEST(DisplayItemListTest, CompactingItems) { | 296 TEST(DisplayItemListTest, CompactingItems) { |
296 gfx::Rect layer_rect(100, 100); | 297 gfx::Rect layer_rect(100, 100); |
297 SkPictureRecorder recorder; | 298 PaintRecorder recorder; |
298 SkPaint blue_paint; | 299 PaintFlags blue_paint; |
299 blue_paint.setColor(SK_ColorBLUE); | 300 blue_paint.setColor(SK_ColorBLUE); |
300 SkPaint red_paint; | 301 PaintFlags red_paint; |
301 red_paint.setColor(SK_ColorRED); | 302 red_paint.setColor(SK_ColorRED); |
302 unsigned char pixels[4 * 100 * 100] = {0}; | 303 unsigned char pixels[4 * 100 * 100] = {0}; |
303 | 304 |
304 gfx::PointF offset(8.f, 9.f); | 305 gfx::PointF offset(8.f, 9.f); |
305 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size())); | 306 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size())); |
306 | 307 |
307 DisplayItemListSettings no_caching_settings; | 308 DisplayItemListSettings no_caching_settings; |
308 scoped_refptr<DisplayItemList> list_without_caching = | 309 scoped_refptr<DisplayItemList> list_without_caching = |
309 DisplayItemList::Create(no_caching_settings); | 310 DisplayItemList::Create(no_caching_settings); |
310 | 311 |
311 SkCanvas* canvas = | 312 PaintCanvas* canvas = |
312 recorder.beginRecording(gfx::RectFToSkRect(recording_rect)); | 313 recorder.beginRecording(gfx::RectFToSkRect(recording_rect)); |
313 canvas->translate(offset.x(), offset.y()); | 314 canvas->translate(offset.x(), offset.y()); |
314 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); | 315 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); |
315 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); | 316 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); |
316 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture(); | 317 sk_sp<PaintRecord> picture = recorder.finishRecordingAsPicture(); |
317 list_without_caching->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 318 list_without_caching->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
318 kVisualRect, picture); | 319 kVisualRect, picture); |
319 list_without_caching->Finalize(); | 320 list_without_caching->Finalize(); |
320 DrawDisplayList(pixels, layer_rect, list_without_caching); | 321 DrawDisplayList(pixels, layer_rect, list_without_caching); |
321 | 322 |
322 unsigned char expected_pixels[4 * 100 * 100] = {0}; | 323 unsigned char expected_pixels[4 * 100 * 100] = {0}; |
323 DisplayItemListSettings caching_settings; | 324 DisplayItemListSettings caching_settings; |
324 caching_settings.use_cached_picture = true; | 325 caching_settings.use_cached_picture = true; |
325 scoped_refptr<DisplayItemList> list_with_caching = | 326 scoped_refptr<DisplayItemList> list_with_caching = |
326 DisplayItemList::Create(caching_settings); | 327 DisplayItemList::Create(caching_settings); |
327 list_with_caching->CreateAndAppendDrawingItem<DrawingDisplayItem>(kVisualRect, | 328 list_with_caching->CreateAndAppendDrawingItem<DrawingDisplayItem>(kVisualRect, |
328 picture); | 329 picture); |
329 list_with_caching->Finalize(); | 330 list_with_caching->Finalize(); |
330 DrawDisplayList(expected_pixels, layer_rect, list_with_caching); | 331 DrawDisplayList(expected_pixels, layer_rect, list_with_caching); |
331 | 332 |
332 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); | 333 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); |
333 } | 334 } |
334 | 335 |
335 TEST(DisplayItemListTest, ApproximateMemoryUsage) { | 336 TEST(DisplayItemListTest, ApproximateMemoryUsage) { |
336 const int kNumCommandsInTestSkPicture = 1000; | 337 const int kNumCommandsInTestPaintRecord = 1000; |
337 scoped_refptr<DisplayItemList> list; | 338 scoped_refptr<DisplayItemList> list; |
338 size_t memory_usage; | 339 size_t memory_usage; |
339 | 340 |
340 // Make an SkPicture whose size is known. | 341 // Make a PaintRecord whose size is known. |
341 gfx::Rect layer_rect(100, 100); | 342 gfx::Rect layer_rect(100, 100); |
342 SkPictureRecorder recorder; | 343 PaintRecorder recorder; |
343 SkPaint blue_paint; | 344 PaintFlags blue_paint; |
344 blue_paint.setColor(SK_ColorBLUE); | 345 blue_paint.setColor(SK_ColorBLUE); |
345 SkCanvas* canvas = recorder.beginRecording(gfx::RectToSkRect(layer_rect)); | 346 PaintCanvas* canvas = recorder.beginRecording(gfx::RectToSkRect(layer_rect)); |
346 for (int i = 0; i < kNumCommandsInTestSkPicture; i++) | 347 for (int i = 0; i < kNumCommandsInTestPaintRecord; i++) |
347 canvas->drawPaint(blue_paint); | 348 canvas->drawPaint(blue_paint); |
348 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture(); | 349 sk_sp<PaintRecord> picture = recorder.finishRecordingAsPicture(); |
349 size_t picture_size = SkPictureUtils::ApproximateBytesUsed(picture.get()); | 350 size_t picture_size = SkPictureUtils::ApproximateBytesUsed(picture.get()); |
350 ASSERT_GE(picture_size, kNumCommandsInTestSkPicture * sizeof(blue_paint)); | 351 ASSERT_GE(picture_size, kNumCommandsInTestPaintRecord * sizeof(blue_paint)); |
351 | 352 |
352 // Using a cached picture, we should get about the right size. | 353 // Using a cached picture, we should get about the right size. |
353 DisplayItemListSettings caching_settings; | 354 DisplayItemListSettings caching_settings; |
354 caching_settings.use_cached_picture = true; | 355 caching_settings.use_cached_picture = true; |
355 list = DisplayItemList::Create(caching_settings); | 356 list = DisplayItemList::Create(caching_settings); |
356 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(kVisualRect, picture); | 357 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(kVisualRect, picture); |
357 list->Finalize(); | 358 list->Finalize(); |
358 memory_usage = list->ApproximateMemoryUsage(); | 359 memory_usage = list->ApproximateMemoryUsage(); |
359 EXPECT_GE(memory_usage, picture_size); | 360 EXPECT_GE(memory_usage, picture_size); |
360 EXPECT_LE(memory_usage, 2 * picture_size); | 361 EXPECT_LE(memory_usage, 2 * picture_size); |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); | 730 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); |
730 | 731 |
731 EXPECT_EQ(4u, list->size()); | 732 EXPECT_EQ(4u, list->size()); |
732 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(0)); | 733 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(0)); |
733 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(1)); | 734 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(1)); |
734 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(2)); | 735 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(2)); |
735 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(3)); | 736 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(3)); |
736 } | 737 } |
737 | 738 |
738 } // namespace cc | 739 } // namespace cc |
OLD | NEW |