OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/resources/picture.h" | 5 #include "cc/resources/picture.h" |
6 | 6 |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "cc/test/fake_content_layer_client.h" | 10 #include "cc/test/fake_content_layer_client.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 | 50 |
51 // Single full-size rect picture. | 51 // Single full-size rect picture. |
52 content_layer_client.add_draw_rect(layer_rect, red_paint); | 52 content_layer_client.add_draw_rect(layer_rect, red_paint); |
53 | 53 |
54 for (size_t i = 0; i < arraysize(kRecordingModes); ++i) { | 54 for (size_t i = 0; i < arraysize(kRecordingModes); ++i) { |
55 scoped_refptr<Picture> one_rect_picture = | 55 scoped_refptr<Picture> one_rect_picture = |
56 Picture::Create(layer_rect, | 56 Picture::Create(layer_rect, |
57 &content_layer_client, | 57 &content_layer_client, |
58 tile_grid_info, | 58 tile_grid_info, |
59 false, | 59 false, |
| 60 false, |
60 0, | 61 0, |
61 kRecordingModes[i]); | 62 kRecordingModes[i]); |
62 scoped_ptr<base::Value> serialized_one_rect(one_rect_picture->AsValue()); | 63 scoped_ptr<base::Value> serialized_one_rect(one_rect_picture->AsValue()); |
63 | 64 |
64 // Reconstruct the picture. | 65 // Reconstruct the picture. |
65 scoped_refptr<Picture> one_rect_picture_check = | 66 scoped_refptr<Picture> one_rect_picture_check = |
66 Picture::CreateFromValue(serialized_one_rect.get()); | 67 Picture::CreateFromValue(serialized_one_rect.get()); |
67 EXPECT_TRUE(!!one_rect_picture_check.get()); | 68 EXPECT_TRUE(!!one_rect_picture_check.get()); |
68 | 69 |
69 // Check for equivalence. | 70 // Check for equivalence. |
(...skipping 12 matching lines...) Expand all Loading... |
82 | 83 |
83 // Two rect picture. | 84 // Two rect picture. |
84 content_layer_client.add_draw_rect(gfx::Rect(25, 25, 50, 50), green_paint); | 85 content_layer_client.add_draw_rect(gfx::Rect(25, 25, 50, 50), green_paint); |
85 | 86 |
86 for (size_t i = 0; i < arraysize(kRecordingModes); ++i) { | 87 for (size_t i = 0; i < arraysize(kRecordingModes); ++i) { |
87 scoped_refptr<Picture> two_rect_picture = | 88 scoped_refptr<Picture> two_rect_picture = |
88 Picture::Create(layer_rect, | 89 Picture::Create(layer_rect, |
89 &content_layer_client, | 90 &content_layer_client, |
90 tile_grid_info, | 91 tile_grid_info, |
91 false, | 92 false, |
| 93 false, |
92 0, | 94 0, |
93 Picture::RECORD_NORMALLY); | 95 Picture::RECORD_NORMALLY); |
94 | 96 |
95 scoped_ptr<base::Value> serialized_two_rect(two_rect_picture->AsValue()); | 97 scoped_ptr<base::Value> serialized_two_rect(two_rect_picture->AsValue()); |
96 | 98 |
97 // Reconstruct the picture. | 99 // Reconstruct the picture. |
98 scoped_refptr<Picture> two_rect_picture_check = | 100 scoped_refptr<Picture> two_rect_picture_check = |
99 Picture::CreateFromValue(serialized_two_rect.get()); | 101 Picture::CreateFromValue(serialized_two_rect.get()); |
100 EXPECT_TRUE(!!two_rect_picture_check.get()); | 102 EXPECT_TRUE(!!two_rect_picture_check.get()); |
101 | 103 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 discardable_bitmap[y][x], | 147 discardable_bitmap[y][x], |
146 gfx::Point(x * 512 + 6, y * 512 + 6), paint); | 148 gfx::Point(x * 512 + 6, y * 512 + 6), paint); |
147 } | 149 } |
148 } | 150 } |
149 } | 151 } |
150 | 152 |
151 scoped_refptr<Picture> picture = Picture::Create(layer_rect, | 153 scoped_refptr<Picture> picture = Picture::Create(layer_rect, |
152 &content_layer_client, | 154 &content_layer_client, |
153 tile_grid_info, | 155 tile_grid_info, |
154 true, | 156 true, |
| 157 false, |
155 0, | 158 0, |
156 Picture::RECORD_NORMALLY); | 159 Picture::RECORD_NORMALLY); |
157 | 160 |
158 // Default iterator does not have any pixel refs | 161 // Default iterator does not have any pixel refs |
159 { | 162 { |
160 Picture::PixelRefIterator iterator; | 163 Picture::PixelRefIterator iterator; |
161 EXPECT_FALSE(iterator); | 164 EXPECT_FALSE(iterator); |
162 } | 165 } |
163 for (int y = 0; y < 4; ++y) { | 166 for (int y = 0; y < 4; ++y) { |
164 for (int x = 0; x < 4; ++x) { | 167 for (int x = 0; x < 4; ++x) { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 discardable_bitmap[y][x], | 249 discardable_bitmap[y][x], |
247 gfx::Point(1024 + x * 512 + 6, y * 512 + 6), paint); | 250 gfx::Point(1024 + x * 512 + 6, y * 512 + 6), paint); |
248 } | 251 } |
249 } | 252 } |
250 } | 253 } |
251 | 254 |
252 scoped_refptr<Picture> picture = Picture::Create(layer_rect, | 255 scoped_refptr<Picture> picture = Picture::Create(layer_rect, |
253 &content_layer_client, | 256 &content_layer_client, |
254 tile_grid_info, | 257 tile_grid_info, |
255 true, | 258 true, |
| 259 false, |
256 0, | 260 0, |
257 Picture::RECORD_NORMALLY); | 261 Picture::RECORD_NORMALLY); |
258 | 262 |
259 // Default iterator does not have any pixel refs | 263 // Default iterator does not have any pixel refs |
260 { | 264 { |
261 Picture::PixelRefIterator iterator; | 265 Picture::PixelRefIterator iterator; |
262 EXPECT_FALSE(iterator); | 266 EXPECT_FALSE(iterator); |
263 } | 267 } |
264 for (int y = 0; y < 4; ++y) { | 268 for (int y = 0; y < 4; ++y) { |
265 for (int x = 0; x < 4; ++x) { | 269 for (int x = 0; x < 4; ++x) { |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 discardable_bitmap[y][x], | 374 discardable_bitmap[y][x], |
371 gfx::Point(x * 512 + 6, y * 512 + 6), paint); | 375 gfx::Point(x * 512 + 6, y * 512 + 6), paint); |
372 } | 376 } |
373 } | 377 } |
374 } | 378 } |
375 | 379 |
376 scoped_refptr<Picture> picture = Picture::Create(layer_rect, | 380 scoped_refptr<Picture> picture = Picture::Create(layer_rect, |
377 &content_layer_client, | 381 &content_layer_client, |
378 tile_grid_info, | 382 tile_grid_info, |
379 true, | 383 true, |
| 384 false, |
380 0, | 385 0, |
381 Picture::RECORD_NORMALLY); | 386 Picture::RECORD_NORMALLY); |
382 | 387 |
383 for (int y = 0; y < 4; ++y) { | 388 for (int y = 0; y < 4; ++y) { |
384 for (int x = 0; x < 4; ++x) { | 389 for (int x = 0; x < 4; ++x) { |
385 Picture::PixelRefIterator iterator( | 390 Picture::PixelRefIterator iterator( |
386 gfx::Rect(x * 512, y * 512 + 256, 1, 1), picture.get()); | 391 gfx::Rect(x * 512, y * 512 + 256, 1, 1), picture.get()); |
387 if ((x + y) & 1) { | 392 if ((x + y) & 1) { |
388 EXPECT_TRUE(iterator) << x << " " << y; | 393 EXPECT_TRUE(iterator) << x << " " << y; |
389 EXPECT_TRUE(*iterator == discardable_bitmap[y][x].pixelRef()); | 394 EXPECT_TRUE(*iterator == discardable_bitmap[y][x].pixelRef()); |
(...skipping 30 matching lines...) Expand all Loading... |
420 Picture::CreateFromSkpValue(tmp.get()); | 425 Picture::CreateFromSkpValue(tmp.get()); |
421 EXPECT_TRUE(!invalid_picture.get()); | 426 EXPECT_TRUE(!invalid_picture.get()); |
422 | 427 |
423 // Single full-size rect picture. | 428 // Single full-size rect picture. |
424 content_layer_client.add_draw_rect(layer_rect, red_paint); | 429 content_layer_client.add_draw_rect(layer_rect, red_paint); |
425 scoped_refptr<Picture> one_rect_picture = | 430 scoped_refptr<Picture> one_rect_picture = |
426 Picture::Create(layer_rect, | 431 Picture::Create(layer_rect, |
427 &content_layer_client, | 432 &content_layer_client, |
428 tile_grid_info, | 433 tile_grid_info, |
429 false, | 434 false, |
| 435 false, |
430 0, | 436 0, |
431 Picture::RECORD_NORMALLY); | 437 Picture::RECORD_NORMALLY); |
432 scoped_ptr<base::Value> serialized_one_rect( | 438 scoped_ptr<base::Value> serialized_one_rect( |
433 one_rect_picture->AsValue()); | 439 one_rect_picture->AsValue()); |
434 | 440 |
435 const base::DictionaryValue* value = NULL; | 441 const base::DictionaryValue* value = NULL; |
436 EXPECT_TRUE(serialized_one_rect->GetAsDictionary(&value)); | 442 EXPECT_TRUE(serialized_one_rect->GetAsDictionary(&value)); |
437 | 443 |
438 // Decode the picture from base64. | 444 // Decode the picture from base64. |
439 const base::Value* skp_value; | 445 const base::Value* skp_value; |
(...skipping 20 matching lines...) Expand all Loading... |
460 tile_grid_info.fMargin.setEmpty(); | 466 tile_grid_info.fMargin.setEmpty(); |
461 tile_grid_info.fOffset.setZero(); | 467 tile_grid_info.fOffset.setZero(); |
462 | 468 |
463 FakeContentLayerClient content_layer_client; | 469 FakeContentLayerClient content_layer_client; |
464 EXPECT_EQ(NULL, content_layer_client.last_canvas()); | 470 EXPECT_EQ(NULL, content_layer_client.last_canvas()); |
465 | 471 |
466 scoped_refptr<Picture> picture = Picture::Create(layer_rect, | 472 scoped_refptr<Picture> picture = Picture::Create(layer_rect, |
467 &content_layer_client, | 473 &content_layer_client, |
468 tile_grid_info, | 474 tile_grid_info, |
469 false, | 475 false, |
| 476 false, |
470 0, | 477 0, |
471 Picture::RECORD_NORMALLY); | 478 Picture::RECORD_NORMALLY); |
472 EXPECT_TRUE(content_layer_client.last_canvas() != NULL); | 479 EXPECT_TRUE(content_layer_client.last_canvas() != NULL); |
473 EXPECT_EQ(ContentLayerClient::GRAPHICS_CONTEXT_ENABLED, | 480 EXPECT_EQ(ContentLayerClient::GRAPHICS_CONTEXT_ENABLED, |
474 content_layer_client.last_context_status()); | 481 content_layer_client.last_context_status()); |
475 EXPECT_TRUE(picture); | 482 EXPECT_TRUE(picture); |
476 | 483 |
477 picture = Picture::Create(layer_rect, | 484 picture = Picture::Create(layer_rect, |
478 &content_layer_client, | 485 &content_layer_client, |
479 tile_grid_info, | 486 tile_grid_info, |
480 false, | 487 false, |
| 488 false, |
481 0, | 489 0, |
482 Picture::RECORD_WITH_SK_NULL_CANVAS); | 490 Picture::RECORD_WITH_SK_NULL_CANVAS); |
483 EXPECT_TRUE(content_layer_client.last_canvas() != NULL); | 491 EXPECT_TRUE(content_layer_client.last_canvas() != NULL); |
484 EXPECT_EQ(ContentLayerClient::GRAPHICS_CONTEXT_ENABLED, | 492 EXPECT_EQ(ContentLayerClient::GRAPHICS_CONTEXT_ENABLED, |
485 content_layer_client.last_context_status()); | 493 content_layer_client.last_context_status()); |
486 EXPECT_TRUE(picture); | 494 EXPECT_TRUE(picture); |
487 | 495 |
488 picture = Picture::Create(layer_rect, | 496 picture = Picture::Create(layer_rect, |
489 &content_layer_client, | 497 &content_layer_client, |
490 tile_grid_info, | 498 tile_grid_info, |
491 false, | 499 false, |
| 500 false, |
492 0, | 501 0, |
493 Picture::RECORD_WITH_PAINTING_DISABLED); | 502 Picture::RECORD_WITH_PAINTING_DISABLED); |
494 EXPECT_TRUE(content_layer_client.last_canvas() != NULL); | 503 EXPECT_TRUE(content_layer_client.last_canvas() != NULL); |
495 EXPECT_EQ(ContentLayerClient::GRAPHICS_CONTEXT_DISABLED, | 504 EXPECT_EQ(ContentLayerClient::GRAPHICS_CONTEXT_DISABLED, |
496 content_layer_client.last_context_status()); | 505 content_layer_client.last_context_status()); |
497 EXPECT_TRUE(picture); | 506 EXPECT_TRUE(picture); |
498 | 507 |
499 picture = Picture::Create(layer_rect, | 508 picture = Picture::Create(layer_rect, |
500 &content_layer_client, | 509 &content_layer_client, |
501 tile_grid_info, | 510 tile_grid_info, |
502 false, | 511 false, |
| 512 false, |
503 0, | 513 0, |
504 Picture::RECORD_WITH_SKRECORD); | 514 Picture::RECORD_WITH_SKRECORD); |
505 EXPECT_TRUE(content_layer_client.last_canvas() != NULL); | 515 EXPECT_TRUE(content_layer_client.last_canvas() != NULL); |
506 EXPECT_TRUE(picture); | 516 EXPECT_TRUE(picture); |
507 | 517 |
508 EXPECT_EQ(4, Picture::RECORDING_MODE_COUNT); | 518 EXPECT_EQ(4, Picture::RECORDING_MODE_COUNT); |
509 } | 519 } |
510 | 520 |
511 } // namespace | 521 } // namespace |
512 } // namespace cc | 522 } // namespace cc |
OLD | NEW |