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