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 <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <set> | 9 #include <set> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "cc/layers/append_quads_data.h" | 12 #include "cc/layers/append_quads_data.h" |
13 #include "cc/layers/picture_layer.h" | 13 #include "cc/layers/picture_layer.h" |
14 #include "cc/test/fake_content_layer_client.h" | 14 #include "cc/test/fake_content_layer_client.h" |
15 #include "cc/test/fake_impl_proxy.h" | 15 #include "cc/test/fake_impl_proxy.h" |
16 #include "cc/test/fake_layer_tree_host_impl.h" | 16 #include "cc/test/fake_layer_tree_host_impl.h" |
17 #include "cc/test/fake_output_surface.h" | 17 #include "cc/test/fake_output_surface.h" |
18 #include "cc/test/fake_picture_layer_impl.h" | 18 #include "cc/test/fake_picture_layer_impl.h" |
19 #include "cc/test/fake_picture_pile_impl.h" | 19 #include "cc/test/fake_picture_pile_impl.h" |
20 #include "cc/test/geometry_test_utils.h" | 20 #include "cc/test/geometry_test_utils.h" |
21 #include "cc/test/impl_side_painting_settings.h" | 21 #include "cc/test/impl_side_painting_settings.h" |
22 #include "cc/test/layer_test_common.h" | 22 #include "cc/test/layer_test_common.h" |
23 #include "cc/test/mock_quad_culler.h" | 23 #include "cc/test/mock_quad_culler.h" |
24 #include "cc/test/test_shared_bitmap_manager.h" | 24 #include "cc/test/test_shared_bitmap_manager.h" |
25 #include "cc/test/test_web_graphics_context_3d.h" | 25 #include "cc/test/test_web_graphics_context_3d.h" |
26 #include "cc/trees/layer_tree_impl.h" | 26 #include "cc/trees/layer_tree_impl.h" |
27 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
28 #include "ui/gfx/rect_conversions.h" | 28 #include "ui/gfx/rect_conversions.h" |
| 29 #include "ui/gfx/size_conversions.h" |
29 | 30 |
30 namespace cc { | 31 namespace cc { |
31 namespace { | 32 namespace { |
32 | 33 |
33 class MockCanvas : public SkCanvas { | 34 class MockCanvas : public SkCanvas { |
34 public: | 35 public: |
35 explicit MockCanvas(int w, int h) : SkCanvas(w, h) {} | 36 explicit MockCanvas(int w, int h) : SkCanvas(w, h) {} |
36 | 37 |
37 virtual void drawRect(const SkRect& rect, const SkPaint& paint) OVERRIDE { | 38 virtual void drawRect(const SkRect& rect, const SkPaint& paint) OVERRIDE { |
38 // Capture calls before SkCanvas quickReject() kicks in. | 39 // Capture calls before SkCanvas quickReject() kicks in. |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 FakePictureLayerImpl::CreateWithPile(pending_tree, id_, pile); | 134 FakePictureLayerImpl::CreateWithPile(pending_tree, id_, pile); |
134 pending_layer->SetDrawsContent(true); | 135 pending_layer->SetDrawsContent(true); |
135 pending_layer->SetAnchorPoint(gfx::PointF()); | 136 pending_layer->SetAnchorPoint(gfx::PointF()); |
136 pending_tree->SetRootLayer(pending_layer.PassAs<LayerImpl>()); | 137 pending_tree->SetRootLayer(pending_layer.PassAs<LayerImpl>()); |
137 | 138 |
138 pending_layer_ = static_cast<FakePictureLayerImpl*>( | 139 pending_layer_ = static_cast<FakePictureLayerImpl*>( |
139 host_impl_.pending_tree()->LayerById(id_)); | 140 host_impl_.pending_tree()->LayerById(id_)); |
140 pending_layer_->DoPostCommitInitializationIfNeeded(); | 141 pending_layer_->DoPostCommitInitializationIfNeeded(); |
141 } | 142 } |
142 | 143 |
| 144 void SetupDrawPropertiesAndManageTilings( |
| 145 FakePictureLayerImpl* layer, |
| 146 float ideal_contents_scale, |
| 147 float device_scale_factor, |
| 148 float page_scale_factor, |
| 149 float maximum_animation_contents_scale, |
| 150 bool animating_transform_to_screen) { |
| 151 layer->draw_properties().ideal_contents_scale = ideal_contents_scale; |
| 152 layer->draw_properties().device_scale_factor = device_scale_factor; |
| 153 layer->draw_properties().page_scale_factor = page_scale_factor; |
| 154 layer->draw_properties().maximum_animation_contents_scale = |
| 155 maximum_animation_contents_scale; |
| 156 layer->draw_properties().screen_space_transform_is_animating = |
| 157 animating_transform_to_screen; |
| 158 layer->ScaleAndManageTilings(animating_transform_to_screen, |
| 159 maximum_animation_contents_scale); |
| 160 } |
143 static void VerifyAllTilesExistAndHavePile( | 161 static void VerifyAllTilesExistAndHavePile( |
144 const PictureLayerTiling* tiling, | 162 const PictureLayerTiling* tiling, |
145 PicturePileImpl* pile) { | 163 PicturePileImpl* pile) { |
146 for (PictureLayerTiling::CoverageIterator iter( | 164 for (PictureLayerTiling::CoverageIterator iter( |
147 tiling, tiling->contents_scale(), tiling->TilingRect()); | 165 tiling, tiling->contents_scale(), tiling->TilingRect()); |
148 iter; | 166 iter; |
149 ++iter) { | 167 ++iter) { |
150 EXPECT_TRUE(*iter); | 168 EXPECT_TRUE(*iter); |
151 EXPECT_EQ(pile, iter->picture_pile()); | 169 EXPECT_EQ(pile, iter->picture_pile()); |
152 } | 170 } |
153 } | 171 } |
154 | 172 |
155 void SetContentsScaleOnBothLayers(float contents_scale, | 173 void SetContentsScaleOnBothLayers(float contents_scale, |
156 float device_scale_factor, | 174 float device_scale_factor, |
157 float page_scale_factor, | 175 float page_scale_factor, |
158 float maximum_animation_contents_scale, | 176 float maximum_animation_contents_scale, |
159 bool animating_transform) { | 177 bool animating_transform) { |
160 float result_scale_x, result_scale_y; | 178 SetupDrawPropertiesAndManageTilings(pending_layer_, |
161 gfx::Size result_bounds; | 179 contents_scale, |
162 pending_layer_->CalculateContentsScale(contents_scale, | 180 device_scale_factor, |
163 device_scale_factor, | 181 page_scale_factor, |
164 page_scale_factor, | 182 maximum_animation_contents_scale, |
165 maximum_animation_contents_scale, | 183 animating_transform); |
166 animating_transform, | 184 |
167 &result_scale_x, | 185 SetupDrawPropertiesAndManageTilings(active_layer_, |
168 &result_scale_y, | 186 contents_scale, |
169 &result_bounds); | 187 device_scale_factor, |
170 active_layer_->CalculateContentsScale(contents_scale, | 188 page_scale_factor, |
171 device_scale_factor, | 189 maximum_animation_contents_scale, |
172 page_scale_factor, | 190 animating_transform); |
173 maximum_animation_contents_scale, | |
174 animating_transform, | |
175 &result_scale_x, | |
176 &result_scale_y, | |
177 &result_bounds); | |
178 } | 191 } |
179 | 192 |
180 void ResetTilingsAndRasterScales() { | 193 void ResetTilingsAndRasterScales() { |
181 pending_layer_->ReleaseResources(); | 194 pending_layer_->ReleaseResources(); |
182 active_layer_->ReleaseResources(); | 195 active_layer_->ReleaseResources(); |
183 } | 196 } |
184 | 197 |
185 void AssertAllTilesRequired(PictureLayerTiling* tiling) { | 198 void AssertAllTilesRequired(PictureLayerTiling* tiling) { |
186 std::vector<Tile*> tiles = tiling->AllTilesForTesting(); | 199 std::vector<Tile*> tiles = tiling->AllTilesForTesting(); |
187 for (size_t i = 0; i < tiles.size(); ++i) | 200 for (size_t i = 0; i < tiles.size(); ++i) |
(...skipping 16 matching lines...) Expand all Loading... |
204 settings.default_tile_size.width() * 7 / 2, | 217 settings.default_tile_size.width() * 7 / 2, |
205 settings.default_tile_size.height() * 7 / 2); | 218 settings.default_tile_size.height() * 7 / 2); |
206 | 219 |
207 scoped_refptr<FakePicturePileImpl> pending_pile = | 220 scoped_refptr<FakePicturePileImpl> pending_pile = |
208 FakePicturePileImpl::CreateFilledPile(layer_size, layer_size); | 221 FakePicturePileImpl::CreateFilledPile(layer_size, layer_size); |
209 scoped_refptr<FakePicturePileImpl> active_pile = | 222 scoped_refptr<FakePicturePileImpl> active_pile = |
210 FakePicturePileImpl::CreateFilledPile(layer_size, layer_size); | 223 FakePicturePileImpl::CreateFilledPile(layer_size, layer_size); |
211 | 224 |
212 SetupTrees(pending_pile, active_pile); | 225 SetupTrees(pending_pile, active_pile); |
213 | 226 |
214 float result_scale_x, result_scale_y; | 227 SetupDrawPropertiesAndManageTilings( |
215 gfx::Size result_bounds; | 228 active_layer_, 1.f, 1.f, 1.f, 1.f, false); |
216 active_layer_->CalculateContentsScale(1.f, | |
217 1.f, | |
218 1.f, | |
219 1.f, | |
220 false, | |
221 &result_scale_x, | |
222 &result_scale_y, | |
223 &result_bounds); | |
224 | 229 |
225 // Add 1x1 rects at the centers of each tile, then re-record pile contents | 230 // Add 1x1 rects at the centers of each tile, then re-record pile contents |
226 active_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting(); | 231 active_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting(); |
227 std::vector<Tile*> tiles = | 232 std::vector<Tile*> tiles = |
228 active_layer_->tilings()->tiling_at(0)->AllTilesForTesting(); | 233 active_layer_->tilings()->tiling_at(0)->AllTilesForTesting(); |
229 EXPECT_EQ(16u, tiles.size()); | 234 EXPECT_EQ(16u, tiles.size()); |
230 std::vector<SkRect> rects; | 235 std::vector<SkRect> rects; |
231 std::vector<Tile*>::const_iterator tile_iter; | 236 std::vector<Tile*>::const_iterator tile_iter; |
232 for (tile_iter = tiles.begin(); tile_iter < tiles.end(); tile_iter++) { | 237 for (tile_iter = tiles.begin(); tile_iter < tiles.end(); tile_iter++) { |
233 gfx::Point tile_center = (*tile_iter)->content_rect().CenterPoint(); | 238 gfx::Point tile_center = (*tile_iter)->content_rect().CenterPoint(); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 scoped_refptr<FakePicturePileImpl> active_pile = | 313 scoped_refptr<FakePicturePileImpl> active_pile = |
309 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 314 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
310 | 315 |
311 SetupTrees(pending_pile, active_pile); | 316 SetupTrees(pending_pile, active_pile); |
312 | 317 |
313 std::vector<TileManager::PairedPictureLayer> paired_layers; | 318 std::vector<TileManager::PairedPictureLayer> paired_layers; |
314 host_impl_.tile_manager()->GetPairedPictureLayers(&paired_layers); | 319 host_impl_.tile_manager()->GetPairedPictureLayers(&paired_layers); |
315 EXPECT_EQ(0u, paired_layers.size()); | 320 EXPECT_EQ(0u, paired_layers.size()); |
316 | 321 |
317 // Update tile priorities will force the layer to register itself. | 322 // Update tile priorities will force the layer to register itself. |
318 float dummy_contents_scale_x; | 323 SetupDrawPropertiesAndManageTilings(active_layer_, 1.f, 1.f, 1.f, 1.f, false); |
319 float dummy_contents_scale_y; | |
320 gfx::Size dummy_content_bounds; | |
321 active_layer_->CalculateContentsScale(1.f, | |
322 1.f, | |
323 1.f, | |
324 1.f, | |
325 false, | |
326 &dummy_contents_scale_x, | |
327 &dummy_contents_scale_y, | |
328 &dummy_content_bounds); | |
329 active_layer_->UpdateTilePriorities(); | 324 active_layer_->UpdateTilePriorities(); |
330 host_impl_.pending_tree()->UpdateDrawProperties(); | 325 host_impl_.pending_tree()->UpdateDrawProperties(); |
331 pending_layer_->CalculateContentsScale(1.f, | 326 |
332 1.f, | 327 SetupDrawPropertiesAndManageTilings( |
333 1.f, | 328 pending_layer_, 1.f, 1.f, 1.f, 1.f, false); |
334 1.f, | |
335 false, | |
336 &dummy_contents_scale_x, | |
337 &dummy_contents_scale_y, | |
338 &dummy_content_bounds); | |
339 pending_layer_->UpdateTilePriorities(); | 329 pending_layer_->UpdateTilePriorities(); |
340 | 330 |
341 host_impl_.tile_manager()->GetPairedPictureLayers(&paired_layers); | 331 host_impl_.tile_manager()->GetPairedPictureLayers(&paired_layers); |
342 EXPECT_EQ(1u, paired_layers.size()); | 332 EXPECT_EQ(1u, paired_layers.size()); |
343 EXPECT_EQ(active_layer_, paired_layers[0].active_layer); | 333 EXPECT_EQ(active_layer_, paired_layers[0].active_layer); |
344 EXPECT_EQ(pending_layer_, paired_layers[0].pending_layer); | 334 EXPECT_EQ(pending_layer_, paired_layers[0].pending_layer); |
345 | 335 |
346 // Destroy and recreate tile manager. | 336 // Destroy and recreate tile manager. |
347 host_impl_.DidLoseOutputSurface(); | 337 host_impl_.DidLoseOutputSurface(); |
348 scoped_ptr<TestWebGraphicsContext3D> context = | 338 scoped_ptr<TestWebGraphicsContext3D> context = |
349 TestWebGraphicsContext3D::Create(); | 339 TestWebGraphicsContext3D::Create(); |
350 host_impl_.InitializeRenderer( | 340 host_impl_.InitializeRenderer( |
351 FakeOutputSurface::Create3d(context.Pass()).PassAs<OutputSurface>()); | 341 FakeOutputSurface::Create3d(context.Pass()).PassAs<OutputSurface>()); |
352 | 342 |
353 host_impl_.tile_manager()->GetPairedPictureLayers(&paired_layers); | 343 host_impl_.tile_manager()->GetPairedPictureLayers(&paired_layers); |
354 EXPECT_EQ(0u, paired_layers.size()); | 344 EXPECT_EQ(0u, paired_layers.size()); |
355 | 345 |
356 active_layer_->CalculateContentsScale(1.f, | 346 SetupDrawPropertiesAndManageTilings(active_layer_, 1.f, 1.f, 1.f, 1.f, false); |
357 1.f, | |
358 1.f, | |
359 1.f, | |
360 false, | |
361 &dummy_contents_scale_x, | |
362 &dummy_contents_scale_y, | |
363 &dummy_content_bounds); | |
364 active_layer_->UpdateTilePriorities(); | 347 active_layer_->UpdateTilePriorities(); |
365 host_impl_.pending_tree()->UpdateDrawProperties(); | 348 host_impl_.pending_tree()->UpdateDrawProperties(); |
366 pending_layer_->CalculateContentsScale(1.f, | 349 |
367 1.f, | 350 SetupDrawPropertiesAndManageTilings( |
368 1.f, | 351 pending_layer_, 1.f, 1.f, 1.f, 1.f, false); |
369 1.f, | |
370 false, | |
371 &dummy_contents_scale_x, | |
372 &dummy_contents_scale_y, | |
373 &dummy_content_bounds); | |
374 pending_layer_->UpdateTilePriorities(); | 352 pending_layer_->UpdateTilePriorities(); |
375 | 353 |
376 host_impl_.tile_manager()->GetPairedPictureLayers(&paired_layers); | 354 host_impl_.tile_manager()->GetPairedPictureLayers(&paired_layers); |
377 EXPECT_EQ(1u, paired_layers.size()); | 355 EXPECT_EQ(1u, paired_layers.size()); |
378 EXPECT_EQ(active_layer_, paired_layers[0].active_layer); | 356 EXPECT_EQ(active_layer_, paired_layers[0].active_layer); |
379 EXPECT_EQ(pending_layer_, paired_layers[0].pending_layer); | 357 EXPECT_EQ(pending_layer_, paired_layers[0].pending_layer); |
380 } | 358 } |
381 | 359 |
382 TEST_F(PictureLayerImplTest, InvalidViewportForPrioritizingTiles) { | 360 TEST_F(PictureLayerImplTest, InvalidViewportForPrioritizingTiles) { |
383 base::TimeTicks time_ticks; | 361 base::TimeTicks time_ticks; |
384 host_impl_.SetCurrentFrameTimeTicks(time_ticks); | 362 host_impl_.SetCurrentFrameTimeTicks(time_ticks); |
385 | 363 |
386 gfx::Size tile_size(100, 100); | 364 gfx::Size tile_size(100, 100); |
387 gfx::Size layer_bounds(400, 400); | 365 gfx::Size layer_bounds(400, 400); |
388 | 366 |
389 scoped_refptr<FakePicturePileImpl> pending_pile = | 367 scoped_refptr<FakePicturePileImpl> pending_pile = |
390 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 368 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
391 scoped_refptr<FakePicturePileImpl> active_pile = | 369 scoped_refptr<FakePicturePileImpl> active_pile = |
392 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 370 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
393 | 371 |
394 SetupTrees(pending_pile, active_pile); | 372 SetupTrees(pending_pile, active_pile); |
395 | 373 |
396 Region invalidation; | 374 Region invalidation; |
397 AddDefaultTilingsWithInvalidation(invalidation); | 375 AddDefaultTilingsWithInvalidation(invalidation); |
398 float dummy_contents_scale_x; | 376 SetupDrawPropertiesAndManageTilings(active_layer_, 1.f, 1.f, 1.f, 1.f, false); |
399 float dummy_contents_scale_y; | |
400 gfx::Size dummy_content_bounds; | |
401 active_layer_->CalculateContentsScale(1.f, | |
402 1.f, | |
403 1.f, | |
404 1.f, | |
405 false, | |
406 &dummy_contents_scale_x, | |
407 &dummy_contents_scale_y, | |
408 &dummy_content_bounds); | |
409 | 377 |
410 // UpdateTilePriorities with valid viewport. Should update tile viewport. | 378 // UpdateTilePriorities with valid viewport. Should update tile viewport. |
411 bool valid_for_tile_management = true; | 379 bool valid_for_tile_management = true; |
412 gfx::Rect viewport = gfx::Rect(layer_bounds); | 380 gfx::Rect viewport = gfx::Rect(layer_bounds); |
413 gfx::Transform transform; | 381 gfx::Transform transform; |
414 host_impl_.SetExternalDrawConstraints( | 382 host_impl_.SetExternalDrawConstraints( |
415 transform, viewport, viewport, valid_for_tile_management); | 383 transform, viewport, viewport, valid_for_tile_management); |
416 active_layer_->draw_properties().visible_content_rect = viewport; | 384 active_layer_->draw_properties().visible_content_rect = viewport; |
417 active_layer_->draw_properties().screen_space_transform = transform; | 385 active_layer_->draw_properties().screen_space_transform = transform; |
418 active_layer_->UpdateTilePriorities(); | 386 active_layer_->UpdateTilePriorities(); |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 | 623 |
656 TEST_F(PictureLayerImplTest, ManageTilingsWithNoRecording) { | 624 TEST_F(PictureLayerImplTest, ManageTilingsWithNoRecording) { |
657 gfx::Size tile_size(400, 400); | 625 gfx::Size tile_size(400, 400); |
658 gfx::Size layer_bounds(1300, 1900); | 626 gfx::Size layer_bounds(1300, 1900); |
659 | 627 |
660 scoped_refptr<FakePicturePileImpl> pending_pile = | 628 scoped_refptr<FakePicturePileImpl> pending_pile = |
661 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); | 629 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); |
662 scoped_refptr<FakePicturePileImpl> active_pile = | 630 scoped_refptr<FakePicturePileImpl> active_pile = |
663 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); | 631 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); |
664 | 632 |
665 float result_scale_x, result_scale_y; | |
666 gfx::Size result_bounds; | |
667 | |
668 SetupTrees(pending_pile, active_pile); | 633 SetupTrees(pending_pile, active_pile); |
669 | 634 |
670 pending_layer_->CalculateContentsScale(1.f, | 635 SetupDrawPropertiesAndManageTilings( |
671 1.f, | 636 pending_layer_, 1.f, 1.f, 1.f, 1.f, false); |
672 1.f, | |
673 1.f, | |
674 false, | |
675 &result_scale_x, | |
676 &result_scale_y, | |
677 &result_bounds); | |
678 | 637 |
679 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); | 638 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); |
680 } | 639 } |
681 | 640 |
682 TEST_F(PictureLayerImplTest, ManageTilingsCreatesTilings) { | 641 TEST_F(PictureLayerImplTest, ManageTilingsCreatesTilings) { |
683 gfx::Size tile_size(400, 400); | 642 gfx::Size tile_size(400, 400); |
684 gfx::Size layer_bounds(1300, 1900); | 643 gfx::Size layer_bounds(1300, 1900); |
685 | 644 |
686 scoped_refptr<FakePicturePileImpl> pending_pile = | 645 scoped_refptr<FakePicturePileImpl> pending_pile = |
687 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 646 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
688 scoped_refptr<FakePicturePileImpl> active_pile = | 647 scoped_refptr<FakePicturePileImpl> active_pile = |
689 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 648 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
690 | 649 |
691 float result_scale_x, result_scale_y; | |
692 gfx::Size result_bounds; | |
693 | |
694 SetupTrees(pending_pile, active_pile); | 650 SetupTrees(pending_pile, active_pile); |
695 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); | 651 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); |
696 | 652 |
697 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; | 653 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; |
698 EXPECT_LT(low_res_factor, 1.f); | 654 EXPECT_LT(low_res_factor, 1.f); |
699 | 655 |
700 pending_layer_->CalculateContentsScale(6.f, // ideal contents scale | 656 SetupDrawPropertiesAndManageTilings(pending_layer_, |
701 3.f, // device scale | 657 6.f, // ideal contents scale |
702 2.f, // page scale | 658 3.f, // device scale |
703 1.f, // maximum animation scale | 659 2.f, // page scale |
704 false, | 660 1.f, // maximum animation scale |
705 &result_scale_x, | 661 false); |
706 &result_scale_y, | |
707 &result_bounds); | |
708 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); | 662 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); |
709 EXPECT_FLOAT_EQ(6.f, | 663 EXPECT_FLOAT_EQ(6.f, |
710 pending_layer_->tilings()->tiling_at(0)->contents_scale()); | 664 pending_layer_->tilings()->tiling_at(0)->contents_scale()); |
711 EXPECT_FLOAT_EQ(6.f * low_res_factor, | 665 EXPECT_FLOAT_EQ(6.f * low_res_factor, |
712 pending_layer_->tilings()->tiling_at(1)->contents_scale()); | 666 pending_layer_->tilings()->tiling_at(1)->contents_scale()); |
713 | 667 |
714 // If we change the page scale factor, then we should get new tilings. | 668 // If we change the page scale factor, then we should get new tilings. |
715 pending_layer_->CalculateContentsScale(6.6f, // ideal contents scale | 669 SetupDrawPropertiesAndManageTilings(pending_layer_, |
716 3.f, // device scale | 670 6.6f, // ideal contents scale |
717 2.2f, // page scale | 671 3.f, // device scale |
718 1.f, // maximum animation scale | 672 2.2f, // page scale |
719 false, | 673 1.f, // maximum animation scale |
720 &result_scale_x, | 674 false); |
721 &result_scale_y, | |
722 &result_bounds); | |
723 ASSERT_EQ(4u, pending_layer_->tilings()->num_tilings()); | 675 ASSERT_EQ(4u, pending_layer_->tilings()->num_tilings()); |
724 EXPECT_FLOAT_EQ(6.6f, | 676 EXPECT_FLOAT_EQ(6.6f, |
725 pending_layer_->tilings()->tiling_at(0)->contents_scale()); | 677 pending_layer_->tilings()->tiling_at(0)->contents_scale()); |
726 EXPECT_FLOAT_EQ(6.6f * low_res_factor, | 678 EXPECT_FLOAT_EQ(6.6f * low_res_factor, |
727 pending_layer_->tilings()->tiling_at(2)->contents_scale()); | 679 pending_layer_->tilings()->tiling_at(2)->contents_scale()); |
728 | 680 |
729 // If we change the device scale factor, then we should get new tilings. | 681 // If we change the device scale factor, then we should get new tilings. |
730 pending_layer_->CalculateContentsScale(7.26f, // ideal contents scale | 682 SetupDrawPropertiesAndManageTilings(pending_layer_, |
731 3.3f, // device scale | 683 7.26f, // ideal contents scale |
732 2.2f, // page scale | 684 3.3f, // device scale |
733 1.f, // maximum animation scale | 685 2.2f, // page scale |
734 false, | 686 1.f, // maximum animation scale |
735 &result_scale_x, | 687 false); |
736 &result_scale_y, | |
737 &result_bounds); | |
738 ASSERT_EQ(6u, pending_layer_->tilings()->num_tilings()); | 688 ASSERT_EQ(6u, pending_layer_->tilings()->num_tilings()); |
739 EXPECT_FLOAT_EQ(7.26f, | 689 EXPECT_FLOAT_EQ(7.26f, |
740 pending_layer_->tilings()->tiling_at(0)->contents_scale()); | 690 pending_layer_->tilings()->tiling_at(0)->contents_scale()); |
741 EXPECT_FLOAT_EQ(7.26f * low_res_factor, | 691 EXPECT_FLOAT_EQ(7.26f * low_res_factor, |
742 pending_layer_->tilings()->tiling_at(3)->contents_scale()); | 692 pending_layer_->tilings()->tiling_at(3)->contents_scale()); |
743 | 693 |
744 // If we change the device scale factor, but end up at the same total scale | 694 // If we change the device scale factor, but end up at the same total scale |
745 // factor somehow, then we don't get new tilings. | 695 // factor somehow, then we don't get new tilings. |
746 pending_layer_->CalculateContentsScale(7.26f, // ideal contents scale | 696 SetupDrawPropertiesAndManageTilings(pending_layer_, |
747 2.2f, // device scale | 697 7.26f, // ideal contents scale |
748 3.3f, // page scale | 698 2.2f, // device scale |
749 1.f, // maximum animation scale | 699 3.3f, // page scale |
750 false, | 700 1.f, // maximum animation scale |
751 &result_scale_x, | 701 false); |
752 &result_scale_y, | |
753 &result_bounds); | |
754 ASSERT_EQ(6u, pending_layer_->tilings()->num_tilings()); | 702 ASSERT_EQ(6u, pending_layer_->tilings()->num_tilings()); |
755 EXPECT_FLOAT_EQ(7.26f, | 703 EXPECT_FLOAT_EQ(7.26f, |
756 pending_layer_->tilings()->tiling_at(0)->contents_scale()); | 704 pending_layer_->tilings()->tiling_at(0)->contents_scale()); |
757 EXPECT_FLOAT_EQ(7.26f * low_res_factor, | 705 EXPECT_FLOAT_EQ(7.26f * low_res_factor, |
758 pending_layer_->tilings()->tiling_at(3)->contents_scale()); | 706 pending_layer_->tilings()->tiling_at(3)->contents_scale()); |
759 } | 707 } |
760 | 708 |
761 TEST_F(PictureLayerImplTest, CreateTilingsEvenIfTwinHasNone) { | 709 TEST_F(PictureLayerImplTest, CreateTilingsEvenIfTwinHasNone) { |
762 // This test makes sure that if a layer can have tilings, then a commit makes | 710 // This test makes sure that if a layer can have tilings, then a commit makes |
763 // it not able to have tilings (empty size), and then a future commit that | 711 // it not able to have tilings (empty size), and then a future commit that |
764 // makes it valid again should be able to create tilings. | 712 // makes it valid again should be able to create tilings. |
765 gfx::Size tile_size(400, 400); | 713 gfx::Size tile_size(400, 400); |
766 gfx::Size layer_bounds(1300, 1900); | 714 gfx::Size layer_bounds(1300, 1900); |
767 | 715 |
768 scoped_refptr<FakePicturePileImpl> empty_pile = | 716 scoped_refptr<FakePicturePileImpl> empty_pile = |
769 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); | 717 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); |
770 scoped_refptr<FakePicturePileImpl> valid_pile = | 718 scoped_refptr<FakePicturePileImpl> valid_pile = |
771 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 719 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
772 | 720 |
773 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; | 721 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; |
774 EXPECT_LT(low_res_factor, 1.f); | 722 EXPECT_LT(low_res_factor, 1.f); |
775 | 723 |
776 float high_res_scale = 1.3f; | 724 float high_res_scale = 1.3f; |
777 float low_res_scale = high_res_scale * low_res_factor; | 725 float low_res_scale = high_res_scale * low_res_factor; |
778 float device_scale = 1.7f; | 726 float device_scale = 1.7f; |
779 float page_scale = 3.2f; | 727 float page_scale = 3.2f; |
780 float maximum_animation_scale = 1.f; | 728 float maximum_animation_scale = 1.f; |
781 float result_scale_x, result_scale_y; | |
782 gfx::Size result_bounds; | |
783 | 729 |
784 SetupPendingTree(valid_pile); | 730 SetupPendingTree(valid_pile); |
785 pending_layer_->CalculateContentsScale(high_res_scale, | 731 SetupDrawPropertiesAndManageTilings(pending_layer_, |
786 device_scale, | 732 high_res_scale, |
787 page_scale, | 733 device_scale, |
788 maximum_animation_scale, | 734 page_scale, |
789 false, | 735 maximum_animation_scale, |
790 &result_scale_x, | 736 false); |
791 &result_scale_y, | |
792 &result_bounds); | |
793 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); | 737 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); |
794 EXPECT_FLOAT_EQ(high_res_scale, | 738 EXPECT_FLOAT_EQ(high_res_scale, |
795 pending_layer_->HighResTiling()->contents_scale()); | 739 pending_layer_->HighResTiling()->contents_scale()); |
796 EXPECT_FLOAT_EQ(low_res_scale, | 740 EXPECT_FLOAT_EQ(low_res_scale, |
797 pending_layer_->LowResTiling()->contents_scale()); | 741 pending_layer_->LowResTiling()->contents_scale()); |
798 | 742 |
799 ActivateTree(); | 743 ActivateTree(); |
800 SetupPendingTree(empty_pile); | 744 SetupPendingTree(empty_pile); |
801 pending_layer_->CalculateContentsScale(high_res_scale, | 745 SetupDrawPropertiesAndManageTilings(pending_layer_, |
802 device_scale, | 746 high_res_scale, |
803 page_scale, | 747 device_scale, |
804 maximum_animation_scale, | 748 page_scale, |
805 false, | 749 maximum_animation_scale, |
806 &result_scale_x, | 750 false); |
807 &result_scale_y, | |
808 &result_bounds); | |
809 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); | 751 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); |
810 ASSERT_EQ(0u, pending_layer_->tilings()->num_tilings()); | 752 ASSERT_EQ(0u, pending_layer_->tilings()->num_tilings()); |
811 | 753 |
812 ActivateTree(); | 754 ActivateTree(); |
813 active_layer_->CalculateContentsScale(high_res_scale, | 755 SetupDrawPropertiesAndManageTilings(active_layer_, |
814 device_scale, | 756 high_res_scale, |
815 page_scale, | 757 device_scale, |
816 maximum_animation_scale, | 758 page_scale, |
817 false, | 759 maximum_animation_scale, |
818 &result_scale_x, | 760 false); |
819 &result_scale_y, | |
820 &result_bounds); | |
821 ASSERT_EQ(0u, active_layer_->tilings()->num_tilings()); | 761 ASSERT_EQ(0u, active_layer_->tilings()->num_tilings()); |
822 | 762 |
823 SetupPendingTree(valid_pile); | 763 SetupPendingTree(valid_pile); |
824 pending_layer_->CalculateContentsScale(high_res_scale, | 764 SetupDrawPropertiesAndManageTilings(pending_layer_, |
825 device_scale, | 765 high_res_scale, |
826 page_scale, | 766 device_scale, |
827 maximum_animation_scale, | 767 page_scale, |
828 false, | 768 maximum_animation_scale, |
829 &result_scale_x, | 769 false); |
830 &result_scale_y, | |
831 &result_bounds); | |
832 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); | 770 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); |
833 ASSERT_EQ(0u, active_layer_->tilings()->num_tilings()); | 771 ASSERT_EQ(0u, active_layer_->tilings()->num_tilings()); |
834 EXPECT_FLOAT_EQ(high_res_scale, | 772 EXPECT_FLOAT_EQ(high_res_scale, |
835 pending_layer_->HighResTiling()->contents_scale()); | 773 pending_layer_->HighResTiling()->contents_scale()); |
836 EXPECT_FLOAT_EQ(low_res_scale, | 774 EXPECT_FLOAT_EQ(low_res_scale, |
837 pending_layer_->LowResTiling()->contents_scale()); | 775 pending_layer_->LowResTiling()->contents_scale()); |
838 } | 776 } |
839 | 777 |
840 TEST_F(PictureLayerImplTest, ZoomOutCrash) { | 778 TEST_F(PictureLayerImplTest, ZoomOutCrash) { |
841 gfx::Size tile_size(400, 400); | 779 gfx::Size tile_size(400, 400); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
955 | 893 |
956 TEST_F(PictureLayerImplTest, CleanUpTilings) { | 894 TEST_F(PictureLayerImplTest, CleanUpTilings) { |
957 gfx::Size tile_size(400, 400); | 895 gfx::Size tile_size(400, 400); |
958 gfx::Size layer_bounds(1300, 1900); | 896 gfx::Size layer_bounds(1300, 1900); |
959 | 897 |
960 scoped_refptr<FakePicturePileImpl> pending_pile = | 898 scoped_refptr<FakePicturePileImpl> pending_pile = |
961 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 899 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
962 scoped_refptr<FakePicturePileImpl> active_pile = | 900 scoped_refptr<FakePicturePileImpl> active_pile = |
963 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 901 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
964 | 902 |
965 float result_scale_x, result_scale_y; | |
966 gfx::Size result_bounds; | |
967 std::vector<PictureLayerTiling*> used_tilings; | 903 std::vector<PictureLayerTiling*> used_tilings; |
968 | 904 |
969 SetupTrees(pending_pile, active_pile); | 905 SetupTrees(pending_pile, active_pile); |
970 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); | 906 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); |
971 | 907 |
972 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; | 908 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; |
973 EXPECT_LT(low_res_factor, 1.f); | 909 EXPECT_LT(low_res_factor, 1.f); |
974 | 910 |
975 float device_scale = 1.7f; | 911 float device_scale = 1.7f; |
976 float page_scale = 3.2f; | 912 float page_scale = 3.2f; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1030 // Now move the ideal scale to 1.0. Our target stays 1.2. | 966 // Now move the ideal scale to 1.0. Our target stays 1.2. |
1031 SetContentsScaleOnBothLayers(1.f, device_scale, page_scale, 1.f, false); | 967 SetContentsScaleOnBothLayers(1.f, device_scale, page_scale, 1.f, false); |
1032 | 968 |
1033 // All the tilings are between are target and the ideal, so they are not | 969 // All the tilings are between are target and the ideal, so they are not |
1034 // removed. | 970 // removed. |
1035 used_tilings.clear(); | 971 used_tilings.clear(); |
1036 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); | 972 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); |
1037 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings()); | 973 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings()); |
1038 | 974 |
1039 // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2. | 975 // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2. |
1040 active_layer_->CalculateContentsScale(1.1f, | 976 SetupDrawPropertiesAndManageTilings( |
1041 device_scale, | 977 active_layer_, 1.1f, device_scale, page_scale, 1.f, false); |
1042 page_scale, | |
1043 1.f, | |
1044 false, | |
1045 &result_scale_x, | |
1046 &result_scale_y, | |
1047 &result_bounds); | |
1048 | 978 |
1049 // Because the pending layer's ideal scale is still 1.0, our tilings fall | 979 // Because the pending layer's ideal scale is still 1.0, our tilings fall |
1050 // in the range [1.0,1.2] and are kept. | 980 // in the range [1.0,1.2] and are kept. |
1051 used_tilings.clear(); | 981 used_tilings.clear(); |
1052 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); | 982 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); |
1053 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings()); | 983 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings()); |
1054 | 984 |
1055 // Move the ideal scale on the pending layer to 1.1 as well. Our target stays | 985 // Move the ideal scale on the pending layer to 1.1 as well. Our target stays |
1056 // 1.2 still. | 986 // 1.2 still. |
1057 pending_layer_->CalculateContentsScale(1.1f, | 987 SetupDrawPropertiesAndManageTilings( |
1058 device_scale, | 988 pending_layer_, 1.1f, device_scale, page_scale, 1.f, false); |
1059 page_scale, | |
1060 1.f, | |
1061 false, | |
1062 &result_scale_x, | |
1063 &result_scale_y, | |
1064 &result_bounds); | |
1065 | 989 |
1066 // Our 1.0 tiling now falls outside the range between our ideal scale and our | 990 // Our 1.0 tiling now falls outside the range between our ideal scale and our |
1067 // target raster scale. But it is in our used tilings set, so nothing is | 991 // target raster scale. But it is in our used tilings set, so nothing is |
1068 // deleted. | 992 // deleted. |
1069 used_tilings.clear(); | 993 used_tilings.clear(); |
1070 used_tilings.push_back(active_layer_->tilings()->tiling_at(1)); | 994 used_tilings.push_back(active_layer_->tilings()->tiling_at(1)); |
1071 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); | 995 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); |
1072 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings()); | 996 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings()); |
1073 | 997 |
1074 // If we remove it from our used tilings set, it is outside the range to keep | 998 // If we remove it from our used tilings set, it is outside the range to keep |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1208 | 1132 |
1209 TEST_F(PictureLayerImplTest, ReleaseResources) { | 1133 TEST_F(PictureLayerImplTest, ReleaseResources) { |
1210 gfx::Size tile_size(400, 400); | 1134 gfx::Size tile_size(400, 400); |
1211 gfx::Size layer_bounds(1300, 1900); | 1135 gfx::Size layer_bounds(1300, 1900); |
1212 | 1136 |
1213 scoped_refptr<FakePicturePileImpl> pending_pile = | 1137 scoped_refptr<FakePicturePileImpl> pending_pile = |
1214 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 1138 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
1215 scoped_refptr<FakePicturePileImpl> active_pile = | 1139 scoped_refptr<FakePicturePileImpl> active_pile = |
1216 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 1140 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
1217 | 1141 |
1218 float result_scale_x, result_scale_y; | |
1219 gfx::Size result_bounds; | |
1220 | |
1221 SetupTrees(pending_pile, active_pile); | 1142 SetupTrees(pending_pile, active_pile); |
1222 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); | 1143 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); |
1223 | 1144 |
1224 pending_layer_->CalculateContentsScale(1.3f, // ideal contents scale | 1145 SetupDrawPropertiesAndManageTilings(pending_layer_, |
1225 2.7f, // device scale | 1146 1.3f, // ideal contents scale |
1226 3.2f, // page scale | 1147 2.7f, // device scale |
1227 1.f, // maximum animation scale | 1148 3.2f, // page scale |
1228 false, | 1149 1.f, // maximum animation scale |
1229 &result_scale_x, | 1150 false); |
1230 &result_scale_y, | |
1231 &result_bounds); | |
1232 EXPECT_EQ(2u, pending_layer_->tilings()->num_tilings()); | 1151 EXPECT_EQ(2u, pending_layer_->tilings()->num_tilings()); |
1233 | 1152 |
1234 // All tilings should be removed when losing output surface. | 1153 // All tilings should be removed when losing output surface. |
1235 active_layer_->ReleaseResources(); | 1154 active_layer_->ReleaseResources(); |
1236 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings()); | 1155 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings()); |
1237 pending_layer_->ReleaseResources(); | 1156 pending_layer_->ReleaseResources(); |
1238 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); | 1157 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); |
1239 | 1158 |
1240 // This should create new tilings. | 1159 // This should create new tilings. |
1241 pending_layer_->CalculateContentsScale(1.3f, // ideal contents scale | 1160 SetupDrawPropertiesAndManageTilings(pending_layer_, |
1242 2.7f, // device scale | 1161 1.3f, // ideal contents scale |
1243 3.2f, // page scale | 1162 2.7f, // device scale |
1244 1.f, // maximum animation scale | 1163 3.2f, // page scale |
1245 false, | 1164 1.f, // maximum animation scale |
1246 &result_scale_x, | 1165 false); |
1247 &result_scale_y, | |
1248 &result_bounds); | |
1249 EXPECT_EQ(2u, pending_layer_->tilings()->num_tilings()); | 1166 EXPECT_EQ(2u, pending_layer_->tilings()->num_tilings()); |
1250 } | 1167 } |
1251 | 1168 |
1252 TEST_F(PictureLayerImplTest, ClampTilesToToMaxTileSize) { | 1169 TEST_F(PictureLayerImplTest, ClampTilesToToMaxTileSize) { |
1253 // The default max tile size is larger than 400x400. | 1170 // The default max tile size is larger than 400x400. |
1254 gfx::Size tile_size(400, 400); | 1171 gfx::Size tile_size(400, 400); |
1255 gfx::Size layer_bounds(5000, 5000); | 1172 gfx::Size layer_bounds(5000, 5000); |
1256 | 1173 |
1257 scoped_refptr<FakePicturePileImpl> pending_pile = | 1174 scoped_refptr<FakePicturePileImpl> pending_pile = |
1258 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 1175 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
1259 scoped_refptr<FakePicturePileImpl> active_pile = | 1176 scoped_refptr<FakePicturePileImpl> active_pile = |
1260 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 1177 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
1261 | 1178 |
1262 float result_scale_x, result_scale_y; | |
1263 gfx::Size result_bounds; | |
1264 | |
1265 SetupTrees(pending_pile, active_pile); | 1179 SetupTrees(pending_pile, active_pile); |
1266 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); | 1180 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); |
1267 | 1181 |
1268 pending_layer_->CalculateContentsScale(1.f, | 1182 SetupDrawPropertiesAndManageTilings( |
1269 1.f, | 1183 pending_layer_, 1.f, 1.f, 1.f, 1.f, false); |
1270 1.f, | |
1271 1.f, | |
1272 false, | |
1273 &result_scale_x, | |
1274 &result_scale_y, | |
1275 &result_bounds); | |
1276 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); | 1184 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); |
1277 | 1185 |
1278 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting(); | 1186 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting(); |
1279 | 1187 |
1280 // The default value. | 1188 // The default value. |
1281 EXPECT_EQ(gfx::Size(256, 256).ToString(), | 1189 EXPECT_EQ(gfx::Size(256, 256).ToString(), |
1282 host_impl_.settings().default_tile_size.ToString()); | 1190 host_impl_.settings().default_tile_size.ToString()); |
1283 | 1191 |
1284 Tile* tile = pending_layer_->tilings()->tiling_at(0)->AllTilesForTesting()[0]; | 1192 Tile* tile = pending_layer_->tilings()->tiling_at(0)->AllTilesForTesting()[0]; |
1285 EXPECT_EQ(gfx::Size(256, 256).ToString(), | 1193 EXPECT_EQ(gfx::Size(256, 256).ToString(), |
1286 tile->content_rect().size().ToString()); | 1194 tile->content_rect().size().ToString()); |
1287 | 1195 |
1288 pending_layer_->ReleaseResources(); | 1196 pending_layer_->ReleaseResources(); |
1289 | 1197 |
1290 // Change the max texture size on the output surface context. | 1198 // Change the max texture size on the output surface context. |
1291 scoped_ptr<TestWebGraphicsContext3D> context = | 1199 scoped_ptr<TestWebGraphicsContext3D> context = |
1292 TestWebGraphicsContext3D::Create(); | 1200 TestWebGraphicsContext3D::Create(); |
1293 context->set_max_texture_size(140); | 1201 context->set_max_texture_size(140); |
1294 host_impl_.DidLoseOutputSurface(); | 1202 host_impl_.DidLoseOutputSurface(); |
1295 host_impl_.InitializeRenderer(FakeOutputSurface::Create3d( | 1203 host_impl_.InitializeRenderer(FakeOutputSurface::Create3d( |
1296 context.Pass()).PassAs<OutputSurface>()); | 1204 context.Pass()).PassAs<OutputSurface>()); |
1297 | 1205 |
1298 pending_layer_->CalculateContentsScale(1.f, | 1206 SetupDrawPropertiesAndManageTilings( |
1299 1.f, | 1207 pending_layer_, 1.f, 1.f, 1.f, 1.f, false); |
1300 1.f, | |
1301 1.f, | |
1302 false, | |
1303 &result_scale_x, | |
1304 &result_scale_y, | |
1305 &result_bounds); | |
1306 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); | 1208 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); |
1307 | 1209 |
1308 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting(); | 1210 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting(); |
1309 | 1211 |
1310 // Verify the tiles are not larger than the context's max texture size. | 1212 // Verify the tiles are not larger than the context's max texture size. |
1311 tile = pending_layer_->tilings()->tiling_at(0)->AllTilesForTesting()[0]; | 1213 tile = pending_layer_->tilings()->tiling_at(0)->AllTilesForTesting()[0]; |
1312 EXPECT_GE(140, tile->content_rect().width()); | 1214 EXPECT_GE(140, tile->content_rect().width()); |
1313 EXPECT_GE(140, tile->content_rect().height()); | 1215 EXPECT_GE(140, tile->content_rect().height()); |
1314 } | 1216 } |
1315 | 1217 |
1316 TEST_F(PictureLayerImplTest, ClampSingleTileToToMaxTileSize) { | 1218 TEST_F(PictureLayerImplTest, ClampSingleTileToToMaxTileSize) { |
1317 // The default max tile size is larger than 400x400. | 1219 // The default max tile size is larger than 400x400. |
1318 gfx::Size tile_size(400, 400); | 1220 gfx::Size tile_size(400, 400); |
1319 gfx::Size layer_bounds(500, 500); | 1221 gfx::Size layer_bounds(500, 500); |
1320 | 1222 |
1321 scoped_refptr<FakePicturePileImpl> pending_pile = | 1223 scoped_refptr<FakePicturePileImpl> pending_pile = |
1322 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 1224 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
1323 scoped_refptr<FakePicturePileImpl> active_pile = | 1225 scoped_refptr<FakePicturePileImpl> active_pile = |
1324 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 1226 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
1325 | 1227 |
1326 float result_scale_x, result_scale_y; | |
1327 gfx::Size result_bounds; | |
1328 | |
1329 SetupTrees(pending_pile, active_pile); | 1228 SetupTrees(pending_pile, active_pile); |
1330 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); | 1229 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); |
1331 | 1230 |
1332 pending_layer_->CalculateContentsScale(1.f, | 1231 SetupDrawPropertiesAndManageTilings( |
1333 1.f, | 1232 pending_layer_, 1.f, 1.f, 1.f, 1.f, false); |
1334 1.f, | |
1335 1.f, | |
1336 false, | |
1337 &result_scale_x, | |
1338 &result_scale_y, | |
1339 &result_bounds); | |
1340 ASSERT_LE(1u, pending_layer_->tilings()->num_tilings()); | 1233 ASSERT_LE(1u, pending_layer_->tilings()->num_tilings()); |
1341 | 1234 |
1342 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting(); | 1235 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting(); |
1343 | 1236 |
1344 // The default value. The layer is smaller than this. | 1237 // The default value. The layer is smaller than this. |
1345 EXPECT_EQ(gfx::Size(512, 512).ToString(), | 1238 EXPECT_EQ(gfx::Size(512, 512).ToString(), |
1346 host_impl_.settings().max_untiled_layer_size.ToString()); | 1239 host_impl_.settings().max_untiled_layer_size.ToString()); |
1347 | 1240 |
1348 // There should be a single tile since the layer is small. | 1241 // There should be a single tile since the layer is small. |
1349 PictureLayerTiling* high_res_tiling = pending_layer_->tilings()->tiling_at(0); | 1242 PictureLayerTiling* high_res_tiling = pending_layer_->tilings()->tiling_at(0); |
1350 EXPECT_EQ(1u, high_res_tiling->AllTilesForTesting().size()); | 1243 EXPECT_EQ(1u, high_res_tiling->AllTilesForTesting().size()); |
1351 | 1244 |
1352 pending_layer_->ReleaseResources(); | 1245 pending_layer_->ReleaseResources(); |
1353 | 1246 |
1354 // Change the max texture size on the output surface context. | 1247 // Change the max texture size on the output surface context. |
1355 scoped_ptr<TestWebGraphicsContext3D> context = | 1248 scoped_ptr<TestWebGraphicsContext3D> context = |
1356 TestWebGraphicsContext3D::Create(); | 1249 TestWebGraphicsContext3D::Create(); |
1357 context->set_max_texture_size(140); | 1250 context->set_max_texture_size(140); |
1358 host_impl_.DidLoseOutputSurface(); | 1251 host_impl_.DidLoseOutputSurface(); |
1359 host_impl_.InitializeRenderer(FakeOutputSurface::Create3d( | 1252 host_impl_.InitializeRenderer(FakeOutputSurface::Create3d( |
1360 context.Pass()).PassAs<OutputSurface>()); | 1253 context.Pass()).PassAs<OutputSurface>()); |
1361 | 1254 |
1362 pending_layer_->CalculateContentsScale(1.f, | 1255 SetupDrawPropertiesAndManageTilings( |
1363 1.f, | 1256 pending_layer_, 1.f, 1.f, 1.f, 1.f, false); |
1364 1.f, | |
1365 1.f, | |
1366 false, | |
1367 &result_scale_x, | |
1368 &result_scale_y, | |
1369 &result_bounds); | |
1370 ASSERT_LE(1u, pending_layer_->tilings()->num_tilings()); | 1257 ASSERT_LE(1u, pending_layer_->tilings()->num_tilings()); |
1371 | 1258 |
1372 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting(); | 1259 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting(); |
1373 | 1260 |
1374 // There should be more than one tile since the max texture size won't cover | 1261 // There should be more than one tile since the max texture size won't cover |
1375 // the layer. | 1262 // the layer. |
1376 high_res_tiling = pending_layer_->tilings()->tiling_at(0); | 1263 high_res_tiling = pending_layer_->tilings()->tiling_at(0); |
1377 EXPECT_LT(1u, high_res_tiling->AllTilesForTesting().size()); | 1264 EXPECT_LT(1u, high_res_tiling->AllTilesForTesting().size()); |
1378 | 1265 |
1379 // Verify the tiles are not larger than the context's max texture size. | 1266 // Verify the tiles are not larger than the context's max texture size. |
1380 Tile* tile = pending_layer_->tilings()->tiling_at(0)->AllTilesForTesting()[0]; | 1267 Tile* tile = pending_layer_->tilings()->tiling_at(0)->AllTilesForTesting()[0]; |
1381 EXPECT_GE(140, tile->content_rect().width()); | 1268 EXPECT_GE(140, tile->content_rect().width()); |
1382 EXPECT_GE(140, tile->content_rect().height()); | 1269 EXPECT_GE(140, tile->content_rect().height()); |
1383 } | 1270 } |
1384 | 1271 |
1385 TEST_F(PictureLayerImplTest, DisallowTileDrawQuads) { | 1272 TEST_F(PictureLayerImplTest, DisallowTileDrawQuads) { |
1386 MockQuadCuller quad_culler; | 1273 MockQuadCuller quad_culler; |
1387 | 1274 |
1388 gfx::Size tile_size(400, 400); | 1275 gfx::Size tile_size(400, 400); |
1389 gfx::Size layer_bounds(1300, 1900); | 1276 gfx::Size layer_bounds(1300, 1900); |
1390 | 1277 |
1391 scoped_refptr<FakePicturePileImpl> pending_pile = | 1278 scoped_refptr<FakePicturePileImpl> pending_pile = |
1392 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 1279 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
1393 scoped_refptr<FakePicturePileImpl> active_pile = | 1280 scoped_refptr<FakePicturePileImpl> active_pile = |
1394 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 1281 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
1395 | 1282 |
1396 SetupTrees(pending_pile, active_pile); | 1283 SetupTrees(pending_pile, active_pile); |
1397 | 1284 |
1398 active_layer_->SetContentBounds(layer_bounds); | |
1399 active_layer_->draw_properties().visible_content_rect = | 1285 active_layer_->draw_properties().visible_content_rect = |
1400 gfx::Rect(layer_bounds); | 1286 gfx::Rect(layer_bounds); |
1401 | 1287 |
1402 gfx::Rect layer_invalidation(150, 200, 30, 180); | 1288 gfx::Rect layer_invalidation(150, 200, 30, 180); |
1403 Region invalidation(layer_invalidation); | 1289 Region invalidation(layer_invalidation); |
1404 AddDefaultTilingsWithInvalidation(invalidation); | 1290 AddDefaultTilingsWithInvalidation(invalidation); |
1405 | 1291 |
1406 AppendQuadsData data; | 1292 AppendQuadsData data; |
1407 active_layer_->WillDraw(DRAW_MODE_RESOURCELESS_SOFTWARE, NULL); | 1293 active_layer_->WillDraw(DRAW_MODE_RESOURCELESS_SOFTWARE, NULL); |
1408 active_layer_->AppendQuads(&quad_culler, &data); | 1294 active_layer_->AppendQuads(&quad_culler, &data); |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1806 pending_layer_->tilings()->TilingAtScale(1.0f)->resolution()); | 1692 pending_layer_->tilings()->TilingAtScale(1.0f)->resolution()); |
1807 ASSERT_TRUE(pending_layer_->tilings()->TilingAtScale(1.5f)); | 1693 ASSERT_TRUE(pending_layer_->tilings()->TilingAtScale(1.5f)); |
1808 EXPECT_EQ(NON_IDEAL_RESOLUTION, | 1694 EXPECT_EQ(NON_IDEAL_RESOLUTION, |
1809 pending_layer_->tilings()->TilingAtScale(1.5f)->resolution()); | 1695 pending_layer_->tilings()->TilingAtScale(1.5f)->resolution()); |
1810 } | 1696 } |
1811 | 1697 |
1812 TEST_F(PictureLayerImplTest, NoLowResTilingWithGpuRasterization) { | 1698 TEST_F(PictureLayerImplTest, NoLowResTilingWithGpuRasterization) { |
1813 gfx::Size default_tile_size(host_impl_.settings().default_tile_size); | 1699 gfx::Size default_tile_size(host_impl_.settings().default_tile_size); |
1814 gfx::Size layer_bounds(default_tile_size.width() * 4, | 1700 gfx::Size layer_bounds(default_tile_size.width() * 4, |
1815 default_tile_size.height() * 4); | 1701 default_tile_size.height() * 4); |
1816 float result_scale_x, result_scale_y; | |
1817 gfx::Size result_bounds; | |
1818 | 1702 |
1819 SetupDefaultTrees(layer_bounds); | 1703 SetupDefaultTrees(layer_bounds); |
1820 EXPECT_FALSE(host_impl_.use_gpu_rasterization()); | 1704 EXPECT_FALSE(host_impl_.use_gpu_rasterization()); |
1821 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); | 1705 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); |
1822 pending_layer_->CalculateContentsScale(1.f, | 1706 SetupDrawPropertiesAndManageTilings( |
1823 1.f, | 1707 pending_layer_, 1.f, 1.f, 1.f, 1.f, false); |
1824 1.f, | |
1825 1.f, | |
1826 false, | |
1827 &result_scale_x, | |
1828 &result_scale_y, | |
1829 &result_bounds); | |
1830 // Should have a low-res and a high-res tiling. | 1708 // Should have a low-res and a high-res tiling. |
1831 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); | 1709 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); |
1832 | 1710 |
1833 ResetTilingsAndRasterScales(); | 1711 ResetTilingsAndRasterScales(); |
1834 | 1712 |
1835 host_impl_.SetUseGpuRasterization(true); | 1713 host_impl_.SetUseGpuRasterization(true); |
1836 EXPECT_TRUE(host_impl_.use_gpu_rasterization()); | 1714 EXPECT_TRUE(host_impl_.use_gpu_rasterization()); |
1837 pending_layer_->CalculateContentsScale(1.f, | 1715 SetupDrawPropertiesAndManageTilings( |
1838 1.f, | 1716 pending_layer_, 1.f, 1.f, 1.f, 1.f, false); |
1839 1.f, | 1717 |
1840 1.f, | |
1841 false, | |
1842 &result_scale_x, | |
1843 &result_scale_y, | |
1844 &result_bounds); | |
1845 // Should only have the high-res tiling. | 1718 // Should only have the high-res tiling. |
1846 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings()); | 1719 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings()); |
1847 } | 1720 } |
1848 | 1721 |
1849 TEST_F(PictureLayerImplTest, NoTilingIfDoesNotDrawContent) { | 1722 TEST_F(PictureLayerImplTest, NoTilingIfDoesNotDrawContent) { |
1850 // Set up layers with tilings. | 1723 // Set up layers with tilings. |
1851 SetupDefaultTrees(gfx::Size(10, 10)); | 1724 SetupDefaultTrees(gfx::Size(10, 10)); |
1852 SetContentsScaleOnBothLayers(1.f, 1.f, 1.f, 1.f, false); | 1725 SetContentsScaleOnBothLayers(1.f, 1.f, 1.f, 1.f, false); |
1853 pending_layer_->PushPropertiesTo(active_layer_); | 1726 pending_layer_->PushPropertiesTo(active_layer_); |
1854 EXPECT_TRUE(pending_layer_->DrawsContent()); | 1727 EXPECT_TRUE(pending_layer_->DrawsContent()); |
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2440 | 2313 |
2441 // High-res tiles should not be enough. | 2314 // High-res tiles should not be enough. |
2442 EXPECT_FALSE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw()); | 2315 EXPECT_FALSE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw()); |
2443 | 2316 |
2444 // Initialize remaining tiles. | 2317 // Initialize remaining tiles. |
2445 pending_layer_->SetAllTilesReady(); | 2318 pending_layer_->SetAllTilesReady(); |
2446 | 2319 |
2447 EXPECT_TRUE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw()); | 2320 EXPECT_TRUE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw()); |
2448 } | 2321 } |
2449 | 2322 |
| 2323 TEST_F(PictureLayerImplTest, SharedQuadStateContainsMaxTilingScale) { |
| 2324 MockQuadCuller quad_culler; |
| 2325 |
| 2326 gfx::Size tile_size(400, 400); |
| 2327 gfx::Size layer_bounds(1000, 2000); |
| 2328 |
| 2329 scoped_refptr<FakePicturePileImpl> pending_pile = |
| 2330 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 2331 scoped_refptr<FakePicturePileImpl> active_pile = |
| 2332 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 2333 |
| 2334 SetupTrees(pending_pile, active_pile); |
| 2335 |
| 2336 SetupDrawPropertiesAndManageTilings( |
| 2337 pending_layer_, 2.5f, 1.f, 1.f, 1.f, false); |
| 2338 host_impl_.pending_tree()->UpdateDrawProperties(); |
| 2339 |
| 2340 active_layer_->draw_properties().visible_content_rect = |
| 2341 gfx::Rect(layer_bounds); |
| 2342 host_impl_.active_tree()->UpdateDrawProperties(); |
| 2343 |
| 2344 float max_contents_scale = active_layer_->MaximumTilingContentScale(); |
| 2345 gfx::Transform scaled_draw_transform = active_layer_->draw_transform(); |
| 2346 scaled_draw_transform.Scale(SK_MScalar1 / max_contents_scale, |
| 2347 SK_MScalar1 / max_contents_scale); |
| 2348 |
| 2349 AppendQuadsData data; |
| 2350 active_layer_->AppendQuads(&quad_culler, &data); |
| 2351 |
| 2352 // SharedQuadState should have be of size 1, as we are doing AppenQuad once. |
| 2353 EXPECT_EQ(1u, quad_culler.shared_quad_state_list().size()); |
| 2354 // The content_to_target_transform should be scaled by the |
| 2355 // MaximumTilingContentScale on the layer. |
| 2356 EXPECT_EQ(scaled_draw_transform.ToString(), |
| 2357 quad_culler.shared_quad_state_list()[0] |
| 2358 ->content_to_target_transform.ToString()); |
| 2359 // The content_bounds should be scaled by the |
| 2360 // MaximumTilingContentScale on the layer. |
| 2361 EXPECT_EQ(gfx::Size(2500u, 5000u).ToString(), |
| 2362 quad_culler.shared_quad_state_list()[0]->content_bounds.ToString()); |
| 2363 // The visible_content_rect should be scaled by the |
| 2364 // MaximumTilingContentScale on the layer. |
| 2365 EXPECT_EQ( |
| 2366 gfx::Rect(0u, 0u, 2500u, 5000u).ToString(), |
| 2367 quad_culler.shared_quad_state_list()[0]->visible_content_rect.ToString()); |
| 2368 } |
| 2369 |
2450 } // namespace | 2370 } // namespace |
2451 } // namespace cc | 2371 } // namespace cc |
OLD | NEW |