Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: cc/playback/display_item_list_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698