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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "cc/output/filter_operation.h" | 9 #include "cc/output/filter_operation.h" |
10 #include "cc/output/filter_operations.h" | 10 #include "cc/output/filter_operations.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 | 36 |
37 namespace { | 37 namespace { |
38 | 38 |
39 const gfx::Rect kVisualRect(0, 0, 42, 42); | 39 const gfx::Rect kVisualRect(0, 0, 42, 42); |
40 | 40 |
41 void AppendFirstSerializationTestPicture(scoped_refptr<DisplayItemList> list, | 41 void AppendFirstSerializationTestPicture(scoped_refptr<DisplayItemList> list, |
42 const gfx::Size& layer_size) { | 42 const gfx::Size& layer_size) { |
43 gfx::PointF offset(2.f, 3.f); | 43 gfx::PointF offset(2.f, 3.f); |
44 SkPictureRecorder recorder; | 44 SkPictureRecorder recorder; |
45 skia::RefPtr<SkCanvas> canvas; | 45 skia::RefPtr<SkCanvas> canvas; |
| 46 skia::RefPtr<SkPicture> picture; |
46 | 47 |
47 SkPaint red_paint; | 48 SkPaint red_paint; |
48 red_paint.setColor(SK_ColorRED); | 49 red_paint.setColor(SK_ColorRED); |
49 | 50 |
50 canvas = skia::SharePtr(recorder.beginRecording(SkRect::MakeXYWH( | 51 canvas = skia::SharePtr(recorder.beginRecording(SkRect::MakeXYWH( |
51 offset.x(), offset.y(), layer_size.width(), layer_size.height()))); | 52 offset.x(), offset.y(), layer_size.width(), layer_size.height()))); |
52 canvas->translate(offset.x(), offset.y()); | 53 canvas->translate(offset.x(), offset.y()); |
53 canvas->drawRectCoords(0.f, 0.f, 4.f, 4.f, red_paint); | 54 canvas->drawRectCoords(0.f, 0.f, 4.f, 4.f, red_paint); |
54 list->CreateAndAppendItem<DrawingDisplayItem>( | 55 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
55 kVisualRect, skia::AdoptRef(recorder.endRecordingAsPicture())); | 56 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect)->SetNew(picture); |
56 } | 57 } |
57 | 58 |
58 void AppendSecondSerializationTestPicture(scoped_refptr<DisplayItemList> list, | 59 void AppendSecondSerializationTestPicture(scoped_refptr<DisplayItemList> list, |
59 const gfx::Size& layer_size) { | 60 const gfx::Size& layer_size) { |
60 gfx::PointF offset(2.f, 2.f); | 61 gfx::PointF offset(2.f, 2.f); |
61 SkPictureRecorder recorder; | 62 SkPictureRecorder recorder; |
62 skia::RefPtr<SkCanvas> canvas; | 63 skia::RefPtr<SkCanvas> canvas; |
| 64 skia::RefPtr<SkPicture> picture; |
63 | 65 |
64 SkPaint blue_paint; | 66 SkPaint blue_paint; |
65 blue_paint.setColor(SK_ColorBLUE); | 67 blue_paint.setColor(SK_ColorBLUE); |
66 | 68 |
67 canvas = skia::SharePtr(recorder.beginRecording(SkRect::MakeXYWH( | 69 canvas = skia::SharePtr(recorder.beginRecording(SkRect::MakeXYWH( |
68 offset.x(), offset.y(), layer_size.width(), layer_size.height()))); | 70 offset.x(), offset.y(), layer_size.width(), layer_size.height()))); |
69 canvas->translate(offset.x(), offset.y()); | 71 canvas->translate(offset.x(), offset.y()); |
70 canvas->drawRectCoords(3.f, 3.f, 7.f, 7.f, blue_paint); | 72 canvas->drawRectCoords(3.f, 3.f, 7.f, 7.f, blue_paint); |
71 list->CreateAndAppendItem<DrawingDisplayItem>( | 73 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
72 kVisualRect, skia::AdoptRef(recorder.endRecordingAsPicture())); | 74 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect)->SetNew(picture); |
73 } | 75 } |
74 | 76 |
75 void ValidateDisplayItemListSerialization(const gfx::Size& layer_size, | 77 void ValidateDisplayItemListSerialization(const gfx::Size& layer_size, |
76 scoped_refptr<DisplayItemList> list) { | 78 scoped_refptr<DisplayItemList> list) { |
77 list->Finalize(); | 79 list->Finalize(); |
78 | 80 |
79 // Serialize and deserialize the DisplayItemList. | 81 // Serialize and deserialize the DisplayItemList. |
80 proto::DisplayItemList proto; | 82 proto::DisplayItemList proto; |
81 list->ToProtobuf(&proto); | 83 list->ToProtobuf(&proto); |
82 scoped_refptr<DisplayItemList> new_list = | 84 scoped_refptr<DisplayItemList> new_list = |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 scoped_refptr<DisplayItemList> list = | 144 scoped_refptr<DisplayItemList> list = |
143 DisplayItemList::Create(gfx::Rect(layer_size), settings); | 145 DisplayItemList::Create(gfx::Rect(layer_size), settings); |
144 | 146 |
145 // Build the DrawingDisplayItem. | 147 // Build the DrawingDisplayItem. |
146 AppendFirstSerializationTestPicture(list, layer_size); | 148 AppendFirstSerializationTestPicture(list, layer_size); |
147 | 149 |
148 // Build the ClipDisplayItem. | 150 // Build the ClipDisplayItem. |
149 gfx::Rect clip_rect(6, 6, 1, 1); | 151 gfx::Rect clip_rect(6, 6, 1, 1); |
150 std::vector<SkRRect> rrects; | 152 std::vector<SkRRect> rrects; |
151 rrects.push_back(SkRRect::MakeOval(SkRect::MakeXYWH(5.f, 5.f, 4.f, 4.f))); | 153 rrects.push_back(SkRRect::MakeOval(SkRect::MakeXYWH(5.f, 5.f, 4.f, 4.f))); |
152 list->CreateAndAppendItem<ClipDisplayItem>(kVisualRect, clip_rect, rrects); | 154 auto* item = list->CreateAndAppendItem<ClipDisplayItem>(kVisualRect); |
| 155 item->SetNew(clip_rect, rrects); |
153 | 156 |
154 // Build the second DrawingDisplayItem. | 157 // Build the second DrawingDisplayItem. |
155 AppendSecondSerializationTestPicture(list, layer_size); | 158 AppendSecondSerializationTestPicture(list, layer_size); |
156 | 159 |
157 // Build the EndClipDisplayItem. | 160 // Build the EndClipDisplayItem. |
158 list->CreateAndAppendItem<EndClipDisplayItem>(kVisualRect); | 161 list->CreateAndAppendItem<EndClipDisplayItem>(kVisualRect); |
159 | 162 |
160 ValidateDisplayItemListSerialization(layer_size, list); | 163 ValidateDisplayItemListSerialization(layer_size, list); |
161 } | 164 } |
162 | 165 |
163 TEST(DisplayItemListTest, SerializeClipPathItem) { | 166 TEST(DisplayItemListTest, SerializeClipPathItem) { |
164 gfx::Size layer_size(10, 10); | 167 gfx::Size layer_size(10, 10); |
165 | 168 |
166 DisplayItemListSettings settings; | 169 DisplayItemListSettings settings; |
167 scoped_refptr<DisplayItemList> list = | 170 scoped_refptr<DisplayItemList> list = |
168 DisplayItemList::Create(gfx::Rect(layer_size), settings); | 171 DisplayItemList::Create(gfx::Rect(layer_size), settings); |
169 | 172 |
170 // Build the DrawingDisplayItem. | 173 // Build the DrawingDisplayItem. |
171 AppendFirstSerializationTestPicture(list, layer_size); | 174 AppendFirstSerializationTestPicture(list, layer_size); |
172 | 175 |
173 // Build the ClipPathDisplayItem. | 176 // Build the ClipPathDisplayItem. |
174 SkPath path; | 177 SkPath path; |
175 path.addCircle(5.f, 5.f, 2.f, SkPath::Direction::kCW_Direction); | 178 path.addCircle(5.f, 5.f, 2.f, SkPath::Direction::kCW_Direction); |
176 list->CreateAndAppendItem<ClipPathDisplayItem>( | 179 auto* item = list->CreateAndAppendItem<ClipPathDisplayItem>(kVisualRect); |
177 kVisualRect, path, SkRegion::Op::kReplace_Op, false); | 180 item->SetNew(path, SkRegion::Op::kReplace_Op, false); |
178 | 181 |
179 // Build the second DrawingDisplayItem. | 182 // Build the second DrawingDisplayItem. |
180 AppendSecondSerializationTestPicture(list, layer_size); | 183 AppendSecondSerializationTestPicture(list, layer_size); |
181 | 184 |
182 // Build the EndClipPathDisplayItem. | 185 // Build the EndClipPathDisplayItem. |
183 list->CreateAndAppendItem<EndClipPathDisplayItem>(kVisualRect); | 186 list->CreateAndAppendItem<EndClipPathDisplayItem>(kVisualRect); |
184 | 187 |
185 ValidateDisplayItemListSerialization(layer_size, list); | 188 ValidateDisplayItemListSerialization(layer_size, list); |
186 } | 189 } |
187 | 190 |
188 TEST(DisplayItemListTest, SerializeCompositingItem) { | 191 TEST(DisplayItemListTest, SerializeCompositingItem) { |
189 gfx::Size layer_size(10, 10); | 192 gfx::Size layer_size(10, 10); |
190 | 193 |
191 DisplayItemListSettings settings; | 194 DisplayItemListSettings settings; |
192 scoped_refptr<DisplayItemList> list = | 195 scoped_refptr<DisplayItemList> list = |
193 DisplayItemList::Create(gfx::Rect(layer_size), settings); | 196 DisplayItemList::Create(gfx::Rect(layer_size), settings); |
194 | 197 |
195 // Build the DrawingDisplayItem. | 198 // Build the DrawingDisplayItem. |
196 AppendFirstSerializationTestPicture(list, layer_size); | 199 AppendFirstSerializationTestPicture(list, layer_size); |
197 | 200 |
198 // Build the CompositingDisplayItem. | 201 // Build the CompositingDisplayItem. |
199 skia::RefPtr<SkColorFilter> filter = skia::AdoptRef( | 202 skia::RefPtr<SkColorFilter> filter = skia::AdoptRef( |
200 SkColorFilter::CreateLightingFilter(SK_ColorRED, SK_ColorGREEN)); | 203 SkColorFilter::CreateLightingFilter(SK_ColorRED, SK_ColorGREEN)); |
201 list->CreateAndAppendItem<CompositingDisplayItem>( | 204 auto* item = list->CreateAndAppendItem<CompositingDisplayItem>(kVisualRect); |
202 kVisualRect, 150, SkXfermode::Mode::kDst_Mode, nullptr, filter); | 205 item->SetNew(150, SkXfermode::Mode::kDst_Mode, nullptr, filter); |
203 | 206 |
204 // Build the second DrawingDisplayItem. | 207 // Build the second DrawingDisplayItem. |
205 AppendSecondSerializationTestPicture(list, layer_size); | 208 AppendSecondSerializationTestPicture(list, layer_size); |
206 | 209 |
207 // Build the EndCompositingDisplayItem. | 210 // Build the EndCompositingDisplayItem. |
208 list->CreateAndAppendItem<EndCompositingDisplayItem>(kVisualRect); | 211 list->CreateAndAppendItem<EndCompositingDisplayItem>(kVisualRect); |
209 | 212 |
210 ValidateDisplayItemListSerialization(layer_size, list); | 213 ValidateDisplayItemListSerialization(layer_size, list); |
211 } | 214 } |
212 | 215 |
213 TEST(DisplayItemListTest, SerializeFloatClipItem) { | 216 TEST(DisplayItemListTest, SerializeFloatClipItem) { |
214 gfx::Size layer_size(10, 10); | 217 gfx::Size layer_size(10, 10); |
215 | 218 |
216 DisplayItemListSettings settings; | 219 DisplayItemListSettings settings; |
217 scoped_refptr<DisplayItemList> list = | 220 scoped_refptr<DisplayItemList> list = |
218 DisplayItemList::Create(gfx::Rect(layer_size), settings); | 221 DisplayItemList::Create(gfx::Rect(layer_size), settings); |
219 | 222 |
220 // Build the DrawingDisplayItem. | 223 // Build the DrawingDisplayItem. |
221 AppendFirstSerializationTestPicture(list, layer_size); | 224 AppendFirstSerializationTestPicture(list, layer_size); |
222 | 225 |
223 // Build the FloatClipDisplayItem. | 226 // Build the FloatClipDisplayItem. |
224 gfx::RectF clip_rect(6.f, 6.f, 1.f, 1.f); | 227 gfx::RectF clip_rect(6.f, 6.f, 1.f, 1.f); |
225 list->CreateAndAppendItem<FloatClipDisplayItem>(kVisualRect, clip_rect); | 228 auto* item2 = list->CreateAndAppendItem<FloatClipDisplayItem>(kVisualRect); |
| 229 item2->SetNew(clip_rect); |
226 | 230 |
227 // Build the second DrawingDisplayItem. | 231 // Build the second DrawingDisplayItem. |
228 AppendSecondSerializationTestPicture(list, layer_size); | 232 AppendSecondSerializationTestPicture(list, layer_size); |
229 | 233 |
230 // Build the EndFloatClipDisplayItem. | 234 // Build the EndFloatClipDisplayItem. |
231 list->CreateAndAppendItem<EndFloatClipDisplayItem>(kVisualRect); | 235 list->CreateAndAppendItem<EndFloatClipDisplayItem>(kVisualRect); |
232 | 236 |
233 ValidateDisplayItemListSerialization(layer_size, list); | 237 ValidateDisplayItemListSerialization(layer_size, list); |
234 } | 238 } |
235 | 239 |
236 TEST(DisplayItemListTest, SerializeTransformItem) { | 240 TEST(DisplayItemListTest, SerializeTransformItem) { |
237 gfx::Size layer_size(10, 10); | 241 gfx::Size layer_size(10, 10); |
238 | 242 |
239 DisplayItemListSettings settings; | 243 DisplayItemListSettings settings; |
240 scoped_refptr<DisplayItemList> list = | 244 scoped_refptr<DisplayItemList> list = |
241 DisplayItemList::Create(gfx::Rect(layer_size), settings); | 245 DisplayItemList::Create(gfx::Rect(layer_size), settings); |
242 | 246 |
243 // Build the DrawingDisplayItem. | 247 // Build the DrawingDisplayItem. |
244 AppendFirstSerializationTestPicture(list, layer_size); | 248 AppendFirstSerializationTestPicture(list, layer_size); |
245 | 249 |
246 // Build the TransformDisplayItem. | 250 // Build the TransformDisplayItem. |
247 gfx::Transform transform; | 251 gfx::Transform transform; |
248 transform.Scale(1.25f, 1.25f); | 252 transform.Scale(1.25f, 1.25f); |
249 transform.Translate(-1.f, -1.f); | 253 transform.Translate(-1.f, -1.f); |
250 list->CreateAndAppendItem<TransformDisplayItem>(kVisualRect, transform); | 254 auto* item2 = list->CreateAndAppendItem<TransformDisplayItem>(kVisualRect); |
| 255 item2->SetNew(transform); |
251 | 256 |
252 // Build the second DrawingDisplayItem. | 257 // Build the second DrawingDisplayItem. |
253 AppendSecondSerializationTestPicture(list, layer_size); | 258 AppendSecondSerializationTestPicture(list, layer_size); |
254 | 259 |
255 // Build the EndTransformDisplayItem. | 260 // Build the EndTransformDisplayItem. |
256 list->CreateAndAppendItem<EndTransformDisplayItem>(kVisualRect); | 261 list->CreateAndAppendItem<EndTransformDisplayItem>(kVisualRect); |
257 | 262 |
258 ValidateDisplayItemListSerialization(layer_size, list); | 263 ValidateDisplayItemListSerialization(layer_size, list); |
259 } | 264 } |
260 | 265 |
(...skipping 12 matching lines...) Expand all Loading... |
273 DisplayItemList::Create(layer_rect, settings); | 278 DisplayItemList::Create(layer_rect, settings); |
274 | 279 |
275 gfx::PointF offset(8.f, 9.f); | 280 gfx::PointF offset(8.f, 9.f); |
276 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size())); | 281 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size())); |
277 canvas = skia::SharePtr( | 282 canvas = skia::SharePtr( |
278 recorder.beginRecording(gfx::RectFToSkRect(recording_rect))); | 283 recorder.beginRecording(gfx::RectFToSkRect(recording_rect))); |
279 canvas->translate(offset.x(), offset.y()); | 284 canvas->translate(offset.x(), offset.y()); |
280 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); | 285 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); |
281 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); | 286 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); |
282 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 287 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
283 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, | 288 auto* item = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); |
284 std::move(picture)); | 289 item->SetNew(picture); |
285 list->Finalize(); | 290 list->Finalize(); |
286 DrawDisplayList(pixels, layer_rect, list); | 291 DrawDisplayList(pixels, layer_rect, list); |
287 | 292 |
288 SkBitmap expected_bitmap; | 293 SkBitmap expected_bitmap; |
289 unsigned char expected_pixels[4 * 100 * 100] = {0}; | 294 unsigned char expected_pixels[4 * 100 * 100] = {0}; |
290 SkImageInfo info = | 295 SkImageInfo info = |
291 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); | 296 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); |
292 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); | 297 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); |
293 SkCanvas expected_canvas(expected_bitmap); | 298 SkCanvas expected_canvas(expected_bitmap); |
294 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect)); | 299 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect)); |
295 expected_canvas.drawRectCoords(0.f + offset.x(), 0.f + offset.y(), | 300 expected_canvas.drawRectCoords(0.f + offset.x(), 0.f + offset.y(), |
296 60.f + offset.x(), 60.f + offset.y(), | 301 60.f + offset.x(), 60.f + offset.y(), |
297 red_paint); | 302 red_paint); |
298 expected_canvas.drawRectCoords(50.f + offset.x(), 50.f + offset.y(), | 303 expected_canvas.drawRectCoords(50.f + offset.x(), 50.f + offset.y(), |
299 75.f + offset.x(), 75.f + offset.y(), | 304 75.f + offset.x(), 75.f + offset.y(), |
300 blue_paint); | 305 blue_paint); |
301 | 306 |
302 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); | 307 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); |
303 } | 308 } |
304 | 309 |
305 TEST(DisplayItemListTest, ClipItem) { | 310 TEST(DisplayItemListTest, ClipItem) { |
306 gfx::Rect layer_rect(100, 100); | 311 gfx::Rect layer_rect(100, 100); |
307 SkPictureRecorder recorder; | 312 SkPictureRecorder recorder; |
308 skia::RefPtr<SkCanvas> canvas; | 313 skia::RefPtr<SkCanvas> canvas; |
| 314 skia::RefPtr<SkPicture> picture; |
309 SkPaint blue_paint; | 315 SkPaint blue_paint; |
310 blue_paint.setColor(SK_ColorBLUE); | 316 blue_paint.setColor(SK_ColorBLUE); |
311 SkPaint red_paint; | 317 SkPaint red_paint; |
312 red_paint.setColor(SK_ColorRED); | 318 red_paint.setColor(SK_ColorRED); |
313 unsigned char pixels[4 * 100 * 100] = {0}; | 319 unsigned char pixels[4 * 100 * 100] = {0}; |
314 DisplayItemListSettings settings; | 320 DisplayItemListSettings settings; |
315 settings.use_cached_picture = true; | 321 settings.use_cached_picture = true; |
316 scoped_refptr<DisplayItemList> list = | 322 scoped_refptr<DisplayItemList> list = |
317 DisplayItemList::Create(layer_rect, settings); | 323 DisplayItemList::Create(layer_rect, settings); |
318 | 324 |
319 gfx::PointF first_offset(8.f, 9.f); | 325 gfx::PointF first_offset(8.f, 9.f); |
320 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); | 326 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); |
321 canvas = skia::SharePtr( | 327 canvas = skia::SharePtr( |
322 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect))); | 328 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect))); |
323 canvas->translate(first_offset.x(), first_offset.y()); | 329 canvas->translate(first_offset.x(), first_offset.y()); |
324 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); | 330 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); |
325 list->CreateAndAppendItem<DrawingDisplayItem>( | 331 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
326 kVisualRect, skia::AdoptRef(recorder.endRecordingAsPicture())); | 332 auto* item1 = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); |
| 333 item1->SetNew(std::move(picture)); |
327 | 334 |
328 gfx::Rect clip_rect(60, 60, 10, 10); | 335 gfx::Rect clip_rect(60, 60, 10, 10); |
329 list->CreateAndAppendItem<ClipDisplayItem>(kVisualRect, clip_rect, | 336 auto* item2 = list->CreateAndAppendItem<ClipDisplayItem>(kVisualRect); |
330 std::vector<SkRRect>()); | 337 item2->SetNew(clip_rect, std::vector<SkRRect>()); |
331 | 338 |
332 gfx::PointF second_offset(2.f, 3.f); | 339 gfx::PointF second_offset(2.f, 3.f); |
333 gfx::RectF second_recording_rect(second_offset, | 340 gfx::RectF second_recording_rect(second_offset, |
334 gfx::SizeF(layer_rect.size())); | 341 gfx::SizeF(layer_rect.size())); |
335 canvas = skia::SharePtr( | 342 canvas = skia::SharePtr( |
336 recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect))); | 343 recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect))); |
337 canvas->translate(second_offset.x(), second_offset.y()); | 344 canvas->translate(second_offset.x(), second_offset.y()); |
338 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); | 345 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); |
339 list->CreateAndAppendItem<DrawingDisplayItem>( | 346 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
340 kVisualRect, skia::AdoptRef(recorder.endRecordingAsPicture())); | 347 auto* item3 = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); |
| 348 item3->SetNew(std::move(picture)); |
341 | 349 |
342 list->CreateAndAppendItem<EndClipDisplayItem>(kVisualRect); | 350 list->CreateAndAppendItem<EndClipDisplayItem>(kVisualRect); |
343 list->Finalize(); | 351 list->Finalize(); |
344 | 352 |
345 DrawDisplayList(pixels, layer_rect, list); | 353 DrawDisplayList(pixels, layer_rect, list); |
346 | 354 |
347 SkBitmap expected_bitmap; | 355 SkBitmap expected_bitmap; |
348 unsigned char expected_pixels[4 * 100 * 100] = {0}; | 356 unsigned char expected_pixels[4 * 100 * 100] = {0}; |
349 SkImageInfo info = | 357 SkImageInfo info = |
350 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); | 358 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); |
351 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); | 359 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); |
352 SkCanvas expected_canvas(expected_bitmap); | 360 SkCanvas expected_canvas(expected_bitmap); |
353 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect)); | 361 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect)); |
354 expected_canvas.drawRectCoords(0.f + first_offset.x(), 0.f + first_offset.y(), | 362 expected_canvas.drawRectCoords(0.f + first_offset.x(), 0.f + first_offset.y(), |
355 60.f + first_offset.x(), | 363 60.f + first_offset.x(), |
356 60.f + first_offset.y(), red_paint); | 364 60.f + first_offset.y(), red_paint); |
357 expected_canvas.clipRect(gfx::RectToSkRect(clip_rect)); | 365 expected_canvas.clipRect(gfx::RectToSkRect(clip_rect)); |
358 expected_canvas.drawRectCoords( | 366 expected_canvas.drawRectCoords( |
359 50.f + second_offset.x(), 50.f + second_offset.y(), | 367 50.f + second_offset.x(), 50.f + second_offset.y(), |
360 75.f + second_offset.x(), 75.f + second_offset.y(), blue_paint); | 368 75.f + second_offset.x(), 75.f + second_offset.y(), blue_paint); |
361 | 369 |
362 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); | 370 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); |
363 } | 371 } |
364 | 372 |
365 TEST(DisplayItemListTest, TransformItem) { | 373 TEST(DisplayItemListTest, TransformItem) { |
366 gfx::Rect layer_rect(100, 100); | 374 gfx::Rect layer_rect(100, 100); |
367 SkPictureRecorder recorder; | 375 SkPictureRecorder recorder; |
368 skia::RefPtr<SkCanvas> canvas; | 376 skia::RefPtr<SkCanvas> canvas; |
| 377 skia::RefPtr<SkPicture> picture; |
369 SkPaint blue_paint; | 378 SkPaint blue_paint; |
370 blue_paint.setColor(SK_ColorBLUE); | 379 blue_paint.setColor(SK_ColorBLUE); |
371 SkPaint red_paint; | 380 SkPaint red_paint; |
372 red_paint.setColor(SK_ColorRED); | 381 red_paint.setColor(SK_ColorRED); |
373 unsigned char pixels[4 * 100 * 100] = {0}; | 382 unsigned char pixels[4 * 100 * 100] = {0}; |
374 DisplayItemListSettings settings; | 383 DisplayItemListSettings settings; |
375 settings.use_cached_picture = true; | 384 settings.use_cached_picture = true; |
376 scoped_refptr<DisplayItemList> list = | 385 scoped_refptr<DisplayItemList> list = |
377 DisplayItemList::Create(layer_rect, settings); | 386 DisplayItemList::Create(layer_rect, settings); |
378 | 387 |
379 gfx::PointF first_offset(8.f, 9.f); | 388 gfx::PointF first_offset(8.f, 9.f); |
380 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); | 389 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); |
381 canvas = skia::SharePtr( | 390 canvas = skia::SharePtr( |
382 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect))); | 391 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect))); |
383 canvas->translate(first_offset.x(), first_offset.y()); | 392 canvas->translate(first_offset.x(), first_offset.y()); |
384 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); | 393 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); |
385 list->CreateAndAppendItem<DrawingDisplayItem>( | 394 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
386 kVisualRect, skia::AdoptRef(recorder.endRecordingAsPicture())); | 395 auto* item1 = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); |
| 396 item1->SetNew(picture); |
387 | 397 |
388 gfx::Transform transform; | 398 gfx::Transform transform; |
389 transform.Rotate(45.0); | 399 transform.Rotate(45.0); |
390 list->CreateAndAppendItem<TransformDisplayItem>(kVisualRect, transform); | 400 auto* item2 = list->CreateAndAppendItem<TransformDisplayItem>(kVisualRect); |
| 401 item2->SetNew(transform); |
391 | 402 |
392 gfx::PointF second_offset(2.f, 3.f); | 403 gfx::PointF second_offset(2.f, 3.f); |
393 gfx::RectF second_recording_rect(second_offset, | 404 gfx::RectF second_recording_rect(second_offset, |
394 gfx::SizeF(layer_rect.size())); | 405 gfx::SizeF(layer_rect.size())); |
395 canvas = skia::SharePtr( | 406 canvas = skia::SharePtr( |
396 recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect))); | 407 recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect))); |
397 canvas->translate(second_offset.x(), second_offset.y()); | 408 canvas->translate(second_offset.x(), second_offset.y()); |
398 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); | 409 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); |
399 list->CreateAndAppendItem<DrawingDisplayItem>( | 410 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
400 kVisualRect, skia::AdoptRef(recorder.endRecordingAsPicture())); | 411 auto* item3 = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); |
| 412 item3->SetNew(picture); |
401 | 413 |
402 list->CreateAndAppendItem<EndTransformDisplayItem>(kVisualRect); | 414 list->CreateAndAppendItem<EndTransformDisplayItem>(kVisualRect); |
403 list->Finalize(); | 415 list->Finalize(); |
404 | 416 |
405 DrawDisplayList(pixels, layer_rect, list); | 417 DrawDisplayList(pixels, layer_rect, list); |
406 | 418 |
407 SkBitmap expected_bitmap; | 419 SkBitmap expected_bitmap; |
408 unsigned char expected_pixels[4 * 100 * 100] = {0}; | 420 unsigned char expected_pixels[4 * 100 * 100] = {0}; |
409 SkImageInfo info = | 421 SkImageInfo info = |
410 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); | 422 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 // translating |dst| after it is computed by computeFastBounds, rather than | 459 // translating |dst| after it is computed by computeFastBounds, rather than |
448 // translating |src| before it provided to computedFastBounds) can cause | 460 // translating |src| before it provided to computedFastBounds) can cause |
449 // incorrect clipping of filter output. To test for this, we include an | 461 // incorrect clipping of filter output. To test for this, we include an |
450 // SkImageSource filter in |filters|. Here, |src| is |filter_bounds|, defined | 462 // SkImageSource filter in |filters|. Here, |src| is |filter_bounds|, defined |
451 // below. | 463 // below. |
452 skia::RefPtr<SkImageFilter> image_filter = | 464 skia::RefPtr<SkImageFilter> image_filter = |
453 skia::AdoptRef(SkImageSource::Create(source_image.get())); | 465 skia::AdoptRef(SkImageSource::Create(source_image.get())); |
454 filters.Append(FilterOperation::CreateReferenceFilter(image_filter)); | 466 filters.Append(FilterOperation::CreateReferenceFilter(image_filter)); |
455 filters.Append(FilterOperation::CreateBrightnessFilter(0.5f)); | 467 filters.Append(FilterOperation::CreateBrightnessFilter(0.5f)); |
456 gfx::RectF filter_bounds(10.f, 10.f, 50.f, 50.f); | 468 gfx::RectF filter_bounds(10.f, 10.f, 50.f, 50.f); |
457 list->CreateAndAppendItem<FilterDisplayItem>(kVisualRect, filters, | 469 auto* item = list->CreateAndAppendItem<FilterDisplayItem>(kVisualRect); |
458 filter_bounds); | 470 item->SetNew(filters, filter_bounds); |
459 list->CreateAndAppendItem<EndFilterDisplayItem>(kVisualRect); | 471 list->CreateAndAppendItem<EndFilterDisplayItem>(kVisualRect); |
460 list->Finalize(); | 472 list->Finalize(); |
461 | 473 |
462 DrawDisplayList(pixels, layer_rect, list); | 474 DrawDisplayList(pixels, layer_rect, list); |
463 | 475 |
464 SkBitmap expected_bitmap; | 476 SkBitmap expected_bitmap; |
465 unsigned char expected_pixels[4 * 100 * 100] = {0}; | 477 unsigned char expected_pixels[4 * 100 * 100] = {0}; |
466 SkPaint paint; | 478 SkPaint paint; |
467 paint.setColor(SkColorSetRGB(64, 64, 64)); | 479 paint.setColor(SkColorSetRGB(64, 64, 64)); |
468 SkImageInfo info = | 480 SkImageInfo info = |
(...skipping 23 matching lines...) Expand all Loading... |
492 no_caching_settings.use_cached_picture = false; | 504 no_caching_settings.use_cached_picture = false; |
493 scoped_refptr<DisplayItemList> list_without_caching = | 505 scoped_refptr<DisplayItemList> list_without_caching = |
494 DisplayItemList::Create(layer_rect, no_caching_settings); | 506 DisplayItemList::Create(layer_rect, no_caching_settings); |
495 | 507 |
496 canvas = skia::SharePtr( | 508 canvas = skia::SharePtr( |
497 recorder.beginRecording(gfx::RectFToSkRect(recording_rect))); | 509 recorder.beginRecording(gfx::RectFToSkRect(recording_rect))); |
498 canvas->translate(offset.x(), offset.y()); | 510 canvas->translate(offset.x(), offset.y()); |
499 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); | 511 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); |
500 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); | 512 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); |
501 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 513 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
502 list_without_caching->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, | 514 auto* item1 = list_without_caching->CreateAndAppendItem<DrawingDisplayItem>( |
503 picture); | 515 kVisualRect); |
| 516 item1->SetNew(picture); |
504 list_without_caching->Finalize(); | 517 list_without_caching->Finalize(); |
505 DrawDisplayList(pixels, layer_rect, list_without_caching); | 518 DrawDisplayList(pixels, layer_rect, list_without_caching); |
506 | 519 |
507 unsigned char expected_pixels[4 * 100 * 100] = {0}; | 520 unsigned char expected_pixels[4 * 100 * 100] = {0}; |
508 DisplayItemListSettings caching_settings; | 521 DisplayItemListSettings caching_settings; |
509 caching_settings.use_cached_picture = true; | 522 caching_settings.use_cached_picture = true; |
510 scoped_refptr<DisplayItemList> list_with_caching = | 523 scoped_refptr<DisplayItemList> list_with_caching = |
511 DisplayItemList::Create(layer_rect, caching_settings); | 524 DisplayItemList::Create(layer_rect, caching_settings); |
512 list_with_caching->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, | 525 auto* item2 = |
513 picture); | 526 list_with_caching->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); |
| 527 item2->SetNew(picture); |
514 list_with_caching->Finalize(); | 528 list_with_caching->Finalize(); |
515 DrawDisplayList(expected_pixels, layer_rect, list_with_caching); | 529 DrawDisplayList(expected_pixels, layer_rect, list_with_caching); |
516 | 530 |
517 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); | 531 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); |
518 } | 532 } |
519 | 533 |
520 TEST(DisplayItemListTest, IsSuitableForGpuRasterizationWithCachedPicture) { | 534 TEST(DisplayItemListTest, IsSuitableForGpuRasterizationWithCachedPicture) { |
521 gfx::Rect layer_rect(1000, 1000); | 535 gfx::Rect layer_rect(1000, 1000); |
522 SkPictureRecorder recorder; | 536 SkPictureRecorder recorder; |
523 skia::RefPtr<SkCanvas> canvas; | 537 skia::RefPtr<SkCanvas> canvas; |
| 538 skia::RefPtr<SkPicture> picture; |
524 | 539 |
525 DisplayItemListSettings settings; | 540 DisplayItemListSettings settings; |
526 settings.use_cached_picture = true; | 541 settings.use_cached_picture = true; |
527 scoped_refptr<DisplayItemList> list = | 542 scoped_refptr<DisplayItemList> list = |
528 DisplayItemList::Create(layer_rect, settings); | 543 DisplayItemList::Create(layer_rect, settings); |
529 canvas = | 544 canvas = |
530 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); | 545 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); |
531 | 546 |
532 SkPath path; | 547 SkPath path; |
533 path.moveTo(0, 0); | 548 path.moveTo(0, 0); |
534 path.lineTo(0, 100); | 549 path.lineTo(0, 100); |
535 path.lineTo(50, 50); | 550 path.lineTo(50, 50); |
536 path.lineTo(100, 100); | 551 path.lineTo(100, 100); |
537 path.lineTo(100, 0); | 552 path.lineTo(100, 0); |
538 path.close(); | 553 path.close(); |
539 | 554 |
540 SkPaint paint; | 555 SkPaint paint; |
541 paint.setAntiAlias(true); | 556 paint.setAntiAlias(true); |
542 canvas->drawPath(path, paint); | 557 canvas->drawPath(path, paint); |
543 | 558 |
544 list->CreateAndAppendItem<DrawingDisplayItem>( | 559 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
545 kVisualRect, skia::AdoptRef(recorder.endRecordingAsPicture())); | 560 DrawingDisplayItem* item = |
| 561 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); |
| 562 item->SetNew(picture); |
546 list->Finalize(); | 563 list->Finalize(); |
547 | 564 |
548 // A single DrawingDisplayItem with a large AA concave path shouldn't trigger | 565 // A single DrawingDisplayItem with a large AA concave path shouldn't trigger |
549 // a veto. | 566 // a veto. |
550 EXPECT_TRUE(list->IsSuitableForGpuRasterization()); | 567 EXPECT_TRUE(list->IsSuitableForGpuRasterization()); |
551 | 568 |
552 list = DisplayItemList::Create(layer_rect, settings); | 569 list = DisplayItemList::Create(layer_rect, settings); |
553 canvas = | 570 canvas = |
554 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); | 571 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); |
555 for (int i = 0; i < 10; ++i) | 572 for (int i = 0; i < 10; ++i) |
556 canvas->drawPath(path, paint); | 573 canvas->drawPath(path, paint); |
557 list->CreateAndAppendItem<DrawingDisplayItem>( | 574 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
558 kVisualRect, skia::AdoptRef(recorder.endRecordingAsPicture())); | 575 item = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); |
| 576 item->SetNew(picture); |
559 list->Finalize(); | 577 list->Finalize(); |
560 | 578 |
561 // A single DrawingDisplayItem with several large AA concave paths should | 579 // A single DrawingDisplayItem with several large AA concave paths should |
562 // trigger a veto. | 580 // trigger a veto. |
563 EXPECT_FALSE(list->IsSuitableForGpuRasterization()); | 581 EXPECT_FALSE(list->IsSuitableForGpuRasterization()); |
| 582 |
| 583 list = DisplayItemList::Create(layer_rect, settings); |
| 584 for (int i = 0; i < 10; ++i) { |
| 585 canvas = |
| 586 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); |
| 587 canvas->drawPath(path, paint); |
| 588 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
| 589 item = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); |
| 590 item->SetNew(picture); |
| 591 } |
| 592 list->Finalize(); |
| 593 |
| 594 // Having several DrawingDisplayItems that each contain a large AA concave |
| 595 // path should trigger a veto. |
| 596 EXPECT_FALSE(list->IsSuitableForGpuRasterization()); |
564 } | 597 } |
565 | 598 |
566 TEST(DisplayItemListTest, IsSuitableForGpuRasterizationWithoutCachedPicture) { | 599 TEST(DisplayItemListTest, IsSuitableForGpuRasterizationWithoutCachedPicture) { |
567 gfx::Rect layer_rect(1000, 1000); | 600 gfx::Rect layer_rect(1000, 1000); |
568 SkPictureRecorder recorder; | 601 SkPictureRecorder recorder; |
569 skia::RefPtr<SkCanvas> canvas; | 602 skia::RefPtr<SkCanvas> canvas; |
570 skia::RefPtr<SkPicture> picture; | 603 skia::RefPtr<SkPicture> picture; |
571 | 604 |
572 DisplayItemListSettings settings; | 605 DisplayItemListSettings settings; |
573 settings.use_cached_picture = false; | 606 settings.use_cached_picture = false; |
574 scoped_refptr<DisplayItemList> list = | 607 scoped_refptr<DisplayItemList> list = |
575 DisplayItemList::Create(layer_rect, settings); | 608 DisplayItemList::Create(layer_rect, settings); |
576 canvas = | 609 canvas = |
577 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); | 610 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); |
578 | 611 |
579 SkPath path; | 612 SkPath path; |
580 path.moveTo(0, 0); | 613 path.moveTo(0, 0); |
581 path.lineTo(0, 100); | 614 path.lineTo(0, 100); |
582 path.lineTo(50, 50); | 615 path.lineTo(50, 50); |
583 path.lineTo(100, 100); | 616 path.lineTo(100, 100); |
584 path.lineTo(100, 0); | 617 path.lineTo(100, 0); |
585 path.close(); | 618 path.close(); |
586 | 619 |
587 SkPaint paint; | 620 SkPaint paint; |
588 paint.setAntiAlias(true); | 621 paint.setAntiAlias(true); |
589 canvas->drawPath(path, paint); | 622 canvas->drawPath(path, paint); |
590 | 623 |
591 list->CreateAndAppendItem<DrawingDisplayItem>( | 624 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
592 kVisualRect, skia::AdoptRef(recorder.endRecordingAsPicture())); | 625 DrawingDisplayItem* item = |
| 626 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); |
| 627 item->SetNew(picture); |
593 list->Finalize(); | 628 list->Finalize(); |
594 | 629 |
595 // A single DrawingDisplayItem with a large AA concave path shouldn't trigger | 630 // A single DrawingDisplayItem with a large AA concave path shouldn't trigger |
596 // a veto. | 631 // a veto. |
597 EXPECT_TRUE(list->IsSuitableForGpuRasterization()); | 632 EXPECT_TRUE(list->IsSuitableForGpuRasterization()); |
598 | 633 |
599 list = DisplayItemList::Create(layer_rect, settings); | 634 list = DisplayItemList::Create(layer_rect, settings); |
600 canvas = | 635 canvas = |
601 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); | 636 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); |
602 for (int i = 0; i < 10; ++i) | 637 for (int i = 0; i < 10; ++i) |
603 canvas->drawPath(path, paint); | 638 canvas->drawPath(path, paint); |
604 list->CreateAndAppendItem<DrawingDisplayItem>( | 639 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
605 kVisualRect, skia::AdoptRef(recorder.endRecordingAsPicture())); | 640 item = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); |
| 641 item->SetNew(picture); |
606 list->Finalize(); | 642 list->Finalize(); |
607 | 643 |
608 // A single DrawingDisplayItem with several large AA concave paths should | 644 // A single DrawingDisplayItem with several large AA concave paths should |
609 // trigger a veto. | 645 // trigger a veto. |
610 EXPECT_FALSE(list->IsSuitableForGpuRasterization()); | 646 EXPECT_FALSE(list->IsSuitableForGpuRasterization()); |
611 | 647 |
612 list = DisplayItemList::Create(layer_rect, settings); | 648 list = DisplayItemList::Create(layer_rect, settings); |
613 for (int i = 0; i < 10; ++i) { | 649 for (int i = 0; i < 10; ++i) { |
614 canvas = | 650 canvas = |
615 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); | 651 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); |
616 canvas->drawPath(path, paint); | 652 canvas->drawPath(path, paint); |
617 list->CreateAndAppendItem<DrawingDisplayItem>( | 653 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
618 kVisualRect, skia::AdoptRef(recorder.endRecordingAsPicture())); | 654 item = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); |
| 655 item->SetNew(picture); |
619 } | 656 } |
620 list->Finalize(); | 657 list->Finalize(); |
621 | 658 |
622 // Without a cached picture, having several DrawingDisplayItems that each | 659 // Without a cached picture, having several DrawingDisplayItems that each |
623 // contain a single large AA concave will not trigger a veto, since each item | 660 // contain a single large AA concave will not trigger a veto, since each item |
624 // is individually suitable for GPU rasterization. | 661 // is individually suitable for GPU rasterization. |
625 EXPECT_TRUE(list->IsSuitableForGpuRasterization()); | 662 EXPECT_TRUE(list->IsSuitableForGpuRasterization()); |
626 } | 663 } |
627 | 664 |
628 TEST(DisplayItemListTest, ApproximateMemoryUsage) { | 665 TEST(DisplayItemListTest, ApproximateMemoryUsage) { |
(...skipping 11 matching lines...) Expand all Loading... |
640 canvas->drawPaint(blue_paint); | 677 canvas->drawPaint(blue_paint); |
641 skia::RefPtr<SkPicture> picture = | 678 skia::RefPtr<SkPicture> picture = |
642 skia::AdoptRef(recorder.endRecordingAsPicture()); | 679 skia::AdoptRef(recorder.endRecordingAsPicture()); |
643 size_t picture_size = SkPictureUtils::ApproximateBytesUsed(picture.get()); | 680 size_t picture_size = SkPictureUtils::ApproximateBytesUsed(picture.get()); |
644 ASSERT_GE(picture_size, kNumCommandsInTestSkPicture * sizeof(blue_paint)); | 681 ASSERT_GE(picture_size, kNumCommandsInTestSkPicture * sizeof(blue_paint)); |
645 | 682 |
646 // Using a cached picture, we should get about the right size. | 683 // Using a cached picture, we should get about the right size. |
647 DisplayItemListSettings caching_settings; | 684 DisplayItemListSettings caching_settings; |
648 caching_settings.use_cached_picture = true; | 685 caching_settings.use_cached_picture = true; |
649 list = DisplayItemList::Create(layer_rect, caching_settings); | 686 list = DisplayItemList::Create(layer_rect, caching_settings); |
650 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, picture); | 687 auto* item = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); |
| 688 item->SetNew(picture); |
651 list->Finalize(); | 689 list->Finalize(); |
652 memory_usage = list->ApproximateMemoryUsage(); | 690 memory_usage = list->ApproximateMemoryUsage(); |
653 EXPECT_GE(memory_usage, picture_size); | 691 EXPECT_GE(memory_usage, picture_size); |
654 EXPECT_LE(memory_usage, 2 * picture_size); | 692 EXPECT_LE(memory_usage, 2 * picture_size); |
655 | 693 |
656 // Using no cached picture, we should still get the right size. | 694 // Using no cached picture, we should still get the right size. |
657 DisplayItemListSettings no_caching_settings; | 695 DisplayItemListSettings no_caching_settings; |
658 no_caching_settings.use_cached_picture = false; | 696 no_caching_settings.use_cached_picture = false; |
659 list = DisplayItemList::Create(layer_rect, no_caching_settings); | 697 list = DisplayItemList::Create(layer_rect, no_caching_settings); |
660 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, picture); | 698 item = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); |
| 699 item->SetNew(picture); |
661 list->Finalize(); | 700 list->Finalize(); |
662 memory_usage = list->ApproximateMemoryUsage(); | 701 memory_usage = list->ApproximateMemoryUsage(); |
663 EXPECT_GE(memory_usage, picture_size); | 702 EXPECT_GE(memory_usage, picture_size); |
664 EXPECT_LE(memory_usage, 2 * picture_size); | 703 EXPECT_LE(memory_usage, 2 * picture_size); |
665 | 704 |
666 // To avoid double counting, we expect zero size to be computed if both the | 705 // To avoid double counting, we expect zero size to be computed if both the |
667 // picture and items are retained (currently this only happens due to certain | 706 // picture and items are retained (currently this only happens due to certain |
668 // categories being traced). | 707 // categories being traced). |
669 list = new DisplayItemList(layer_rect, caching_settings, true); | 708 list = new DisplayItemList(layer_rect, caching_settings, true); |
670 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, picture); | 709 item = list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect); |
| 710 item->SetNew(picture); |
671 list->Finalize(); | 711 list->Finalize(); |
672 memory_usage = list->ApproximateMemoryUsage(); | 712 memory_usage = list->ApproximateMemoryUsage(); |
673 EXPECT_EQ(static_cast<size_t>(0), memory_usage); | 713 EXPECT_EQ(static_cast<size_t>(0), memory_usage); |
674 } | 714 } |
675 | 715 |
676 } // namespace cc | 716 } // namespace cc |
OLD | NEW |