OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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_layer_tiling.h" | 5 #include "cc/resources/picture_layer_tiling.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "cc/base/math_util.h" | 10 #include "cc/base/math_util.h" |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 Region invalidation = | 214 Region invalidation = |
215 SubtractRegions(gfx::Rect(tile_size), gfx::Rect(original_layer_size)); | 215 SubtractRegions(gfx::Rect(tile_size), gfx::Rect(original_layer_size)); |
216 tiling_->Resize(gfx::Size(200, 200)); | 216 tiling_->Resize(gfx::Size(200, 200)); |
217 EXPECT_TRUE(tiling_->TileAt(0, 0)); | 217 EXPECT_TRUE(tiling_->TileAt(0, 0)); |
218 tiling_->Invalidate(invalidation); | 218 tiling_->Invalidate(invalidation); |
219 EXPECT_FALSE(tiling_->TileAt(0, 0)); | 219 EXPECT_FALSE(tiling_->TileAt(0, 0)); |
220 } | 220 } |
221 | 221 |
222 TEST_F(PictureLayerTilingIteratorTest, CreateMissingTilesStaysInsideLiveRect) { | 222 TEST_F(PictureLayerTilingIteratorTest, CreateMissingTilesStaysInsideLiveRect) { |
223 // The tiling has three rows and columns. | 223 // The tiling has three rows and columns. |
224 Initialize(gfx::Size(100, 100), 1, gfx::Size(250, 250)); | 224 Initialize(gfx::Size(100, 100), 1.f, gfx::Size(250, 250)); |
225 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_x()); | 225 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_x()); |
226 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_y()); | 226 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_y()); |
227 | 227 |
228 // The live tiles rect is at the very edge of the right-most and | 228 // The live tiles rect is at the very edge of the right-most and |
229 // bottom-most tiles. Their border pixels would still be inside the live | 229 // bottom-most tiles. Their border pixels would still be inside the live |
230 // tiles rect, but the tiles should not exist just for that. | 230 // tiles rect, but the tiles should not exist just for that. |
231 int right = tiling_->TilingDataForTesting().TileBounds(2, 2).x(); | 231 int right = tiling_->TilingDataForTesting().TileBounds(2, 2).x(); |
232 int bottom = tiling_->TilingDataForTesting().TileBounds(2, 2).y(); | 232 int bottom = tiling_->TilingDataForTesting().TileBounds(2, 2).y(); |
233 | 233 |
234 SetLiveRectAndVerifyTiles(gfx::Rect(right, bottom)); | 234 SetLiveRectAndVerifyTiles(gfx::Rect(right, bottom)); |
235 EXPECT_FALSE(tiling_->TileAt(2, 0)); | 235 EXPECT_FALSE(tiling_->TileAt(2, 0)); |
236 EXPECT_FALSE(tiling_->TileAt(2, 1)); | 236 EXPECT_FALSE(tiling_->TileAt(2, 1)); |
237 EXPECT_FALSE(tiling_->TileAt(2, 2)); | 237 EXPECT_FALSE(tiling_->TileAt(2, 2)); |
238 EXPECT_FALSE(tiling_->TileAt(1, 2)); | 238 EXPECT_FALSE(tiling_->TileAt(1, 2)); |
239 EXPECT_FALSE(tiling_->TileAt(0, 2)); | 239 EXPECT_FALSE(tiling_->TileAt(0, 2)); |
240 | 240 |
241 // Verify CreateMissingTilesInLiveTilesRect respects this. | 241 // Verify CreateMissingTilesInLiveTilesRect respects this. |
242 tiling_->CreateMissingTilesInLiveTilesRect(); | 242 tiling_->CreateMissingTilesInLiveTilesRect(); |
243 EXPECT_FALSE(tiling_->TileAt(2, 0)); | 243 EXPECT_FALSE(tiling_->TileAt(2, 0)); |
244 EXPECT_FALSE(tiling_->TileAt(2, 1)); | 244 EXPECT_FALSE(tiling_->TileAt(2, 1)); |
245 EXPECT_FALSE(tiling_->TileAt(2, 2)); | 245 EXPECT_FALSE(tiling_->TileAt(2, 2)); |
246 EXPECT_FALSE(tiling_->TileAt(1, 2)); | 246 EXPECT_FALSE(tiling_->TileAt(1, 2)); |
247 EXPECT_FALSE(tiling_->TileAt(0, 2)); | 247 EXPECT_FALSE(tiling_->TileAt(0, 2)); |
248 } | 248 } |
249 | 249 |
250 TEST_F(PictureLayerTilingIteratorTest, ResizeTilingOverTileBorders) { | 250 TEST_F(PictureLayerTilingIteratorTest, ResizeTilingOverTileBorders) { |
251 // The tiling has four rows and three columns. | 251 // The tiling has four rows and three columns. |
252 Initialize(gfx::Size(100, 100), 1, gfx::Size(250, 350)); | 252 Initialize(gfx::Size(100, 100), 1.f, gfx::Size(250, 350)); |
253 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_x()); | 253 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_x()); |
254 EXPECT_EQ(4, tiling_->TilingDataForTesting().num_tiles_y()); | 254 EXPECT_EQ(4, tiling_->TilingDataForTesting().num_tiles_y()); |
255 | 255 |
256 // The live tiles rect covers the whole tiling. | 256 // The live tiles rect covers the whole tiling. |
257 SetLiveRectAndVerifyTiles(gfx::Rect(250, 350)); | 257 SetLiveRectAndVerifyTiles(gfx::Rect(250, 350)); |
258 | 258 |
259 // Tiles in the bottom row and right column exist. | 259 // Tiles in the bottom row and right column exist. |
260 EXPECT_TRUE(tiling_->TileAt(2, 0)); | 260 EXPECT_TRUE(tiling_->TileAt(2, 0)); |
261 EXPECT_TRUE(tiling_->TileAt(2, 1)); | 261 EXPECT_TRUE(tiling_->TileAt(2, 1)); |
262 EXPECT_TRUE(tiling_->TileAt(2, 2)); | 262 EXPECT_TRUE(tiling_->TileAt(2, 2)); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 EXPECT_TRUE(tiling_->TileAt(2, 0)); | 302 EXPECT_TRUE(tiling_->TileAt(2, 0)); |
303 EXPECT_TRUE(tiling_->TileAt(2, 1)); | 303 EXPECT_TRUE(tiling_->TileAt(2, 1)); |
304 EXPECT_TRUE(tiling_->TileAt(2, 2)); | 304 EXPECT_TRUE(tiling_->TileAt(2, 2)); |
305 EXPECT_TRUE(tiling_->TileAt(2, 3)); | 305 EXPECT_TRUE(tiling_->TileAt(2, 3)); |
306 EXPECT_TRUE(tiling_->TileAt(1, 3)); | 306 EXPECT_TRUE(tiling_->TileAt(1, 3)); |
307 EXPECT_TRUE(tiling_->TileAt(0, 3)); | 307 EXPECT_TRUE(tiling_->TileAt(0, 3)); |
308 } | 308 } |
309 | 309 |
310 TEST_F(PictureLayerTilingIteratorTest, ResizeLiveTileRectOverTileBorders) { | 310 TEST_F(PictureLayerTilingIteratorTest, ResizeLiveTileRectOverTileBorders) { |
311 // The tiling has three rows and columns. | 311 // The tiling has three rows and columns. |
312 Initialize(gfx::Size(100, 100), 1, gfx::Size(250, 350)); | 312 Initialize(gfx::Size(100, 100), 1.f, gfx::Size(250, 350)); |
313 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_x()); | 313 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_x()); |
314 EXPECT_EQ(4, tiling_->TilingDataForTesting().num_tiles_y()); | 314 EXPECT_EQ(4, tiling_->TilingDataForTesting().num_tiles_y()); |
315 | 315 |
316 // The live tiles rect covers the whole tiling. | 316 // The live tiles rect covers the whole tiling. |
317 SetLiveRectAndVerifyTiles(gfx::Rect(250, 350)); | 317 SetLiveRectAndVerifyTiles(gfx::Rect(250, 350)); |
318 | 318 |
319 // Tiles in the bottom row and right column exist. | 319 // Tiles in the bottom row and right column exist. |
320 EXPECT_TRUE(tiling_->TileAt(2, 0)); | 320 EXPECT_TRUE(tiling_->TileAt(2, 0)); |
321 EXPECT_TRUE(tiling_->TileAt(2, 1)); | 321 EXPECT_TRUE(tiling_->TileAt(2, 1)); |
322 EXPECT_TRUE(tiling_->TileAt(2, 2)); | 322 EXPECT_TRUE(tiling_->TileAt(2, 2)); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 EXPECT_TRUE(tiling_->TileAt(0, 3)); | 367 EXPECT_TRUE(tiling_->TileAt(0, 3)); |
368 EXPECT_TRUE(tiling_->TileAt(0, 2)); | 368 EXPECT_TRUE(tiling_->TileAt(0, 2)); |
369 EXPECT_TRUE(tiling_->TileAt(0, 1)); | 369 EXPECT_TRUE(tiling_->TileAt(0, 1)); |
370 EXPECT_TRUE(tiling_->TileAt(0, 0)); | 370 EXPECT_TRUE(tiling_->TileAt(0, 0)); |
371 EXPECT_TRUE(tiling_->TileAt(1, 0)); | 371 EXPECT_TRUE(tiling_->TileAt(1, 0)); |
372 EXPECT_TRUE(tiling_->TileAt(2, 0)); | 372 EXPECT_TRUE(tiling_->TileAt(2, 0)); |
373 } | 373 } |
374 | 374 |
375 TEST_F(PictureLayerTilingIteratorTest, ResizeLiveTileRectOverSameTiles) { | 375 TEST_F(PictureLayerTilingIteratorTest, ResizeLiveTileRectOverSameTiles) { |
376 // The tiling has four rows and three columns. | 376 // The tiling has four rows and three columns. |
377 Initialize(gfx::Size(100, 100), 1, gfx::Size(250, 350)); | 377 Initialize(gfx::Size(100, 100), 1.f, gfx::Size(250, 350)); |
378 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_x()); | 378 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_x()); |
379 EXPECT_EQ(4, tiling_->TilingDataForTesting().num_tiles_y()); | 379 EXPECT_EQ(4, tiling_->TilingDataForTesting().num_tiles_y()); |
380 | 380 |
381 // The live tiles rect covers the whole tiling. | 381 // The live tiles rect covers the whole tiling. |
382 SetLiveRectAndVerifyTiles(gfx::Rect(250, 350)); | 382 SetLiveRectAndVerifyTiles(gfx::Rect(250, 350)); |
383 | 383 |
384 // All tiles exist. | 384 // All tiles exist. |
385 for (int i = 0; i < 3; ++i) { | 385 for (int i = 0; i < 3; ++i) { |
386 for (int j = 0; j < 4; ++j) | 386 for (int j = 0; j < 4; ++j) |
387 EXPECT_TRUE(tiling_->TileAt(i, j)) << i << "," << j; | 387 EXPECT_TRUE(tiling_->TileAt(i, j)) << i << "," << j; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 tiling_->Invalidate(invalidation); | 427 tiling_->Invalidate(invalidation); |
428 EXPECT_FALSE(tiling_->TileAt(0, 0)); | 428 EXPECT_FALSE(tiling_->TileAt(0, 0)); |
429 | 429 |
430 // The original tile was the same size after resize, but it would include new | 430 // The original tile was the same size after resize, but it would include new |
431 // border pixels. | 431 // border pixels. |
432 EXPECT_EQ(gfx::Rect(original_layer_size), | 432 EXPECT_EQ(gfx::Rect(original_layer_size), |
433 tiling_->TilingDataForTesting().TileBounds(0, 0)); | 433 tiling_->TilingDataForTesting().TileBounds(0, 0)); |
434 } | 434 } |
435 | 435 |
436 TEST_F(PictureLayerTilingIteratorTest, LiveTilesExactlyCoverLiveTileRect) { | 436 TEST_F(PictureLayerTilingIteratorTest, LiveTilesExactlyCoverLiveTileRect) { |
437 Initialize(gfx::Size(100, 100), 1, gfx::Size(1099, 801)); | 437 Initialize(gfx::Size(100, 100), 1.f, gfx::Size(1099, 801)); |
438 SetLiveRectAndVerifyTiles(gfx::Rect(100, 100)); | 438 SetLiveRectAndVerifyTiles(gfx::Rect(100, 100)); |
439 SetLiveRectAndVerifyTiles(gfx::Rect(101, 99)); | 439 SetLiveRectAndVerifyTiles(gfx::Rect(101, 99)); |
440 SetLiveRectAndVerifyTiles(gfx::Rect(1099, 1)); | 440 SetLiveRectAndVerifyTiles(gfx::Rect(1099, 1)); |
441 SetLiveRectAndVerifyTiles(gfx::Rect(1, 801)); | 441 SetLiveRectAndVerifyTiles(gfx::Rect(1, 801)); |
442 SetLiveRectAndVerifyTiles(gfx::Rect(1099, 1)); | 442 SetLiveRectAndVerifyTiles(gfx::Rect(1099, 1)); |
443 SetLiveRectAndVerifyTiles(gfx::Rect(201, 800)); | 443 SetLiveRectAndVerifyTiles(gfx::Rect(201, 800)); |
444 } | 444 } |
445 | 445 |
446 TEST_F(PictureLayerTilingIteratorTest, IteratorCoversLayerBoundsNoScale) { | 446 TEST_F(PictureLayerTilingIteratorTest, IteratorCoversLayerBoundsNoScale) { |
447 Initialize(gfx::Size(100, 100), 1, gfx::Size(1099, 801)); | 447 Initialize(gfx::Size(100, 100), 1.f, gfx::Size(1099, 801)); |
448 VerifyTilesExactlyCoverRect(1, gfx::Rect()); | 448 VerifyTilesExactlyCoverRect(1, gfx::Rect()); |
449 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1099, 801)); | 449 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1099, 801)); |
450 VerifyTilesExactlyCoverRect(1, gfx::Rect(52, 83, 789, 412)); | 450 VerifyTilesExactlyCoverRect(1, gfx::Rect(52, 83, 789, 412)); |
451 | 451 |
452 // With borders, a size of 3x3 = 1 pixel of content. | 452 // With borders, a size of 3x3 = 1 pixel of content. |
453 Initialize(gfx::Size(3, 3), 1, gfx::Size(10, 10)); | 453 Initialize(gfx::Size(3, 3), 1.f, gfx::Size(10, 10)); |
454 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1, 1)); | 454 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1, 1)); |
455 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 2, 2)); | 455 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 2, 2)); |
456 VerifyTilesExactlyCoverRect(1, gfx::Rect(1, 1, 2, 2)); | 456 VerifyTilesExactlyCoverRect(1, gfx::Rect(1, 1, 2, 2)); |
457 VerifyTilesExactlyCoverRect(1, gfx::Rect(3, 2, 5, 2)); | 457 VerifyTilesExactlyCoverRect(1, gfx::Rect(3, 2, 5, 2)); |
458 } | 458 } |
459 | 459 |
460 TEST_F(PictureLayerTilingIteratorTest, IteratorCoversLayerBoundsTilingScale) { | 460 TEST_F(PictureLayerTilingIteratorTest, IteratorCoversLayerBoundsTilingScale) { |
461 Initialize(gfx::Size(200, 100), 2.0f, gfx::Size(1005, 2010)); | 461 Initialize(gfx::Size(200, 100), 2.0f, gfx::Size(1005, 2010)); |
462 VerifyTilesExactlyCoverRect(1, gfx::Rect()); | 462 VerifyTilesExactlyCoverRect(1, gfx::Rect()); |
463 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1005, 2010)); | 463 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1005, 2010)); |
(...skipping 1597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2061 EXPECT_EQ(active_tiling->TileAt(0, 0), recycle_tiling->TileAt(0, 0)); | 2061 EXPECT_EQ(active_tiling->TileAt(0, 0), recycle_tiling->TileAt(0, 0)); |
2062 | 2062 |
2063 // Reset the active tiling. The recycle tiles should be released too. | 2063 // Reset the active tiling. The recycle tiles should be released too. |
2064 active_tiling->Reset(); | 2064 active_tiling->Reset(); |
2065 EXPECT_FALSE(active_tiling->TileAt(0, 0)); | 2065 EXPECT_FALSE(active_tiling->TileAt(0, 0)); |
2066 EXPECT_FALSE(recycle_tiling->TileAt(0, 0)); | 2066 EXPECT_FALSE(recycle_tiling->TileAt(0, 0)); |
2067 } | 2067 } |
2068 | 2068 |
2069 TEST_F(PictureLayerTilingIteratorTest, ResizeTilesAndUpdateToCurrent) { | 2069 TEST_F(PictureLayerTilingIteratorTest, ResizeTilesAndUpdateToCurrent) { |
2070 // The tiling has four rows and three columns. | 2070 // The tiling has four rows and three columns. |
2071 Initialize(gfx::Size(150, 100), 1, gfx::Size(250, 150)); | 2071 Initialize(gfx::Size(150, 100), 1.f, gfx::Size(250, 150)); |
2072 tiling_->CreateAllTilesForTesting(); | 2072 tiling_->CreateAllTilesForTesting(); |
2073 EXPECT_EQ(150, tiling_->TilingDataForTesting().max_texture_size().width()); | 2073 EXPECT_EQ(150, tiling_->TilingDataForTesting().max_texture_size().width()); |
2074 EXPECT_EQ(100, tiling_->TilingDataForTesting().max_texture_size().height()); | 2074 EXPECT_EQ(100, tiling_->TilingDataForTesting().max_texture_size().height()); |
2075 EXPECT_EQ(4u, tiling_->AllRefTilesForTesting().size()); | 2075 EXPECT_EQ(4u, tiling_->AllRefTilesForTesting().size()); |
2076 | 2076 |
2077 client_.SetTileSize(gfx::Size(250, 200)); | 2077 client_.SetTileSize(gfx::Size(250, 200)); |
2078 client_.set_tree(PENDING_TREE); | 2078 client_.set_tree(PENDING_TREE); |
2079 | 2079 |
2080 // Tile size in the tiling should still be 150x100. | 2080 // Tile size in the tiling should still be 150x100. |
2081 EXPECT_EQ(150, tiling_->TilingDataForTesting().max_texture_size().width()); | 2081 EXPECT_EQ(150, tiling_->TilingDataForTesting().max_texture_size().width()); |
2082 EXPECT_EQ(100, tiling_->TilingDataForTesting().max_texture_size().height()); | 2082 EXPECT_EQ(100, tiling_->TilingDataForTesting().max_texture_size().height()); |
2083 | 2083 |
2084 tiling_->Resize(gfx::Size(250, 150)); | 2084 tiling_->Resize(gfx::Size(250, 150)); |
2085 | 2085 |
2086 // Tile size in the tiling should be resized to 250x200. | 2086 // Tile size in the tiling should be resized to 250x200. |
2087 EXPECT_EQ(250, tiling_->TilingDataForTesting().max_texture_size().width()); | 2087 EXPECT_EQ(250, tiling_->TilingDataForTesting().max_texture_size().width()); |
2088 EXPECT_EQ(200, tiling_->TilingDataForTesting().max_texture_size().height()); | 2088 EXPECT_EQ(200, tiling_->TilingDataForTesting().max_texture_size().height()); |
2089 EXPECT_EQ(0u, tiling_->AllRefTilesForTesting().size()); | 2089 EXPECT_EQ(0u, tiling_->AllRefTilesForTesting().size()); |
2090 } | 2090 } |
2091 | 2091 |
2092 } // namespace | 2092 } // namespace |
2093 } // namespace cc | 2093 } // namespace cc |
OLD | NEW |