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 0, | |
61 kRecordingModes[i]); | 60 kRecordingModes[i]); |
62 scoped_ptr<base::Value> serialized_one_rect(one_rect_picture->AsValue()); | 61 scoped_ptr<base::Value> serialized_one_rect(one_rect_picture->AsValue()); |
63 | 62 |
64 // Reconstruct the picture. | 63 // Reconstruct the picture. |
65 scoped_refptr<Picture> one_rect_picture_check = | 64 scoped_refptr<Picture> one_rect_picture_check = |
66 Picture::CreateFromValue(serialized_one_rect.get()); | 65 Picture::CreateFromValue(serialized_one_rect.get()); |
67 EXPECT_TRUE(!!one_rect_picture_check.get()); | 66 EXPECT_TRUE(!!one_rect_picture_check.get()); |
68 | 67 |
69 // Check for equivalence. | 68 // Check for equivalence. |
70 unsigned char one_rect_buffer[4 * 100 * 100] = {0}; | 69 unsigned char one_rect_buffer[4 * 100 * 100] = {0}; |
71 DrawPicture(one_rect_buffer, layer_rect, one_rect_picture); | 70 DrawPicture(one_rect_buffer, layer_rect, one_rect_picture); |
72 unsigned char one_rect_buffer_check[4 * 100 * 100] = {0}; | 71 unsigned char one_rect_buffer_check[4 * 100 * 100] = {0}; |
73 DrawPicture(one_rect_buffer_check, layer_rect, one_rect_picture_check); | 72 DrawPicture(one_rect_buffer_check, layer_rect, one_rect_picture_check); |
74 | 73 |
75 EXPECT_EQ(one_rect_picture->LayerRect(), | 74 EXPECT_EQ(one_rect_picture->LayerRect(), |
76 one_rect_picture_check->LayerRect()); | 75 one_rect_picture_check->LayerRect()); |
77 EXPECT_EQ(one_rect_picture->OpaqueRect(), | 76 EXPECT_EQ(one_rect_picture->OpaqueRect(), |
78 one_rect_picture_check->OpaqueRect()); | 77 one_rect_picture_check->OpaqueRect()); |
79 EXPECT_TRUE(memcmp(one_rect_buffer, one_rect_buffer_check, 4 * 100 * 100) == | 78 EXPECT_EQ(0, memcmp(one_rect_buffer, one_rect_buffer_check, 4 * 100 * 100)); |
80 0); | |
81 } | 79 } |
82 | 80 |
83 // Two rect picture. | 81 // Two rect picture. |
84 content_layer_client.add_draw_rect(gfx::Rect(25, 25, 50, 50), green_paint); | 82 content_layer_client.add_draw_rect(gfx::Rect(25, 25, 50, 50), green_paint); |
85 | 83 |
86 for (size_t i = 0; i < arraysize(kRecordingModes); ++i) { | 84 for (size_t i = 0; i < arraysize(kRecordingModes); ++i) { |
87 scoped_refptr<Picture> two_rect_picture = | 85 scoped_refptr<Picture> two_rect_picture = |
88 Picture::Create(layer_rect, | 86 Picture::Create(layer_rect, |
89 &content_layer_client, | 87 &content_layer_client, |
90 tile_grid_info, | 88 tile_grid_info, |
91 false, | 89 false, |
92 0, | |
93 Picture::RECORD_NORMALLY); | 90 Picture::RECORD_NORMALLY); |
94 | 91 |
95 scoped_ptr<base::Value> serialized_two_rect(two_rect_picture->AsValue()); | 92 scoped_ptr<base::Value> serialized_two_rect(two_rect_picture->AsValue()); |
96 | 93 |
97 // Reconstruct the picture. | 94 // Reconstruct the picture. |
98 scoped_refptr<Picture> two_rect_picture_check = | 95 scoped_refptr<Picture> two_rect_picture_check = |
99 Picture::CreateFromValue(serialized_two_rect.get()); | 96 Picture::CreateFromValue(serialized_two_rect.get()); |
100 EXPECT_TRUE(!!two_rect_picture_check.get()); | 97 EXPECT_TRUE(!!two_rect_picture_check.get()); |
101 | 98 |
102 // Check for equivalence. | 99 // Check for equivalence. |
103 unsigned char two_rect_buffer[4 * 100 * 100] = {0}; | 100 unsigned char two_rect_buffer[4 * 100 * 100] = {0}; |
104 DrawPicture(two_rect_buffer, layer_rect, two_rect_picture); | 101 DrawPicture(two_rect_buffer, layer_rect, two_rect_picture); |
105 unsigned char two_rect_buffer_check[4 * 100 * 100] = {0}; | 102 unsigned char two_rect_buffer_check[4 * 100 * 100] = {0}; |
106 DrawPicture(two_rect_buffer_check, layer_rect, two_rect_picture_check); | 103 DrawPicture(two_rect_buffer_check, layer_rect, two_rect_picture_check); |
107 | 104 |
108 EXPECT_EQ(two_rect_picture->LayerRect(), | 105 EXPECT_EQ(two_rect_picture->LayerRect(), |
109 two_rect_picture_check->LayerRect()); | 106 two_rect_picture_check->LayerRect()); |
110 EXPECT_EQ(two_rect_picture->OpaqueRect(), | 107 EXPECT_EQ(two_rect_picture->OpaqueRect(), |
111 two_rect_picture_check->OpaqueRect()); | 108 two_rect_picture_check->OpaqueRect()); |
112 EXPECT_TRUE(memcmp(two_rect_buffer, two_rect_buffer_check, 4 * 100 * 100) == | 109 EXPECT_EQ(0, memcmp(two_rect_buffer, two_rect_buffer_check, 4 * 100 * 100)); |
113 0); | |
114 } | 110 } |
115 } | 111 } |
116 | 112 |
117 TEST(PictureTest, PixelRefIterator) { | 113 TEST(PictureTest, PixelRefIterator) { |
118 gfx::Rect layer_rect(2048, 2048); | 114 gfx::Rect layer_rect(2048, 2048); |
119 | 115 |
120 SkTileGridFactory::TileGridInfo tile_grid_info; | 116 SkTileGridFactory::TileGridInfo tile_grid_info; |
121 tile_grid_info.fTileInterval = SkISize::Make(512, 512); | 117 tile_grid_info.fTileInterval = SkISize::Make(512, 512); |
122 tile_grid_info.fMargin.setEmpty(); | 118 tile_grid_info.fMargin.setEmpty(); |
123 tile_grid_info.fOffset.setZero(); | 119 tile_grid_info.fOffset.setZero(); |
(...skipping 21 matching lines...) Expand all Loading... |
145 discardable_bitmap[y][x], | 141 discardable_bitmap[y][x], |
146 gfx::Point(x * 512 + 6, y * 512 + 6), paint); | 142 gfx::Point(x * 512 + 6, y * 512 + 6), paint); |
147 } | 143 } |
148 } | 144 } |
149 } | 145 } |
150 | 146 |
151 scoped_refptr<Picture> picture = Picture::Create(layer_rect, | 147 scoped_refptr<Picture> picture = Picture::Create(layer_rect, |
152 &content_layer_client, | 148 &content_layer_client, |
153 tile_grid_info, | 149 tile_grid_info, |
154 true, | 150 true, |
155 0, | |
156 Picture::RECORD_NORMALLY); | 151 Picture::RECORD_NORMALLY); |
157 | 152 |
158 // Default iterator does not have any pixel refs | 153 // Default iterator does not have any pixel refs |
159 { | 154 { |
160 Picture::PixelRefIterator iterator; | 155 Picture::PixelRefIterator iterator; |
161 EXPECT_FALSE(iterator); | 156 EXPECT_FALSE(iterator); |
162 } | 157 } |
163 for (int y = 0; y < 4; ++y) { | 158 for (int y = 0; y < 4; ++y) { |
164 for (int x = 0; x < 4; ++x) { | 159 for (int x = 0; x < 4; ++x) { |
165 Picture::PixelRefIterator iterator(gfx::Rect(x * 512, y * 512, 500, 500), | 160 Picture::PixelRefIterator iterator(gfx::Rect(x * 512, y * 512, 500, 500), |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 discardable_bitmap[y][x], | 241 discardable_bitmap[y][x], |
247 gfx::Point(1024 + x * 512 + 6, y * 512 + 6), paint); | 242 gfx::Point(1024 + x * 512 + 6, y * 512 + 6), paint); |
248 } | 243 } |
249 } | 244 } |
250 } | 245 } |
251 | 246 |
252 scoped_refptr<Picture> picture = Picture::Create(layer_rect, | 247 scoped_refptr<Picture> picture = Picture::Create(layer_rect, |
253 &content_layer_client, | 248 &content_layer_client, |
254 tile_grid_info, | 249 tile_grid_info, |
255 true, | 250 true, |
256 0, | |
257 Picture::RECORD_NORMALLY); | 251 Picture::RECORD_NORMALLY); |
258 | 252 |
259 // Default iterator does not have any pixel refs | 253 // Default iterator does not have any pixel refs |
260 { | 254 { |
261 Picture::PixelRefIterator iterator; | 255 Picture::PixelRefIterator iterator; |
262 EXPECT_FALSE(iterator); | 256 EXPECT_FALSE(iterator); |
263 } | 257 } |
264 for (int y = 0; y < 4; ++y) { | 258 for (int y = 0; y < 4; ++y) { |
265 for (int x = 0; x < 4; ++x) { | 259 for (int x = 0; x < 4; ++x) { |
266 Picture::PixelRefIterator iterator( | 260 Picture::PixelRefIterator iterator( |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 discardable_bitmap[y][x], | 364 discardable_bitmap[y][x], |
371 gfx::Point(x * 512 + 6, y * 512 + 6), paint); | 365 gfx::Point(x * 512 + 6, y * 512 + 6), paint); |
372 } | 366 } |
373 } | 367 } |
374 } | 368 } |
375 | 369 |
376 scoped_refptr<Picture> picture = Picture::Create(layer_rect, | 370 scoped_refptr<Picture> picture = Picture::Create(layer_rect, |
377 &content_layer_client, | 371 &content_layer_client, |
378 tile_grid_info, | 372 tile_grid_info, |
379 true, | 373 true, |
380 0, | |
381 Picture::RECORD_NORMALLY); | 374 Picture::RECORD_NORMALLY); |
382 | 375 |
383 for (int y = 0; y < 4; ++y) { | 376 for (int y = 0; y < 4; ++y) { |
384 for (int x = 0; x < 4; ++x) { | 377 for (int x = 0; x < 4; ++x) { |
385 Picture::PixelRefIterator iterator( | 378 Picture::PixelRefIterator iterator( |
386 gfx::Rect(x * 512, y * 512 + 256, 1, 1), picture.get()); | 379 gfx::Rect(x * 512, y * 512 + 256, 1, 1), picture.get()); |
387 if ((x + y) & 1) { | 380 if ((x + y) & 1) { |
388 EXPECT_TRUE(iterator) << x << " " << y; | 381 EXPECT_TRUE(iterator) << x << " " << y; |
389 EXPECT_TRUE(*iterator == discardable_bitmap[y][x].pixelRef()); | 382 EXPECT_TRUE(*iterator == discardable_bitmap[y][x].pixelRef()); |
390 EXPECT_FALSE(++iterator) << x << " " << y; | 383 EXPECT_FALSE(++iterator) << x << " " << y; |
(...skipping 29 matching lines...) Expand all Loading... |
420 Picture::CreateFromSkpValue(tmp.get()); | 413 Picture::CreateFromSkpValue(tmp.get()); |
421 EXPECT_TRUE(!invalid_picture.get()); | 414 EXPECT_TRUE(!invalid_picture.get()); |
422 | 415 |
423 // Single full-size rect picture. | 416 // Single full-size rect picture. |
424 content_layer_client.add_draw_rect(layer_rect, red_paint); | 417 content_layer_client.add_draw_rect(layer_rect, red_paint); |
425 scoped_refptr<Picture> one_rect_picture = | 418 scoped_refptr<Picture> one_rect_picture = |
426 Picture::Create(layer_rect, | 419 Picture::Create(layer_rect, |
427 &content_layer_client, | 420 &content_layer_client, |
428 tile_grid_info, | 421 tile_grid_info, |
429 false, | 422 false, |
430 0, | |
431 Picture::RECORD_NORMALLY); | 423 Picture::RECORD_NORMALLY); |
432 scoped_ptr<base::Value> serialized_one_rect( | 424 scoped_ptr<base::Value> serialized_one_rect( |
433 one_rect_picture->AsValue()); | 425 one_rect_picture->AsValue()); |
434 | 426 |
435 const base::DictionaryValue* value = NULL; | 427 const base::DictionaryValue* value = NULL; |
436 EXPECT_TRUE(serialized_one_rect->GetAsDictionary(&value)); | 428 EXPECT_TRUE(serialized_one_rect->GetAsDictionary(&value)); |
437 | 429 |
438 // Decode the picture from base64. | 430 // Decode the picture from base64. |
439 const base::Value* skp_value; | 431 const base::Value* skp_value; |
440 EXPECT_TRUE(value->Get("skp64", &skp_value)); | 432 EXPECT_TRUE(value->Get("skp64", &skp_value)); |
(...skipping 19 matching lines...) Expand all Loading... |
460 tile_grid_info.fMargin.setEmpty(); | 452 tile_grid_info.fMargin.setEmpty(); |
461 tile_grid_info.fOffset.setZero(); | 453 tile_grid_info.fOffset.setZero(); |
462 | 454 |
463 FakeContentLayerClient content_layer_client; | 455 FakeContentLayerClient content_layer_client; |
464 EXPECT_EQ(NULL, content_layer_client.last_canvas()); | 456 EXPECT_EQ(NULL, content_layer_client.last_canvas()); |
465 | 457 |
466 scoped_refptr<Picture> picture = Picture::Create(layer_rect, | 458 scoped_refptr<Picture> picture = Picture::Create(layer_rect, |
467 &content_layer_client, | 459 &content_layer_client, |
468 tile_grid_info, | 460 tile_grid_info, |
469 false, | 461 false, |
470 0, | |
471 Picture::RECORD_NORMALLY); | 462 Picture::RECORD_NORMALLY); |
472 EXPECT_TRUE(content_layer_client.last_canvas() != NULL); | 463 EXPECT_TRUE(content_layer_client.last_canvas() != NULL); |
473 EXPECT_EQ(ContentLayerClient::GRAPHICS_CONTEXT_ENABLED, | 464 EXPECT_EQ(ContentLayerClient::GRAPHICS_CONTEXT_ENABLED, |
474 content_layer_client.last_context_status()); | 465 content_layer_client.last_context_status()); |
475 EXPECT_TRUE(picture); | 466 EXPECT_TRUE(picture); |
476 | 467 |
477 picture = Picture::Create(layer_rect, | 468 picture = Picture::Create(layer_rect, |
478 &content_layer_client, | 469 &content_layer_client, |
479 tile_grid_info, | 470 tile_grid_info, |
480 false, | 471 false, |
481 0, | |
482 Picture::RECORD_WITH_SK_NULL_CANVAS); | 472 Picture::RECORD_WITH_SK_NULL_CANVAS); |
483 EXPECT_TRUE(content_layer_client.last_canvas() != NULL); | 473 EXPECT_TRUE(content_layer_client.last_canvas() != NULL); |
484 EXPECT_EQ(ContentLayerClient::GRAPHICS_CONTEXT_ENABLED, | 474 EXPECT_EQ(ContentLayerClient::GRAPHICS_CONTEXT_ENABLED, |
485 content_layer_client.last_context_status()); | 475 content_layer_client.last_context_status()); |
486 EXPECT_TRUE(picture); | 476 EXPECT_TRUE(picture); |
487 | 477 |
488 picture = Picture::Create(layer_rect, | 478 picture = Picture::Create(layer_rect, |
489 &content_layer_client, | 479 &content_layer_client, |
490 tile_grid_info, | 480 tile_grid_info, |
491 false, | 481 false, |
492 0, | |
493 Picture::RECORD_WITH_PAINTING_DISABLED); | 482 Picture::RECORD_WITH_PAINTING_DISABLED); |
494 EXPECT_TRUE(content_layer_client.last_canvas() != NULL); | 483 EXPECT_TRUE(content_layer_client.last_canvas() != NULL); |
495 EXPECT_EQ(ContentLayerClient::GRAPHICS_CONTEXT_DISABLED, | 484 EXPECT_EQ(ContentLayerClient::GRAPHICS_CONTEXT_DISABLED, |
496 content_layer_client.last_context_status()); | 485 content_layer_client.last_context_status()); |
497 EXPECT_TRUE(picture); | 486 EXPECT_TRUE(picture); |
498 | 487 |
499 picture = Picture::Create(layer_rect, | 488 picture = Picture::Create(layer_rect, |
500 &content_layer_client, | 489 &content_layer_client, |
501 tile_grid_info, | 490 tile_grid_info, |
502 false, | 491 false, |
503 0, | |
504 Picture::RECORD_WITH_SKRECORD); | 492 Picture::RECORD_WITH_SKRECORD); |
505 EXPECT_TRUE(content_layer_client.last_canvas() != NULL); | 493 EXPECT_TRUE(content_layer_client.last_canvas() != NULL); |
506 EXPECT_TRUE(picture); | 494 EXPECT_TRUE(picture); |
507 | 495 |
508 EXPECT_EQ(4, Picture::RECORDING_MODE_COUNT); | 496 EXPECT_EQ(4, Picture::RECORDING_MODE_COUNT); |
509 } | 497 } |
510 | 498 |
511 } // namespace | 499 } // namespace |
512 } // namespace cc | 500 } // namespace cc |
OLD | NEW |