| 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/layers/picture_layer_impl.h" | 5 #include "cc/layers/picture_layer_impl.h" |
| 6 | 6 |
| 7 #include "cc/layers/picture_layer.h" | 7 #include "cc/layers/picture_layer.h" |
| 8 #include "cc/test/fake_content_layer_client.h" | 8 #include "cc/test/fake_content_layer_client.h" |
| 9 #include "cc/test/fake_impl_proxy.h" | 9 #include "cc/test/fake_impl_proxy.h" |
| 10 #include "cc/test/fake_layer_tree_host_impl.h" | 10 #include "cc/test/fake_layer_tree_host_impl.h" |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 virtual ~TestablePicturePileImpl() {} | 131 virtual ~TestablePicturePileImpl() {} |
| 132 | 132 |
| 133 FakeContentLayerClient client_; | 133 FakeContentLayerClient client_; |
| 134 }; | 134 }; |
| 135 | 135 |
| 136 class MockCanvas : public SkCanvas { | 136 class MockCanvas : public SkCanvas { |
| 137 public: | 137 public: |
| 138 explicit MockCanvas(SkDevice* device) : SkCanvas(device) {} | 138 explicit MockCanvas(SkDevice* device) : SkCanvas(device) {} |
| 139 | 139 |
| 140 virtual void drawRect(const SkRect& rect, const SkPaint& paint) OVERRIDE { | 140 virtual void drawRect(const SkRect& rect, const SkPaint& paint) OVERRIDE { |
| 141 // Capture calls before SkCanvas quickReject kicks in | 141 // Capture calls before SkCanvas quickReject() kicks in. |
| 142 rects_.push_back(rect); | 142 rects_.push_back(rect); |
| 143 } | 143 } |
| 144 | 144 |
| 145 std::vector<SkRect> rects_; | 145 std::vector<SkRect> rects_; |
| 146 }; | 146 }; |
| 147 | 147 |
| 148 class PictureLayerImplTest : public testing::Test { | 148 class PictureLayerImplTest : public testing::Test { |
| 149 public: | 149 public: |
| 150 PictureLayerImplTest() | 150 PictureLayerImplTest() |
| 151 : host_impl_(ImplSidePaintingSettings(), &proxy_), | 151 : host_impl_(ImplSidePaintingSettings(), &proxy_), |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 active_pile->add_draw_rect(rect); | 247 active_pile->add_draw_rect(rect); |
| 248 rects.push_back(SkRect::MakeXYWH(rect.x(), rect.y(), 1, 1)); | 248 rects.push_back(SkRect::MakeXYWH(rect.x(), rect.y(), 1, 1)); |
| 249 } | 249 } |
| 250 // Force re-record with newly injected content | 250 // Force re-record with newly injected content |
| 251 active_pile->RemoveRecordingAt(0, 0); | 251 active_pile->RemoveRecordingAt(0, 0); |
| 252 active_pile->AddRecordingAt(0, 0); | 252 active_pile->AddRecordingAt(0, 0); |
| 253 | 253 |
| 254 SkBitmap store; | 254 SkBitmap store; |
| 255 store.setConfig(SkBitmap::kNo_Config, 1000, 1000); | 255 store.setConfig(SkBitmap::kNo_Config, 1000, 1000); |
| 256 SkDevice device(store); | 256 SkDevice device(store); |
| 257 int64 pixelsRasterized; | 257 int64 pixels_rasterized; |
| 258 | 258 |
| 259 std::vector<SkRect>::const_iterator rect_iter = rects.begin(); | 259 std::vector<SkRect>::const_iterator rect_iter = rects.begin(); |
| 260 for (tile_iter = tiles.begin(); tile_iter < tiles.end(); tile_iter++) { | 260 for (tile_iter = tiles.begin(); tile_iter < tiles.end(); tile_iter++) { |
| 261 MockCanvas mock_canvas(&device); | 261 MockCanvas mock_canvas(&device); |
| 262 active_pile->Raster(&mock_canvas, (*tile_iter)->content_rect(), | 262 active_pile->Raster(&mock_canvas, (*tile_iter)->content_rect(), |
| 263 1.0f, &pixelsRasterized); | 263 1.0f, &pixels_rasterized); |
| 264 | 264 |
| 265 // This test verifies that when drawing the contents of a specific tile | 265 // This test verifies that when drawing the contents of a specific tile |
| 266 // at content scale 1.0, the playback canvas never receives content from | 266 // at content scale 1.0, the playback canvas never receives content from |
| 267 // neighboring tiles which indicates that the tile grid embedded in | 267 // neighboring tiles which indicates that the tile grid embedded in |
| 268 // SkPicture is perfectly aligned with the compositor's tiles. | 268 // SkPicture is perfectly aligned with the compositor's tiles. |
| 269 // Note: There are two rects: the initial clear and the explicitly | 269 // Note: There are two rects: the initial clear and the explicitly |
| 270 // recorded rect. We only care about the second one. | 270 // recorded rect. We only care about the second one. |
| 271 EXPECT_EQ(2, mock_canvas.rects_.size()); | 271 EXPECT_EQ(2, mock_canvas.rects_.size()); |
| 272 EXPECT_EQ(*rect_iter, mock_canvas.rects_[1]); | 272 EXPECT_EQ(*rect_iter, mock_canvas.rects_[1]); |
| 273 rect_iter++; | 273 rect_iter++; |
| 274 } | 274 } |
| 275 } | 275 } |
| 276 | 276 |
| 277 FakeImplProxy proxy_; | 277 FakeImplProxy proxy_; |
| 278 FakeLayerTreeHostImpl host_impl_; | 278 FakeLayerTreeHostImpl host_impl_; |
| 279 int id_; | 279 int id_; |
| 280 TestablePictureLayerImpl* pending_layer_; | 280 TestablePictureLayerImpl* pending_layer_; |
| 281 TestablePictureLayerImpl* active_layer_; | 281 TestablePictureLayerImpl* active_layer_; |
| 282 | 282 |
| 283 DISALLOW_COPY_AND_ASSIGN(PictureLayerImplTest); | 283 DISALLOW_COPY_AND_ASSIGN(PictureLayerImplTest); |
| 284 }; | 284 }; |
| 285 | 285 |
| 286 TEST_F(PictureLayerImplTest, tileGridAlignment) { | 286 TEST_F(PictureLayerImplTest, TileGridAlignment) { |
| 287 host_impl_.SetDeviceScaleFactor(1.f); | 287 host_impl_.SetDeviceScaleFactor(1.f); |
| 288 TestTileGridAlignmentCommon(); | 288 TestTileGridAlignmentCommon(); |
| 289 } | 289 } |
| 290 | 290 |
| 291 TEST_F(PictureLayerImplTest, tileGridAlignmentHiDPI) { | 291 TEST_F(PictureLayerImplTest, TileGridAlignmentHiDPI) { |
| 292 host_impl_.SetDeviceScaleFactor(2.f); | 292 host_impl_.SetDeviceScaleFactor(2.f); |
| 293 TestTileGridAlignmentCommon(); | 293 TestTileGridAlignmentCommon(); |
| 294 } | 294 } |
| 295 | 295 |
| 296 TEST_F(PictureLayerImplTest, cloneNoInvalidation) { | 296 TEST_F(PictureLayerImplTest, CloneNoInvalidation) { |
| 297 gfx::Size tile_size(100, 100); | 297 gfx::Size tile_size(100, 100); |
| 298 gfx::Size layer_bounds(400, 400); | 298 gfx::Size layer_bounds(400, 400); |
| 299 | 299 |
| 300 scoped_refptr<TestablePicturePileImpl> pending_pile = | 300 scoped_refptr<TestablePicturePileImpl> pending_pile = |
| 301 TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 301 TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 302 scoped_refptr<TestablePicturePileImpl> active_pile = | 302 scoped_refptr<TestablePicturePileImpl> active_pile = |
| 303 TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 303 TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 304 | 304 |
| 305 SetupTrees(pending_pile, active_pile); | 305 SetupTrees(pending_pile, active_pile); |
| 306 | 306 |
| 307 Region invalidation; | 307 Region invalidation; |
| 308 AddDefaultTilingsWithInvalidation(invalidation); | 308 AddDefaultTilingsWithInvalidation(invalidation); |
| 309 | 309 |
| 310 EXPECT_EQ(pending_layer_->tilings().num_tilings(), | 310 EXPECT_EQ(pending_layer_->tilings().num_tilings(), |
| 311 active_layer_->tilings().num_tilings()); | 311 active_layer_->tilings().num_tilings()); |
| 312 | 312 |
| 313 const PictureLayerTilingSet& tilings = pending_layer_->tilings(); | 313 const PictureLayerTilingSet& tilings = pending_layer_->tilings(); |
| 314 EXPECT_GT(tilings.num_tilings(), 0u); | 314 EXPECT_GT(tilings.num_tilings(), 0u); |
| 315 for (size_t i = 0; i < tilings.num_tilings(); ++i) | 315 for (size_t i = 0; i < tilings.num_tilings(); ++i) |
| 316 VerifyAllTilesExistAndHavePile(tilings.tiling_at(i), active_pile.get()); | 316 VerifyAllTilesExistAndHavePile(tilings.tiling_at(i), active_pile.get()); |
| 317 } | 317 } |
| 318 | 318 |
| 319 TEST_F(PictureLayerImplTest, clonePartialInvalidation) { | 319 TEST_F(PictureLayerImplTest, ClonePartialInvalidation) { |
| 320 gfx::Size tile_size(100, 100); | 320 gfx::Size tile_size(100, 100); |
| 321 gfx::Size layer_bounds(400, 400); | 321 gfx::Size layer_bounds(400, 400); |
| 322 gfx::Rect layer_invalidation(150, 200, 30, 180); | 322 gfx::Rect layer_invalidation(150, 200, 30, 180); |
| 323 | 323 |
| 324 scoped_refptr<TestablePicturePileImpl> pending_pile = | 324 scoped_refptr<TestablePicturePileImpl> pending_pile = |
| 325 TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 325 TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 326 scoped_refptr<TestablePicturePileImpl> active_pile = | 326 scoped_refptr<TestablePicturePileImpl> active_pile = |
| 327 TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 327 TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 328 | 328 |
| 329 SetupTrees(pending_pile, active_pile); | 329 SetupTrees(pending_pile, active_pile); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 347 EXPECT_TRUE(*iter); | 347 EXPECT_TRUE(*iter); |
| 348 EXPECT_FALSE(iter.geometry_rect().IsEmpty()); | 348 EXPECT_FALSE(iter.geometry_rect().IsEmpty()); |
| 349 if (iter.geometry_rect().Intersects(content_invalidation)) | 349 if (iter.geometry_rect().Intersects(content_invalidation)) |
| 350 EXPECT_EQ(pending_pile, iter->picture_pile()); | 350 EXPECT_EQ(pending_pile, iter->picture_pile()); |
| 351 else | 351 else |
| 352 EXPECT_EQ(active_pile, iter->picture_pile()); | 352 EXPECT_EQ(active_pile, iter->picture_pile()); |
| 353 } | 353 } |
| 354 } | 354 } |
| 355 } | 355 } |
| 356 | 356 |
| 357 TEST_F(PictureLayerImplTest, cloneFullInvalidation) { | 357 TEST_F(PictureLayerImplTest, CloneFullInvalidation) { |
| 358 gfx::Size tile_size(90, 80); | 358 gfx::Size tile_size(90, 80); |
| 359 gfx::Size layer_bounds(300, 500); | 359 gfx::Size layer_bounds(300, 500); |
| 360 | 360 |
| 361 scoped_refptr<TestablePicturePileImpl> pending_pile = | 361 scoped_refptr<TestablePicturePileImpl> pending_pile = |
| 362 TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 362 TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 363 scoped_refptr<TestablePicturePileImpl> active_pile = | 363 scoped_refptr<TestablePicturePileImpl> active_pile = |
| 364 TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 364 TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 365 | 365 |
| 366 SetupTrees(pending_pile, active_pile); | 366 SetupTrees(pending_pile, active_pile); |
| 367 | 367 |
| 368 Region invalidation((gfx::Rect(layer_bounds))); | 368 Region invalidation((gfx::Rect(layer_bounds))); |
| 369 AddDefaultTilingsWithInvalidation(invalidation); | 369 AddDefaultTilingsWithInvalidation(invalidation); |
| 370 | 370 |
| 371 EXPECT_EQ(pending_layer_->tilings().num_tilings(), | 371 EXPECT_EQ(pending_layer_->tilings().num_tilings(), |
| 372 active_layer_->tilings().num_tilings()); | 372 active_layer_->tilings().num_tilings()); |
| 373 | 373 |
| 374 const PictureLayerTilingSet& tilings = pending_layer_->tilings(); | 374 const PictureLayerTilingSet& tilings = pending_layer_->tilings(); |
| 375 EXPECT_GT(tilings.num_tilings(), 0u); | 375 EXPECT_GT(tilings.num_tilings(), 0u); |
| 376 for (size_t i = 0; i < tilings.num_tilings(); ++i) | 376 for (size_t i = 0; i < tilings.num_tilings(); ++i) |
| 377 VerifyAllTilesExistAndHavePile(tilings.tiling_at(i), pending_pile.get()); | 377 VerifyAllTilesExistAndHavePile(tilings.tiling_at(i), pending_pile.get()); |
| 378 } | 378 } |
| 379 | 379 |
| 380 TEST_F(PictureLayerImplTest, noInvalidationBoundsChange) { | 380 TEST_F(PictureLayerImplTest, NoInvalidationBoundsChange) { |
| 381 gfx::Size tile_size(90, 80); | 381 gfx::Size tile_size(90, 80); |
| 382 gfx::Size active_layer_bounds(300, 500); | 382 gfx::Size active_layer_bounds(300, 500); |
| 383 gfx::Size pending_layer_bounds(400, 800); | 383 gfx::Size pending_layer_bounds(400, 800); |
| 384 | 384 |
| 385 scoped_refptr<TestablePicturePileImpl> pending_pile = | 385 scoped_refptr<TestablePicturePileImpl> pending_pile = |
| 386 TestablePicturePileImpl::CreateFilledPile(tile_size, | 386 TestablePicturePileImpl::CreateFilledPile(tile_size, |
| 387 pending_layer_bounds); | 387 pending_layer_bounds); |
| 388 scoped_refptr<TestablePicturePileImpl> active_pile = | 388 scoped_refptr<TestablePicturePileImpl> active_pile = |
| 389 TestablePicturePileImpl::CreateFilledPile(tile_size, active_layer_bounds); | 389 TestablePicturePileImpl::CreateFilledPile(tile_size, active_layer_bounds); |
| 390 | 390 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 411 if (iter.geometry_rect().right() >= active_content_bounds.width() || | 411 if (iter.geometry_rect().right() >= active_content_bounds.width() || |
| 412 iter.geometry_rect().bottom() >= active_content_bounds.height()) { | 412 iter.geometry_rect().bottom() >= active_content_bounds.height()) { |
| 413 EXPECT_EQ(pending_pile, iter->picture_pile()); | 413 EXPECT_EQ(pending_pile, iter->picture_pile()); |
| 414 } else { | 414 } else { |
| 415 EXPECT_EQ(active_pile, iter->picture_pile()); | 415 EXPECT_EQ(active_pile, iter->picture_pile()); |
| 416 } | 416 } |
| 417 } | 417 } |
| 418 } | 418 } |
| 419 } | 419 } |
| 420 | 420 |
| 421 TEST_F(PictureLayerImplTest, addTilesFromNewRecording) { | 421 TEST_F(PictureLayerImplTest, AddTilesFromNewRecording) { |
| 422 gfx::Size tile_size(400, 400); | 422 gfx::Size tile_size(400, 400); |
| 423 gfx::Size layer_bounds(1300, 1900); | 423 gfx::Size layer_bounds(1300, 1900); |
| 424 | 424 |
| 425 scoped_refptr<TestablePicturePileImpl> pending_pile = | 425 scoped_refptr<TestablePicturePileImpl> pending_pile = |
| 426 TestablePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); | 426 TestablePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); |
| 427 scoped_refptr<TestablePicturePileImpl> active_pile = | 427 scoped_refptr<TestablePicturePileImpl> active_pile = |
| 428 TestablePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); | 428 TestablePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); |
| 429 | 429 |
| 430 // Fill in some of active pile, but more of pending pile. | 430 // Fill in some of active pile, but more of pending pile. |
| 431 int hole_count = 0; | 431 int hole_count = 0; |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 used_tilings.push_back(active_layer_->tilings().tiling_at(1)); | 694 used_tilings.push_back(active_layer_->tilings().tiling_at(1)); |
| 695 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); | 695 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); |
| 696 ASSERT_EQ(3u, active_layer_->tilings().num_tilings()); | 696 ASSERT_EQ(3u, active_layer_->tilings().num_tilings()); |
| 697 used_tilings.clear(); | 697 used_tilings.clear(); |
| 698 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); | 698 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); |
| 699 ASSERT_EQ(2u, active_layer_->tilings().num_tilings()); | 699 ASSERT_EQ(2u, active_layer_->tilings().num_tilings()); |
| 700 } | 700 } |
| 701 | 701 |
| 702 } // namespace | 702 } // namespace |
| 703 } // namespace cc | 703 } // namespace cc |
| OLD | NEW |