| 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/fake_rendering_stats_instrumentation.h" | |
| 12 #include "cc/test/skia_common.h" | 11 #include "cc/test/skia_common.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "third_party/skia/include/core/SkCanvas.h" | 13 #include "third_party/skia/include/core/SkCanvas.h" |
| 15 #include "third_party/skia/include/core/SkDevice.h" | 14 #include "third_party/skia/include/core/SkDevice.h" |
| 16 #include "third_party/skia/include/core/SkGraphics.h" | 15 #include "third_party/skia/include/core/SkGraphics.h" |
| 17 #include "third_party/skia/include/core/SkPixelRef.h" | 16 #include "third_party/skia/include/core/SkPixelRef.h" |
| 18 #include "third_party/skia/include/core/SkTileGridPicture.h" | 17 #include "third_party/skia/include/core/SkTileGridPicture.h" |
| 19 #include "ui/gfx/rect.h" | 18 #include "ui/gfx/rect.h" |
| 20 #include "ui/gfx/skia_util.h" | 19 #include "ui/gfx/skia_util.h" |
| 21 | 20 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 | 102 |
| 104 TEST(PictureTest, PixelRefIterator) { | 103 TEST(PictureTest, PixelRefIterator) { |
| 105 gfx::Rect layer_rect(2048, 2048); | 104 gfx::Rect layer_rect(2048, 2048); |
| 106 | 105 |
| 107 SkTileGridPicture::TileGridInfo tile_grid_info; | 106 SkTileGridPicture::TileGridInfo tile_grid_info; |
| 108 tile_grid_info.fTileInterval = SkISize::Make(512, 512); | 107 tile_grid_info.fTileInterval = SkISize::Make(512, 512); |
| 109 tile_grid_info.fMargin.setEmpty(); | 108 tile_grid_info.fMargin.setEmpty(); |
| 110 tile_grid_info.fOffset.setZero(); | 109 tile_grid_info.fOffset.setZero(); |
| 111 | 110 |
| 112 FakeContentLayerClient content_layer_client; | 111 FakeContentLayerClient content_layer_client; |
| 113 FakeRenderingStatsInstrumentation stats_instrumentation; | |
| 114 | 112 |
| 115 // Lazy pixel refs are found in the following grids: | 113 // Lazy pixel refs are found in the following grids: |
| 116 // |---|---|---|---| | 114 // |---|---|---|---| |
| 117 // | | x | | x | | 115 // | | x | | x | |
| 118 // |---|---|---|---| | 116 // |---|---|---|---| |
| 119 // | x | | x | | | 117 // | x | | x | | |
| 120 // |---|---|---|---| | 118 // |---|---|---|---| |
| 121 // | | x | | x | | 119 // | | x | | x | |
| 122 // |---|---|---|---| | 120 // |---|---|---|---| |
| 123 // | x | | x | | | 121 // | x | | x | | |
| 124 // |---|---|---|---| | 122 // |---|---|---|---| |
| 125 SkBitmap lazy_bitmap[4][4]; | 123 SkBitmap lazy_bitmap[4][4]; |
| 126 for (int y = 0; y < 4; ++y) { | 124 for (int y = 0; y < 4; ++y) { |
| 127 for (int x = 0; x < 4; ++x) { | 125 for (int x = 0; x < 4; ++x) { |
| 128 if ((x + y) & 1) { | 126 if ((x + y) & 1) { |
| 129 CreateBitmap(gfx::Size(500, 500), "lazy", &lazy_bitmap[y][x]); | 127 CreateBitmap(gfx::Size(500, 500), "lazy", &lazy_bitmap[y][x]); |
| 130 content_layer_client.add_draw_bitmap( | 128 content_layer_client.add_draw_bitmap( |
| 131 lazy_bitmap[y][x], | 129 lazy_bitmap[y][x], |
| 132 gfx::Point(x * 512 + 6, y * 512 + 6)); | 130 gfx::Point(x * 512 + 6, y * 512 + 6)); |
| 133 } | 131 } |
| 134 } | 132 } |
| 135 } | 133 } |
| 136 | 134 |
| 137 scoped_refptr<Picture> picture = Picture::Create(layer_rect); | 135 scoped_refptr<Picture> picture = Picture::Create(layer_rect); |
| 138 picture->Record(&content_layer_client, | 136 picture->Record(&content_layer_client, |
| 139 tile_grid_info); | 137 tile_grid_info); |
| 140 picture->GatherPixelRefs(tile_grid_info, &stats_instrumentation); | 138 picture->GatherPixelRefs(tile_grid_info); |
| 141 | 139 |
| 142 // Default iterator does not have any pixel refs | 140 // Default iterator does not have any pixel refs |
| 143 { | 141 { |
| 144 Picture::PixelRefIterator iterator; | 142 Picture::PixelRefIterator iterator; |
| 145 EXPECT_FALSE(iterator); | 143 EXPECT_FALSE(iterator); |
| 146 } | 144 } |
| 147 for (int y = 0; y < 4; ++y) { | 145 for (int y = 0; y < 4; ++y) { |
| 148 for (int x = 0; x < 4; ++x) { | 146 for (int x = 0; x < 4; ++x) { |
| 149 Picture::PixelRefIterator iterator(gfx::Rect(x * 512, y * 512, 500, 500), | 147 Picture::PixelRefIterator iterator(gfx::Rect(x * 512, y * 512, 500, 500), |
| 150 picture.get()); | 148 picture.get()); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 | 198 |
| 201 TEST(PictureTest, PixelRefIteratorNonZeroLayer) { | 199 TEST(PictureTest, PixelRefIteratorNonZeroLayer) { |
| 202 gfx::Rect layer_rect(1024, 0, 2048, 2048); | 200 gfx::Rect layer_rect(1024, 0, 2048, 2048); |
| 203 | 201 |
| 204 SkTileGridPicture::TileGridInfo tile_grid_info; | 202 SkTileGridPicture::TileGridInfo tile_grid_info; |
| 205 tile_grid_info.fTileInterval = SkISize::Make(512, 512); | 203 tile_grid_info.fTileInterval = SkISize::Make(512, 512); |
| 206 tile_grid_info.fMargin.setEmpty(); | 204 tile_grid_info.fMargin.setEmpty(); |
| 207 tile_grid_info.fOffset.setZero(); | 205 tile_grid_info.fOffset.setZero(); |
| 208 | 206 |
| 209 FakeContentLayerClient content_layer_client; | 207 FakeContentLayerClient content_layer_client; |
| 210 FakeRenderingStatsInstrumentation stats_instrumentation; | |
| 211 | 208 |
| 212 // Lazy pixel refs are found in the following grids: | 209 // Lazy pixel refs are found in the following grids: |
| 213 // |---|---|---|---| | 210 // |---|---|---|---| |
| 214 // | | x | | x | | 211 // | | x | | x | |
| 215 // |---|---|---|---| | 212 // |---|---|---|---| |
| 216 // | x | | x | | | 213 // | x | | x | | |
| 217 // |---|---|---|---| | 214 // |---|---|---|---| |
| 218 // | | x | | x | | 215 // | | x | | x | |
| 219 // |---|---|---|---| | 216 // |---|---|---|---| |
| 220 // | x | | x | | | 217 // | x | | x | | |
| 221 // |---|---|---|---| | 218 // |---|---|---|---| |
| 222 SkBitmap lazy_bitmap[4][4]; | 219 SkBitmap lazy_bitmap[4][4]; |
| 223 for (int y = 0; y < 4; ++y) { | 220 for (int y = 0; y < 4; ++y) { |
| 224 for (int x = 0; x < 4; ++x) { | 221 for (int x = 0; x < 4; ++x) { |
| 225 if ((x + y) & 1) { | 222 if ((x + y) & 1) { |
| 226 CreateBitmap(gfx::Size(500, 500), "lazy", &lazy_bitmap[y][x]); | 223 CreateBitmap(gfx::Size(500, 500), "lazy", &lazy_bitmap[y][x]); |
| 227 content_layer_client.add_draw_bitmap( | 224 content_layer_client.add_draw_bitmap( |
| 228 lazy_bitmap[y][x], | 225 lazy_bitmap[y][x], |
| 229 gfx::Point(1024 + x * 512 + 6, y * 512 + 6)); | 226 gfx::Point(1024 + x * 512 + 6, y * 512 + 6)); |
| 230 } | 227 } |
| 231 } | 228 } |
| 232 } | 229 } |
| 233 | 230 |
| 234 scoped_refptr<Picture> picture = Picture::Create(layer_rect); | 231 scoped_refptr<Picture> picture = Picture::Create(layer_rect); |
| 235 picture->Record(&content_layer_client, | 232 picture->Record(&content_layer_client, |
| 236 tile_grid_info); | 233 tile_grid_info); |
| 237 picture->GatherPixelRefs(tile_grid_info, &stats_instrumentation); | 234 picture->GatherPixelRefs(tile_grid_info); |
| 238 | 235 |
| 239 // Default iterator does not have any pixel refs | 236 // Default iterator does not have any pixel refs |
| 240 { | 237 { |
| 241 Picture::PixelRefIterator iterator; | 238 Picture::PixelRefIterator iterator; |
| 242 EXPECT_FALSE(iterator); | 239 EXPECT_FALSE(iterator); |
| 243 } | 240 } |
| 244 for (int y = 0; y < 4; ++y) { | 241 for (int y = 0; y < 4; ++y) { |
| 245 for (int x = 0; x < 4; ++x) { | 242 for (int x = 0; x < 4; ++x) { |
| 246 Picture::PixelRefIterator iterator( | 243 Picture::PixelRefIterator iterator( |
| 247 gfx::Rect(1024 + x * 512, y * 512, 500, 500), picture.get()); | 244 gfx::Rect(1024 + x * 512, y * 512, 500, 500), picture.get()); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 | 318 |
| 322 TEST(PictureTest, PixelRefIteratorOnePixelQuery) { | 319 TEST(PictureTest, PixelRefIteratorOnePixelQuery) { |
| 323 gfx::Rect layer_rect(2048, 2048); | 320 gfx::Rect layer_rect(2048, 2048); |
| 324 | 321 |
| 325 SkTileGridPicture::TileGridInfo tile_grid_info; | 322 SkTileGridPicture::TileGridInfo tile_grid_info; |
| 326 tile_grid_info.fTileInterval = SkISize::Make(512, 512); | 323 tile_grid_info.fTileInterval = SkISize::Make(512, 512); |
| 327 tile_grid_info.fMargin.setEmpty(); | 324 tile_grid_info.fMargin.setEmpty(); |
| 328 tile_grid_info.fOffset.setZero(); | 325 tile_grid_info.fOffset.setZero(); |
| 329 | 326 |
| 330 FakeContentLayerClient content_layer_client; | 327 FakeContentLayerClient content_layer_client; |
| 331 FakeRenderingStatsInstrumentation stats_instrumentation; | |
| 332 | 328 |
| 333 // Lazy pixel refs are found in the following grids: | 329 // Lazy pixel refs are found in the following grids: |
| 334 // |---|---|---|---| | 330 // |---|---|---|---| |
| 335 // | | x | | x | | 331 // | | x | | x | |
| 336 // |---|---|---|---| | 332 // |---|---|---|---| |
| 337 // | x | | x | | | 333 // | x | | x | | |
| 338 // |---|---|---|---| | 334 // |---|---|---|---| |
| 339 // | | x | | x | | 335 // | | x | | x | |
| 340 // |---|---|---|---| | 336 // |---|---|---|---| |
| 341 // | x | | x | | | 337 // | x | | x | | |
| 342 // |---|---|---|---| | 338 // |---|---|---|---| |
| 343 SkBitmap lazy_bitmap[4][4]; | 339 SkBitmap lazy_bitmap[4][4]; |
| 344 for (int y = 0; y < 4; ++y) { | 340 for (int y = 0; y < 4; ++y) { |
| 345 for (int x = 0; x < 4; ++x) { | 341 for (int x = 0; x < 4; ++x) { |
| 346 if ((x + y) & 1) { | 342 if ((x + y) & 1) { |
| 347 CreateBitmap(gfx::Size(500, 500), "lazy", &lazy_bitmap[y][x]); | 343 CreateBitmap(gfx::Size(500, 500), "lazy", &lazy_bitmap[y][x]); |
| 348 content_layer_client.add_draw_bitmap( | 344 content_layer_client.add_draw_bitmap( |
| 349 lazy_bitmap[y][x], | 345 lazy_bitmap[y][x], |
| 350 gfx::Point(x * 512 + 6, y * 512 + 6)); | 346 gfx::Point(x * 512 + 6, y * 512 + 6)); |
| 351 } | 347 } |
| 352 } | 348 } |
| 353 } | 349 } |
| 354 | 350 |
| 355 scoped_refptr<Picture> picture = Picture::Create(layer_rect); | 351 scoped_refptr<Picture> picture = Picture::Create(layer_rect); |
| 356 picture->Record(&content_layer_client, | 352 picture->Record(&content_layer_client, |
| 357 tile_grid_info); | 353 tile_grid_info); |
| 358 picture->GatherPixelRefs(tile_grid_info, &stats_instrumentation); | 354 picture->GatherPixelRefs(tile_grid_info); |
| 359 | 355 |
| 360 for (int y = 0; y < 4; ++y) { | 356 for (int y = 0; y < 4; ++y) { |
| 361 for (int x = 0; x < 4; ++x) { | 357 for (int x = 0; x < 4; ++x) { |
| 362 Picture::PixelRefIterator iterator( | 358 Picture::PixelRefIterator iterator( |
| 363 gfx::Rect(x * 512, y * 512 + 256, 1, 1), picture.get()); | 359 gfx::Rect(x * 512, y * 512 + 256, 1, 1), picture.get()); |
| 364 if ((x + y) & 1) { | 360 if ((x + y) & 1) { |
| 365 EXPECT_TRUE(iterator) << x << " " << y; | 361 EXPECT_TRUE(iterator) << x << " " << y; |
| 366 EXPECT_TRUE(*iterator == lazy_bitmap[y][x].pixelRef()); | 362 EXPECT_TRUE(*iterator == lazy_bitmap[y][x].pixelRef()); |
| 367 EXPECT_FALSE(++iterator) << x << " " << y; | 363 EXPECT_FALSE(++iterator) << x << " " << y; |
| 368 } else { | 364 } else { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 Picture::CreateFromSkpValue(skp_value); | 413 Picture::CreateFromSkpValue(skp_value); |
| 418 EXPECT_TRUE(!!one_rect_picture_check.get()); | 414 EXPECT_TRUE(!!one_rect_picture_check.get()); |
| 419 | 415 |
| 420 EXPECT_EQ(100, one_rect_picture_check->LayerRect().width()); | 416 EXPECT_EQ(100, one_rect_picture_check->LayerRect().width()); |
| 421 EXPECT_EQ(200, one_rect_picture_check->LayerRect().height()); | 417 EXPECT_EQ(200, one_rect_picture_check->LayerRect().height()); |
| 422 EXPECT_EQ(100, one_rect_picture_check->OpaqueRect().width()); | 418 EXPECT_EQ(100, one_rect_picture_check->OpaqueRect().width()); |
| 423 EXPECT_EQ(200, one_rect_picture_check->OpaqueRect().height()); | 419 EXPECT_EQ(200, one_rect_picture_check->OpaqueRect().height()); |
| 424 } | 420 } |
| 425 } // namespace | 421 } // namespace |
| 426 } // namespace cc | 422 } // namespace cc |
| OLD | NEW |