Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Side by Side Diff: cc/layers/picture_layer_impl_unittest.cc

Issue 271533011: cc: Move tiling management out of draw properties calculation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase + update test Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 scoped_ptr<FakePictureLayerImpl> pending_layer = 133 scoped_ptr<FakePictureLayerImpl> pending_layer =
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_tree->SetRootLayer(pending_layer.PassAs<LayerImpl>()); 136 pending_tree->SetRootLayer(pending_layer.PassAs<LayerImpl>());
136 137
137 pending_layer_ = static_cast<FakePictureLayerImpl*>( 138 pending_layer_ = static_cast<FakePictureLayerImpl*>(
138 host_impl_.pending_tree()->LayerById(id_)); 139 host_impl_.pending_tree()->LayerById(id_));
139 pending_layer_->DoPostCommitInitializationIfNeeded(); 140 pending_layer_->DoPostCommitInitializationIfNeeded();
140 } 141 }
141 142
143 void SetupDrawPropertiesAndManageTilings(
144 FakePictureLayerImpl* layer,
145 float ideal_contents_scale,
146 float device_scale_factor,
147 float page_scale_factor,
148 float maximum_animation_contents_scale,
149 bool animating_transform_to_screen) {
150 layer->draw_properties().ideal_contents_scale = ideal_contents_scale;
151 layer->draw_properties().device_scale_factor = device_scale_factor;
152 layer->draw_properties().page_scale_factor = page_scale_factor;
153 layer->draw_properties().maximum_animation_contents_scale =
154 maximum_animation_contents_scale;
155 layer->draw_properties().screen_space_transform_is_animating =
156 animating_transform_to_screen;
157 layer->ScaleAndManageTilings(animating_transform_to_screen,
158 maximum_animation_contents_scale);
159 }
142 static void VerifyAllTilesExistAndHavePile( 160 static void VerifyAllTilesExistAndHavePile(
143 const PictureLayerTiling* tiling, 161 const PictureLayerTiling* tiling,
144 PicturePileImpl* pile) { 162 PicturePileImpl* pile) {
145 for (PictureLayerTiling::CoverageIterator iter( 163 for (PictureLayerTiling::CoverageIterator iter(
146 tiling, tiling->contents_scale(), tiling->TilingRect()); 164 tiling, tiling->contents_scale(), tiling->TilingRect());
147 iter; 165 iter;
148 ++iter) { 166 ++iter) {
149 EXPECT_TRUE(*iter); 167 EXPECT_TRUE(*iter);
150 EXPECT_EQ(pile, iter->picture_pile()); 168 EXPECT_EQ(pile, iter->picture_pile());
151 } 169 }
152 } 170 }
153 171
154 void SetContentsScaleOnBothLayers(float contents_scale, 172 void SetContentsScaleOnBothLayers(float contents_scale,
155 float device_scale_factor, 173 float device_scale_factor,
156 float page_scale_factor, 174 float page_scale_factor,
157 float maximum_animation_contents_scale, 175 float maximum_animation_contents_scale,
158 bool animating_transform) { 176 bool animating_transform) {
159 float result_scale_x, result_scale_y; 177 SetupDrawPropertiesAndManageTilings(pending_layer_,
160 gfx::Size result_bounds; 178 contents_scale,
161 pending_layer_->CalculateContentsScale(contents_scale, 179 device_scale_factor,
162 device_scale_factor, 180 page_scale_factor,
163 page_scale_factor, 181 maximum_animation_contents_scale,
164 maximum_animation_contents_scale, 182 animating_transform);
165 animating_transform, 183
166 &result_scale_x, 184 SetupDrawPropertiesAndManageTilings(active_layer_,
167 &result_scale_y, 185 contents_scale,
168 &result_bounds); 186 device_scale_factor,
169 active_layer_->CalculateContentsScale(contents_scale, 187 page_scale_factor,
170 device_scale_factor, 188 maximum_animation_contents_scale,
171 page_scale_factor, 189 animating_transform);
172 maximum_animation_contents_scale,
173 animating_transform,
174 &result_scale_x,
175 &result_scale_y,
176 &result_bounds);
177 } 190 }
178 191
179 void ResetTilingsAndRasterScales() { 192 void ResetTilingsAndRasterScales() {
180 pending_layer_->ReleaseResources(); 193 pending_layer_->ReleaseResources();
181 active_layer_->ReleaseResources(); 194 active_layer_->ReleaseResources();
182 } 195 }
183 196
184 void AssertAllTilesRequired(PictureLayerTiling* tiling) { 197 void AssertAllTilesRequired(PictureLayerTiling* tiling) {
185 std::vector<Tile*> tiles = tiling->AllTilesForTesting(); 198 std::vector<Tile*> tiles = tiling->AllTilesForTesting();
186 for (size_t i = 0; i < tiles.size(); ++i) 199 for (size_t i = 0; i < tiles.size(); ++i)
(...skipping 16 matching lines...) Expand all
203 settings.default_tile_size.width() * 7 / 2, 216 settings.default_tile_size.width() * 7 / 2,
204 settings.default_tile_size.height() * 7 / 2); 217 settings.default_tile_size.height() * 7 / 2);
205 218
206 scoped_refptr<FakePicturePileImpl> pending_pile = 219 scoped_refptr<FakePicturePileImpl> pending_pile =
207 FakePicturePileImpl::CreateFilledPile(layer_size, layer_size); 220 FakePicturePileImpl::CreateFilledPile(layer_size, layer_size);
208 scoped_refptr<FakePicturePileImpl> active_pile = 221 scoped_refptr<FakePicturePileImpl> active_pile =
209 FakePicturePileImpl::CreateFilledPile(layer_size, layer_size); 222 FakePicturePileImpl::CreateFilledPile(layer_size, layer_size);
210 223
211 SetupTrees(pending_pile, active_pile); 224 SetupTrees(pending_pile, active_pile);
212 225
213 float result_scale_x, result_scale_y; 226 SetupDrawPropertiesAndManageTilings(
214 gfx::Size result_bounds; 227 active_layer_, 1.f, 1.f, 1.f, 1.f, false);
215 active_layer_->CalculateContentsScale(1.f,
216 1.f,
217 1.f,
218 1.f,
219 false,
220 &result_scale_x,
221 &result_scale_y,
222 &result_bounds);
223 228
224 // Add 1x1 rects at the centers of each tile, then re-record pile contents 229 // Add 1x1 rects at the centers of each tile, then re-record pile contents
225 active_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting(); 230 active_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting();
226 std::vector<Tile*> tiles = 231 std::vector<Tile*> tiles =
227 active_layer_->tilings()->tiling_at(0)->AllTilesForTesting(); 232 active_layer_->tilings()->tiling_at(0)->AllTilesForTesting();
228 EXPECT_EQ(16u, tiles.size()); 233 EXPECT_EQ(16u, tiles.size());
229 std::vector<SkRect> rects; 234 std::vector<SkRect> rects;
230 std::vector<Tile*>::const_iterator tile_iter; 235 std::vector<Tile*>::const_iterator tile_iter;
231 for (tile_iter = tiles.begin(); tile_iter < tiles.end(); tile_iter++) { 236 for (tile_iter = tiles.begin(); tile_iter < tiles.end(); tile_iter++) {
232 gfx::Point tile_center = (*tile_iter)->content_rect().CenterPoint(); 237 gfx::Point tile_center = (*tile_iter)->content_rect().CenterPoint();
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 scoped_refptr<FakePicturePileImpl> active_pile = 312 scoped_refptr<FakePicturePileImpl> active_pile =
308 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 313 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
309 314
310 SetupTrees(pending_pile, active_pile); 315 SetupTrees(pending_pile, active_pile);
311 316
312 std::vector<TileManager::PairedPictureLayer> paired_layers; 317 std::vector<TileManager::PairedPictureLayer> paired_layers;
313 host_impl_.tile_manager()->GetPairedPictureLayers(&paired_layers); 318 host_impl_.tile_manager()->GetPairedPictureLayers(&paired_layers);
314 EXPECT_EQ(0u, paired_layers.size()); 319 EXPECT_EQ(0u, paired_layers.size());
315 320
316 // Update tile priorities will force the layer to register itself. 321 // Update tile priorities will force the layer to register itself.
317 float dummy_contents_scale_x; 322 SetupDrawPropertiesAndManageTilings(active_layer_, 1.f, 1.f, 1.f, 1.f, false);
318 float dummy_contents_scale_y;
319 gfx::Size dummy_content_bounds;
320 active_layer_->CalculateContentsScale(1.f,
321 1.f,
322 1.f,
323 1.f,
324 false,
325 &dummy_contents_scale_x,
326 &dummy_contents_scale_y,
327 &dummy_content_bounds);
328 active_layer_->UpdateTilePriorities(); 323 active_layer_->UpdateTilePriorities();
329 host_impl_.pending_tree()->UpdateDrawProperties(); 324 host_impl_.pending_tree()->UpdateDrawProperties();
330 pending_layer_->CalculateContentsScale(1.f, 325
331 1.f, 326 SetupDrawPropertiesAndManageTilings(
332 1.f, 327 pending_layer_, 1.f, 1.f, 1.f, 1.f, false);
333 1.f,
334 false,
335 &dummy_contents_scale_x,
336 &dummy_contents_scale_y,
337 &dummy_content_bounds);
338 pending_layer_->UpdateTilePriorities(); 328 pending_layer_->UpdateTilePriorities();
339 329
340 host_impl_.tile_manager()->GetPairedPictureLayers(&paired_layers); 330 host_impl_.tile_manager()->GetPairedPictureLayers(&paired_layers);
341 EXPECT_EQ(1u, paired_layers.size()); 331 EXPECT_EQ(1u, paired_layers.size());
342 EXPECT_EQ(active_layer_, paired_layers[0].active_layer); 332 EXPECT_EQ(active_layer_, paired_layers[0].active_layer);
343 EXPECT_EQ(pending_layer_, paired_layers[0].pending_layer); 333 EXPECT_EQ(pending_layer_, paired_layers[0].pending_layer);
344 334
345 // Destroy and recreate tile manager. 335 // Destroy and recreate tile manager.
346 host_impl_.DidLoseOutputSurface(); 336 host_impl_.DidLoseOutputSurface();
347 scoped_ptr<TestWebGraphicsContext3D> context = 337 scoped_ptr<TestWebGraphicsContext3D> context =
348 TestWebGraphicsContext3D::Create(); 338 TestWebGraphicsContext3D::Create();
349 host_impl_.InitializeRenderer( 339 host_impl_.InitializeRenderer(
350 FakeOutputSurface::Create3d(context.Pass()).PassAs<OutputSurface>()); 340 FakeOutputSurface::Create3d(context.Pass()).PassAs<OutputSurface>());
351 341
352 host_impl_.tile_manager()->GetPairedPictureLayers(&paired_layers); 342 host_impl_.tile_manager()->GetPairedPictureLayers(&paired_layers);
353 EXPECT_EQ(0u, paired_layers.size()); 343 EXPECT_EQ(0u, paired_layers.size());
354 344
355 active_layer_->CalculateContentsScale(1.f, 345 SetupDrawPropertiesAndManageTilings(active_layer_, 1.f, 1.f, 1.f, 1.f, false);
356 1.f,
357 1.f,
358 1.f,
359 false,
360 &dummy_contents_scale_x,
361 &dummy_contents_scale_y,
362 &dummy_content_bounds);
363 active_layer_->UpdateTilePriorities(); 346 active_layer_->UpdateTilePriorities();
364 host_impl_.pending_tree()->UpdateDrawProperties(); 347 host_impl_.pending_tree()->UpdateDrawProperties();
365 pending_layer_->CalculateContentsScale(1.f, 348
366 1.f, 349 SetupDrawPropertiesAndManageTilings(
367 1.f, 350 pending_layer_, 1.f, 1.f, 1.f, 1.f, false);
368 1.f,
369 false,
370 &dummy_contents_scale_x,
371 &dummy_contents_scale_y,
372 &dummy_content_bounds);
373 pending_layer_->UpdateTilePriorities(); 351 pending_layer_->UpdateTilePriorities();
374 352
375 host_impl_.tile_manager()->GetPairedPictureLayers(&paired_layers); 353 host_impl_.tile_manager()->GetPairedPictureLayers(&paired_layers);
376 EXPECT_EQ(1u, paired_layers.size()); 354 EXPECT_EQ(1u, paired_layers.size());
377 EXPECT_EQ(active_layer_, paired_layers[0].active_layer); 355 EXPECT_EQ(active_layer_, paired_layers[0].active_layer);
378 EXPECT_EQ(pending_layer_, paired_layers[0].pending_layer); 356 EXPECT_EQ(pending_layer_, paired_layers[0].pending_layer);
379 } 357 }
380 358
381 TEST_F(PictureLayerImplTest, InvalidViewportForPrioritizingTiles) { 359 TEST_F(PictureLayerImplTest, InvalidViewportForPrioritizingTiles) {
382 base::TimeTicks time_ticks; 360 base::TimeTicks time_ticks;
383 host_impl_.SetCurrentFrameTimeTicks(time_ticks); 361 host_impl_.SetCurrentFrameTimeTicks(time_ticks);
384 362
385 gfx::Size tile_size(100, 100); 363 gfx::Size tile_size(100, 100);
386 gfx::Size layer_bounds(400, 400); 364 gfx::Size layer_bounds(400, 400);
387 365
388 scoped_refptr<FakePicturePileImpl> pending_pile = 366 scoped_refptr<FakePicturePileImpl> pending_pile =
389 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 367 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
390 scoped_refptr<FakePicturePileImpl> active_pile = 368 scoped_refptr<FakePicturePileImpl> active_pile =
391 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 369 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
392 370
393 SetupTrees(pending_pile, active_pile); 371 SetupTrees(pending_pile, active_pile);
394 372
395 Region invalidation; 373 Region invalidation;
396 AddDefaultTilingsWithInvalidation(invalidation); 374 AddDefaultTilingsWithInvalidation(invalidation);
397 float dummy_contents_scale_x; 375 SetupDrawPropertiesAndManageTilings(active_layer_, 1.f, 1.f, 1.f, 1.f, false);
398 float dummy_contents_scale_y;
399 gfx::Size dummy_content_bounds;
400 active_layer_->CalculateContentsScale(1.f,
401 1.f,
402 1.f,
403 1.f,
404 false,
405 &dummy_contents_scale_x,
406 &dummy_contents_scale_y,
407 &dummy_content_bounds);
408 376
409 // UpdateTilePriorities with valid viewport. Should update tile viewport. 377 // UpdateTilePriorities with valid viewport. Should update tile viewport.
410 bool valid_for_tile_management = true; 378 bool valid_for_tile_management = true;
411 gfx::Rect viewport = gfx::Rect(layer_bounds); 379 gfx::Rect viewport = gfx::Rect(layer_bounds);
412 gfx::Transform transform; 380 gfx::Transform transform;
413 host_impl_.SetExternalDrawConstraints( 381 host_impl_.SetExternalDrawConstraints(
414 transform, viewport, viewport, valid_for_tile_management); 382 transform, viewport, viewport, valid_for_tile_management);
415 active_layer_->draw_properties().visible_content_rect = viewport; 383 active_layer_->draw_properties().visible_content_rect = viewport;
416 active_layer_->draw_properties().screen_space_transform = transform; 384 active_layer_->draw_properties().screen_space_transform = transform;
417 active_layer_->UpdateTilePriorities(); 385 active_layer_->UpdateTilePriorities();
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 622
655 TEST_F(PictureLayerImplTest, ManageTilingsWithNoRecording) { 623 TEST_F(PictureLayerImplTest, ManageTilingsWithNoRecording) {
656 gfx::Size tile_size(400, 400); 624 gfx::Size tile_size(400, 400);
657 gfx::Size layer_bounds(1300, 1900); 625 gfx::Size layer_bounds(1300, 1900);
658 626
659 scoped_refptr<FakePicturePileImpl> pending_pile = 627 scoped_refptr<FakePicturePileImpl> pending_pile =
660 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); 628 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds);
661 scoped_refptr<FakePicturePileImpl> active_pile = 629 scoped_refptr<FakePicturePileImpl> active_pile =
662 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); 630 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds);
663 631
664 float result_scale_x, result_scale_y;
665 gfx::Size result_bounds;
666
667 SetupTrees(pending_pile, active_pile); 632 SetupTrees(pending_pile, active_pile);
668 633
669 pending_layer_->CalculateContentsScale(1.f, 634 SetupDrawPropertiesAndManageTilings(
670 1.f, 635 pending_layer_, 1.f, 1.f, 1.f, 1.f, false);
671 1.f,
672 1.f,
673 false,
674 &result_scale_x,
675 &result_scale_y,
676 &result_bounds);
677 636
678 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); 637 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
679 } 638 }
680 639
681 TEST_F(PictureLayerImplTest, ManageTilingsCreatesTilings) { 640 TEST_F(PictureLayerImplTest, ManageTilingsCreatesTilings) {
682 gfx::Size tile_size(400, 400); 641 gfx::Size tile_size(400, 400);
683 gfx::Size layer_bounds(1300, 1900); 642 gfx::Size layer_bounds(1300, 1900);
684 643
685 scoped_refptr<FakePicturePileImpl> pending_pile = 644 scoped_refptr<FakePicturePileImpl> pending_pile =
686 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 645 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
687 scoped_refptr<FakePicturePileImpl> active_pile = 646 scoped_refptr<FakePicturePileImpl> active_pile =
688 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 647 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
689 648
690 float result_scale_x, result_scale_y;
691 gfx::Size result_bounds;
692
693 SetupTrees(pending_pile, active_pile); 649 SetupTrees(pending_pile, active_pile);
694 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); 650 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
695 651
696 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; 652 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
697 EXPECT_LT(low_res_factor, 1.f); 653 EXPECT_LT(low_res_factor, 1.f);
698 654
699 pending_layer_->CalculateContentsScale(6.f, // ideal contents scale 655 SetupDrawPropertiesAndManageTilings(pending_layer_,
700 3.f, // device scale 656 6.f, // ideal contents scale
701 2.f, // page scale 657 3.f, // device scale
702 1.f, // maximum animation scale 658 2.f, // page scale
703 false, 659 1.f, // maximum animation scale
704 &result_scale_x, 660 false);
705 &result_scale_y,
706 &result_bounds);
707 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); 661 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
708 EXPECT_FLOAT_EQ(6.f, 662 EXPECT_FLOAT_EQ(6.f,
709 pending_layer_->tilings()->tiling_at(0)->contents_scale()); 663 pending_layer_->tilings()->tiling_at(0)->contents_scale());
710 EXPECT_FLOAT_EQ(6.f * low_res_factor, 664 EXPECT_FLOAT_EQ(6.f * low_res_factor,
711 pending_layer_->tilings()->tiling_at(1)->contents_scale()); 665 pending_layer_->tilings()->tiling_at(1)->contents_scale());
712 666
713 // If we change the page scale factor, then we should get new tilings. 667 // If we change the page scale factor, then we should get new tilings.
714 pending_layer_->CalculateContentsScale(6.6f, // ideal contents scale 668 SetupDrawPropertiesAndManageTilings(pending_layer_,
715 3.f, // device scale 669 6.6f, // ideal contents scale
716 2.2f, // page scale 670 3.f, // device scale
717 1.f, // maximum animation scale 671 2.2f, // page scale
718 false, 672 1.f, // maximum animation scale
719 &result_scale_x, 673 false);
720 &result_scale_y,
721 &result_bounds);
722 ASSERT_EQ(4u, pending_layer_->tilings()->num_tilings()); 674 ASSERT_EQ(4u, pending_layer_->tilings()->num_tilings());
723 EXPECT_FLOAT_EQ(6.6f, 675 EXPECT_FLOAT_EQ(6.6f,
724 pending_layer_->tilings()->tiling_at(0)->contents_scale()); 676 pending_layer_->tilings()->tiling_at(0)->contents_scale());
725 EXPECT_FLOAT_EQ(6.6f * low_res_factor, 677 EXPECT_FLOAT_EQ(6.6f * low_res_factor,
726 pending_layer_->tilings()->tiling_at(2)->contents_scale()); 678 pending_layer_->tilings()->tiling_at(2)->contents_scale());
727 679
728 // If we change the device scale factor, then we should get new tilings. 680 // If we change the device scale factor, then we should get new tilings.
729 pending_layer_->CalculateContentsScale(7.26f, // ideal contents scale 681 SetupDrawPropertiesAndManageTilings(pending_layer_,
730 3.3f, // device scale 682 7.26f, // ideal contents scale
731 2.2f, // page scale 683 3.3f, // device scale
732 1.f, // maximum animation scale 684 2.2f, // page scale
733 false, 685 1.f, // maximum animation scale
734 &result_scale_x, 686 false);
735 &result_scale_y,
736 &result_bounds);
737 ASSERT_EQ(6u, pending_layer_->tilings()->num_tilings()); 687 ASSERT_EQ(6u, pending_layer_->tilings()->num_tilings());
738 EXPECT_FLOAT_EQ(7.26f, 688 EXPECT_FLOAT_EQ(7.26f,
739 pending_layer_->tilings()->tiling_at(0)->contents_scale()); 689 pending_layer_->tilings()->tiling_at(0)->contents_scale());
740 EXPECT_FLOAT_EQ(7.26f * low_res_factor, 690 EXPECT_FLOAT_EQ(7.26f * low_res_factor,
741 pending_layer_->tilings()->tiling_at(3)->contents_scale()); 691 pending_layer_->tilings()->tiling_at(3)->contents_scale());
742 692
743 // If we change the device scale factor, but end up at the same total scale 693 // If we change the device scale factor, but end up at the same total scale
744 // factor somehow, then we don't get new tilings. 694 // factor somehow, then we don't get new tilings.
745 pending_layer_->CalculateContentsScale(7.26f, // ideal contents scale 695 SetupDrawPropertiesAndManageTilings(pending_layer_,
746 2.2f, // device scale 696 7.26f, // ideal contents scale
747 3.3f, // page scale 697 2.2f, // device scale
748 1.f, // maximum animation scale 698 3.3f, // page scale
749 false, 699 1.f, // maximum animation scale
750 &result_scale_x, 700 false);
751 &result_scale_y,
752 &result_bounds);
753 ASSERT_EQ(6u, pending_layer_->tilings()->num_tilings()); 701 ASSERT_EQ(6u, pending_layer_->tilings()->num_tilings());
754 EXPECT_FLOAT_EQ(7.26f, 702 EXPECT_FLOAT_EQ(7.26f,
755 pending_layer_->tilings()->tiling_at(0)->contents_scale()); 703 pending_layer_->tilings()->tiling_at(0)->contents_scale());
756 EXPECT_FLOAT_EQ(7.26f * low_res_factor, 704 EXPECT_FLOAT_EQ(7.26f * low_res_factor,
757 pending_layer_->tilings()->tiling_at(3)->contents_scale()); 705 pending_layer_->tilings()->tiling_at(3)->contents_scale());
758 } 706 }
759 707
760 TEST_F(PictureLayerImplTest, CreateTilingsEvenIfTwinHasNone) { 708 TEST_F(PictureLayerImplTest, CreateTilingsEvenIfTwinHasNone) {
761 // This test makes sure that if a layer can have tilings, then a commit makes 709 // This test makes sure that if a layer can have tilings, then a commit makes
762 // it not able to have tilings (empty size), and then a future commit that 710 // it not able to have tilings (empty size), and then a future commit that
763 // makes it valid again should be able to create tilings. 711 // makes it valid again should be able to create tilings.
764 gfx::Size tile_size(400, 400); 712 gfx::Size tile_size(400, 400);
765 gfx::Size layer_bounds(1300, 1900); 713 gfx::Size layer_bounds(1300, 1900);
766 714
767 scoped_refptr<FakePicturePileImpl> empty_pile = 715 scoped_refptr<FakePicturePileImpl> empty_pile =
768 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); 716 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds);
769 scoped_refptr<FakePicturePileImpl> valid_pile = 717 scoped_refptr<FakePicturePileImpl> valid_pile =
770 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 718 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
771 719
772 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; 720 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
773 EXPECT_LT(low_res_factor, 1.f); 721 EXPECT_LT(low_res_factor, 1.f);
774 722
775 float high_res_scale = 1.3f; 723 float high_res_scale = 1.3f;
776 float low_res_scale = high_res_scale * low_res_factor; 724 float low_res_scale = high_res_scale * low_res_factor;
777 float device_scale = 1.7f; 725 float device_scale = 1.7f;
778 float page_scale = 3.2f; 726 float page_scale = 3.2f;
779 float maximum_animation_scale = 1.f; 727 float maximum_animation_scale = 1.f;
780 float result_scale_x, result_scale_y;
781 gfx::Size result_bounds;
782 728
783 SetupPendingTree(valid_pile); 729 SetupPendingTree(valid_pile);
784 pending_layer_->CalculateContentsScale(high_res_scale, 730 SetupDrawPropertiesAndManageTilings(pending_layer_,
785 device_scale, 731 high_res_scale,
786 page_scale, 732 device_scale,
787 maximum_animation_scale, 733 page_scale,
788 false, 734 maximum_animation_scale,
789 &result_scale_x, 735 false);
790 &result_scale_y,
791 &result_bounds);
792 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); 736 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
793 EXPECT_FLOAT_EQ(high_res_scale, 737 EXPECT_FLOAT_EQ(high_res_scale,
794 pending_layer_->HighResTiling()->contents_scale()); 738 pending_layer_->HighResTiling()->contents_scale());
795 EXPECT_FLOAT_EQ(low_res_scale, 739 EXPECT_FLOAT_EQ(low_res_scale,
796 pending_layer_->LowResTiling()->contents_scale()); 740 pending_layer_->LowResTiling()->contents_scale());
797 741
798 ActivateTree(); 742 ActivateTree();
799 SetupPendingTree(empty_pile); 743 SetupPendingTree(empty_pile);
800 pending_layer_->CalculateContentsScale(high_res_scale, 744 SetupDrawPropertiesAndManageTilings(pending_layer_,
801 device_scale, 745 high_res_scale,
802 page_scale, 746 device_scale,
803 maximum_animation_scale, 747 page_scale,
804 false, 748 maximum_animation_scale,
805 &result_scale_x, 749 false);
806 &result_scale_y,
807 &result_bounds);
808 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); 750 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
809 ASSERT_EQ(0u, pending_layer_->tilings()->num_tilings()); 751 ASSERT_EQ(0u, pending_layer_->tilings()->num_tilings());
810 752
811 ActivateTree(); 753 ActivateTree();
812 active_layer_->CalculateContentsScale(high_res_scale, 754 SetupDrawPropertiesAndManageTilings(active_layer_,
813 device_scale, 755 high_res_scale,
814 page_scale, 756 device_scale,
815 maximum_animation_scale, 757 page_scale,
816 false, 758 maximum_animation_scale,
817 &result_scale_x, 759 false);
818 &result_scale_y,
819 &result_bounds);
820 ASSERT_EQ(0u, active_layer_->tilings()->num_tilings()); 760 ASSERT_EQ(0u, active_layer_->tilings()->num_tilings());
821 761
822 SetupPendingTree(valid_pile); 762 SetupPendingTree(valid_pile);
823 pending_layer_->CalculateContentsScale(high_res_scale, 763 SetupDrawPropertiesAndManageTilings(pending_layer_,
824 device_scale, 764 high_res_scale,
825 page_scale, 765 device_scale,
826 maximum_animation_scale, 766 page_scale,
827 false, 767 maximum_animation_scale,
828 &result_scale_x, 768 false);
829 &result_scale_y,
830 &result_bounds);
831 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); 769 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
832 ASSERT_EQ(0u, active_layer_->tilings()->num_tilings()); 770 ASSERT_EQ(0u, active_layer_->tilings()->num_tilings());
833 EXPECT_FLOAT_EQ(high_res_scale, 771 EXPECT_FLOAT_EQ(high_res_scale,
834 pending_layer_->HighResTiling()->contents_scale()); 772 pending_layer_->HighResTiling()->contents_scale());
835 EXPECT_FLOAT_EQ(low_res_scale, 773 EXPECT_FLOAT_EQ(low_res_scale,
836 pending_layer_->LowResTiling()->contents_scale()); 774 pending_layer_->LowResTiling()->contents_scale());
837 } 775 }
838 776
839 TEST_F(PictureLayerImplTest, ZoomOutCrash) { 777 TEST_F(PictureLayerImplTest, ZoomOutCrash) {
840 gfx::Size tile_size(400, 400); 778 gfx::Size tile_size(400, 400);
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
954 892
955 TEST_F(PictureLayerImplTest, CleanUpTilings) { 893 TEST_F(PictureLayerImplTest, CleanUpTilings) {
956 gfx::Size tile_size(400, 400); 894 gfx::Size tile_size(400, 400);
957 gfx::Size layer_bounds(1300, 1900); 895 gfx::Size layer_bounds(1300, 1900);
958 896
959 scoped_refptr<FakePicturePileImpl> pending_pile = 897 scoped_refptr<FakePicturePileImpl> pending_pile =
960 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 898 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
961 scoped_refptr<FakePicturePileImpl> active_pile = 899 scoped_refptr<FakePicturePileImpl> active_pile =
962 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 900 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
963 901
964 float result_scale_x, result_scale_y;
965 gfx::Size result_bounds;
966 std::vector<PictureLayerTiling*> used_tilings; 902 std::vector<PictureLayerTiling*> used_tilings;
967 903
968 SetupTrees(pending_pile, active_pile); 904 SetupTrees(pending_pile, active_pile);
969 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); 905 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
970 906
971 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; 907 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
972 EXPECT_LT(low_res_factor, 1.f); 908 EXPECT_LT(low_res_factor, 1.f);
973 909
974 float device_scale = 1.7f; 910 float device_scale = 1.7f;
975 float page_scale = 3.2f; 911 float page_scale = 3.2f;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 // Now move the ideal scale to 1.0. Our target stays 1.2. 965 // Now move the ideal scale to 1.0. Our target stays 1.2.
1030 SetContentsScaleOnBothLayers(1.f, device_scale, page_scale, 1.f, false); 966 SetContentsScaleOnBothLayers(1.f, device_scale, page_scale, 1.f, false);
1031 967
1032 // All the tilings are between are target and the ideal, so they are not 968 // All the tilings are between are target and the ideal, so they are not
1033 // removed. 969 // removed.
1034 used_tilings.clear(); 970 used_tilings.clear();
1035 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); 971 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
1036 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings()); 972 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings());
1037 973
1038 // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2. 974 // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2.
1039 active_layer_->CalculateContentsScale(1.1f, 975 SetupDrawPropertiesAndManageTilings(
1040 device_scale, 976 active_layer_, 1.1f, device_scale, page_scale, 1.f, false);
1041 page_scale,
1042 1.f,
1043 false,
1044 &result_scale_x,
1045 &result_scale_y,
1046 &result_bounds);
1047 977
1048 // Because the pending layer's ideal scale is still 1.0, our tilings fall 978 // Because the pending layer's ideal scale is still 1.0, our tilings fall
1049 // in the range [1.0,1.2] and are kept. 979 // in the range [1.0,1.2] and are kept.
1050 used_tilings.clear(); 980 used_tilings.clear();
1051 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); 981 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
1052 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings()); 982 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings());
1053 983
1054 // Move the ideal scale on the pending layer to 1.1 as well. Our target stays 984 // Move the ideal scale on the pending layer to 1.1 as well. Our target stays
1055 // 1.2 still. 985 // 1.2 still.
1056 pending_layer_->CalculateContentsScale(1.1f, 986 SetupDrawPropertiesAndManageTilings(
1057 device_scale, 987 pending_layer_, 1.1f, device_scale, page_scale, 1.f, false);
1058 page_scale,
1059 1.f,
1060 false,
1061 &result_scale_x,
1062 &result_scale_y,
1063 &result_bounds);
1064 988
1065 // Our 1.0 tiling now falls outside the range between our ideal scale and our 989 // Our 1.0 tiling now falls outside the range between our ideal scale and our
1066 // target raster scale. But it is in our used tilings set, so nothing is 990 // target raster scale. But it is in our used tilings set, so nothing is
1067 // deleted. 991 // deleted.
1068 used_tilings.clear(); 992 used_tilings.clear();
1069 used_tilings.push_back(active_layer_->tilings()->tiling_at(1)); 993 used_tilings.push_back(active_layer_->tilings()->tiling_at(1));
1070 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); 994 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
1071 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings()); 995 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings());
1072 996
1073 // If we remove it from our used tilings set, it is outside the range to keep 997 // 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
1207 1131
1208 TEST_F(PictureLayerImplTest, ReleaseResources) { 1132 TEST_F(PictureLayerImplTest, ReleaseResources) {
1209 gfx::Size tile_size(400, 400); 1133 gfx::Size tile_size(400, 400);
1210 gfx::Size layer_bounds(1300, 1900); 1134 gfx::Size layer_bounds(1300, 1900);
1211 1135
1212 scoped_refptr<FakePicturePileImpl> pending_pile = 1136 scoped_refptr<FakePicturePileImpl> pending_pile =
1213 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 1137 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1214 scoped_refptr<FakePicturePileImpl> active_pile = 1138 scoped_refptr<FakePicturePileImpl> active_pile =
1215 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 1139 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1216 1140
1217 float result_scale_x, result_scale_y;
1218 gfx::Size result_bounds;
1219
1220 SetupTrees(pending_pile, active_pile); 1141 SetupTrees(pending_pile, active_pile);
1221 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); 1142 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
1222 1143
1223 pending_layer_->CalculateContentsScale(1.3f, // ideal contents scale 1144 SetupDrawPropertiesAndManageTilings(pending_layer_,
1224 2.7f, // device scale 1145 1.3f, // ideal contents scale
1225 3.2f, // page scale 1146 2.7f, // device scale
1226 1.f, // maximum animation scale 1147 3.2f, // page scale
1227 false, 1148 1.f, // maximum animation scale
1228 &result_scale_x, 1149 false);
1229 &result_scale_y,
1230 &result_bounds);
1231 EXPECT_EQ(2u, pending_layer_->tilings()->num_tilings()); 1150 EXPECT_EQ(2u, pending_layer_->tilings()->num_tilings());
1232 1151
1233 // All tilings should be removed when losing output surface. 1152 // All tilings should be removed when losing output surface.
1234 active_layer_->ReleaseResources(); 1153 active_layer_->ReleaseResources();
1235 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings()); 1154 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
1236 pending_layer_->ReleaseResources(); 1155 pending_layer_->ReleaseResources();
1237 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); 1156 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
1238 1157
1239 // This should create new tilings. 1158 // This should create new tilings.
1240 pending_layer_->CalculateContentsScale(1.3f, // ideal contents scale 1159 SetupDrawPropertiesAndManageTilings(pending_layer_,
1241 2.7f, // device scale 1160 1.3f, // ideal contents scale
1242 3.2f, // page scale 1161 2.7f, // device scale
1243 1.f, // maximum animation scale 1162 3.2f, // page scale
1244 false, 1163 1.f, // maximum animation scale
1245 &result_scale_x, 1164 false);
1246 &result_scale_y,
1247 &result_bounds);
1248 EXPECT_EQ(2u, pending_layer_->tilings()->num_tilings()); 1165 EXPECT_EQ(2u, pending_layer_->tilings()->num_tilings());
1249 } 1166 }
1250 1167
1251 TEST_F(PictureLayerImplTest, ClampTilesToToMaxTileSize) { 1168 TEST_F(PictureLayerImplTest, ClampTilesToToMaxTileSize) {
1252 // The default max tile size is larger than 400x400. 1169 // The default max tile size is larger than 400x400.
1253 gfx::Size tile_size(400, 400); 1170 gfx::Size tile_size(400, 400);
1254 gfx::Size layer_bounds(5000, 5000); 1171 gfx::Size layer_bounds(5000, 5000);
1255 1172
1256 scoped_refptr<FakePicturePileImpl> pending_pile = 1173 scoped_refptr<FakePicturePileImpl> pending_pile =
1257 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 1174 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1258 scoped_refptr<FakePicturePileImpl> active_pile = 1175 scoped_refptr<FakePicturePileImpl> active_pile =
1259 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 1176 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1260 1177
1261 float result_scale_x, result_scale_y;
1262 gfx::Size result_bounds;
1263
1264 SetupTrees(pending_pile, active_pile); 1178 SetupTrees(pending_pile, active_pile);
1265 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); 1179 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
1266 1180
1267 pending_layer_->CalculateContentsScale(1.f, 1181 SetupDrawPropertiesAndManageTilings(
1268 1.f, 1182 pending_layer_, 1.f, 1.f, 1.f, 1.f, false);
1269 1.f,
1270 1.f,
1271 false,
1272 &result_scale_x,
1273 &result_scale_y,
1274 &result_bounds);
1275 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); 1183 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
1276 1184
1277 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting(); 1185 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1278 1186
1279 // The default value. 1187 // The default value.
1280 EXPECT_EQ(gfx::Size(256, 256).ToString(), 1188 EXPECT_EQ(gfx::Size(256, 256).ToString(),
1281 host_impl_.settings().default_tile_size.ToString()); 1189 host_impl_.settings().default_tile_size.ToString());
1282 1190
1283 Tile* tile = pending_layer_->tilings()->tiling_at(0)->AllTilesForTesting()[0]; 1191 Tile* tile = pending_layer_->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1284 EXPECT_EQ(gfx::Size(256, 256).ToString(), 1192 EXPECT_EQ(gfx::Size(256, 256).ToString(),
1285 tile->content_rect().size().ToString()); 1193 tile->content_rect().size().ToString());
1286 1194
1287 pending_layer_->ReleaseResources(); 1195 pending_layer_->ReleaseResources();
1288 1196
1289 // Change the max texture size on the output surface context. 1197 // Change the max texture size on the output surface context.
1290 scoped_ptr<TestWebGraphicsContext3D> context = 1198 scoped_ptr<TestWebGraphicsContext3D> context =
1291 TestWebGraphicsContext3D::Create(); 1199 TestWebGraphicsContext3D::Create();
1292 context->set_max_texture_size(140); 1200 context->set_max_texture_size(140);
1293 host_impl_.DidLoseOutputSurface(); 1201 host_impl_.DidLoseOutputSurface();
1294 host_impl_.InitializeRenderer(FakeOutputSurface::Create3d( 1202 host_impl_.InitializeRenderer(FakeOutputSurface::Create3d(
1295 context.Pass()).PassAs<OutputSurface>()); 1203 context.Pass()).PassAs<OutputSurface>());
1296 1204
1297 pending_layer_->CalculateContentsScale(1.f, 1205 SetupDrawPropertiesAndManageTilings(
1298 1.f, 1206 pending_layer_, 1.f, 1.f, 1.f, 1.f, false);
1299 1.f,
1300 1.f,
1301 false,
1302 &result_scale_x,
1303 &result_scale_y,
1304 &result_bounds);
1305 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); 1207 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
1306 1208
1307 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting(); 1209 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1308 1210
1309 // Verify the tiles are not larger than the context's max texture size. 1211 // Verify the tiles are not larger than the context's max texture size.
1310 tile = pending_layer_->tilings()->tiling_at(0)->AllTilesForTesting()[0]; 1212 tile = pending_layer_->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1311 EXPECT_GE(140, tile->content_rect().width()); 1213 EXPECT_GE(140, tile->content_rect().width());
1312 EXPECT_GE(140, tile->content_rect().height()); 1214 EXPECT_GE(140, tile->content_rect().height());
1313 } 1215 }
1314 1216
1315 TEST_F(PictureLayerImplTest, ClampSingleTileToToMaxTileSize) { 1217 TEST_F(PictureLayerImplTest, ClampSingleTileToToMaxTileSize) {
1316 // The default max tile size is larger than 400x400. 1218 // The default max tile size is larger than 400x400.
1317 gfx::Size tile_size(400, 400); 1219 gfx::Size tile_size(400, 400);
1318 gfx::Size layer_bounds(500, 500); 1220 gfx::Size layer_bounds(500, 500);
1319 1221
1320 scoped_refptr<FakePicturePileImpl> pending_pile = 1222 scoped_refptr<FakePicturePileImpl> pending_pile =
1321 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 1223 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1322 scoped_refptr<FakePicturePileImpl> active_pile = 1224 scoped_refptr<FakePicturePileImpl> active_pile =
1323 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 1225 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1324 1226
1325 float result_scale_x, result_scale_y;
1326 gfx::Size result_bounds;
1327
1328 SetupTrees(pending_pile, active_pile); 1227 SetupTrees(pending_pile, active_pile);
1329 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); 1228 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
1330 1229
1331 pending_layer_->CalculateContentsScale(1.f, 1230 SetupDrawPropertiesAndManageTilings(
1332 1.f, 1231 pending_layer_, 1.f, 1.f, 1.f, 1.f, false);
1333 1.f,
1334 1.f,
1335 false,
1336 &result_scale_x,
1337 &result_scale_y,
1338 &result_bounds);
1339 ASSERT_LE(1u, pending_layer_->tilings()->num_tilings()); 1232 ASSERT_LE(1u, pending_layer_->tilings()->num_tilings());
1340 1233
1341 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting(); 1234 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1342 1235
1343 // The default value. The layer is smaller than this. 1236 // The default value. The layer is smaller than this.
1344 EXPECT_EQ(gfx::Size(512, 512).ToString(), 1237 EXPECT_EQ(gfx::Size(512, 512).ToString(),
1345 host_impl_.settings().max_untiled_layer_size.ToString()); 1238 host_impl_.settings().max_untiled_layer_size.ToString());
1346 1239
1347 // There should be a single tile since the layer is small. 1240 // There should be a single tile since the layer is small.
1348 PictureLayerTiling* high_res_tiling = pending_layer_->tilings()->tiling_at(0); 1241 PictureLayerTiling* high_res_tiling = pending_layer_->tilings()->tiling_at(0);
1349 EXPECT_EQ(1u, high_res_tiling->AllTilesForTesting().size()); 1242 EXPECT_EQ(1u, high_res_tiling->AllTilesForTesting().size());
1350 1243
1351 pending_layer_->ReleaseResources(); 1244 pending_layer_->ReleaseResources();
1352 1245
1353 // Change the max texture size on the output surface context. 1246 // Change the max texture size on the output surface context.
1354 scoped_ptr<TestWebGraphicsContext3D> context = 1247 scoped_ptr<TestWebGraphicsContext3D> context =
1355 TestWebGraphicsContext3D::Create(); 1248 TestWebGraphicsContext3D::Create();
1356 context->set_max_texture_size(140); 1249 context->set_max_texture_size(140);
1357 host_impl_.DidLoseOutputSurface(); 1250 host_impl_.DidLoseOutputSurface();
1358 host_impl_.InitializeRenderer(FakeOutputSurface::Create3d( 1251 host_impl_.InitializeRenderer(FakeOutputSurface::Create3d(
1359 context.Pass()).PassAs<OutputSurface>()); 1252 context.Pass()).PassAs<OutputSurface>());
1360 1253
1361 pending_layer_->CalculateContentsScale(1.f, 1254 SetupDrawPropertiesAndManageTilings(
1362 1.f, 1255 pending_layer_, 1.f, 1.f, 1.f, 1.f, false);
1363 1.f,
1364 1.f,
1365 false,
1366 &result_scale_x,
1367 &result_scale_y,
1368 &result_bounds);
1369 ASSERT_LE(1u, pending_layer_->tilings()->num_tilings()); 1256 ASSERT_LE(1u, pending_layer_->tilings()->num_tilings());
1370 1257
1371 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting(); 1258 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1372 1259
1373 // There should be more than one tile since the max texture size won't cover 1260 // There should be more than one tile since the max texture size won't cover
1374 // the layer. 1261 // the layer.
1375 high_res_tiling = pending_layer_->tilings()->tiling_at(0); 1262 high_res_tiling = pending_layer_->tilings()->tiling_at(0);
1376 EXPECT_LT(1u, high_res_tiling->AllTilesForTesting().size()); 1263 EXPECT_LT(1u, high_res_tiling->AllTilesForTesting().size());
1377 1264
1378 // Verify the tiles are not larger than the context's max texture size. 1265 // Verify the tiles are not larger than the context's max texture size.
1379 Tile* tile = pending_layer_->tilings()->tiling_at(0)->AllTilesForTesting()[0]; 1266 Tile* tile = pending_layer_->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1380 EXPECT_GE(140, tile->content_rect().width()); 1267 EXPECT_GE(140, tile->content_rect().width());
1381 EXPECT_GE(140, tile->content_rect().height()); 1268 EXPECT_GE(140, tile->content_rect().height());
1382 } 1269 }
1383 1270
1384 TEST_F(PictureLayerImplTest, DisallowTileDrawQuads) { 1271 TEST_F(PictureLayerImplTest, DisallowTileDrawQuads) {
1385 MockQuadCuller quad_culler; 1272 MockQuadCuller quad_culler;
1386 1273
1387 gfx::Size tile_size(400, 400); 1274 gfx::Size tile_size(400, 400);
1388 gfx::Size layer_bounds(1300, 1900); 1275 gfx::Size layer_bounds(1300, 1900);
1389 1276
1390 scoped_refptr<FakePicturePileImpl> pending_pile = 1277 scoped_refptr<FakePicturePileImpl> pending_pile =
1391 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 1278 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1392 scoped_refptr<FakePicturePileImpl> active_pile = 1279 scoped_refptr<FakePicturePileImpl> active_pile =
1393 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 1280 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1394 1281
1395 SetupTrees(pending_pile, active_pile); 1282 SetupTrees(pending_pile, active_pile);
1396 1283
1397 active_layer_->SetContentBounds(layer_bounds);
1398 active_layer_->draw_properties().visible_content_rect = 1284 active_layer_->draw_properties().visible_content_rect =
1399 gfx::Rect(layer_bounds); 1285 gfx::Rect(layer_bounds);
1400 1286
1401 gfx::Rect layer_invalidation(150, 200, 30, 180); 1287 gfx::Rect layer_invalidation(150, 200, 30, 180);
1402 Region invalidation(layer_invalidation); 1288 Region invalidation(layer_invalidation);
1403 AddDefaultTilingsWithInvalidation(invalidation); 1289 AddDefaultTilingsWithInvalidation(invalidation);
1404 1290
1405 AppendQuadsData data; 1291 AppendQuadsData data;
1406 active_layer_->WillDraw(DRAW_MODE_RESOURCELESS_SOFTWARE, NULL); 1292 active_layer_->WillDraw(DRAW_MODE_RESOURCELESS_SOFTWARE, NULL);
1407 active_layer_->AppendQuads(&quad_culler, &data); 1293 active_layer_->AppendQuads(&quad_culler, &data);
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
1752 host_impl_.SetUseGpuRasterization(false); 1638 host_impl_.SetUseGpuRasterization(false);
1753 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); 1639 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
1754 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings()); 1640 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
1755 } 1641 }
1756 1642
1757 TEST_F(PictureLayerImplTest, HighResCreatedWhenBoundsShrink) { 1643 TEST_F(PictureLayerImplTest, HighResCreatedWhenBoundsShrink) {
1758 SetupDefaultTrees(gfx::Size(10, 10)); 1644 SetupDefaultTrees(gfx::Size(10, 10));
1759 host_impl_.active_tree()->UpdateDrawProperties(); 1645 host_impl_.active_tree()->UpdateDrawProperties();
1760 EXPECT_FALSE(host_impl_.active_tree()->needs_update_draw_properties()); 1646 EXPECT_FALSE(host_impl_.active_tree()->needs_update_draw_properties());
1761 1647
1762 float result_scale_x; 1648 SetupDrawPropertiesAndManageTilings(
1763 float result_scale_y; 1649 active_layer_, 0.5f, 0.5f, 0.5f, 0.5f, false);
1764 gfx::Size result_bounds;
1765 active_layer_->CalculateContentsScale(0.5f,
1766 0.5f,
1767 0.5f,
1768 0.5f,
1769 false,
1770 &result_scale_x,
1771 &result_scale_y,
1772 &result_bounds);
1773 active_layer_->tilings()->RemoveAllTilings(); 1650 active_layer_->tilings()->RemoveAllTilings();
1774 PictureLayerTiling* tiling = active_layer_->tilings()->AddTiling(0.5f); 1651 PictureLayerTiling* tiling = active_layer_->tilings()->AddTiling(0.5f);
1775 active_layer_->tilings()->AddTiling(1.5f); 1652 active_layer_->tilings()->AddTiling(1.5f);
1776 active_layer_->tilings()->AddTiling(0.25f); 1653 active_layer_->tilings()->AddTiling(0.25f);
1777 tiling->set_resolution(HIGH_RESOLUTION); 1654 tiling->set_resolution(HIGH_RESOLUTION);
1778 1655
1779 // Sanity checks. 1656 // Sanity checks.
1780 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings()); 1657 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings());
1781 ASSERT_EQ(tiling, active_layer_->tilings()->TilingAtScale(0.5f)); 1658 ASSERT_EQ(tiling, active_layer_->tilings()->TilingAtScale(0.5f));
1782 1659
(...skipping 22 matching lines...) Expand all
1805 pending_layer_->tilings()->TilingAtScale(1.0f)->resolution()); 1682 pending_layer_->tilings()->TilingAtScale(1.0f)->resolution());
1806 ASSERT_TRUE(pending_layer_->tilings()->TilingAtScale(1.5f)); 1683 ASSERT_TRUE(pending_layer_->tilings()->TilingAtScale(1.5f));
1807 EXPECT_EQ(NON_IDEAL_RESOLUTION, 1684 EXPECT_EQ(NON_IDEAL_RESOLUTION,
1808 pending_layer_->tilings()->TilingAtScale(1.5f)->resolution()); 1685 pending_layer_->tilings()->TilingAtScale(1.5f)->resolution());
1809 } 1686 }
1810 1687
1811 TEST_F(PictureLayerImplTest, NoLowResTilingWithGpuRasterization) { 1688 TEST_F(PictureLayerImplTest, NoLowResTilingWithGpuRasterization) {
1812 gfx::Size default_tile_size(host_impl_.settings().default_tile_size); 1689 gfx::Size default_tile_size(host_impl_.settings().default_tile_size);
1813 gfx::Size layer_bounds(default_tile_size.width() * 4, 1690 gfx::Size layer_bounds(default_tile_size.width() * 4,
1814 default_tile_size.height() * 4); 1691 default_tile_size.height() * 4);
1815 float result_scale_x, result_scale_y;
1816 gfx::Size result_bounds;
1817 1692
1818 SetupDefaultTrees(layer_bounds); 1693 SetupDefaultTrees(layer_bounds);
1819 EXPECT_FALSE(host_impl_.use_gpu_rasterization()); 1694 EXPECT_FALSE(host_impl_.use_gpu_rasterization());
1820 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); 1695 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
1821 pending_layer_->CalculateContentsScale(1.f, 1696 SetupDrawPropertiesAndManageTilings(
1822 1.f, 1697 pending_layer_, 1.f, 1.f, 1.f, 1.f, false);
1823 1.f,
1824 1.f,
1825 false,
1826 &result_scale_x,
1827 &result_scale_y,
1828 &result_bounds);
1829 // Should have a low-res and a high-res tiling. 1698 // Should have a low-res and a high-res tiling.
1830 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); 1699 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
1831 1700
1832 ResetTilingsAndRasterScales(); 1701 ResetTilingsAndRasterScales();
1833 1702
1834 host_impl_.SetUseGpuRasterization(true); 1703 host_impl_.SetUseGpuRasterization(true);
1835 EXPECT_TRUE(host_impl_.use_gpu_rasterization()); 1704 EXPECT_TRUE(host_impl_.use_gpu_rasterization());
1836 pending_layer_->CalculateContentsScale(1.f, 1705 SetupDrawPropertiesAndManageTilings(
1837 1.f, 1706 pending_layer_, 1.f, 1.f, 1.f, 1.f, false);
1838 1.f, 1707
1839 1.f,
1840 false,
1841 &result_scale_x,
1842 &result_scale_y,
1843 &result_bounds);
1844 // Should only have the high-res tiling. 1708 // Should only have the high-res tiling.
1845 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings()); 1709 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
1846 } 1710 }
1847 1711
1848 TEST_F(PictureLayerImplTest, NoTilingIfDoesNotDrawContent) { 1712 TEST_F(PictureLayerImplTest, NoTilingIfDoesNotDrawContent) {
1849 // Set up layers with tilings. 1713 // Set up layers with tilings.
1850 SetupDefaultTrees(gfx::Size(10, 10)); 1714 SetupDefaultTrees(gfx::Size(10, 10));
1851 SetContentsScaleOnBothLayers(1.f, 1.f, 1.f, 1.f, false); 1715 SetContentsScaleOnBothLayers(1.f, 1.f, 1.f, 1.f, false);
1852 pending_layer_->PushPropertiesTo(active_layer_); 1716 pending_layer_->PushPropertiesTo(active_layer_);
1853 EXPECT_TRUE(pending_layer_->DrawsContent()); 1717 EXPECT_TRUE(pending_layer_->DrawsContent());
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
2459 2323
2460 TEST_F(NoLowResPictureLayerImplTest, ManageTilingsCreatesTilings) { 2324 TEST_F(NoLowResPictureLayerImplTest, ManageTilingsCreatesTilings) {
2461 gfx::Size tile_size(400, 400); 2325 gfx::Size tile_size(400, 400);
2462 gfx::Size layer_bounds(1300, 1900); 2326 gfx::Size layer_bounds(1300, 1900);
2463 2327
2464 scoped_refptr<FakePicturePileImpl> pending_pile = 2328 scoped_refptr<FakePicturePileImpl> pending_pile =
2465 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 2329 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2466 scoped_refptr<FakePicturePileImpl> active_pile = 2330 scoped_refptr<FakePicturePileImpl> active_pile =
2467 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 2331 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2468 2332
2469 float result_scale_x, result_scale_y;
2470 gfx::Size result_bounds;
2471
2472 SetupTrees(pending_pile, active_pile); 2333 SetupTrees(pending_pile, active_pile);
2473 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); 2334 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
2474 2335
2475 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; 2336 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
2476 EXPECT_LT(low_res_factor, 1.f); 2337 EXPECT_LT(low_res_factor, 1.f);
2477 2338
2478 pending_layer_->CalculateContentsScale(6.f, // ideal contents scale 2339 SetupDrawPropertiesAndManageTilings(pending_layer_,
2479 3.f, // device scale 2340 6.f, // ideal contents scale
2480 2.f, // page scale 2341 3.f, // device scale
2481 1.f, // maximum animation scale 2342 2.f, // page scale
2482 false, 2343 1.f, // maximum animation scale
2483 &result_scale_x, 2344 false);
2484 &result_scale_y,
2485 &result_bounds);
2486 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings()); 2345 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
2487 EXPECT_FLOAT_EQ(6.f, 2346 EXPECT_FLOAT_EQ(6.f,
2488 pending_layer_->tilings()->tiling_at(0)->contents_scale()); 2347 pending_layer_->tilings()->tiling_at(0)->contents_scale());
2489 2348
2490 // If we change the page scale factor, then we should get new tilings. 2349 // If we change the page scale factor, then we should get new tilings.
2491 pending_layer_->CalculateContentsScale(6.6f, // ideal contents scale 2350 SetupDrawPropertiesAndManageTilings(pending_layer_,
2492 3.f, // device scale 2351 6.6f, // ideal contents scale
2493 2.2f, // page scale 2352 3.f, // device scale
2494 1.f, // maximum animation scale 2353 2.2f, // page scale
2495 false, 2354 1.f, // maximum animation scale
2496 &result_scale_x, 2355 false);
2497 &result_scale_y,
2498 &result_bounds);
2499 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); 2356 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
2500 EXPECT_FLOAT_EQ(6.6f, 2357 EXPECT_FLOAT_EQ(6.6f,
2501 pending_layer_->tilings()->tiling_at(0)->contents_scale()); 2358 pending_layer_->tilings()->tiling_at(0)->contents_scale());
2502 2359
2503 // If we change the device scale factor, then we should get new tilings. 2360 // If we change the device scale factor, then we should get new tilings.
2504 pending_layer_->CalculateContentsScale(7.26f, // ideal contents scale 2361 SetupDrawPropertiesAndManageTilings(pending_layer_,
2505 3.3f, // device scale 2362 7.26f, // ideal contents scale
2506 2.2f, // page scale 2363 3.3f, // device scale
2507 1.f, // maximum animation scale 2364 2.2f, // page scale
2508 false, 2365 1.f, // maximum animation scale
2509 &result_scale_x, 2366 false);
2510 &result_scale_y,
2511 &result_bounds);
2512 ASSERT_EQ(3u, pending_layer_->tilings()->num_tilings()); 2367 ASSERT_EQ(3u, pending_layer_->tilings()->num_tilings());
2513 EXPECT_FLOAT_EQ(7.26f, 2368 EXPECT_FLOAT_EQ(7.26f,
2514 pending_layer_->tilings()->tiling_at(0)->contents_scale()); 2369 pending_layer_->tilings()->tiling_at(0)->contents_scale());
2515 2370
2516 // If we change the device scale factor, but end up at the same total scale 2371 // If we change the device scale factor, but end up at the same total scale
2517 // factor somehow, then we don't get new tilings. 2372 // factor somehow, then we don't get new tilings.
2518 pending_layer_->CalculateContentsScale(7.26f, // ideal contents scale 2373 SetupDrawPropertiesAndManageTilings(pending_layer_,
2519 2.2f, // device scale 2374 7.26f, // ideal contents scale
2520 3.3f, // page scale 2375 2.2f, // device scale
2521 1.f, // maximum animation scale 2376 3.3f, // page scale
2522 false, 2377 1.f, // maximum animation scale
2523 &result_scale_x, 2378 false);
2524 &result_scale_y,
2525 &result_bounds);
2526 ASSERT_EQ(3u, pending_layer_->tilings()->num_tilings()); 2379 ASSERT_EQ(3u, pending_layer_->tilings()->num_tilings());
2527 EXPECT_FLOAT_EQ(7.26f, 2380 EXPECT_FLOAT_EQ(7.26f,
2528 pending_layer_->tilings()->tiling_at(0)->contents_scale()); 2381 pending_layer_->tilings()->tiling_at(0)->contents_scale());
2529 } 2382 }
2530 2383
2531 TEST_F(NoLowResPictureLayerImplTest, MarkRequiredNullTiles) { 2384 TEST_F(NoLowResPictureLayerImplTest, MarkRequiredNullTiles) {
2532 gfx::Size tile_size(100, 100); 2385 gfx::Size tile_size(100, 100);
2533 gfx::Size layer_bounds(1000, 1000); 2386 gfx::Size layer_bounds(1000, 1000);
2534 2387
2535 scoped_refptr<FakePicturePileImpl> pending_pile = 2388 scoped_refptr<FakePicturePileImpl> pending_pile =
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
2610 scoped_refptr<FakePicturePileImpl> active_pile = 2463 scoped_refptr<FakePicturePileImpl> active_pile =
2611 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 2464 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2612 2465
2613 SetupTrees(pending_pile, active_pile); 2466 SetupTrees(pending_pile, active_pile);
2614 2467
2615 std::vector<TileManager::PairedPictureLayer> paired_layers; 2468 std::vector<TileManager::PairedPictureLayer> paired_layers;
2616 host_impl_.tile_manager()->GetPairedPictureLayers(&paired_layers); 2469 host_impl_.tile_manager()->GetPairedPictureLayers(&paired_layers);
2617 EXPECT_EQ(0u, paired_layers.size()); 2470 EXPECT_EQ(0u, paired_layers.size());
2618 2471
2619 // Update tile priorities will force the layer to register itself. 2472 // Update tile priorities will force the layer to register itself.
2620 float dummy_contents_scale_x; 2473 SetupDrawPropertiesAndManageTilings(active_layer_, 1.f, 1.f, 1.f, 1.f, false);
2621 float dummy_contents_scale_y;
2622 gfx::Size dummy_content_bounds;
2623 active_layer_->CalculateContentsScale(1.f,
2624 1.f,
2625 1.f,
2626 1.f,
2627 false,
2628 &dummy_contents_scale_x,
2629 &dummy_contents_scale_y,
2630 &dummy_content_bounds);
2631 active_layer_->UpdateTilePriorities(); 2474 active_layer_->UpdateTilePriorities();
2632 host_impl_.pending_tree()->UpdateDrawProperties(); 2475 host_impl_.pending_tree()->UpdateDrawProperties();
2633 pending_layer_->CalculateContentsScale(1.f, 2476 SetupDrawPropertiesAndManageTilings(
2634 1.f, 2477 pending_layer_, 1.f, 1.f, 1.f, 1.f, false);
2635 1.f,
2636 1.f,
2637 false,
2638 &dummy_contents_scale_x,
2639 &dummy_contents_scale_y,
2640 &dummy_content_bounds);
2641 pending_layer_->UpdateTilePriorities(); 2478 pending_layer_->UpdateTilePriorities();
2642 2479
2643 host_impl_.tile_manager()->GetPairedPictureLayers(&paired_layers); 2480 host_impl_.tile_manager()->GetPairedPictureLayers(&paired_layers);
2644 EXPECT_EQ(1u, paired_layers.size()); 2481 EXPECT_EQ(1u, paired_layers.size());
2645 EXPECT_EQ(active_layer_, paired_layers[0].active_layer); 2482 EXPECT_EQ(active_layer_, paired_layers[0].active_layer);
2646 EXPECT_EQ(pending_layer_, paired_layers[0].pending_layer); 2483 EXPECT_EQ(pending_layer_, paired_layers[0].pending_layer);
2647 2484
2648 // Destroy and recreate tile manager. 2485 // Destroy and recreate tile manager.
2649 host_impl_.DidLoseOutputSurface(); 2486 host_impl_.DidLoseOutputSurface();
2650 scoped_ptr<TestWebGraphicsContext3D> context = 2487 scoped_ptr<TestWebGraphicsContext3D> context =
2651 TestWebGraphicsContext3D::Create(); 2488 TestWebGraphicsContext3D::Create();
2652 host_impl_.InitializeRenderer( 2489 host_impl_.InitializeRenderer(
2653 FakeOutputSurface::Create3d(context.Pass()).PassAs<OutputSurface>()); 2490 FakeOutputSurface::Create3d(context.Pass()).PassAs<OutputSurface>());
2654 2491
2655 host_impl_.tile_manager()->GetPairedPictureLayers(&paired_layers); 2492 host_impl_.tile_manager()->GetPairedPictureLayers(&paired_layers);
2656 EXPECT_EQ(0u, paired_layers.size()); 2493 EXPECT_EQ(0u, paired_layers.size());
2657 2494
2658 active_layer_->CalculateContentsScale(1.f, 2495 SetupDrawPropertiesAndManageTilings(active_layer_, 1.f, 1.f, 1.f, 1.f, false);
2659 1.f,
2660 1.f,
2661 1.f,
2662 false,
2663 &dummy_contents_scale_x,
2664 &dummy_contents_scale_y,
2665 &dummy_content_bounds);
2666 active_layer_->UpdateTilePriorities(); 2496 active_layer_->UpdateTilePriorities();
2667 host_impl_.pending_tree()->UpdateDrawProperties(); 2497 host_impl_.pending_tree()->UpdateDrawProperties();
2668 pending_layer_->CalculateContentsScale(1.f, 2498 SetupDrawPropertiesAndManageTilings(
2669 1.f, 2499 pending_layer_, 1.f, 1.f, 1.f, 1.f, false);
2670 1.f,
2671 1.f,
2672 false,
2673 &dummy_contents_scale_x,
2674 &dummy_contents_scale_y,
2675 &dummy_content_bounds);
2676 pending_layer_->UpdateTilePriorities(); 2500 pending_layer_->UpdateTilePriorities();
2677 2501
2678 host_impl_.tile_manager()->GetPairedPictureLayers(&paired_layers); 2502 host_impl_.tile_manager()->GetPairedPictureLayers(&paired_layers);
2679 EXPECT_EQ(1u, paired_layers.size()); 2503 EXPECT_EQ(1u, paired_layers.size());
2680 EXPECT_EQ(active_layer_, paired_layers[0].active_layer); 2504 EXPECT_EQ(active_layer_, paired_layers[0].active_layer);
2681 EXPECT_EQ(pending_layer_, paired_layers[0].pending_layer); 2505 EXPECT_EQ(pending_layer_, paired_layers[0].pending_layer);
2682 } 2506 }
2683 2507
2684 TEST_F(NoLowResPictureLayerImplTest, InvalidViewportForPrioritizingTiles) { 2508 TEST_F(NoLowResPictureLayerImplTest, InvalidViewportForPrioritizingTiles) {
2685 base::TimeTicks time_ticks; 2509 base::TimeTicks time_ticks;
2686 host_impl_.SetCurrentFrameTimeTicks(time_ticks); 2510 host_impl_.SetCurrentFrameTimeTicks(time_ticks);
2687 2511
2688 gfx::Size tile_size(100, 100); 2512 gfx::Size tile_size(100, 100);
2689 gfx::Size layer_bounds(400, 400); 2513 gfx::Size layer_bounds(400, 400);
2690 2514
2691 scoped_refptr<FakePicturePileImpl> pending_pile = 2515 scoped_refptr<FakePicturePileImpl> pending_pile =
2692 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 2516 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2693 scoped_refptr<FakePicturePileImpl> active_pile = 2517 scoped_refptr<FakePicturePileImpl> active_pile =
2694 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 2518 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2695 2519
2696 SetupTrees(pending_pile, active_pile); 2520 SetupTrees(pending_pile, active_pile);
2697 2521
2698 Region invalidation; 2522 Region invalidation;
2699 AddDefaultTilingsWithInvalidation(invalidation); 2523 AddDefaultTilingsWithInvalidation(invalidation);
2700 float dummy_contents_scale_x; 2524 SetupDrawPropertiesAndManageTilings(active_layer_, 1.f, 1.f, 1.f, 1.f, false);
2701 float dummy_contents_scale_y;
2702 gfx::Size dummy_content_bounds;
2703 active_layer_->CalculateContentsScale(1.f,
2704 1.f,
2705 1.f,
2706 1.f,
2707 false,
2708 &dummy_contents_scale_x,
2709 &dummy_contents_scale_y,
2710 &dummy_content_bounds);
2711 2525
2712 // UpdateTilePriorities with valid viewport. Should update tile viewport. 2526 // UpdateTilePriorities with valid viewport. Should update tile viewport.
2713 bool valid_for_tile_management = true; 2527 bool valid_for_tile_management = true;
2714 gfx::Rect viewport = gfx::Rect(layer_bounds); 2528 gfx::Rect viewport = gfx::Rect(layer_bounds);
2715 gfx::Transform transform; 2529 gfx::Transform transform;
2716 host_impl_.SetExternalDrawConstraints( 2530 host_impl_.SetExternalDrawConstraints(
2717 transform, viewport, viewport, valid_for_tile_management); 2531 transform, viewport, viewport, valid_for_tile_management);
2718 active_layer_->draw_properties().visible_content_rect = viewport; 2532 active_layer_->draw_properties().visible_content_rect = viewport;
2719 active_layer_->draw_properties().screen_space_transform = transform; 2533 active_layer_->draw_properties().screen_space_transform = transform;
2720 active_layer_->UpdateTilePriorities(); 2534 active_layer_->UpdateTilePriorities();
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
2799 2613
2800 TEST_F(NoLowResPictureLayerImplTest, CleanUpTilings) { 2614 TEST_F(NoLowResPictureLayerImplTest, CleanUpTilings) {
2801 gfx::Size tile_size(400, 400); 2615 gfx::Size tile_size(400, 400);
2802 gfx::Size layer_bounds(1300, 1900); 2616 gfx::Size layer_bounds(1300, 1900);
2803 2617
2804 scoped_refptr<FakePicturePileImpl> pending_pile = 2618 scoped_refptr<FakePicturePileImpl> pending_pile =
2805 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 2619 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2806 scoped_refptr<FakePicturePileImpl> active_pile = 2620 scoped_refptr<FakePicturePileImpl> active_pile =
2807 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 2621 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2808 2622
2809 float result_scale_x, result_scale_y;
2810 gfx::Size result_bounds;
2811 std::vector<PictureLayerTiling*> used_tilings; 2623 std::vector<PictureLayerTiling*> used_tilings;
2812 2624
2813 SetupTrees(pending_pile, active_pile); 2625 SetupTrees(pending_pile, active_pile);
2814 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); 2626 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
2815 2627
2816 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; 2628 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
2817 EXPECT_LT(low_res_factor, 1.f); 2629 EXPECT_LT(low_res_factor, 1.f);
2818 2630
2819 float device_scale = 1.7f; 2631 float device_scale = 1.7f;
2820 float page_scale = 3.2f; 2632 float page_scale = 3.2f;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
2869 // Now move the ideal scale to 1.0. Our target stays 1.2. 2681 // Now move the ideal scale to 1.0. Our target stays 1.2.
2870 SetContentsScaleOnBothLayers(1.f, device_scale, page_scale, 1.f, false); 2682 SetContentsScaleOnBothLayers(1.f, device_scale, page_scale, 1.f, false);
2871 2683
2872 // All the tilings are between are target and the ideal, so they are not 2684 // All the tilings are between are target and the ideal, so they are not
2873 // removed. 2685 // removed.
2874 used_tilings.clear(); 2686 used_tilings.clear();
2875 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); 2687 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
2876 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); 2688 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
2877 2689
2878 // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2. 2690 // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2.
2879 active_layer_->CalculateContentsScale(1.1f, 2691 SetupDrawPropertiesAndManageTilings(
2880 device_scale, 2692 active_layer_, 1.1f, device_scale, page_scale, 1.f, false);
2881 page_scale,
2882 1.f,
2883 false,
2884 &result_scale_x,
2885 &result_scale_y,
2886 &result_bounds);
2887 2693
2888 // Because the pending layer's ideal scale is still 1.0, our tilings fall 2694 // Because the pending layer's ideal scale is still 1.0, our tilings fall
2889 // in the range [1.0,1.2] and are kept. 2695 // in the range [1.0,1.2] and are kept.
2890 used_tilings.clear(); 2696 used_tilings.clear();
2891 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); 2697 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
2892 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); 2698 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
2893 2699
2894 // Move the ideal scale on the pending layer to 1.1 as well. Our target stays 2700 // Move the ideal scale on the pending layer to 1.1 as well. Our target stays
2895 // 1.2 still. 2701 // 1.2 still.
2896 pending_layer_->CalculateContentsScale(1.1f, 2702 SetupDrawPropertiesAndManageTilings(
2897 device_scale, 2703 pending_layer_, 1.1f, device_scale, page_scale, 1.f, false);
2898 page_scale,
2899 1.f,
2900 false,
2901 &result_scale_x,
2902 &result_scale_y,
2903 &result_bounds);
2904 2704
2905 // Our 1.0 tiling now falls outside the range between our ideal scale and our 2705 // Our 1.0 tiling now falls outside the range between our ideal scale and our
2906 // target raster scale. But it is in our used tilings set, so nothing is 2706 // target raster scale. But it is in our used tilings set, so nothing is
2907 // deleted. 2707 // deleted.
2908 used_tilings.clear(); 2708 used_tilings.clear();
2909 used_tilings.push_back(active_layer_->tilings()->tiling_at(1)); 2709 used_tilings.push_back(active_layer_->tilings()->tiling_at(1));
2910 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); 2710 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
2911 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); 2711 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
2912 2712
2913 // If we remove it from our used tilings set, it is outside the range to keep 2713 // If we remove it from our used tilings set, it is outside the range to keep
2914 // so it is deleted. 2714 // so it is deleted.
2915 used_tilings.clear(); 2715 used_tilings.clear();
2916 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); 2716 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
2917 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings()); 2717 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings());
2918 } 2718 }
2919 2719
2920 TEST_F(PictureLayerImplTest, ScaleCollision) { 2720 TEST_F(PictureLayerImplTest, ScaleCollision) {
2921 gfx::Size tile_size(400, 400); 2721 gfx::Size tile_size(400, 400);
2922 gfx::Size layer_bounds(1300, 1900); 2722 gfx::Size layer_bounds(1300, 1900);
2923 2723
2924 scoped_refptr<FakePicturePileImpl> pending_pile = 2724 scoped_refptr<FakePicturePileImpl> pending_pile =
2925 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 2725 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2926 scoped_refptr<FakePicturePileImpl> active_pile = 2726 scoped_refptr<FakePicturePileImpl> active_pile =
2927 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 2727 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2928 2728
2929 float result_scale_x, result_scale_y;
2930 gfx::Size result_bounds;
2931 std::vector<PictureLayerTiling*> used_tilings; 2729 std::vector<PictureLayerTiling*> used_tilings;
2932 2730
2933 SetupTrees(pending_pile, active_pile); 2731 SetupTrees(pending_pile, active_pile);
2934 2732
2935 float pending_contents_scale = 1.f; 2733 float pending_contents_scale = 1.f;
2936 float active_contents_scale = 2.f; 2734 float active_contents_scale = 2.f;
2937 float device_scale_factor = 1.f; 2735 float device_scale_factor = 1.f;
2938 float page_scale_factor = 1.f; 2736 float page_scale_factor = 1.f;
2939 float maximum_animation_contents_scale = 1.f; 2737 float maximum_animation_contents_scale = 1.f;
2940 bool animating_transform = false; 2738 bool animating_transform = false;
2941 2739
2942 EXPECT_TRUE(host_impl_.settings().create_low_res_tiling); 2740 EXPECT_TRUE(host_impl_.settings().create_low_res_tiling);
2943 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; 2741 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
2944 EXPECT_LT(low_res_factor, 1.f); 2742 EXPECT_LT(low_res_factor, 1.f);
2945 2743
2946 pending_layer_->CalculateContentsScale(pending_contents_scale, 2744 SetupDrawPropertiesAndManageTilings(pending_layer_,
2947 device_scale_factor, 2745 pending_contents_scale,
2948 page_scale_factor, 2746 device_scale_factor,
2949 maximum_animation_contents_scale, 2747 page_scale_factor,
2950 animating_transform, 2748 maximum_animation_contents_scale,
2951 &result_scale_x, 2749 animating_transform);
2952 &result_scale_y, 2750 SetupDrawPropertiesAndManageTilings(active_layer_,
2953 &result_bounds); 2751 active_contents_scale,
2954 active_layer_->CalculateContentsScale(active_contents_scale, 2752 device_scale_factor,
2955 device_scale_factor, 2753 page_scale_factor,
2956 page_scale_factor, 2754 maximum_animation_contents_scale,
2957 maximum_animation_contents_scale, 2755 animating_transform);
2958 animating_transform,
2959 &result_scale_x,
2960 &result_scale_y,
2961 &result_bounds);
2962 2756
2963 ASSERT_EQ(4u, pending_layer_->tilings()->num_tilings()); 2757 ASSERT_EQ(4u, pending_layer_->tilings()->num_tilings());
2964 ASSERT_EQ(4u, active_layer_->tilings()->num_tilings()); 2758 ASSERT_EQ(4u, active_layer_->tilings()->num_tilings());
2965 2759
2966 EXPECT_EQ(active_contents_scale, 2760 EXPECT_EQ(active_contents_scale,
2967 pending_layer_->tilings()->tiling_at(0)->contents_scale()); 2761 pending_layer_->tilings()->tiling_at(0)->contents_scale());
2968 EXPECT_EQ(pending_contents_scale, 2762 EXPECT_EQ(pending_contents_scale,
2969 pending_layer_->tilings()->tiling_at(1)->contents_scale()); 2763 pending_layer_->tilings()->tiling_at(1)->contents_scale());
2970 EXPECT_EQ(active_contents_scale * low_res_factor, 2764 EXPECT_EQ(active_contents_scale * low_res_factor,
2971 pending_layer_->tilings()->tiling_at(2)->contents_scale()); 2765 pending_layer_->tilings()->tiling_at(2)->contents_scale());
(...skipping 27 matching lines...) Expand all
2999 2793
3000 TEST_F(NoLowResPictureLayerImplTest, ReleaseResources) { 2794 TEST_F(NoLowResPictureLayerImplTest, ReleaseResources) {
3001 gfx::Size tile_size(400, 400); 2795 gfx::Size tile_size(400, 400);
3002 gfx::Size layer_bounds(1300, 1900); 2796 gfx::Size layer_bounds(1300, 1900);
3003 2797
3004 scoped_refptr<FakePicturePileImpl> pending_pile = 2798 scoped_refptr<FakePicturePileImpl> pending_pile =
3005 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 2799 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3006 scoped_refptr<FakePicturePileImpl> active_pile = 2800 scoped_refptr<FakePicturePileImpl> active_pile =
3007 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 2801 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3008 2802
3009 float result_scale_x, result_scale_y;
3010 gfx::Size result_bounds;
3011
3012 SetupTrees(pending_pile, active_pile); 2803 SetupTrees(pending_pile, active_pile);
3013 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); 2804 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
3014 2805
3015 pending_layer_->CalculateContentsScale(1.3f, // ideal contents scale 2806 SetupDrawPropertiesAndManageTilings(pending_layer_,
3016 2.7f, // device scale 2807 1.3f, // ideal contents scale
3017 3.2f, // page scale 2808 2.7f, // device scale
3018 1.f, // maximum animation scale 2809 3.2f, // page scale
3019 false, 2810 1.f, // maximum animation scale
3020 &result_scale_x, 2811 false);
3021 &result_scale_y,
3022 &result_bounds);
3023 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings()); 2812 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings());
3024 2813
3025 // All tilings should be removed when losing output surface. 2814 // All tilings should be removed when losing output surface.
3026 active_layer_->ReleaseResources(); 2815 active_layer_->ReleaseResources();
3027 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings()); 2816 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
3028 pending_layer_->ReleaseResources(); 2817 pending_layer_->ReleaseResources();
3029 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); 2818 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
3030 2819
3031 // This should create new tilings. 2820 // This should create new tilings.
3032 pending_layer_->CalculateContentsScale(1.3f, // ideal contents scale 2821 SetupDrawPropertiesAndManageTilings(pending_layer_,
3033 2.7f, // device scale 2822 1.3f, // ideal contents scale
3034 3.2f, // page scale 2823 2.7f, // device scale
3035 1.f, // maximum animation scale 2824 3.2f, // page scale
3036 false, 2825 1.f, // maximum animation scale
3037 &result_scale_x, 2826 false);
3038 &result_scale_y,
3039 &result_bounds);
3040 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings()); 2827 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings());
3041 } 2828 }
3042 2829
2830 TEST_F(PictureLayerImplTest, SharedQuadStateContainsMaxTilingScale) {
2831 MockQuadCuller quad_culler;
2832
2833 gfx::Size tile_size(400, 400);
2834 gfx::Size layer_bounds(1000, 2000);
2835
2836 scoped_refptr<FakePicturePileImpl> pending_pile =
2837 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2838 scoped_refptr<FakePicturePileImpl> active_pile =
2839 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2840
2841 SetupTrees(pending_pile, active_pile);
2842
2843 SetupDrawPropertiesAndManageTilings(
2844 pending_layer_, 2.5f, 1.f, 1.f, 1.f, false);
2845 host_impl_.pending_tree()->UpdateDrawProperties();
2846
2847 active_layer_->draw_properties().visible_content_rect =
2848 gfx::Rect(layer_bounds);
2849 host_impl_.active_tree()->UpdateDrawProperties();
2850
2851 float max_contents_scale = active_layer_->MaximumTilingContentsScale();
2852 gfx::Transform scaled_draw_transform = active_layer_->draw_transform();
2853 scaled_draw_transform.Scale(SK_MScalar1 / max_contents_scale,
2854 SK_MScalar1 / max_contents_scale);
2855
2856 AppendQuadsData data;
2857 active_layer_->AppendQuads(&quad_culler, &data);
2858
2859 // SharedQuadState should have be of size 1, as we are doing AppenQuad once.
2860 EXPECT_EQ(1u, quad_culler.shared_quad_state_list().size());
2861 // The content_to_target_transform should be scaled by the
2862 // MaximumTilingContentsScale on the layer.
2863 EXPECT_EQ(scaled_draw_transform.ToString(),
2864 quad_culler.shared_quad_state_list()[0]
2865 ->content_to_target_transform.ToString());
2866 // The content_bounds should be scaled by the
2867 // MaximumTilingContentsScale on the layer.
2868 EXPECT_EQ(gfx::Size(2500u, 5000u).ToString(),
2869 quad_culler.shared_quad_state_list()[0]->content_bounds.ToString());
2870 // The visible_content_rect should be scaled by the
2871 // MaximumTilingContentsScale on the layer.
2872 EXPECT_EQ(
2873 gfx::Rect(0u, 0u, 2500u, 5000u).ToString(),
2874 quad_culler.shared_quad_state_list()[0]->visible_content_rect.ToString());
2875 }
2876
3043 } // namespace 2877 } // namespace
3044 } // namespace cc 2878 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698