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 26 matching lines...) Expand all Loading... |
37 tmp.reset(new base::StringValue("abc!@#$%")); | 37 tmp.reset(new base::StringValue("abc!@#$%")); |
38 scoped_refptr<Picture> invalid_picture = | 38 scoped_refptr<Picture> invalid_picture = |
39 Picture::CreateFromValue(tmp.get()); | 39 Picture::CreateFromValue(tmp.get()); |
40 EXPECT_FALSE(invalid_picture.get()); | 40 EXPECT_FALSE(invalid_picture.get()); |
41 | 41 |
42 // Single full-size rect picture. | 42 // Single full-size rect picture. |
43 content_layer_client.add_draw_rect(layer_rect, red_paint); | 43 content_layer_client.add_draw_rect(layer_rect, red_paint); |
44 | 44 |
45 scoped_refptr<Picture> one_rect_picture = | 45 scoped_refptr<Picture> one_rect_picture = |
46 Picture::Create(layer_rect, &content_layer_client, tile_grid_size, false, | 46 Picture::Create(layer_rect, &content_layer_client, tile_grid_size, false, |
47 Picture::RECORD_NORMALLY); | 47 RecordingSource::RECORD_NORMALLY); |
48 scoped_ptr<base::Value> serialized_one_rect(one_rect_picture->AsValue()); | 48 scoped_ptr<base::Value> serialized_one_rect(one_rect_picture->AsValue()); |
49 | 49 |
50 // Reconstruct the picture. | 50 // Reconstruct the picture. |
51 scoped_refptr<Picture> one_rect_picture_check = | 51 scoped_refptr<Picture> one_rect_picture_check = |
52 Picture::CreateFromValue(serialized_one_rect.get()); | 52 Picture::CreateFromValue(serialized_one_rect.get()); |
53 EXPECT_TRUE(!!one_rect_picture_check.get()); | 53 EXPECT_TRUE(!!one_rect_picture_check.get()); |
54 | 54 |
55 // Check for equivalence. | 55 // Check for equivalence. |
56 unsigned char one_rect_buffer[4 * 100 * 100] = {0}; | 56 unsigned char one_rect_buffer[4 * 100 * 100] = {0}; |
57 DrawPicture(one_rect_buffer, layer_rect, one_rect_picture); | 57 DrawPicture(one_rect_buffer, layer_rect, one_rect_picture); |
58 unsigned char one_rect_buffer_check[4 * 100 * 100] = {0}; | 58 unsigned char one_rect_buffer_check[4 * 100 * 100] = {0}; |
59 DrawPicture(one_rect_buffer_check, layer_rect, one_rect_picture_check); | 59 DrawPicture(one_rect_buffer_check, layer_rect, one_rect_picture_check); |
60 | 60 |
61 EXPECT_EQ(one_rect_picture->LayerRect(), one_rect_picture_check->LayerRect()); | 61 EXPECT_EQ(one_rect_picture->LayerRect(), one_rect_picture_check->LayerRect()); |
62 EXPECT_EQ(0, memcmp(one_rect_buffer, one_rect_buffer_check, 4 * 100 * 100)); | 62 EXPECT_EQ(0, memcmp(one_rect_buffer, one_rect_buffer_check, 4 * 100 * 100)); |
63 | 63 |
64 // Two rect picture. | 64 // Two rect picture. |
65 content_layer_client.add_draw_rect(gfx::Rect(25, 25, 50, 50), green_paint); | 65 content_layer_client.add_draw_rect(gfx::Rect(25, 25, 50, 50), green_paint); |
66 | 66 |
67 scoped_refptr<Picture> two_rect_picture = | 67 scoped_refptr<Picture> two_rect_picture = |
68 Picture::Create(layer_rect, &content_layer_client, tile_grid_size, false, | 68 Picture::Create(layer_rect, &content_layer_client, tile_grid_size, false, |
69 Picture::RECORD_NORMALLY); | 69 RecordingSource::RECORD_NORMALLY); |
70 | 70 |
71 scoped_ptr<base::Value> serialized_two_rect(two_rect_picture->AsValue()); | 71 scoped_ptr<base::Value> serialized_two_rect(two_rect_picture->AsValue()); |
72 | 72 |
73 // Reconstruct the picture. | 73 // Reconstruct the picture. |
74 scoped_refptr<Picture> two_rect_picture_check = | 74 scoped_refptr<Picture> two_rect_picture_check = |
75 Picture::CreateFromValue(serialized_two_rect.get()); | 75 Picture::CreateFromValue(serialized_two_rect.get()); |
76 EXPECT_TRUE(!!two_rect_picture_check.get()); | 76 EXPECT_TRUE(!!two_rect_picture_check.get()); |
77 | 77 |
78 // Check for equivalence. | 78 // Check for equivalence. |
79 unsigned char two_rect_buffer[4 * 100 * 100] = {0}; | 79 unsigned char two_rect_buffer[4 * 100 * 100] = {0}; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 SkPaint paint; | 111 SkPaint paint; |
112 content_layer_client.add_draw_bitmap( | 112 content_layer_client.add_draw_bitmap( |
113 discardable_bitmap[y][x], | 113 discardable_bitmap[y][x], |
114 gfx::Point(x * 512 + 6, y * 512 + 6), paint); | 114 gfx::Point(x * 512 + 6, y * 512 + 6), paint); |
115 } | 115 } |
116 } | 116 } |
117 } | 117 } |
118 | 118 |
119 scoped_refptr<Picture> picture = | 119 scoped_refptr<Picture> picture = |
120 Picture::Create(layer_rect, &content_layer_client, tile_grid_size, true, | 120 Picture::Create(layer_rect, &content_layer_client, tile_grid_size, true, |
121 Picture::RECORD_NORMALLY); | 121 RecordingSource::RECORD_NORMALLY); |
122 | 122 |
123 // Default iterator does not have any pixel refs | 123 // Default iterator does not have any pixel refs |
124 { | 124 { |
125 Picture::PixelRefIterator iterator; | 125 Picture::PixelRefIterator iterator; |
126 EXPECT_FALSE(iterator); | 126 EXPECT_FALSE(iterator); |
127 } | 127 } |
128 for (int y = 0; y < 4; ++y) { | 128 for (int y = 0; y < 4; ++y) { |
129 for (int x = 0; x < 4; ++x) { | 129 for (int x = 0; x < 4; ++x) { |
130 Picture::PixelRefIterator iterator(gfx::Rect(x * 512, y * 512, 500, 500), | 130 Picture::PixelRefIterator iterator(gfx::Rect(x * 512, y * 512, 500, 500), |
131 picture.get()); | 131 picture.get()); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 SkPaint paint; | 206 SkPaint paint; |
207 content_layer_client.add_draw_bitmap( | 207 content_layer_client.add_draw_bitmap( |
208 discardable_bitmap[y][x], | 208 discardable_bitmap[y][x], |
209 gfx::Point(1024 + x * 512 + 6, y * 512 + 6), paint); | 209 gfx::Point(1024 + x * 512 + 6, y * 512 + 6), paint); |
210 } | 210 } |
211 } | 211 } |
212 } | 212 } |
213 | 213 |
214 scoped_refptr<Picture> picture = | 214 scoped_refptr<Picture> picture = |
215 Picture::Create(layer_rect, &content_layer_client, tile_grid_size, true, | 215 Picture::Create(layer_rect, &content_layer_client, tile_grid_size, true, |
216 Picture::RECORD_NORMALLY); | 216 RecordingSource::RECORD_NORMALLY); |
217 | 217 |
218 // Default iterator does not have any pixel refs | 218 // Default iterator does not have any pixel refs |
219 { | 219 { |
220 Picture::PixelRefIterator iterator; | 220 Picture::PixelRefIterator iterator; |
221 EXPECT_FALSE(iterator); | 221 EXPECT_FALSE(iterator); |
222 } | 222 } |
223 for (int y = 0; y < 4; ++y) { | 223 for (int y = 0; y < 4; ++y) { |
224 for (int x = 0; x < 4; ++x) { | 224 for (int x = 0; x < 4; ++x) { |
225 Picture::PixelRefIterator iterator( | 225 Picture::PixelRefIterator iterator( |
226 gfx::Rect(1024 + x * 512, y * 512, 500, 500), picture.get()); | 226 gfx::Rect(1024 + x * 512, y * 512, 500, 500), picture.get()); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 SkPaint paint; | 324 SkPaint paint; |
325 content_layer_client.add_draw_bitmap( | 325 content_layer_client.add_draw_bitmap( |
326 discardable_bitmap[y][x], | 326 discardable_bitmap[y][x], |
327 gfx::Point(x * 512 + 6, y * 512 + 6), paint); | 327 gfx::Point(x * 512 + 6, y * 512 + 6), paint); |
328 } | 328 } |
329 } | 329 } |
330 } | 330 } |
331 | 331 |
332 scoped_refptr<Picture> picture = | 332 scoped_refptr<Picture> picture = |
333 Picture::Create(layer_rect, &content_layer_client, tile_grid_size, true, | 333 Picture::Create(layer_rect, &content_layer_client, tile_grid_size, true, |
334 Picture::RECORD_NORMALLY); | 334 RecordingSource::RECORD_NORMALLY); |
335 | 335 |
336 for (int y = 0; y < 4; ++y) { | 336 for (int y = 0; y < 4; ++y) { |
337 for (int x = 0; x < 4; ++x) { | 337 for (int x = 0; x < 4; ++x) { |
338 Picture::PixelRefIterator iterator( | 338 Picture::PixelRefIterator iterator( |
339 gfx::Rect(x * 512, y * 512 + 256, 1, 1), picture.get()); | 339 gfx::Rect(x * 512, y * 512 + 256, 1, 1), picture.get()); |
340 if ((x + y) & 1) { | 340 if ((x + y) & 1) { |
341 EXPECT_TRUE(iterator) << x << " " << y; | 341 EXPECT_TRUE(iterator) << x << " " << y; |
342 EXPECT_TRUE(*iterator == discardable_bitmap[y][x].pixelRef()); | 342 EXPECT_TRUE(*iterator == discardable_bitmap[y][x].pixelRef()); |
343 EXPECT_FALSE(++iterator) << x << " " << y; | 343 EXPECT_FALSE(++iterator) << x << " " << y; |
344 } else { | 344 } else { |
(...skipping 22 matching lines...) Expand all Loading... |
367 // Invalid picture (not a dict). | 367 // Invalid picture (not a dict). |
368 tmp.reset(new base::StringValue("abc!@#$%")); | 368 tmp.reset(new base::StringValue("abc!@#$%")); |
369 scoped_refptr<Picture> invalid_picture = | 369 scoped_refptr<Picture> invalid_picture = |
370 Picture::CreateFromSkpValue(tmp.get()); | 370 Picture::CreateFromSkpValue(tmp.get()); |
371 EXPECT_TRUE(!invalid_picture.get()); | 371 EXPECT_TRUE(!invalid_picture.get()); |
372 | 372 |
373 // Single full-size rect picture. | 373 // Single full-size rect picture. |
374 content_layer_client.add_draw_rect(layer_rect, red_paint); | 374 content_layer_client.add_draw_rect(layer_rect, red_paint); |
375 scoped_refptr<Picture> one_rect_picture = | 375 scoped_refptr<Picture> one_rect_picture = |
376 Picture::Create(layer_rect, &content_layer_client, tile_grid_size, false, | 376 Picture::Create(layer_rect, &content_layer_client, tile_grid_size, false, |
377 Picture::RECORD_NORMALLY); | 377 RecordingSource::RECORD_NORMALLY); |
378 scoped_ptr<base::Value> serialized_one_rect( | 378 scoped_ptr<base::Value> serialized_one_rect( |
379 one_rect_picture->AsValue()); | 379 one_rect_picture->AsValue()); |
380 | 380 |
381 const base::DictionaryValue* value = NULL; | 381 const base::DictionaryValue* value = NULL; |
382 EXPECT_TRUE(serialized_one_rect->GetAsDictionary(&value)); | 382 EXPECT_TRUE(serialized_one_rect->GetAsDictionary(&value)); |
383 | 383 |
384 // Decode the picture from base64. | 384 // Decode the picture from base64. |
385 const base::Value* skp_value; | 385 const base::Value* skp_value; |
386 EXPECT_TRUE(value->Get("skp64", &skp_value)); | 386 EXPECT_TRUE(value->Get("skp64", &skp_value)); |
387 | 387 |
(...skipping 11 matching lines...) Expand all Loading... |
399 | 399 |
400 gfx::Rect layer_rect(100, 200); | 400 gfx::Rect layer_rect(100, 200); |
401 | 401 |
402 gfx::Size tile_grid_size(100, 200); | 402 gfx::Size tile_grid_size(100, 200); |
403 | 403 |
404 FakeContentLayerClient content_layer_client; | 404 FakeContentLayerClient content_layer_client; |
405 EXPECT_EQ(NULL, content_layer_client.last_canvas()); | 405 EXPECT_EQ(NULL, content_layer_client.last_canvas()); |
406 | 406 |
407 scoped_refptr<Picture> picture = | 407 scoped_refptr<Picture> picture = |
408 Picture::Create(layer_rect, &content_layer_client, tile_grid_size, false, | 408 Picture::Create(layer_rect, &content_layer_client, tile_grid_size, false, |
409 Picture::RECORD_NORMALLY); | 409 RecordingSource::RECORD_NORMALLY); |
410 EXPECT_TRUE(content_layer_client.last_canvas() != NULL); | 410 EXPECT_TRUE(content_layer_client.last_canvas() != NULL); |
411 EXPECT_EQ(ContentLayerClient::GRAPHICS_CONTEXT_ENABLED, | 411 EXPECT_EQ(ContentLayerClient::PAINTING_BEHAVIOR_NORMAL, |
412 content_layer_client.last_context_status()); | 412 content_layer_client.last_painting_control()); |
413 EXPECT_TRUE(picture.get()); | 413 EXPECT_TRUE(picture.get()); |
414 | 414 |
415 picture = Picture::Create(layer_rect, &content_layer_client, tile_grid_size, | 415 picture = Picture::Create(layer_rect, &content_layer_client, tile_grid_size, |
416 false, Picture::RECORD_WITH_SK_NULL_CANVAS); | 416 false, RecordingSource::RECORD_WITH_SK_NULL_CANVAS); |
417 EXPECT_TRUE(content_layer_client.last_canvas() != NULL); | 417 EXPECT_TRUE(content_layer_client.last_canvas() != NULL); |
418 EXPECT_EQ(ContentLayerClient::GRAPHICS_CONTEXT_ENABLED, | 418 EXPECT_EQ(ContentLayerClient::PAINTING_BEHAVIOR_NORMAL, |
419 content_layer_client.last_context_status()); | 419 content_layer_client.last_painting_control()); |
420 EXPECT_TRUE(picture.get()); | 420 EXPECT_TRUE(picture.get()); |
421 | 421 |
422 picture = Picture::Create(layer_rect, &content_layer_client, tile_grid_size, | 422 picture = |
423 false, Picture::RECORD_WITH_PAINTING_DISABLED); | 423 Picture::Create(layer_rect, &content_layer_client, tile_grid_size, false, |
| 424 RecordingSource::RECORD_WITH_PAINTING_DISABLED); |
424 EXPECT_TRUE(content_layer_client.last_canvas() != NULL); | 425 EXPECT_TRUE(content_layer_client.last_canvas() != NULL); |
425 EXPECT_EQ(ContentLayerClient::GRAPHICS_CONTEXT_DISABLED, | 426 EXPECT_EQ(ContentLayerClient::DISPLAY_LIST_CONSTRUCTION_DISABLED, |
426 content_layer_client.last_context_status()); | 427 content_layer_client.last_painting_control()); |
427 EXPECT_TRUE(picture.get()); | 428 EXPECT_TRUE(picture.get()); |
428 | 429 |
429 EXPECT_EQ(3, Picture::RECORDING_MODE_COUNT); | 430 picture = |
| 431 Picture::Create(layer_rect, &content_layer_client, tile_grid_size, false, |
| 432 RecordingSource::RECORD_WITH_CACHING_DISABLED); |
| 433 EXPECT_TRUE(content_layer_client.last_canvas() != NULL); |
| 434 EXPECT_EQ(ContentLayerClient::DISPLAY_LIST_CACHING_DISABLED, |
| 435 content_layer_client.last_painting_control()); |
| 436 EXPECT_TRUE(picture.get()); |
| 437 |
| 438 EXPECT_EQ(4, RecordingSource::RECORDING_MODE_COUNT); |
430 } | 439 } |
431 | 440 |
432 } // namespace | 441 } // namespace |
433 } // namespace cc | 442 } // namespace cc |
OLD | NEW |