| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 EXPECT_TRUE(!!one_rect_picture_check.get()); | 66 EXPECT_TRUE(!!one_rect_picture_check.get()); |
| 67 | 67 |
| 68 // Check for equivalence. | 68 // Check for equivalence. |
| 69 unsigned char one_rect_buffer[4 * 100 * 100] = {0}; | 69 unsigned char one_rect_buffer[4 * 100 * 100] = {0}; |
| 70 DrawPicture(one_rect_buffer, layer_rect, one_rect_picture); | 70 DrawPicture(one_rect_buffer, layer_rect, one_rect_picture); |
| 71 unsigned char one_rect_buffer_check[4 * 100 * 100] = {0}; | 71 unsigned char one_rect_buffer_check[4 * 100 * 100] = {0}; |
| 72 DrawPicture(one_rect_buffer_check, layer_rect, one_rect_picture_check); | 72 DrawPicture(one_rect_buffer_check, layer_rect, one_rect_picture_check); |
| 73 | 73 |
| 74 EXPECT_EQ(one_rect_picture->LayerRect(), | 74 EXPECT_EQ(one_rect_picture->LayerRect(), |
| 75 one_rect_picture_check->LayerRect()); | 75 one_rect_picture_check->LayerRect()); |
| 76 EXPECT_EQ(one_rect_picture->OpaqueRect(), | |
| 77 one_rect_picture_check->OpaqueRect()); | |
| 78 EXPECT_EQ(0, memcmp(one_rect_buffer, one_rect_buffer_check, 4 * 100 * 100)); | 76 EXPECT_EQ(0, memcmp(one_rect_buffer, one_rect_buffer_check, 4 * 100 * 100)); |
| 79 } | 77 } |
| 80 | 78 |
| 81 // Two rect picture. | 79 // Two rect picture. |
| 82 content_layer_client.add_draw_rect(gfx::Rect(25, 25, 50, 50), green_paint); | 80 content_layer_client.add_draw_rect(gfx::Rect(25, 25, 50, 50), green_paint); |
| 83 | 81 |
| 84 for (size_t i = 0; i < arraysize(kRecordingModes); ++i) { | 82 for (size_t i = 0; i < arraysize(kRecordingModes); ++i) { |
| 85 scoped_refptr<Picture> two_rect_picture = | 83 scoped_refptr<Picture> two_rect_picture = |
| 86 Picture::Create(layer_rect, | 84 Picture::Create(layer_rect, |
| 87 &content_layer_client, | 85 &content_layer_client, |
| 88 tile_grid_info, | 86 tile_grid_info, |
| 89 false, | 87 false, |
| 90 Picture::RECORD_NORMALLY); | 88 Picture::RECORD_NORMALLY); |
| 91 | 89 |
| 92 scoped_ptr<base::Value> serialized_two_rect(two_rect_picture->AsValue()); | 90 scoped_ptr<base::Value> serialized_two_rect(two_rect_picture->AsValue()); |
| 93 | 91 |
| 94 // Reconstruct the picture. | 92 // Reconstruct the picture. |
| 95 scoped_refptr<Picture> two_rect_picture_check = | 93 scoped_refptr<Picture> two_rect_picture_check = |
| 96 Picture::CreateFromValue(serialized_two_rect.get()); | 94 Picture::CreateFromValue(serialized_two_rect.get()); |
| 97 EXPECT_TRUE(!!two_rect_picture_check.get()); | 95 EXPECT_TRUE(!!two_rect_picture_check.get()); |
| 98 | 96 |
| 99 // Check for equivalence. | 97 // Check for equivalence. |
| 100 unsigned char two_rect_buffer[4 * 100 * 100] = {0}; | 98 unsigned char two_rect_buffer[4 * 100 * 100] = {0}; |
| 101 DrawPicture(two_rect_buffer, layer_rect, two_rect_picture); | 99 DrawPicture(two_rect_buffer, layer_rect, two_rect_picture); |
| 102 unsigned char two_rect_buffer_check[4 * 100 * 100] = {0}; | 100 unsigned char two_rect_buffer_check[4 * 100 * 100] = {0}; |
| 103 DrawPicture(two_rect_buffer_check, layer_rect, two_rect_picture_check); | 101 DrawPicture(two_rect_buffer_check, layer_rect, two_rect_picture_check); |
| 104 | 102 |
| 105 EXPECT_EQ(two_rect_picture->LayerRect(), | 103 EXPECT_EQ(two_rect_picture->LayerRect(), |
| 106 two_rect_picture_check->LayerRect()); | 104 two_rect_picture_check->LayerRect()); |
| 107 EXPECT_EQ(two_rect_picture->OpaqueRect(), | |
| 108 two_rect_picture_check->OpaqueRect()); | |
| 109 EXPECT_EQ(0, memcmp(two_rect_buffer, two_rect_buffer_check, 4 * 100 * 100)); | 105 EXPECT_EQ(0, memcmp(two_rect_buffer, two_rect_buffer_check, 4 * 100 * 100)); |
| 110 } | 106 } |
| 111 } | 107 } |
| 112 | 108 |
| 113 TEST(PictureTest, PixelRefIterator) { | 109 TEST(PictureTest, PixelRefIterator) { |
| 114 gfx::Rect layer_rect(2048, 2048); | 110 gfx::Rect layer_rect(2048, 2048); |
| 115 | 111 |
| 116 SkTileGridFactory::TileGridInfo tile_grid_info; | 112 SkTileGridFactory::TileGridInfo tile_grid_info; |
| 117 tile_grid_info.fTileInterval = SkISize::Make(512, 512); | 113 tile_grid_info.fTileInterval = SkISize::Make(512, 512); |
| 118 tile_grid_info.fMargin.setEmpty(); | 114 tile_grid_info.fMargin.setEmpty(); |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 const base::Value* skp_value; | 427 const base::Value* skp_value; |
| 432 EXPECT_TRUE(value->Get("skp64", &skp_value)); | 428 EXPECT_TRUE(value->Get("skp64", &skp_value)); |
| 433 | 429 |
| 434 // Reconstruct the picture. | 430 // Reconstruct the picture. |
| 435 scoped_refptr<Picture> one_rect_picture_check = | 431 scoped_refptr<Picture> one_rect_picture_check = |
| 436 Picture::CreateFromSkpValue(skp_value); | 432 Picture::CreateFromSkpValue(skp_value); |
| 437 EXPECT_TRUE(!!one_rect_picture_check.get()); | 433 EXPECT_TRUE(!!one_rect_picture_check.get()); |
| 438 | 434 |
| 439 EXPECT_EQ(100, one_rect_picture_check->LayerRect().width()); | 435 EXPECT_EQ(100, one_rect_picture_check->LayerRect().width()); |
| 440 EXPECT_EQ(200, one_rect_picture_check->LayerRect().height()); | 436 EXPECT_EQ(200, one_rect_picture_check->LayerRect().height()); |
| 441 EXPECT_EQ(100, one_rect_picture_check->OpaqueRect().width()); | |
| 442 EXPECT_EQ(200, one_rect_picture_check->OpaqueRect().height()); | |
| 443 } | 437 } |
| 444 | 438 |
| 445 TEST(PictureTest, RecordingModes) { | 439 TEST(PictureTest, RecordingModes) { |
| 446 SkGraphics::Init(); | 440 SkGraphics::Init(); |
| 447 | 441 |
| 448 gfx::Rect layer_rect(100, 200); | 442 gfx::Rect layer_rect(100, 200); |
| 449 | 443 |
| 450 SkTileGridFactory::TileGridInfo tile_grid_info; | 444 SkTileGridFactory::TileGridInfo tile_grid_info; |
| 451 tile_grid_info.fTileInterval = SkISize::Make(100, 200); | 445 tile_grid_info.fTileInterval = SkISize::Make(100, 200); |
| 452 tile_grid_info.fMargin.setEmpty(); | 446 tile_grid_info.fMargin.setEmpty(); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 false, | 485 false, |
| 492 Picture::RECORD_WITH_SKRECORD); | 486 Picture::RECORD_WITH_SKRECORD); |
| 493 EXPECT_TRUE(content_layer_client.last_canvas() != NULL); | 487 EXPECT_TRUE(content_layer_client.last_canvas() != NULL); |
| 494 EXPECT_TRUE(picture.get()); | 488 EXPECT_TRUE(picture.get()); |
| 495 | 489 |
| 496 EXPECT_EQ(4, Picture::RECORDING_MODE_COUNT); | 490 EXPECT_EQ(4, Picture::RECORDING_MODE_COUNT); |
| 497 } | 491 } |
| 498 | 492 |
| 499 } // namespace | 493 } // namespace |
| 500 } // namespace cc | 494 } // namespace cc |
| OLD | NEW |