| 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" |
| 11 #include "cc/test/skia_common.h" | 11 #include "cc/test/skia_common.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "third_party/skia/include/core/SkBBHFactory.h" | |
| 14 #include "third_party/skia/include/core/SkGraphics.h" | 13 #include "third_party/skia/include/core/SkGraphics.h" |
| 15 #include "ui/gfx/geometry/rect.h" | 14 #include "ui/gfx/geometry/rect.h" |
| 16 #include "ui/gfx/skia_util.h" | 15 #include "ui/gfx/skia_util.h" |
| 17 | 16 |
| 18 namespace cc { | 17 namespace cc { |
| 19 namespace { | 18 namespace { |
| 20 | 19 |
| 21 TEST(PictureTest, AsBase64String) { | 20 TEST(PictureTest, AsBase64String) { |
| 22 SkGraphics::Init(); | 21 SkGraphics::Init(); |
| 23 | 22 |
| 24 gfx::Rect layer_rect(100, 100); | 23 gfx::Rect layer_rect(100, 100); |
| 25 | 24 |
| 26 SkTileGridFactory::TileGridInfo tile_grid_info; | 25 gfx::Size tile_grid_size(100, 100); |
| 27 tile_grid_info.fTileInterval = SkISize::Make(100, 100); | |
| 28 tile_grid_info.fMargin.setEmpty(); | |
| 29 tile_grid_info.fOffset.setZero(); | |
| 30 | 26 |
| 31 FakeContentLayerClient content_layer_client; | 27 FakeContentLayerClient content_layer_client; |
| 32 | 28 |
| 33 scoped_ptr<base::Value> tmp; | 29 scoped_ptr<base::Value> tmp; |
| 34 | 30 |
| 35 SkPaint red_paint; | 31 SkPaint red_paint; |
| 36 red_paint.setColor(SkColorSetARGB(255, 255, 0, 0)); | 32 red_paint.setColor(SkColorSetARGB(255, 255, 0, 0)); |
| 37 SkPaint green_paint; | 33 SkPaint green_paint; |
| 38 green_paint.setColor(SkColorSetARGB(255, 0, 255, 0)); | 34 green_paint.setColor(SkColorSetARGB(255, 0, 255, 0)); |
| 39 | 35 |
| 40 // Invalid picture (not a dict). | 36 // Invalid picture (not a dict). |
| 41 tmp.reset(new base::StringValue("abc!@#$%")); | 37 tmp.reset(new base::StringValue("abc!@#$%")); |
| 42 scoped_refptr<Picture> invalid_picture = | 38 scoped_refptr<Picture> invalid_picture = |
| 43 Picture::CreateFromValue(tmp.get()); | 39 Picture::CreateFromValue(tmp.get()); |
| 44 EXPECT_FALSE(invalid_picture.get()); | 40 EXPECT_FALSE(invalid_picture.get()); |
| 45 | 41 |
| 46 // Single full-size rect picture. | 42 // Single full-size rect picture. |
| 47 content_layer_client.add_draw_rect(layer_rect, red_paint); | 43 content_layer_client.add_draw_rect(layer_rect, red_paint); |
| 48 | 44 |
| 49 scoped_refptr<Picture> one_rect_picture = | 45 scoped_refptr<Picture> one_rect_picture = |
| 50 Picture::Create(layer_rect, | 46 Picture::Create(layer_rect, &content_layer_client, tile_grid_size, false, |
| 51 &content_layer_client, | |
| 52 tile_grid_info, | |
| 53 false, | |
| 54 Picture::RECORD_NORMALLY); | 47 Picture::RECORD_NORMALLY); |
| 55 scoped_ptr<base::Value> serialized_one_rect(one_rect_picture->AsValue()); | 48 scoped_ptr<base::Value> serialized_one_rect(one_rect_picture->AsValue()); |
| 56 | 49 |
| 57 // Reconstruct the picture. | 50 // Reconstruct the picture. |
| 58 scoped_refptr<Picture> one_rect_picture_check = | 51 scoped_refptr<Picture> one_rect_picture_check = |
| 59 Picture::CreateFromValue(serialized_one_rect.get()); | 52 Picture::CreateFromValue(serialized_one_rect.get()); |
| 60 EXPECT_TRUE(!!one_rect_picture_check.get()); | 53 EXPECT_TRUE(!!one_rect_picture_check.get()); |
| 61 | 54 |
| 62 // Check for equivalence. | 55 // Check for equivalence. |
| 63 unsigned char one_rect_buffer[4 * 100 * 100] = {0}; | 56 unsigned char one_rect_buffer[4 * 100 * 100] = {0}; |
| 64 DrawPicture(one_rect_buffer, layer_rect, one_rect_picture); | 57 DrawPicture(one_rect_buffer, layer_rect, one_rect_picture); |
| 65 unsigned char one_rect_buffer_check[4 * 100 * 100] = {0}; | 58 unsigned char one_rect_buffer_check[4 * 100 * 100] = {0}; |
| 66 DrawPicture(one_rect_buffer_check, layer_rect, one_rect_picture_check); | 59 DrawPicture(one_rect_buffer_check, layer_rect, one_rect_picture_check); |
| 67 | 60 |
| 68 EXPECT_EQ(one_rect_picture->LayerRect(), one_rect_picture_check->LayerRect()); | 61 EXPECT_EQ(one_rect_picture->LayerRect(), one_rect_picture_check->LayerRect()); |
| 69 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)); |
| 70 | 63 |
| 71 // Two rect picture. | 64 // Two rect picture. |
| 72 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); |
| 73 | 66 |
| 74 scoped_refptr<Picture> two_rect_picture = | 67 scoped_refptr<Picture> two_rect_picture = |
| 75 Picture::Create(layer_rect, | 68 Picture::Create(layer_rect, &content_layer_client, tile_grid_size, false, |
| 76 &content_layer_client, | |
| 77 tile_grid_info, | |
| 78 false, | |
| 79 Picture::RECORD_NORMALLY); | 69 Picture::RECORD_NORMALLY); |
| 80 | 70 |
| 81 scoped_ptr<base::Value> serialized_two_rect(two_rect_picture->AsValue()); | 71 scoped_ptr<base::Value> serialized_two_rect(two_rect_picture->AsValue()); |
| 82 | 72 |
| 83 // Reconstruct the picture. | 73 // Reconstruct the picture. |
| 84 scoped_refptr<Picture> two_rect_picture_check = | 74 scoped_refptr<Picture> two_rect_picture_check = |
| 85 Picture::CreateFromValue(serialized_two_rect.get()); | 75 Picture::CreateFromValue(serialized_two_rect.get()); |
| 86 EXPECT_TRUE(!!two_rect_picture_check.get()); | 76 EXPECT_TRUE(!!two_rect_picture_check.get()); |
| 87 | 77 |
| 88 // Check for equivalence. | 78 // Check for equivalence. |
| 89 unsigned char two_rect_buffer[4 * 100 * 100] = {0}; | 79 unsigned char two_rect_buffer[4 * 100 * 100] = {0}; |
| 90 DrawPicture(two_rect_buffer, layer_rect, two_rect_picture); | 80 DrawPicture(two_rect_buffer, layer_rect, two_rect_picture); |
| 91 unsigned char two_rect_buffer_check[4 * 100 * 100] = {0}; | 81 unsigned char two_rect_buffer_check[4 * 100 * 100] = {0}; |
| 92 DrawPicture(two_rect_buffer_check, layer_rect, two_rect_picture_check); | 82 DrawPicture(two_rect_buffer_check, layer_rect, two_rect_picture_check); |
| 93 | 83 |
| 94 EXPECT_EQ(two_rect_picture->LayerRect(), two_rect_picture_check->LayerRect()); | 84 EXPECT_EQ(two_rect_picture->LayerRect(), two_rect_picture_check->LayerRect()); |
| 95 EXPECT_EQ(0, memcmp(two_rect_buffer, two_rect_buffer_check, 4 * 100 * 100)); | 85 EXPECT_EQ(0, memcmp(two_rect_buffer, two_rect_buffer_check, 4 * 100 * 100)); |
| 96 } | 86 } |
| 97 | 87 |
| 98 TEST(PictureTest, PixelRefIterator) { | 88 TEST(PictureTest, PixelRefIterator) { |
| 99 gfx::Rect layer_rect(2048, 2048); | 89 gfx::Rect layer_rect(2048, 2048); |
| 100 | 90 |
| 101 SkTileGridFactory::TileGridInfo tile_grid_info; | 91 gfx::Size tile_grid_size(512, 512); |
| 102 tile_grid_info.fTileInterval = SkISize::Make(512, 512); | |
| 103 tile_grid_info.fMargin.setEmpty(); | |
| 104 tile_grid_info.fOffset.setZero(); | |
| 105 | 92 |
| 106 FakeContentLayerClient content_layer_client; | 93 FakeContentLayerClient content_layer_client; |
| 107 | 94 |
| 108 // Discardable pixel refs are found in the following grids: | 95 // Discardable pixel refs are found in the following grids: |
| 109 // |---|---|---|---| | 96 // |---|---|---|---| |
| 110 // | | x | | x | | 97 // | | x | | x | |
| 111 // |---|---|---|---| | 98 // |---|---|---|---| |
| 112 // | x | | x | | | 99 // | x | | x | | |
| 113 // |---|---|---|---| | 100 // |---|---|---|---| |
| 114 // | | x | | x | | 101 // | | x | | x | |
| 115 // |---|---|---|---| | 102 // |---|---|---|---| |
| 116 // | x | | x | | | 103 // | x | | x | | |
| 117 // |---|---|---|---| | 104 // |---|---|---|---| |
| 118 SkBitmap discardable_bitmap[4][4]; | 105 SkBitmap discardable_bitmap[4][4]; |
| 119 for (int y = 0; y < 4; ++y) { | 106 for (int y = 0; y < 4; ++y) { |
| 120 for (int x = 0; x < 4; ++x) { | 107 for (int x = 0; x < 4; ++x) { |
| 121 if ((x + y) & 1) { | 108 if ((x + y) & 1) { |
| 122 CreateBitmap( | 109 CreateBitmap( |
| 123 gfx::Size(500, 500), "discardable", &discardable_bitmap[y][x]); | 110 gfx::Size(500, 500), "discardable", &discardable_bitmap[y][x]); |
| 124 SkPaint paint; | 111 SkPaint paint; |
| 125 content_layer_client.add_draw_bitmap( | 112 content_layer_client.add_draw_bitmap( |
| 126 discardable_bitmap[y][x], | 113 discardable_bitmap[y][x], |
| 127 gfx::Point(x * 512 + 6, y * 512 + 6), paint); | 114 gfx::Point(x * 512 + 6, y * 512 + 6), paint); |
| 128 } | 115 } |
| 129 } | 116 } |
| 130 } | 117 } |
| 131 | 118 |
| 132 scoped_refptr<Picture> picture = Picture::Create(layer_rect, | 119 scoped_refptr<Picture> picture = |
| 133 &content_layer_client, | 120 Picture::Create(layer_rect, &content_layer_client, tile_grid_size, true, |
| 134 tile_grid_info, | 121 Picture::RECORD_NORMALLY); |
| 135 true, | |
| 136 Picture::RECORD_NORMALLY); | |
| 137 | 122 |
| 138 // Default iterator does not have any pixel refs | 123 // Default iterator does not have any pixel refs |
| 139 { | 124 { |
| 140 Picture::PixelRefIterator iterator; | 125 Picture::PixelRefIterator iterator; |
| 141 EXPECT_FALSE(iterator); | 126 EXPECT_FALSE(iterator); |
| 142 } | 127 } |
| 143 for (int y = 0; y < 4; ++y) { | 128 for (int y = 0; y < 4; ++y) { |
| 144 for (int x = 0; x < 4; ++x) { | 129 for (int x = 0; x < 4; ++x) { |
| 145 Picture::PixelRefIterator iterator(gfx::Rect(x * 512, y * 512, 500, 500), | 130 Picture::PixelRefIterator iterator(gfx::Rect(x * 512, y * 512, 500, 500), |
| 146 picture.get()); | 131 picture.get()); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 EXPECT_TRUE(++copy); | 176 EXPECT_TRUE(++copy); |
| 192 EXPECT_TRUE(*copy == discardable_bitmap[2][3].pixelRef()); | 177 EXPECT_TRUE(*copy == discardable_bitmap[2][3].pixelRef()); |
| 193 EXPECT_TRUE(++copy); | 178 EXPECT_TRUE(++copy); |
| 194 EXPECT_TRUE(*copy == discardable_bitmap[3][2].pixelRef()); | 179 EXPECT_TRUE(*copy == discardable_bitmap[3][2].pixelRef()); |
| 195 EXPECT_FALSE(++copy); | 180 EXPECT_FALSE(++copy); |
| 196 } | 181 } |
| 197 | 182 |
| 198 TEST(PictureTest, PixelRefIteratorNonZeroLayer) { | 183 TEST(PictureTest, PixelRefIteratorNonZeroLayer) { |
| 199 gfx::Rect layer_rect(1024, 0, 2048, 2048); | 184 gfx::Rect layer_rect(1024, 0, 2048, 2048); |
| 200 | 185 |
| 201 SkTileGridFactory::TileGridInfo tile_grid_info; | 186 gfx::Size tile_grid_size(512, 512); |
| 202 tile_grid_info.fTileInterval = SkISize::Make(512, 512); | |
| 203 tile_grid_info.fMargin.setEmpty(); | |
| 204 tile_grid_info.fOffset.setZero(); | |
| 205 | 187 |
| 206 FakeContentLayerClient content_layer_client; | 188 FakeContentLayerClient content_layer_client; |
| 207 | 189 |
| 208 // Discardable pixel refs are found in the following grids: | 190 // Discardable pixel refs are found in the following grids: |
| 209 // |---|---|---|---| | 191 // |---|---|---|---| |
| 210 // | | x | | x | | 192 // | | x | | x | |
| 211 // |---|---|---|---| | 193 // |---|---|---|---| |
| 212 // | x | | x | | | 194 // | x | | x | | |
| 213 // |---|---|---|---| | 195 // |---|---|---|---| |
| 214 // | | x | | x | | 196 // | | x | | x | |
| 215 // |---|---|---|---| | 197 // |---|---|---|---| |
| 216 // | x | | x | | | 198 // | x | | x | | |
| 217 // |---|---|---|---| | 199 // |---|---|---|---| |
| 218 SkBitmap discardable_bitmap[4][4]; | 200 SkBitmap discardable_bitmap[4][4]; |
| 219 for (int y = 0; y < 4; ++y) { | 201 for (int y = 0; y < 4; ++y) { |
| 220 for (int x = 0; x < 4; ++x) { | 202 for (int x = 0; x < 4; ++x) { |
| 221 if ((x + y) & 1) { | 203 if ((x + y) & 1) { |
| 222 CreateBitmap( | 204 CreateBitmap( |
| 223 gfx::Size(500, 500), "discardable", &discardable_bitmap[y][x]); | 205 gfx::Size(500, 500), "discardable", &discardable_bitmap[y][x]); |
| 224 SkPaint paint; | 206 SkPaint paint; |
| 225 content_layer_client.add_draw_bitmap( | 207 content_layer_client.add_draw_bitmap( |
| 226 discardable_bitmap[y][x], | 208 discardable_bitmap[y][x], |
| 227 gfx::Point(1024 + x * 512 + 6, y * 512 + 6), paint); | 209 gfx::Point(1024 + x * 512 + 6, y * 512 + 6), paint); |
| 228 } | 210 } |
| 229 } | 211 } |
| 230 } | 212 } |
| 231 | 213 |
| 232 scoped_refptr<Picture> picture = Picture::Create(layer_rect, | 214 scoped_refptr<Picture> picture = |
| 233 &content_layer_client, | 215 Picture::Create(layer_rect, &content_layer_client, tile_grid_size, true, |
| 234 tile_grid_info, | 216 Picture::RECORD_NORMALLY); |
| 235 true, | |
| 236 Picture::RECORD_NORMALLY); | |
| 237 | 217 |
| 238 // Default iterator does not have any pixel refs | 218 // Default iterator does not have any pixel refs |
| 239 { | 219 { |
| 240 Picture::PixelRefIterator iterator; | 220 Picture::PixelRefIterator iterator; |
| 241 EXPECT_FALSE(iterator); | 221 EXPECT_FALSE(iterator); |
| 242 } | 222 } |
| 243 for (int y = 0; y < 4; ++y) { | 223 for (int y = 0; y < 4; ++y) { |
| 244 for (int x = 0; x < 4; ++x) { | 224 for (int x = 0; x < 4; ++x) { |
| 245 Picture::PixelRefIterator iterator( | 225 Picture::PixelRefIterator iterator( |
| 246 gfx::Rect(1024 + x * 512, y * 512, 500, 500), picture.get()); | 226 gfx::Rect(1024 + x * 512, y * 512, 500, 500), picture.get()); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 { | 294 { |
| 315 Picture::PixelRefIterator iterator(gfx::Rect(3500, 1100, 1000, 1000), | 295 Picture::PixelRefIterator iterator(gfx::Rect(3500, 1100, 1000, 1000), |
| 316 picture.get()); | 296 picture.get()); |
| 317 EXPECT_FALSE(iterator); | 297 EXPECT_FALSE(iterator); |
| 318 } | 298 } |
| 319 } | 299 } |
| 320 | 300 |
| 321 TEST(PictureTest, PixelRefIteratorOnePixelQuery) { | 301 TEST(PictureTest, PixelRefIteratorOnePixelQuery) { |
| 322 gfx::Rect layer_rect(2048, 2048); | 302 gfx::Rect layer_rect(2048, 2048); |
| 323 | 303 |
| 324 SkTileGridFactory::TileGridInfo tile_grid_info; | 304 gfx::Size tile_grid_size(512, 512); |
| 325 tile_grid_info.fTileInterval = SkISize::Make(512, 512); | |
| 326 tile_grid_info.fMargin.setEmpty(); | |
| 327 tile_grid_info.fOffset.setZero(); | |
| 328 | 305 |
| 329 FakeContentLayerClient content_layer_client; | 306 FakeContentLayerClient content_layer_client; |
| 330 | 307 |
| 331 // Discardable pixel refs are found in the following grids: | 308 // Discardable pixel refs are found in the following grids: |
| 332 // |---|---|---|---| | 309 // |---|---|---|---| |
| 333 // | | x | | x | | 310 // | | x | | x | |
| 334 // |---|---|---|---| | 311 // |---|---|---|---| |
| 335 // | x | | x | | | 312 // | x | | x | | |
| 336 // |---|---|---|---| | 313 // |---|---|---|---| |
| 337 // | | x | | x | | 314 // | | x | | x | |
| 338 // |---|---|---|---| | 315 // |---|---|---|---| |
| 339 // | x | | x | | | 316 // | x | | x | | |
| 340 // |---|---|---|---| | 317 // |---|---|---|---| |
| 341 SkBitmap discardable_bitmap[4][4]; | 318 SkBitmap discardable_bitmap[4][4]; |
| 342 for (int y = 0; y < 4; ++y) { | 319 for (int y = 0; y < 4; ++y) { |
| 343 for (int x = 0; x < 4; ++x) { | 320 for (int x = 0; x < 4; ++x) { |
| 344 if ((x + y) & 1) { | 321 if ((x + y) & 1) { |
| 345 CreateBitmap( | 322 CreateBitmap( |
| 346 gfx::Size(500, 500), "discardable", &discardable_bitmap[y][x]); | 323 gfx::Size(500, 500), "discardable", &discardable_bitmap[y][x]); |
| 347 SkPaint paint; | 324 SkPaint paint; |
| 348 content_layer_client.add_draw_bitmap( | 325 content_layer_client.add_draw_bitmap( |
| 349 discardable_bitmap[y][x], | 326 discardable_bitmap[y][x], |
| 350 gfx::Point(x * 512 + 6, y * 512 + 6), paint); | 327 gfx::Point(x * 512 + 6, y * 512 + 6), paint); |
| 351 } | 328 } |
| 352 } | 329 } |
| 353 } | 330 } |
| 354 | 331 |
| 355 scoped_refptr<Picture> picture = Picture::Create(layer_rect, | 332 scoped_refptr<Picture> picture = |
| 356 &content_layer_client, | 333 Picture::Create(layer_rect, &content_layer_client, tile_grid_size, true, |
| 357 tile_grid_info, | 334 Picture::RECORD_NORMALLY); |
| 358 true, | |
| 359 Picture::RECORD_NORMALLY); | |
| 360 | 335 |
| 361 for (int y = 0; y < 4; ++y) { | 336 for (int y = 0; y < 4; ++y) { |
| 362 for (int x = 0; x < 4; ++x) { | 337 for (int x = 0; x < 4; ++x) { |
| 363 Picture::PixelRefIterator iterator( | 338 Picture::PixelRefIterator iterator( |
| 364 gfx::Rect(x * 512, y * 512 + 256, 1, 1), picture.get()); | 339 gfx::Rect(x * 512, y * 512 + 256, 1, 1), picture.get()); |
| 365 if ((x + y) & 1) { | 340 if ((x + y) & 1) { |
| 366 EXPECT_TRUE(iterator) << x << " " << y; | 341 EXPECT_TRUE(iterator) << x << " " << y; |
| 367 EXPECT_TRUE(*iterator == discardable_bitmap[y][x].pixelRef()); | 342 EXPECT_TRUE(*iterator == discardable_bitmap[y][x].pixelRef()); |
| 368 EXPECT_FALSE(++iterator) << x << " " << y; | 343 EXPECT_FALSE(++iterator) << x << " " << y; |
| 369 } else { | 344 } else { |
| 370 EXPECT_FALSE(iterator) << x << " " << y; | 345 EXPECT_FALSE(iterator) << x << " " << y; |
| 371 } | 346 } |
| 372 } | 347 } |
| 373 } | 348 } |
| 374 } | 349 } |
| 375 | 350 |
| 376 TEST(PictureTest, CreateFromSkpValue) { | 351 TEST(PictureTest, CreateFromSkpValue) { |
| 377 SkGraphics::Init(); | 352 SkGraphics::Init(); |
| 378 | 353 |
| 379 gfx::Rect layer_rect(100, 200); | 354 gfx::Rect layer_rect(100, 200); |
| 380 | 355 |
| 381 SkTileGridFactory::TileGridInfo tile_grid_info; | 356 gfx::Size tile_grid_size(100, 200); |
| 382 tile_grid_info.fTileInterval = SkISize::Make(100, 200); | |
| 383 tile_grid_info.fMargin.setEmpty(); | |
| 384 tile_grid_info.fOffset.setZero(); | |
| 385 | 357 |
| 386 FakeContentLayerClient content_layer_client; | 358 FakeContentLayerClient content_layer_client; |
| 387 | 359 |
| 388 scoped_ptr<base::Value> tmp; | 360 scoped_ptr<base::Value> tmp; |
| 389 | 361 |
| 390 SkPaint red_paint; | 362 SkPaint red_paint; |
| 391 red_paint.setColor(SkColorSetARGB(255, 255, 0, 0)); | 363 red_paint.setColor(SkColorSetARGB(255, 255, 0, 0)); |
| 392 SkPaint green_paint; | 364 SkPaint green_paint; |
| 393 green_paint.setColor(SkColorSetARGB(255, 0, 255, 0)); | 365 green_paint.setColor(SkColorSetARGB(255, 0, 255, 0)); |
| 394 | 366 |
| 395 // Invalid picture (not a dict). | 367 // Invalid picture (not a dict). |
| 396 tmp.reset(new base::StringValue("abc!@#$%")); | 368 tmp.reset(new base::StringValue("abc!@#$%")); |
| 397 scoped_refptr<Picture> invalid_picture = | 369 scoped_refptr<Picture> invalid_picture = |
| 398 Picture::CreateFromSkpValue(tmp.get()); | 370 Picture::CreateFromSkpValue(tmp.get()); |
| 399 EXPECT_TRUE(!invalid_picture.get()); | 371 EXPECT_TRUE(!invalid_picture.get()); |
| 400 | 372 |
| 401 // Single full-size rect picture. | 373 // Single full-size rect picture. |
| 402 content_layer_client.add_draw_rect(layer_rect, red_paint); | 374 content_layer_client.add_draw_rect(layer_rect, red_paint); |
| 403 scoped_refptr<Picture> one_rect_picture = | 375 scoped_refptr<Picture> one_rect_picture = |
| 404 Picture::Create(layer_rect, | 376 Picture::Create(layer_rect, &content_layer_client, tile_grid_size, false, |
| 405 &content_layer_client, | |
| 406 tile_grid_info, | |
| 407 false, | |
| 408 Picture::RECORD_NORMALLY); | 377 Picture::RECORD_NORMALLY); |
| 409 scoped_ptr<base::Value> serialized_one_rect( | 378 scoped_ptr<base::Value> serialized_one_rect( |
| 410 one_rect_picture->AsValue()); | 379 one_rect_picture->AsValue()); |
| 411 | 380 |
| 412 const base::DictionaryValue* value = NULL; | 381 const base::DictionaryValue* value = NULL; |
| 413 EXPECT_TRUE(serialized_one_rect->GetAsDictionary(&value)); | 382 EXPECT_TRUE(serialized_one_rect->GetAsDictionary(&value)); |
| 414 | 383 |
| 415 // Decode the picture from base64. | 384 // Decode the picture from base64. |
| 416 const base::Value* skp_value; | 385 const base::Value* skp_value; |
| 417 EXPECT_TRUE(value->Get("skp64", &skp_value)); | 386 EXPECT_TRUE(value->Get("skp64", &skp_value)); |
| 418 | 387 |
| 419 // Reconstruct the picture. | 388 // Reconstruct the picture. |
| 420 scoped_refptr<Picture> one_rect_picture_check = | 389 scoped_refptr<Picture> one_rect_picture_check = |
| 421 Picture::CreateFromSkpValue(skp_value); | 390 Picture::CreateFromSkpValue(skp_value); |
| 422 EXPECT_TRUE(!!one_rect_picture_check.get()); | 391 EXPECT_TRUE(!!one_rect_picture_check.get()); |
| 423 | 392 |
| 424 EXPECT_EQ(100, one_rect_picture_check->LayerRect().width()); | 393 EXPECT_EQ(100, one_rect_picture_check->LayerRect().width()); |
| 425 EXPECT_EQ(200, one_rect_picture_check->LayerRect().height()); | 394 EXPECT_EQ(200, one_rect_picture_check->LayerRect().height()); |
| 426 } | 395 } |
| 427 | 396 |
| 428 TEST(PictureTest, RecordingModes) { | 397 TEST(PictureTest, RecordingModes) { |
| 429 SkGraphics::Init(); | 398 SkGraphics::Init(); |
| 430 | 399 |
| 431 gfx::Rect layer_rect(100, 200); | 400 gfx::Rect layer_rect(100, 200); |
| 432 | 401 |
| 433 SkTileGridFactory::TileGridInfo tile_grid_info; | 402 gfx::Size tile_grid_size(100, 200); |
| 434 tile_grid_info.fTileInterval = SkISize::Make(100, 200); | |
| 435 tile_grid_info.fMargin.setEmpty(); | |
| 436 tile_grid_info.fOffset.setZero(); | |
| 437 | 403 |
| 438 FakeContentLayerClient content_layer_client; | 404 FakeContentLayerClient content_layer_client; |
| 439 EXPECT_EQ(NULL, content_layer_client.last_canvas()); | 405 EXPECT_EQ(NULL, content_layer_client.last_canvas()); |
| 440 | 406 |
| 441 scoped_refptr<Picture> picture = Picture::Create(layer_rect, | 407 scoped_refptr<Picture> picture = |
| 442 &content_layer_client, | 408 Picture::Create(layer_rect, &content_layer_client, tile_grid_size, false, |
| 443 tile_grid_info, | 409 Picture::RECORD_NORMALLY); |
| 444 false, | |
| 445 Picture::RECORD_NORMALLY); | |
| 446 EXPECT_TRUE(content_layer_client.last_canvas() != NULL); | 410 EXPECT_TRUE(content_layer_client.last_canvas() != NULL); |
| 447 EXPECT_EQ(ContentLayerClient::GRAPHICS_CONTEXT_ENABLED, | 411 EXPECT_EQ(ContentLayerClient::GRAPHICS_CONTEXT_ENABLED, |
| 448 content_layer_client.last_context_status()); | 412 content_layer_client.last_context_status()); |
| 449 EXPECT_TRUE(picture.get()); | 413 EXPECT_TRUE(picture.get()); |
| 450 | 414 |
| 451 picture = Picture::Create(layer_rect, | 415 picture = Picture::Create(layer_rect, &content_layer_client, tile_grid_size, |
| 452 &content_layer_client, | 416 false, Picture::RECORD_WITH_SK_NULL_CANVAS); |
| 453 tile_grid_info, | |
| 454 false, | |
| 455 Picture::RECORD_WITH_SK_NULL_CANVAS); | |
| 456 EXPECT_TRUE(content_layer_client.last_canvas() != NULL); | 417 EXPECT_TRUE(content_layer_client.last_canvas() != NULL); |
| 457 EXPECT_EQ(ContentLayerClient::GRAPHICS_CONTEXT_ENABLED, | 418 EXPECT_EQ(ContentLayerClient::GRAPHICS_CONTEXT_ENABLED, |
| 458 content_layer_client.last_context_status()); | 419 content_layer_client.last_context_status()); |
| 459 EXPECT_TRUE(picture.get()); | 420 EXPECT_TRUE(picture.get()); |
| 460 | 421 |
| 461 picture = Picture::Create(layer_rect, | 422 picture = Picture::Create(layer_rect, &content_layer_client, tile_grid_size, |
| 462 &content_layer_client, | 423 false, Picture::RECORD_WITH_PAINTING_DISABLED); |
| 463 tile_grid_info, | |
| 464 false, | |
| 465 Picture::RECORD_WITH_PAINTING_DISABLED); | |
| 466 EXPECT_TRUE(content_layer_client.last_canvas() != NULL); | 424 EXPECT_TRUE(content_layer_client.last_canvas() != NULL); |
| 467 EXPECT_EQ(ContentLayerClient::GRAPHICS_CONTEXT_DISABLED, | 425 EXPECT_EQ(ContentLayerClient::GRAPHICS_CONTEXT_DISABLED, |
| 468 content_layer_client.last_context_status()); | 426 content_layer_client.last_context_status()); |
| 469 EXPECT_TRUE(picture.get()); | 427 EXPECT_TRUE(picture.get()); |
| 470 | 428 |
| 471 EXPECT_EQ(3, Picture::RECORDING_MODE_COUNT); | 429 EXPECT_EQ(3, Picture::RECORDING_MODE_COUNT); |
| 472 } | 430 } |
| 473 | 431 |
| 474 } // namespace | 432 } // namespace |
| 475 } // namespace cc | 433 } // namespace cc |
| OLD | NEW |