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

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

Issue 1988053002: Revert of cc: Refactor layer/tile manager unittest to extract common code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « cc/cc_tests.gyp ('k') | cc/test/test_layer_tree_host_base.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <limits> 10 #include <limits>
(...skipping 12 matching lines...) Expand all
23 #include "cc/test/fake_content_layer_client.h" 23 #include "cc/test/fake_content_layer_client.h"
24 #include "cc/test/fake_impl_task_runner_provider.h" 24 #include "cc/test/fake_impl_task_runner_provider.h"
25 #include "cc/test/fake_layer_tree_host_impl.h" 25 #include "cc/test/fake_layer_tree_host_impl.h"
26 #include "cc/test/fake_output_surface.h" 26 #include "cc/test/fake_output_surface.h"
27 #include "cc/test/fake_picture_layer_impl.h" 27 #include "cc/test/fake_picture_layer_impl.h"
28 #include "cc/test/fake_raster_source.h" 28 #include "cc/test/fake_raster_source.h"
29 #include "cc/test/fake_recording_source.h" 29 #include "cc/test/fake_recording_source.h"
30 #include "cc/test/geometry_test_utils.h" 30 #include "cc/test/geometry_test_utils.h"
31 #include "cc/test/gpu_rasterization_enabled_settings.h" 31 #include "cc/test/gpu_rasterization_enabled_settings.h"
32 #include "cc/test/layer_test_common.h" 32 #include "cc/test/layer_test_common.h"
33 #include "cc/test/test_layer_tree_host_base.h"
34 #include "cc/test/test_shared_bitmap_manager.h" 33 #include "cc/test/test_shared_bitmap_manager.h"
35 #include "cc/test/test_task_graph_runner.h" 34 #include "cc/test/test_task_graph_runner.h"
36 #include "cc/test/test_web_graphics_context_3d.h" 35 #include "cc/test/test_web_graphics_context_3d.h"
37 #include "cc/tiles/tiling_set_raster_queue_all.h" 36 #include "cc/tiles/tiling_set_raster_queue_all.h"
38 #include "cc/tiles/tiling_set_raster_queue_required.h" 37 #include "cc/tiles/tiling_set_raster_queue_required.h"
39 #include "cc/trees/layer_tree_impl.h" 38 #include "cc/trees/layer_tree_impl.h"
40 #include "testing/gtest/include/gtest/gtest.h" 39 #include "testing/gtest/include/gtest/gtest.h"
41 #include "ui/gfx/geometry/rect_conversions.h" 40 #include "ui/gfx/geometry/rect_conversions.h"
42 #include "ui/gfx/geometry/size_conversions.h" 41 #include "ui/gfx/geometry/size_conversions.h"
43 42
44 namespace cc { 43 namespace cc {
45 namespace { 44 namespace {
46 45
47 #define EXPECT_BOTH_EQ(expression, x) \ 46 #define EXPECT_BOTH_EQ(expression, x) \
48 do { \ 47 do { \
49 EXPECT_EQ(x, pending_layer()->expression); \ 48 EXPECT_EQ(x, pending_layer_->expression); \
50 EXPECT_EQ(x, active_layer()->expression); \ 49 EXPECT_EQ(x, active_layer_->expression); \
51 } while (false) 50 } while (false)
52 51
53 #define EXPECT_BOTH_NE(expression, x) \ 52 #define EXPECT_BOTH_NE(expression, x) \
54 do { \ 53 do { \
55 EXPECT_NE(x, pending_layer()->expression); \ 54 EXPECT_NE(x, pending_layer_->expression); \
56 EXPECT_NE(x, active_layer()->expression); \ 55 EXPECT_NE(x, active_layer_->expression); \
57 } while (false) 56 } while (false)
58 57
59 #define EXPECT_BOTH_TRUE(expression) \ 58 #define EXPECT_BOTH_TRUE(expression) \
60 do { \ 59 do { \
61 EXPECT_TRUE(pending_layer()->expression); \ 60 EXPECT_TRUE(pending_layer_->expression); \
62 EXPECT_TRUE(active_layer()->expression); \ 61 EXPECT_TRUE(active_layer_->expression); \
63 } while (false) 62 } while (false)
64 63
65 #define EXPECT_BOTH_FALSE(expression) \ 64 #define EXPECT_BOTH_FALSE(expression) \
66 do { \ 65 do { \
67 EXPECT_FALSE(pending_layer()->expression); \ 66 EXPECT_FALSE(pending_layer_->expression); \
68 EXPECT_FALSE(active_layer()->expression); \ 67 EXPECT_FALSE(active_layer_->expression); \
69 } while (false) 68 } while (false)
70 69
71 class MockCanvas : public SkCanvas { 70 class MockCanvas : public SkCanvas {
72 public: 71 public:
73 explicit MockCanvas(int w, int h) : SkCanvas(w, h) {} 72 explicit MockCanvas(int w, int h) : SkCanvas(w, h) {}
74 73
75 void onDrawRect(const SkRect& rect, const SkPaint& paint) override { 74 void onDrawRect(const SkRect& rect, const SkPaint& paint) override {
76 // Capture calls before SkCanvas quickReject() kicks in. 75 // Capture calls before SkCanvas quickReject() kicks in.
77 rects_.push_back(rect); 76 rects_.push_back(rect);
78 } 77 }
79 78
80 std::vector<SkRect> rects_; 79 std::vector<SkRect> rects_;
81 }; 80 };
82 81
83 class PictureLayerImplTest : public TestLayerTreeHostBase { 82 class PictureLayerImplTestSettings : public GpuRasterizationEnabledSettings {
84 public: 83 public:
85 void SetUp() override { 84 PictureLayerImplTestSettings() {
86 TestLayerTreeHostBase::SetUp(); 85 layer_transforms_should_scale_layer_contents = true;
87 host_impl()->SetViewportSize(gfx::Size(10000, 10000)); 86 verify_clip_tree_calculations = true;
87 }
88 };
89
90 class NoLowResTilingsSettings : public PictureLayerImplTestSettings {};
91
92 class LowResTilingsSettings : public PictureLayerImplTestSettings {
93 public:
94 LowResTilingsSettings() { create_low_res_tiling = true; }
95 };
96
97 class PictureLayerImplTest : public testing::Test {
98 public:
99 explicit PictureLayerImplTest(const LayerTreeSettings& settings)
100 : task_runner_provider_(base::ThreadTaskRunnerHandle::Get()),
101 output_surface_(FakeOutputSurface::Create3d()),
102 host_impl_(settings,
103 &task_runner_provider_,
104 &shared_bitmap_manager_,
105 &task_graph_runner_),
106 root_id_(6),
107 id_(7),
108 pending_layer_(nullptr),
109 old_pending_layer_(nullptr),
110 active_layer_(nullptr) {
111 host_impl_.SetViewportSize(gfx::Size(10000, 10000));
88 } 112 }
89 113
90 LayerTreeSettings CreateSettings() override { 114 PictureLayerImplTest() : PictureLayerImplTest(LowResTilingsSettings()) {}
91 LayerTreeSettings settings; 115
92 settings.gpu_rasterization_enabled = true; 116 ~PictureLayerImplTest() override {}
93 settings.layer_transforms_should_scale_layer_contents = true; 117
94 settings.create_low_res_tiling = true; 118 void SetUp() override { InitializeRenderer(); }
95 settings.verify_clip_tree_calculations = true; 119
96 return settings; 120 virtual void InitializeRenderer() {
121 host_impl_.SetVisible(true);
122 host_impl_.InitializeRenderer(output_surface_.get());
123 }
124
125 void SetupDefaultTrees(const gfx::Size& layer_bounds) {
126 scoped_refptr<FakeRasterSource> pending_raster_source =
127 FakeRasterSource::CreateFilled(layer_bounds);
128 scoped_refptr<FakeRasterSource> active_raster_source =
129 FakeRasterSource::CreateFilled(layer_bounds);
130
131 SetupTrees(pending_raster_source, active_raster_source);
132 }
133
134 void SetupDefaultTreesWithInvalidation(const gfx::Size& layer_bounds,
135 const Region& invalidation) {
136 scoped_refptr<FakeRasterSource> pending_raster_source =
137 FakeRasterSource::CreateFilled(layer_bounds);
138 scoped_refptr<FakeRasterSource> active_raster_source =
139 FakeRasterSource::CreateFilled(layer_bounds);
140
141 SetupTreesWithInvalidation(pending_raster_source, active_raster_source,
142 invalidation);
143 }
144
145 void RebuildPropertyTreesOnPendingTree() {
146 host_impl_.pending_tree()->property_trees()->needs_rebuild = true;
147 host_impl_.pending_tree()->BuildPropertyTreesForTesting();
148 }
149
150 void ActivateTree() {
151 RebuildPropertyTreesOnPendingTree();
152 host_impl_.ActivateSyncTree();
153 CHECK(!host_impl_.pending_tree());
154 CHECK(host_impl_.recycle_tree());
155 old_pending_layer_ = pending_layer_;
156 pending_layer_ = nullptr;
157 active_layer_ = static_cast<FakePictureLayerImpl*>(
158 host_impl_.active_tree()->LayerById(id_));
159
160 bool update_lcd_text = false;
161 host_impl_.active_tree()->UpdateDrawProperties(update_lcd_text);
97 } 162 }
98 163
99 void SetupDefaultTreesWithFixedTileSize(const gfx::Size& layer_bounds, 164 void SetupDefaultTreesWithFixedTileSize(const gfx::Size& layer_bounds,
100 const gfx::Size& tile_size, 165 const gfx::Size& tile_size,
101 const Region& invalidation) { 166 const Region& invalidation) {
102 scoped_refptr<FakeRasterSource> pending_raster_source = 167 scoped_refptr<FakeRasterSource> pending_raster_source =
103 FakeRasterSource::CreateFilled(layer_bounds); 168 FakeRasterSource::CreateFilled(layer_bounds);
104 scoped_refptr<FakeRasterSource> active_raster_source = 169 scoped_refptr<FakeRasterSource> active_raster_source =
105 FakeRasterSource::CreateFilled(layer_bounds); 170 FakeRasterSource::CreateFilled(layer_bounds);
106 171
107 SetupTreesWithFixedTileSize(std::move(pending_raster_source), 172 SetupTreesWithFixedTileSize(pending_raster_source, active_raster_source,
108 std::move(active_raster_source), tile_size, 173 tile_size, invalidation);
109 invalidation); 174 }
175
176 void SetupTrees(scoped_refptr<RasterSource> pending_raster_source,
177 scoped_refptr<RasterSource> active_raster_source) {
178 SetupPendingTree(active_raster_source);
179 ActivateTree();
180 SetupPendingTreeInternal(pending_raster_source, gfx::Size(), Region());
181 }
182
183 void SetupTreesWithInvalidation(
184 scoped_refptr<RasterSource> pending_raster_source,
185 scoped_refptr<RasterSource> active_raster_source,
186 const Region& pending_invalidation) {
187 SetupPendingTreeInternal(active_raster_source, gfx::Size(), Region());
188 ActivateTree();
189 SetupPendingTreeInternal(pending_raster_source, gfx::Size(),
190 pending_invalidation);
110 } 191 }
111 192
112 void SetupTreesWithFixedTileSize( 193 void SetupTreesWithFixedTileSize(
113 scoped_refptr<RasterSource> pending_raster_source, 194 scoped_refptr<RasterSource> pending_raster_source,
114 scoped_refptr<RasterSource> active_raster_source, 195 scoped_refptr<RasterSource> active_raster_source,
115 const gfx::Size& tile_size, 196 const gfx::Size& tile_size,
116 const Region& pending_invalidation) { 197 const Region& pending_invalidation) {
117 SetupPendingTree(std::move(active_raster_source), tile_size, Region()); 198 SetupPendingTreeInternal(active_raster_source, tile_size, Region());
118 ActivateTree(); 199 ActivateTree();
119 SetupPendingTree(std::move(pending_raster_source), tile_size, 200 SetupPendingTreeInternal(pending_raster_source, tile_size,
120 pending_invalidation); 201 pending_invalidation);
121 } 202 }
122 203
123 void SetupDefaultTreesWithInvalidation(const gfx::Size& layer_bounds, 204 void SetupPendingTree(scoped_refptr<RasterSource> raster_source) {
124 const Region& invalidation) { 205 SetupPendingTreeInternal(raster_source, gfx::Size(), Region());
125 scoped_refptr<FakeRasterSource> pending_raster_source =
126 FakeRasterSource::CreateFilled(layer_bounds);
127 scoped_refptr<FakeRasterSource> active_raster_source =
128 FakeRasterSource::CreateFilled(layer_bounds);
129
130 SetupTreesWithInvalidation(std::move(pending_raster_source),
131 std::move(active_raster_source), invalidation);
132 }
133
134 void SetupTreesWithInvalidation(
135 scoped_refptr<RasterSource> pending_raster_source,
136 scoped_refptr<RasterSource> active_raster_source,
137 const Region& pending_invalidation) {
138 SetupPendingTree(std::move(active_raster_source), gfx::Size(), Region());
139 ActivateTree();
140 SetupPendingTree(std::move(pending_raster_source), gfx::Size(),
141 pending_invalidation);
142 } 206 }
143 207
144 void SetupPendingTreeWithInvalidation( 208 void SetupPendingTreeWithInvalidation(
145 scoped_refptr<RasterSource> raster_source, 209 scoped_refptr<RasterSource> raster_source,
146 const Region& invalidation) { 210 const Region& invalidation) {
147 SetupPendingTree(std::move(raster_source), gfx::Size(), invalidation); 211 SetupPendingTreeInternal(raster_source, gfx::Size(), invalidation);
148 } 212 }
149 213
150 void SetupPendingTreeWithFixedTileSize( 214 void SetupPendingTreeWithFixedTileSize(
151 scoped_refptr<RasterSource> raster_source, 215 scoped_refptr<RasterSource> raster_source,
152 const gfx::Size& tile_size, 216 const gfx::Size& tile_size,
153 const Region& invalidation) { 217 const Region& invalidation) {
154 SetupPendingTree(std::move(raster_source), tile_size, invalidation); 218 SetupPendingTreeInternal(raster_source, tile_size, invalidation);
219 }
220
221 void SetupPendingTreeInternal(scoped_refptr<RasterSource> raster_source,
222 const gfx::Size& tile_size,
223 const Region& invalidation) {
224 host_impl_.CreatePendingTree();
225 host_impl_.pending_tree()->PushPageScaleFromMainThread(1.f, 0.00001f,
226 100000.f);
227 LayerTreeImpl* pending_tree = host_impl_.pending_tree();
228 pending_tree->SetDeviceScaleFactor(
229 host_impl_.active_tree()->device_scale_factor());
230
231 // Steal from the recycled tree if possible.
232 LayerImpl* pending_root = pending_tree->root_layer();
233 std::unique_ptr<FakePictureLayerImpl> pending_layer;
234 DCHECK(!pending_root || pending_root->id() == root_id_);
235 if (!pending_root) {
236 std::unique_ptr<LayerImpl> new_pending_root =
237 LayerImpl::Create(pending_tree, root_id_);
238 pending_layer = FakePictureLayerImpl::Create(pending_tree, id_);
239 if (!tile_size.IsEmpty())
240 pending_layer->set_fixed_tile_size(tile_size);
241 pending_layer->SetDrawsContent(true);
242 pending_layer->SetScrollClipLayer(new_pending_root->id());
243 pending_root = new_pending_root.get();
244 pending_tree->SetRootLayer(std::move(new_pending_root));
245 } else {
246 pending_layer.reset(static_cast<FakePictureLayerImpl*>(
247 pending_root->RemoveChildForTesting(pending_root->children()[0])
248 .release()));
249 if (!tile_size.IsEmpty())
250 pending_layer->set_fixed_tile_size(tile_size);
251 }
252 pending_root->test_properties()->force_render_surface = true;
253 // The bounds() just mirror the raster source size.
254 pending_layer->SetBounds(raster_source->GetSize());
255 pending_layer->SetRasterSourceOnPending(raster_source, invalidation);
256
257 pending_root->AddChild(std::move(pending_layer));
258 pending_tree->SetViewportLayersFromIds(
259 Layer::INVALID_ID, pending_tree->root_layer()->id(), Layer::INVALID_ID,
260 Layer::INVALID_ID);
261
262 pending_layer_ = static_cast<FakePictureLayerImpl*>(
263 host_impl_.pending_tree()->LayerById(id_));
264
265 // Add tilings/tiles for the layer.
266 bool update_lcd_text = false;
267 RebuildPropertyTreesOnPendingTree();
268 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
155 } 269 }
156 270
157 void SetupDrawProperties(FakePictureLayerImpl* layer, 271 void SetupDrawProperties(FakePictureLayerImpl* layer,
158 float ideal_contents_scale, 272 float ideal_contents_scale,
159 float device_scale_factor, 273 float device_scale_factor,
160 float page_scale_factor, 274 float page_scale_factor,
161 float maximum_animation_contents_scale, 275 float maximum_animation_contents_scale,
162 float starting_animation_contents_scale, 276 float starting_animation_contents_scale,
163 bool animating_transform_to_screen) { 277 bool animating_transform_to_screen) {
164 layer->layer_tree_impl()->SetDeviceScaleFactor(device_scale_factor); 278 layer->layer_tree_impl()->SetDeviceScaleFactor(device_scale_factor);
165 host_impl()->active_tree()->SetPageScaleOnActiveTree(page_scale_factor); 279 host_impl_.active_tree()->SetPageScaleOnActiveTree(page_scale_factor);
166 280
167 gfx::Transform scale_transform; 281 gfx::Transform scale_transform;
168 scale_transform.Scale(ideal_contents_scale, ideal_contents_scale); 282 scale_transform.Scale(ideal_contents_scale, ideal_contents_scale);
169 layer->draw_properties().target_space_transform = scale_transform; 283 layer->draw_properties().target_space_transform = scale_transform;
170 layer->set_is_drawn_render_surface_layer_list_member(true); 284 layer->set_is_drawn_render_surface_layer_list_member(true);
171 DCHECK_EQ(layer->GetIdealContentsScale(), ideal_contents_scale); 285 DCHECK_EQ(layer->GetIdealContentsScale(), ideal_contents_scale);
172 layer->draw_properties().maximum_animation_contents_scale = 286 layer->draw_properties().maximum_animation_contents_scale =
173 maximum_animation_contents_scale; 287 maximum_animation_contents_scale;
174 layer->draw_properties().starting_animation_contents_scale = 288 layer->draw_properties().starting_animation_contents_scale =
175 starting_animation_contents_scale; 289 starting_animation_contents_scale;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 } 322 }
209 } 323 }
210 324
211 void SetContentsScaleOnBothLayers(float contents_scale, 325 void SetContentsScaleOnBothLayers(float contents_scale,
212 float device_scale_factor, 326 float device_scale_factor,
213 float page_scale_factor, 327 float page_scale_factor,
214 float maximum_animation_contents_scale, 328 float maximum_animation_contents_scale,
215 float starting_animation_contents_scale, 329 float starting_animation_contents_scale,
216 bool animating_transform) { 330 bool animating_transform) {
217 SetupDrawPropertiesAndUpdateTiles( 331 SetupDrawPropertiesAndUpdateTiles(
218 pending_layer(), contents_scale, device_scale_factor, page_scale_factor, 332 pending_layer_, contents_scale, device_scale_factor, page_scale_factor,
219 maximum_animation_contents_scale, starting_animation_contents_scale, 333 maximum_animation_contents_scale, starting_animation_contents_scale,
220 animating_transform); 334 animating_transform);
221 335
222 SetupDrawPropertiesAndUpdateTiles( 336 SetupDrawPropertiesAndUpdateTiles(
223 active_layer(), contents_scale, device_scale_factor, page_scale_factor, 337 active_layer_, contents_scale, device_scale_factor, page_scale_factor,
224 maximum_animation_contents_scale, starting_animation_contents_scale, 338 maximum_animation_contents_scale, starting_animation_contents_scale,
225 animating_transform); 339 animating_transform);
226 } 340 }
227 341
228 void ResetTilingsAndRasterScales() { 342 void ResetTilingsAndRasterScales() {
229 if (pending_layer()) { 343 if (pending_layer_) {
230 pending_layer()->ReleaseResources(); 344 pending_layer_->ReleaseResources();
231 EXPECT_FALSE(pending_layer()->tilings()); 345 EXPECT_FALSE(pending_layer_->tilings());
232 pending_layer()->RecreateResources(); 346 pending_layer_->RecreateResources();
233 EXPECT_EQ(0u, pending_layer()->tilings()->num_tilings()); 347 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
234 } 348 }
235 349
236 if (active_layer()) { 350 if (active_layer_) {
237 active_layer()->ReleaseResources(); 351 active_layer_->ReleaseResources();
238 EXPECT_FALSE(active_layer()->tilings()); 352 EXPECT_FALSE(active_layer_->tilings());
239 active_layer()->RecreateResources(); 353 active_layer_->RecreateResources();
240 EXPECT_EQ(0u, active_layer()->tilings()->num_tilings()); 354 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
241 } 355 }
242 } 356 }
243 357
244 size_t NumberOfTilesRequired(PictureLayerTiling* tiling) { 358 size_t NumberOfTilesRequired(PictureLayerTiling* tiling) {
245 size_t num_required = 0; 359 size_t num_required = 0;
246 std::vector<Tile*> tiles = tiling->AllTilesForTesting(); 360 std::vector<Tile*> tiles = tiling->AllTilesForTesting();
247 for (size_t i = 0; i < tiles.size(); ++i) { 361 for (size_t i = 0; i < tiles.size(); ++i) {
248 if (tiles[i]->required_for_activation()) 362 if (tiles[i]->required_for_activation())
249 num_required++; 363 num_required++;
250 } 364 }
(...skipping 10 matching lines...) Expand all
261 void AssertNoTilesRequired(PictureLayerTiling* tiling) { 375 void AssertNoTilesRequired(PictureLayerTiling* tiling) {
262 std::vector<Tile*> tiles = tiling->AllTilesForTesting(); 376 std::vector<Tile*> tiles = tiling->AllTilesForTesting();
263 for (size_t i = 0; i < tiles.size(); ++i) 377 for (size_t i = 0; i < tiles.size(); ++i)
264 EXPECT_FALSE(tiles[i]->required_for_activation()) << "i: " << i; 378 EXPECT_FALSE(tiles[i]->required_for_activation()) << "i: " << i;
265 EXPECT_GT(tiles.size(), 0u); 379 EXPECT_GT(tiles.size(), 0u);
266 } 380 }
267 381
268 void SetInitialDeviceScaleFactor(float device_scale_factor) { 382 void SetInitialDeviceScaleFactor(float device_scale_factor) {
269 // Device scale factor is a per-tree property. However, tests can't directly 383 // Device scale factor is a per-tree property. However, tests can't directly
270 // set the pending tree's device scale factor before the pending tree is 384 // set the pending tree's device scale factor before the pending tree is
271 // created, and setting it after SetupPendingTreeis too late, since 385 // created, and setting it after SetupPendingTreeInternal is too late, since
272 // draw properties will already have been updated on the tree. To handle 386 // draw properties will already have been updated on the tree. To handle
273 // this, we initially set only the active tree's device scale factor, and we 387 // this, we initially set only the active tree's device scale factor, and we
274 // copy this over to the pending tree inside SetupPendingTree. 388 // copy this over to the pending tree inside SetupPendingTreeInternal.
275 host_impl()->active_tree()->SetDeviceScaleFactor(device_scale_factor); 389 host_impl_.active_tree()->SetDeviceScaleFactor(device_scale_factor);
276 } 390 }
277 391
392 protected:
278 void TestQuadsForSolidColor(bool test_for_solid); 393 void TestQuadsForSolidColor(bool test_for_solid);
394
395 FakeImplTaskRunnerProvider task_runner_provider_;
396 TestSharedBitmapManager shared_bitmap_manager_;
397 TestTaskGraphRunner task_graph_runner_;
398 std::unique_ptr<OutputSurface> output_surface_;
399 FakeLayerTreeHostImpl host_impl_;
400 int root_id_;
401 int id_;
402 FakePictureLayerImpl* pending_layer_;
403 FakePictureLayerImpl* old_pending_layer_;
404 FakePictureLayerImpl* active_layer_;
405
406 private:
407 DISALLOW_COPY_AND_ASSIGN(PictureLayerImplTest);
279 }; 408 };
280 409
281 class NoLowResPictureLayerImplTest : public PictureLayerImplTest { 410 class NoLowResPictureLayerImplTest : public PictureLayerImplTest {
282 public: 411 public:
283 LayerTreeSettings CreateSettings() override { 412 NoLowResPictureLayerImplTest()
284 LayerTreeSettings settings = PictureLayerImplTest::CreateSettings(); 413 : PictureLayerImplTest(NoLowResTilingsSettings()) {}
285 settings.create_low_res_tiling = false;
286 return settings;
287 }
288 }; 414 };
289 415
290 TEST_F(PictureLayerImplTest, TileGridAlignment) { 416 TEST_F(PictureLayerImplTest, TileGridAlignment) {
291 // Layer to span 4 raster tiles in x and in y 417 // Layer to span 4 raster tiles in x and in y
292 LayerTreeSettings settings; 418 LayerTreeSettings settings;
293 gfx::Size layer_size(settings.default_tile_size.width() * 7 / 2, 419 gfx::Size layer_size(settings.default_tile_size.width() * 7 / 2,
294 settings.default_tile_size.height() * 7 / 2); 420 settings.default_tile_size.height() * 7 / 2);
295 421
296 scoped_refptr<FakeRasterSource> pending_raster_source = 422 scoped_refptr<FakeRasterSource> pending_raster_source =
297 FakeRasterSource::CreateFilled(layer_size); 423 FakeRasterSource::CreateFilled(layer_size);
298 424
299 // Create an active recording source, but make sure it's not solid. 425 // Create an active recording source, but make sure it's not solid.
300 std::unique_ptr<FakeRecordingSource> active_recording_source = 426 std::unique_ptr<FakeRecordingSource> active_recording_source =
301 FakeRecordingSource::CreateFilledRecordingSource(layer_size); 427 FakeRecordingSource::CreateFilledRecordingSource(layer_size);
302 active_recording_source->SetLayerBounds(layer_size); 428 active_recording_source->SetLayerBounds(layer_size);
303 active_recording_source->add_draw_rect(gfx::Rect(layer_size)); 429 active_recording_source->add_draw_rect(gfx::Rect(layer_size));
304 active_recording_source->add_draw_rect( 430 active_recording_source->add_draw_rect(
305 gfx::Rect(0, 0, layer_size.width() - 1, layer_size.height() - 1)); 431 gfx::Rect(0, 0, layer_size.width() - 1, layer_size.height() - 1));
306 active_recording_source->Rerecord(); 432 active_recording_source->Rerecord();
307 scoped_refptr<FakeRasterSource> active_raster_source = 433 scoped_refptr<FakeRasterSource> active_raster_source =
308 FakeRasterSource::CreateFromRecordingSource(active_recording_source.get(), 434 FakeRasterSource::CreateFromRecordingSource(active_recording_source.get(),
309 false); 435 false);
310 436
311 SetupTrees(pending_raster_source, active_raster_source); 437 SetupTrees(pending_raster_source, active_raster_source);
312 438
313 // Add 1x1 rects at the centers of each tile, then re-record recording source 439 // Add 1x1 rects at the centers of each tile, then re-record recording source
314 // contents. 440 // contents.
315 active_layer()->tilings()->tiling_at(0)->CreateAllTilesForTesting(); 441 active_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting();
316 std::vector<Tile*> tiles = 442 std::vector<Tile*> tiles =
317 active_layer()->tilings()->tiling_at(0)->AllTilesForTesting(); 443 active_layer_->tilings()->tiling_at(0)->AllTilesForTesting();
318 EXPECT_EQ(16u, tiles.size()); 444 EXPECT_EQ(16u, tiles.size());
319 std::vector<SkRect> rects; 445 std::vector<SkRect> rects;
320 std::vector<Tile*>::const_iterator tile_iter; 446 std::vector<Tile*>::const_iterator tile_iter;
321 active_recording_source->reset_draws(); 447 active_recording_source->reset_draws();
322 for (tile_iter = tiles.begin(); tile_iter < tiles.end(); tile_iter++) { 448 for (tile_iter = tiles.begin(); tile_iter < tiles.end(); tile_iter++) {
323 gfx::Point tile_center = (*tile_iter)->content_rect().CenterPoint(); 449 gfx::Point tile_center = (*tile_iter)->content_rect().CenterPoint();
324 gfx::Rect rect(tile_center.x(), tile_center.y(), 1, 1); 450 gfx::Rect rect(tile_center.x(), tile_center.y(), 1, 1);
325 active_recording_source->add_draw_rect(rect); 451 active_recording_source->add_draw_rect(rect);
326 rects.push_back(SkRect::MakeXYWH(rect.x(), rect.y(), 1, 1)); 452 rects.push_back(SkRect::MakeXYWH(rect.x(), rect.y(), 1, 1));
327 } 453 }
(...skipping 21 matching lines...) Expand all
349 EXPECT_EQ(1u, mock_canvas.rects_.size()); 475 EXPECT_EQ(1u, mock_canvas.rects_.size());
350 EXPECT_EQ(*rect_iter, mock_canvas.rects_[0]); 476 EXPECT_EQ(*rect_iter, mock_canvas.rects_[0]);
351 rect_iter++; 477 rect_iter++;
352 } 478 }
353 } 479 }
354 480
355 TEST_F(PictureLayerImplTest, CloneNoInvalidation) { 481 TEST_F(PictureLayerImplTest, CloneNoInvalidation) {
356 gfx::Size layer_bounds(400, 400); 482 gfx::Size layer_bounds(400, 400);
357 SetupDefaultTrees(layer_bounds); 483 SetupDefaultTrees(layer_bounds);
358 484
359 EXPECT_EQ(pending_layer()->tilings()->num_tilings(), 485 EXPECT_EQ(pending_layer_->tilings()->num_tilings(),
360 active_layer()->tilings()->num_tilings()); 486 active_layer_->tilings()->num_tilings());
361 487
362 const PictureLayerTilingSet* tilings = pending_layer()->tilings(); 488 const PictureLayerTilingSet* tilings = pending_layer_->tilings();
363 EXPECT_GT(tilings->num_tilings(), 0u); 489 EXPECT_GT(tilings->num_tilings(), 0u);
364 for (size_t i = 0; i < tilings->num_tilings(); ++i) 490 for (size_t i = 0; i < tilings->num_tilings(); ++i)
365 EXPECT_TRUE(tilings->tiling_at(i)->AllTilesForTesting().empty()); 491 EXPECT_TRUE(tilings->tiling_at(i)->AllTilesForTesting().empty());
366 } 492 }
367 493
368 TEST_F(PictureLayerImplTest, ExternalViewportRectForPrioritizingTiles) { 494 TEST_F(PictureLayerImplTest, ExternalViewportRectForPrioritizingTiles) {
369 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); 495 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
370 gfx::Size layer_bounds(400, 400); 496 gfx::Size layer_bounds(400, 400);
371 SetupDefaultTrees(layer_bounds); 497 SetupDefaultTrees(layer_bounds);
372 498
373 SetupDrawPropertiesAndUpdateTiles(active_layer(), 1.f, 1.f, 1.f, 1.f, 0.f, 499 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, 1.f, 1.f, 1.f, 0.f,
374 false); 500 false);
375 501
376 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200)); 502 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
377 503
378 // Update tiles with viewport for tile priority as (0, 0, 100, 100) and the 504 // Update tiles with viewport for tile priority as (0, 0, 100, 100) and the
379 // identify transform for tile priority. 505 // identify transform for tile priority.
380 gfx::Rect viewport_rect_for_tile_priority = gfx::Rect(0, 0, 100, 100); 506 gfx::Rect viewport_rect_for_tile_priority = gfx::Rect(0, 0, 100, 100);
381 gfx::Transform transform, transform_for_tile_priority; 507 gfx::Transform transform, transform_for_tile_priority;
382 508
383 host_impl()->SetExternalTilePriorityConstraints( 509 host_impl_.SetExternalTilePriorityConstraints(viewport_rect_for_tile_priority,
384 viewport_rect_for_tile_priority, transform_for_tile_priority); 510 transform_for_tile_priority);
385 bool update_lcd_text = false; 511 bool update_lcd_text = false;
386 host_impl()->active_tree()->UpdateDrawProperties(update_lcd_text); 512 host_impl_.active_tree()->UpdateDrawProperties(update_lcd_text);
387 513
388 gfx::Rect viewport_rect_for_tile_priority_in_view_space = 514 gfx::Rect viewport_rect_for_tile_priority_in_view_space =
389 viewport_rect_for_tile_priority; 515 viewport_rect_for_tile_priority;
390 516
391 // Verify the viewport rect for tile priority is used in picture layer tiling. 517 // Verify the viewport rect for tile priority is used in picture layer tiling.
392 EXPECT_EQ(viewport_rect_for_tile_priority_in_view_space, 518 EXPECT_EQ(viewport_rect_for_tile_priority_in_view_space,
393 active_layer()->viewport_rect_for_tile_priority_in_content_space()); 519 active_layer_->viewport_rect_for_tile_priority_in_content_space());
394 PictureLayerTilingSet* tilings = active_layer()->tilings(); 520 PictureLayerTilingSet* tilings = active_layer_->tilings();
395 for (size_t i = 0; i < tilings->num_tilings(); i++) { 521 for (size_t i = 0; i < tilings->num_tilings(); i++) {
396 PictureLayerTiling* tiling = tilings->tiling_at(i); 522 PictureLayerTiling* tiling = tilings->tiling_at(i);
397 EXPECT_EQ( 523 EXPECT_EQ(
398 tiling->GetCurrentVisibleRectForTesting(), 524 tiling->GetCurrentVisibleRectForTesting(),
399 gfx::ScaleToEnclosingRect(viewport_rect_for_tile_priority_in_view_space, 525 gfx::ScaleToEnclosingRect(viewport_rect_for_tile_priority_in_view_space,
400 tiling->contents_scale())); 526 tiling->contents_scale()));
401 } 527 }
402 528
403 // Update tiles with viewport for tile priority as (200, 200, 100, 100) in 529 // Update tiles with viewport for tile priority as (200, 200, 100, 100) in
404 // screen space and the transform for tile priority is translated and 530 // screen space and the transform for tile priority is translated and
405 // rotated. The actual viewport for tile priority used by PictureLayerImpl 531 // rotated. The actual viewport for tile priority used by PictureLayerImpl
406 // should be (200, 200, 100, 100) applied with the said transform. 532 // should be (200, 200, 100, 100) applied with the said transform.
407 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200)); 533 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
408 534
409 viewport_rect_for_tile_priority = gfx::Rect(200, 200, 100, 100); 535 viewport_rect_for_tile_priority = gfx::Rect(200, 200, 100, 100);
410 transform_for_tile_priority.Translate(100, 100); 536 transform_for_tile_priority.Translate(100, 100);
411 transform_for_tile_priority.Rotate(45); 537 transform_for_tile_priority.Rotate(45);
412 host_impl()->SetExternalTilePriorityConstraints( 538 host_impl_.SetExternalTilePriorityConstraints(viewport_rect_for_tile_priority,
413 viewport_rect_for_tile_priority, transform_for_tile_priority); 539 transform_for_tile_priority);
414 host_impl()->active_tree()->UpdateDrawProperties(update_lcd_text); 540 host_impl_.active_tree()->UpdateDrawProperties(update_lcd_text);
415 541
416 gfx::Transform screen_to_view(gfx::Transform::kSkipInitialization); 542 gfx::Transform screen_to_view(gfx::Transform::kSkipInitialization);
417 bool success = transform_for_tile_priority.GetInverse(&screen_to_view); 543 bool success = transform_for_tile_priority.GetInverse(&screen_to_view);
418 EXPECT_TRUE(success); 544 EXPECT_TRUE(success);
419 545
420 // Note that we don't clip this to the layer bounds, since it is expected that 546 // Note that we don't clip this to the layer bounds, since it is expected that
421 // the rect will sometimes be outside of the layer bounds. If we clip to 547 // the rect will sometimes be outside of the layer bounds. If we clip to
422 // bounds, then tile priorities will end up being incorrect in cases of fully 548 // bounds, then tile priorities will end up being incorrect in cases of fully
423 // offscreen layer. 549 // offscreen layer.
424 viewport_rect_for_tile_priority_in_view_space = 550 viewport_rect_for_tile_priority_in_view_space =
425 MathUtil::ProjectEnclosingClippedRect(screen_to_view, 551 MathUtil::ProjectEnclosingClippedRect(screen_to_view,
426 viewport_rect_for_tile_priority); 552 viewport_rect_for_tile_priority);
427 553
428 EXPECT_EQ(viewport_rect_for_tile_priority_in_view_space, 554 EXPECT_EQ(viewport_rect_for_tile_priority_in_view_space,
429 active_layer()->viewport_rect_for_tile_priority_in_content_space()); 555 active_layer_->viewport_rect_for_tile_priority_in_content_space());
430 tilings = active_layer()->tilings(); 556 tilings = active_layer_->tilings();
431 for (size_t i = 0; i < tilings->num_tilings(); i++) { 557 for (size_t i = 0; i < tilings->num_tilings(); i++) {
432 PictureLayerTiling* tiling = tilings->tiling_at(i); 558 PictureLayerTiling* tiling = tilings->tiling_at(i);
433 EXPECT_EQ( 559 EXPECT_EQ(
434 tiling->GetCurrentVisibleRectForTesting(), 560 tiling->GetCurrentVisibleRectForTesting(),
435 gfx::ScaleToEnclosingRect(viewport_rect_for_tile_priority_in_view_space, 561 gfx::ScaleToEnclosingRect(viewport_rect_for_tile_priority_in_view_space,
436 tiling->contents_scale())); 562 tiling->contents_scale()));
437 } 563 }
438 } 564 }
439 565
440 TEST_F(PictureLayerImplTest, ViewportRectForTilePriorityIsCached) { 566 TEST_F(PictureLayerImplTest, ViewportRectForTilePriorityIsCached) {
441 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); 567 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
442 gfx::Size layer_bounds(400, 400); 568 gfx::Size layer_bounds(400, 400);
443 SetupDefaultTrees(layer_bounds); 569 SetupDefaultTrees(layer_bounds);
444 570
445 SetupDrawPropertiesAndUpdateTiles(active_layer(), 1.f, 1.f, 1.f, 1.f, 0.f, 571 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, 1.f, 1.f, 1.f, 0.f,
446 false); 572 false);
447 573
448 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200)); 574 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
449 575
450 gfx::Rect viewport_rect_for_tile_priority(0, 0, 100, 100); 576 gfx::Rect viewport_rect_for_tile_priority(0, 0, 100, 100);
451 gfx::Transform transform_for_tile_priority; 577 gfx::Transform transform_for_tile_priority;
452 578
453 host_impl()->SetExternalTilePriorityConstraints( 579 host_impl_.SetExternalTilePriorityConstraints(viewport_rect_for_tile_priority,
454 viewport_rect_for_tile_priority, transform_for_tile_priority); 580 transform_for_tile_priority);
455 bool update_lcd_text = false; 581 bool update_lcd_text = false;
456 host_impl()->active_tree()->UpdateDrawProperties(update_lcd_text); 582 host_impl_.active_tree()->UpdateDrawProperties(update_lcd_text);
457 583
458 EXPECT_EQ(viewport_rect_for_tile_priority, 584 EXPECT_EQ(viewport_rect_for_tile_priority,
459 active_layer()->viewport_rect_for_tile_priority_in_content_space()); 585 active_layer_->viewport_rect_for_tile_priority_in_content_space());
460 586
461 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200)); 587 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
462 588
463 gfx::Rect another_viewport_rect_for_tile_priority(11, 11, 50, 50); 589 gfx::Rect another_viewport_rect_for_tile_priority(11, 11, 50, 50);
464 host_impl()->SetExternalTilePriorityConstraints( 590 host_impl_.SetExternalTilePriorityConstraints(
465 another_viewport_rect_for_tile_priority, transform_for_tile_priority); 591 another_viewport_rect_for_tile_priority, transform_for_tile_priority);
466 592
467 // Didn't call UpdateDrawProperties yet. The viewport rect for tile priority 593 // Didn't call UpdateDrawProperties yet. The viewport rect for tile priority
468 // should remain to be the previously cached value. 594 // should remain to be the previously cached value.
469 EXPECT_EQ(viewport_rect_for_tile_priority, 595 EXPECT_EQ(viewport_rect_for_tile_priority,
470 active_layer()->viewport_rect_for_tile_priority_in_content_space()); 596 active_layer_->viewport_rect_for_tile_priority_in_content_space());
471 host_impl()->active_tree()->UpdateDrawProperties(update_lcd_text); 597 host_impl_.active_tree()->UpdateDrawProperties(update_lcd_text);
472 598
473 // Now the UpdateDrawProperties is called. The viewport rect for tile 599 // Now the UpdateDrawProperties is called. The viewport rect for tile
474 // priority should be the latest value. 600 // priority should be the latest value.
475 EXPECT_EQ(another_viewport_rect_for_tile_priority, 601 EXPECT_EQ(another_viewport_rect_for_tile_priority,
476 active_layer()->viewport_rect_for_tile_priority_in_content_space()); 602 active_layer_->viewport_rect_for_tile_priority_in_content_space());
477 } 603 }
478 604
479 TEST_F(PictureLayerImplTest, ClonePartialInvalidation) { 605 TEST_F(PictureLayerImplTest, ClonePartialInvalidation) {
480 gfx::Size layer_bounds(400, 400); 606 gfx::Size layer_bounds(400, 400);
481 gfx::Rect layer_invalidation(150, 200, 30, 180); 607 gfx::Rect layer_invalidation(150, 200, 30, 180);
482 608
483 scoped_refptr<FakeRasterSource> pending_raster_source = 609 scoped_refptr<FakeRasterSource> pending_raster_source =
484 FakeRasterSource::CreateFilled(layer_bounds); 610 FakeRasterSource::CreateFilled(layer_bounds);
485 scoped_refptr<FakeRasterSource> active_raster_source = 611 scoped_refptr<FakeRasterSource> active_raster_source =
486 FakeRasterSource::CreateFilled(layer_bounds); 612 FakeRasterSource::CreateFilled(layer_bounds);
487 scoped_refptr<FakeRasterSource> lost_raster_source = 613 scoped_refptr<FakeRasterSource> lost_raster_source =
488 FakeRasterSource::CreateFilled(layer_bounds); 614 FakeRasterSource::CreateFilled(layer_bounds);
489 615
490 SetupPendingTreeWithFixedTileSize(lost_raster_source, gfx::Size(50, 50), 616 SetupPendingTreeWithFixedTileSize(lost_raster_source, gfx::Size(50, 50),
491 Region()); 617 Region());
492 ActivateTree(); 618 ActivateTree();
493 // Add a unique tiling on the active tree. 619 // Add a unique tiling on the active tree.
494 PictureLayerTiling* tiling = active_layer()->AddTiling(3.f); 620 PictureLayerTiling* tiling = active_layer_->AddTiling(3.f);
495 tiling->set_resolution(HIGH_RESOLUTION); 621 tiling->set_resolution(HIGH_RESOLUTION);
496 tiling->CreateAllTilesForTesting(); 622 tiling->CreateAllTilesForTesting();
497 623
498 // Ensure UpdateTiles won't remove any tilings. 624 // Ensure UpdateTiles won't remove any tilings.
499 active_layer()->MarkAllTilingsUsed(); 625 active_layer_->MarkAllTilingsUsed();
500 626
501 // Then setup a new pending tree and activate it. 627 // Then setup a new pending tree and activate it.
502 SetupTreesWithFixedTileSize(pending_raster_source, active_raster_source, 628 SetupTreesWithFixedTileSize(pending_raster_source, active_raster_source,
503 gfx::Size(50, 50), layer_invalidation); 629 gfx::Size(50, 50), layer_invalidation);
504 630
505 EXPECT_EQ(1u, pending_layer()->num_tilings()); 631 EXPECT_EQ(1u, pending_layer_->num_tilings());
506 EXPECT_EQ(3u, active_layer()->num_tilings()); 632 EXPECT_EQ(3u, active_layer_->num_tilings());
507 633
508 const PictureLayerTilingSet* tilings = pending_layer()->tilings(); 634 const PictureLayerTilingSet* tilings = pending_layer_->tilings();
509 EXPECT_GT(tilings->num_tilings(), 0u); 635 EXPECT_GT(tilings->num_tilings(), 0u);
510 for (size_t i = 0; i < tilings->num_tilings(); ++i) { 636 for (size_t i = 0; i < tilings->num_tilings(); ++i) {
511 const PictureLayerTiling* tiling = tilings->tiling_at(i); 637 const PictureLayerTiling* tiling = tilings->tiling_at(i);
512 gfx::Rect content_invalidation = gfx::ScaleToEnclosingRect( 638 gfx::Rect content_invalidation = gfx::ScaleToEnclosingRect(
513 layer_invalidation, 639 layer_invalidation,
514 tiling->contents_scale()); 640 tiling->contents_scale());
515 auto prioritized_tiles = 641 auto prioritized_tiles =
516 tiling->UpdateAndGetAllPrioritizedTilesForTesting(); 642 tiling->UpdateAndGetAllPrioritizedTilesForTesting();
517 for (PictureLayerTiling::CoverageIterator iter( 643 for (PictureLayerTiling::CoverageIterator iter(
518 tiling, 644 tiling,
519 tiling->contents_scale(), 645 tiling->contents_scale(),
520 gfx::Rect(tiling->tiling_size())); 646 gfx::Rect(tiling->tiling_size()));
521 iter; 647 iter;
522 ++iter) { 648 ++iter) {
523 // We don't always have a tile, but when we do it's because it was 649 // We don't always have a tile, but when we do it's because it was
524 // invalidated and it has the latest raster source. 650 // invalidated and it has the latest raster source.
525 if (*iter) { 651 if (*iter) {
526 EXPECT_FALSE(iter.geometry_rect().IsEmpty()); 652 EXPECT_FALSE(iter.geometry_rect().IsEmpty());
527 EXPECT_EQ(pending_raster_source.get(), 653 EXPECT_EQ(pending_raster_source.get(),
528 prioritized_tiles[*iter].raster_source()); 654 prioritized_tiles[*iter].raster_source());
529 EXPECT_TRUE(iter.geometry_rect().Intersects(content_invalidation)); 655 EXPECT_TRUE(iter.geometry_rect().Intersects(content_invalidation));
530 } else { 656 } else {
531 // We don't create tiles in non-invalidated regions. 657 // We don't create tiles in non-invalidated regions.
532 EXPECT_FALSE(iter.geometry_rect().Intersects(content_invalidation)); 658 EXPECT_FALSE(iter.geometry_rect().Intersects(content_invalidation));
533 } 659 }
534 } 660 }
535 } 661 }
536 662
537 tilings = active_layer()->tilings(); 663 tilings = active_layer_->tilings();
538 EXPECT_GT(tilings->num_tilings(), 0u); 664 EXPECT_GT(tilings->num_tilings(), 0u);
539 for (size_t i = 0; i < tilings->num_tilings(); ++i) { 665 for (size_t i = 0; i < tilings->num_tilings(); ++i) {
540 const PictureLayerTiling* tiling = tilings->tiling_at(i); 666 const PictureLayerTiling* tiling = tilings->tiling_at(i);
541 gfx::Rect content_invalidation = 667 gfx::Rect content_invalidation =
542 gfx::ScaleToEnclosingRect(layer_invalidation, tiling->contents_scale()); 668 gfx::ScaleToEnclosingRect(layer_invalidation, tiling->contents_scale());
543 auto prioritized_tiles = 669 auto prioritized_tiles =
544 tiling->UpdateAndGetAllPrioritizedTilesForTesting(); 670 tiling->UpdateAndGetAllPrioritizedTilesForTesting();
545 for (PictureLayerTiling::CoverageIterator iter( 671 for (PictureLayerTiling::CoverageIterator iter(
546 tiling, 672 tiling,
547 tiling->contents_scale(), 673 tiling->contents_scale(),
(...skipping 13 matching lines...) Expand all
561 gfx::Size layer_bounds(300, 500); 687 gfx::Size layer_bounds(300, 500);
562 688
563 scoped_refptr<FakeRasterSource> pending_raster_source = 689 scoped_refptr<FakeRasterSource> pending_raster_source =
564 FakeRasterSource::CreateFilled(layer_bounds); 690 FakeRasterSource::CreateFilled(layer_bounds);
565 scoped_refptr<FakeRasterSource> active_raster_source = 691 scoped_refptr<FakeRasterSource> active_raster_source =
566 FakeRasterSource::CreateFilled(layer_bounds); 692 FakeRasterSource::CreateFilled(layer_bounds);
567 693
568 SetupTreesWithInvalidation(pending_raster_source, active_raster_source, 694 SetupTreesWithInvalidation(pending_raster_source, active_raster_source,
569 gfx::Rect(layer_bounds)); 695 gfx::Rect(layer_bounds));
570 696
571 EXPECT_EQ(pending_layer()->tilings()->num_tilings(), 697 EXPECT_EQ(pending_layer_->tilings()->num_tilings(),
572 active_layer()->tilings()->num_tilings()); 698 active_layer_->tilings()->num_tilings());
573 699
574 const PictureLayerTilingSet* tilings = pending_layer()->tilings(); 700 const PictureLayerTilingSet* tilings = pending_layer_->tilings();
575 EXPECT_GT(tilings->num_tilings(), 0u); 701 EXPECT_GT(tilings->num_tilings(), 0u);
576 for (size_t i = 0; i < tilings->num_tilings(); ++i) { 702 for (size_t i = 0; i < tilings->num_tilings(); ++i) {
577 VerifyAllPrioritizedTilesExistAndHaveRasterSource( 703 VerifyAllPrioritizedTilesExistAndHaveRasterSource(
578 tilings->tiling_at(i), pending_raster_source.get()); 704 tilings->tiling_at(i), pending_raster_source.get());
579 } 705 }
580 } 706 }
581 707
582 TEST_F(PictureLayerImplTest, UpdateTilesCreatesTilings) { 708 TEST_F(PictureLayerImplTest, UpdateTilesCreatesTilings) {
583 gfx::Size layer_bounds(1300, 1900); 709 gfx::Size layer_bounds(1300, 1900);
584 SetupDefaultTrees(layer_bounds); 710 SetupDefaultTrees(layer_bounds);
585 711
586 float low_res_factor = host_impl()->settings().low_res_contents_scale_factor; 712 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
587 EXPECT_LT(low_res_factor, 1.f); 713 EXPECT_LT(low_res_factor, 1.f);
588 714
589 active_layer()->ReleaseResources(); 715 active_layer_->ReleaseResources();
590 EXPECT_FALSE(active_layer()->tilings()); 716 EXPECT_FALSE(active_layer_->tilings());
591 active_layer()->RecreateResources(); 717 active_layer_->RecreateResources();
592 EXPECT_EQ(0u, active_layer()->tilings()->num_tilings()); 718 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
593 719
594 SetupDrawPropertiesAndUpdateTiles(active_layer(), 720 SetupDrawPropertiesAndUpdateTiles(active_layer_,
595 6.f, // ideal contents scale 721 6.f, // ideal contents scale
596 3.f, // device scale 722 3.f, // device scale
597 2.f, // page scale 723 2.f, // page scale
598 1.f, // maximum animation scale 724 1.f, // maximum animation scale
599 0.f, // starting animation scale 725 0.f, // starting animation scale
600 false); 726 false);
601 ASSERT_EQ(2u, active_layer()->tilings()->num_tilings()); 727 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
602 EXPECT_FLOAT_EQ(6.f, 728 EXPECT_FLOAT_EQ(6.f,
603 active_layer()->tilings()->tiling_at(0)->contents_scale()); 729 active_layer_->tilings()->tiling_at(0)->contents_scale());
604 EXPECT_FLOAT_EQ(6.f * low_res_factor, 730 EXPECT_FLOAT_EQ(6.f * low_res_factor,
605 active_layer()->tilings()->tiling_at(1)->contents_scale()); 731 active_layer_->tilings()->tiling_at(1)->contents_scale());
606 732
607 // If we change the page scale factor, then we should get new tilings. 733 // If we change the page scale factor, then we should get new tilings.
608 SetupDrawPropertiesAndUpdateTiles(active_layer(), 734 SetupDrawPropertiesAndUpdateTiles(active_layer_,
609 6.6f, // ideal contents scale 735 6.6f, // ideal contents scale
610 3.f, // device scale 736 3.f, // device scale
611 2.2f, // page scale 737 2.2f, // page scale
612 1.f, // maximum animation scale 738 1.f, // maximum animation scale
613 0.f, // starting animation scale 739 0.f, // starting animation scale
614 false); 740 false);
615 ASSERT_EQ(4u, active_layer()->tilings()->num_tilings()); 741 ASSERT_EQ(4u, active_layer_->tilings()->num_tilings());
616 EXPECT_FLOAT_EQ(6.6f, 742 EXPECT_FLOAT_EQ(6.6f,
617 active_layer()->tilings()->tiling_at(0)->contents_scale()); 743 active_layer_->tilings()->tiling_at(0)->contents_scale());
618 EXPECT_FLOAT_EQ(6.6f * low_res_factor, 744 EXPECT_FLOAT_EQ(6.6f * low_res_factor,
619 active_layer()->tilings()->tiling_at(2)->contents_scale()); 745 active_layer_->tilings()->tiling_at(2)->contents_scale());
620 746
621 // If we change the device scale factor, then we should get new tilings. 747 // If we change the device scale factor, then we should get new tilings.
622 SetupDrawPropertiesAndUpdateTiles(active_layer(), 748 SetupDrawPropertiesAndUpdateTiles(active_layer_,
623 7.26f, // ideal contents scale 749 7.26f, // ideal contents scale
624 3.3f, // device scale 750 3.3f, // device scale
625 2.2f, // page scale 751 2.2f, // page scale
626 1.f, // maximum animation scale 752 1.f, // maximum animation scale
627 0.f, // starting animation scale 753 0.f, // starting animation scale
628 false); 754 false);
629 ASSERT_EQ(6u, active_layer()->tilings()->num_tilings()); 755 ASSERT_EQ(6u, active_layer_->tilings()->num_tilings());
630 EXPECT_FLOAT_EQ(7.26f, 756 EXPECT_FLOAT_EQ(7.26f,
631 active_layer()->tilings()->tiling_at(0)->contents_scale()); 757 active_layer_->tilings()->tiling_at(0)->contents_scale());
632 EXPECT_FLOAT_EQ(7.26f * low_res_factor, 758 EXPECT_FLOAT_EQ(7.26f * low_res_factor,
633 active_layer()->tilings()->tiling_at(3)->contents_scale()); 759 active_layer_->tilings()->tiling_at(3)->contents_scale());
634 760
635 // If we change the device scale factor, but end up at the same total scale 761 // If we change the device scale factor, but end up at the same total scale
636 // factor somehow, then we don't get new tilings. 762 // factor somehow, then we don't get new tilings.
637 SetupDrawPropertiesAndUpdateTiles(active_layer(), 763 SetupDrawPropertiesAndUpdateTiles(active_layer_,
638 7.26f, // ideal contents scale 764 7.26f, // ideal contents scale
639 2.2f, // device scale 765 2.2f, // device scale
640 3.3f, // page scale 766 3.3f, // page scale
641 1.f, // maximum animation scale 767 1.f, // maximum animation scale
642 0.f, // starting animation scale 768 0.f, // starting animation scale
643 false); 769 false);
644 ASSERT_EQ(6u, active_layer()->tilings()->num_tilings()); 770 ASSERT_EQ(6u, active_layer_->tilings()->num_tilings());
645 EXPECT_FLOAT_EQ(7.26f, 771 EXPECT_FLOAT_EQ(7.26f,
646 active_layer()->tilings()->tiling_at(0)->contents_scale()); 772 active_layer_->tilings()->tiling_at(0)->contents_scale());
647 EXPECT_FLOAT_EQ(7.26f * low_res_factor, 773 EXPECT_FLOAT_EQ(7.26f * low_res_factor,
648 active_layer()->tilings()->tiling_at(3)->contents_scale()); 774 active_layer_->tilings()->tiling_at(3)->contents_scale());
649 } 775 }
650 776
651 TEST_F(PictureLayerImplTest, PendingLayerOnlyHasHighResTiling) { 777 TEST_F(PictureLayerImplTest, PendingLayerOnlyHasHighResTiling) {
652 gfx::Size layer_bounds(1300, 1900); 778 gfx::Size layer_bounds(1300, 1900);
653 SetupDefaultTrees(layer_bounds); 779 SetupDefaultTrees(layer_bounds);
654 780
655 float low_res_factor = host_impl()->settings().low_res_contents_scale_factor; 781 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
656 EXPECT_LT(low_res_factor, 1.f); 782 EXPECT_LT(low_res_factor, 1.f);
657 783
658 pending_layer()->ReleaseResources(); 784 pending_layer_->ReleaseResources();
659 EXPECT_FALSE(pending_layer()->tilings()); 785 EXPECT_FALSE(pending_layer_->tilings());
660 pending_layer()->RecreateResources(); 786 pending_layer_->RecreateResources();
661 EXPECT_EQ(0u, pending_layer()->tilings()->num_tilings()); 787 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
662 788
663 SetupDrawPropertiesAndUpdateTiles(pending_layer(), 789 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
664 6.f, // ideal contents scale 790 6.f, // ideal contents scale
665 3.f, // device scale 791 3.f, // device scale
666 2.f, // page scale 792 2.f, // page scale
667 1.f, // maximum animation scale 793 1.f, // maximum animation scale
668 0.f, // starting animation scale 794 0.f, // starting animation scale
669 false); 795 false);
670 ASSERT_EQ(1u, pending_layer()->tilings()->num_tilings()); 796 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
671 EXPECT_FLOAT_EQ(6.f, 797 EXPECT_FLOAT_EQ(6.f,
672 pending_layer()->tilings()->tiling_at(0)->contents_scale()); 798 pending_layer_->tilings()->tiling_at(0)->contents_scale());
673 799
674 // If we change the page scale factor, then we should get new tilings. 800 // If we change the page scale factor, then we should get new tilings.
675 SetupDrawPropertiesAndUpdateTiles(pending_layer(), 801 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
676 6.6f, // ideal contents scale 802 6.6f, // ideal contents scale
677 3.f, // device scale 803 3.f, // device scale
678 2.2f, // page scale 804 2.2f, // page scale
679 1.f, // maximum animation scale 805 1.f, // maximum animation scale
680 0.f, // starting animation scale 806 0.f, // starting animation scale
681 false); 807 false);
682 ASSERT_EQ(1u, pending_layer()->tilings()->num_tilings()); 808 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
683 EXPECT_FLOAT_EQ(6.6f, 809 EXPECT_FLOAT_EQ(6.6f,
684 pending_layer()->tilings()->tiling_at(0)->contents_scale()); 810 pending_layer_->tilings()->tiling_at(0)->contents_scale());
685 811
686 // If we change the device scale factor, then we should get new tilings. 812 // If we change the device scale factor, then we should get new tilings.
687 SetupDrawPropertiesAndUpdateTiles(pending_layer(), 813 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
688 7.26f, // ideal contents scale 814 7.26f, // ideal contents scale
689 3.3f, // device scale 815 3.3f, // device scale
690 2.2f, // page scale 816 2.2f, // page scale
691 1.f, // maximum animation scale 817 1.f, // maximum animation scale
692 0.f, // starting animation scale 818 0.f, // starting animation scale
693 false); 819 false);
694 ASSERT_EQ(1u, pending_layer()->tilings()->num_tilings()); 820 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
695 EXPECT_FLOAT_EQ(7.26f, 821 EXPECT_FLOAT_EQ(7.26f,
696 pending_layer()->tilings()->tiling_at(0)->contents_scale()); 822 pending_layer_->tilings()->tiling_at(0)->contents_scale());
697 823
698 // If we change the device scale factor, but end up at the same total scale 824 // If we change the device scale factor, but end up at the same total scale
699 // factor somehow, then we don't get new tilings. 825 // factor somehow, then we don't get new tilings.
700 SetupDrawPropertiesAndUpdateTiles(pending_layer(), 826 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
701 7.26f, // ideal contents scale 827 7.26f, // ideal contents scale
702 2.2f, // device scale 828 2.2f, // device scale
703 3.3f, // page scale 829 3.3f, // page scale
704 1.f, // maximum animation scale 830 1.f, // maximum animation scale
705 0.f, // starting animation scale 831 0.f, // starting animation scale
706 false); 832 false);
707 ASSERT_EQ(1u, pending_layer()->tilings()->num_tilings()); 833 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
708 EXPECT_FLOAT_EQ(7.26f, 834 EXPECT_FLOAT_EQ(7.26f,
709 pending_layer()->tilings()->tiling_at(0)->contents_scale()); 835 pending_layer_->tilings()->tiling_at(0)->contents_scale());
710 } 836 }
711 837
712 TEST_F(PictureLayerImplTest, CreateTilingsEvenIfTwinHasNone) { 838 TEST_F(PictureLayerImplTest, CreateTilingsEvenIfTwinHasNone) {
713 // This test makes sure that if a layer can have tilings, then a commit makes 839 // This test makes sure that if a layer can have tilings, then a commit makes
714 // it not able to have tilings (empty size), and then a future commit that 840 // it not able to have tilings (empty size), and then a future commit that
715 // makes it valid again should be able to create tilings. 841 // makes it valid again should be able to create tilings.
716 gfx::Size layer_bounds(1300, 1900); 842 gfx::Size layer_bounds(1300, 1900);
717 843
718 scoped_refptr<FakeRasterSource> empty_raster_source = 844 scoped_refptr<FakeRasterSource> empty_raster_source =
719 FakeRasterSource::CreateEmpty(layer_bounds); 845 FakeRasterSource::CreateEmpty(layer_bounds);
720 scoped_refptr<FakeRasterSource> valid_raster_source = 846 scoped_refptr<FakeRasterSource> valid_raster_source =
721 FakeRasterSource::CreateFilled(layer_bounds); 847 FakeRasterSource::CreateFilled(layer_bounds);
722 848
723 SetupPendingTree(valid_raster_source); 849 SetupPendingTree(valid_raster_source);
724 ASSERT_EQ(1u, pending_layer()->tilings()->num_tilings()); 850 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
725 851
726 ActivateTree(); 852 ActivateTree();
727 SetupPendingTree(empty_raster_source); 853 SetupPendingTree(empty_raster_source);
728 EXPECT_FALSE(pending_layer()->CanHaveTilings()); 854 EXPECT_FALSE(pending_layer_->CanHaveTilings());
729 ASSERT_EQ(2u, active_layer()->tilings()->num_tilings()); 855 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
730 ASSERT_EQ(0u, pending_layer()->tilings()->num_tilings()); 856 ASSERT_EQ(0u, pending_layer_->tilings()->num_tilings());
731 857
732 ActivateTree(); 858 ActivateTree();
733 EXPECT_FALSE(active_layer()->CanHaveTilings()); 859 EXPECT_FALSE(active_layer_->CanHaveTilings());
734 ASSERT_EQ(0u, active_layer()->tilings()->num_tilings()); 860 ASSERT_EQ(0u, active_layer_->tilings()->num_tilings());
735 861
736 SetupPendingTree(valid_raster_source); 862 SetupPendingTree(valid_raster_source);
737 ASSERT_EQ(1u, pending_layer()->tilings()->num_tilings()); 863 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
738 ASSERT_EQ(0u, active_layer()->tilings()->num_tilings()); 864 ASSERT_EQ(0u, active_layer_->tilings()->num_tilings());
739 } 865 }
740 866
741 TEST_F(PictureLayerImplTest, LowResTilingStaysOnActiveTree) { 867 TEST_F(PictureLayerImplTest, LowResTilingStaysOnActiveTree) {
742 gfx::Size layer_bounds(1300, 1900); 868 gfx::Size layer_bounds(1300, 1900);
743 869
744 scoped_refptr<FakeRasterSource> valid_raster_source = 870 scoped_refptr<FakeRasterSource> valid_raster_source =
745 FakeRasterSource::CreateFilled(layer_bounds); 871 FakeRasterSource::CreateFilled(layer_bounds);
746 scoped_refptr<FakeRasterSource> other_valid_raster_source = 872 scoped_refptr<FakeRasterSource> other_valid_raster_source =
747 FakeRasterSource::CreateFilled(layer_bounds); 873 FakeRasterSource::CreateFilled(layer_bounds);
748 874
749 SetupPendingTree(valid_raster_source); 875 SetupPendingTree(valid_raster_source);
750 ASSERT_EQ(1u, pending_layer()->tilings()->num_tilings()); 876 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
751 877
752 ActivateTree(); 878 ActivateTree();
753 SetupPendingTree(other_valid_raster_source); 879 SetupPendingTree(other_valid_raster_source);
754 ASSERT_EQ(2u, active_layer()->tilings()->num_tilings()); 880 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
755 ASSERT_EQ(1u, pending_layer()->tilings()->num_tilings()); 881 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
756 auto* low_res_tiling = 882 auto* low_res_tiling =
757 active_layer()->tilings()->FindTilingWithResolution(LOW_RESOLUTION); 883 active_layer_->tilings()->FindTilingWithResolution(LOW_RESOLUTION);
758 EXPECT_TRUE(low_res_tiling); 884 EXPECT_TRUE(low_res_tiling);
759 885
760 ActivateTree(); 886 ActivateTree();
761 ASSERT_EQ(2u, active_layer()->tilings()->num_tilings()); 887 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
762 auto* other_low_res_tiling = 888 auto* other_low_res_tiling =
763 active_layer()->tilings()->FindTilingWithResolution(LOW_RESOLUTION); 889 active_layer_->tilings()->FindTilingWithResolution(LOW_RESOLUTION);
764 EXPECT_TRUE(other_low_res_tiling); 890 EXPECT_TRUE(other_low_res_tiling);
765 EXPECT_EQ(low_res_tiling, other_low_res_tiling); 891 EXPECT_EQ(low_res_tiling, other_low_res_tiling);
766 } 892 }
767 893
768 TEST_F(PictureLayerImplTest, ZoomOutCrash) { 894 TEST_F(PictureLayerImplTest, ZoomOutCrash) {
769 gfx::Size layer_bounds(1300, 1900); 895 gfx::Size layer_bounds(1300, 1900);
770 896
771 // Set up the high and low res tilings before pinch zoom. 897 // Set up the high and low res tilings before pinch zoom.
772 SetupDefaultTrees(layer_bounds); 898 SetupDefaultTrees(layer_bounds);
773 ResetTilingsAndRasterScales(); 899 ResetTilingsAndRasterScales();
774 EXPECT_EQ(0u, active_layer()->tilings()->num_tilings()); 900 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
775 SetContentsScaleOnBothLayers(32.0f, 1.0f, 32.0f, 1.0f, 0.f, false); 901 SetContentsScaleOnBothLayers(32.0f, 1.0f, 32.0f, 1.0f, 0.f, false);
776 EXPECT_EQ(32.f, active_layer()->HighResTiling()->contents_scale()); 902 EXPECT_EQ(32.f, active_layer_->HighResTiling()->contents_scale());
777 host_impl()->PinchGestureBegin(); 903 host_impl_.PinchGestureBegin();
778 SetContentsScaleOnBothLayers(1.0f, 1.0f, 1.0f, 1.0f, 0.f, false); 904 SetContentsScaleOnBothLayers(1.0f, 1.0f, 1.0f, 1.0f, 0.f, false);
779 SetContentsScaleOnBothLayers(1.0f, 1.0f, 1.0f, 1.0f, 0.f, false); 905 SetContentsScaleOnBothLayers(1.0f, 1.0f, 1.0f, 1.0f, 0.f, false);
780 EXPECT_EQ(active_layer()->tilings()->NumHighResTilings(), 1); 906 EXPECT_EQ(active_layer_->tilings()->NumHighResTilings(), 1);
781 } 907 }
782 908
783 TEST_F(PictureLayerImplTest, PinchGestureTilings) { 909 TEST_F(PictureLayerImplTest, PinchGestureTilings) {
784 gfx::Size layer_bounds(1300, 1900); 910 gfx::Size layer_bounds(1300, 1900);
785 911
786 float low_res_factor = host_impl()->settings().low_res_contents_scale_factor; 912 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
787 // Set up the high and low res tilings before pinch zoom. 913 // Set up the high and low res tilings before pinch zoom.
788 SetupDefaultTrees(layer_bounds); 914 SetupDefaultTrees(layer_bounds);
789 ResetTilingsAndRasterScales(); 915 ResetTilingsAndRasterScales();
790 916
791 SetContentsScaleOnBothLayers(2.f, 1.0f, 2.f, 1.0f, 0.f, false); 917 SetContentsScaleOnBothLayers(2.f, 1.0f, 2.f, 1.0f, 0.f, false);
792 EXPECT_EQ(active_layer()->num_tilings(), 2u); 918 EXPECT_EQ(active_layer_->num_tilings(), 2u);
793 EXPECT_EQ(pending_layer()->num_tilings(), 1u); 919 EXPECT_EQ(pending_layer_->num_tilings(), 1u);
794 EXPECT_EQ(active_layer()->tilings()->tiling_at(0)->contents_scale(), 2.f); 920 EXPECT_EQ(active_layer_->tilings()->tiling_at(0)->contents_scale(), 2.f);
795 EXPECT_EQ(active_layer()->tilings()->tiling_at(1)->contents_scale(), 921 EXPECT_EQ(active_layer_->tilings()->tiling_at(1)->contents_scale(),
796 2.f * low_res_factor); 922 2.f * low_res_factor);
797 // One of the tilings has to be a low resolution one. 923 // One of the tilings has to be a low resolution one.
798 EXPECT_EQ(LOW_RESOLUTION, 924 EXPECT_EQ(LOW_RESOLUTION,
799 active_layer()->tilings()->tiling_at(1)->resolution()); 925 active_layer_->tilings()->tiling_at(1)->resolution());
800 926
801 // Ensure UpdateTiles won't remove any tilings. 927 // Ensure UpdateTiles won't remove any tilings.
802 active_layer()->MarkAllTilingsUsed(); 928 active_layer_->MarkAllTilingsUsed();
803 929
804 // Start a pinch gesture. 930 // Start a pinch gesture.
805 host_impl()->PinchGestureBegin(); 931 host_impl_.PinchGestureBegin();
806 932
807 // Zoom out by a small amount. We should create a tiling at half 933 // Zoom out by a small amount. We should create a tiling at half
808 // the scale (2/kMaxScaleRatioDuringPinch). 934 // the scale (2/kMaxScaleRatioDuringPinch).
809 SetContentsScaleOnBothLayers(1.8f, 1.0f, 1.8f, 1.0f, 0.f, false); 935 SetContentsScaleOnBothLayers(1.8f, 1.0f, 1.8f, 1.0f, 0.f, false);
810 EXPECT_EQ(3u, active_layer()->tilings()->num_tilings()); 936 EXPECT_EQ(3u, active_layer_->tilings()->num_tilings());
811 EXPECT_FLOAT_EQ(2.0f, 937 EXPECT_FLOAT_EQ(2.0f,
812 active_layer()->tilings()->tiling_at(0)->contents_scale()); 938 active_layer_->tilings()->tiling_at(0)->contents_scale());
813 EXPECT_FLOAT_EQ(1.0f, 939 EXPECT_FLOAT_EQ(1.0f,
814 active_layer()->tilings()->tiling_at(1)->contents_scale()); 940 active_layer_->tilings()->tiling_at(1)->contents_scale());
815 EXPECT_FLOAT_EQ(2.0f * low_res_factor, 941 EXPECT_FLOAT_EQ(2.0f * low_res_factor,
816 active_layer()->tilings()->tiling_at(2)->contents_scale()); 942 active_layer_->tilings()->tiling_at(2)->contents_scale());
817 // Since we're pinching, we shouldn't create a low resolution tiling. 943 // Since we're pinching, we shouldn't create a low resolution tiling.
818 EXPECT_FALSE( 944 EXPECT_FALSE(
819 active_layer()->tilings()->FindTilingWithResolution(LOW_RESOLUTION)); 945 active_layer_->tilings()->FindTilingWithResolution(LOW_RESOLUTION));
820 946
821 // Ensure UpdateTiles won't remove any tilings. 947 // Ensure UpdateTiles won't remove any tilings.
822 active_layer()->MarkAllTilingsUsed(); 948 active_layer_->MarkAllTilingsUsed();
823 949
824 // Zoom out further, close to our low-res scale factor. We should 950 // Zoom out further, close to our low-res scale factor. We should
825 // use that tiling as high-res, and not create a new tiling. 951 // use that tiling as high-res, and not create a new tiling.
826 SetContentsScaleOnBothLayers(low_res_factor * 2.1f, 1.0f, 952 SetContentsScaleOnBothLayers(low_res_factor * 2.1f, 1.0f,
827 low_res_factor * 2.1f, 1.0f, 0.f, false); 953 low_res_factor * 2.1f, 1.0f, 0.f, false);
828 EXPECT_EQ(3u, active_layer()->tilings()->num_tilings()); 954 EXPECT_EQ(3u, active_layer_->tilings()->num_tilings());
829 EXPECT_FALSE( 955 EXPECT_FALSE(
830 active_layer()->tilings()->FindTilingWithResolution(LOW_RESOLUTION)); 956 active_layer_->tilings()->FindTilingWithResolution(LOW_RESOLUTION));
831 957
832 // Zoom in a lot now. Since we increase by increments of 958 // Zoom in a lot now. Since we increase by increments of
833 // kMaxScaleRatioDuringPinch, this will create a new tiling at 4.0. 959 // kMaxScaleRatioDuringPinch, this will create a new tiling at 4.0.
834 SetContentsScaleOnBothLayers(3.8f, 1.0f, 3.8f, 1.f, 0.f, false); 960 SetContentsScaleOnBothLayers(3.8f, 1.0f, 3.8f, 1.f, 0.f, false);
835 EXPECT_EQ(4u, active_layer()->tilings()->num_tilings()); 961 EXPECT_EQ(4u, active_layer_->tilings()->num_tilings());
836 EXPECT_FLOAT_EQ(4.0f, 962 EXPECT_FLOAT_EQ(4.0f,
837 active_layer()->tilings()->tiling_at(0)->contents_scale()); 963 active_layer_->tilings()->tiling_at(0)->contents_scale());
838 // Although one of the tilings matches the low resolution scale, it still 964 // Although one of the tilings matches the low resolution scale, it still
839 // shouldn't be marked as low resolution since we're pinching. 965 // shouldn't be marked as low resolution since we're pinching.
840 auto* low_res_tiling = 966 auto* low_res_tiling =
841 active_layer()->tilings()->FindTilingWithScale(4.f * low_res_factor); 967 active_layer_->tilings()->FindTilingWithScale(4.f * low_res_factor);
842 EXPECT_TRUE(low_res_tiling); 968 EXPECT_TRUE(low_res_tiling);
843 EXPECT_NE(LOW_RESOLUTION, low_res_tiling->resolution()); 969 EXPECT_NE(LOW_RESOLUTION, low_res_tiling->resolution());
844 970
845 // Stop a pinch gesture. 971 // Stop a pinch gesture.
846 host_impl()->PinchGestureEnd(); 972 host_impl_.PinchGestureEnd();
847 973
848 // Ensure UpdateTiles won't remove any tilings. 974 // Ensure UpdateTiles won't remove any tilings.
849 active_layer()->MarkAllTilingsUsed(); 975 active_layer_->MarkAllTilingsUsed();
850 976
851 // After pinch ends, set the scale to what the raster scale was updated to 977 // After pinch ends, set the scale to what the raster scale was updated to
852 // (checked above). 978 // (checked above).
853 SetContentsScaleOnBothLayers(4.0f, 1.0f, 4.0f, 1.f, 0.f, false); 979 SetContentsScaleOnBothLayers(4.0f, 1.0f, 4.0f, 1.f, 0.f, false);
854 EXPECT_EQ(4u, active_layer()->tilings()->num_tilings()); 980 EXPECT_EQ(4u, active_layer_->tilings()->num_tilings());
855 EXPECT_FLOAT_EQ(4.0f, 981 EXPECT_FLOAT_EQ(4.0f,
856 active_layer()->tilings()->tiling_at(0)->contents_scale()); 982 active_layer_->tilings()->tiling_at(0)->contents_scale());
857 // Now that we stopped pinching, the low resolution tiling that existed should 983 // Now that we stopped pinching, the low resolution tiling that existed should
858 // now be marked as low resolution. 984 // now be marked as low resolution.
859 low_res_tiling = 985 low_res_tiling =
860 active_layer()->tilings()->FindTilingWithScale(4.f * low_res_factor); 986 active_layer_->tilings()->FindTilingWithScale(4.f * low_res_factor);
861 EXPECT_TRUE(low_res_tiling); 987 EXPECT_TRUE(low_res_tiling);
862 EXPECT_EQ(LOW_RESOLUTION, low_res_tiling->resolution()); 988 EXPECT_EQ(LOW_RESOLUTION, low_res_tiling->resolution());
863 } 989 }
864 990
865 TEST_F(PictureLayerImplTest, SnappedTilingDuringZoom) { 991 TEST_F(PictureLayerImplTest, SnappedTilingDuringZoom) {
866 gfx::Size layer_bounds(2600, 3800); 992 gfx::Size layer_bounds(2600, 3800);
867 SetupDefaultTrees(layer_bounds); 993 SetupDefaultTrees(layer_bounds);
868 994
869 ResetTilingsAndRasterScales(); 995 ResetTilingsAndRasterScales();
870 EXPECT_EQ(0u, active_layer()->tilings()->num_tilings()); 996 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
871 997
872 // Set up the high and low res tilings before pinch zoom. 998 // Set up the high and low res tilings before pinch zoom.
873 SetContentsScaleOnBothLayers(0.24f, 1.0f, 0.24f, 1.0f, 0.f, false); 999 SetContentsScaleOnBothLayers(0.24f, 1.0f, 0.24f, 1.0f, 0.f, false);
874 EXPECT_EQ(2u, active_layer()->tilings()->num_tilings()); 1000 EXPECT_EQ(2u, active_layer_->tilings()->num_tilings());
875 EXPECT_FLOAT_EQ(0.24f, 1001 EXPECT_FLOAT_EQ(0.24f,
876 active_layer()->tilings()->tiling_at(0)->contents_scale()); 1002 active_layer_->tilings()->tiling_at(0)->contents_scale());
877 EXPECT_FLOAT_EQ(0.0625f, 1003 EXPECT_FLOAT_EQ(0.0625f,
878 active_layer()->tilings()->tiling_at(1)->contents_scale()); 1004 active_layer_->tilings()->tiling_at(1)->contents_scale());
879 1005
880 // Ensure UpdateTiles won't remove any tilings. 1006 // Ensure UpdateTiles won't remove any tilings.
881 active_layer()->MarkAllTilingsUsed(); 1007 active_layer_->MarkAllTilingsUsed();
882 1008
883 // Start a pinch gesture. 1009 // Start a pinch gesture.
884 host_impl()->PinchGestureBegin(); 1010 host_impl_.PinchGestureBegin();
885 1011
886 // Zoom out by a small amount. We should create a tiling at half 1012 // Zoom out by a small amount. We should create a tiling at half
887 // the scale (1/kMaxScaleRatioDuringPinch). 1013 // the scale (1/kMaxScaleRatioDuringPinch).
888 SetContentsScaleOnBothLayers(0.2f, 1.0f, 0.2f, 1.0f, 0.f, false); 1014 SetContentsScaleOnBothLayers(0.2f, 1.0f, 0.2f, 1.0f, 0.f, false);
889 EXPECT_EQ(3u, active_layer()->tilings()->num_tilings()); 1015 EXPECT_EQ(3u, active_layer_->tilings()->num_tilings());
890 EXPECT_FLOAT_EQ(0.24f, 1016 EXPECT_FLOAT_EQ(0.24f,
891 active_layer()->tilings()->tiling_at(0)->contents_scale()); 1017 active_layer_->tilings()->tiling_at(0)->contents_scale());
892 EXPECT_FLOAT_EQ(0.12f, 1018 EXPECT_FLOAT_EQ(0.12f,
893 active_layer()->tilings()->tiling_at(1)->contents_scale()); 1019 active_layer_->tilings()->tiling_at(1)->contents_scale());
894 EXPECT_FLOAT_EQ(0.0625, 1020 EXPECT_FLOAT_EQ(0.0625,
895 active_layer()->tilings()->tiling_at(2)->contents_scale()); 1021 active_layer_->tilings()->tiling_at(2)->contents_scale());
896 1022
897 // Ensure UpdateTiles won't remove any tilings. 1023 // Ensure UpdateTiles won't remove any tilings.
898 active_layer()->MarkAllTilingsUsed(); 1024 active_layer_->MarkAllTilingsUsed();
899 1025
900 // Zoom out further, close to our low-res scale factor. We should 1026 // Zoom out further, close to our low-res scale factor. We should
901 // use that tiling as high-res, and not create a new tiling. 1027 // use that tiling as high-res, and not create a new tiling.
902 SetContentsScaleOnBothLayers(0.1f, 1.0f, 0.1f, 1.0f, 0.f, false); 1028 SetContentsScaleOnBothLayers(0.1f, 1.0f, 0.1f, 1.0f, 0.f, false);
903 EXPECT_EQ(3u, active_layer()->tilings()->num_tilings()); 1029 EXPECT_EQ(3u, active_layer_->tilings()->num_tilings());
904 1030
905 // Zoom in. 0.25(desired_scale) should be snapped to 0.24 during zoom-in 1031 // Zoom in. 0.25(desired_scale) should be snapped to 0.24 during zoom-in
906 // because 0.25(desired_scale) is within the ratio(1.2). 1032 // because 0.25(desired_scale) is within the ratio(1.2).
907 SetContentsScaleOnBothLayers(0.25f, 1.0f, 0.25f, 1.0f, 0.f, false); 1033 SetContentsScaleOnBothLayers(0.25f, 1.0f, 0.25f, 1.0f, 0.f, false);
908 EXPECT_EQ(3u, active_layer()->tilings()->num_tilings()); 1034 EXPECT_EQ(3u, active_layer_->tilings()->num_tilings());
909 1035
910 // Zoom in a lot. Since we move in factors of two, we should get a scale that 1036 // Zoom in a lot. Since we move in factors of two, we should get a scale that
911 // is a power of 2 times 0.24. 1037 // is a power of 2 times 0.24.
912 SetContentsScaleOnBothLayers(1.f, 1.0f, 1.f, 1.0f, 0.f, false); 1038 SetContentsScaleOnBothLayers(1.f, 1.0f, 1.f, 1.0f, 0.f, false);
913 EXPECT_EQ(4u, active_layer()->tilings()->num_tilings()); 1039 EXPECT_EQ(4u, active_layer_->tilings()->num_tilings());
914 EXPECT_FLOAT_EQ(1.92f, 1040 EXPECT_FLOAT_EQ(1.92f,
915 active_layer()->tilings()->tiling_at(0)->contents_scale()); 1041 active_layer_->tilings()->tiling_at(0)->contents_scale());
916 } 1042 }
917 1043
918 TEST_F(PictureLayerImplTest, CleanUpTilings) { 1044 TEST_F(PictureLayerImplTest, CleanUpTilings) {
919 gfx::Size layer_bounds(1300, 1900); 1045 gfx::Size layer_bounds(1300, 1900);
920 1046
921 std::vector<PictureLayerTiling*> used_tilings; 1047 std::vector<PictureLayerTiling*> used_tilings;
922 1048
923 float low_res_factor = host_impl()->settings().low_res_contents_scale_factor; 1049 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
924 EXPECT_LT(low_res_factor, 1.f); 1050 EXPECT_LT(low_res_factor, 1.f);
925 1051
926 float scale = 1.f; 1052 float scale = 1.f;
927 float page_scale = 1.f; 1053 float page_scale = 1.f;
928 1054
929 SetupDefaultTrees(layer_bounds); 1055 SetupDefaultTrees(layer_bounds);
930 EXPECT_EQ(2u, active_layer()->tilings()->num_tilings()); 1056 EXPECT_EQ(2u, active_layer_->tilings()->num_tilings());
931 EXPECT_EQ(1.f, active_layer()->HighResTiling()->contents_scale()); 1057 EXPECT_EQ(1.f, active_layer_->HighResTiling()->contents_scale());
932 1058
933 // Ensure UpdateTiles won't remove any tilings. Note this is unrelated to 1059 // Ensure UpdateTiles won't remove any tilings. Note this is unrelated to
934 // |used_tilings| variable, and it's here only to ensure that active_layer() 1060 // |used_tilings| variable, and it's here only to ensure that active_layer_
935 // won't remove tilings before the test has a chance to verify behavior. 1061 // won't remove tilings before the test has a chance to verify behavior.
936 active_layer()->MarkAllTilingsUsed(); 1062 active_layer_->MarkAllTilingsUsed();
937 1063
938 // We only have ideal tilings, so they aren't removed. 1064 // We only have ideal tilings, so they aren't removed.
939 used_tilings.clear(); 1065 used_tilings.clear();
940 active_layer()->CleanUpTilingsOnActiveLayer(used_tilings); 1066 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
941 EXPECT_EQ(2u, active_layer()->tilings()->num_tilings()); 1067 EXPECT_EQ(2u, active_layer_->tilings()->num_tilings());
942 1068
943 host_impl()->PinchGestureBegin(); 1069 host_impl_.PinchGestureBegin();
944 1070
945 // Changing the ideal but not creating new tilings. 1071 // Changing the ideal but not creating new tilings.
946 scale = 1.5f; 1072 scale = 1.5f;
947 page_scale = 1.5f; 1073 page_scale = 1.5f;
948 SetContentsScaleOnBothLayers(scale, 1.f, page_scale, 1.f, 0.f, false); 1074 SetContentsScaleOnBothLayers(scale, 1.f, page_scale, 1.f, 0.f, false);
949 EXPECT_EQ(2u, active_layer()->tilings()->num_tilings()); 1075 EXPECT_EQ(2u, active_layer_->tilings()->num_tilings());
950 1076
951 // The tilings are still our target scale, so they aren't removed. 1077 // The tilings are still our target scale, so they aren't removed.
952 used_tilings.clear(); 1078 used_tilings.clear();
953 active_layer()->CleanUpTilingsOnActiveLayer(used_tilings); 1079 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
954 ASSERT_EQ(2u, active_layer()->tilings()->num_tilings()); 1080 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
955 1081
956 host_impl()->PinchGestureEnd(); 1082 host_impl_.PinchGestureEnd();
957 1083
958 // Create a 1.2 scale tiling. Now we have 1.0 and 1.2 tilings. Ideal = 1.2. 1084 // Create a 1.2 scale tiling. Now we have 1.0 and 1.2 tilings. Ideal = 1.2.
959 scale = 1.2f; 1085 scale = 1.2f;
960 page_scale = 1.2f; 1086 page_scale = 1.2f;
961 SetContentsScaleOnBothLayers(1.2f, 1.f, page_scale, 1.f, 0.f, false); 1087 SetContentsScaleOnBothLayers(1.2f, 1.f, page_scale, 1.f, 0.f, false);
962 ASSERT_EQ(4u, active_layer()->tilings()->num_tilings()); 1088 ASSERT_EQ(4u, active_layer_->tilings()->num_tilings());
963 EXPECT_FLOAT_EQ(1.f, 1089 EXPECT_FLOAT_EQ(
964 active_layer()->tilings()->tiling_at(1)->contents_scale()); 1090 1.f,
965 EXPECT_FLOAT_EQ(1.f * low_res_factor, 1091 active_layer_->tilings()->tiling_at(1)->contents_scale());
966 active_layer()->tilings()->tiling_at(3)->contents_scale()); 1092 EXPECT_FLOAT_EQ(
1093 1.f * low_res_factor,
1094 active_layer_->tilings()->tiling_at(3)->contents_scale());
967 1095
968 // Ensure UpdateTiles won't remove any tilings. 1096 // Ensure UpdateTiles won't remove any tilings.
969 active_layer()->MarkAllTilingsUsed(); 1097 active_layer_->MarkAllTilingsUsed();
970 1098
971 // Mark the non-ideal tilings as used. They won't be removed. 1099 // Mark the non-ideal tilings as used. They won't be removed.
972 used_tilings.clear(); 1100 used_tilings.clear();
973 used_tilings.push_back(active_layer()->tilings()->tiling_at(1)); 1101 used_tilings.push_back(active_layer_->tilings()->tiling_at(1));
974 used_tilings.push_back(active_layer()->tilings()->tiling_at(3)); 1102 used_tilings.push_back(active_layer_->tilings()->tiling_at(3));
975 active_layer()->CleanUpTilingsOnActiveLayer(used_tilings); 1103 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
976 ASSERT_EQ(4u, active_layer()->tilings()->num_tilings()); 1104 ASSERT_EQ(4u, active_layer_->tilings()->num_tilings());
977 1105
978 // Now move the ideal scale to 0.5. Our target stays 1.2. 1106 // Now move the ideal scale to 0.5. Our target stays 1.2.
979 SetContentsScaleOnBothLayers(0.5f, 1.f, page_scale, 1.f, 0.f, false); 1107 SetContentsScaleOnBothLayers(0.5f, 1.f, page_scale, 1.f, 0.f, false);
980 1108
981 // The high resolution tiling is between target and ideal, so is not 1109 // The high resolution tiling is between target and ideal, so is not
982 // removed. The low res tiling for the old ideal=1.0 scale is removed. 1110 // removed. The low res tiling for the old ideal=1.0 scale is removed.
983 used_tilings.clear(); 1111 used_tilings.clear();
984 active_layer()->CleanUpTilingsOnActiveLayer(used_tilings); 1112 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
985 ASSERT_EQ(3u, active_layer()->tilings()->num_tilings()); 1113 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings());
986 1114
987 // Now move the ideal scale to 1.0. Our target stays 1.2. 1115 // Now move the ideal scale to 1.0. Our target stays 1.2.
988 SetContentsScaleOnBothLayers(1.f, 1.f, page_scale, 1.f, 0.f, false); 1116 SetContentsScaleOnBothLayers(1.f, 1.f, page_scale, 1.f, 0.f, false);
989 1117
990 // All the tilings are between are target and the ideal, so they are not 1118 // All the tilings are between are target and the ideal, so they are not
991 // removed. 1119 // removed.
992 used_tilings.clear(); 1120 used_tilings.clear();
993 active_layer()->CleanUpTilingsOnActiveLayer(used_tilings); 1121 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
994 ASSERT_EQ(3u, active_layer()->tilings()->num_tilings()); 1122 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings());
995 1123
996 // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2. 1124 // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2.
997 SetupDrawPropertiesAndUpdateTiles(active_layer(), 1.1f, 1.f, page_scale, 1.f, 1125 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.1f, 1.f, page_scale, 1.f,
998 0.f, false); 1126 0.f, false);
999 1127
1000 // Because the pending layer's ideal scale is still 1.0, our tilings fall 1128 // Because the pending layer's ideal scale is still 1.0, our tilings fall
1001 // in the range [1.0,1.2] and are kept. 1129 // in the range [1.0,1.2] and are kept.
1002 used_tilings.clear(); 1130 used_tilings.clear();
1003 active_layer()->CleanUpTilingsOnActiveLayer(used_tilings); 1131 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
1004 ASSERT_EQ(3u, active_layer()->tilings()->num_tilings()); 1132 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings());
1005 1133
1006 // Move the ideal scale on the pending layer to 1.1 as well. Our target stays 1134 // Move the ideal scale on the pending layer to 1.1 as well. Our target stays
1007 // 1.2 still. 1135 // 1.2 still.
1008 SetupDrawPropertiesAndUpdateTiles(pending_layer(), 1.1f, 1.f, page_scale, 1.f, 1136 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.1f, 1.f, page_scale, 1.f,
1009 0.f, false); 1137 0.f, false);
1010 1138
1011 // Our 1.0 tiling now falls outside the range between our ideal scale and our 1139 // Our 1.0 tiling now falls outside the range between our ideal scale and our
1012 // target raster scale. But it is in our used tilings set, so nothing is 1140 // target raster scale. But it is in our used tilings set, so nothing is
1013 // deleted. 1141 // deleted.
1014 used_tilings.clear(); 1142 used_tilings.clear();
1015 used_tilings.push_back(active_layer()->tilings()->tiling_at(1)); 1143 used_tilings.push_back(active_layer_->tilings()->tiling_at(1));
1016 active_layer()->CleanUpTilingsOnActiveLayer(used_tilings); 1144 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
1017 ASSERT_EQ(3u, active_layer()->tilings()->num_tilings()); 1145 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings());
1018 1146
1019 // If we remove it from our used tilings set, it is outside the range to keep 1147 // If we remove it from our used tilings set, it is outside the range to keep
1020 // so it is deleted. 1148 // so it is deleted.
1021 used_tilings.clear(); 1149 used_tilings.clear();
1022 active_layer()->CleanUpTilingsOnActiveLayer(used_tilings); 1150 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
1023 ASSERT_EQ(2u, active_layer()->tilings()->num_tilings()); 1151 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
1024 } 1152 }
1025 1153
1026 TEST_F(PictureLayerImplTest, DontAddLowResDuringAnimation) { 1154 TEST_F(PictureLayerImplTest, DontAddLowResDuringAnimation) {
1027 // Make sure this layer covers multiple tiles, since otherwise low 1155 // Make sure this layer covers multiple tiles, since otherwise low
1028 // res won't get created because it is too small. 1156 // res won't get created because it is too small.
1029 gfx::Size tile_size(host_impl()->settings().default_tile_size); 1157 gfx::Size tile_size(host_impl_.settings().default_tile_size);
1030 // Avoid max untiled layer size heuristics via fixed tile size. 1158 // Avoid max untiled layer size heuristics via fixed tile size.
1031 gfx::Size layer_bounds(tile_size.width() + 1, tile_size.height() + 1); 1159 gfx::Size layer_bounds(tile_size.width() + 1, tile_size.height() + 1);
1032 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, Region()); 1160 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, Region());
1033 1161
1034 float low_res_factor = host_impl()->settings().low_res_contents_scale_factor; 1162 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
1035 float contents_scale = 1.f; 1163 float contents_scale = 1.f;
1036 float device_scale = 1.f; 1164 float device_scale = 1.f;
1037 float page_scale = 1.f; 1165 float page_scale = 1.f;
1038 float maximum_animation_scale = 1.f; 1166 float maximum_animation_scale = 1.f;
1039 float starting_animation_scale = 0.f; 1167 float starting_animation_scale = 0.f;
1040 bool animating_transform = true; 1168 bool animating_transform = true;
1041 1169
1042 ResetTilingsAndRasterScales(); 1170 ResetTilingsAndRasterScales();
1043 1171
1044 // Animating, so don't create low res even if there isn't one already. 1172 // Animating, so don't create low res even if there isn't one already.
1045 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale, 1173 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale,
1046 maximum_animation_scale, 1174 maximum_animation_scale,
1047 starting_animation_scale, animating_transform); 1175 starting_animation_scale, animating_transform);
1048 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f); 1176 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f);
1049 EXPECT_BOTH_EQ(num_tilings(), 1u); 1177 EXPECT_BOTH_EQ(num_tilings(), 1u);
1050 1178
1051 // Stop animating, low res gets created. 1179 // Stop animating, low res gets created.
1052 animating_transform = false; 1180 animating_transform = false;
1053 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale, 1181 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale,
1054 maximum_animation_scale, 1182 maximum_animation_scale,
1055 starting_animation_scale, animating_transform); 1183 starting_animation_scale, animating_transform);
1056 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f); 1184 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f);
1057 EXPECT_EQ(active_layer()->LowResTiling()->contents_scale(), low_res_factor); 1185 EXPECT_EQ(active_layer_->LowResTiling()->contents_scale(), low_res_factor);
1058 EXPECT_EQ(active_layer()->num_tilings(), 2u); 1186 EXPECT_EQ(active_layer_->num_tilings(), 2u);
1059 EXPECT_EQ(pending_layer()->num_tilings(), 1u); 1187 EXPECT_EQ(pending_layer_->num_tilings(), 1u);
1060 1188
1061 // Ensure UpdateTiles won't remove any tilings. 1189 // Ensure UpdateTiles won't remove any tilings.
1062 active_layer()->MarkAllTilingsUsed(); 1190 active_layer_->MarkAllTilingsUsed();
1063 1191
1064 // Page scale animation, new high res, but no low res. We still have 1192 // Page scale animation, new high res, but no low res. We still have
1065 // a tiling at the previous scale, it's just not marked as low res on the 1193 // a tiling at the previous scale, it's just not marked as low res on the
1066 // active layer. The pending layer drops non-ideal tilings. 1194 // active layer. The pending layer drops non-ideal tilings.
1067 contents_scale = 2.f; 1195 contents_scale = 2.f;
1068 page_scale = 2.f; 1196 page_scale = 2.f;
1069 maximum_animation_scale = 2.f; 1197 maximum_animation_scale = 2.f;
1070 animating_transform = true; 1198 animating_transform = true;
1071 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale, 1199 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale,
1072 maximum_animation_scale, 1200 maximum_animation_scale,
1073 starting_animation_scale, animating_transform); 1201 starting_animation_scale, animating_transform);
1074 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f); 1202 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f);
1075 EXPECT_FALSE(active_layer()->LowResTiling()); 1203 EXPECT_FALSE(active_layer_->LowResTiling());
1076 EXPECT_FALSE(pending_layer()->LowResTiling()); 1204 EXPECT_FALSE(pending_layer_->LowResTiling());
1077 EXPECT_EQ(3u, active_layer()->num_tilings()); 1205 EXPECT_EQ(3u, active_layer_->num_tilings());
1078 EXPECT_EQ(1u, pending_layer()->num_tilings()); 1206 EXPECT_EQ(1u, pending_layer_->num_tilings());
1079 1207
1080 // Stop animating, new low res gets created for final page scale. 1208 // Stop animating, new low res gets created for final page scale.
1081 animating_transform = false; 1209 animating_transform = false;
1082 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale, 1210 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale,
1083 maximum_animation_scale, 1211 maximum_animation_scale,
1084 starting_animation_scale, animating_transform); 1212 starting_animation_scale, animating_transform);
1085 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f); 1213 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f);
1086 EXPECT_EQ(active_layer()->LowResTiling()->contents_scale(), 1214 EXPECT_EQ(active_layer_->LowResTiling()->contents_scale(),
1087 2.f * low_res_factor); 1215 2.f * low_res_factor);
1088 EXPECT_EQ(4u, active_layer()->num_tilings()); 1216 EXPECT_EQ(4u, active_layer_->num_tilings());
1089 EXPECT_EQ(1u, pending_layer()->num_tilings()); 1217 EXPECT_EQ(1u, pending_layer_->num_tilings());
1090 } 1218 }
1091 1219
1092 TEST_F(PictureLayerImplTest, DontAddLowResForSmallLayers) { 1220 TEST_F(PictureLayerImplTest, DontAddLowResForSmallLayers) {
1093 gfx::Size layer_bounds(host_impl()->settings().default_tile_size); 1221 gfx::Size layer_bounds(host_impl_.settings().default_tile_size);
1094 1222
1095 scoped_refptr<FakeRasterSource> pending_raster_source = 1223 scoped_refptr<FakeRasterSource> pending_raster_source =
1096 FakeRasterSource::CreateFilled(layer_bounds); 1224 FakeRasterSource::CreateFilled(layer_bounds);
1097 scoped_refptr<FakeRasterSource> active_raster_source = 1225 scoped_refptr<FakeRasterSource> active_raster_source =
1098 FakeRasterSource::CreateFilled(layer_bounds); 1226 FakeRasterSource::CreateFilled(layer_bounds);
1099 1227
1100 SetupTrees(pending_raster_source, active_raster_source); 1228 SetupTrees(pending_raster_source, active_raster_source);
1101 1229
1102 float low_res_factor = host_impl()->settings().low_res_contents_scale_factor; 1230 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
1103 float device_scale = 1.f; 1231 float device_scale = 1.f;
1104 float page_scale = 1.f; 1232 float page_scale = 1.f;
1105 float maximum_animation_scale = 1.f; 1233 float maximum_animation_scale = 1.f;
1106 float starting_animation_scale = 0.f; 1234 float starting_animation_scale = 0.f;
1107 bool animating_transform = false; 1235 bool animating_transform = false;
1108 1236
1109 // Contents exactly fit on one tile at scale 1, no low res. 1237 // Contents exactly fit on one tile at scale 1, no low res.
1110 float contents_scale = 1.f; 1238 float contents_scale = 1.f;
1111 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale, 1239 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale,
1112 maximum_animation_scale, 1240 maximum_animation_scale,
(...skipping 14 matching lines...) Expand all
1127 // TODO(danakj): Remove these when raster scale doesn't get fixed? 1255 // TODO(danakj): Remove these when raster scale doesn't get fixed?
1128 ResetTilingsAndRasterScales(); 1256 ResetTilingsAndRasterScales();
1129 1257
1130 // Any content bounds that would create more than one tile will 1258 // Any content bounds that would create more than one tile will
1131 // generate a low res tiling. 1259 // generate a low res tiling.
1132 contents_scale = 2.5f; 1260 contents_scale = 2.5f;
1133 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale, 1261 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale,
1134 maximum_animation_scale, 1262 maximum_animation_scale,
1135 starting_animation_scale, animating_transform); 1263 starting_animation_scale, animating_transform);
1136 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale); 1264 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale);
1137 EXPECT_EQ(active_layer()->LowResTiling()->contents_scale(), 1265 EXPECT_EQ(active_layer_->LowResTiling()->contents_scale(),
1138 contents_scale * low_res_factor); 1266 contents_scale * low_res_factor);
1139 EXPECT_FALSE(pending_layer()->LowResTiling()); 1267 EXPECT_FALSE(pending_layer_->LowResTiling());
1140 EXPECT_EQ(active_layer()->num_tilings(), 2u); 1268 EXPECT_EQ(active_layer_->num_tilings(), 2u);
1141 EXPECT_EQ(pending_layer()->num_tilings(), 1u); 1269 EXPECT_EQ(pending_layer_->num_tilings(), 1u);
1142 1270
1143 // Mask layers dont create low res since they always fit on one tile. 1271 // Mask layers dont create low res since they always fit on one tile.
1144 std::unique_ptr<FakePictureLayerImpl> mask = 1272 std::unique_ptr<FakePictureLayerImpl> mask =
1145 FakePictureLayerImpl::CreateMaskWithRasterSource( 1273 FakePictureLayerImpl::CreateMaskWithRasterSource(
1146 host_impl()->pending_tree(), 3, pending_raster_source); 1274 host_impl_.pending_tree(), 3, pending_raster_source);
1147 mask->SetBounds(layer_bounds); 1275 mask->SetBounds(layer_bounds);
1148 mask->SetDrawsContent(true); 1276 mask->SetDrawsContent(true);
1149 pending_layer()->SetMaskLayer(std::move(mask)); 1277 pending_layer_->SetMaskLayer(std::move(mask));
1150 pending_layer()->SetHasRenderSurface(true); 1278 pending_layer_->SetHasRenderSurface(true);
1151 RebuildPropertyTreesOnPendingTree(); 1279 RebuildPropertyTreesOnPendingTree();
1152 host_impl()->pending_tree()->UpdateDrawProperties(false); 1280 host_impl_.pending_tree()->UpdateDrawProperties(false);
1153 1281
1154 FakePictureLayerImpl* mask_raw = 1282 FakePictureLayerImpl* mask_raw =
1155 static_cast<FakePictureLayerImpl*>(pending_layer()->mask_layer()); 1283 static_cast<FakePictureLayerImpl*>(pending_layer_->mask_layer());
1156 // We did an UpdateDrawProperties above, which will set a contents scale on 1284 // We did an UpdateDrawProperties above, which will set a contents scale on
1157 // the mask layer, so allow us to reset the contents scale. 1285 // the mask layer, so allow us to reset the contents scale.
1158 mask_raw->ReleaseResources(); 1286 mask_raw->ReleaseResources();
1159 mask_raw->RecreateResources(); 1287 mask_raw->RecreateResources();
1160 1288
1161 SetupDrawPropertiesAndUpdateTiles( 1289 SetupDrawPropertiesAndUpdateTiles(
1162 mask_raw, contents_scale, device_scale, page_scale, 1290 mask_raw, contents_scale, device_scale, page_scale,
1163 maximum_animation_scale, starting_animation_scale, animating_transform); 1291 maximum_animation_scale, starting_animation_scale, animating_transform);
1164 EXPECT_EQ(mask_raw->HighResTiling()->contents_scale(), contents_scale); 1292 EXPECT_EQ(mask_raw->HighResTiling()->contents_scale(), contents_scale);
1165 EXPECT_EQ(mask_raw->num_tilings(), 1u); 1293 EXPECT_EQ(mask_raw->num_tilings(), 1u);
1166 } 1294 }
1167 1295
1168 TEST_F(PictureLayerImplTest, HugeMasksGetScaledDown) { 1296 TEST_F(PictureLayerImplTest, HugeMasksGetScaledDown) {
1169 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); 1297 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1170 1298
1171 gfx::Size layer_bounds(1000, 1000); 1299 gfx::Size layer_bounds(1000, 1000);
1172 1300
1173 scoped_refptr<FakeRasterSource> valid_raster_source = 1301 scoped_refptr<FakeRasterSource> valid_raster_source =
1174 FakeRasterSource::CreateFilled(layer_bounds); 1302 FakeRasterSource::CreateFilled(layer_bounds);
1175 SetupPendingTree(valid_raster_source); 1303 SetupPendingTree(valid_raster_source);
1176 1304
1177 std::unique_ptr<FakePictureLayerImpl> mask_ptr = 1305 std::unique_ptr<FakePictureLayerImpl> mask_ptr =
1178 FakePictureLayerImpl::CreateMaskWithRasterSource( 1306 FakePictureLayerImpl::CreateMaskWithRasterSource(
1179 host_impl()->pending_tree(), 3, valid_raster_source); 1307 host_impl_.pending_tree(), 3, valid_raster_source);
1180 mask_ptr->SetBounds(layer_bounds); 1308 mask_ptr->SetBounds(layer_bounds);
1181 mask_ptr->SetDrawsContent(true); 1309 mask_ptr->SetDrawsContent(true);
1182 pending_layer()->SetMaskLayer(std::move(mask_ptr)); 1310 pending_layer_->SetMaskLayer(std::move(mask_ptr));
1183 pending_layer()->test_properties()->force_render_surface = true; 1311 pending_layer_->test_properties()->force_render_surface = true;
1184 1312
1185 RebuildPropertyTreesOnPendingTree(); 1313 RebuildPropertyTreesOnPendingTree();
1186 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); 1314 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1187 bool update_lcd_text = false; 1315 bool update_lcd_text = false;
1188 host_impl()->pending_tree()->UpdateDrawProperties(update_lcd_text); 1316 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
1189 1317
1190 FakePictureLayerImpl* pending_mask = 1318 FakePictureLayerImpl* pending_mask =
1191 static_cast<FakePictureLayerImpl*>(pending_layer()->mask_layer()); 1319 static_cast<FakePictureLayerImpl*>(pending_layer_->mask_layer());
1192 1320
1193 EXPECT_EQ(1.f, pending_mask->HighResTiling()->contents_scale()); 1321 EXPECT_EQ(1.f, pending_mask->HighResTiling()->contents_scale());
1194 EXPECT_EQ(1u, pending_mask->num_tilings()); 1322 EXPECT_EQ(1u, pending_mask->num_tilings());
1195 1323
1196 host_impl()->tile_manager()->InitializeTilesWithResourcesForTesting( 1324 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(
1197 pending_mask->HighResTiling()->AllTilesForTesting()); 1325 pending_mask->HighResTiling()->AllTilesForTesting());
1198 1326
1199 ActivateTree(); 1327 ActivateTree();
1200 1328
1201 FakePictureLayerImpl* active_mask = 1329 FakePictureLayerImpl* active_mask =
1202 static_cast<FakePictureLayerImpl*>(active_layer()->mask_layer()); 1330 static_cast<FakePictureLayerImpl*>(active_layer_->mask_layer());
1203 1331
1204 // Mask layers have a tiling with a single tile in it. 1332 // Mask layers have a tiling with a single tile in it.
1205 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size()); 1333 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size());
1206 // The mask resource exists. 1334 // The mask resource exists.
1207 ResourceId mask_resource_id; 1335 ResourceId mask_resource_id;
1208 gfx::Size mask_texture_size; 1336 gfx::Size mask_texture_size;
1209 active_mask->GetContentsResourceId(&mask_resource_id, &mask_texture_size); 1337 active_mask->GetContentsResourceId(&mask_resource_id, &mask_texture_size);
1210 EXPECT_NE(0u, mask_resource_id); 1338 EXPECT_NE(0u, mask_resource_id);
1211 EXPECT_EQ(active_mask->bounds(), mask_texture_size); 1339 EXPECT_EQ(active_mask->bounds(), mask_texture_size);
1212 1340
1213 // Drop resources and recreate them, still the same. 1341 // Drop resources and recreate them, still the same.
1214 pending_mask->ReleaseResources(); 1342 pending_mask->ReleaseResources();
1215 active_mask->ReleaseResources(); 1343 active_mask->ReleaseResources();
1216 pending_mask->RecreateResources(); 1344 pending_mask->RecreateResources();
1217 active_mask->RecreateResources(); 1345 active_mask->RecreateResources();
1218 SetupDrawPropertiesAndUpdateTiles(active_mask, 1.f, 1.f, 1.f, 1.f, 0.f, 1346 SetupDrawPropertiesAndUpdateTiles(active_mask, 1.f, 1.f, 1.f, 1.f, 0.f,
1219 false); 1347 false);
1220 active_mask->HighResTiling()->CreateAllTilesForTesting(); 1348 active_mask->HighResTiling()->CreateAllTilesForTesting();
1221 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size()); 1349 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size());
1222 EXPECT_NE(0u, mask_resource_id); 1350 EXPECT_NE(0u, mask_resource_id);
1223 EXPECT_EQ(active_mask->bounds(), mask_texture_size); 1351 EXPECT_EQ(active_mask->bounds(), mask_texture_size);
1224 1352
1225 // Resize larger than the max texture size. 1353 // Resize larger than the max texture size.
1226 int max_texture_size = 1354 int max_texture_size = host_impl_.GetRendererCapabilities().max_texture_size;
1227 host_impl()->GetRendererCapabilities().max_texture_size;
1228 gfx::Size huge_bounds(max_texture_size + 1, 10); 1355 gfx::Size huge_bounds(max_texture_size + 1, 10);
1229 scoped_refptr<FakeRasterSource> huge_raster_source = 1356 scoped_refptr<FakeRasterSource> huge_raster_source =
1230 FakeRasterSource::CreateFilled(huge_bounds); 1357 FakeRasterSource::CreateFilled(huge_bounds);
1231 1358
1232 SetupPendingTree(huge_raster_source); 1359 SetupPendingTree(huge_raster_source);
1233 pending_mask->SetBounds(huge_bounds); 1360 pending_mask->SetBounds(huge_bounds);
1234 pending_mask->SetRasterSourceOnPending(huge_raster_source, Region()); 1361 pending_mask->SetRasterSourceOnPending(huge_raster_source, Region());
1235 1362
1236 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); 1363 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1237 host_impl()->pending_tree()->UpdateDrawProperties(update_lcd_text); 1364 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
1238 1365
1239 // The mask tiling gets scaled down. 1366 // The mask tiling gets scaled down.
1240 EXPECT_LT(pending_mask->HighResTiling()->contents_scale(), 1.f); 1367 EXPECT_LT(pending_mask->HighResTiling()->contents_scale(), 1.f);
1241 EXPECT_EQ(1u, pending_mask->num_tilings()); 1368 EXPECT_EQ(1u, pending_mask->num_tilings());
1242 1369
1243 host_impl()->tile_manager()->InitializeTilesWithResourcesForTesting( 1370 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(
1244 pending_mask->HighResTiling()->AllTilesForTesting()); 1371 pending_mask->HighResTiling()->AllTilesForTesting());
1245 1372
1246 ActivateTree(); 1373 ActivateTree();
1247 1374
1248 // Mask layers have a tiling with a single tile in it. 1375 // Mask layers have a tiling with a single tile in it.
1249 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size()); 1376 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size());
1250 // The mask resource exists. 1377 // The mask resource exists.
1251 active_mask->GetContentsResourceId(&mask_resource_id, &mask_texture_size); 1378 active_mask->GetContentsResourceId(&mask_resource_id, &mask_texture_size);
1252 EXPECT_NE(0u, mask_resource_id); 1379 EXPECT_NE(0u, mask_resource_id);
1253 gfx::Size expected_size = active_mask->bounds(); 1380 gfx::Size expected_size = active_mask->bounds();
1254 expected_size.SetToMin(gfx::Size(max_texture_size, max_texture_size)); 1381 expected_size.SetToMin(gfx::Size(max_texture_size, max_texture_size));
1255 EXPECT_EQ(expected_size, mask_texture_size); 1382 EXPECT_EQ(expected_size, mask_texture_size);
1256 1383
1257 // Drop resources and recreate them, still the same. 1384 // Drop resources and recreate them, still the same.
1258 pending_mask->ReleaseResources(); 1385 pending_mask->ReleaseResources();
1259 active_mask->ReleaseResources(); 1386 active_mask->ReleaseResources();
1260 pending_mask->RecreateResources(); 1387 pending_mask->RecreateResources();
1261 active_mask->RecreateResources(); 1388 active_mask->RecreateResources();
1262 SetupDrawPropertiesAndUpdateTiles(active_mask, 1.f, 1.f, 1.f, 1.f, 0.f, 1389 SetupDrawPropertiesAndUpdateTiles(active_mask, 1.f, 1.f, 1.f, 1.f, 0.f,
1263 false); 1390 false);
1264 active_mask->HighResTiling()->CreateAllTilesForTesting(); 1391 active_mask->HighResTiling()->CreateAllTilesForTesting();
1265 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size()); 1392 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size());
1266 EXPECT_NE(0u, mask_resource_id); 1393 EXPECT_NE(0u, mask_resource_id);
1267 EXPECT_EQ(expected_size, mask_texture_size); 1394 EXPECT_EQ(expected_size, mask_texture_size);
1268 1395
1269 // Do another activate, the same holds. 1396 // Do another activate, the same holds.
1270 SetupPendingTree(huge_raster_source); 1397 SetupPendingTree(huge_raster_source);
1271 ActivateTree(); 1398 ActivateTree();
1272 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size()); 1399 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size());
1273 active_layer()->GetContentsResourceId(&mask_resource_id, &mask_texture_size); 1400 active_layer_->GetContentsResourceId(&mask_resource_id, &mask_texture_size);
1274 EXPECT_EQ(expected_size, mask_texture_size); 1401 EXPECT_EQ(expected_size, mask_texture_size);
1275 EXPECT_EQ(0u, mask_resource_id); 1402 EXPECT_EQ(0u, mask_resource_id);
1276 1403
1277 // Resize even larger, so that the scale would be smaller than the minimum 1404 // Resize even larger, so that the scale would be smaller than the minimum
1278 // contents scale. Then the layer should no longer have any tiling. 1405 // contents scale. Then the layer should no longer have any tiling.
1279 float min_contents_scale = host_impl()->settings().minimum_contents_scale; 1406 float min_contents_scale = host_impl_.settings().minimum_contents_scale;
1280 gfx::Size extra_huge_bounds(max_texture_size / min_contents_scale + 1, 10); 1407 gfx::Size extra_huge_bounds(max_texture_size / min_contents_scale + 1, 10);
1281 scoped_refptr<FakeRasterSource> extra_huge_raster_source = 1408 scoped_refptr<FakeRasterSource> extra_huge_raster_source =
1282 FakeRasterSource::CreateFilled(extra_huge_bounds); 1409 FakeRasterSource::CreateFilled(extra_huge_bounds);
1283 1410
1284 SetupPendingTree(extra_huge_raster_source); 1411 SetupPendingTree(extra_huge_raster_source);
1285 pending_mask->SetBounds(extra_huge_bounds); 1412 pending_mask->SetBounds(extra_huge_bounds);
1286 pending_mask->SetRasterSourceOnPending(extra_huge_raster_source, Region()); 1413 pending_mask->SetRasterSourceOnPending(extra_huge_raster_source, Region());
1287 1414
1288 EXPECT_FALSE(pending_mask->CanHaveTilings()); 1415 EXPECT_FALSE(pending_mask->CanHaveTilings());
1289 1416
1290 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); 1417 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1291 host_impl()->pending_tree()->UpdateDrawProperties(update_lcd_text); 1418 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
1292 1419
1293 EXPECT_EQ(0u, pending_mask->num_tilings()); 1420 EXPECT_EQ(0u, pending_mask->num_tilings());
1294 } 1421 }
1295 1422
1296 TEST_F(PictureLayerImplTest, ScaledMaskLayer) { 1423 TEST_F(PictureLayerImplTest, ScaledMaskLayer) {
1297 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); 1424 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1298 1425
1299 gfx::Size layer_bounds(1000, 1000); 1426 gfx::Size layer_bounds(1000, 1000);
1300 1427
1301 SetInitialDeviceScaleFactor(1.3f); 1428 SetInitialDeviceScaleFactor(1.3f);
1302 1429
1303 scoped_refptr<FakeRasterSource> valid_raster_source = 1430 scoped_refptr<FakeRasterSource> valid_raster_source =
1304 FakeRasterSource::CreateFilled(layer_bounds); 1431 FakeRasterSource::CreateFilled(layer_bounds);
1305 SetupPendingTree(valid_raster_source); 1432 SetupPendingTree(valid_raster_source);
1306 1433
1307 std::unique_ptr<FakePictureLayerImpl> mask_ptr = 1434 std::unique_ptr<FakePictureLayerImpl> mask_ptr =
1308 FakePictureLayerImpl::CreateMaskWithRasterSource( 1435 FakePictureLayerImpl::CreateMaskWithRasterSource(
1309 host_impl()->pending_tree(), 3, valid_raster_source); 1436 host_impl_.pending_tree(), 3, valid_raster_source);
1310 mask_ptr->SetBounds(layer_bounds); 1437 mask_ptr->SetBounds(layer_bounds);
1311 mask_ptr->SetDrawsContent(true); 1438 mask_ptr->SetDrawsContent(true);
1312 pending_layer()->SetMaskLayer(std::move(mask_ptr)); 1439 pending_layer_->SetMaskLayer(std::move(mask_ptr));
1313 pending_layer()->test_properties()->force_render_surface = true; 1440 pending_layer_->test_properties()->force_render_surface = true;
1314 1441
1315 RebuildPropertyTreesOnPendingTree(); 1442 RebuildPropertyTreesOnPendingTree();
1316 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); 1443 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1317 bool update_lcd_text = false; 1444 bool update_lcd_text = false;
1318 host_impl()->pending_tree()->UpdateDrawProperties(update_lcd_text); 1445 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
1319 1446
1320 FakePictureLayerImpl* pending_mask = 1447 FakePictureLayerImpl* pending_mask =
1321 static_cast<FakePictureLayerImpl*>(pending_layer()->mask_layer()); 1448 static_cast<FakePictureLayerImpl*>(pending_layer_->mask_layer());
1322 1449
1323 // Masks are scaled, and do not have a low res tiling. 1450 // Masks are scaled, and do not have a low res tiling.
1324 EXPECT_EQ(1.3f, pending_mask->HighResTiling()->contents_scale()); 1451 EXPECT_EQ(1.3f, pending_mask->HighResTiling()->contents_scale());
1325 EXPECT_EQ(1u, pending_mask->num_tilings()); 1452 EXPECT_EQ(1u, pending_mask->num_tilings());
1326 1453
1327 host_impl()->tile_manager()->InitializeTilesWithResourcesForTesting( 1454 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(
1328 pending_mask->HighResTiling()->AllTilesForTesting()); 1455 pending_mask->HighResTiling()->AllTilesForTesting());
1329 1456
1330 ActivateTree(); 1457 ActivateTree();
1331 1458
1332 FakePictureLayerImpl* active_mask = 1459 FakePictureLayerImpl* active_mask =
1333 static_cast<FakePictureLayerImpl*>(active_layer()->mask_layer()); 1460 static_cast<FakePictureLayerImpl*>(active_layer_->mask_layer());
1334 1461
1335 // Mask layers have a tiling with a single tile in it. 1462 // Mask layers have a tiling with a single tile in it.
1336 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size()); 1463 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size());
1337 // The mask resource exists. 1464 // The mask resource exists.
1338 ResourceId mask_resource_id; 1465 ResourceId mask_resource_id;
1339 gfx::Size mask_texture_size; 1466 gfx::Size mask_texture_size;
1340 active_mask->GetContentsResourceId(&mask_resource_id, &mask_texture_size); 1467 active_mask->GetContentsResourceId(&mask_resource_id, &mask_texture_size);
1341 EXPECT_NE(0u, mask_resource_id); 1468 EXPECT_NE(0u, mask_resource_id);
1342 gfx::Size expected_mask_texture_size = 1469 gfx::Size expected_mask_texture_size =
1343 gfx::ScaleToCeiledSize(active_mask->bounds(), 1.3f); 1470 gfx::ScaleToCeiledSize(active_mask->bounds(), 1.3f);
1344 EXPECT_EQ(mask_texture_size, expected_mask_texture_size); 1471 EXPECT_EQ(mask_texture_size, expected_mask_texture_size);
1345 } 1472 }
1346 1473
1347 TEST_F(PictureLayerImplTest, ReleaseResources) { 1474 TEST_F(PictureLayerImplTest, ReleaseResources) {
1348 gfx::Size layer_bounds(1300, 1900); 1475 gfx::Size layer_bounds(1300, 1900);
1349 SetupDefaultTrees(layer_bounds); 1476 SetupDefaultTrees(layer_bounds);
1350 EXPECT_EQ(1u, pending_layer()->tilings()->num_tilings()); 1477 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings());
1351 1478
1352 // All tilings should be removed when losing output surface. 1479 // All tilings should be removed when losing output surface.
1353 active_layer()->ReleaseResources(); 1480 active_layer_->ReleaseResources();
1354 EXPECT_FALSE(active_layer()->tilings()); 1481 EXPECT_FALSE(active_layer_->tilings());
1355 active_layer()->RecreateResources(); 1482 active_layer_->RecreateResources();
1356 EXPECT_EQ(0u, active_layer()->tilings()->num_tilings()); 1483 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
1357 pending_layer()->ReleaseResources(); 1484 pending_layer_->ReleaseResources();
1358 EXPECT_FALSE(pending_layer()->tilings()); 1485 EXPECT_FALSE(pending_layer_->tilings());
1359 pending_layer()->RecreateResources(); 1486 pending_layer_->RecreateResources();
1360 EXPECT_EQ(0u, pending_layer()->tilings()->num_tilings()); 1487 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
1361 1488
1362 // This should create new tilings. 1489 // This should create new tilings.
1363 SetupDrawPropertiesAndUpdateTiles(pending_layer(), 1490 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
1364 1.f, // ideal contents scale 1491 1.f, // ideal contents scale
1365 1.f, // device scale 1492 1.f, // device scale
1366 1.f, // page scale 1493 1.f, // page scale
1367 1.f, // maximum animation scale 1494 1.f, // maximum animation scale
1368 0.f, // starting animation_scale 1495 0.f, // starting animation_scale
1369 false); 1496 false);
1370 EXPECT_EQ(1u, pending_layer()->tilings()->num_tilings()); 1497 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings());
1371 } 1498 }
1372 1499
1373 TEST_F(PictureLayerImplTest, ClampTilesToMaxTileSize) { 1500 TEST_F(PictureLayerImplTest, ClampTilesToMaxTileSize) {
1374 gfx::Size layer_bounds(5000, 5000); 1501 gfx::Size layer_bounds(5000, 5000);
1375 1502
1376 scoped_refptr<FakeRasterSource> pending_raster_source = 1503 scoped_refptr<FakeRasterSource> pending_raster_source =
1377 FakeRasterSource::CreateFilled(layer_bounds); 1504 FakeRasterSource::CreateFilled(layer_bounds);
1378 1505
1379 SetupPendingTree(pending_raster_source); 1506 SetupPendingTree(pending_raster_source);
1380 EXPECT_GE(pending_layer()->tilings()->num_tilings(), 1u); 1507 EXPECT_GE(pending_layer_->tilings()->num_tilings(), 1u);
1381 1508
1382 pending_layer()->tilings()->tiling_at(0)->CreateAllTilesForTesting(); 1509 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1383 1510
1384 // The default value. 1511 // The default value.
1385 EXPECT_EQ(gfx::Size(256, 256).ToString(), 1512 EXPECT_EQ(gfx::Size(256, 256).ToString(),
1386 host_impl()->settings().default_tile_size.ToString()); 1513 host_impl_.settings().default_tile_size.ToString());
1387 1514
1388 Tile* tile = 1515 Tile* tile = pending_layer_->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1389 pending_layer()->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1390 EXPECT_EQ(gfx::Size(256, 256).ToString(), 1516 EXPECT_EQ(gfx::Size(256, 256).ToString(),
1391 tile->content_rect().size().ToString()); 1517 tile->content_rect().size().ToString());
1392 1518
1393 ResetTilingsAndRasterScales(); 1519 ResetTilingsAndRasterScales();
1394 1520
1395 // Change the max texture size on the output surface context. 1521 // Change the max texture size on the output surface context.
1396 std::unique_ptr<TestWebGraphicsContext3D> context = 1522 std::unique_ptr<TestWebGraphicsContext3D> context =
1397 TestWebGraphicsContext3D::Create(); 1523 TestWebGraphicsContext3D::Create();
1398 context->set_max_texture_size(140); 1524 context->set_max_texture_size(140);
1399 ResetOutputSurface(FakeOutputSurface::Create3d(std::move(context))); 1525 host_impl_.DidLoseOutputSurface();
1526 std::unique_ptr<OutputSurface> new_output_surface =
1527 FakeOutputSurface::Create3d(std::move(context));
1528 host_impl_.SetVisible(true);
1529 host_impl_.InitializeRenderer(new_output_surface.get());
1530 output_surface_ = std::move(new_output_surface);
1400 1531
1401 SetupDrawPropertiesAndUpdateTiles(pending_layer(), 1.f, 1.f, 1.f, 1.f, 0.f, 1532 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.f, 1.f, 1.f, 1.f, 0.f,
1402 false); 1533 false);
1403 ASSERT_EQ(1u, pending_layer()->tilings()->num_tilings()); 1534 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
1404 1535
1405 pending_layer()->tilings()->tiling_at(0)->CreateAllTilesForTesting(); 1536 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1406 1537
1407 // Verify the tiles are not larger than the context's max texture size. 1538 // Verify the tiles are not larger than the context's max texture size.
1408 tile = pending_layer()->tilings()->tiling_at(0)->AllTilesForTesting()[0]; 1539 tile = pending_layer_->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1409 EXPECT_GE(140, tile->content_rect().width()); 1540 EXPECT_GE(140, tile->content_rect().width());
1410 EXPECT_GE(140, tile->content_rect().height()); 1541 EXPECT_GE(140, tile->content_rect().height());
1411 } 1542 }
1412 1543
1413 TEST_F(PictureLayerImplTest, ClampSingleTileToToMaxTileSize) { 1544 TEST_F(PictureLayerImplTest, ClampSingleTileToToMaxTileSize) {
1414 gfx::Size layer_bounds(500, 500); 1545 gfx::Size layer_bounds(500, 500);
1415 SetupDefaultTrees(layer_bounds); 1546 SetupDefaultTrees(layer_bounds);
1416 EXPECT_GE(active_layer()->tilings()->num_tilings(), 1u); 1547 EXPECT_GE(active_layer_->tilings()->num_tilings(), 1u);
1417 1548
1418 active_layer()->tilings()->tiling_at(0)->CreateAllTilesForTesting(); 1549 active_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1419 1550
1420 // The default value. The layer is smaller than this. 1551 // The default value. The layer is smaller than this.
1421 EXPECT_EQ(gfx::Size(512, 512).ToString(), 1552 EXPECT_EQ(gfx::Size(512, 512).ToString(),
1422 host_impl()->settings().max_untiled_layer_size.ToString()); 1553 host_impl_.settings().max_untiled_layer_size.ToString());
1423 1554
1424 // There should be a single tile since the layer is small. 1555 // There should be a single tile since the layer is small.
1425 PictureLayerTiling* high_res_tiling = active_layer()->tilings()->tiling_at(0); 1556 PictureLayerTiling* high_res_tiling = active_layer_->tilings()->tiling_at(0);
1426 EXPECT_EQ(1u, high_res_tiling->AllTilesForTesting().size()); 1557 EXPECT_EQ(1u, high_res_tiling->AllTilesForTesting().size());
1427 1558
1428 ResetTilingsAndRasterScales(); 1559 ResetTilingsAndRasterScales();
1429 1560
1430 // Change the max texture size on the output surface context. 1561 // Change the max texture size on the output surface context.
1431 std::unique_ptr<TestWebGraphicsContext3D> context = 1562 std::unique_ptr<TestWebGraphicsContext3D> context =
1432 TestWebGraphicsContext3D::Create(); 1563 TestWebGraphicsContext3D::Create();
1433 context->set_max_texture_size(140); 1564 context->set_max_texture_size(140);
1434 ResetOutputSurface(FakeOutputSurface::Create3d(std::move(context))); 1565 host_impl_.DidLoseOutputSurface();
1566 std::unique_ptr<OutputSurface> new_output_surface =
1567 FakeOutputSurface::Create3d(std::move(context));
1568 host_impl_.SetVisible(true);
1569 host_impl_.InitializeRenderer(new_output_surface.get());
1570 output_surface_ = std::move(new_output_surface);
1435 1571
1436 SetupDrawPropertiesAndUpdateTiles(active_layer(), 1.f, 1.f, 1.f, 1.f, 0.f, 1572 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, 1.f, 1.f, 1.f, 0.f,
1437 false); 1573 false);
1438 ASSERT_LE(1u, active_layer()->tilings()->num_tilings()); 1574 ASSERT_LE(1u, active_layer_->tilings()->num_tilings());
1439 1575
1440 active_layer()->tilings()->tiling_at(0)->CreateAllTilesForTesting(); 1576 active_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1441 1577
1442 // There should be more than one tile since the max texture size won't cover 1578 // There should be more than one tile since the max texture size won't cover
1443 // the layer. 1579 // the layer.
1444 high_res_tiling = active_layer()->tilings()->tiling_at(0); 1580 high_res_tiling = active_layer_->tilings()->tiling_at(0);
1445 EXPECT_LT(1u, high_res_tiling->AllTilesForTesting().size()); 1581 EXPECT_LT(1u, high_res_tiling->AllTilesForTesting().size());
1446 1582
1447 // Verify the tiles are not larger than the context's max texture size. 1583 // Verify the tiles are not larger than the context's max texture size.
1448 Tile* tile = active_layer()->tilings()->tiling_at(0)->AllTilesForTesting()[0]; 1584 Tile* tile = active_layer_->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1449 EXPECT_GE(140, tile->content_rect().width()); 1585 EXPECT_GE(140, tile->content_rect().width());
1450 EXPECT_GE(140, tile->content_rect().height()); 1586 EXPECT_GE(140, tile->content_rect().height());
1451 } 1587 }
1452 1588
1453 TEST_F(PictureLayerImplTest, DisallowTileDrawQuads) { 1589 TEST_F(PictureLayerImplTest, DisallowTileDrawQuads) {
1454 std::unique_ptr<RenderPass> render_pass = RenderPass::Create(); 1590 std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
1455 1591
1456 gfx::Size layer_bounds(1300, 1900); 1592 gfx::Size layer_bounds(1300, 1900);
1457 gfx::Rect layer_rect(layer_bounds); 1593 gfx::Rect layer_rect(layer_bounds);
1458 1594
1459 gfx::Rect layer_invalidation(150, 200, 30, 180); 1595 gfx::Rect layer_invalidation(150, 200, 30, 180);
1460 SetupDefaultTreesWithInvalidation(layer_bounds, layer_invalidation); 1596 SetupDefaultTreesWithInvalidation(layer_bounds, layer_invalidation);
1461 1597
1462 active_layer()->SetContentsOpaque(true); 1598 active_layer_->SetContentsOpaque(true);
1463 active_layer()->draw_properties().visible_layer_rect = 1599 active_layer_->draw_properties().visible_layer_rect = gfx::Rect(layer_bounds);
1464 gfx::Rect(layer_bounds);
1465 1600
1466 AppendQuadsData data; 1601 AppendQuadsData data;
1467 active_layer()->WillDraw(DRAW_MODE_RESOURCELESS_SOFTWARE, nullptr); 1602 active_layer_->WillDraw(DRAW_MODE_RESOURCELESS_SOFTWARE, nullptr);
1468 active_layer()->AppendQuads(render_pass.get(), &data); 1603 active_layer_->AppendQuads(render_pass.get(), &data);
1469 active_layer()->DidDraw(nullptr); 1604 active_layer_->DidDraw(nullptr);
1470 1605
1471 ASSERT_EQ(1u, render_pass->quad_list.size()); 1606 ASSERT_EQ(1u, render_pass->quad_list.size());
1472 EXPECT_EQ(DrawQuad::PICTURE_CONTENT, 1607 EXPECT_EQ(DrawQuad::PICTURE_CONTENT,
1473 render_pass->quad_list.front()->material); 1608 render_pass->quad_list.front()->material);
1474 EXPECT_EQ(render_pass->quad_list.front()->rect, layer_rect); 1609 EXPECT_EQ(render_pass->quad_list.front()->rect, layer_rect);
1475 EXPECT_EQ(render_pass->quad_list.front()->opaque_rect, layer_rect); 1610 EXPECT_EQ(render_pass->quad_list.front()->opaque_rect, layer_rect);
1476 EXPECT_EQ(render_pass->quad_list.front()->visible_rect, layer_rect); 1611 EXPECT_EQ(render_pass->quad_list.front()->visible_rect, layer_rect);
1477 } 1612 }
1478 1613
1479 TEST_F(PictureLayerImplTest, ResourcelessPartialRecording) { 1614 TEST_F(PictureLayerImplTest, ResourcelessPartialRecording) {
1480 std::unique_ptr<RenderPass> render_pass = RenderPass::Create(); 1615 std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
1481 1616
1482 gfx::Size tile_size(400, 400); 1617 gfx::Size tile_size(400, 400);
1483 gfx::Size layer_bounds(700, 650); 1618 gfx::Size layer_bounds(700, 650);
1484 gfx::Rect layer_rect(layer_bounds); 1619 gfx::Rect layer_rect(layer_bounds);
1485 SetInitialDeviceScaleFactor(2.f); 1620 SetInitialDeviceScaleFactor(2.f);
1486 1621
1487 gfx::Rect recorded_viewport(20, 30, 40, 50); 1622 gfx::Rect recorded_viewport(20, 30, 40, 50);
1488 scoped_refptr<FakeRasterSource> active_raster_source = 1623 scoped_refptr<FakeRasterSource> active_raster_source =
1489 FakeRasterSource::CreatePartiallyFilled(layer_bounds, recorded_viewport); 1624 FakeRasterSource::CreatePartiallyFilled(layer_bounds, recorded_viewport);
1490 1625
1491 SetupPendingTree(active_raster_source); 1626 SetupPendingTree(active_raster_source);
1492 ActivateTree(); 1627 ActivateTree();
1493 1628
1494 active_layer()->SetContentsOpaque(true); 1629 active_layer_->SetContentsOpaque(true);
1495 gfx::Rect visible_rect(30, 35, 10, 5); 1630 gfx::Rect visible_rect(30, 35, 10, 5);
1496 active_layer()->draw_properties().visible_layer_rect = visible_rect; 1631 active_layer_->draw_properties().visible_layer_rect = visible_rect;
1497 1632
1498 AppendQuadsData data; 1633 AppendQuadsData data;
1499 active_layer()->WillDraw(DRAW_MODE_RESOURCELESS_SOFTWARE, nullptr); 1634 active_layer_->WillDraw(DRAW_MODE_RESOURCELESS_SOFTWARE, nullptr);
1500 active_layer()->AppendQuads(render_pass.get(), &data); 1635 active_layer_->AppendQuads(render_pass.get(), &data);
1501 active_layer()->DidDraw(nullptr); 1636 active_layer_->DidDraw(nullptr);
1502 1637
1503 gfx::Rect scaled_visible = gfx::ScaleToEnclosingRect(visible_rect, 2.f); 1638 gfx::Rect scaled_visible = gfx::ScaleToEnclosingRect(visible_rect, 2.f);
1504 gfx::Rect scaled_recorded = gfx::ScaleToEnclosingRect(recorded_viewport, 2.f); 1639 gfx::Rect scaled_recorded = gfx::ScaleToEnclosingRect(recorded_viewport, 2.f);
1505 gfx::Rect quad_visible = gfx::IntersectRects(scaled_visible, scaled_recorded); 1640 gfx::Rect quad_visible = gfx::IntersectRects(scaled_visible, scaled_recorded);
1506 1641
1507 ASSERT_EQ(1U, render_pass->quad_list.size()); 1642 ASSERT_EQ(1U, render_pass->quad_list.size());
1508 EXPECT_EQ(DrawQuad::PICTURE_CONTENT, 1643 EXPECT_EQ(DrawQuad::PICTURE_CONTENT,
1509 render_pass->quad_list.front()->material); 1644 render_pass->quad_list.front()->material);
1510 const DrawQuad* quad = render_pass->quad_list.front(); 1645 const DrawQuad* quad = render_pass->quad_list.front();
1511 EXPECT_EQ(quad_visible, quad->rect); 1646 EXPECT_EQ(quad_visible, quad->rect);
1512 EXPECT_EQ(quad_visible, quad->opaque_rect); 1647 EXPECT_EQ(quad_visible, quad->opaque_rect);
1513 EXPECT_EQ(quad_visible, quad->visible_rect); 1648 EXPECT_EQ(quad_visible, quad->visible_rect);
1514 } 1649 }
1515 1650
1516 TEST_F(PictureLayerImplTest, ResourcelessEmptyRecording) { 1651 TEST_F(PictureLayerImplTest, ResourcelessEmptyRecording) {
1517 std::unique_ptr<RenderPass> render_pass = RenderPass::Create(); 1652 std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
1518 1653
1519 gfx::Size layer_bounds(700, 650); 1654 gfx::Size layer_bounds(700, 650);
1520 scoped_refptr<FakeRasterSource> active_raster_source = 1655 scoped_refptr<FakeRasterSource> active_raster_source =
1521 FakeRasterSource::CreatePartiallyFilled(layer_bounds, gfx::Rect()); 1656 FakeRasterSource::CreatePartiallyFilled(layer_bounds, gfx::Rect());
1522 SetupPendingTree(active_raster_source); 1657 SetupPendingTree(active_raster_source);
1523 ActivateTree(); 1658 ActivateTree();
1524 1659
1525 active_layer()->SetContentsOpaque(true); 1660 active_layer_->SetContentsOpaque(true);
1526 active_layer()->draw_properties().visible_layer_rect = 1661 active_layer_->draw_properties().visible_layer_rect = gfx::Rect(layer_bounds);
1527 gfx::Rect(layer_bounds);
1528 1662
1529 AppendQuadsData data; 1663 AppendQuadsData data;
1530 active_layer()->WillDraw(DRAW_MODE_RESOURCELESS_SOFTWARE, nullptr); 1664 active_layer_->WillDraw(DRAW_MODE_RESOURCELESS_SOFTWARE, nullptr);
1531 active_layer()->AppendQuads(render_pass.get(), &data); 1665 active_layer_->AppendQuads(render_pass.get(), &data);
1532 active_layer()->DidDraw(nullptr); 1666 active_layer_->DidDraw(nullptr);
1533 1667
1534 EXPECT_EQ(0U, render_pass->quad_list.size()); 1668 EXPECT_EQ(0U, render_pass->quad_list.size());
1535 } 1669 }
1536 1670
1537 TEST_F(PictureLayerImplTest, SolidColorLayerHasVisibleFullCoverage) { 1671 TEST_F(PictureLayerImplTest, SolidColorLayerHasVisibleFullCoverage) {
1538 std::unique_ptr<RenderPass> render_pass = RenderPass::Create(); 1672 std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
1539 1673
1540 gfx::Size layer_bounds(1500, 1500); 1674 gfx::Size layer_bounds(1500, 1500);
1541 gfx::Rect visible_rect(250, 250, 1000, 1000); 1675 gfx::Rect visible_rect(250, 250, 1000, 1000);
1542 1676
1543 scoped_refptr<FakeRasterSource> pending_raster_source = 1677 scoped_refptr<FakeRasterSource> pending_raster_source =
1544 FakeRasterSource::CreateFilledSolidColor(layer_bounds); 1678 FakeRasterSource::CreateFilledSolidColor(layer_bounds);
1545 scoped_refptr<FakeRasterSource> active_raster_source = 1679 scoped_refptr<FakeRasterSource> active_raster_source =
1546 FakeRasterSource::CreateFilledSolidColor(layer_bounds); 1680 FakeRasterSource::CreateFilledSolidColor(layer_bounds);
1547 1681
1548 SetupTrees(pending_raster_source, active_raster_source); 1682 SetupTrees(pending_raster_source, active_raster_source);
1549 1683
1550 active_layer()->draw_properties().visible_layer_rect = visible_rect; 1684 active_layer_->draw_properties().visible_layer_rect = visible_rect;
1551 1685
1552 AppendQuadsData data; 1686 AppendQuadsData data;
1553 active_layer()->WillDraw(DRAW_MODE_SOFTWARE, nullptr); 1687 active_layer_->WillDraw(DRAW_MODE_SOFTWARE, nullptr);
1554 active_layer()->AppendQuads(render_pass.get(), &data); 1688 active_layer_->AppendQuads(render_pass.get(), &data);
1555 active_layer()->DidDraw(nullptr); 1689 active_layer_->DidDraw(nullptr);
1556 1690
1557 Region remaining = visible_rect; 1691 Region remaining = visible_rect;
1558 for (const auto& quad : render_pass->quad_list) { 1692 for (const auto& quad : render_pass->quad_list) {
1559 EXPECT_TRUE(visible_rect.Contains(quad->rect)); 1693 EXPECT_TRUE(visible_rect.Contains(quad->rect));
1560 EXPECT_TRUE(remaining.Contains(quad->rect)); 1694 EXPECT_TRUE(remaining.Contains(quad->rect));
1561 remaining.Subtract(quad->rect); 1695 remaining.Subtract(quad->rect);
1562 } 1696 }
1563 1697
1564 EXPECT_TRUE(remaining.IsEmpty()); 1698 EXPECT_TRUE(remaining.IsEmpty());
1565 } 1699 }
1566 1700
1567 TEST_F(PictureLayerImplTest, TileScalesWithSolidColorRasterSource) { 1701 TEST_F(PictureLayerImplTest, TileScalesWithSolidColorRasterSource) {
1568 gfx::Size layer_bounds(200, 200); 1702 gfx::Size layer_bounds(200, 200);
1569 scoped_refptr<FakeRasterSource> pending_raster_source = 1703 scoped_refptr<FakeRasterSource> pending_raster_source =
1570 FakeRasterSource::CreateFilled(layer_bounds); 1704 FakeRasterSource::CreateFilled(layer_bounds);
1571 scoped_refptr<FakeRasterSource> active_raster_source = 1705 scoped_refptr<FakeRasterSource> active_raster_source =
1572 FakeRasterSource::CreateFilledSolidColor(layer_bounds); 1706 FakeRasterSource::CreateFilledSolidColor(layer_bounds);
1573 1707
1574 SetupTrees(pending_raster_source, active_raster_source); 1708 SetupTrees(pending_raster_source, active_raster_source);
1575 // Solid color raster source should not allow tilings at any scale. 1709 // Solid color raster source should not allow tilings at any scale.
1576 EXPECT_FALSE(active_layer()->CanHaveTilings()); 1710 EXPECT_FALSE(active_layer_->CanHaveTilings());
1577 EXPECT_EQ(0.f, active_layer()->ideal_contents_scale()); 1711 EXPECT_EQ(0.f, active_layer_->ideal_contents_scale());
1578 1712
1579 // Activate non-solid-color pending raster source makes active layer can have 1713 // Activate non-solid-color pending raster source makes active layer can have
1580 // tilings. 1714 // tilings.
1581 ActivateTree(); 1715 ActivateTree();
1582 EXPECT_TRUE(active_layer()->CanHaveTilings()); 1716 EXPECT_TRUE(active_layer_->CanHaveTilings());
1583 EXPECT_GT(active_layer()->ideal_contents_scale(), 0.f); 1717 EXPECT_GT(active_layer_->ideal_contents_scale(), 0.f);
1584 } 1718 }
1585 1719
1586 TEST_F(NoLowResPictureLayerImplTest, MarkRequiredOffscreenTiles) { 1720 TEST_F(NoLowResPictureLayerImplTest, MarkRequiredOffscreenTiles) {
1587 gfx::Size layer_bounds(200, 200); 1721 gfx::Size layer_bounds(200, 200);
1588 1722
1589 gfx::Transform transform; 1723 gfx::Transform transform;
1590 gfx::Rect viewport(0, 0, 100, 200); 1724 gfx::Rect viewport(0, 0, 100, 200);
1591 host_impl()->SetExternalTilePriorityConstraints(viewport, transform); 1725 host_impl_.SetExternalTilePriorityConstraints(viewport, transform);
1592 1726
1593 scoped_refptr<FakeRasterSource> pending_raster_source = 1727 scoped_refptr<FakeRasterSource> pending_raster_source =
1594 FakeRasterSource::CreateFilled(layer_bounds); 1728 FakeRasterSource::CreateFilled(layer_bounds);
1595 SetupPendingTreeWithFixedTileSize(pending_raster_source, gfx::Size(100, 100), 1729 SetupPendingTreeWithFixedTileSize(pending_raster_source, gfx::Size(100, 100),
1596 Region()); 1730 Region());
1597 1731
1598 EXPECT_EQ(1u, pending_layer()->num_tilings()); 1732 EXPECT_EQ(1u, pending_layer_->num_tilings());
1599 EXPECT_EQ( 1733 EXPECT_EQ(viewport,
1600 viewport, 1734 pending_layer_->viewport_rect_for_tile_priority_in_content_space());
1601 pending_layer()->viewport_rect_for_tile_priority_in_content_space());
1602 1735
1603 base::TimeTicks time_ticks; 1736 base::TimeTicks time_ticks;
1604 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); 1737 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1605 pending_layer()->UpdateTiles(); 1738 pending_layer_->UpdateTiles();
1606 1739
1607 int num_visible = 0; 1740 int num_visible = 0;
1608 int num_offscreen = 0; 1741 int num_offscreen = 0;
1609 1742
1610 std::unique_ptr<TilingSetRasterQueueAll> queue(new TilingSetRasterQueueAll( 1743 std::unique_ptr<TilingSetRasterQueueAll> queue(new TilingSetRasterQueueAll(
1611 pending_layer()->picture_layer_tiling_set(), false)); 1744 pending_layer_->picture_layer_tiling_set(), false));
1612 for (; !queue->IsEmpty(); queue->Pop()) { 1745 for (; !queue->IsEmpty(); queue->Pop()) {
1613 const PrioritizedTile& prioritized_tile = queue->Top(); 1746 const PrioritizedTile& prioritized_tile = queue->Top();
1614 DCHECK(prioritized_tile.tile()); 1747 DCHECK(prioritized_tile.tile());
1615 if (prioritized_tile.priority().distance_to_visible == 0.f) { 1748 if (prioritized_tile.priority().distance_to_visible == 0.f) {
1616 EXPECT_TRUE(prioritized_tile.tile()->required_for_activation()); 1749 EXPECT_TRUE(prioritized_tile.tile()->required_for_activation());
1617 num_visible++; 1750 num_visible++;
1618 } else { 1751 } else {
1619 EXPECT_FALSE(prioritized_tile.tile()->required_for_activation()); 1752 EXPECT_FALSE(prioritized_tile.tile()->required_for_activation());
1620 num_offscreen++; 1753 num_offscreen++;
1621 } 1754 }
1622 } 1755 }
1623 1756
1624 EXPECT_GT(num_visible, 0); 1757 EXPECT_GT(num_visible, 0);
1625 EXPECT_GT(num_offscreen, 0); 1758 EXPECT_GT(num_offscreen, 0);
1626 } 1759 }
1627 1760
1628 TEST_F(NoLowResPictureLayerImplTest, 1761 TEST_F(NoLowResPictureLayerImplTest,
1629 TileOutsideOfViewportForTilePriorityNotRequired) { 1762 TileOutsideOfViewportForTilePriorityNotRequired) {
1630 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); 1763 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1631 1764
1632 gfx::Size tile_size(100, 100); 1765 gfx::Size tile_size(100, 100);
1633 gfx::Size layer_bounds(400, 400); 1766 gfx::Size layer_bounds(400, 400);
1634 gfx::Rect external_viewport_for_tile_priority(400, 200); 1767 gfx::Rect external_viewport_for_tile_priority(400, 200);
1635 gfx::Rect visible_layer_rect(200, 400); 1768 gfx::Rect visible_layer_rect(200, 400);
1636 1769
1637 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, Region()); 1770 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, Region());
1638 1771
1639 ASSERT_EQ(1u, pending_layer()->num_tilings()); 1772 ASSERT_EQ(1u, pending_layer_->num_tilings());
1640 ASSERT_EQ(1.f, pending_layer()->HighResTiling()->contents_scale()); 1773 ASSERT_EQ(1.f, pending_layer_->HighResTiling()->contents_scale());
1641 1774
1642 // Set external viewport for tile priority. 1775 // Set external viewport for tile priority.
1643 gfx::Rect viewport = gfx::Rect(layer_bounds); 1776 gfx::Rect viewport = gfx::Rect(layer_bounds);
1644 gfx::Transform transform; 1777 gfx::Transform transform;
1645 gfx::Transform transform_for_tile_priority; 1778 gfx::Transform transform_for_tile_priority;
1646 host_impl()->SetExternalTilePriorityConstraints( 1779 host_impl_.SetExternalTilePriorityConstraints(
1647 external_viewport_for_tile_priority, transform_for_tile_priority); 1780 external_viewport_for_tile_priority, transform_for_tile_priority);
1648 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); 1781 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1649 bool update_lcd_text = false; 1782 bool update_lcd_text = false;
1650 host_impl()->pending_tree()->UpdateDrawProperties(update_lcd_text); 1783 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
1651 1784
1652 // Set visible content rect that is different from 1785 // Set visible content rect that is different from
1653 // external_viewport_for_tile_priority. 1786 // external_viewport_for_tile_priority.
1654 pending_layer()->draw_properties().visible_layer_rect = visible_layer_rect; 1787 pending_layer_->draw_properties().visible_layer_rect = visible_layer_rect;
1655 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200)); 1788 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
1656 pending_layer()->UpdateTiles(); 1789 pending_layer_->UpdateTiles();
1657 1790
1658 // Intersect the two rects. Any tile outside should not be required for 1791 // Intersect the two rects. Any tile outside should not be required for
1659 // activation. 1792 // activation.
1660 gfx::Rect viewport_for_tile_priority = 1793 gfx::Rect viewport_for_tile_priority =
1661 pending_layer()->viewport_rect_for_tile_priority_in_content_space(); 1794 pending_layer_->viewport_rect_for_tile_priority_in_content_space();
1662 viewport_for_tile_priority.Intersect(pending_layer()->visible_layer_rect()); 1795 viewport_for_tile_priority.Intersect(pending_layer_->visible_layer_rect());
1663 1796
1664 EXPECT_TRUE(pending_layer()->HighResTiling()->AllTilesForTesting().empty()); 1797 EXPECT_TRUE(pending_layer_->HighResTiling()->AllTilesForTesting().empty());
1665 1798
1666 int num_inside = 0; 1799 int num_inside = 0;
1667 int num_outside = 0; 1800 int num_outside = 0;
1668 for (PictureLayerTiling::CoverageIterator iter( 1801 for (PictureLayerTiling::CoverageIterator iter(active_layer_->HighResTiling(),
1669 active_layer()->HighResTiling(), 1.f, gfx::Rect(layer_bounds)); 1802 1.f, gfx::Rect(layer_bounds));
1670 iter; ++iter) { 1803 iter; ++iter) {
1671 if (!*iter) 1804 if (!*iter)
1672 continue; 1805 continue;
1673 Tile* tile = *iter; 1806 Tile* tile = *iter;
1674 if (viewport_for_tile_priority.Intersects(iter.geometry_rect())) { 1807 if (viewport_for_tile_priority.Intersects(iter.geometry_rect())) {
1675 num_inside++; 1808 num_inside++;
1676 // Mark everything in viewport for tile priority as ready to draw. 1809 // Mark everything in viewport for tile priority as ready to draw.
1677 TileDrawInfo& draw_info = tile->draw_info(); 1810 TileDrawInfo& draw_info = tile->draw_info();
1678 draw_info.SetSolidColorForTesting(SK_ColorRED); 1811 draw_info.SetSolidColorForTesting(SK_ColorRED);
1679 } else { 1812 } else {
1680 num_outside++; 1813 num_outside++;
1681 EXPECT_FALSE(tile->required_for_activation()); 1814 EXPECT_FALSE(tile->required_for_activation());
1682 } 1815 }
1683 } 1816 }
1684 1817
1685 EXPECT_GT(num_inside, 0); 1818 EXPECT_GT(num_inside, 0);
1686 EXPECT_GT(num_outside, 0); 1819 EXPECT_GT(num_outside, 0);
1687 1820
1688 // Activate and draw active layer. 1821 // Activate and draw active layer.
1689 host_impl()->ActivateSyncTree(); 1822 host_impl_.ActivateSyncTree();
1690 host_impl()->active_tree()->UpdateDrawProperties(update_lcd_text); 1823 host_impl_.active_tree()->UpdateDrawProperties(update_lcd_text);
1691 active_layer()->draw_properties().visible_layer_rect = visible_layer_rect; 1824 active_layer_->draw_properties().visible_layer_rect = visible_layer_rect;
1692 1825
1693 std::unique_ptr<RenderPass> render_pass = RenderPass::Create(); 1826 std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
1694 AppendQuadsData data; 1827 AppendQuadsData data;
1695 active_layer()->WillDraw(DRAW_MODE_SOFTWARE, nullptr); 1828 active_layer_->WillDraw(DRAW_MODE_SOFTWARE, nullptr);
1696 active_layer()->AppendQuads(render_pass.get(), &data); 1829 active_layer_->AppendQuads(render_pass.get(), &data);
1697 active_layer()->DidDraw(nullptr); 1830 active_layer_->DidDraw(nullptr);
1698 1831
1699 // All tiles in activation rect is ready to draw. 1832 // All tiles in activation rect is ready to draw.
1700 EXPECT_EQ(0u, data.num_missing_tiles); 1833 EXPECT_EQ(0u, data.num_missing_tiles);
1701 EXPECT_EQ(0u, data.num_incomplete_tiles); 1834 EXPECT_EQ(0u, data.num_incomplete_tiles);
1702 EXPECT_FALSE(active_layer()->only_used_low_res_last_append_quads()); 1835 EXPECT_FALSE(active_layer_->only_used_low_res_last_append_quads());
1703 } 1836 }
1704 1837
1705 TEST_F(PictureLayerImplTest, HighResTileIsComplete) { 1838 TEST_F(PictureLayerImplTest, HighResTileIsComplete) {
1706 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); 1839 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1707 1840
1708 gfx::Size tile_size(100, 100); 1841 gfx::Size tile_size(100, 100);
1709 gfx::Size layer_bounds(200, 200); 1842 gfx::Size layer_bounds(200, 200);
1710 1843
1711 scoped_refptr<FakeRasterSource> pending_raster_source = 1844 scoped_refptr<FakeRasterSource> pending_raster_source =
1712 FakeRasterSource::CreateFilled(layer_bounds); 1845 FakeRasterSource::CreateFilled(layer_bounds);
1713 1846
1714 SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size, Region()); 1847 SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size, Region());
1715 ActivateTree(); 1848 ActivateTree();
1716 1849
1717 // All high res tiles have resources. 1850 // All high res tiles have resources.
1718 std::vector<Tile*> tiles = 1851 std::vector<Tile*> tiles =
1719 active_layer()->tilings()->tiling_at(0)->AllTilesForTesting(); 1852 active_layer_->tilings()->tiling_at(0)->AllTilesForTesting();
1720 host_impl()->tile_manager()->InitializeTilesWithResourcesForTesting(tiles); 1853 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(tiles);
1721 1854
1722 std::unique_ptr<RenderPass> render_pass = RenderPass::Create(); 1855 std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
1723 AppendQuadsData data; 1856 AppendQuadsData data;
1724 active_layer()->WillDraw(DRAW_MODE_SOFTWARE, nullptr); 1857 active_layer_->WillDraw(DRAW_MODE_SOFTWARE, nullptr);
1725 active_layer()->AppendQuads(render_pass.get(), &data); 1858 active_layer_->AppendQuads(render_pass.get(), &data);
1726 active_layer()->DidDraw(nullptr); 1859 active_layer_->DidDraw(nullptr);
1727 1860
1728 // All high res tiles drew, nothing was incomplete. 1861 // All high res tiles drew, nothing was incomplete.
1729 EXPECT_EQ(9u, render_pass->quad_list.size()); 1862 EXPECT_EQ(9u, render_pass->quad_list.size());
1730 EXPECT_EQ(0u, data.num_missing_tiles); 1863 EXPECT_EQ(0u, data.num_missing_tiles);
1731 EXPECT_EQ(0u, data.num_incomplete_tiles); 1864 EXPECT_EQ(0u, data.num_incomplete_tiles);
1732 EXPECT_FALSE(active_layer()->only_used_low_res_last_append_quads()); 1865 EXPECT_FALSE(active_layer_->only_used_low_res_last_append_quads());
1733 } 1866 }
1734 1867
1735 TEST_F(PictureLayerImplTest, HighResTileIsIncomplete) { 1868 TEST_F(PictureLayerImplTest, HighResTileIsIncomplete) {
1736 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); 1869 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1737 1870
1738 gfx::Size tile_size(100, 100); 1871 gfx::Size tile_size(100, 100);
1739 gfx::Size layer_bounds(200, 200); 1872 gfx::Size layer_bounds(200, 200);
1740 1873
1741 scoped_refptr<FakeRasterSource> pending_raster_source = 1874 scoped_refptr<FakeRasterSource> pending_raster_source =
1742 FakeRasterSource::CreateFilled(layer_bounds); 1875 FakeRasterSource::CreateFilled(layer_bounds);
1743 SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size, Region()); 1876 SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size, Region());
1744 ActivateTree(); 1877 ActivateTree();
1745 1878
1746 std::unique_ptr<RenderPass> render_pass = RenderPass::Create(); 1879 std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
1747 AppendQuadsData data; 1880 AppendQuadsData data;
1748 active_layer()->WillDraw(DRAW_MODE_SOFTWARE, nullptr); 1881 active_layer_->WillDraw(DRAW_MODE_SOFTWARE, nullptr);
1749 active_layer()->AppendQuads(render_pass.get(), &data); 1882 active_layer_->AppendQuads(render_pass.get(), &data);
1750 active_layer()->DidDraw(nullptr); 1883 active_layer_->DidDraw(nullptr);
1751 1884
1752 EXPECT_EQ(1u, render_pass->quad_list.size()); 1885 EXPECT_EQ(1u, render_pass->quad_list.size());
1753 EXPECT_EQ(1u, data.num_missing_tiles); 1886 EXPECT_EQ(1u, data.num_missing_tiles);
1754 EXPECT_EQ(0u, data.num_incomplete_tiles); 1887 EXPECT_EQ(0u, data.num_incomplete_tiles);
1755 EXPECT_TRUE(active_layer()->only_used_low_res_last_append_quads()); 1888 EXPECT_TRUE(active_layer_->only_used_low_res_last_append_quads());
1756 } 1889 }
1757 1890
1758 TEST_F(PictureLayerImplTest, HighResTileIsIncompleteLowResComplete) { 1891 TEST_F(PictureLayerImplTest, HighResTileIsIncompleteLowResComplete) {
1759 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); 1892 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1760 1893
1761 gfx::Size tile_size(100, 100); 1894 gfx::Size tile_size(100, 100);
1762 gfx::Size layer_bounds(200, 200); 1895 gfx::Size layer_bounds(200, 200);
1763 1896
1764 scoped_refptr<FakeRasterSource> pending_raster_source = 1897 scoped_refptr<FakeRasterSource> pending_raster_source =
1765 FakeRasterSource::CreateFilled(layer_bounds); 1898 FakeRasterSource::CreateFilled(layer_bounds);
1766 SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size, Region()); 1899 SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size, Region());
1767 ActivateTree(); 1900 ActivateTree();
1768 1901
1769 std::vector<Tile*> low_tiles = 1902 std::vector<Tile*> low_tiles =
1770 active_layer()->tilings()->tiling_at(1)->AllTilesForTesting(); 1903 active_layer_->tilings()->tiling_at(1)->AllTilesForTesting();
1771 host_impl()->tile_manager()->InitializeTilesWithResourcesForTesting( 1904 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(low_tiles);
1772 low_tiles);
1773 1905
1774 std::unique_ptr<RenderPass> render_pass = RenderPass::Create(); 1906 std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
1775 AppendQuadsData data; 1907 AppendQuadsData data;
1776 active_layer()->WillDraw(DRAW_MODE_SOFTWARE, nullptr); 1908 active_layer_->WillDraw(DRAW_MODE_SOFTWARE, nullptr);
1777 active_layer()->AppendQuads(render_pass.get(), &data); 1909 active_layer_->AppendQuads(render_pass.get(), &data);
1778 active_layer()->DidDraw(nullptr); 1910 active_layer_->DidDraw(nullptr);
1779 1911
1780 EXPECT_EQ(1u, render_pass->quad_list.size()); 1912 EXPECT_EQ(1u, render_pass->quad_list.size());
1781 EXPECT_EQ(0u, data.num_missing_tiles); 1913 EXPECT_EQ(0u, data.num_missing_tiles);
1782 EXPECT_EQ(1u, data.num_incomplete_tiles); 1914 EXPECT_EQ(1u, data.num_incomplete_tiles);
1783 EXPECT_TRUE(active_layer()->only_used_low_res_last_append_quads()); 1915 EXPECT_TRUE(active_layer_->only_used_low_res_last_append_quads());
1784 } 1916 }
1785 1917
1786 TEST_F(PictureLayerImplTest, LowResTileIsIncomplete) { 1918 TEST_F(PictureLayerImplTest, LowResTileIsIncomplete) {
1787 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); 1919 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1788 1920
1789 gfx::Size tile_size(100, 100); 1921 gfx::Size tile_size(100, 100);
1790 gfx::Size layer_bounds(200, 200); 1922 gfx::Size layer_bounds(200, 200);
1791 1923
1792 scoped_refptr<FakeRasterSource> pending_raster_source = 1924 scoped_refptr<FakeRasterSource> pending_raster_source =
1793 FakeRasterSource::CreateFilled(layer_bounds); 1925 FakeRasterSource::CreateFilled(layer_bounds);
1794 SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size, Region()); 1926 SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size, Region());
1795 ActivateTree(); 1927 ActivateTree();
1796 1928
1797 // All high res tiles have resources except one. 1929 // All high res tiles have resources except one.
1798 std::vector<Tile*> high_tiles = 1930 std::vector<Tile*> high_tiles =
1799 active_layer()->tilings()->tiling_at(0)->AllTilesForTesting(); 1931 active_layer_->tilings()->tiling_at(0)->AllTilesForTesting();
1800 high_tiles.erase(high_tiles.begin()); 1932 high_tiles.erase(high_tiles.begin());
1801 host_impl()->tile_manager()->InitializeTilesWithResourcesForTesting( 1933 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(high_tiles);
1802 high_tiles);
1803 1934
1804 // All low res tiles have resources. 1935 // All low res tiles have resources.
1805 std::vector<Tile*> low_tiles = 1936 std::vector<Tile*> low_tiles =
1806 active_layer()->tilings()->tiling_at(1)->AllTilesForTesting(); 1937 active_layer_->tilings()->tiling_at(1)->AllTilesForTesting();
1807 host_impl()->tile_manager()->InitializeTilesWithResourcesForTesting( 1938 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(low_tiles);
1808 low_tiles);
1809 1939
1810 std::unique_ptr<RenderPass> render_pass = RenderPass::Create(); 1940 std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
1811 AppendQuadsData data; 1941 AppendQuadsData data;
1812 active_layer()->WillDraw(DRAW_MODE_SOFTWARE, nullptr); 1942 active_layer_->WillDraw(DRAW_MODE_SOFTWARE, nullptr);
1813 active_layer()->AppendQuads(render_pass.get(), &data); 1943 active_layer_->AppendQuads(render_pass.get(), &data);
1814 active_layer()->DidDraw(nullptr); 1944 active_layer_->DidDraw(nullptr);
1815 1945
1816 // The missing high res tile was replaced by a low res tile. 1946 // The missing high res tile was replaced by a low res tile.
1817 EXPECT_EQ(9u, render_pass->quad_list.size()); 1947 EXPECT_EQ(9u, render_pass->quad_list.size());
1818 EXPECT_EQ(0u, data.num_missing_tiles); 1948 EXPECT_EQ(0u, data.num_missing_tiles);
1819 EXPECT_EQ(1u, data.num_incomplete_tiles); 1949 EXPECT_EQ(1u, data.num_incomplete_tiles);
1820 EXPECT_FALSE(active_layer()->only_used_low_res_last_append_quads()); 1950 EXPECT_FALSE(active_layer_->only_used_low_res_last_append_quads());
1821 } 1951 }
1822 1952
1823 TEST_F(PictureLayerImplTest, 1953 TEST_F(PictureLayerImplTest,
1824 HighResAndIdealResTileIsCompleteWhenRasterScaleIsNotIdeal) { 1954 HighResAndIdealResTileIsCompleteWhenRasterScaleIsNotIdeal) {
1825 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); 1955 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1826 1956
1827 gfx::Size tile_size(100, 100); 1957 gfx::Size tile_size(100, 100);
1828 gfx::Size layer_bounds(200, 200); 1958 gfx::Size layer_bounds(200, 200);
1829 gfx::Size viewport_size(400, 400); 1959 gfx::Size viewport_size(400, 400);
1830 1960
1831 host_impl()->SetViewportSize(viewport_size); 1961 host_impl_.SetViewportSize(viewport_size);
1832 SetInitialDeviceScaleFactor(2.f); 1962 SetInitialDeviceScaleFactor(2.f);
1833 1963
1834 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, Region()); 1964 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, Region());
1835 1965
1836 // One ideal tile exists, this will get used when drawing. 1966 // One ideal tile exists, this will get used when drawing.
1837 std::vector<Tile*> ideal_tiles; 1967 std::vector<Tile*> ideal_tiles;
1838 EXPECT_EQ(2.f, active_layer()->HighResTiling()->contents_scale()); 1968 EXPECT_EQ(2.f, active_layer_->HighResTiling()->contents_scale());
1839 ideal_tiles.push_back(active_layer()->HighResTiling()->TileAt(0, 0)); 1969 ideal_tiles.push_back(active_layer_->HighResTiling()->TileAt(0, 0));
1840 host_impl()->tile_manager()->InitializeTilesWithResourcesForTesting( 1970 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(
1841 ideal_tiles); 1971 ideal_tiles);
1842 1972
1843 // Due to layer scale throttling, the raster contents scale is changed to 1, 1973 // Due to layer scale throttling, the raster contents scale is changed to 1,
1844 // while the ideal is still 2. 1974 // while the ideal is still 2.
1845 SetupDrawPropertiesAndUpdateTiles(active_layer(), 1.f, 1.f, 1.f, 1.f, 0.f, 1975 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, 1.f, 1.f, 1.f, 0.f,
1846 false); 1976 false);
1847 SetupDrawPropertiesAndUpdateTiles(active_layer(), 2.f, 1.f, 1.f, 1.f, 0.f, 1977 SetupDrawPropertiesAndUpdateTiles(active_layer_, 2.f, 1.f, 1.f, 1.f, 0.f,
1848 false); 1978 false);
1849 1979
1850 EXPECT_EQ(1.f, active_layer()->HighResTiling()->contents_scale()); 1980 EXPECT_EQ(1.f, active_layer_->HighResTiling()->contents_scale());
1851 EXPECT_EQ(1.f, active_layer()->raster_contents_scale()); 1981 EXPECT_EQ(1.f, active_layer_->raster_contents_scale());
1852 EXPECT_EQ(2.f, active_layer()->ideal_contents_scale()); 1982 EXPECT_EQ(2.f, active_layer_->ideal_contents_scale());
1853 1983
1854 // Both tilings still exist. 1984 // Both tilings still exist.
1855 EXPECT_EQ(2.f, active_layer()->tilings()->tiling_at(0)->contents_scale()); 1985 EXPECT_EQ(2.f, active_layer_->tilings()->tiling_at(0)->contents_scale());
1856 EXPECT_EQ(1.f, active_layer()->tilings()->tiling_at(1)->contents_scale()); 1986 EXPECT_EQ(1.f, active_layer_->tilings()->tiling_at(1)->contents_scale());
1857 1987
1858 // All high res tiles have resources. 1988 // All high res tiles have resources.
1859 std::vector<Tile*> high_tiles = 1989 std::vector<Tile*> high_tiles =
1860 active_layer()->HighResTiling()->AllTilesForTesting(); 1990 active_layer_->HighResTiling()->AllTilesForTesting();
1861 host_impl()->tile_manager()->InitializeTilesWithResourcesForTesting( 1991 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(high_tiles);
1862 high_tiles);
1863 1992
1864 std::unique_ptr<RenderPass> render_pass = RenderPass::Create(); 1993 std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
1865 AppendQuadsData data; 1994 AppendQuadsData data;
1866 active_layer()->WillDraw(DRAW_MODE_SOFTWARE, nullptr); 1995 active_layer_->WillDraw(DRAW_MODE_SOFTWARE, nullptr);
1867 active_layer()->AppendQuads(render_pass.get(), &data); 1996 active_layer_->AppendQuads(render_pass.get(), &data);
1868 active_layer()->DidDraw(nullptr); 1997 active_layer_->DidDraw(nullptr);
1869 1998
1870 // All high res tiles drew, and the one ideal res tile drew. 1999 // All high res tiles drew, and the one ideal res tile drew.
1871 ASSERT_GT(render_pass->quad_list.size(), 9u); 2000 ASSERT_GT(render_pass->quad_list.size(), 9u);
1872 EXPECT_EQ(gfx::SizeF(99.f, 99.f), 2001 EXPECT_EQ(gfx::SizeF(99.f, 99.f),
1873 TileDrawQuad::MaterialCast(render_pass->quad_list.front()) 2002 TileDrawQuad::MaterialCast(render_pass->quad_list.front())
1874 ->tex_coord_rect.size()); 2003 ->tex_coord_rect.size());
1875 EXPECT_EQ(gfx::SizeF(49.5f, 49.5f), 2004 EXPECT_EQ(gfx::SizeF(49.5f, 49.5f),
1876 TileDrawQuad::MaterialCast(render_pass->quad_list.ElementAt(1)) 2005 TileDrawQuad::MaterialCast(render_pass->quad_list.ElementAt(1))
1877 ->tex_coord_rect.size()); 2006 ->tex_coord_rect.size());
1878 2007
1879 // Neither the high res nor the ideal tiles were considered as incomplete. 2008 // Neither the high res nor the ideal tiles were considered as incomplete.
1880 EXPECT_EQ(0u, data.num_missing_tiles); 2009 EXPECT_EQ(0u, data.num_missing_tiles);
1881 EXPECT_EQ(0u, data.num_incomplete_tiles); 2010 EXPECT_EQ(0u, data.num_incomplete_tiles);
1882 EXPECT_FALSE(active_layer()->only_used_low_res_last_append_quads()); 2011 EXPECT_FALSE(active_layer_->only_used_low_res_last_append_quads());
1883 } 2012 }
1884 2013
1885 TEST_F(PictureLayerImplTest, AppendQuadsDataForCheckerboard) { 2014 TEST_F(PictureLayerImplTest, AppendQuadsDataForCheckerboard) {
1886 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); 2015 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1887 2016
1888 gfx::Size tile_size(100, 100); 2017 gfx::Size tile_size(100, 100);
1889 gfx::Size layer_bounds(200, 200); 2018 gfx::Size layer_bounds(200, 200);
1890 gfx::Rect recorded_viewport(0, 0, 150, 150); 2019 gfx::Rect recorded_viewport(0, 0, 150, 150);
1891 2020
1892 scoped_refptr<FakeRasterSource> pending_raster_source = 2021 scoped_refptr<FakeRasterSource> pending_raster_source =
1893 FakeRasterSource::CreatePartiallyFilled(layer_bounds, recorded_viewport); 2022 FakeRasterSource::CreatePartiallyFilled(layer_bounds, recorded_viewport);
1894 SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size, Region()); 2023 SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size, Region());
1895 ActivateTree(); 2024 ActivateTree();
1896 2025
1897 std::unique_ptr<RenderPass> render_pass = RenderPass::Create(); 2026 std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
1898 AppendQuadsData data; 2027 AppendQuadsData data;
1899 active_layer()->WillDraw(DRAW_MODE_SOFTWARE, nullptr); 2028 active_layer_->WillDraw(DRAW_MODE_SOFTWARE, nullptr);
1900 active_layer()->AppendQuads(render_pass.get(), &data); 2029 active_layer_->AppendQuads(render_pass.get(), &data);
1901 active_layer()->DidDraw(nullptr); 2030 active_layer_->DidDraw(nullptr);
1902 2031
1903 EXPECT_EQ(1u, render_pass->quad_list.size()); 2032 EXPECT_EQ(1u, render_pass->quad_list.size());
1904 EXPECT_EQ(1u, data.num_missing_tiles); 2033 EXPECT_EQ(1u, data.num_missing_tiles);
1905 EXPECT_EQ(0u, data.num_incomplete_tiles); 2034 EXPECT_EQ(0u, data.num_incomplete_tiles);
1906 EXPECT_EQ(40000, data.checkerboarded_visible_content_area); 2035 EXPECT_EQ(40000, data.checkerboarded_visible_content_area);
1907 EXPECT_EQ(17500, data.checkerboarded_no_recording_content_area); 2036 EXPECT_EQ(17500, data.checkerboarded_no_recording_content_area);
1908 EXPECT_EQ(22500, data.checkerboarded_needs_raster_content_area); 2037 EXPECT_EQ(22500, data.checkerboarded_needs_raster_content_area);
1909 EXPECT_TRUE(active_layer()->only_used_low_res_last_append_quads()); 2038 EXPECT_TRUE(active_layer_->only_used_low_res_last_append_quads());
1910 } 2039 }
1911 2040
1912 TEST_F(PictureLayerImplTest, HighResRequiredWhenActiveAllReady) { 2041 TEST_F(PictureLayerImplTest, HighResRequiredWhenActiveAllReady) {
1913 gfx::Size layer_bounds(400, 400); 2042 gfx::Size layer_bounds(400, 400);
1914 gfx::Size tile_size(100, 100); 2043 gfx::Size tile_size(100, 100);
1915 2044
1916 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, 2045 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size,
1917 gfx::Rect(layer_bounds)); 2046 gfx::Rect(layer_bounds));
1918 2047
1919 active_layer()->SetAllTilesReady(); 2048 active_layer_->SetAllTilesReady();
1920 2049
1921 // All active tiles ready, so pending can only activate with all high res 2050 // All active tiles ready, so pending can only activate with all high res
1922 // tiles. 2051 // tiles.
1923 pending_layer()->HighResTiling()->UpdateAllRequiredStateForTesting(); 2052 pending_layer_->HighResTiling()->UpdateAllRequiredStateForTesting();
1924 EXPECT_FALSE(pending_layer()->LowResTiling()); 2053 EXPECT_FALSE(pending_layer_->LowResTiling());
1925 2054
1926 AssertAllTilesRequired(pending_layer()->HighResTiling()); 2055 AssertAllTilesRequired(pending_layer_->HighResTiling());
1927 } 2056 }
1928 2057
1929 TEST_F(PictureLayerImplTest, HighResRequiredWhenMissingHighResFlagOn) { 2058 TEST_F(PictureLayerImplTest, HighResRequiredWhenMissingHighResFlagOn) {
1930 gfx::Size layer_bounds(400, 400); 2059 gfx::Size layer_bounds(400, 400);
1931 gfx::Size tile_size(100, 100); 2060 gfx::Size tile_size(100, 100);
1932 2061
1933 // No invalidation. 2062 // No invalidation.
1934 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, Region()); 2063 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, Region());
1935 2064
1936 // Verify active tree not ready. 2065 // Verify active tree not ready.
1937 Tile* some_active_tile = 2066 Tile* some_active_tile =
1938 active_layer()->HighResTiling()->AllTilesForTesting()[0]; 2067 active_layer_->HighResTiling()->AllTilesForTesting()[0];
1939 EXPECT_FALSE(some_active_tile->draw_info().IsReadyToDraw()); 2068 EXPECT_FALSE(some_active_tile->draw_info().IsReadyToDraw());
1940 2069
1941 // When high res are required, all tiles in active high res tiling should be 2070 // When high res are required, all tiles in active high res tiling should be
1942 // required for activation. 2071 // required for activation.
1943 host_impl()->SetRequiresHighResToDraw(); 2072 host_impl_.SetRequiresHighResToDraw();
1944 2073
1945 pending_layer()->HighResTiling()->UpdateAllRequiredStateForTesting(); 2074 pending_layer_->HighResTiling()->UpdateAllRequiredStateForTesting();
1946 EXPECT_FALSE(pending_layer()->LowResTiling()); 2075 EXPECT_FALSE(pending_layer_->LowResTiling());
1947 active_layer()->HighResTiling()->UpdateAllRequiredStateForTesting(); 2076 active_layer_->HighResTiling()->UpdateAllRequiredStateForTesting();
1948 active_layer()->LowResTiling()->UpdateAllRequiredStateForTesting(); 2077 active_layer_->LowResTiling()->UpdateAllRequiredStateForTesting();
1949 2078
1950 EXPECT_TRUE(pending_layer()->HighResTiling()->AllTilesForTesting().empty()); 2079 EXPECT_TRUE(pending_layer_->HighResTiling()->AllTilesForTesting().empty());
1951 AssertAllTilesRequired(active_layer()->HighResTiling()); 2080 AssertAllTilesRequired(active_layer_->HighResTiling());
1952 AssertNoTilesRequired(active_layer()->LowResTiling()); 2081 AssertNoTilesRequired(active_layer_->LowResTiling());
1953 } 2082 }
1954 2083
1955 TEST_F(PictureLayerImplTest, AllHighResRequiredEvenIfNotChanged) { 2084 TEST_F(PictureLayerImplTest, AllHighResRequiredEvenIfNotChanged) {
1956 gfx::Size layer_bounds(400, 400); 2085 gfx::Size layer_bounds(400, 400);
1957 gfx::Size tile_size(100, 100); 2086 gfx::Size tile_size(100, 100);
1958 2087
1959 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, Region()); 2088 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, Region());
1960 2089
1961 Tile* some_active_tile = 2090 Tile* some_active_tile =
1962 active_layer()->HighResTiling()->AllTilesForTesting()[0]; 2091 active_layer_->HighResTiling()->AllTilesForTesting()[0];
1963 EXPECT_FALSE(some_active_tile->draw_info().IsReadyToDraw()); 2092 EXPECT_FALSE(some_active_tile->draw_info().IsReadyToDraw());
1964 2093
1965 // Since there are no invalidations, pending tree should have no tiles. 2094 // Since there are no invalidations, pending tree should have no tiles.
1966 EXPECT_TRUE(pending_layer()->HighResTiling()->AllTilesForTesting().empty()); 2095 EXPECT_TRUE(pending_layer_->HighResTiling()->AllTilesForTesting().empty());
1967 EXPECT_FALSE(pending_layer()->LowResTiling()); 2096 EXPECT_FALSE(pending_layer_->LowResTiling());
1968 2097
1969 active_layer()->HighResTiling()->UpdateAllRequiredStateForTesting(); 2098 active_layer_->HighResTiling()->UpdateAllRequiredStateForTesting();
1970 active_layer()->LowResTiling()->UpdateAllRequiredStateForTesting(); 2099 active_layer_->LowResTiling()->UpdateAllRequiredStateForTesting();
1971 2100
1972 AssertAllTilesRequired(active_layer()->HighResTiling()); 2101 AssertAllTilesRequired(active_layer_->HighResTiling());
1973 AssertNoTilesRequired(active_layer()->LowResTiling()); 2102 AssertNoTilesRequired(active_layer_->LowResTiling());
1974 } 2103 }
1975 2104
1976 TEST_F(PictureLayerImplTest, DisallowRequiredForActivation) { 2105 TEST_F(PictureLayerImplTest, DisallowRequiredForActivation) {
1977 gfx::Size layer_bounds(400, 400); 2106 gfx::Size layer_bounds(400, 400);
1978 gfx::Size tile_size(100, 100); 2107 gfx::Size tile_size(100, 100);
1979 2108
1980 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, Region()); 2109 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, Region());
1981 2110
1982 Tile* some_active_tile = 2111 Tile* some_active_tile =
1983 active_layer()->HighResTiling()->AllTilesForTesting()[0]; 2112 active_layer_->HighResTiling()->AllTilesForTesting()[0];
1984 EXPECT_FALSE(some_active_tile->draw_info().IsReadyToDraw()); 2113 EXPECT_FALSE(some_active_tile->draw_info().IsReadyToDraw());
1985 2114
1986 EXPECT_TRUE(pending_layer()->HighResTiling()->AllTilesForTesting().empty()); 2115 EXPECT_TRUE(pending_layer_->HighResTiling()->AllTilesForTesting().empty());
1987 EXPECT_FALSE(pending_layer()->LowResTiling()); 2116 EXPECT_FALSE(pending_layer_->LowResTiling());
1988 active_layer()->HighResTiling()->set_can_require_tiles_for_activation(false); 2117 active_layer_->HighResTiling()->set_can_require_tiles_for_activation(false);
1989 active_layer()->LowResTiling()->set_can_require_tiles_for_activation(false); 2118 active_layer_->LowResTiling()->set_can_require_tiles_for_activation(false);
1990 pending_layer()->HighResTiling()->set_can_require_tiles_for_activation(false); 2119 pending_layer_->HighResTiling()->set_can_require_tiles_for_activation(false);
1991 2120
1992 // If we disallow required for activation, no tiles can be required. 2121 // If we disallow required for activation, no tiles can be required.
1993 active_layer()->HighResTiling()->UpdateAllRequiredStateForTesting(); 2122 active_layer_->HighResTiling()->UpdateAllRequiredStateForTesting();
1994 active_layer()->LowResTiling()->UpdateAllRequiredStateForTesting(); 2123 active_layer_->LowResTiling()->UpdateAllRequiredStateForTesting();
1995 2124
1996 AssertNoTilesRequired(active_layer()->HighResTiling()); 2125 AssertNoTilesRequired(active_layer_->HighResTiling());
1997 AssertNoTilesRequired(active_layer()->LowResTiling()); 2126 AssertNoTilesRequired(active_layer_->LowResTiling());
1998 } 2127 }
1999 2128
2000 TEST_F(PictureLayerImplTest, NothingRequiredIfActiveMissingTiles) { 2129 TEST_F(PictureLayerImplTest, NothingRequiredIfActiveMissingTiles) {
2001 gfx::Size layer_bounds(400, 400); 2130 gfx::Size layer_bounds(400, 400);
2002 gfx::Size tile_size(100, 100); 2131 gfx::Size tile_size(100, 100);
2003 2132
2004 scoped_refptr<FakeRasterSource> pending_raster_source = 2133 scoped_refptr<FakeRasterSource> pending_raster_source =
2005 FakeRasterSource::CreateFilled(layer_bounds); 2134 FakeRasterSource::CreateFilled(layer_bounds);
2006 // This raster source will create tilings, but has no recordings so will not 2135 // This raster source will create tilings, but has no recordings so will not
2007 // create any tiles. This is attempting to simulate scrolling past the end of 2136 // create any tiles. This is attempting to simulate scrolling past the end of
2008 // recorded content on the active layer, where the recordings are so far away 2137 // recorded content on the active layer, where the recordings are so far away
2009 // that no tiles are created. 2138 // that no tiles are created.
2010 scoped_refptr<FakeRasterSource> active_raster_source = 2139 scoped_refptr<FakeRasterSource> active_raster_source =
2011 FakeRasterSource::CreatePartiallyFilled(layer_bounds, gfx::Rect()); 2140 FakeRasterSource::CreatePartiallyFilled(layer_bounds, gfx::Rect());
2012 2141
2013 SetupTreesWithFixedTileSize(pending_raster_source, active_raster_source, 2142 SetupTreesWithFixedTileSize(pending_raster_source, active_raster_source,
2014 tile_size, Region()); 2143 tile_size, Region());
2015 2144
2016 // Active layer has tilings, but no tiles due to missing recordings. 2145 // Active layer has tilings, but no tiles due to missing recordings.
2017 EXPECT_TRUE(active_layer()->CanHaveTilings()); 2146 EXPECT_TRUE(active_layer_->CanHaveTilings());
2018 EXPECT_EQ(active_layer()->tilings()->num_tilings(), 2u); 2147 EXPECT_EQ(active_layer_->tilings()->num_tilings(), 2u);
2019 EXPECT_EQ(active_layer()->HighResTiling()->AllTilesForTesting().size(), 0u); 2148 EXPECT_EQ(active_layer_->HighResTiling()->AllTilesForTesting().size(), 0u);
2020 2149
2021 // Since the active layer has no tiles at all, the pending layer doesn't 2150 // Since the active layer has no tiles at all, the pending layer doesn't
2022 // need content in order to activate. 2151 // need content in order to activate.
2023 pending_layer()->HighResTiling()->UpdateAllRequiredStateForTesting(); 2152 pending_layer_->HighResTiling()->UpdateAllRequiredStateForTesting();
2024 EXPECT_FALSE(pending_layer()->LowResTiling()); 2153 EXPECT_FALSE(pending_layer_->LowResTiling());
2025 2154
2026 AssertNoTilesRequired(pending_layer()->HighResTiling()); 2155 AssertNoTilesRequired(pending_layer_->HighResTiling());
2027 } 2156 }
2028 2157
2029 TEST_F(PictureLayerImplTest, HighResRequiredIfActiveCantHaveTiles) { 2158 TEST_F(PictureLayerImplTest, HighResRequiredIfActiveCantHaveTiles) {
2030 gfx::Size layer_bounds(400, 400); 2159 gfx::Size layer_bounds(400, 400);
2031 gfx::Size tile_size(100, 100); 2160 gfx::Size tile_size(100, 100);
2032 2161
2033 scoped_refptr<FakeRasterSource> pending_raster_source = 2162 scoped_refptr<FakeRasterSource> pending_raster_source =
2034 FakeRasterSource::CreateFilled(layer_bounds); 2163 FakeRasterSource::CreateFilled(layer_bounds);
2035 scoped_refptr<FakeRasterSource> active_raster_source = 2164 scoped_refptr<FakeRasterSource> active_raster_source =
2036 FakeRasterSource::CreateEmpty(layer_bounds); 2165 FakeRasterSource::CreateEmpty(layer_bounds);
2037 SetupTreesWithFixedTileSize(pending_raster_source, active_raster_source, 2166 SetupTreesWithFixedTileSize(pending_raster_source, active_raster_source,
2038 tile_size, Region()); 2167 tile_size, Region());
2039 2168
2040 // Active layer can't have tiles. 2169 // Active layer can't have tiles.
2041 EXPECT_FALSE(active_layer()->CanHaveTilings()); 2170 EXPECT_FALSE(active_layer_->CanHaveTilings());
2042 2171
2043 // All high res tiles required. This should be considered identical 2172 // All high res tiles required. This should be considered identical
2044 // to the case where there is no active layer, to avoid flashing content. 2173 // to the case where there is no active layer, to avoid flashing content.
2045 // This can happen if a layer exists for a while and switches from 2174 // This can happen if a layer exists for a while and switches from
2046 // not being able to have content to having content. 2175 // not being able to have content to having content.
2047 pending_layer()->HighResTiling()->UpdateAllRequiredStateForTesting(); 2176 pending_layer_->HighResTiling()->UpdateAllRequiredStateForTesting();
2048 EXPECT_FALSE(pending_layer()->LowResTiling()); 2177 EXPECT_FALSE(pending_layer_->LowResTiling());
2049 2178
2050 AssertAllTilesRequired(pending_layer()->HighResTiling()); 2179 AssertAllTilesRequired(pending_layer_->HighResTiling());
2051 } 2180 }
2052 2181
2053 TEST_F(PictureLayerImplTest, HighResRequiredWhenActiveHasDifferentBounds) { 2182 TEST_F(PictureLayerImplTest, HighResRequiredWhenActiveHasDifferentBounds) {
2054 gfx::Size pending_layer_bounds(400, 400); 2183 gfx::Size pending_layer_bounds(400, 400);
2055 gfx::Size active_layer_bounds(200, 200); 2184 gfx::Size active_layer_bounds(200, 200);
2056 gfx::Size tile_size(100, 100); 2185 gfx::Size tile_size(100, 100);
2057 2186
2058 scoped_refptr<FakeRasterSource> pending_raster_source = 2187 scoped_refptr<FakeRasterSource> pending_raster_source =
2059 FakeRasterSource::CreateFilled(pending_layer_bounds); 2188 FakeRasterSource::CreateFilled(pending_layer_bounds);
2060 scoped_refptr<FakeRasterSource> active_raster_source = 2189 scoped_refptr<FakeRasterSource> active_raster_source =
2061 FakeRasterSource::CreateFilled(active_layer_bounds); 2190 FakeRasterSource::CreateFilled(active_layer_bounds);
2062 2191
2063 SetupTreesWithFixedTileSize(pending_raster_source, active_raster_source, 2192 SetupTreesWithFixedTileSize(pending_raster_source, active_raster_source,
2064 tile_size, Region()); 2193 tile_size, Region());
2065 2194
2066 // Since the active layer has different bounds, the pending layer needs all 2195 // Since the active layer has different bounds, the pending layer needs all
2067 // high res tiles in order to activate. 2196 // high res tiles in order to activate.
2068 pending_layer()->HighResTiling()->UpdateAllRequiredStateForTesting(); 2197 pending_layer_->HighResTiling()->UpdateAllRequiredStateForTesting();
2069 EXPECT_FALSE(pending_layer()->LowResTiling()); 2198 EXPECT_FALSE(pending_layer_->LowResTiling());
2070 active_layer()->HighResTiling()->UpdateAllRequiredStateForTesting(); 2199 active_layer_->HighResTiling()->UpdateAllRequiredStateForTesting();
2071 active_layer()->LowResTiling()->UpdateAllRequiredStateForTesting(); 2200 active_layer_->LowResTiling()->UpdateAllRequiredStateForTesting();
2072 2201
2073 AssertAllTilesRequired(pending_layer()->HighResTiling()); 2202 AssertAllTilesRequired(pending_layer_->HighResTiling());
2074 AssertAllTilesRequired(active_layer()->HighResTiling()); 2203 AssertAllTilesRequired(active_layer_->HighResTiling());
2075 AssertNoTilesRequired(active_layer()->LowResTiling()); 2204 AssertNoTilesRequired(active_layer_->LowResTiling());
2076 } 2205 }
2077 2206
2078 TEST_F(PictureLayerImplTest, ActivateUninitializedLayer) { 2207 TEST_F(PictureLayerImplTest, ActivateUninitializedLayer) {
2079 gfx::Size layer_bounds(400, 400); 2208 gfx::Size layer_bounds(400, 400);
2080 scoped_refptr<FakeRasterSource> pending_raster_source = 2209 scoped_refptr<FakeRasterSource> pending_raster_source =
2081 FakeRasterSource::CreateFilled(layer_bounds); 2210 FakeRasterSource::CreateFilled(layer_bounds);
2082 2211
2083 host_impl()->CreatePendingTree(); 2212 host_impl_.CreatePendingTree();
2084 LayerTreeImpl* pending_tree = host_impl()->pending_tree(); 2213 LayerTreeImpl* pending_tree = host_impl_.pending_tree();
2085 2214
2086 std::unique_ptr<FakePictureLayerImpl> pending_layer = 2215 std::unique_ptr<FakePictureLayerImpl> pending_layer =
2087 FakePictureLayerImpl::CreateWithRasterSource(pending_tree, layer_id(), 2216 FakePictureLayerImpl::CreateWithRasterSource(pending_tree, id_,
2088 pending_raster_source); 2217 pending_raster_source);
2089 pending_layer->SetDrawsContent(true); 2218 pending_layer->SetDrawsContent(true);
2090 pending_tree->SetRootLayer(std::move(pending_layer)); 2219 pending_tree->SetRootLayer(std::move(pending_layer));
2091 2220
2092 FakePictureLayerImpl* raw_pending_layer = static_cast<FakePictureLayerImpl*>( 2221 pending_layer_ = static_cast<FakePictureLayerImpl*>(
2093 host_impl()->pending_tree()->LayerById(layer_id())); 2222 host_impl_.pending_tree()->LayerById(id_));
2094 2223
2095 // Set some state on the pending layer, make sure it is not clobbered 2224 // Set some state on the pending layer, make sure it is not clobbered
2096 // by a sync from the active layer. This could happen because if the 2225 // by a sync from the active layer. This could happen because if the
2097 // pending layer has not been post-commit initialized it will attempt 2226 // pending layer has not been post-commit initialized it will attempt
2098 // to sync from the active layer. 2227 // to sync from the active layer.
2099 float raster_page_scale = 10.f * raw_pending_layer->raster_page_scale(); 2228 float raster_page_scale = 10.f * pending_layer_->raster_page_scale();
2100 raw_pending_layer->set_raster_page_scale(raster_page_scale); 2229 pending_layer_->set_raster_page_scale(raster_page_scale);
2101 2230
2102 host_impl()->ActivateSyncTree(); 2231 host_impl_.ActivateSyncTree();
2103 2232
2104 FakePictureLayerImpl* raw_active_layer = static_cast<FakePictureLayerImpl*>( 2233 active_layer_ = static_cast<FakePictureLayerImpl*>(
2105 host_impl()->active_tree()->LayerById(layer_id())); 2234 host_impl_.active_tree()->LayerById(id_));
2106 2235
2107 EXPECT_EQ(0u, raw_active_layer->num_tilings()); 2236 EXPECT_EQ(0u, active_layer_->num_tilings());
2108 EXPECT_EQ(raster_page_scale, raw_active_layer->raster_page_scale()); 2237 EXPECT_EQ(raster_page_scale, active_layer_->raster_page_scale());
2109 } 2238 }
2110 2239
2111 TEST_F(PictureLayerImplTest, ShareTilesOnNextFrame) { 2240 TEST_F(PictureLayerImplTest, ShareTilesOnNextFrame) {
2112 gfx::Size layer_bounds(1500, 1500); 2241 gfx::Size layer_bounds(1500, 1500);
2113 2242
2114 scoped_refptr<FakeRasterSource> pending_raster_source = 2243 scoped_refptr<FakeRasterSource> pending_raster_source =
2115 FakeRasterSource::CreateFilled(layer_bounds); 2244 FakeRasterSource::CreateFilled(layer_bounds);
2116 2245
2117 SetupPendingTree(pending_raster_source); 2246 SetupPendingTree(pending_raster_source);
2118 2247
2119 PictureLayerTiling* tiling = pending_layer()->HighResTiling(); 2248 PictureLayerTiling* tiling = pending_layer_->HighResTiling();
2120 gfx::Rect first_invalidate = tiling->TilingDataForTesting().TileBounds(0, 0); 2249 gfx::Rect first_invalidate = tiling->TilingDataForTesting().TileBounds(0, 0);
2121 first_invalidate.Inset(tiling->TilingDataForTesting().border_texels(), 2250 first_invalidate.Inset(tiling->TilingDataForTesting().border_texels(),
2122 tiling->TilingDataForTesting().border_texels()); 2251 tiling->TilingDataForTesting().border_texels());
2123 gfx::Rect second_invalidate = tiling->TilingDataForTesting().TileBounds(1, 1); 2252 gfx::Rect second_invalidate = tiling->TilingDataForTesting().TileBounds(1, 1);
2124 second_invalidate.Inset(tiling->TilingDataForTesting().border_texels(), 2253 second_invalidate.Inset(tiling->TilingDataForTesting().border_texels(),
2125 tiling->TilingDataForTesting().border_texels()); 2254 tiling->TilingDataForTesting().border_texels());
2126 2255
2127 ActivateTree(); 2256 ActivateTree();
2128 2257
2129 // Make a pending tree with an invalidated raster tile 0,0. 2258 // Make a pending tree with an invalidated raster tile 0,0.
2130 SetupPendingTreeWithInvalidation(pending_raster_source, first_invalidate); 2259 SetupPendingTreeWithInvalidation(pending_raster_source, first_invalidate);
2131 2260
2132 // Activate and make a pending tree with an invalidated raster tile 1,1. 2261 // Activate and make a pending tree with an invalidated raster tile 1,1.
2133 ActivateTree(); 2262 ActivateTree();
2134 2263
2135 SetupPendingTreeWithInvalidation(pending_raster_source, second_invalidate); 2264 SetupPendingTreeWithInvalidation(pending_raster_source, second_invalidate);
2136 2265
2137 PictureLayerTiling* pending_tiling = pending_layer()->tilings()->tiling_at(0); 2266 PictureLayerTiling* pending_tiling = pending_layer_->tilings()->tiling_at(0);
2138 PictureLayerTiling* active_tiling = active_layer()->tilings()->tiling_at(0); 2267 PictureLayerTiling* active_tiling = active_layer_->tilings()->tiling_at(0);
2139 2268
2140 // Tile 0,0 not exist on pending, but tile 1,1 should. 2269 // Tile 0,0 not exist on pending, but tile 1,1 should.
2141 EXPECT_TRUE(active_tiling->TileAt(0, 0)); 2270 EXPECT_TRUE(active_tiling->TileAt(0, 0));
2142 EXPECT_TRUE(active_tiling->TileAt(1, 0)); 2271 EXPECT_TRUE(active_tiling->TileAt(1, 0));
2143 EXPECT_TRUE(active_tiling->TileAt(0, 1)); 2272 EXPECT_TRUE(active_tiling->TileAt(0, 1));
2144 EXPECT_FALSE(pending_tiling->TileAt(0, 0)); 2273 EXPECT_FALSE(pending_tiling->TileAt(0, 0));
2145 EXPECT_FALSE(pending_tiling->TileAt(1, 0)); 2274 EXPECT_FALSE(pending_tiling->TileAt(1, 0));
2146 EXPECT_FALSE(pending_tiling->TileAt(0, 1)); 2275 EXPECT_FALSE(pending_tiling->TileAt(0, 1));
2147 EXPECT_NE(active_tiling->TileAt(1, 1), pending_tiling->TileAt(1, 1)); 2276 EXPECT_NE(active_tiling->TileAt(1, 1), pending_tiling->TileAt(1, 1));
2148 EXPECT_TRUE(active_tiling->TileAt(1, 1)); 2277 EXPECT_TRUE(active_tiling->TileAt(1, 1));
2149 EXPECT_TRUE(pending_tiling->TileAt(1, 1)); 2278 EXPECT_TRUE(pending_tiling->TileAt(1, 1));
2150 2279
2151 // Drop the tiles on the active tree and recreate them. 2280 // Drop the tiles on the active tree and recreate them.
2152 active_layer()->tilings()->UpdateTilePriorities(gfx::Rect(), 1.f, 1.0, 2281 active_layer_->tilings()->UpdateTilePriorities(gfx::Rect(), 1.f, 1.0,
2153 Occlusion(), true); 2282 Occlusion(), true);
2154 EXPECT_TRUE(active_tiling->AllTilesForTesting().empty()); 2283 EXPECT_TRUE(active_tiling->AllTilesForTesting().empty());
2155 active_tiling->CreateAllTilesForTesting(); 2284 active_tiling->CreateAllTilesForTesting();
2156 2285
2157 // Tile 0,0 not exist on pending, but tile 1,1 should. 2286 // Tile 0,0 not exist on pending, but tile 1,1 should.
2158 EXPECT_TRUE(active_tiling->TileAt(0, 0)); 2287 EXPECT_TRUE(active_tiling->TileAt(0, 0));
2159 EXPECT_TRUE(active_tiling->TileAt(1, 0)); 2288 EXPECT_TRUE(active_tiling->TileAt(1, 0));
2160 EXPECT_TRUE(active_tiling->TileAt(0, 1)); 2289 EXPECT_TRUE(active_tiling->TileAt(0, 1));
2161 EXPECT_FALSE(pending_tiling->TileAt(0, 0)); 2290 EXPECT_FALSE(pending_tiling->TileAt(0, 0));
2162 EXPECT_FALSE(pending_tiling->TileAt(1, 0)); 2291 EXPECT_FALSE(pending_tiling->TileAt(1, 0));
2163 EXPECT_FALSE(pending_tiling->TileAt(0, 1)); 2292 EXPECT_FALSE(pending_tiling->TileAt(0, 1));
2164 EXPECT_NE(active_tiling->TileAt(1, 1), pending_tiling->TileAt(1, 1)); 2293 EXPECT_NE(active_tiling->TileAt(1, 1), pending_tiling->TileAt(1, 1));
2165 EXPECT_TRUE(active_tiling->TileAt(1, 1)); 2294 EXPECT_TRUE(active_tiling->TileAt(1, 1));
2166 EXPECT_TRUE(pending_tiling->TileAt(1, 1)); 2295 EXPECT_TRUE(pending_tiling->TileAt(1, 1));
2167 } 2296 }
2168 2297
2169 TEST_F(PictureLayerImplTest, PendingHasNoTilesWithNoInvalidation) { 2298 TEST_F(PictureLayerImplTest, PendingHasNoTilesWithNoInvalidation) {
2170 SetupDefaultTrees(gfx::Size(1500, 1500)); 2299 SetupDefaultTrees(gfx::Size(1500, 1500));
2171 2300
2172 EXPECT_GE(active_layer()->num_tilings(), 1u); 2301 EXPECT_GE(active_layer_->num_tilings(), 1u);
2173 EXPECT_GE(pending_layer()->num_tilings(), 1u); 2302 EXPECT_GE(pending_layer_->num_tilings(), 1u);
2174 2303
2175 // No invalidation. 2304 // No invalidation.
2176 PictureLayerTiling* active_tiling = active_layer()->tilings()->tiling_at(0); 2305 PictureLayerTiling* active_tiling = active_layer_->tilings()->tiling_at(0);
2177 PictureLayerTiling* pending_tiling = pending_layer()->tilings()->tiling_at(0); 2306 PictureLayerTiling* pending_tiling = pending_layer_->tilings()->tiling_at(0);
2178 ASSERT_TRUE(active_tiling); 2307 ASSERT_TRUE(active_tiling);
2179 ASSERT_TRUE(pending_tiling); 2308 ASSERT_TRUE(pending_tiling);
2180 2309
2181 EXPECT_TRUE(active_tiling->TileAt(0, 0)); 2310 EXPECT_TRUE(active_tiling->TileAt(0, 0));
2182 EXPECT_TRUE(active_tiling->TileAt(1, 0)); 2311 EXPECT_TRUE(active_tiling->TileAt(1, 0));
2183 EXPECT_TRUE(active_tiling->TileAt(0, 1)); 2312 EXPECT_TRUE(active_tiling->TileAt(0, 1));
2184 EXPECT_TRUE(active_tiling->TileAt(1, 1)); 2313 EXPECT_TRUE(active_tiling->TileAt(1, 1));
2185 2314
2186 EXPECT_FALSE(pending_tiling->TileAt(0, 0)); 2315 EXPECT_FALSE(pending_tiling->TileAt(0, 0));
2187 EXPECT_FALSE(pending_tiling->TileAt(1, 0)); 2316 EXPECT_FALSE(pending_tiling->TileAt(1, 0));
(...skipping 10 matching lines...) Expand all
2198 FakeRasterSource::CreateFilled(layer_bounds); 2327 FakeRasterSource::CreateFilled(layer_bounds);
2199 SetupTreesWithInvalidation(pending_raster_source, active_raster_source, 2328 SetupTreesWithInvalidation(pending_raster_source, active_raster_source,
2200 gfx::Rect(1, 1)); 2329 gfx::Rect(1, 1));
2201 // Activate the invalidation. 2330 // Activate the invalidation.
2202 ActivateTree(); 2331 ActivateTree();
2203 // Make another pending tree without any invalidation in it. 2332 // Make another pending tree without any invalidation in it.
2204 scoped_refptr<FakeRasterSource> pending_raster_source2 = 2333 scoped_refptr<FakeRasterSource> pending_raster_source2 =
2205 FakeRasterSource::CreateFilled(layer_bounds); 2334 FakeRasterSource::CreateFilled(layer_bounds);
2206 SetupPendingTree(pending_raster_source2); 2335 SetupPendingTree(pending_raster_source2);
2207 2336
2208 EXPECT_GE(active_layer()->num_tilings(), 1u); 2337 EXPECT_GE(active_layer_->num_tilings(), 1u);
2209 EXPECT_GE(pending_layer()->num_tilings(), 1u); 2338 EXPECT_GE(pending_layer_->num_tilings(), 1u);
2210 2339
2211 // The active tree invalidation was handled by the active tiles. 2340 // The active tree invalidation was handled by the active tiles.
2212 PictureLayerTiling* active_tiling = active_layer()->tilings()->tiling_at(0); 2341 PictureLayerTiling* active_tiling = active_layer_->tilings()->tiling_at(0);
2213 PictureLayerTiling* pending_tiling = pending_layer()->tilings()->tiling_at(0); 2342 PictureLayerTiling* pending_tiling = pending_layer_->tilings()->tiling_at(0);
2214 ASSERT_TRUE(active_tiling); 2343 ASSERT_TRUE(active_tiling);
2215 ASSERT_TRUE(pending_tiling); 2344 ASSERT_TRUE(pending_tiling);
2216 2345
2217 EXPECT_TRUE(active_tiling->TileAt(0, 0)); 2346 EXPECT_TRUE(active_tiling->TileAt(0, 0));
2218 EXPECT_TRUE(active_tiling->TileAt(1, 0)); 2347 EXPECT_TRUE(active_tiling->TileAt(1, 0));
2219 EXPECT_TRUE(active_tiling->TileAt(0, 1)); 2348 EXPECT_TRUE(active_tiling->TileAt(0, 1));
2220 EXPECT_TRUE(active_tiling->TileAt(1, 1)); 2349 EXPECT_TRUE(active_tiling->TileAt(1, 1));
2221 2350
2222 EXPECT_FALSE(pending_tiling->TileAt(0, 0)); 2351 EXPECT_FALSE(pending_tiling->TileAt(0, 0));
2223 EXPECT_FALSE(pending_tiling->TileAt(1, 0)); 2352 EXPECT_FALSE(pending_tiling->TileAt(1, 0));
2224 EXPECT_FALSE(pending_tiling->TileAt(0, 1)); 2353 EXPECT_FALSE(pending_tiling->TileAt(0, 1));
2225 EXPECT_FALSE(pending_tiling->TileAt(1, 1)); 2354 EXPECT_FALSE(pending_tiling->TileAt(1, 1));
2226 } 2355 }
2227 2356
2228 TEST_F(PictureLayerImplTest, RecreateInvalidPendingTreeTiles) { 2357 TEST_F(PictureLayerImplTest, RecreateInvalidPendingTreeTiles) {
2229 // Set some invalidation on the pending tree. We should replace raster tiles 2358 // Set some invalidation on the pending tree. We should replace raster tiles
2230 // that touch this. 2359 // that touch this.
2231 SetupDefaultTreesWithInvalidation(gfx::Size(1500, 1500), gfx::Rect(1, 1)); 2360 SetupDefaultTreesWithInvalidation(gfx::Size(1500, 1500), gfx::Rect(1, 1));
2232 2361
2233 EXPECT_GE(active_layer()->num_tilings(), 1u); 2362 EXPECT_GE(active_layer_->num_tilings(), 1u);
2234 EXPECT_GE(pending_layer()->num_tilings(), 1u); 2363 EXPECT_GE(pending_layer_->num_tilings(), 1u);
2235 2364
2236 // The pending tree invalidation creates tiles on the pending tree. 2365 // The pending tree invalidation creates tiles on the pending tree.
2237 PictureLayerTiling* active_tiling = active_layer()->tilings()->tiling_at(0); 2366 PictureLayerTiling* active_tiling = active_layer_->tilings()->tiling_at(0);
2238 PictureLayerTiling* pending_tiling = pending_layer()->tilings()->tiling_at(0); 2367 PictureLayerTiling* pending_tiling = pending_layer_->tilings()->tiling_at(0);
2239 ASSERT_TRUE(active_tiling); 2368 ASSERT_TRUE(active_tiling);
2240 ASSERT_TRUE(pending_tiling); 2369 ASSERT_TRUE(pending_tiling);
2241 2370
2242 EXPECT_TRUE(active_tiling->TileAt(0, 0)); 2371 EXPECT_TRUE(active_tiling->TileAt(0, 0));
2243 EXPECT_TRUE(active_tiling->TileAt(1, 0)); 2372 EXPECT_TRUE(active_tiling->TileAt(1, 0));
2244 EXPECT_TRUE(active_tiling->TileAt(0, 1)); 2373 EXPECT_TRUE(active_tiling->TileAt(0, 1));
2245 EXPECT_TRUE(active_tiling->TileAt(1, 1)); 2374 EXPECT_TRUE(active_tiling->TileAt(1, 1));
2246 2375
2247 EXPECT_TRUE(pending_tiling->TileAt(0, 0)); 2376 EXPECT_TRUE(pending_tiling->TileAt(0, 0));
2248 EXPECT_FALSE(pending_tiling->TileAt(1, 0)); 2377 EXPECT_FALSE(pending_tiling->TileAt(1, 0));
2249 EXPECT_FALSE(pending_tiling->TileAt(0, 1)); 2378 EXPECT_FALSE(pending_tiling->TileAt(0, 1));
2250 EXPECT_FALSE(pending_tiling->TileAt(1, 1)); 2379 EXPECT_FALSE(pending_tiling->TileAt(1, 1));
2251 2380
2252 EXPECT_NE(active_tiling->TileAt(0, 0), pending_tiling->TileAt(0, 0)); 2381 EXPECT_NE(active_tiling->TileAt(0, 0), pending_tiling->TileAt(0, 0));
2253 } 2382 }
2254 2383
2255 TEST_F(PictureLayerImplTest, SyncTilingAfterGpuRasterizationToggles) { 2384 TEST_F(PictureLayerImplTest, SyncTilingAfterGpuRasterizationToggles) {
2256 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); 2385 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
2257 2386
2258 gfx::Size layer_bounds(10, 10); 2387 gfx::Size layer_bounds(10, 10);
2259 2388
2260 scoped_refptr<FakeRasterSource> pending_raster_source = 2389 scoped_refptr<FakeRasterSource> pending_raster_source =
2261 FakeRasterSource::CreateFilled(layer_bounds); 2390 FakeRasterSource::CreateFilled(layer_bounds);
2262 scoped_refptr<FakeRasterSource> active_raster_source = 2391 scoped_refptr<FakeRasterSource> active_raster_source =
2263 FakeRasterSource::CreateFilled(layer_bounds); 2392 FakeRasterSource::CreateFilled(layer_bounds);
2264 2393
2265 SetupTrees(pending_raster_source, active_raster_source); 2394 SetupTrees(pending_raster_source, active_raster_source);
2266 2395
2267 EXPECT_TRUE(pending_layer()->tilings()->FindTilingWithScale(1.f)); 2396 EXPECT_TRUE(pending_layer_->tilings()->FindTilingWithScale(1.f));
2268 EXPECT_TRUE(active_layer()->tilings()->FindTilingWithScale(1.f)); 2397 EXPECT_TRUE(active_layer_->tilings()->FindTilingWithScale(1.f));
2269 2398
2270 // Gpu rasterization is disabled by default. 2399 // Gpu rasterization is disabled by default.
2271 EXPECT_FALSE(host_impl()->use_gpu_rasterization()); 2400 EXPECT_FALSE(host_impl_.use_gpu_rasterization());
2272 // Toggling the gpu rasterization clears all tilings on both trees. 2401 // Toggling the gpu rasterization clears all tilings on both trees.
2273 host_impl()->SetHasGpuRasterizationTrigger(true); 2402 host_impl_.SetHasGpuRasterizationTrigger(true);
2274 host_impl()->SetContentIsSuitableForGpuRasterization(true); 2403 host_impl_.SetContentIsSuitableForGpuRasterization(true);
2275 host_impl()->UpdateTreeResourcesForGpuRasterizationIfNeeded(); 2404 host_impl_.UpdateTreeResourcesForGpuRasterizationIfNeeded();
2276 EXPECT_EQ(0u, pending_layer()->tilings()->num_tilings()); 2405 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
2277 EXPECT_EQ(0u, active_layer()->tilings()->num_tilings()); 2406 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
2278 2407
2279 // Make sure that we can still add tiling to the pending layer, 2408 // Make sure that we can still add tiling to the pending layer,
2280 // that gets synced to the active layer. 2409 // that gets synced to the active layer.
2281 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); 2410 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
2282 bool update_lcd_text = false; 2411 bool update_lcd_text = false;
2283 host_impl()->pending_tree()->UpdateDrawProperties(update_lcd_text); 2412 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
2284 EXPECT_TRUE(pending_layer()->tilings()->FindTilingWithScale(1.f)); 2413 EXPECT_TRUE(pending_layer_->tilings()->FindTilingWithScale(1.f));
2285 2414
2286 ActivateTree(); 2415 ActivateTree();
2287 EXPECT_TRUE(active_layer()->tilings()->FindTilingWithScale(1.f)); 2416 EXPECT_TRUE(active_layer_->tilings()->FindTilingWithScale(1.f));
2288 2417
2289 SetupPendingTree(pending_raster_source); 2418 SetupPendingTree(pending_raster_source);
2290 EXPECT_TRUE(pending_layer()->tilings()->FindTilingWithScale(1.f)); 2419 EXPECT_TRUE(pending_layer_->tilings()->FindTilingWithScale(1.f));
2291 2420
2292 // Toggling the gpu rasterization clears all tilings on both trees. 2421 // Toggling the gpu rasterization clears all tilings on both trees.
2293 EXPECT_TRUE(host_impl()->use_gpu_rasterization()); 2422 EXPECT_TRUE(host_impl_.use_gpu_rasterization());
2294 host_impl()->SetHasGpuRasterizationTrigger(false); 2423 host_impl_.SetHasGpuRasterizationTrigger(false);
2295 host_impl()->UpdateTreeResourcesForGpuRasterizationIfNeeded(); 2424 host_impl_.UpdateTreeResourcesForGpuRasterizationIfNeeded();
2296 EXPECT_EQ(GpuRasterizationStatus::OFF_VIEWPORT, 2425 EXPECT_EQ(GpuRasterizationStatus::OFF_VIEWPORT,
2297 host_impl()->gpu_rasterization_status()); 2426 host_impl_.gpu_rasterization_status());
2298 EXPECT_EQ(0u, pending_layer()->tilings()->num_tilings()); 2427 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
2299 EXPECT_EQ(0u, active_layer()->tilings()->num_tilings()); 2428 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
2300 2429
2301 host_impl()->SetHasGpuRasterizationTrigger(true); 2430 host_impl_.SetHasGpuRasterizationTrigger(true);
2302 host_impl()->SetContentIsSuitableForGpuRasterization(false); 2431 host_impl_.SetContentIsSuitableForGpuRasterization(false);
2303 EXPECT_EQ(GpuRasterizationStatus::OFF_CONTENT, 2432 EXPECT_EQ(GpuRasterizationStatus::OFF_CONTENT,
2304 host_impl()->gpu_rasterization_status()); 2433 host_impl_.gpu_rasterization_status());
2305 } 2434 }
2306 2435
2307 TEST_F(PictureLayerImplTest, HighResCreatedWhenBoundsShrink) { 2436 TEST_F(PictureLayerImplTest, HighResCreatedWhenBoundsShrink) {
2308 // Put 0.5 as high res. 2437 // Put 0.5 as high res.
2309 SetInitialDeviceScaleFactor(0.5f); 2438 SetInitialDeviceScaleFactor(0.5f);
2310 2439
2311 scoped_refptr<FakeRasterSource> pending_raster_source = 2440 scoped_refptr<FakeRasterSource> pending_raster_source =
2312 FakeRasterSource::CreateFilled(gfx::Size(10, 10)); 2441 FakeRasterSource::CreateFilled(gfx::Size(10, 10));
2313 SetupPendingTree(pending_raster_source); 2442 SetupPendingTree(pending_raster_source);
2314 2443
2315 // Sanity checks. 2444 // Sanity checks.
2316 EXPECT_EQ(1u, pending_layer()->tilings()->num_tilings()); 2445 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings());
2317 EXPECT_TRUE(pending_layer()->tilings()->FindTilingWithScale(0.5f)); 2446 EXPECT_TRUE(pending_layer_->tilings()->FindTilingWithScale(0.5f));
2318 2447
2319 ActivateTree(); 2448 ActivateTree();
2320 2449
2321 // Now, set the bounds to be 1x1, so that minimum contents scale becomes 1. 2450 // Now, set the bounds to be 1x1, so that minimum contents scale becomes 1.
2322 pending_raster_source = FakeRasterSource::CreateFilled(gfx::Size(1, 1)); 2451 pending_raster_source = FakeRasterSource::CreateFilled(gfx::Size(1, 1));
2323 SetupPendingTree(pending_raster_source); 2452 SetupPendingTree(pending_raster_source);
2324 2453
2325 // Another sanity check. 2454 // Another sanity check.
2326 EXPECT_EQ(1.f, pending_layer()->MinimumContentsScale()); 2455 EXPECT_EQ(1.f, pending_layer_->MinimumContentsScale());
2327 2456
2328 // Since the MinContentsScale is 1, the 0.5 tiling should have been replaced 2457 // Since the MinContentsScale is 1, the 0.5 tiling should have been replaced
2329 // by a 1.0 tiling during the UDP in SetupPendingTree. 2458 // by a 1.0 tiling during the UDP in SetupPendingTree.
2330 EXPECT_EQ(1u, pending_layer()->tilings()->num_tilings()); 2459 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings());
2331 PictureLayerTiling* tiling = 2460 PictureLayerTiling* tiling =
2332 pending_layer()->tilings()->FindTilingWithScale(1.0f); 2461 pending_layer_->tilings()->FindTilingWithScale(1.0f);
2333 ASSERT_TRUE(tiling); 2462 ASSERT_TRUE(tiling);
2334 EXPECT_EQ(HIGH_RESOLUTION, tiling->resolution()); 2463 EXPECT_EQ(HIGH_RESOLUTION, tiling->resolution());
2335 } 2464 }
2336 2465
2337 TEST_F(PictureLayerImplTest, LowResTilingWithoutGpuRasterization) { 2466 TEST_F(PictureLayerImplTest, LowResTilingWithoutGpuRasterization) {
2338 gfx::Size default_tile_size(host_impl()->settings().default_tile_size); 2467 gfx::Size default_tile_size(host_impl_.settings().default_tile_size);
2339 gfx::Size layer_bounds(default_tile_size.width() * 4, 2468 gfx::Size layer_bounds(default_tile_size.width() * 4,
2340 default_tile_size.height() * 4); 2469 default_tile_size.height() * 4);
2341 2470
2342 host_impl()->SetHasGpuRasterizationTrigger(false); 2471 host_impl_.SetHasGpuRasterizationTrigger(false);
2343 2472
2344 SetupDefaultTrees(layer_bounds); 2473 SetupDefaultTrees(layer_bounds);
2345 EXPECT_FALSE(host_impl()->use_gpu_rasterization()); 2474 EXPECT_FALSE(host_impl_.use_gpu_rasterization());
2346 // Should have only a high-res tiling. 2475 // Should have only a high-res tiling.
2347 EXPECT_EQ(1u, pending_layer()->tilings()->num_tilings()); 2476 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings());
2348 ActivateTree(); 2477 ActivateTree();
2349 // Should add a high and a low res for active tree. 2478 // Should add a high and a low res for active tree.
2350 EXPECT_EQ(2u, active_layer()->tilings()->num_tilings()); 2479 EXPECT_EQ(2u, active_layer_->tilings()->num_tilings());
2351 } 2480 }
2352 2481
2353 TEST_F(PictureLayerImplTest, NoLowResTilingWithGpuRasterization) { 2482 TEST_F(PictureLayerImplTest, NoLowResTilingWithGpuRasterization) {
2354 gfx::Size default_tile_size(host_impl()->settings().default_tile_size); 2483 gfx::Size default_tile_size(host_impl_.settings().default_tile_size);
2355 gfx::Size layer_bounds(default_tile_size.width() * 4, 2484 gfx::Size layer_bounds(default_tile_size.width() * 4,
2356 default_tile_size.height() * 4); 2485 default_tile_size.height() * 4);
2357 2486
2358 host_impl()->SetHasGpuRasterizationTrigger(true); 2487 host_impl_.SetHasGpuRasterizationTrigger(true);
2359 host_impl()->SetContentIsSuitableForGpuRasterization(true); 2488 host_impl_.SetContentIsSuitableForGpuRasterization(true);
2360 2489
2361 SetupDefaultTrees(layer_bounds); 2490 SetupDefaultTrees(layer_bounds);
2362 EXPECT_TRUE(host_impl()->use_gpu_rasterization()); 2491 EXPECT_TRUE(host_impl_.use_gpu_rasterization());
2363 // Should only have the high-res tiling. 2492 // Should only have the high-res tiling.
2364 EXPECT_EQ(1u, pending_layer()->tilings()->num_tilings()); 2493 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings());
2365 ActivateTree(); 2494 ActivateTree();
2366 // Should only have the high-res tiling. 2495 // Should only have the high-res tiling.
2367 EXPECT_EQ(1u, active_layer()->tilings()->num_tilings()); 2496 EXPECT_EQ(1u, active_layer_->tilings()->num_tilings());
2368 } 2497 }
2369 2498
2370 TEST_F(PictureLayerImplTest, RequiredTilesWithGpuRasterization) { 2499 TEST_F(PictureLayerImplTest, RequiredTilesWithGpuRasterization) {
2371 host_impl()->SetHasGpuRasterizationTrigger(true); 2500 host_impl_.SetHasGpuRasterizationTrigger(true);
2372 host_impl()->SetContentIsSuitableForGpuRasterization(true); 2501 host_impl_.SetContentIsSuitableForGpuRasterization(true);
2373 2502
2374 gfx::Size viewport_size(1000, 1000); 2503 gfx::Size viewport_size(1000, 1000);
2375 host_impl()->SetViewportSize(viewport_size); 2504 host_impl_.SetViewportSize(viewport_size);
2376 2505
2377 gfx::Size layer_bounds(4000, 4000); 2506 gfx::Size layer_bounds(4000, 4000);
2378 SetupDefaultTrees(layer_bounds); 2507 SetupDefaultTrees(layer_bounds);
2379 EXPECT_TRUE(host_impl()->use_gpu_rasterization()); 2508 EXPECT_TRUE(host_impl_.use_gpu_rasterization());
2380 2509
2381 // Should only have the high-res tiling. 2510 // Should only have the high-res tiling.
2382 EXPECT_EQ(1u, active_layer()->tilings()->num_tilings()); 2511 EXPECT_EQ(1u, active_layer_->tilings()->num_tilings());
2383 2512
2384 active_layer()->HighResTiling()->UpdateAllRequiredStateForTesting(); 2513 active_layer_->HighResTiling()->UpdateAllRequiredStateForTesting();
2385 2514
2386 // High res tiling should have 64 tiles (4x16 tile grid). 2515 // High res tiling should have 64 tiles (4x16 tile grid).
2387 EXPECT_EQ(64u, active_layer()->HighResTiling()->AllTilesForTesting().size()); 2516 EXPECT_EQ(64u, active_layer_->HighResTiling()->AllTilesForTesting().size());
2388 2517
2389 // Visible viewport should be covered by 4 tiles. No other 2518 // Visible viewport should be covered by 4 tiles. No other
2390 // tiles should be required for activation. 2519 // tiles should be required for activation.
2391 EXPECT_EQ(4u, NumberOfTilesRequired(active_layer()->HighResTiling())); 2520 EXPECT_EQ(4u, NumberOfTilesRequired(active_layer_->HighResTiling()));
2392 } 2521 }
2393 2522
2394 TEST_F(PictureLayerImplTest, NoTilingIfDoesNotDrawContent) { 2523 TEST_F(PictureLayerImplTest, NoTilingIfDoesNotDrawContent) {
2395 // Set up layers with tilings. 2524 // Set up layers with tilings.
2396 SetupDefaultTrees(gfx::Size(10, 10)); 2525 SetupDefaultTrees(gfx::Size(10, 10));
2397 SetContentsScaleOnBothLayers(1.f, 1.f, 1.f, 1.f, 0.f, false); 2526 SetContentsScaleOnBothLayers(1.f, 1.f, 1.f, 1.f, 0.f, false);
2398 pending_layer()->PushPropertiesTo(active_layer()); 2527 pending_layer_->PushPropertiesTo(active_layer_);
2399 EXPECT_TRUE(pending_layer()->DrawsContent()); 2528 EXPECT_TRUE(pending_layer_->DrawsContent());
2400 EXPECT_TRUE(pending_layer()->CanHaveTilings()); 2529 EXPECT_TRUE(pending_layer_->CanHaveTilings());
2401 EXPECT_GE(pending_layer()->num_tilings(), 0u); 2530 EXPECT_GE(pending_layer_->num_tilings(), 0u);
2402 EXPECT_GE(active_layer()->num_tilings(), 0u); 2531 EXPECT_GE(active_layer_->num_tilings(), 0u);
2403 2532
2404 // Set content to false, which should make CanHaveTilings return false. 2533 // Set content to false, which should make CanHaveTilings return false.
2405 pending_layer()->SetDrawsContent(false); 2534 pending_layer_->SetDrawsContent(false);
2406 EXPECT_FALSE(pending_layer()->DrawsContent()); 2535 EXPECT_FALSE(pending_layer_->DrawsContent());
2407 EXPECT_FALSE(pending_layer()->CanHaveTilings()); 2536 EXPECT_FALSE(pending_layer_->CanHaveTilings());
2408 2537
2409 // No tilings should be pushed to active layer. 2538 // No tilings should be pushed to active layer.
2410 pending_layer()->PushPropertiesTo(active_layer()); 2539 pending_layer_->PushPropertiesTo(active_layer_);
2411 EXPECT_EQ(0u, active_layer()->num_tilings()); 2540 EXPECT_EQ(0u, active_layer_->num_tilings());
2412 } 2541 }
2413 2542
2414 TEST_F(PictureLayerImplTest, FirstTilingDuringPinch) { 2543 TEST_F(PictureLayerImplTest, FirstTilingDuringPinch) {
2415 SetupDefaultTrees(gfx::Size(10, 10)); 2544 SetupDefaultTrees(gfx::Size(10, 10));
2416 2545
2417 // We start with a tiling at scale 1. 2546 // We start with a tiling at scale 1.
2418 EXPECT_EQ(1.f, pending_layer()->HighResTiling()->contents_scale()); 2547 EXPECT_EQ(1.f, pending_layer_->HighResTiling()->contents_scale());
2419 2548
2420 // When we page scale up by 2.3, we get a new tiling that is a power of 2, in 2549 // When we page scale up by 2.3, we get a new tiling that is a power of 2, in
2421 // this case 4. 2550 // this case 4.
2422 host_impl()->PinchGestureBegin(); 2551 host_impl_.PinchGestureBegin();
2423 float high_res_scale = 2.3f; 2552 float high_res_scale = 2.3f;
2424 SetContentsScaleOnBothLayers(high_res_scale, 1.f, high_res_scale, 1.f, 0.f, 2553 SetContentsScaleOnBothLayers(high_res_scale, 1.f, high_res_scale, 1.f, 0.f,
2425 false); 2554 false);
2426 EXPECT_EQ(4.f, pending_layer()->HighResTiling()->contents_scale()); 2555 EXPECT_EQ(4.f, pending_layer_->HighResTiling()->contents_scale());
2427 } 2556 }
2428 2557
2429 TEST_F(PictureLayerImplTest, PinchingTooSmall) { 2558 TEST_F(PictureLayerImplTest, PinchingTooSmall) {
2430 SetupDefaultTrees(gfx::Size(10, 10)); 2559 SetupDefaultTrees(gfx::Size(10, 10));
2431 2560
2432 // We start with a tiling at scale 1. 2561 // We start with a tiling at scale 1.
2433 EXPECT_EQ(1.f, pending_layer()->HighResTiling()->contents_scale()); 2562 EXPECT_EQ(1.f, pending_layer_->HighResTiling()->contents_scale());
2434 2563
2435 host_impl()->PinchGestureBegin(); 2564 host_impl_.PinchGestureBegin();
2436 float high_res_scale = 0.0001f; 2565 float high_res_scale = 0.0001f;
2437 EXPECT_LT(high_res_scale, pending_layer()->MinimumContentsScale()); 2566 EXPECT_LT(high_res_scale, pending_layer_->MinimumContentsScale());
2438 2567
2439 SetContentsScaleOnBothLayers(high_res_scale, 1.f, high_res_scale, 1.f, 0.f, 2568 SetContentsScaleOnBothLayers(high_res_scale, 1.f, high_res_scale, 1.f, 0.f,
2440 false); 2569 false);
2441 EXPECT_FLOAT_EQ(pending_layer()->MinimumContentsScale(), 2570 EXPECT_FLOAT_EQ(pending_layer_->MinimumContentsScale(),
2442 pending_layer()->HighResTiling()->contents_scale()); 2571 pending_layer_->HighResTiling()->contents_scale());
2443 } 2572 }
2444 2573
2445 TEST_F(PictureLayerImplTest, PinchingTooSmallWithContentsScale) { 2574 TEST_F(PictureLayerImplTest, PinchingTooSmallWithContentsScale) {
2446 SetupDefaultTrees(gfx::Size(10, 10)); 2575 SetupDefaultTrees(gfx::Size(10, 10));
2447 2576
2448 ResetTilingsAndRasterScales(); 2577 ResetTilingsAndRasterScales();
2449 2578
2450 float contents_scale = 0.15f; 2579 float contents_scale = 0.15f;
2451 SetContentsScaleOnBothLayers(contents_scale, 1.f, 1.f, 1.f, 0.f, false); 2580 SetContentsScaleOnBothLayers(contents_scale, 1.f, 1.f, 1.f, 0.f, false);
2452 2581
2453 ASSERT_GE(pending_layer()->num_tilings(), 0u); 2582 ASSERT_GE(pending_layer_->num_tilings(), 0u);
2454 EXPECT_FLOAT_EQ(contents_scale, 2583 EXPECT_FLOAT_EQ(contents_scale,
2455 pending_layer()->HighResTiling()->contents_scale()); 2584 pending_layer_->HighResTiling()->contents_scale());
2456 2585
2457 host_impl()->PinchGestureBegin(); 2586 host_impl_.PinchGestureBegin();
2458 2587
2459 float page_scale = 0.0001f; 2588 float page_scale = 0.0001f;
2460 EXPECT_LT(page_scale * contents_scale, 2589 EXPECT_LT(page_scale * contents_scale,
2461 pending_layer()->MinimumContentsScale()); 2590 pending_layer_->MinimumContentsScale());
2462 2591
2463 SetContentsScaleOnBothLayers(contents_scale * page_scale, 1.f, page_scale, 2592 SetContentsScaleOnBothLayers(contents_scale * page_scale, 1.f, page_scale,
2464 1.f, 0.f, false); 2593 1.f, 0.f, false);
2465 ASSERT_GE(pending_layer()->num_tilings(), 0u); 2594 ASSERT_GE(pending_layer_->num_tilings(), 0u);
2466 EXPECT_FLOAT_EQ(pending_layer()->MinimumContentsScale(), 2595 EXPECT_FLOAT_EQ(pending_layer_->MinimumContentsScale(),
2467 pending_layer()->HighResTiling()->contents_scale()); 2596 pending_layer_->HighResTiling()->contents_scale());
2468 } 2597 }
2469 2598
2470 TEST_F(PictureLayerImplTest, ConsiderAnimationStartScaleForRasterScale) { 2599 TEST_F(PictureLayerImplTest, ConsiderAnimationStartScaleForRasterScale) {
2471 gfx::Size viewport_size(1000, 1000); 2600 gfx::Size viewport_size(1000, 1000);
2472 host_impl()->SetViewportSize(viewport_size); 2601 host_impl_.SetViewportSize(viewport_size);
2473 2602
2474 gfx::Size layer_bounds(100, 100); 2603 gfx::Size layer_bounds(100, 100);
2475 SetupDefaultTrees(layer_bounds); 2604 SetupDefaultTrees(layer_bounds);
2476 2605
2477 float contents_scale = 2.f; 2606 float contents_scale = 2.f;
2478 float device_scale = 1.f; 2607 float device_scale = 1.f;
2479 float page_scale = 1.f; 2608 float page_scale = 1.f;
2480 float maximum_animation_scale = 3.f; 2609 float maximum_animation_scale = 3.f;
2481 float starting_animation_scale = 1.f; 2610 float starting_animation_scale = 1.f;
2482 bool animating_transform = true; 2611 bool animating_transform = true;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2520 starting_animation_scale = 11.f; 2649 starting_animation_scale = 11.f;
2521 2650
2522 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale, 2651 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale,
2523 maximum_animation_scale, 2652 maximum_animation_scale,
2524 starting_animation_scale, animating_transform); 2653 starting_animation_scale, animating_transform);
2525 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f); 2654 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f);
2526 } 2655 }
2527 2656
2528 TEST_F(PictureLayerImplTest, HighResTilingDuringAnimationForCpuRasterization) { 2657 TEST_F(PictureLayerImplTest, HighResTilingDuringAnimationForCpuRasterization) {
2529 gfx::Size viewport_size(1000, 1000); 2658 gfx::Size viewport_size(1000, 1000);
2530 host_impl()->SetViewportSize(viewport_size); 2659 host_impl_.SetViewportSize(viewport_size);
2531 2660
2532 gfx::Size layer_bounds(100, 100); 2661 gfx::Size layer_bounds(100, 100);
2533 SetupDefaultTrees(layer_bounds); 2662 SetupDefaultTrees(layer_bounds);
2534 2663
2535 float contents_scale = 1.f; 2664 float contents_scale = 1.f;
2536 float device_scale = 1.f; 2665 float device_scale = 1.f;
2537 float page_scale = 1.f; 2666 float page_scale = 1.f;
2538 float maximum_animation_scale = 1.f; 2667 float maximum_animation_scale = 1.f;
2539 float starting_animation_scale = 0.f; 2668 float starting_animation_scale = 0.f;
2540 bool animating_transform = false; 2669 bool animating_transform = false;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
2663 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale, 2792 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale,
2664 maximum_animation_scale, 2793 maximum_animation_scale,
2665 starting_animation_scale, animating_transform); 2794 starting_animation_scale, animating_transform);
2666 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 11.f); 2795 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 11.f);
2667 } 2796 }
2668 2797
2669 TEST_F(PictureLayerImplTest, HighResTilingDuringAnimationForGpuRasterization) { 2798 TEST_F(PictureLayerImplTest, HighResTilingDuringAnimationForGpuRasterization) {
2670 gfx::Size layer_bounds(100, 100); 2799 gfx::Size layer_bounds(100, 100);
2671 gfx::Size viewport_size(1000, 1000); 2800 gfx::Size viewport_size(1000, 1000);
2672 SetupDefaultTrees(layer_bounds); 2801 SetupDefaultTrees(layer_bounds);
2673 host_impl()->SetViewportSize(viewport_size); 2802 host_impl_.SetViewportSize(viewport_size);
2674 host_impl()->SetHasGpuRasterizationTrigger(true); 2803 host_impl_.SetHasGpuRasterizationTrigger(true);
2675 host_impl()->SetContentIsSuitableForGpuRasterization(true); 2804 host_impl_.SetContentIsSuitableForGpuRasterization(true);
2676 host_impl()->UpdateTreeResourcesForGpuRasterizationIfNeeded(); 2805 host_impl_.UpdateTreeResourcesForGpuRasterizationIfNeeded();
2677 2806
2678 float contents_scale = 1.f; 2807 float contents_scale = 1.f;
2679 float device_scale = 1.3f; 2808 float device_scale = 1.3f;
2680 float page_scale = 1.4f; 2809 float page_scale = 1.4f;
2681 float maximum_animation_scale = 1.f; 2810 float maximum_animation_scale = 1.f;
2682 float starting_animation_scale = 0.f; 2811 float starting_animation_scale = 0.f;
2683 bool animating_transform = false; 2812 bool animating_transform = false;
2684 2813
2685 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale, 2814 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale,
2686 maximum_animation_scale, 2815 maximum_animation_scale,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2722 contents_scale = 4.f; 2851 contents_scale = 4.f;
2723 animating_transform = false; 2852 animating_transform = false;
2724 2853
2725 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale, 2854 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale,
2726 maximum_animation_scale, 2855 maximum_animation_scale,
2727 starting_animation_scale, animating_transform); 2856 starting_animation_scale, animating_transform);
2728 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f); 2857 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f);
2729 } 2858 }
2730 2859
2731 TEST_F(PictureLayerImplTest, TilingSetRasterQueue) { 2860 TEST_F(PictureLayerImplTest, TilingSetRasterQueue) {
2732 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); 2861 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
2733 2862
2734 host_impl()->SetViewportSize(gfx::Size(500, 500)); 2863 host_impl_.SetViewportSize(gfx::Size(500, 500));
2735 2864
2736 gfx::Size layer_bounds(1000, 1000); 2865 gfx::Size layer_bounds(1000, 1000);
2737 2866
2738 scoped_refptr<FakeRasterSource> pending_raster_source = 2867 scoped_refptr<FakeRasterSource> pending_raster_source =
2739 FakeRasterSource::CreateFilled(layer_bounds); 2868 FakeRasterSource::CreateFilled(layer_bounds);
2740 2869
2741 SetupPendingTree(pending_raster_source); 2870 SetupPendingTree(pending_raster_source);
2742 EXPECT_EQ(1u, pending_layer()->num_tilings()); 2871 EXPECT_EQ(1u, pending_layer_->num_tilings());
2743 2872
2744 std::set<Tile*> unique_tiles; 2873 std::set<Tile*> unique_tiles;
2745 bool reached_prepaint = false; 2874 bool reached_prepaint = false;
2746 int non_ideal_tile_count = 0u; 2875 int non_ideal_tile_count = 0u;
2747 int low_res_tile_count = 0u; 2876 int low_res_tile_count = 0u;
2748 int high_res_tile_count = 0u; 2877 int high_res_tile_count = 0u;
2749 int high_res_now_tiles = 0u; 2878 int high_res_now_tiles = 0u;
2750 std::unique_ptr<TilingSetRasterQueueAll> queue(new TilingSetRasterQueueAll( 2879 std::unique_ptr<TilingSetRasterQueueAll> queue(new TilingSetRasterQueueAll(
2751 pending_layer()->picture_layer_tiling_set(), false)); 2880 pending_layer_->picture_layer_tiling_set(), false));
2752 while (!queue->IsEmpty()) { 2881 while (!queue->IsEmpty()) {
2753 PrioritizedTile prioritized_tile = queue->Top(); 2882 PrioritizedTile prioritized_tile = queue->Top();
2754 TilePriority priority = prioritized_tile.priority(); 2883 TilePriority priority = prioritized_tile.priority();
2755 2884
2756 EXPECT_TRUE(prioritized_tile.tile()); 2885 EXPECT_TRUE(prioritized_tile.tile());
2757 2886
2758 // Non-high res tiles only get visible tiles. Also, prepaint should only 2887 // Non-high res tiles only get visible tiles. Also, prepaint should only
2759 // come at the end of the iteration. 2888 // come at the end of the iteration.
2760 if (priority.resolution != HIGH_RESOLUTION) { 2889 if (priority.resolution != HIGH_RESOLUTION) {
2761 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); 2890 EXPECT_EQ(TilePriority::NOW, priority.priority_bin);
(...skipping 19 matching lines...) Expand all
2781 2910
2782 // With layer size being 1000x1000 and default tile size 256x256, we expect to 2911 // With layer size being 1000x1000 and default tile size 256x256, we expect to
2783 // see 4 now tiles out of 16 total high res tiles. 2912 // see 4 now tiles out of 16 total high res tiles.
2784 EXPECT_EQ(16, high_res_tile_count); 2913 EXPECT_EQ(16, high_res_tile_count);
2785 EXPECT_EQ(4, high_res_now_tiles); 2914 EXPECT_EQ(4, high_res_now_tiles);
2786 EXPECT_EQ(low_res_tile_count + high_res_tile_count + non_ideal_tile_count, 2915 EXPECT_EQ(low_res_tile_count + high_res_tile_count + non_ideal_tile_count,
2787 static_cast<int>(unique_tiles.size())); 2916 static_cast<int>(unique_tiles.size()));
2788 2917
2789 std::unique_ptr<TilingSetRasterQueueRequired> required_queue( 2918 std::unique_ptr<TilingSetRasterQueueRequired> required_queue(
2790 new TilingSetRasterQueueRequired( 2919 new TilingSetRasterQueueRequired(
2791 pending_layer()->picture_layer_tiling_set(), 2920 pending_layer_->picture_layer_tiling_set(),
2792 RasterTilePriorityQueue::Type::REQUIRED_FOR_DRAW)); 2921 RasterTilePriorityQueue::Type::REQUIRED_FOR_DRAW));
2793 EXPECT_TRUE(required_queue->IsEmpty()); 2922 EXPECT_TRUE(required_queue->IsEmpty());
2794 2923
2795 required_queue.reset(new TilingSetRasterQueueRequired( 2924 required_queue.reset(new TilingSetRasterQueueRequired(
2796 pending_layer()->picture_layer_tiling_set(), 2925 pending_layer_->picture_layer_tiling_set(),
2797 RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION)); 2926 RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION));
2798 EXPECT_FALSE(required_queue->IsEmpty()); 2927 EXPECT_FALSE(required_queue->IsEmpty());
2799 int required_for_activation_count = 0; 2928 int required_for_activation_count = 0;
2800 while (!required_queue->IsEmpty()) { 2929 while (!required_queue->IsEmpty()) {
2801 PrioritizedTile prioritized_tile = required_queue->Top(); 2930 PrioritizedTile prioritized_tile = required_queue->Top();
2802 EXPECT_TRUE(prioritized_tile.tile()->required_for_activation()); 2931 EXPECT_TRUE(prioritized_tile.tile()->required_for_activation());
2803 EXPECT_FALSE(prioritized_tile.tile()->draw_info().IsReadyToDraw()); 2932 EXPECT_FALSE(prioritized_tile.tile()->draw_info().IsReadyToDraw());
2804 ++required_for_activation_count; 2933 ++required_for_activation_count;
2805 required_queue->Pop(); 2934 required_queue->Pop();
2806 } 2935 }
2807 2936
2808 // All of the high res tiles should be required for activation, since there is 2937 // All of the high res tiles should be required for activation, since there is
2809 // no active twin. 2938 // no active twin.
2810 EXPECT_EQ(high_res_now_tiles, required_for_activation_count); 2939 EXPECT_EQ(high_res_now_tiles, required_for_activation_count);
2811 2940
2812 // No NOW tiles. 2941 // No NOW tiles.
2813 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200)); 2942 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
2814 2943
2815 pending_layer()->draw_properties().visible_layer_rect = 2944 pending_layer_->draw_properties().visible_layer_rect =
2816 gfx::Rect(1100, 1100, 500, 500); 2945 gfx::Rect(1100, 1100, 500, 500);
2817 pending_layer()->UpdateTiles(); 2946 pending_layer_->UpdateTiles();
2818 2947
2819 unique_tiles.clear(); 2948 unique_tiles.clear();
2820 high_res_tile_count = 0u; 2949 high_res_tile_count = 0u;
2821 queue.reset(new TilingSetRasterQueueAll( 2950 queue.reset(new TilingSetRasterQueueAll(
2822 pending_layer()->picture_layer_tiling_set(), false)); 2951 pending_layer_->picture_layer_tiling_set(), false));
2823 while (!queue->IsEmpty()) { 2952 while (!queue->IsEmpty()) {
2824 PrioritizedTile prioritized_tile = queue->Top(); 2953 PrioritizedTile prioritized_tile = queue->Top();
2825 TilePriority priority = prioritized_tile.priority(); 2954 TilePriority priority = prioritized_tile.priority();
2826 2955
2827 EXPECT_TRUE(prioritized_tile.tile()); 2956 EXPECT_TRUE(prioritized_tile.tile());
2828 2957
2829 // Non-high res tiles only get visible tiles. 2958 // Non-high res tiles only get visible tiles.
2830 EXPECT_EQ(HIGH_RESOLUTION, priority.resolution); 2959 EXPECT_EQ(HIGH_RESOLUTION, priority.resolution);
2831 EXPECT_NE(TilePriority::NOW, priority.priority_bin); 2960 EXPECT_NE(TilePriority::NOW, priority.priority_bin);
2832 2961
2833 high_res_tile_count += priority.resolution == HIGH_RESOLUTION; 2962 high_res_tile_count += priority.resolution == HIGH_RESOLUTION;
2834 2963
2835 unique_tiles.insert(prioritized_tile.tile()); 2964 unique_tiles.insert(prioritized_tile.tile());
2836 queue->Pop(); 2965 queue->Pop();
2837 } 2966 }
2838 2967
2839 EXPECT_EQ(16, high_res_tile_count); 2968 EXPECT_EQ(16, high_res_tile_count);
2840 EXPECT_EQ(high_res_tile_count, static_cast<int>(unique_tiles.size())); 2969 EXPECT_EQ(high_res_tile_count, static_cast<int>(unique_tiles.size()));
2841 2970
2842 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200)); 2971 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
2843 2972
2844 pending_layer()->draw_properties().visible_layer_rect = 2973 pending_layer_->draw_properties().visible_layer_rect =
2845 gfx::Rect(0, 0, 500, 500); 2974 gfx::Rect(0, 0, 500, 500);
2846 pending_layer()->UpdateTiles(); 2975 pending_layer_->UpdateTiles();
2847 2976
2848 std::vector<Tile*> high_res_tiles = 2977 std::vector<Tile*> high_res_tiles =
2849 pending_layer()->HighResTiling()->AllTilesForTesting(); 2978 pending_layer_->HighResTiling()->AllTilesForTesting();
2850 for (std::vector<Tile*>::iterator tile_it = high_res_tiles.begin(); 2979 for (std::vector<Tile*>::iterator tile_it = high_res_tiles.begin();
2851 tile_it != high_res_tiles.end(); 2980 tile_it != high_res_tiles.end();
2852 ++tile_it) { 2981 ++tile_it) {
2853 Tile* tile = *tile_it; 2982 Tile* tile = *tile_it;
2854 TileDrawInfo& draw_info = tile->draw_info(); 2983 TileDrawInfo& draw_info = tile->draw_info();
2855 draw_info.SetSolidColorForTesting(SK_ColorRED); 2984 draw_info.SetSolidColorForTesting(SK_ColorRED);
2856 } 2985 }
2857 2986
2858 queue.reset(new TilingSetRasterQueueAll( 2987 queue.reset(new TilingSetRasterQueueAll(
2859 pending_layer()->picture_layer_tiling_set(), true)); 2988 pending_layer_->picture_layer_tiling_set(), true));
2860 EXPECT_TRUE(queue->IsEmpty()); 2989 EXPECT_TRUE(queue->IsEmpty());
2861 } 2990 }
2862 2991
2863 TEST_F(PictureLayerImplTest, TilingSetRasterQueueActiveTree) { 2992 TEST_F(PictureLayerImplTest, TilingSetRasterQueueActiveTree) {
2864 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); 2993 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
2865 2994
2866 host_impl()->SetViewportSize(gfx::Size(500, 500)); 2995 host_impl_.SetViewportSize(gfx::Size(500, 500));
2867 2996
2868 gfx::Size layer_bounds(1000, 1000); 2997 gfx::Size layer_bounds(1000, 1000);
2869 2998
2870 scoped_refptr<FakeRasterSource> pending_raster_source = 2999 scoped_refptr<FakeRasterSource> pending_raster_source =
2871 FakeRasterSource::CreateFilled(layer_bounds); 3000 FakeRasterSource::CreateFilled(layer_bounds);
2872 3001
2873 SetupPendingTree(pending_raster_source); 3002 SetupPendingTree(pending_raster_source);
2874 ActivateTree(); 3003 ActivateTree();
2875 EXPECT_EQ(2u, active_layer()->num_tilings()); 3004 EXPECT_EQ(2u, active_layer_->num_tilings());
2876 3005
2877 std::unique_ptr<TilingSetRasterQueueRequired> queue( 3006 std::unique_ptr<TilingSetRasterQueueRequired> queue(
2878 new TilingSetRasterQueueRequired( 3007 new TilingSetRasterQueueRequired(
2879 active_layer()->picture_layer_tiling_set(), 3008 active_layer_->picture_layer_tiling_set(),
2880 RasterTilePriorityQueue::Type::REQUIRED_FOR_DRAW)); 3009 RasterTilePriorityQueue::Type::REQUIRED_FOR_DRAW));
2881 EXPECT_FALSE(queue->IsEmpty()); 3010 EXPECT_FALSE(queue->IsEmpty());
2882 while (!queue->IsEmpty()) { 3011 while (!queue->IsEmpty()) {
2883 PrioritizedTile prioritized_tile = queue->Top(); 3012 PrioritizedTile prioritized_tile = queue->Top();
2884 EXPECT_TRUE(prioritized_tile.tile()->required_for_draw()); 3013 EXPECT_TRUE(prioritized_tile.tile()->required_for_draw());
2885 EXPECT_FALSE(prioritized_tile.tile()->draw_info().IsReadyToDraw()); 3014 EXPECT_FALSE(prioritized_tile.tile()->draw_info().IsReadyToDraw());
2886 queue->Pop(); 3015 queue->Pop();
2887 } 3016 }
2888 3017
2889 queue.reset(new TilingSetRasterQueueRequired( 3018 queue.reset(new TilingSetRasterQueueRequired(
2890 active_layer()->picture_layer_tiling_set(), 3019 active_layer_->picture_layer_tiling_set(),
2891 RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION)); 3020 RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION));
2892 EXPECT_TRUE(queue->IsEmpty()); 3021 EXPECT_TRUE(queue->IsEmpty());
2893 } 3022 }
2894 3023
2895 TEST_F(PictureLayerImplTest, TilingSetRasterQueueRequiredNoHighRes) { 3024 TEST_F(PictureLayerImplTest, TilingSetRasterQueueRequiredNoHighRes) {
2896 scoped_refptr<FakeRasterSource> pending_raster_source = 3025 scoped_refptr<FakeRasterSource> pending_raster_source =
2897 FakeRasterSource::CreateFilledSolidColor(gfx::Size(1024, 1024)); 3026 FakeRasterSource::CreateFilledSolidColor(gfx::Size(1024, 1024));
2898 3027
2899 SetupPendingTree(pending_raster_source); 3028 SetupPendingTree(pending_raster_source);
2900 EXPECT_FALSE( 3029 EXPECT_FALSE(
2901 pending_layer()->picture_layer_tiling_set()->FindTilingWithResolution( 3030 pending_layer_->picture_layer_tiling_set()->FindTilingWithResolution(
2902 HIGH_RESOLUTION)); 3031 HIGH_RESOLUTION));
2903 3032
2904 std::unique_ptr<TilingSetRasterQueueRequired> queue( 3033 std::unique_ptr<TilingSetRasterQueueRequired> queue(
2905 new TilingSetRasterQueueRequired( 3034 new TilingSetRasterQueueRequired(
2906 pending_layer()->picture_layer_tiling_set(), 3035 pending_layer_->picture_layer_tiling_set(),
2907 RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION)); 3036 RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION));
2908 EXPECT_TRUE(queue->IsEmpty()); 3037 EXPECT_TRUE(queue->IsEmpty());
2909 } 3038 }
2910 3039
2911 TEST_F(PictureLayerImplTest, TilingSetEvictionQueue) { 3040 TEST_F(PictureLayerImplTest, TilingSetEvictionQueue) {
2912 gfx::Size layer_bounds(1000, 1000); 3041 gfx::Size layer_bounds(1000, 1000);
2913 float low_res_factor = host_impl()->settings().low_res_contents_scale_factor; 3042 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
2914 3043
2915 host_impl()->SetViewportSize(gfx::Size(500, 500)); 3044 host_impl_.SetViewportSize(gfx::Size(500, 500));
2916 3045
2917 scoped_refptr<FakeRasterSource> pending_raster_source = 3046 scoped_refptr<FakeRasterSource> pending_raster_source =
2918 FakeRasterSource::CreateFilled(layer_bounds); 3047 FakeRasterSource::CreateFilled(layer_bounds);
2919 3048
2920 // TODO(vmpstr): Add a test with tilings other than high res on the active 3049 // TODO(vmpstr): Add a test with tilings other than high res on the active
2921 // tree (crbug.com/519607). 3050 // tree (crbug.com/519607).
2922 SetupPendingTree(pending_raster_source); 3051 SetupPendingTree(pending_raster_source);
2923 EXPECT_EQ(1u, pending_layer()->num_tilings()); 3052 EXPECT_EQ(1u, pending_layer_->num_tilings());
2924 3053
2925 std::vector<Tile*> all_tiles; 3054 std::vector<Tile*> all_tiles;
2926 for (size_t i = 0; i < pending_layer()->num_tilings(); ++i) { 3055 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) {
2927 PictureLayerTiling* tiling = pending_layer()->tilings()->tiling_at(i); 3056 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i);
2928 std::vector<Tile*> tiles = tiling->AllTilesForTesting(); 3057 std::vector<Tile*> tiles = tiling->AllTilesForTesting();
2929 all_tiles.insert(all_tiles.end(), tiles.begin(), tiles.end()); 3058 all_tiles.insert(all_tiles.end(), tiles.begin(), tiles.end());
2930 } 3059 }
2931 3060
2932 std::set<Tile*> all_tiles_set(all_tiles.begin(), all_tiles.end()); 3061 std::set<Tile*> all_tiles_set(all_tiles.begin(), all_tiles.end());
2933 3062
2934 bool mark_required = false; 3063 bool mark_required = false;
2935 size_t number_of_marked_tiles = 0u; 3064 size_t number_of_marked_tiles = 0u;
2936 size_t number_of_unmarked_tiles = 0u; 3065 size_t number_of_unmarked_tiles = 0u;
2937 for (size_t i = 0; i < pending_layer()->num_tilings(); ++i) { 3066 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) {
2938 PictureLayerTiling* tiling = pending_layer()->tilings()->tiling_at(i); 3067 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i);
2939 for (PictureLayerTiling::CoverageIterator iter( 3068 for (PictureLayerTiling::CoverageIterator iter(
2940 tiling, 1.f, pending_layer()->visible_layer_rect()); 3069 tiling, 1.f, pending_layer_->visible_layer_rect());
2941 iter; ++iter) { 3070 iter; ++iter) {
2942 if (mark_required) { 3071 if (mark_required) {
2943 number_of_marked_tiles++; 3072 number_of_marked_tiles++;
2944 iter->set_required_for_activation(true); 3073 iter->set_required_for_activation(true);
2945 } else { 3074 } else {
2946 number_of_unmarked_tiles++; 3075 number_of_unmarked_tiles++;
2947 } 3076 }
2948 mark_required = !mark_required; 3077 mark_required = !mark_required;
2949 } 3078 }
2950 } 3079 }
2951 3080
2952 // Sanity checks. 3081 // Sanity checks.
2953 EXPECT_EQ(16u, all_tiles.size()); 3082 EXPECT_EQ(16u, all_tiles.size());
2954 EXPECT_EQ(16u, all_tiles_set.size()); 3083 EXPECT_EQ(16u, all_tiles_set.size());
2955 EXPECT_GT(number_of_marked_tiles, 1u); 3084 EXPECT_GT(number_of_marked_tiles, 1u);
2956 EXPECT_GT(number_of_unmarked_tiles, 1u); 3085 EXPECT_GT(number_of_unmarked_tiles, 1u);
2957 3086
2958 // Tiles don't have resources yet. 3087 // Tiles don't have resources yet.
2959 std::unique_ptr<TilingSetEvictionQueue> queue( 3088 std::unique_ptr<TilingSetEvictionQueue> queue(
2960 new TilingSetEvictionQueue(pending_layer()->picture_layer_tiling_set())); 3089 new TilingSetEvictionQueue(pending_layer_->picture_layer_tiling_set()));
2961 EXPECT_TRUE(queue->IsEmpty()); 3090 EXPECT_TRUE(queue->IsEmpty());
2962 3091
2963 host_impl()->tile_manager()->InitializeTilesWithResourcesForTesting( 3092 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles);
2964 all_tiles);
2965 3093
2966 std::set<Tile*> unique_tiles; 3094 std::set<Tile*> unique_tiles;
2967 float expected_scales[] = {low_res_factor, 1.f}; 3095 float expected_scales[] = {low_res_factor, 1.f};
2968 size_t scale_index = 0; 3096 size_t scale_index = 0;
2969 bool reached_visible = false; 3097 bool reached_visible = false;
2970 PrioritizedTile last_tile; 3098 PrioritizedTile last_tile;
2971 size_t distance_decreasing = 0; 3099 size_t distance_decreasing = 0;
2972 size_t distance_increasing = 0; 3100 size_t distance_increasing = 0;
2973 queue.reset( 3101 queue.reset(
2974 new TilingSetEvictionQueue(pending_layer()->picture_layer_tiling_set())); 3102 new TilingSetEvictionQueue(pending_layer_->picture_layer_tiling_set()));
2975 while (!queue->IsEmpty()) { 3103 while (!queue->IsEmpty()) {
2976 PrioritizedTile prioritized_tile = queue->Top(); 3104 PrioritizedTile prioritized_tile = queue->Top();
2977 Tile* tile = prioritized_tile.tile(); 3105 Tile* tile = prioritized_tile.tile();
2978 if (!last_tile.tile()) 3106 if (!last_tile.tile())
2979 last_tile = prioritized_tile; 3107 last_tile = prioritized_tile;
2980 3108
2981 EXPECT_TRUE(tile); 3109 EXPECT_TRUE(tile);
2982 3110
2983 TilePriority priority = prioritized_tile.priority(); 3111 TilePriority priority = prioritized_tile.priority();
2984 3112
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
3051 EXPECT_TRUE(reached_required); 3179 EXPECT_TRUE(reached_required);
3052 EXPECT_EQ(all_tiles_set.size(), unique_tiles.size()); 3180 EXPECT_EQ(all_tiles_set.size(), unique_tiles.size());
3053 } 3181 }
3054 3182
3055 TEST_F(PictureLayerImplTest, Occlusion) { 3183 TEST_F(PictureLayerImplTest, Occlusion) {
3056 gfx::Size tile_size(102, 102); 3184 gfx::Size tile_size(102, 102);
3057 gfx::Size layer_bounds(1000, 1000); 3185 gfx::Size layer_bounds(1000, 1000);
3058 gfx::Size viewport_size(1000, 1000); 3186 gfx::Size viewport_size(1000, 1000);
3059 3187
3060 LayerTestCommon::LayerImplTest impl; 3188 LayerTestCommon::LayerImplTest impl;
3061 host_impl()->SetViewportSize(viewport_size); 3189 host_impl_.SetViewportSize(viewport_size);
3062 3190
3063 scoped_refptr<FakeRasterSource> pending_raster_source = 3191 scoped_refptr<FakeRasterSource> pending_raster_source =
3064 FakeRasterSource::CreateFilled(layer_bounds); 3192 FakeRasterSource::CreateFilled(layer_bounds);
3065 SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size, Region()); 3193 SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size, Region());
3066 ActivateTree(); 3194 ActivateTree();
3067 3195
3068 std::vector<Tile*> tiles = 3196 std::vector<Tile*> tiles =
3069 active_layer()->HighResTiling()->AllTilesForTesting(); 3197 active_layer_->HighResTiling()->AllTilesForTesting();
3070 host_impl()->tile_manager()->InitializeTilesWithResourcesForTesting(tiles); 3198 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(tiles);
3071 3199
3072 { 3200 {
3073 SCOPED_TRACE("No occlusion"); 3201 SCOPED_TRACE("No occlusion");
3074 gfx::Rect occluded; 3202 gfx::Rect occluded;
3075 impl.AppendQuadsWithOcclusion(active_layer(), occluded); 3203 impl.AppendQuadsWithOcclusion(active_layer_, occluded);
3076 3204
3077 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), 3205 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(),
3078 gfx::Rect(layer_bounds)); 3206 gfx::Rect(layer_bounds));
3079 EXPECT_EQ(100u, impl.quad_list().size()); 3207 EXPECT_EQ(100u, impl.quad_list().size());
3080 } 3208 }
3081 3209
3082 { 3210 {
3083 SCOPED_TRACE("Full occlusion"); 3211 SCOPED_TRACE("Full occlusion");
3084 gfx::Rect occluded(active_layer()->visible_layer_rect()); 3212 gfx::Rect occluded(active_layer_->visible_layer_rect());
3085 impl.AppendQuadsWithOcclusion(active_layer(), occluded); 3213 impl.AppendQuadsWithOcclusion(active_layer_, occluded);
3086 3214
3087 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), gfx::Rect()); 3215 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), gfx::Rect());
3088 EXPECT_EQ(impl.quad_list().size(), 0u); 3216 EXPECT_EQ(impl.quad_list().size(), 0u);
3089 } 3217 }
3090 3218
3091 { 3219 {
3092 SCOPED_TRACE("Partial occlusion"); 3220 SCOPED_TRACE("Partial occlusion");
3093 gfx::Rect occluded(150, 0, 200, 1000); 3221 gfx::Rect occluded(150, 0, 200, 1000);
3094 impl.AppendQuadsWithOcclusion(active_layer(), occluded); 3222 impl.AppendQuadsWithOcclusion(active_layer_, occluded);
3095 3223
3096 size_t partially_occluded_count = 0; 3224 size_t partially_occluded_count = 0;
3097 LayerTestCommon::VerifyQuadsAreOccluded( 3225 LayerTestCommon::VerifyQuadsAreOccluded(
3098 impl.quad_list(), occluded, &partially_occluded_count); 3226 impl.quad_list(), occluded, &partially_occluded_count);
3099 // The layer outputs one quad, which is partially occluded. 3227 // The layer outputs one quad, which is partially occluded.
3100 EXPECT_EQ(100u - 10u, impl.quad_list().size()); 3228 EXPECT_EQ(100u - 10u, impl.quad_list().size());
3101 EXPECT_EQ(10u + 10u, partially_occluded_count); 3229 EXPECT_EQ(10u + 10u, partially_occluded_count);
3102 } 3230 }
3103 } 3231 }
3104 3232
3105 TEST_F(PictureLayerImplTest, RasterScaleChangeWithoutAnimation) { 3233 TEST_F(PictureLayerImplTest, RasterScaleChangeWithoutAnimation) {
3106 gfx::Size tile_size(host_impl()->settings().default_tile_size); 3234 gfx::Size tile_size(host_impl_.settings().default_tile_size);
3107 SetupDefaultTrees(tile_size); 3235 SetupDefaultTrees(tile_size);
3108 3236
3109 ResetTilingsAndRasterScales(); 3237 ResetTilingsAndRasterScales();
3110 3238
3111 float contents_scale = 2.f; 3239 float contents_scale = 2.f;
3112 float device_scale = 1.f; 3240 float device_scale = 1.f;
3113 float page_scale = 1.f; 3241 float page_scale = 1.f;
3114 float maximum_animation_scale = 1.f; 3242 float maximum_animation_scale = 1.f;
3115 float starting_animation_scale = 0.f; 3243 float starting_animation_scale = 0.f;
3116 bool animating_transform = false; 3244 bool animating_transform = false;
(...skipping 24 matching lines...) Expand all
3141 3269
3142 TEST_F(PictureLayerImplTest, LowResReadyToDrawNotEnoughToActivate) { 3270 TEST_F(PictureLayerImplTest, LowResReadyToDrawNotEnoughToActivate) {
3143 gfx::Size tile_size(100, 100); 3271 gfx::Size tile_size(100, 100);
3144 gfx::Size layer_bounds(1000, 1000); 3272 gfx::Size layer_bounds(1000, 1000);
3145 3273
3146 // Make sure pending tree has tiles. 3274 // Make sure pending tree has tiles.
3147 gfx::Rect invalidation(gfx::Point(50, 50), tile_size); 3275 gfx::Rect invalidation(gfx::Point(50, 50), tile_size);
3148 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, invalidation); 3276 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, invalidation);
3149 3277
3150 // All pending layer tiles required are not ready. 3278 // All pending layer tiles required are not ready.
3151 EXPECT_FALSE(host_impl()->tile_manager()->IsReadyToActivate()); 3279 EXPECT_FALSE(host_impl_.tile_manager()->IsReadyToActivate());
3152 3280
3153 // Initialize all low-res tiles. 3281 // Initialize all low-res tiles.
3154 EXPECT_FALSE(pending_layer()->LowResTiling()); 3282 EXPECT_FALSE(pending_layer_->LowResTiling());
3155 pending_layer()->SetAllTilesReadyInTiling(active_layer()->LowResTiling()); 3283 pending_layer_->SetAllTilesReadyInTiling(active_layer_->LowResTiling());
3156 3284
3157 // Low-res tiles should not be enough. 3285 // Low-res tiles should not be enough.
3158 EXPECT_FALSE(host_impl()->tile_manager()->IsReadyToActivate()); 3286 EXPECT_FALSE(host_impl_.tile_manager()->IsReadyToActivate());
3159 3287
3160 // Initialize remaining tiles. 3288 // Initialize remaining tiles.
3161 pending_layer()->SetAllTilesReady(); 3289 pending_layer_->SetAllTilesReady();
3162 active_layer()->SetAllTilesReady(); 3290 active_layer_->SetAllTilesReady();
3163 3291
3164 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToActivate()); 3292 EXPECT_TRUE(host_impl_.tile_manager()->IsReadyToActivate());
3165 } 3293 }
3166 3294
3167 TEST_F(PictureLayerImplTest, HighResReadyToDrawEnoughToActivate) { 3295 TEST_F(PictureLayerImplTest, HighResReadyToDrawEnoughToActivate) {
3168 gfx::Size tile_size(100, 100); 3296 gfx::Size tile_size(100, 100);
3169 gfx::Size layer_bounds(1000, 1000); 3297 gfx::Size layer_bounds(1000, 1000);
3170 3298
3171 // Make sure pending tree has tiles. 3299 // Make sure pending tree has tiles.
3172 gfx::Rect invalidation(gfx::Point(50, 50), tile_size); 3300 gfx::Rect invalidation(gfx::Point(50, 50), tile_size);
3173 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, invalidation); 3301 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, invalidation);
3174 3302
3175 // All pending layer tiles required are not ready. 3303 // All pending layer tiles required are not ready.
3176 EXPECT_FALSE(host_impl()->tile_manager()->IsReadyToActivate()); 3304 EXPECT_FALSE(host_impl_.tile_manager()->IsReadyToActivate());
3177 3305
3178 // Initialize all high-res tiles. 3306 // Initialize all high-res tiles.
3179 pending_layer()->SetAllTilesReadyInTiling(pending_layer()->HighResTiling()); 3307 pending_layer_->SetAllTilesReadyInTiling(pending_layer_->HighResTiling());
3180 active_layer()->SetAllTilesReadyInTiling(active_layer()->HighResTiling()); 3308 active_layer_->SetAllTilesReadyInTiling(active_layer_->HighResTiling());
3181 3309
3182 // High-res tiles should be enough, since they cover everything visible. 3310 // High-res tiles should be enough, since they cover everything visible.
3183 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToActivate()); 3311 EXPECT_TRUE(host_impl_.tile_manager()->IsReadyToActivate());
3184 } 3312 }
3185 3313
3186 TEST_F(PictureLayerImplTest, ActiveHighResReadyNotEnoughToActivate) { 3314 TEST_F(PictureLayerImplTest, ActiveHighResReadyNotEnoughToActivate) {
3187 gfx::Size tile_size(100, 100); 3315 gfx::Size tile_size(100, 100);
3188 gfx::Size layer_bounds(1000, 1000); 3316 gfx::Size layer_bounds(1000, 1000);
3189 3317
3190 // Make sure pending tree has tiles. 3318 // Make sure pending tree has tiles.
3191 gfx::Rect invalidation(gfx::Point(50, 50), tile_size); 3319 gfx::Rect invalidation(gfx::Point(50, 50), tile_size);
3192 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, invalidation); 3320 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, invalidation);
3193 3321
3194 // Initialize all high-res tiles in the active layer. 3322 // Initialize all high-res tiles in the active layer.
3195 active_layer()->SetAllTilesReadyInTiling(active_layer()->HighResTiling()); 3323 active_layer_->SetAllTilesReadyInTiling(active_layer_->HighResTiling());
3196 3324
3197 // The pending high-res tiles are not ready, so we cannot activate. 3325 // The pending high-res tiles are not ready, so we cannot activate.
3198 EXPECT_FALSE(host_impl()->tile_manager()->IsReadyToActivate()); 3326 EXPECT_FALSE(host_impl_.tile_manager()->IsReadyToActivate());
3199 3327
3200 // When the pending high-res tiles are ready, we can activate. 3328 // When the pending high-res tiles are ready, we can activate.
3201 pending_layer()->SetAllTilesReadyInTiling(pending_layer()->HighResTiling()); 3329 pending_layer_->SetAllTilesReadyInTiling(pending_layer_->HighResTiling());
3202 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToActivate()); 3330 EXPECT_TRUE(host_impl_.tile_manager()->IsReadyToActivate());
3203 } 3331 }
3204 3332
3205 TEST_F(NoLowResPictureLayerImplTest, ManageTilingsCreatesTilings) { 3333 TEST_F(NoLowResPictureLayerImplTest, ManageTilingsCreatesTilings) {
3206 gfx::Size layer_bounds(1300, 1900); 3334 gfx::Size layer_bounds(1300, 1900);
3207 SetupDefaultTrees(layer_bounds); 3335 SetupDefaultTrees(layer_bounds);
3208 3336
3209 float low_res_factor = host_impl()->settings().low_res_contents_scale_factor; 3337 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
3210 EXPECT_LT(low_res_factor, 1.f); 3338 EXPECT_LT(low_res_factor, 1.f);
3211 3339
3212 ResetTilingsAndRasterScales(); 3340 ResetTilingsAndRasterScales();
3213 3341
3214 SetupDrawPropertiesAndUpdateTiles(active_layer(), 3342 SetupDrawPropertiesAndUpdateTiles(active_layer_,
3215 6.f, // ideal contents scale 3343 6.f, // ideal contents scale
3216 3.f, // device scale 3344 3.f, // device scale
3217 2.f, // page scale 3345 2.f, // page scale
3218 1.f, // maximum animation scale 3346 1.f, // maximum animation scale
3219 0.f, // starting animation scale 3347 0.f, // starting animation scale
3220 false); 3348 false);
3221 ASSERT_EQ(1u, active_layer()->tilings()->num_tilings()); 3349 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings());
3222 EXPECT_FLOAT_EQ(6.f, 3350 EXPECT_FLOAT_EQ(6.f,
3223 active_layer()->tilings()->tiling_at(0)->contents_scale()); 3351 active_layer_->tilings()->tiling_at(0)->contents_scale());
3224 3352
3225 // If we change the page scale factor, then we should get new tilings. 3353 // If we change the page scale factor, then we should get new tilings.
3226 SetupDrawPropertiesAndUpdateTiles(active_layer(), 3354 SetupDrawPropertiesAndUpdateTiles(active_layer_,
3227 6.6f, // ideal contents scale 3355 6.6f, // ideal contents scale
3228 3.f, // device scale 3356 3.f, // device scale
3229 2.2f, // page scale 3357 2.2f, // page scale
3230 1.f, // maximum animation scale 3358 1.f, // maximum animation scale
3231 0.f, // starting animation scale 3359 0.f, // starting animation scale
3232 false); 3360 false);
3233 ASSERT_EQ(2u, active_layer()->tilings()->num_tilings()); 3361 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
3234 EXPECT_FLOAT_EQ(6.6f, 3362 EXPECT_FLOAT_EQ(6.6f,
3235 active_layer()->tilings()->tiling_at(0)->contents_scale()); 3363 active_layer_->tilings()->tiling_at(0)->contents_scale());
3236 3364
3237 // If we change the device scale factor, then we should get new tilings. 3365 // If we change the device scale factor, then we should get new tilings.
3238 SetupDrawPropertiesAndUpdateTiles(active_layer(), 3366 SetupDrawPropertiesAndUpdateTiles(active_layer_,
3239 7.26f, // ideal contents scale 3367 7.26f, // ideal contents scale
3240 3.3f, // device scale 3368 3.3f, // device scale
3241 2.2f, // page scale 3369 2.2f, // page scale
3242 1.f, // maximum animation scale 3370 1.f, // maximum animation scale
3243 0.f, // starting animation scale 3371 0.f, // starting animation scale
3244 false); 3372 false);
3245 ASSERT_EQ(3u, active_layer()->tilings()->num_tilings()); 3373 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings());
3246 EXPECT_FLOAT_EQ(7.26f, 3374 EXPECT_FLOAT_EQ(7.26f,
3247 active_layer()->tilings()->tiling_at(0)->contents_scale()); 3375 active_layer_->tilings()->tiling_at(0)->contents_scale());
3248 3376
3249 // If we change the device scale factor, but end up at the same total scale 3377 // If we change the device scale factor, but end up at the same total scale
3250 // factor somehow, then we don't get new tilings. 3378 // factor somehow, then we don't get new tilings.
3251 SetupDrawPropertiesAndUpdateTiles(active_layer(), 3379 SetupDrawPropertiesAndUpdateTiles(active_layer_,
3252 7.26f, // ideal contents scale 3380 7.26f, // ideal contents scale
3253 2.2f, // device scale 3381 2.2f, // device scale
3254 3.3f, // page scale 3382 3.3f, // page scale
3255 1.f, // maximum animation scale 3383 1.f, // maximum animation scale
3256 0.f, // starting animation scale 3384 0.f, // starting animation scale
3257 false); 3385 false);
3258 ASSERT_EQ(3u, active_layer()->tilings()->num_tilings()); 3386 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings());
3259 EXPECT_FLOAT_EQ(7.26f, 3387 EXPECT_FLOAT_EQ(7.26f,
3260 active_layer()->tilings()->tiling_at(0)->contents_scale()); 3388 active_layer_->tilings()->tiling_at(0)->contents_scale());
3261 } 3389 }
3262 3390
3263 TEST_F(NoLowResPictureLayerImplTest, PendingLayerOnlyHasHighResTiling) { 3391 TEST_F(NoLowResPictureLayerImplTest, PendingLayerOnlyHasHighResTiling) {
3264 gfx::Size layer_bounds(1300, 1900); 3392 gfx::Size layer_bounds(1300, 1900);
3265 SetupDefaultTrees(layer_bounds); 3393 SetupDefaultTrees(layer_bounds);
3266 3394
3267 float low_res_factor = host_impl()->settings().low_res_contents_scale_factor; 3395 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
3268 EXPECT_LT(low_res_factor, 1.f); 3396 EXPECT_LT(low_res_factor, 1.f);
3269 3397
3270 ResetTilingsAndRasterScales(); 3398 ResetTilingsAndRasterScales();
3271 3399
3272 SetupDrawPropertiesAndUpdateTiles(pending_layer(), 3400 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
3273 6.f, // ideal contents scale 3401 6.f, // ideal contents scale
3274 3.f, // device scale 3402 3.f, // device scale
3275 2.f, // page scale 3403 2.f, // page scale
3276 1.f, // maximum animation scale 3404 1.f, // maximum animation scale
3277 0.f, // starting animation scale 3405 0.f, // starting animation scale
3278 false); 3406 false);
3279 ASSERT_EQ(1u, pending_layer()->tilings()->num_tilings()); 3407 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
3280 EXPECT_FLOAT_EQ(6.f, 3408 EXPECT_FLOAT_EQ(6.f,
3281 pending_layer()->tilings()->tiling_at(0)->contents_scale()); 3409 pending_layer_->tilings()->tiling_at(0)->contents_scale());
3282 3410
3283 // If we change the page scale factor, then we should get new tilings. 3411 // If we change the page scale factor, then we should get new tilings.
3284 SetupDrawPropertiesAndUpdateTiles(pending_layer(), 3412 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
3285 6.6f, // ideal contents scale 3413 6.6f, // ideal contents scale
3286 3.f, // device scale 3414 3.f, // device scale
3287 2.2f, // page scale 3415 2.2f, // page scale
3288 1.f, // maximum animation scale 3416 1.f, // maximum animation scale
3289 0.f, // starting animation scale 3417 0.f, // starting animation scale
3290 false); 3418 false);
3291 ASSERT_EQ(1u, pending_layer()->tilings()->num_tilings()); 3419 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
3292 EXPECT_FLOAT_EQ(6.6f, 3420 EXPECT_FLOAT_EQ(6.6f,
3293 pending_layer()->tilings()->tiling_at(0)->contents_scale()); 3421 pending_layer_->tilings()->tiling_at(0)->contents_scale());
3294 3422
3295 // If we change the device scale factor, then we should get new tilings. 3423 // If we change the device scale factor, then we should get new tilings.
3296 SetupDrawPropertiesAndUpdateTiles(pending_layer(), 3424 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
3297 7.26f, // ideal contents scale 3425 7.26f, // ideal contents scale
3298 3.3f, // device scale 3426 3.3f, // device scale
3299 2.2f, // page scale 3427 2.2f, // page scale
3300 1.f, // maximum animation scale 3428 1.f, // maximum animation scale
3301 0.f, // starting animation scale 3429 0.f, // starting animation scale
3302 false); 3430 false);
3303 ASSERT_EQ(1u, pending_layer()->tilings()->num_tilings()); 3431 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
3304 EXPECT_FLOAT_EQ(7.26f, 3432 EXPECT_FLOAT_EQ(7.26f,
3305 pending_layer()->tilings()->tiling_at(0)->contents_scale()); 3433 pending_layer_->tilings()->tiling_at(0)->contents_scale());
3306 3434
3307 // If we change the device scale factor, but end up at the same total scale 3435 // If we change the device scale factor, but end up at the same total scale
3308 // factor somehow, then we don't get new tilings. 3436 // factor somehow, then we don't get new tilings.
3309 SetupDrawPropertiesAndUpdateTiles(pending_layer(), 3437 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
3310 7.26f, // ideal contents scale 3438 7.26f, // ideal contents scale
3311 2.2f, // device scale 3439 2.2f, // device scale
3312 3.3f, // page scale 3440 3.3f, // page scale
3313 1.f, // maximum animation scale 3441 1.f, // maximum animation scale
3314 0.f, // starting animation scale 3442 0.f, // starting animation scale
3315 false); 3443 false);
3316 ASSERT_EQ(1u, pending_layer()->tilings()->num_tilings()); 3444 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
3317 EXPECT_FLOAT_EQ(7.26f, 3445 EXPECT_FLOAT_EQ(7.26f,
3318 pending_layer()->tilings()->tiling_at(0)->contents_scale()); 3446 pending_layer_->tilings()->tiling_at(0)->contents_scale());
3319 } 3447 }
3320 3448
3321 TEST_F(NoLowResPictureLayerImplTest, AllHighResRequiredEvenIfNotChanged) { 3449 TEST_F(NoLowResPictureLayerImplTest, AllHighResRequiredEvenIfNotChanged) {
3322 gfx::Size layer_bounds(400, 400); 3450 gfx::Size layer_bounds(400, 400);
3323 gfx::Size tile_size(100, 100); 3451 gfx::Size tile_size(100, 100);
3324 3452
3325 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, Region()); 3453 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, Region());
3326 3454
3327 Tile* some_active_tile = 3455 Tile* some_active_tile =
3328 active_layer()->HighResTiling()->AllTilesForTesting()[0]; 3456 active_layer_->HighResTiling()->AllTilesForTesting()[0];
3329 EXPECT_FALSE(some_active_tile->draw_info().IsReadyToDraw()); 3457 EXPECT_FALSE(some_active_tile->draw_info().IsReadyToDraw());
3330 3458
3331 // Since there is no invalidation, pending tree should have no tiles. 3459 // Since there is no invalidation, pending tree should have no tiles.
3332 EXPECT_TRUE(pending_layer()->HighResTiling()->AllTilesForTesting().empty()); 3460 EXPECT_TRUE(pending_layer_->HighResTiling()->AllTilesForTesting().empty());
3333 if (host_impl()->settings().create_low_res_tiling) 3461 if (host_impl_.settings().create_low_res_tiling)
3334 EXPECT_TRUE(pending_layer()->LowResTiling()->AllTilesForTesting().empty()); 3462 EXPECT_TRUE(pending_layer_->LowResTiling()->AllTilesForTesting().empty());
3335 3463
3336 active_layer()->HighResTiling()->UpdateAllRequiredStateForTesting(); 3464 active_layer_->HighResTiling()->UpdateAllRequiredStateForTesting();
3337 if (host_impl()->settings().create_low_res_tiling) 3465 if (host_impl_.settings().create_low_res_tiling)
3338 active_layer()->LowResTiling()->UpdateAllRequiredStateForTesting(); 3466 active_layer_->LowResTiling()->UpdateAllRequiredStateForTesting();
3339 3467
3340 AssertAllTilesRequired(active_layer()->HighResTiling()); 3468 AssertAllTilesRequired(active_layer_->HighResTiling());
3341 if (host_impl()->settings().create_low_res_tiling) 3469 if (host_impl_.settings().create_low_res_tiling)
3342 AssertNoTilesRequired(active_layer()->LowResTiling()); 3470 AssertNoTilesRequired(active_layer_->LowResTiling());
3343 } 3471 }
3344 3472
3345 TEST_F(NoLowResPictureLayerImplTest, NothingRequiredIfActiveMissingTiles) { 3473 TEST_F(NoLowResPictureLayerImplTest, NothingRequiredIfActiveMissingTiles) {
3346 gfx::Size layer_bounds(400, 400); 3474 gfx::Size layer_bounds(400, 400);
3347 gfx::Size tile_size(100, 100); 3475 gfx::Size tile_size(100, 100);
3348 3476
3349 scoped_refptr<FakeRasterSource> pending_raster_source = 3477 scoped_refptr<FakeRasterSource> pending_raster_source =
3350 FakeRasterSource::CreateFilled(layer_bounds); 3478 FakeRasterSource::CreateFilled(layer_bounds);
3351 // This raster source will create tilings, but has no recordings so will not 3479 // This raster source will create tilings, but has no recordings so will not
3352 // create any tiles. This is attempting to simulate scrolling past the end of 3480 // create any tiles. This is attempting to simulate scrolling past the end of
3353 // recorded content on the active layer, where the recordings are so far away 3481 // recorded content on the active layer, where the recordings are so far away
3354 // that no tiles are created. 3482 // that no tiles are created.
3355 scoped_refptr<FakeRasterSource> active_raster_source = 3483 scoped_refptr<FakeRasterSource> active_raster_source =
3356 FakeRasterSource::CreatePartiallyFilled(layer_bounds, gfx::Rect()); 3484 FakeRasterSource::CreatePartiallyFilled(layer_bounds, gfx::Rect());
3357 3485
3358 SetupTreesWithFixedTileSize(pending_raster_source, active_raster_source, 3486 SetupTreesWithFixedTileSize(pending_raster_source, active_raster_source,
3359 tile_size, Region()); 3487 tile_size, Region());
3360 3488
3361 // Active layer has tilings, but no tiles due to missing recordings. 3489 // Active layer has tilings, but no tiles due to missing recordings.
3362 EXPECT_TRUE(active_layer()->CanHaveTilings()); 3490 EXPECT_TRUE(active_layer_->CanHaveTilings());
3363 EXPECT_EQ(active_layer()->tilings()->num_tilings(), 3491 EXPECT_EQ(active_layer_->tilings()->num_tilings(),
3364 host_impl()->settings().create_low_res_tiling ? 2u : 1u); 3492 host_impl_.settings().create_low_res_tiling ? 2u : 1u);
3365 EXPECT_EQ(active_layer()->HighResTiling()->AllTilesForTesting().size(), 0u); 3493 EXPECT_EQ(active_layer_->HighResTiling()->AllTilesForTesting().size(), 0u);
3366 3494
3367 // Since the active layer has no tiles at all, the pending layer doesn't 3495 // Since the active layer has no tiles at all, the pending layer doesn't
3368 // need content in order to activate. 3496 // need content in order to activate.
3369 pending_layer()->HighResTiling()->UpdateAllRequiredStateForTesting(); 3497 pending_layer_->HighResTiling()->UpdateAllRequiredStateForTesting();
3370 if (host_impl()->settings().create_low_res_tiling) 3498 if (host_impl_.settings().create_low_res_tiling)
3371 pending_layer()->LowResTiling()->UpdateAllRequiredStateForTesting(); 3499 pending_layer_->LowResTiling()->UpdateAllRequiredStateForTesting();
3372 3500
3373 AssertNoTilesRequired(pending_layer()->HighResTiling()); 3501 AssertNoTilesRequired(pending_layer_->HighResTiling());
3374 if (host_impl()->settings().create_low_res_tiling) 3502 if (host_impl_.settings().create_low_res_tiling)
3375 AssertNoTilesRequired(pending_layer()->LowResTiling()); 3503 AssertNoTilesRequired(pending_layer_->LowResTiling());
3376 } 3504 }
3377 3505
3378 TEST_F(NoLowResPictureLayerImplTest, CleanUpTilings) { 3506 TEST_F(NoLowResPictureLayerImplTest, CleanUpTilings) {
3379 gfx::Size layer_bounds(1300, 1900); 3507 gfx::Size layer_bounds(1300, 1900);
3380 std::vector<PictureLayerTiling*> used_tilings; 3508 std::vector<PictureLayerTiling*> used_tilings;
3381 SetupDefaultTrees(layer_bounds); 3509 SetupDefaultTrees(layer_bounds);
3382 3510
3383 float low_res_factor = host_impl()->settings().low_res_contents_scale_factor; 3511 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
3384 EXPECT_LT(low_res_factor, 1.f); 3512 EXPECT_LT(low_res_factor, 1.f);
3385 3513
3386 float device_scale = 1.7f; 3514 float device_scale = 1.7f;
3387 float page_scale = 3.2f; 3515 float page_scale = 3.2f;
3388 float scale = 1.f; 3516 float scale = 1.f;
3389 3517
3390 ResetTilingsAndRasterScales(); 3518 ResetTilingsAndRasterScales();
3391 3519
3392 SetContentsScaleOnBothLayers(scale, device_scale, page_scale, 1.f, 0.f, 3520 SetContentsScaleOnBothLayers(scale, device_scale, page_scale, 1.f, 0.f,
3393 false); 3521 false);
3394 ASSERT_EQ(1u, active_layer()->tilings()->num_tilings()); 3522 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings());
3395 3523
3396 // Ensure UpdateTiles won't remove any tilings. Note this is unrelated to 3524 // Ensure UpdateTiles won't remove any tilings. Note this is unrelated to
3397 // |used_tilings| variable, and it's here only to ensure that active_layer() 3525 // |used_tilings| variable, and it's here only to ensure that active_layer_
3398 // won't remove tilings before the test has a chance to verify behavior. 3526 // won't remove tilings before the test has a chance to verify behavior.
3399 active_layer()->MarkAllTilingsUsed(); 3527 active_layer_->MarkAllTilingsUsed();
3400 3528
3401 // We only have ideal tilings, so they aren't removed. 3529 // We only have ideal tilings, so they aren't removed.
3402 used_tilings.clear(); 3530 used_tilings.clear();
3403 active_layer()->CleanUpTilingsOnActiveLayer(used_tilings); 3531 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
3404 ASSERT_EQ(1u, active_layer()->tilings()->num_tilings()); 3532 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings());
3405 3533
3406 host_impl()->PinchGestureBegin(); 3534 host_impl_.PinchGestureBegin();
3407 3535
3408 // Changing the ideal but not creating new tilings. 3536 // Changing the ideal but not creating new tilings.
3409 scale *= 1.5f; 3537 scale *= 1.5f;
3410 page_scale *= 1.5f; 3538 page_scale *= 1.5f;
3411 SetContentsScaleOnBothLayers(scale, device_scale, page_scale, 1.f, 0.f, 3539 SetContentsScaleOnBothLayers(scale, device_scale, page_scale, 1.f, 0.f,
3412 false); 3540 false);
3413 ASSERT_EQ(1u, active_layer()->tilings()->num_tilings()); 3541 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings());
3414 3542
3415 // The tilings are still our target scale, so they aren't removed. 3543 // The tilings are still our target scale, so they aren't removed.
3416 used_tilings.clear(); 3544 used_tilings.clear();
3417 active_layer()->CleanUpTilingsOnActiveLayer(used_tilings); 3545 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
3418 ASSERT_EQ(1u, active_layer()->tilings()->num_tilings()); 3546 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings());
3419 3547
3420 host_impl()->PinchGestureEnd(); 3548 host_impl_.PinchGestureEnd();
3421 3549
3422 // Create a 1.2 scale tiling. Now we have 1.0 and 1.2 tilings. Ideal = 1.2. 3550 // Create a 1.2 scale tiling. Now we have 1.0 and 1.2 tilings. Ideal = 1.2.
3423 scale /= 4.f; 3551 scale /= 4.f;
3424 page_scale /= 4.f; 3552 page_scale /= 4.f;
3425 SetContentsScaleOnBothLayers(1.2f, device_scale, page_scale, 1.f, 0.f, false); 3553 SetContentsScaleOnBothLayers(1.2f, device_scale, page_scale, 1.f, 0.f, false);
3426 ASSERT_EQ(2u, active_layer()->tilings()->num_tilings()); 3554 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
3427 EXPECT_FLOAT_EQ(1.f, 3555 EXPECT_FLOAT_EQ(1.f,
3428 active_layer()->tilings()->tiling_at(1)->contents_scale()); 3556 active_layer_->tilings()->tiling_at(1)->contents_scale());
3429 3557
3430 // Ensure UpdateTiles won't remove any tilings. 3558 // Ensure UpdateTiles won't remove any tilings.
3431 active_layer()->MarkAllTilingsUsed(); 3559 active_layer_->MarkAllTilingsUsed();
3432 3560
3433 // Mark the non-ideal tilings as used. They won't be removed. 3561 // Mark the non-ideal tilings as used. They won't be removed.
3434 used_tilings.clear(); 3562 used_tilings.clear();
3435 used_tilings.push_back(active_layer()->tilings()->tiling_at(1)); 3563 used_tilings.push_back(active_layer_->tilings()->tiling_at(1));
3436 active_layer()->CleanUpTilingsOnActiveLayer(used_tilings); 3564 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
3437 ASSERT_EQ(2u, active_layer()->tilings()->num_tilings()); 3565 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
3438 3566
3439 // Now move the ideal scale to 0.5. Our target stays 1.2. 3567 // Now move the ideal scale to 0.5. Our target stays 1.2.
3440 SetContentsScaleOnBothLayers(0.5f, device_scale, page_scale, 1.f, 0.f, false); 3568 SetContentsScaleOnBothLayers(0.5f, device_scale, page_scale, 1.f, 0.f, false);
3441 3569
3442 // The high resolution tiling is between target and ideal, so is not 3570 // The high resolution tiling is between target and ideal, so is not
3443 // removed. The low res tiling for the old ideal=1.0 scale is removed. 3571 // removed. The low res tiling for the old ideal=1.0 scale is removed.
3444 used_tilings.clear(); 3572 used_tilings.clear();
3445 active_layer()->CleanUpTilingsOnActiveLayer(used_tilings); 3573 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
3446 ASSERT_EQ(2u, active_layer()->tilings()->num_tilings()); 3574 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
3447 3575
3448 // Now move the ideal scale to 1.0. Our target stays 1.2. 3576 // Now move the ideal scale to 1.0. Our target stays 1.2.
3449 SetContentsScaleOnBothLayers(1.f, device_scale, page_scale, 1.f, 0.f, false); 3577 SetContentsScaleOnBothLayers(1.f, device_scale, page_scale, 1.f, 0.f, false);
3450 3578
3451 // All the tilings are between are target and the ideal, so they are not 3579 // All the tilings are between are target and the ideal, so they are not
3452 // removed. 3580 // removed.
3453 used_tilings.clear(); 3581 used_tilings.clear();
3454 active_layer()->CleanUpTilingsOnActiveLayer(used_tilings); 3582 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
3455 ASSERT_EQ(2u, active_layer()->tilings()->num_tilings()); 3583 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
3456 3584
3457 // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2. 3585 // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2.
3458 SetupDrawPropertiesAndUpdateTiles(active_layer(), 1.1f, device_scale, 3586 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.1f, device_scale,
3459 page_scale, 1.f, 0.f, false); 3587 page_scale, 1.f, 0.f, false);
3460 3588
3461 // Because the pending layer's ideal scale is still 1.0, our tilings fall 3589 // Because the pending layer's ideal scale is still 1.0, our tilings fall
3462 // in the range [1.0,1.2] and are kept. 3590 // in the range [1.0,1.2] and are kept.
3463 used_tilings.clear(); 3591 used_tilings.clear();
3464 active_layer()->CleanUpTilingsOnActiveLayer(used_tilings); 3592 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
3465 ASSERT_EQ(2u, active_layer()->tilings()->num_tilings()); 3593 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
3466 3594
3467 // Move the ideal scale on the pending layer to 1.1 as well. Our target stays 3595 // Move the ideal scale on the pending layer to 1.1 as well. Our target stays
3468 // 1.2 still. 3596 // 1.2 still.
3469 SetupDrawPropertiesAndUpdateTiles(pending_layer(), 1.1f, device_scale, 3597 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.1f, device_scale,
3470 page_scale, 1.f, 0.f, false); 3598 page_scale, 1.f, 0.f, false);
3471 3599
3472 // Our 1.0 tiling now falls outside the range between our ideal scale and our 3600 // Our 1.0 tiling now falls outside the range between our ideal scale and our
3473 // target raster scale. But it is in our used tilings set, so nothing is 3601 // target raster scale. But it is in our used tilings set, so nothing is
3474 // deleted. 3602 // deleted.
3475 used_tilings.clear(); 3603 used_tilings.clear();
3476 used_tilings.push_back(active_layer()->tilings()->tiling_at(1)); 3604 used_tilings.push_back(active_layer_->tilings()->tiling_at(1));
3477 active_layer()->CleanUpTilingsOnActiveLayer(used_tilings); 3605 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
3478 ASSERT_EQ(2u, active_layer()->tilings()->num_tilings()); 3606 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
3479 3607
3480 // If we remove it from our used tilings set, it is outside the range to keep 3608 // If we remove it from our used tilings set, it is outside the range to keep
3481 // so it is deleted. 3609 // so it is deleted.
3482 used_tilings.clear(); 3610 used_tilings.clear();
3483 active_layer()->CleanUpTilingsOnActiveLayer(used_tilings); 3611 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
3484 ASSERT_EQ(1u, active_layer()->tilings()->num_tilings()); 3612 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings());
3485 } 3613 }
3486 3614
3487 TEST_F(NoLowResPictureLayerImplTest, ReleaseResources) { 3615 TEST_F(NoLowResPictureLayerImplTest, ReleaseResources) {
3488 gfx::Size layer_bounds(1300, 1900); 3616 gfx::Size layer_bounds(1300, 1900);
3489 SetupDefaultTrees(layer_bounds); 3617 SetupDefaultTrees(layer_bounds);
3490 EXPECT_EQ(1u, pending_layer()->tilings()->num_tilings()); 3618 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings());
3491 EXPECT_EQ(1u, active_layer()->tilings()->num_tilings()); 3619 EXPECT_EQ(1u, active_layer_->tilings()->num_tilings());
3492 3620
3493 // All tilings should be removed when losing output surface. 3621 // All tilings should be removed when losing output surface.
3494 active_layer()->ReleaseResources(); 3622 active_layer_->ReleaseResources();
3495 EXPECT_FALSE(active_layer()->tilings()); 3623 EXPECT_FALSE(active_layer_->tilings());
3496 active_layer()->RecreateResources(); 3624 active_layer_->RecreateResources();
3497 EXPECT_EQ(0u, active_layer()->tilings()->num_tilings()); 3625 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
3498 pending_layer()->ReleaseResources(); 3626 pending_layer_->ReleaseResources();
3499 EXPECT_FALSE(pending_layer()->tilings()); 3627 EXPECT_FALSE(pending_layer_->tilings());
3500 pending_layer()->RecreateResources(); 3628 pending_layer_->RecreateResources();
3501 EXPECT_EQ(0u, pending_layer()->tilings()->num_tilings()); 3629 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
3502 3630
3503 // This should create new tilings. 3631 // This should create new tilings.
3504 SetupDrawPropertiesAndUpdateTiles(pending_layer(), 3632 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
3505 1.3f, // ideal contents scale 3633 1.3f, // ideal contents scale
3506 2.7f, // device scale 3634 2.7f, // device scale
3507 3.2f, // page scale 3635 3.2f, // page scale
3508 1.f, // maximum animation scale 3636 1.f, // maximum animation scale
3509 0.f, // starting animation scale 3637 0.f, // starting animation scale
3510 false); 3638 false);
3511 EXPECT_EQ(1u, pending_layer()->tilings()->num_tilings()); 3639 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings());
3512 } 3640 }
3513 3641
3514 TEST_F(PictureLayerImplTest, SharedQuadStateContainsMaxTilingScale) { 3642 TEST_F(PictureLayerImplTest, SharedQuadStateContainsMaxTilingScale) {
3515 std::unique_ptr<RenderPass> render_pass = RenderPass::Create(); 3643 std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
3516 3644
3517 gfx::Size layer_bounds(1000, 2000); 3645 gfx::Size layer_bounds(1000, 2000);
3518 host_impl()->SetViewportSize(gfx::Size(10000, 20000)); 3646 host_impl_.SetViewportSize(gfx::Size(10000, 20000));
3519 SetupDefaultTrees(layer_bounds); 3647 SetupDefaultTrees(layer_bounds);
3520 3648
3521 ResetTilingsAndRasterScales(); 3649 ResetTilingsAndRasterScales();
3522 SetupDrawPropertiesAndUpdateTiles(active_layer(), 2.5f, 1.f, 1.f, 1.f, 0.f, 3650 SetupDrawPropertiesAndUpdateTiles(active_layer_, 2.5f, 1.f, 1.f, 1.f, 0.f,
3523 false); 3651 false);
3524 3652
3525 float max_contents_scale = active_layer()->MaximumTilingContentsScale(); 3653 float max_contents_scale = active_layer_->MaximumTilingContentsScale();
3526 EXPECT_EQ(2.5f, max_contents_scale); 3654 EXPECT_EQ(2.5f, max_contents_scale);
3527 3655
3528 gfx::Transform scaled_draw_transform = active_layer()->DrawTransform(); 3656 gfx::Transform scaled_draw_transform = active_layer_->DrawTransform();
3529 scaled_draw_transform.Scale(SK_MScalar1 / max_contents_scale, 3657 scaled_draw_transform.Scale(SK_MScalar1 / max_contents_scale,
3530 SK_MScalar1 / max_contents_scale); 3658 SK_MScalar1 / max_contents_scale);
3531 3659
3532 AppendQuadsData data; 3660 AppendQuadsData data;
3533 active_layer()->AppendQuads(render_pass.get(), &data); 3661 active_layer_->AppendQuads(render_pass.get(), &data);
3534 3662
3535 // SharedQuadState should have be of size 1, as we are doing AppenQuad once. 3663 // SharedQuadState should have be of size 1, as we are doing AppenQuad once.
3536 EXPECT_EQ(1u, render_pass->shared_quad_state_list.size()); 3664 EXPECT_EQ(1u, render_pass->shared_quad_state_list.size());
3537 // The quad_to_target_transform should be scaled by the 3665 // The quad_to_target_transform should be scaled by the
3538 // MaximumTilingContentsScale on the layer. 3666 // MaximumTilingContentsScale on the layer.
3539 EXPECT_EQ(scaled_draw_transform.ToString(), 3667 EXPECT_EQ(scaled_draw_transform.ToString(),
3540 render_pass->shared_quad_state_list.front() 3668 render_pass->shared_quad_state_list.front()
3541 ->quad_to_target_transform.ToString()); 3669 ->quad_to_target_transform.ToString());
3542 // The content_bounds should be scaled by the 3670 // The content_bounds should be scaled by the
3543 // MaximumTilingContentsScale on the layer. 3671 // MaximumTilingContentsScale on the layer.
3544 EXPECT_EQ(gfx::Size(2500u, 5000u).ToString(), 3672 EXPECT_EQ(gfx::Size(2500u, 5000u).ToString(),
3545 render_pass->shared_quad_state_list.front() 3673 render_pass->shared_quad_state_list.front()
3546 ->quad_layer_bounds.ToString()); 3674 ->quad_layer_bounds.ToString());
3547 // The visible_layer_rect should be scaled by the 3675 // The visible_layer_rect should be scaled by the
3548 // MaximumTilingContentsScale on the layer. 3676 // MaximumTilingContentsScale on the layer.
3549 EXPECT_EQ(gfx::Rect(0u, 0u, 2500u, 5000u).ToString(), 3677 EXPECT_EQ(gfx::Rect(0u, 0u, 2500u, 5000u).ToString(),
3550 render_pass->shared_quad_state_list.front() 3678 render_pass->shared_quad_state_list.front()
3551 ->visible_quad_layer_rect.ToString()); 3679 ->visible_quad_layer_rect.ToString());
3552 } 3680 }
3553 3681
3554 class PictureLayerImplTestWithDelegatingRenderer : public PictureLayerImplTest { 3682 class PictureLayerImplTestWithDelegatingRenderer : public PictureLayerImplTest {
3555 public: 3683 public:
3556 std::unique_ptr<OutputSurface> CreateOutputSurface() override { 3684 PictureLayerImplTestWithDelegatingRenderer() : PictureLayerImplTest() {
3557 return FakeOutputSurface::CreateDelegating3d(); 3685 output_surface_ = FakeOutputSurface::CreateDelegating3d();
3686 }
3687
3688 void InitializeRenderer() override {
3689 host_impl_.SetVisible(true);
3690 host_impl_.InitializeRenderer(output_surface_.get());
3558 } 3691 }
3559 }; 3692 };
3560 3693
3561 TEST_F(PictureLayerImplTestWithDelegatingRenderer, 3694 TEST_F(PictureLayerImplTestWithDelegatingRenderer,
3562 DelegatingRendererWithTileOOM) { 3695 DelegatingRendererWithTileOOM) {
3563 // This test is added for crbug.com/402321, where quad should be produced when 3696 // This test is added for crbug.com/402321, where quad should be produced when
3564 // raster on demand is not allowed and tile is OOM. 3697 // raster on demand is not allowed and tile is OOM.
3565 gfx::Size layer_bounds(1000, 1000); 3698 gfx::Size layer_bounds(1000, 1000);
3566 3699
3567 // Create tiles. 3700 // Create tiles.
3568 scoped_refptr<FakeRasterSource> pending_raster_source = 3701 scoped_refptr<FakeRasterSource> pending_raster_source =
3569 FakeRasterSource::CreateFilled(layer_bounds); 3702 FakeRasterSource::CreateFilled(layer_bounds);
3570 SetupPendingTree(pending_raster_source); 3703 SetupPendingTree(pending_raster_source);
3571 pending_layer()->SetBounds(layer_bounds); 3704 pending_layer_->SetBounds(layer_bounds);
3572 ActivateTree(); 3705 ActivateTree();
3573 bool update_lcd_text = false; 3706 bool update_lcd_text = false;
3574 host_impl()->active_tree()->UpdateDrawProperties(update_lcd_text); 3707 host_impl_.active_tree()->UpdateDrawProperties(update_lcd_text);
3575 std::vector<Tile*> tiles = 3708 std::vector<Tile*> tiles =
3576 active_layer()->HighResTiling()->AllTilesForTesting(); 3709 active_layer_->HighResTiling()->AllTilesForTesting();
3577 host_impl()->tile_manager()->InitializeTilesWithResourcesForTesting(tiles); 3710 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(tiles);
3578 3711
3579 // Force tiles after max_tiles to be OOM. TileManager uses 3712 // Force tiles after max_tiles to be OOM. TileManager uses
3580 // GlobalStateThatImpactsTilesPriority from LayerTreeHostImpl, and we cannot 3713 // GlobalStateThatImpactsTilesPriority from LayerTreeHostImpl, and we cannot
3581 // directly set state to host_impl_, so we set policy that would change the 3714 // directly set state to host_impl_, so we set policy that would change the
3582 // state. We also need to update tree priority separately. 3715 // state. We also need to update tree priority separately.
3583 GlobalStateThatImpactsTilePriority state; 3716 GlobalStateThatImpactsTilePriority state;
3584 size_t max_tiles = 1; 3717 size_t max_tiles = 1;
3585 gfx::Size tile_size(host_impl()->settings().default_tile_size); 3718 gfx::Size tile_size(host_impl_.settings().default_tile_size);
3586 size_t memory_limit = max_tiles * 4 * tile_size.width() * tile_size.height(); 3719 size_t memory_limit = max_tiles * 4 * tile_size.width() * tile_size.height();
3587 size_t resource_limit = max_tiles; 3720 size_t resource_limit = max_tiles;
3588 ManagedMemoryPolicy policy(memory_limit, 3721 ManagedMemoryPolicy policy(memory_limit,
3589 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING, 3722 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING,
3590 resource_limit); 3723 resource_limit);
3591 host_impl()->SetMemoryPolicy(policy); 3724 host_impl_.SetMemoryPolicy(policy);
3592 host_impl()->SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES); 3725 host_impl_.SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES);
3593 host_impl()->PrepareTiles(); 3726 host_impl_.PrepareTiles();
3594 3727
3595 std::unique_ptr<RenderPass> render_pass = RenderPass::Create(); 3728 std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
3596 AppendQuadsData data; 3729 AppendQuadsData data;
3597 active_layer()->WillDraw(DRAW_MODE_HARDWARE, nullptr); 3730 active_layer_->WillDraw(DRAW_MODE_HARDWARE, nullptr);
3598 active_layer()->AppendQuads(render_pass.get(), &data); 3731 active_layer_->AppendQuads(render_pass.get(), &data);
3599 active_layer()->DidDraw(nullptr); 3732 active_layer_->DidDraw(nullptr);
3600 3733
3601 // Even when OOM, quads should be produced, and should be different material 3734 // Even when OOM, quads should be produced, and should be different material
3602 // from quads with resource. 3735 // from quads with resource.
3603 EXPECT_LT(max_tiles, render_pass->quad_list.size()); 3736 EXPECT_LT(max_tiles, render_pass->quad_list.size());
3604 EXPECT_EQ(DrawQuad::Material::TILED_CONTENT, 3737 EXPECT_EQ(DrawQuad::Material::TILED_CONTENT,
3605 render_pass->quad_list.front()->material); 3738 render_pass->quad_list.front()->material);
3606 EXPECT_EQ(DrawQuad::Material::SOLID_COLOR, 3739 EXPECT_EQ(DrawQuad::Material::SOLID_COLOR,
3607 render_pass->quad_list.back()->material); 3740 render_pass->quad_list.back()->material);
3608 } 3741 }
3609 3742
3743 class OcclusionTrackingSettings : public LowResTilingsSettings {
3744 public:
3745 OcclusionTrackingSettings() { use_occlusion_for_tile_prioritization = true; }
3746 };
3747
3610 class OcclusionTrackingPictureLayerImplTest : public PictureLayerImplTest { 3748 class OcclusionTrackingPictureLayerImplTest : public PictureLayerImplTest {
3611 public: 3749 public:
3612 LayerTreeSettings CreateSettings() override { 3750 OcclusionTrackingPictureLayerImplTest()
3613 LayerTreeSettings settings = PictureLayerImplTest::CreateSettings(); 3751 : PictureLayerImplTest(OcclusionTrackingSettings()) {}
3614 settings.use_occlusion_for_tile_prioritization = true;
3615 return settings;
3616 }
3617 3752
3618 void VerifyEvictionConsidersOcclusion(FakePictureLayerImpl* layer, 3753 void VerifyEvictionConsidersOcclusion(FakePictureLayerImpl* layer,
3619 WhichTree tree, 3754 WhichTree tree,
3620 size_t expected_occluded_tile_count, 3755 size_t expected_occluded_tile_count,
3621 int source_line) { 3756 int source_line) {
3622 size_t occluded_tile_count = 0u; 3757 size_t occluded_tile_count = 0u;
3623 PrioritizedTile last_tile; 3758 PrioritizedTile last_tile;
3624 3759
3625 std::unique_ptr<TilingSetEvictionQueue> queue( 3760 std::unique_ptr<TilingSetEvictionQueue> queue(
3626 new TilingSetEvictionQueue(layer->picture_layer_tiling_set())); 3761 new TilingSetEvictionQueue(layer->picture_layer_tiling_set()));
(...skipping 27 matching lines...) Expand all
3654 last_tile = prioritized_tile; 3789 last_tile = prioritized_tile;
3655 queue->Pop(); 3790 queue->Pop();
3656 } 3791 }
3657 EXPECT_EQ(expected_occluded_tile_count, occluded_tile_count) 3792 EXPECT_EQ(expected_occluded_tile_count, occluded_tile_count)
3658 << "line: " << source_line; 3793 << "line: " << source_line;
3659 } 3794 }
3660 }; 3795 };
3661 3796
3662 TEST_F(OcclusionTrackingPictureLayerImplTest, 3797 TEST_F(OcclusionTrackingPictureLayerImplTest,
3663 OccludedTilesSkippedDuringRasterization) { 3798 OccludedTilesSkippedDuringRasterization) {
3664 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); 3799 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
3665 3800
3666 gfx::Size tile_size(102, 102); 3801 gfx::Size tile_size(102, 102);
3667 gfx::Size layer_bounds(1000, 1000); 3802 gfx::Size layer_bounds(1000, 1000);
3668 gfx::Size viewport_size(500, 500); 3803 gfx::Size viewport_size(500, 500);
3669 gfx::PointF occluding_layer_position(310.f, 0.f); 3804 gfx::PointF occluding_layer_position(310.f, 0.f);
3670 3805
3671 host_impl()->SetViewportSize(viewport_size); 3806 host_impl_.SetViewportSize(viewport_size);
3672 3807
3673 scoped_refptr<FakeRasterSource> pending_raster_source = 3808 scoped_refptr<FakeRasterSource> pending_raster_source =
3674 FakeRasterSource::CreateFilled(layer_bounds); 3809 FakeRasterSource::CreateFilled(layer_bounds);
3675 SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size, Region()); 3810 SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size, Region());
3676 3811
3677 // No occlusion. 3812 // No occlusion.
3678 int unoccluded_tile_count = 0; 3813 int unoccluded_tile_count = 0;
3679 std::unique_ptr<TilingSetRasterQueueAll> queue(new TilingSetRasterQueueAll( 3814 std::unique_ptr<TilingSetRasterQueueAll> queue(new TilingSetRasterQueueAll(
3680 pending_layer()->picture_layer_tiling_set(), false)); 3815 pending_layer_->picture_layer_tiling_set(), false));
3681 while (!queue->IsEmpty()) { 3816 while (!queue->IsEmpty()) {
3682 PrioritizedTile prioritized_tile = queue->Top(); 3817 PrioritizedTile prioritized_tile = queue->Top();
3683 Tile* tile = prioritized_tile.tile(); 3818 Tile* tile = prioritized_tile.tile();
3684 3819
3685 // Occluded tiles should not be iterated over. 3820 // Occluded tiles should not be iterated over.
3686 EXPECT_FALSE(prioritized_tile.is_occluded()); 3821 EXPECT_FALSE(prioritized_tile.is_occluded());
3687 3822
3688 // Some tiles may not be visible (i.e. outside the viewport). The rest are 3823 // Some tiles may not be visible (i.e. outside the viewport). The rest are
3689 // visible and at least partially unoccluded, verified by the above expect. 3824 // visible and at least partially unoccluded, verified by the above expect.
3690 bool tile_is_visible = 3825 bool tile_is_visible =
3691 tile->content_rect().Intersects(pending_layer()->visible_layer_rect()); 3826 tile->content_rect().Intersects(pending_layer_->visible_layer_rect());
3692 if (tile_is_visible) 3827 if (tile_is_visible)
3693 unoccluded_tile_count++; 3828 unoccluded_tile_count++;
3694 queue->Pop(); 3829 queue->Pop();
3695 } 3830 }
3696 EXPECT_EQ(unoccluded_tile_count, 25); 3831 EXPECT_EQ(unoccluded_tile_count, 25);
3697 3832
3698 // Partial occlusion. 3833 // Partial occlusion.
3699 pending_layer()->AddChild(LayerImpl::Create(host_impl()->pending_tree(), 1)); 3834 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 1));
3700 LayerImpl* layer1 = pending_layer()->children()[0]; 3835 LayerImpl* layer1 = pending_layer_->children()[0];
3701 layer1->SetBounds(layer_bounds); 3836 layer1->SetBounds(layer_bounds);
3702 layer1->SetDrawsContent(true); 3837 layer1->SetDrawsContent(true);
3703 layer1->SetContentsOpaque(true); 3838 layer1->SetContentsOpaque(true);
3704 layer1->SetPosition(occluding_layer_position); 3839 layer1->SetPosition(occluding_layer_position);
3705 3840
3706 RebuildPropertyTreesOnPendingTree(); 3841 RebuildPropertyTreesOnPendingTree();
3707 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200)); 3842 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
3708 bool update_lcd_text = false; 3843 bool update_lcd_text = false;
3709 host_impl()->pending_tree()->UpdateDrawProperties(update_lcd_text); 3844 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
3710 3845
3711 unoccluded_tile_count = 0; 3846 unoccluded_tile_count = 0;
3712 queue.reset(new TilingSetRasterQueueAll( 3847 queue.reset(new TilingSetRasterQueueAll(
3713 pending_layer()->picture_layer_tiling_set(), false)); 3848 pending_layer_->picture_layer_tiling_set(), false));
3714 while (!queue->IsEmpty()) { 3849 while (!queue->IsEmpty()) {
3715 PrioritizedTile prioritized_tile = queue->Top(); 3850 PrioritizedTile prioritized_tile = queue->Top();
3716 Tile* tile = prioritized_tile.tile(); 3851 Tile* tile = prioritized_tile.tile();
3717 3852
3718 EXPECT_FALSE(prioritized_tile.is_occluded()); 3853 EXPECT_FALSE(prioritized_tile.is_occluded());
3719 3854
3720 bool tile_is_visible = 3855 bool tile_is_visible =
3721 tile->content_rect().Intersects(pending_layer()->visible_layer_rect()); 3856 tile->content_rect().Intersects(pending_layer_->visible_layer_rect());
3722 if (tile_is_visible) 3857 if (tile_is_visible)
3723 unoccluded_tile_count++; 3858 unoccluded_tile_count++;
3724 queue->Pop(); 3859 queue->Pop();
3725 } 3860 }
3726 EXPECT_EQ(20, unoccluded_tile_count); 3861 EXPECT_EQ(20, unoccluded_tile_count);
3727 3862
3728 // Full occlusion. 3863 // Full occlusion.
3729 layer1->SetPosition(gfx::PointF()); 3864 layer1->SetPosition(gfx::PointF());
3730 layer1->NoteLayerPropertyChanged(); 3865 layer1->NoteLayerPropertyChanged();
3731 3866
3732 RebuildPropertyTreesOnPendingTree(); 3867 RebuildPropertyTreesOnPendingTree();
3733 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200)); 3868 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
3734 host_impl()->pending_tree()->UpdateDrawProperties(update_lcd_text); 3869 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
3735 3870
3736 unoccluded_tile_count = 0; 3871 unoccluded_tile_count = 0;
3737 queue.reset(new TilingSetRasterQueueAll( 3872 queue.reset(new TilingSetRasterQueueAll(
3738 pending_layer()->picture_layer_tiling_set(), false)); 3873 pending_layer_->picture_layer_tiling_set(), false));
3739 while (!queue->IsEmpty()) { 3874 while (!queue->IsEmpty()) {
3740 PrioritizedTile prioritized_tile = queue->Top(); 3875 PrioritizedTile prioritized_tile = queue->Top();
3741 Tile* tile = prioritized_tile.tile(); 3876 Tile* tile = prioritized_tile.tile();
3742 3877
3743 EXPECT_FALSE(prioritized_tile.is_occluded()); 3878 EXPECT_FALSE(prioritized_tile.is_occluded());
3744 3879
3745 bool tile_is_visible = 3880 bool tile_is_visible =
3746 tile->content_rect().Intersects(pending_layer()->visible_layer_rect()); 3881 tile->content_rect().Intersects(pending_layer_->visible_layer_rect());
3747 if (tile_is_visible) 3882 if (tile_is_visible)
3748 unoccluded_tile_count++; 3883 unoccluded_tile_count++;
3749 queue->Pop(); 3884 queue->Pop();
3750 } 3885 }
3751 EXPECT_EQ(unoccluded_tile_count, 0); 3886 EXPECT_EQ(unoccluded_tile_count, 0);
3752 } 3887 }
3753 3888
3754 TEST_F(OcclusionTrackingPictureLayerImplTest, 3889 TEST_F(OcclusionTrackingPictureLayerImplTest,
3755 OccludedTilesNotMarkedAsRequired) { 3890 OccludedTilesNotMarkedAsRequired) {
3756 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); 3891 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
3757 3892
3758 gfx::Size tile_size(102, 102); 3893 gfx::Size tile_size(102, 102);
3759 gfx::Size layer_bounds(1000, 1000); 3894 gfx::Size layer_bounds(1000, 1000);
3760 gfx::Size viewport_size(500, 500); 3895 gfx::Size viewport_size(500, 500);
3761 gfx::PointF occluding_layer_position(310.f, 0.f); 3896 gfx::PointF occluding_layer_position(310.f, 0.f);
3762 3897
3763 host_impl()->SetViewportSize(viewport_size); 3898 host_impl_.SetViewportSize(viewport_size);
3764 3899
3765 scoped_refptr<FakeRasterSource> pending_raster_source = 3900 scoped_refptr<FakeRasterSource> pending_raster_source =
3766 FakeRasterSource::CreateFilled(layer_bounds); 3901 FakeRasterSource::CreateFilled(layer_bounds);
3767 SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size, Region()); 3902 SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size, Region());
3768 3903
3769 // No occlusion. 3904 // No occlusion.
3770 int occluded_tile_count = 0; 3905 int occluded_tile_count = 0;
3771 for (size_t i = 0; i < pending_layer()->num_tilings(); ++i) { 3906 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) {
3772 PictureLayerTiling* tiling = pending_layer()->tilings()->tiling_at(i); 3907 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i);
3773 auto prioritized_tiles = 3908 auto prioritized_tiles =
3774 tiling->UpdateAndGetAllPrioritizedTilesForTesting(); 3909 tiling->UpdateAndGetAllPrioritizedTilesForTesting();
3775 3910
3776 occluded_tile_count = 0; 3911 occluded_tile_count = 0;
3777 for (PictureLayerTiling::CoverageIterator iter(tiling, 1.f, 3912 for (PictureLayerTiling::CoverageIterator iter(tiling, 1.f,
3778 gfx::Rect(layer_bounds)); 3913 gfx::Rect(layer_bounds));
3779 iter; ++iter) { 3914 iter; ++iter) {
3780 if (!*iter) 3915 if (!*iter)
3781 continue; 3916 continue;
3782 const Tile* tile = *iter; 3917 const Tile* tile = *iter;
3783 3918
3784 // Fully occluded tiles are not required for activation. 3919 // Fully occluded tiles are not required for activation.
3785 if (prioritized_tiles[tile].is_occluded()) { 3920 if (prioritized_tiles[tile].is_occluded()) {
3786 EXPECT_FALSE(tile->required_for_activation()); 3921 EXPECT_FALSE(tile->required_for_activation());
3787 occluded_tile_count++; 3922 occluded_tile_count++;
3788 } 3923 }
3789 } 3924 }
3790 EXPECT_EQ(occluded_tile_count, 0); 3925 EXPECT_EQ(occluded_tile_count, 0);
3791 } 3926 }
3792 3927
3793 // Partial occlusion. 3928 // Partial occlusion.
3794 pending_layer()->AddChild(LayerImpl::Create(host_impl()->pending_tree(), 1)); 3929 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 1));
3795 LayerImpl* layer1 = pending_layer()->children()[0]; 3930 LayerImpl* layer1 = pending_layer_->children()[0];
3796 layer1->SetBounds(layer_bounds); 3931 layer1->SetBounds(layer_bounds);
3797 layer1->SetDrawsContent(true); 3932 layer1->SetDrawsContent(true);
3798 layer1->SetContentsOpaque(true); 3933 layer1->SetContentsOpaque(true);
3799 layer1->SetPosition(occluding_layer_position); 3934 layer1->SetPosition(occluding_layer_position);
3800 3935
3801 RebuildPropertyTreesOnPendingTree(); 3936 RebuildPropertyTreesOnPendingTree();
3802 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200)); 3937 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
3803 bool update_lcd_text = false; 3938 bool update_lcd_text = false;
3804 host_impl()->pending_tree()->UpdateDrawProperties(update_lcd_text); 3939 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
3805 3940
3806 for (size_t i = 0; i < pending_layer()->num_tilings(); ++i) { 3941 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) {
3807 PictureLayerTiling* tiling = pending_layer()->tilings()->tiling_at(i); 3942 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i);
3808 auto prioritized_tiles = 3943 auto prioritized_tiles =
3809 tiling->UpdateAndGetAllPrioritizedTilesForTesting(); 3944 tiling->UpdateAndGetAllPrioritizedTilesForTesting();
3810 3945
3811 occluded_tile_count = 0; 3946 occluded_tile_count = 0;
3812 for (PictureLayerTiling::CoverageIterator iter(tiling, 1.f, 3947 for (PictureLayerTiling::CoverageIterator iter(tiling, 1.f,
3813 gfx::Rect(layer_bounds)); 3948 gfx::Rect(layer_bounds));
3814 iter; ++iter) { 3949 iter; ++iter) {
3815 if (!*iter) 3950 if (!*iter)
3816 continue; 3951 continue;
3817 const Tile* tile = *iter; 3952 const Tile* tile = *iter;
(...skipping 13 matching lines...) Expand all
3831 default: 3966 default:
3832 NOTREACHED(); 3967 NOTREACHED();
3833 } 3968 }
3834 } 3969 }
3835 3970
3836 // Full occlusion. 3971 // Full occlusion.
3837 layer1->SetPosition(gfx::PointF()); 3972 layer1->SetPosition(gfx::PointF());
3838 layer1->NoteLayerPropertyChanged(); 3973 layer1->NoteLayerPropertyChanged();
3839 3974
3840 RebuildPropertyTreesOnPendingTree(); 3975 RebuildPropertyTreesOnPendingTree();
3841 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200)); 3976 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
3842 host_impl()->pending_tree()->UpdateDrawProperties(update_lcd_text); 3977 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
3843 3978
3844 for (size_t i = 0; i < pending_layer()->num_tilings(); ++i) { 3979 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) {
3845 PictureLayerTiling* tiling = pending_layer()->tilings()->tiling_at(i); 3980 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i);
3846 auto prioritized_tiles = 3981 auto prioritized_tiles =
3847 tiling->UpdateAndGetAllPrioritizedTilesForTesting(); 3982 tiling->UpdateAndGetAllPrioritizedTilesForTesting();
3848 3983
3849 occluded_tile_count = 0; 3984 occluded_tile_count = 0;
3850 for (PictureLayerTiling::CoverageIterator iter(tiling, 1.f, 3985 for (PictureLayerTiling::CoverageIterator iter(tiling, 1.f,
3851 gfx::Rect(layer_bounds)); 3986 gfx::Rect(layer_bounds));
3852 iter; ++iter) { 3987 iter; ++iter) {
3853 if (!*iter) 3988 if (!*iter)
3854 continue; 3989 continue;
3855 const Tile* tile = *iter; 3990 const Tile* tile = *iter;
(...skipping 10 matching lines...) Expand all
3866 case 1: 4001 case 1:
3867 EXPECT_EQ(4, occluded_tile_count); 4002 EXPECT_EQ(4, occluded_tile_count);
3868 break; 4003 break;
3869 default: 4004 default:
3870 NOTREACHED(); 4005 NOTREACHED();
3871 } 4006 }
3872 } 4007 }
3873 } 4008 }
3874 4009
3875 TEST_F(OcclusionTrackingPictureLayerImplTest, OcclusionForDifferentScales) { 4010 TEST_F(OcclusionTrackingPictureLayerImplTest, OcclusionForDifferentScales) {
3876 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); 4011 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
3877 4012
3878 gfx::Size tile_size(102, 102); 4013 gfx::Size tile_size(102, 102);
3879 gfx::Size layer_bounds(1000, 1000); 4014 gfx::Size layer_bounds(1000, 1000);
3880 gfx::Size viewport_size(500, 500); 4015 gfx::Size viewport_size(500, 500);
3881 gfx::PointF occluding_layer_position(310.f, 0.f); 4016 gfx::PointF occluding_layer_position(310.f, 0.f);
3882 4017
3883 scoped_refptr<FakeRasterSource> pending_raster_source = 4018 scoped_refptr<FakeRasterSource> pending_raster_source =
3884 FakeRasterSource::CreateFilled(layer_bounds); 4019 FakeRasterSource::CreateFilled(layer_bounds);
3885 4020
3886 host_impl()->SetViewportSize(viewport_size); 4021 host_impl_.SetViewportSize(viewport_size);
3887 4022
3888 SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size, Region()); 4023 SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size, Region());
3889 ASSERT_TRUE(pending_layer()->CanHaveTilings()); 4024 ASSERT_TRUE(pending_layer_->CanHaveTilings());
3890 4025
3891 pending_layer()->AddChild(LayerImpl::Create(host_impl()->pending_tree(), 1)); 4026 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 1));
3892 LayerImpl* layer1 = pending_layer()->children()[0]; 4027 LayerImpl* layer1 = pending_layer_->children()[0];
3893 layer1->SetBounds(layer_bounds); 4028 layer1->SetBounds(layer_bounds);
3894 layer1->SetDrawsContent(true); 4029 layer1->SetDrawsContent(true);
3895 layer1->SetContentsOpaque(true); 4030 layer1->SetContentsOpaque(true);
3896 layer1->SetPosition(occluding_layer_position); 4031 layer1->SetPosition(occluding_layer_position);
3897 4032
3898 pending_layer()->tilings()->RemoveAllTilings(); 4033 pending_layer_->tilings()->RemoveAllTilings();
3899 float low_res_factor = host_impl()->settings().low_res_contents_scale_factor; 4034 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
3900 pending_layer()->AddTiling(low_res_factor)->set_resolution(LOW_RESOLUTION); 4035 pending_layer_->AddTiling(low_res_factor)->set_resolution(LOW_RESOLUTION);
3901 pending_layer()->AddTiling(0.3f)->set_resolution(HIGH_RESOLUTION); 4036 pending_layer_->AddTiling(0.3f)->set_resolution(HIGH_RESOLUTION);
3902 pending_layer()->AddTiling(0.7f)->set_resolution(HIGH_RESOLUTION); 4037 pending_layer_->AddTiling(0.7f)->set_resolution(HIGH_RESOLUTION);
3903 pending_layer()->AddTiling(1.0f)->set_resolution(HIGH_RESOLUTION); 4038 pending_layer_->AddTiling(1.0f)->set_resolution(HIGH_RESOLUTION);
3904 pending_layer()->AddTiling(2.0f)->set_resolution(HIGH_RESOLUTION); 4039 pending_layer_->AddTiling(2.0f)->set_resolution(HIGH_RESOLUTION);
3905 4040
3906 RebuildPropertyTreesOnPendingTree(); 4041 RebuildPropertyTreesOnPendingTree();
3907 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); 4042 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
3908 // UpdateDrawProperties with the occluding layer. 4043 // UpdateDrawProperties with the occluding layer.
3909 bool update_lcd_text = false; 4044 bool update_lcd_text = false;
3910 host_impl()->pending_tree()->UpdateDrawProperties(update_lcd_text); 4045 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
3911 4046
3912 EXPECT_EQ(5u, pending_layer()->num_tilings()); 4047 EXPECT_EQ(5u, pending_layer_->num_tilings());
3913 4048
3914 int occluded_tile_count = 0; 4049 int occluded_tile_count = 0;
3915 for (size_t i = 0; i < pending_layer()->num_tilings(); ++i) { 4050 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) {
3916 PictureLayerTiling* tiling = pending_layer()->tilings()->tiling_at(i); 4051 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i);
3917 auto prioritized_tiles = 4052 auto prioritized_tiles =
3918 tiling->UpdateAndGetAllPrioritizedTilesForTesting(); 4053 tiling->UpdateAndGetAllPrioritizedTilesForTesting();
3919 std::vector<Tile*> tiles = tiling->AllTilesForTesting(); 4054 std::vector<Tile*> tiles = tiling->AllTilesForTesting();
3920 4055
3921 occluded_tile_count = 0; 4056 occluded_tile_count = 0;
3922 for (size_t j = 0; j < tiles.size(); ++j) { 4057 for (size_t j = 0; j < tiles.size(); ++j) {
3923 if (prioritized_tiles[tiles[j]].is_occluded()) { 4058 if (prioritized_tiles[tiles[j]].is_occluded()) {
3924 gfx::Rect scaled_content_rect = ScaleToEnclosingRect( 4059 gfx::Rect scaled_content_rect = ScaleToEnclosingRect(
3925 tiles[j]->content_rect(), 1.0f / tiles[j]->contents_scale()); 4060 tiles[j]->content_rect(), 1.0f / tiles[j]->contents_scale());
3926 EXPECT_GE(scaled_content_rect.x(), occluding_layer_position.x()); 4061 EXPECT_GE(scaled_content_rect.x(), occluding_layer_position.x());
(...skipping 25 matching lines...) Expand all
3952 gfx::Size layer_bounds(1000, 1000); 4087 gfx::Size layer_bounds(1000, 1000);
3953 gfx::Size viewport_size(1000, 1000); 4088 gfx::Size viewport_size(1000, 1000);
3954 gfx::PointF occluding_layer_position(310.f, 0.f); 4089 gfx::PointF occluding_layer_position(310.f, 0.f);
3955 gfx::Rect invalidation_rect(230, 230, 102, 102); 4090 gfx::Rect invalidation_rect(230, 230, 102, 102);
3956 4091
3957 scoped_refptr<FakeRasterSource> pending_raster_source = 4092 scoped_refptr<FakeRasterSource> pending_raster_source =
3958 FakeRasterSource::CreateFilled(layer_bounds); 4093 FakeRasterSource::CreateFilled(layer_bounds);
3959 scoped_refptr<FakeRasterSource> active_raster_source = 4094 scoped_refptr<FakeRasterSource> active_raster_source =
3960 FakeRasterSource::CreateFilled(layer_bounds); 4095 FakeRasterSource::CreateFilled(layer_bounds);
3961 4096
3962 host_impl()->SetViewportSize(viewport_size); 4097 host_impl_.SetViewportSize(viewport_size);
3963 SetupPendingTree(active_raster_source); 4098 SetupPendingTree(active_raster_source);
3964 4099
3965 // Partially occlude the active layer. 4100 // Partially occlude the active layer.
3966 pending_layer()->AddChild(LayerImpl::Create(host_impl()->pending_tree(), 2)); 4101 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 2));
3967 LayerImpl* layer1 = pending_layer()->children()[0]; 4102 LayerImpl* layer1 = pending_layer_->children()[0];
3968 layer1->SetBounds(layer_bounds); 4103 layer1->SetBounds(layer_bounds);
3969 layer1->SetDrawsContent(true); 4104 layer1->SetDrawsContent(true);
3970 layer1->SetContentsOpaque(true); 4105 layer1->SetContentsOpaque(true);
3971 layer1->SetPosition(occluding_layer_position); 4106 layer1->SetPosition(occluding_layer_position);
3972 4107
3973 ActivateTree(); 4108 ActivateTree();
3974 4109
3975 for (size_t i = 0; i < active_layer()->num_tilings(); ++i) { 4110 for (size_t i = 0; i < active_layer_->num_tilings(); ++i) {
3976 PictureLayerTiling* tiling = active_layer()->tilings()->tiling_at(i); 4111 PictureLayerTiling* tiling = active_layer_->tilings()->tiling_at(i);
3977 auto prioritized_tiles = 4112 auto prioritized_tiles =
3978 tiling->UpdateAndGetAllPrioritizedTilesForTesting(); 4113 tiling->UpdateAndGetAllPrioritizedTilesForTesting();
3979 4114
3980 for (PictureLayerTiling::CoverageIterator iter(tiling, 1.f, 4115 for (PictureLayerTiling::CoverageIterator iter(tiling, 1.f,
3981 gfx::Rect(layer_bounds)); 4116 gfx::Rect(layer_bounds));
3982 iter; ++iter) { 4117 iter; ++iter) {
3983 if (!*iter) 4118 if (!*iter)
3984 continue; 4119 continue;
3985 const Tile* tile = *iter; 4120 const Tile* tile = *iter;
3986 4121
3987 gfx::Rect scaled_content_rect = ScaleToEnclosingRect( 4122 gfx::Rect scaled_content_rect = ScaleToEnclosingRect(
3988 tile->content_rect(), 1.0f / tile->contents_scale()); 4123 tile->content_rect(), 1.0f / tile->contents_scale());
3989 // Tiles are occluded on the active tree iff they lie beneath the 4124 // Tiles are occluded on the active tree iff they lie beneath the
3990 // occluding layer. 4125 // occluding layer.
3991 EXPECT_EQ(prioritized_tiles[tile].is_occluded(), 4126 EXPECT_EQ(prioritized_tiles[tile].is_occluded(),
3992 scaled_content_rect.x() >= occluding_layer_position.x()); 4127 scaled_content_rect.x() >= occluding_layer_position.x());
3993 } 4128 }
3994 } 4129 }
3995 4130
3996 // Partially invalidate the pending layer. 4131 // Partially invalidate the pending layer.
3997 SetupPendingTreeWithInvalidation(pending_raster_source, invalidation_rect); 4132 SetupPendingTreeWithInvalidation(pending_raster_source, invalidation_rect);
3998 4133
3999 for (size_t i = 0; i < active_layer()->num_tilings(); ++i) { 4134 for (size_t i = 0; i < active_layer_->num_tilings(); ++i) {
4000 PictureLayerTiling* tiling = active_layer()->tilings()->tiling_at(i); 4135 PictureLayerTiling* tiling = active_layer_->tilings()->tiling_at(i);
4001 auto prioritized_tiles = 4136 auto prioritized_tiles =
4002 tiling->UpdateAndGetAllPrioritizedTilesForTesting(); 4137 tiling->UpdateAndGetAllPrioritizedTilesForTesting();
4003 4138
4004 for (PictureLayerTiling::CoverageIterator iter(tiling, 1.f, 4139 for (PictureLayerTiling::CoverageIterator iter(tiling, 1.f,
4005 gfx::Rect(layer_bounds)); 4140 gfx::Rect(layer_bounds));
4006 iter; ++iter) { 4141 iter; ++iter) {
4007 if (!*iter) 4142 if (!*iter)
4008 continue; 4143 continue;
4009 const Tile* tile = *iter; 4144 const Tile* tile = *iter;
4010 EXPECT_TRUE(tile); 4145 EXPECT_TRUE(tile);
4011 4146
4012 // All tiles are unoccluded, because the pending tree has no occlusion. 4147 // All tiles are unoccluded, because the pending tree has no occlusion.
4013 EXPECT_FALSE(prioritized_tiles[tile].is_occluded()); 4148 EXPECT_FALSE(prioritized_tiles[tile].is_occluded());
4014 4149
4015 if (tiling->resolution() == LOW_RESOLUTION) { 4150 if (tiling->resolution() == LOW_RESOLUTION) {
4016 EXPECT_FALSE(active_layer()->GetPendingOrActiveTwinTiling(tiling)); 4151 EXPECT_FALSE(active_layer_->GetPendingOrActiveTwinTiling(tiling));
4017 continue; 4152 continue;
4018 } 4153 }
4019 4154
4020 Tile* twin_tile = 4155 Tile* twin_tile = active_layer_->GetPendingOrActiveTwinTiling(tiling)
4021 active_layer()->GetPendingOrActiveTwinTiling(tiling)->TileAt( 4156 ->TileAt(iter.i(), iter.j());
4022 iter.i(), iter.j());
4023 gfx::Rect scaled_content_rect = ScaleToEnclosingRect( 4157 gfx::Rect scaled_content_rect = ScaleToEnclosingRect(
4024 tile->content_rect(), 1.0f / tile->contents_scale()); 4158 tile->content_rect(), 1.0f / tile->contents_scale());
4025 4159
4026 if (scaled_content_rect.Intersects(invalidation_rect)) { 4160 if (scaled_content_rect.Intersects(invalidation_rect)) {
4027 // Tiles inside the invalidation rect exist on both trees. 4161 // Tiles inside the invalidation rect exist on both trees.
4028 EXPECT_TRUE(twin_tile); 4162 EXPECT_TRUE(twin_tile);
4029 EXPECT_NE(tile, twin_tile); 4163 EXPECT_NE(tile, twin_tile);
4030 } else { 4164 } else {
4031 // Tiles outside the invalidation rect only exist on the active tree. 4165 // Tiles outside the invalidation rect only exist on the active tree.
4032 EXPECT_FALSE(twin_tile); 4166 EXPECT_FALSE(twin_tile);
4033 } 4167 }
4034 } 4168 }
4035 } 4169 }
4036 } 4170 }
4037 4171
4038 TEST_F(OcclusionTrackingPictureLayerImplTest, 4172 TEST_F(OcclusionTrackingPictureLayerImplTest,
4039 OccludedTilesConsideredDuringEviction) { 4173 OccludedTilesConsideredDuringEviction) {
4040 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); 4174 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
4041 4175
4042 gfx::Size tile_size(102, 102); 4176 gfx::Size tile_size(102, 102);
4043 gfx::Size layer_bounds(1000, 1000); 4177 gfx::Size layer_bounds(1000, 1000);
4044 gfx::Size viewport_size(1000, 1000); 4178 gfx::Size viewport_size(1000, 1000);
4045 gfx::PointF pending_occluding_layer_position(310.f, 0.f); 4179 gfx::PointF pending_occluding_layer_position(310.f, 0.f);
4046 gfx::PointF active_occluding_layer_position(0.f, 310.f); 4180 gfx::PointF active_occluding_layer_position(0.f, 310.f);
4047 gfx::Rect invalidation_rect(230, 230, 152, 152); 4181 gfx::Rect invalidation_rect(230, 230, 152, 152);
4048 4182
4049 host_impl()->SetViewportSize(viewport_size); 4183 host_impl_.SetViewportSize(viewport_size);
4050 SetInitialDeviceScaleFactor(2.f); 4184 SetInitialDeviceScaleFactor(2.f);
4051 4185
4052 scoped_refptr<FakeRasterSource> pending_raster_source = 4186 scoped_refptr<FakeRasterSource> pending_raster_source =
4053 FakeRasterSource::CreateFilled(layer_bounds); 4187 FakeRasterSource::CreateFilled(layer_bounds);
4054 scoped_refptr<FakeRasterSource> active_raster_source = 4188 scoped_refptr<FakeRasterSource> active_raster_source =
4055 FakeRasterSource::CreateFilled(layer_bounds); 4189 FakeRasterSource::CreateFilled(layer_bounds);
4056 4190
4057 SetupPendingTreeWithFixedTileSize(active_raster_source, tile_size, Region()); 4191 SetupPendingTreeWithFixedTileSize(active_raster_source, tile_size, Region());
4058 4192
4059 // Partially occlude the active layer. 4193 // Partially occlude the active layer.
4060 pending_layer()->AddChild(LayerImpl::Create(host_impl()->pending_tree(), 2)); 4194 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 2));
4061 LayerImpl* active_occluding_layer = pending_layer()->children()[0]; 4195 LayerImpl* active_occluding_layer = pending_layer_->children()[0];
4062 active_occluding_layer->SetBounds(layer_bounds); 4196 active_occluding_layer->SetBounds(layer_bounds);
4063 active_occluding_layer->SetDrawsContent(true); 4197 active_occluding_layer->SetDrawsContent(true);
4064 active_occluding_layer->SetContentsOpaque(true); 4198 active_occluding_layer->SetContentsOpaque(true);
4065 active_occluding_layer->SetPosition(active_occluding_layer_position); 4199 active_occluding_layer->SetPosition(active_occluding_layer_position);
4066 4200
4067 ActivateTree(); 4201 ActivateTree();
4068 4202
4069 // Partially invalidate the pending layer. Tiles inside the invalidation rect 4203 // Partially invalidate the pending layer. Tiles inside the invalidation rect
4070 // are created. 4204 // are created.
4071 SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size, 4205 SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size,
4072 invalidation_rect); 4206 invalidation_rect);
4073 4207
4074 // Partially occlude the pending layer in a different way. 4208 // Partially occlude the pending layer in a different way.
4075 pending_layer()->AddChild(LayerImpl::Create(host_impl()->pending_tree(), 3)); 4209 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 3));
4076 LayerImpl* pending_occluding_layer = pending_layer()->children()[0]; 4210 LayerImpl* pending_occluding_layer = pending_layer_->children()[0];
4077 pending_occluding_layer->SetBounds(layer_bounds); 4211 pending_occluding_layer->SetBounds(layer_bounds);
4078 pending_occluding_layer->SetDrawsContent(true); 4212 pending_occluding_layer->SetDrawsContent(true);
4079 pending_occluding_layer->SetContentsOpaque(true); 4213 pending_occluding_layer->SetContentsOpaque(true);
4080 pending_occluding_layer->SetPosition(pending_occluding_layer_position); 4214 pending_occluding_layer->SetPosition(pending_occluding_layer_position);
4081 4215
4082 EXPECT_EQ(1u, pending_layer()->num_tilings()); 4216 EXPECT_EQ(1u, pending_layer_->num_tilings());
4083 EXPECT_EQ(2u, active_layer()->num_tilings()); 4217 EXPECT_EQ(2u, active_layer_->num_tilings());
4084 4218
4085 RebuildPropertyTreesOnPendingTree(); 4219 RebuildPropertyTreesOnPendingTree();
4086 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); 4220 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
4087 // UpdateDrawProperties with the occluding layer. 4221 // UpdateDrawProperties with the occluding layer.
4088 bool update_lcd_text = false; 4222 bool update_lcd_text = false;
4089 host_impl()->pending_tree()->UpdateDrawProperties(update_lcd_text); 4223 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
4090 4224
4091 // The expected number of occluded tiles on each of the 2 tilings for each of 4225 // The expected number of occluded tiles on each of the 2 tilings for each of
4092 // the 3 tree priorities. 4226 // the 3 tree priorities.
4093 size_t expected_occluded_tile_count_on_pending[] = {4u, 0u}; 4227 size_t expected_occluded_tile_count_on_pending[] = {4u, 0u};
4094 size_t expected_occluded_tile_count_on_active[] = {12u, 3u}; 4228 size_t expected_occluded_tile_count_on_active[] = {12u, 3u};
4095 size_t total_expected_occluded_tile_count_on_trees[] = {15u, 4u}; 4229 size_t total_expected_occluded_tile_count_on_trees[] = {15u, 4u};
4096 4230
4097 // Verify number of occluded tiles on the pending layer for each tiling. 4231 // Verify number of occluded tiles on the pending layer for each tiling.
4098 for (size_t i = 0; i < pending_layer()->num_tilings(); ++i) { 4232 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) {
4099 PictureLayerTiling* tiling = pending_layer()->tilings()->tiling_at(i); 4233 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i);
4100 auto prioritized_tiles = 4234 auto prioritized_tiles =
4101 tiling->UpdateAndGetAllPrioritizedTilesForTesting(); 4235 tiling->UpdateAndGetAllPrioritizedTilesForTesting();
4102 4236
4103 size_t occluded_tile_count_on_pending = 0u; 4237 size_t occluded_tile_count_on_pending = 0u;
4104 for (PictureLayerTiling::CoverageIterator iter(tiling, 1.f, 4238 for (PictureLayerTiling::CoverageIterator iter(tiling, 1.f,
4105 gfx::Rect(layer_bounds)); 4239 gfx::Rect(layer_bounds));
4106 iter; ++iter) { 4240 iter; ++iter) {
4107 Tile* tile = *iter; 4241 Tile* tile = *iter;
4108 4242
4109 if (invalidation_rect.Intersects(iter.geometry_rect())) 4243 if (invalidation_rect.Intersects(iter.geometry_rect()))
4110 EXPECT_TRUE(tile); 4244 EXPECT_TRUE(tile);
4111 else 4245 else
4112 EXPECT_FALSE(tile); 4246 EXPECT_FALSE(tile);
4113 4247
4114 if (!tile) 4248 if (!tile)
4115 continue; 4249 continue;
4116 if (prioritized_tiles[tile].is_occluded()) 4250 if (prioritized_tiles[tile].is_occluded())
4117 occluded_tile_count_on_pending++; 4251 occluded_tile_count_on_pending++;
4118 } 4252 }
4119 EXPECT_EQ(expected_occluded_tile_count_on_pending[i], 4253 EXPECT_EQ(expected_occluded_tile_count_on_pending[i],
4120 occluded_tile_count_on_pending) 4254 occluded_tile_count_on_pending)
4121 << tiling->contents_scale(); 4255 << tiling->contents_scale();
4122 } 4256 }
4123 4257
4124 // Verify number of occluded tiles on the active layer for each tiling. 4258 // Verify number of occluded tiles on the active layer for each tiling.
4125 for (size_t i = 0; i < active_layer()->num_tilings(); ++i) { 4259 for (size_t i = 0; i < active_layer_->num_tilings(); ++i) {
4126 PictureLayerTiling* tiling = active_layer()->tilings()->tiling_at(i); 4260 PictureLayerTiling* tiling = active_layer_->tilings()->tiling_at(i);
4127 auto prioritized_tiles = 4261 auto prioritized_tiles =
4128 tiling->UpdateAndGetAllPrioritizedTilesForTesting(); 4262 tiling->UpdateAndGetAllPrioritizedTilesForTesting();
4129 4263
4130 size_t occluded_tile_count_on_active = 0u; 4264 size_t occluded_tile_count_on_active = 0u;
4131 for (PictureLayerTiling::CoverageIterator iter(tiling, 1.f, 4265 for (PictureLayerTiling::CoverageIterator iter(tiling, 1.f,
4132 gfx::Rect(layer_bounds)); 4266 gfx::Rect(layer_bounds));
4133 iter; ++iter) { 4267 iter; ++iter) {
4134 Tile* tile = *iter; 4268 Tile* tile = *iter;
4135 4269
4136 if (!tile) 4270 if (!tile)
4137 continue; 4271 continue;
4138 if (prioritized_tiles[tile].is_occluded()) 4272 if (prioritized_tiles[tile].is_occluded())
4139 occluded_tile_count_on_active++; 4273 occluded_tile_count_on_active++;
4140 } 4274 }
4141 EXPECT_EQ(expected_occluded_tile_count_on_active[i], 4275 EXPECT_EQ(expected_occluded_tile_count_on_active[i],
4142 occluded_tile_count_on_active) 4276 occluded_tile_count_on_active)
4143 << i; 4277 << i;
4144 } 4278 }
4145 4279
4146 std::vector<Tile*> all_tiles; 4280 std::vector<Tile*> all_tiles;
4147 for (size_t i = 0; i < pending_layer()->num_tilings(); ++i) { 4281 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) {
4148 PictureLayerTiling* tiling = pending_layer()->tilings()->tiling_at(i); 4282 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i);
4149 std::vector<Tile*> tiles = tiling->AllTilesForTesting(); 4283 std::vector<Tile*> tiles = tiling->AllTilesForTesting();
4150 all_tiles.insert(all_tiles.end(), tiles.begin(), tiles.end()); 4284 all_tiles.insert(all_tiles.end(), tiles.begin(), tiles.end());
4151 } 4285 }
4152 for (size_t i = 0; i < active_layer()->num_tilings(); ++i) { 4286 for (size_t i = 0; i < active_layer_->num_tilings(); ++i) {
4153 PictureLayerTiling* tiling = active_layer()->tilings()->tiling_at(i); 4287 PictureLayerTiling* tiling = active_layer_->tilings()->tiling_at(i);
4154 std::vector<Tile*> tiles = tiling->AllTilesForTesting(); 4288 std::vector<Tile*> tiles = tiling->AllTilesForTesting();
4155 all_tiles.insert(all_tiles.end(), tiles.begin(), tiles.end()); 4289 all_tiles.insert(all_tiles.end(), tiles.begin(), tiles.end());
4156 } 4290 }
4157 4291
4158 host_impl()->tile_manager()->InitializeTilesWithResourcesForTesting( 4292 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles);
4159 all_tiles);
4160 4293
4161 VerifyEvictionConsidersOcclusion( 4294 VerifyEvictionConsidersOcclusion(
4162 pending_layer(), PENDING_TREE, 4295 pending_layer_, PENDING_TREE,
4163 total_expected_occluded_tile_count_on_trees[PENDING_TREE], __LINE__); 4296 total_expected_occluded_tile_count_on_trees[PENDING_TREE], __LINE__);
4164 VerifyEvictionConsidersOcclusion( 4297 VerifyEvictionConsidersOcclusion(
4165 active_layer(), ACTIVE_TREE, 4298 active_layer_, ACTIVE_TREE,
4166 total_expected_occluded_tile_count_on_trees[ACTIVE_TREE], __LINE__); 4299 total_expected_occluded_tile_count_on_trees[ACTIVE_TREE], __LINE__);
4167 4300
4168 // Repeat the tests without valid active tree priorities. 4301 // Repeat the tests without valid active tree priorities.
4169 active_layer()->set_has_valid_tile_priorities(false); 4302 active_layer_->set_has_valid_tile_priorities(false);
4170 VerifyEvictionConsidersOcclusion( 4303 VerifyEvictionConsidersOcclusion(
4171 pending_layer(), PENDING_TREE, 4304 pending_layer_, PENDING_TREE,
4172 total_expected_occluded_tile_count_on_trees[PENDING_TREE], __LINE__); 4305 total_expected_occluded_tile_count_on_trees[PENDING_TREE], __LINE__);
4173 VerifyEvictionConsidersOcclusion( 4306 VerifyEvictionConsidersOcclusion(
4174 active_layer(), ACTIVE_TREE, 4307 active_layer_, ACTIVE_TREE,
4175 total_expected_occluded_tile_count_on_trees[ACTIVE_TREE], __LINE__); 4308 total_expected_occluded_tile_count_on_trees[ACTIVE_TREE], __LINE__);
4176 active_layer()->set_has_valid_tile_priorities(true); 4309 active_layer_->set_has_valid_tile_priorities(true);
4177 4310
4178 // Repeat the tests without valid pending tree priorities. 4311 // Repeat the tests without valid pending tree priorities.
4179 pending_layer()->set_has_valid_tile_priorities(false); 4312 pending_layer_->set_has_valid_tile_priorities(false);
4180 VerifyEvictionConsidersOcclusion( 4313 VerifyEvictionConsidersOcclusion(
4181 active_layer(), ACTIVE_TREE, 4314 active_layer_, ACTIVE_TREE,
4182 total_expected_occluded_tile_count_on_trees[ACTIVE_TREE], __LINE__); 4315 total_expected_occluded_tile_count_on_trees[ACTIVE_TREE], __LINE__);
4183 VerifyEvictionConsidersOcclusion( 4316 VerifyEvictionConsidersOcclusion(
4184 pending_layer(), PENDING_TREE, 4317 pending_layer_, PENDING_TREE,
4185 total_expected_occluded_tile_count_on_trees[PENDING_TREE], __LINE__); 4318 total_expected_occluded_tile_count_on_trees[PENDING_TREE], __LINE__);
4186 pending_layer()->set_has_valid_tile_priorities(true); 4319 pending_layer_->set_has_valid_tile_priorities(true);
4187 } 4320 }
4188 4321
4189 TEST_F(PictureLayerImplTest, PendingOrActiveTwinLayer) { 4322 TEST_F(PictureLayerImplTest, PendingOrActiveTwinLayer) {
4190 gfx::Size layer_bounds(1000, 1000); 4323 gfx::Size layer_bounds(1000, 1000);
4191 4324
4192 scoped_refptr<FakeRasterSource> raster_source = 4325 scoped_refptr<FakeRasterSource> raster_source =
4193 FakeRasterSource::CreateFilled(layer_bounds); 4326 FakeRasterSource::CreateFilled(layer_bounds);
4194 SetupPendingTree(raster_source); 4327 SetupPendingTree(raster_source);
4195 EXPECT_FALSE(pending_layer()->GetPendingOrActiveTwinLayer()); 4328 EXPECT_FALSE(pending_layer_->GetPendingOrActiveTwinLayer());
4196 4329
4197 ActivateTree(); 4330 ActivateTree();
4198 EXPECT_FALSE(active_layer()->GetPendingOrActiveTwinLayer()); 4331 EXPECT_FALSE(active_layer_->GetPendingOrActiveTwinLayer());
4199 4332
4200 SetupPendingTree(raster_source); 4333 SetupPendingTree(raster_source);
4201 EXPECT_TRUE(pending_layer()->GetPendingOrActiveTwinLayer()); 4334 EXPECT_TRUE(pending_layer_->GetPendingOrActiveTwinLayer());
4202 EXPECT_TRUE(active_layer()->GetPendingOrActiveTwinLayer()); 4335 EXPECT_TRUE(active_layer_->GetPendingOrActiveTwinLayer());
4203 EXPECT_EQ(pending_layer(), active_layer()->GetPendingOrActiveTwinLayer()); 4336 EXPECT_EQ(pending_layer_, active_layer_->GetPendingOrActiveTwinLayer());
4204 EXPECT_EQ(active_layer(), pending_layer()->GetPendingOrActiveTwinLayer()); 4337 EXPECT_EQ(active_layer_, pending_layer_->GetPendingOrActiveTwinLayer());
4205 4338
4206 ActivateTree(); 4339 ActivateTree();
4207 EXPECT_FALSE(active_layer()->GetPendingOrActiveTwinLayer()); 4340 EXPECT_FALSE(active_layer_->GetPendingOrActiveTwinLayer());
4208 4341
4209 // Make an empty pending tree. 4342 // Make an empty pending tree.
4210 host_impl()->CreatePendingTree(); 4343 host_impl_.CreatePendingTree();
4211 host_impl()->pending_tree()->ClearLayers(); 4344 host_impl_.pending_tree()->ClearLayers();
4212 EXPECT_FALSE(active_layer()->GetPendingOrActiveTwinLayer()); 4345 EXPECT_FALSE(active_layer_->GetPendingOrActiveTwinLayer());
4213 } 4346 }
4214 4347
4215 void PictureLayerImplTest::TestQuadsForSolidColor(bool test_for_solid) { 4348 void PictureLayerImplTest::TestQuadsForSolidColor(bool test_for_solid) {
4216 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); 4349 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
4217 4350
4218 gfx::Size tile_size(100, 100); 4351 gfx::Size tile_size(100, 100);
4219 gfx::Size layer_bounds(200, 200); 4352 gfx::Size layer_bounds(200, 200);
4220 gfx::Rect layer_rect(layer_bounds); 4353 gfx::Rect layer_rect(layer_bounds);
4221 4354
4222 FakeContentLayerClient client; 4355 FakeContentLayerClient client;
4223 client.set_bounds(layer_bounds); 4356 client.set_bounds(layer_bounds);
4224 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client); 4357 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client);
4225 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); 4358 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D);
4226 TestTaskGraphRunner task_graph_runner; 4359 TestTaskGraphRunner task_graph_runner;
(...skipping 11 matching lines...) Expand all
4238 &client, &invalidation, layer_bounds, frame_number++, 4371 &client, &invalidation, layer_bounds, frame_number++,
4239 RecordingSource::RECORD_NORMALLY); 4372 RecordingSource::RECORD_NORMALLY);
4240 4373
4241 scoped_refptr<RasterSource> pending_raster_source = 4374 scoped_refptr<RasterSource> pending_raster_source =
4242 recording_source->CreateRasterSource(true); 4375 recording_source->CreateRasterSource(true);
4243 4376
4244 SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size, Region()); 4377 SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size, Region());
4245 ActivateTree(); 4378 ActivateTree();
4246 4379
4247 if (test_for_solid) { 4380 if (test_for_solid) {
4248 EXPECT_EQ(0u, active_layer()->tilings()->num_tilings()); 4381 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
4249 } else { 4382 } else {
4250 ASSERT_TRUE(active_layer()->tilings()); 4383 ASSERT_TRUE(active_layer_->tilings());
4251 ASSERT_GT(active_layer()->tilings()->num_tilings(), 0u); 4384 ASSERT_GT(active_layer_->tilings()->num_tilings(), 0u);
4252 std::vector<Tile*> tiles = 4385 std::vector<Tile*> tiles =
4253 active_layer()->tilings()->tiling_at(0)->AllTilesForTesting(); 4386 active_layer_->tilings()->tiling_at(0)->AllTilesForTesting();
4254 EXPECT_FALSE(tiles.empty()); 4387 EXPECT_FALSE(tiles.empty());
4255 host_impl()->tile_manager()->InitializeTilesWithResourcesForTesting(tiles); 4388 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(tiles);
4256 } 4389 }
4257 4390
4258 std::unique_ptr<RenderPass> render_pass = RenderPass::Create(); 4391 std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
4259 AppendQuadsData data; 4392 AppendQuadsData data;
4260 active_layer()->WillDraw(DRAW_MODE_SOFTWARE, nullptr); 4393 active_layer_->WillDraw(DRAW_MODE_SOFTWARE, nullptr);
4261 active_layer()->AppendQuads(render_pass.get(), &data); 4394 active_layer_->AppendQuads(render_pass.get(), &data);
4262 active_layer()->DidDraw(nullptr); 4395 active_layer_->DidDraw(nullptr);
4263 4396
4264 DrawQuad::Material expected = test_for_solid 4397 DrawQuad::Material expected = test_for_solid
4265 ? DrawQuad::Material::SOLID_COLOR 4398 ? DrawQuad::Material::SOLID_COLOR
4266 : DrawQuad::Material::TILED_CONTENT; 4399 : DrawQuad::Material::TILED_CONTENT;
4267 EXPECT_EQ(expected, render_pass->quad_list.front()->material); 4400 EXPECT_EQ(expected, render_pass->quad_list.front()->material);
4268 } 4401 }
4269 4402
4270 TEST_F(PictureLayerImplTest, DrawSolidQuads) { 4403 TEST_F(PictureLayerImplTest, DrawSolidQuads) {
4271 TestQuadsForSolidColor(true); 4404 TestQuadsForSolidColor(true);
4272 } 4405 }
4273 4406
4274 TEST_F(PictureLayerImplTest, DrawNonSolidQuads) { 4407 TEST_F(PictureLayerImplTest, DrawNonSolidQuads) {
4275 TestQuadsForSolidColor(false); 4408 TestQuadsForSolidColor(false);
4276 } 4409 }
4277 4410
4278 TEST_F(PictureLayerImplTest, NonSolidToSolidNoTilings) { 4411 TEST_F(PictureLayerImplTest, NonSolidToSolidNoTilings) {
4279 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); 4412 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
4280 4413
4281 gfx::Size tile_size(100, 100); 4414 gfx::Size tile_size(100, 100);
4282 gfx::Size layer_bounds(200, 200); 4415 gfx::Size layer_bounds(200, 200);
4283 gfx::Rect layer_rect(layer_bounds); 4416 gfx::Rect layer_rect(layer_bounds);
4284 4417
4285 FakeContentLayerClient client; 4418 FakeContentLayerClient client;
4286 client.set_bounds(layer_bounds); 4419 client.set_bounds(layer_bounds);
4287 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client); 4420 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client);
4288 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); 4421 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D);
4289 TestTaskGraphRunner task_graph_runner; 4422 TestTaskGraphRunner task_graph_runner;
(...skipping 11 matching lines...) Expand all
4301 recording_source->UpdateAndExpandInvalidation( 4434 recording_source->UpdateAndExpandInvalidation(
4302 &client, &invalidation1, layer_bounds, frame_number++, 4435 &client, &invalidation1, layer_bounds, frame_number++,
4303 RecordingSource::RECORD_NORMALLY); 4436 RecordingSource::RECORD_NORMALLY);
4304 4437
4305 scoped_refptr<RasterSource> raster_source1 = 4438 scoped_refptr<RasterSource> raster_source1 =
4306 recording_source->CreateRasterSource(true); 4439 recording_source->CreateRasterSource(true);
4307 4440
4308 SetupPendingTree(raster_source1); 4441 SetupPendingTree(raster_source1);
4309 ActivateTree(); 4442 ActivateTree();
4310 bool update_lcd_text = false; 4443 bool update_lcd_text = false;
4311 host_impl()->active_tree()->UpdateDrawProperties(update_lcd_text); 4444 host_impl_.active_tree()->UpdateDrawProperties(update_lcd_text);
4312 4445
4313 // We've started with a solid layer that contains some tilings. 4446 // We've started with a solid layer that contains some tilings.
4314 ASSERT_TRUE(active_layer()->tilings()); 4447 ASSERT_TRUE(active_layer_->tilings());
4315 EXPECT_NE(0u, active_layer()->tilings()->num_tilings()); 4448 EXPECT_NE(0u, active_layer_->tilings()->num_tilings());
4316 4449
4317 client.set_fill_with_nonsolid_color(false); 4450 client.set_fill_with_nonsolid_color(false);
4318 4451
4319 recording_source->SetNeedsDisplayRect(layer_rect); 4452 recording_source->SetNeedsDisplayRect(layer_rect);
4320 Region invalidation2; 4453 Region invalidation2;
4321 recording_source->UpdateAndExpandInvalidation( 4454 recording_source->UpdateAndExpandInvalidation(
4322 &client, &invalidation2, layer_bounds, frame_number++, 4455 &client, &invalidation2, layer_bounds, frame_number++,
4323 RecordingSource::RECORD_NORMALLY); 4456 RecordingSource::RECORD_NORMALLY);
4324 4457
4325 scoped_refptr<RasterSource> raster_source2 = 4458 scoped_refptr<RasterSource> raster_source2 =
4326 recording_source->CreateRasterSource(true); 4459 recording_source->CreateRasterSource(true);
4327 4460
4328 SetupPendingTree(raster_source2); 4461 SetupPendingTree(raster_source2);
4329 ActivateTree(); 4462 ActivateTree();
4330 4463
4331 // We've switched to a solid color, so we should end up with no tilings. 4464 // We've switched to a solid color, so we should end up with no tilings.
4332 ASSERT_TRUE(active_layer()->tilings()); 4465 ASSERT_TRUE(active_layer_->tilings());
4333 EXPECT_EQ(0u, active_layer()->tilings()->num_tilings()); 4466 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
4334 } 4467 }
4335 4468
4336 TEST_F(PictureLayerImplTest, ChangeInViewportAllowsTilingUpdates) { 4469 TEST_F(PictureLayerImplTest, ChangeInViewportAllowsTilingUpdates) {
4337 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); 4470 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
4338 4471
4339 gfx::Size layer_bounds(400, 4000); 4472 gfx::Size layer_bounds(400, 4000);
4340 SetupDefaultTrees(layer_bounds); 4473 SetupDefaultTrees(layer_bounds);
4341 4474
4342 Region invalidation; 4475 Region invalidation;
4343 gfx::Rect viewport = gfx::Rect(0, 0, 100, 100); 4476 gfx::Rect viewport = gfx::Rect(0, 0, 100, 100);
4344 gfx::Transform transform; 4477 gfx::Transform transform;
4345 4478
4346 host_impl()->SetRequiresHighResToDraw(); 4479 host_impl_.SetRequiresHighResToDraw();
4347 4480
4348 // Update tiles. 4481 // Update tiles.
4349 pending_layer()->draw_properties().visible_layer_rect = viewport; 4482 pending_layer_->draw_properties().visible_layer_rect = viewport;
4350 pending_layer()->draw_properties().screen_space_transform = transform; 4483 pending_layer_->draw_properties().screen_space_transform = transform;
4351 SetupDrawPropertiesAndUpdateTiles(pending_layer(), 1.f, 1.f, 1.f, 1.f, 0.f, 4484 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.f, 1.f, 1.f, 1.f, 0.f,
4352 false); 4485 false);
4353 pending_layer()->HighResTiling()->UpdateAllRequiredStateForTesting(); 4486 pending_layer_->HighResTiling()->UpdateAllRequiredStateForTesting();
4354 4487
4355 // Ensure we can't activate. 4488 // Ensure we can't activate.
4356 EXPECT_FALSE(host_impl()->tile_manager()->IsReadyToActivate()); 4489 EXPECT_FALSE(host_impl_.tile_manager()->IsReadyToActivate());
4357 4490
4358 // Now in the same frame, move the viewport (this can happen during 4491 // Now in the same frame, move the viewport (this can happen during
4359 // animation). 4492 // animation).
4360 viewport = gfx::Rect(0, 2000, 100, 100); 4493 viewport = gfx::Rect(0, 2000, 100, 100);
4361 4494
4362 // Update tiles. 4495 // Update tiles.
4363 pending_layer()->draw_properties().visible_layer_rect = viewport; 4496 pending_layer_->draw_properties().visible_layer_rect = viewport;
4364 pending_layer()->draw_properties().screen_space_transform = transform; 4497 pending_layer_->draw_properties().screen_space_transform = transform;
4365 SetupDrawPropertiesAndUpdateTiles(pending_layer(), 1.f, 1.f, 1.f, 1.f, 0.f, 4498 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.f, 1.f, 1.f, 1.f, 0.f,
4366 false); 4499 false);
4367 pending_layer()->HighResTiling()->UpdateAllRequiredStateForTesting(); 4500 pending_layer_->HighResTiling()->UpdateAllRequiredStateForTesting();
4368 4501
4369 // Make sure all viewport tiles (viewport from the tiling) are ready to draw. 4502 // Make sure all viewport tiles (viewport from the tiling) are ready to draw.
4370 std::vector<Tile*> tiles; 4503 std::vector<Tile*> tiles;
4371 for (PictureLayerTiling::CoverageIterator iter( 4504 for (PictureLayerTiling::CoverageIterator iter(
4372 pending_layer()->HighResTiling(), 1.f, 4505 pending_layer_->HighResTiling(),
4373 pending_layer()->HighResTiling()->GetCurrentVisibleRectForTesting()); 4506 1.f,
4374 iter; ++iter) { 4507 pending_layer_->HighResTiling()->GetCurrentVisibleRectForTesting());
4508 iter;
4509 ++iter) {
4375 if (*iter) 4510 if (*iter)
4376 tiles.push_back(*iter); 4511 tiles.push_back(*iter);
4377 } 4512 }
4378 for (PictureLayerTiling::CoverageIterator iter( 4513 for (PictureLayerTiling::CoverageIterator iter(
4379 active_layer()->HighResTiling(), 1.f, 4514 active_layer_->HighResTiling(), 1.f,
4380 active_layer()->HighResTiling()->GetCurrentVisibleRectForTesting()); 4515 active_layer_->HighResTiling()->GetCurrentVisibleRectForTesting());
4381 iter; ++iter) { 4516 iter; ++iter) {
4382 if (*iter) 4517 if (*iter)
4383 tiles.push_back(*iter); 4518 tiles.push_back(*iter);
4384 } 4519 }
4385 4520
4386 host_impl()->tile_manager()->InitializeTilesWithResourcesForTesting(tiles); 4521 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(tiles);
4387 4522
4388 // Ensure we can activate. 4523 // Ensure we can activate.
4389 EXPECT_TRUE(host_impl()->tile_manager()->IsReadyToActivate()); 4524 EXPECT_TRUE(host_impl_.tile_manager()->IsReadyToActivate());
4390 } 4525 }
4391 4526
4392 TEST_F(PictureLayerImplTest, CloneMissingRecordings) { 4527 TEST_F(PictureLayerImplTest, CloneMissingRecordings) {
4393 gfx::Size tile_size(100, 100); 4528 gfx::Size tile_size(100, 100);
4394 gfx::Size layer_bounds(400, 400); 4529 gfx::Size layer_bounds(400, 400);
4395 4530
4396 scoped_refptr<FakeRasterSource> filled_raster_source = 4531 scoped_refptr<FakeRasterSource> filled_raster_source =
4397 FakeRasterSource::CreateFilled(layer_bounds); 4532 FakeRasterSource::CreateFilled(layer_bounds);
4398 4533
4399 scoped_refptr<FakeRasterSource> partial_raster_source = 4534 scoped_refptr<FakeRasterSource> partial_raster_source =
4400 FakeRasterSource::CreatePartiallyFilled(layer_bounds, 4535 FakeRasterSource::CreatePartiallyFilled(layer_bounds,
4401 gfx::Rect(100, 100, 300, 300)); 4536 gfx::Rect(100, 100, 300, 300));
4402 4537
4403 SetupPendingTreeWithFixedTileSize(filled_raster_source, tile_size, Region()); 4538 SetupPendingTreeWithFixedTileSize(filled_raster_source, tile_size, Region());
4404 ActivateTree(); 4539 ActivateTree();
4405 4540
4406 PictureLayerTiling* pending_tiling = old_pending_layer()->HighResTiling(); 4541 PictureLayerTiling* pending_tiling = old_pending_layer_->HighResTiling();
4407 PictureLayerTiling* active_tiling = active_layer()->HighResTiling(); 4542 PictureLayerTiling* active_tiling = active_layer_->HighResTiling();
4408 4543
4409 // We should have all tiles on active, and none on pending. 4544 // We should have all tiles on active, and none on pending.
4410 EXPECT_EQ(0u, pending_tiling->AllTilesForTesting().size()); 4545 EXPECT_EQ(0u, pending_tiling->AllTilesForTesting().size());
4411 EXPECT_EQ(5u * 5u, active_tiling->AllTilesForTesting().size()); 4546 EXPECT_EQ(5u * 5u, active_tiling->AllTilesForTesting().size());
4412 4547
4413 // Now put a partially-recorded raster source on the pending tree (and 4548 // Now put a partially-recorded raster source on the pending tree (and
4414 // invalidate everything, since the main thread recording will invalidate 4549 // invalidate everything, since the main thread recording will invalidate
4415 // dropped recordings). This will cause us to be missing some tiles. 4550 // dropped recordings). This will cause us to be missing some tiles.
4416 SetupPendingTreeWithFixedTileSize(partial_raster_source, tile_size, 4551 SetupPendingTreeWithFixedTileSize(partial_raster_source, tile_size,
4417 Region(gfx::Rect(layer_bounds))); 4552 Region(gfx::Rect(layer_bounds)));
(...skipping 26 matching lines...) Expand all
4444 4579
4445 // Activate the tree. The tiles are moved to the active tree. 4580 // Activate the tree. The tiles are moved to the active tree.
4446 ActivateTree(); 4581 ActivateTree();
4447 EXPECT_EQ(5u * 5u, active_tiling->AllTilesForTesting().size()); 4582 EXPECT_EQ(5u * 5u, active_tiling->AllTilesForTesting().size());
4448 EXPECT_EQ(tile00, active_tiling->TileAt(0, 0)); 4583 EXPECT_EQ(tile00, active_tiling->TileAt(0, 0));
4449 EXPECT_EQ(tile11, active_tiling->TileAt(1, 1)); 4584 EXPECT_EQ(tile11, active_tiling->TileAt(1, 1));
4450 EXPECT_EQ(tile22, active_tiling->TileAt(2, 2)); 4585 EXPECT_EQ(tile22, active_tiling->TileAt(2, 2));
4451 } 4586 }
4452 4587
4453 TEST_F(PictureLayerImplTest, ScrollPastLiveTilesRectAndBack) { 4588 TEST_F(PictureLayerImplTest, ScrollPastLiveTilesRectAndBack) {
4454 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); 4589 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
4455 4590
4456 gfx::Size tile_size(102, 102); 4591 gfx::Size tile_size(102, 102);
4457 gfx::Size layer_bounds(100, 100); 4592 gfx::Size layer_bounds(100, 100);
4458 gfx::Size viewport_size(100, 100); 4593 gfx::Size viewport_size(100, 100);
4459 4594
4460 host_impl()->SetViewportSize(viewport_size); 4595 host_impl_.SetViewportSize(viewport_size);
4461 SetInitialDeviceScaleFactor(1.f); 4596 SetInitialDeviceScaleFactor(1.f);
4462 4597
4463 scoped_refptr<FakeRasterSource> pending_raster_source = 4598 scoped_refptr<FakeRasterSource> pending_raster_source =
4464 FakeRasterSource::CreateFilled(layer_bounds); 4599 FakeRasterSource::CreateFilled(layer_bounds);
4465 scoped_refptr<FakeRasterSource> active_raster_source = 4600 scoped_refptr<FakeRasterSource> active_raster_source =
4466 FakeRasterSource::CreateFilled(layer_bounds); 4601 FakeRasterSource::CreateFilled(layer_bounds);
4467 4602
4468 SetupPendingTreeWithFixedTileSize(active_raster_source, tile_size, Region()); 4603 SetupPendingTreeWithFixedTileSize(active_raster_source, tile_size, Region());
4469 4604
4470 ActivateTree(); 4605 ActivateTree();
4471 EXPECT_TRUE(active_layer()->HighResTiling()->has_tiles()); 4606 EXPECT_TRUE(active_layer_->HighResTiling()->has_tiles());
4472 4607
4473 host_impl()->SetExternalTilePriorityConstraints(gfx::Rect(0, 5000, 100, 100), 4608 host_impl_.SetExternalTilePriorityConstraints(gfx::Rect(0, 5000, 100, 100),
4474 gfx::Transform()); 4609 gfx::Transform());
4475 4610
4476 SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size, 4611 SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size,
4477 gfx::Rect()); 4612 gfx::Rect());
4478 4613
4479 EXPECT_FALSE(pending_layer()->HighResTiling()->has_tiles()); 4614 EXPECT_FALSE(pending_layer_->HighResTiling()->has_tiles());
4480 EXPECT_TRUE(pending_layer()->HighResTiling()->live_tiles_rect().IsEmpty()); 4615 EXPECT_TRUE(pending_layer_->HighResTiling()->live_tiles_rect().IsEmpty());
4481 ActivateTree(); 4616 ActivateTree();
4482 EXPECT_FALSE(active_layer()->HighResTiling()->has_tiles()); 4617 EXPECT_FALSE(active_layer_->HighResTiling()->has_tiles());
4483 EXPECT_TRUE(active_layer()->HighResTiling()->live_tiles_rect().IsEmpty()); 4618 EXPECT_TRUE(active_layer_->HighResTiling()->live_tiles_rect().IsEmpty());
4484 4619
4485 host_impl()->SetExternalTilePriorityConstraints(gfx::Rect(0, 110, 100, 100), 4620 host_impl_.SetExternalTilePriorityConstraints(gfx::Rect(0, 110, 100, 100),
4486 gfx::Transform()); 4621 gfx::Transform());
4487 4622
4488 SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size, 4623 SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size,
4489 gfx::Rect()); 4624 gfx::Rect());
4490 4625
4491 EXPECT_FALSE(pending_layer()->HighResTiling()->has_tiles()); 4626 EXPECT_FALSE(pending_layer_->HighResTiling()->has_tiles());
4492 EXPECT_FALSE(pending_layer()->HighResTiling()->live_tiles_rect().IsEmpty()); 4627 EXPECT_FALSE(pending_layer_->HighResTiling()->live_tiles_rect().IsEmpty());
4493 ActivateTree(); 4628 ActivateTree();
4494 EXPECT_TRUE(active_layer()->HighResTiling()->has_tiles()); 4629 EXPECT_TRUE(active_layer_->HighResTiling()->has_tiles());
4495 EXPECT_FALSE(active_layer()->HighResTiling()->live_tiles_rect().IsEmpty()); 4630 EXPECT_FALSE(active_layer_->HighResTiling()->live_tiles_rect().IsEmpty());
4496 } 4631 }
4497 4632
4498 TEST_F(PictureLayerImplTest, ScrollPropagatesToPending) { 4633 TEST_F(PictureLayerImplTest, ScrollPropagatesToPending) {
4499 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); 4634 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
4500 4635
4501 gfx::Size layer_bounds(1000, 1000); 4636 gfx::Size layer_bounds(1000, 1000);
4502 gfx::Size viewport_size(100, 100); 4637 gfx::Size viewport_size(100, 100);
4503 4638
4504 host_impl()->SetViewportSize(viewport_size); 4639 host_impl_.SetViewportSize(viewport_size);
4505 SetInitialDeviceScaleFactor(1.f); 4640 SetInitialDeviceScaleFactor(1.f);
4506 4641
4507 SetupDefaultTrees(layer_bounds); 4642 SetupDefaultTrees(layer_bounds);
4508 4643
4509 active_layer()->SetCurrentScrollOffset(gfx::ScrollOffset(0.0, 50.0)); 4644 active_layer_->SetCurrentScrollOffset(gfx::ScrollOffset(0.0, 50.0));
4510 host_impl()->active_tree()->UpdateDrawProperties(false); 4645 host_impl_.active_tree()->UpdateDrawProperties(false);
4511 EXPECT_EQ("0,50 100x100", active_layer() 4646 EXPECT_EQ("0,50 100x100", active_layer_->HighResTiling()
4512 ->HighResTiling()
4513 ->GetCurrentVisibleRectForTesting() 4647 ->GetCurrentVisibleRectForTesting()
4514 .ToString()); 4648 .ToString());
4515 4649
4516 EXPECT_EQ("0,0 100x100", pending_layer() 4650 EXPECT_EQ("0,0 100x100", pending_layer_->HighResTiling()
4517 ->HighResTiling()
4518 ->GetCurrentVisibleRectForTesting() 4651 ->GetCurrentVisibleRectForTesting()
4519 .ToString()); 4652 .ToString());
4520 host_impl()->pending_tree()->UpdateDrawProperties(false); 4653 host_impl_.pending_tree()->UpdateDrawProperties(false);
4521 EXPECT_EQ("0,50 100x100", pending_layer() 4654 EXPECT_EQ("0,50 100x100", pending_layer_->HighResTiling()
4522 ->HighResTiling()
4523 ->GetCurrentVisibleRectForTesting() 4655 ->GetCurrentVisibleRectForTesting()
4524 .ToString()); 4656 .ToString());
4525 } 4657 }
4526 4658
4527 TEST_F(PictureLayerImplTest, UpdateLCDInvalidatesPendingTree) { 4659 TEST_F(PictureLayerImplTest, UpdateLCDInvalidatesPendingTree) {
4528 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); 4660 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
4529 4661
4530 gfx::Size tile_size(102, 102); 4662 gfx::Size tile_size(102, 102);
4531 gfx::Size layer_bounds(100, 100); 4663 gfx::Size layer_bounds(100, 100);
4532 gfx::Size viewport_size(100, 100); 4664 gfx::Size viewport_size(100, 100);
4533 4665
4534 host_impl()->SetViewportSize(viewport_size); 4666 host_impl_.SetViewportSize(viewport_size);
4535 SetInitialDeviceScaleFactor(1.f); 4667 SetInitialDeviceScaleFactor(1.f);
4536 4668
4537 scoped_refptr<FakeRasterSource> pending_raster_source = 4669 scoped_refptr<FakeRasterSource> pending_raster_source =
4538 FakeRasterSource::CreateFilledLCD(layer_bounds); 4670 FakeRasterSource::CreateFilledLCD(layer_bounds);
4539 SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size, Region()); 4671 SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size, Region());
4540 4672
4541 EXPECT_TRUE(pending_layer()->RasterSourceUsesLCDText()); 4673 EXPECT_TRUE(pending_layer_->RasterSourceUsesLCDText());
4542 EXPECT_TRUE(pending_layer()->HighResTiling()->has_tiles()); 4674 EXPECT_TRUE(pending_layer_->HighResTiling()->has_tiles());
4543 std::vector<Tile*> tiles = 4675 std::vector<Tile*> tiles =
4544 pending_layer()->HighResTiling()->AllTilesForTesting(); 4676 pending_layer_->HighResTiling()->AllTilesForTesting();
4545 auto prioritized_tiles = pending_layer() 4677 auto prioritized_tiles = pending_layer_->HighResTiling()
4546 ->HighResTiling()
4547 ->UpdateAndGetAllPrioritizedTilesForTesting(); 4678 ->UpdateAndGetAllPrioritizedTilesForTesting();
4548 4679
4549 for (Tile* tile : tiles) 4680 for (Tile* tile : tiles)
4550 EXPECT_EQ(pending_layer()->raster_source(), 4681 EXPECT_EQ(pending_layer_->raster_source(),
4551 prioritized_tiles[tile].raster_source()); 4682 prioritized_tiles[tile].raster_source());
4552 4683
4553 pending_layer()->draw_properties().can_use_lcd_text = false; 4684 pending_layer_->draw_properties().can_use_lcd_text = false;
4554 pending_layer()->UpdateCanUseLCDTextAfterCommit(); 4685 pending_layer_->UpdateCanUseLCDTextAfterCommit();
4555 4686
4556 EXPECT_FALSE(pending_layer()->RasterSourceUsesLCDText()); 4687 EXPECT_FALSE(pending_layer_->RasterSourceUsesLCDText());
4557 EXPECT_NE(pending_raster_source.get(), pending_layer()->raster_source()); 4688 EXPECT_NE(pending_raster_source.get(), pending_layer_->raster_source());
4558 EXPECT_TRUE(pending_layer()->HighResTiling()->has_tiles()); 4689 EXPECT_TRUE(pending_layer_->HighResTiling()->has_tiles());
4559 tiles = pending_layer()->HighResTiling()->AllTilesForTesting(); 4690 tiles = pending_layer_->HighResTiling()->AllTilesForTesting();
4560 prioritized_tiles = pending_layer() 4691 prioritized_tiles = pending_layer_->HighResTiling()
4561 ->HighResTiling()
4562 ->UpdateAndGetAllPrioritizedTilesForTesting(); 4692 ->UpdateAndGetAllPrioritizedTilesForTesting();
4563 for (Tile* tile : tiles) 4693 for (Tile* tile : tiles)
4564 EXPECT_EQ(pending_layer()->raster_source(), 4694 EXPECT_EQ(pending_layer_->raster_source(),
4565 prioritized_tiles[tile].raster_source()); 4695 prioritized_tiles[tile].raster_source());
4566 } 4696 }
4567 4697
4568 TEST_F(PictureLayerImplTest, TilingAllTilesDone) { 4698 TEST_F(PictureLayerImplTest, TilingAllTilesDone) {
4569 gfx::Size tile_size = host_impl()->settings().default_tile_size; 4699 gfx::Size tile_size = host_impl_.settings().default_tile_size;
4570 size_t tile_mem = 4 * tile_size.width() * tile_size.height(); 4700 size_t tile_mem = 4 * tile_size.width() * tile_size.height();
4571 gfx::Size layer_bounds(1000, 1000); 4701 gfx::Size layer_bounds(1000, 1000);
4572 4702
4573 // Create tiles. 4703 // Create tiles.
4574 scoped_refptr<FakeRasterSource> pending_raster_source = 4704 scoped_refptr<FakeRasterSource> pending_raster_source =
4575 FakeRasterSource::CreateFilled(layer_bounds); 4705 FakeRasterSource::CreateFilled(layer_bounds);
4576 SetupPendingTree(pending_raster_source); 4706 SetupPendingTree(pending_raster_source);
4577 pending_layer()->SetBounds(layer_bounds); 4707 pending_layer_->SetBounds(layer_bounds);
4578 ActivateTree(); 4708 ActivateTree();
4579 host_impl()->tile_manager()->InitializeTilesWithResourcesForTesting( 4709 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(
4580 active_layer()->HighResTiling()->AllTilesForTesting()); 4710 active_layer_->HighResTiling()->AllTilesForTesting());
4581 host_impl()->SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES); 4711 host_impl_.SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES);
4582 4712
4583 EXPECT_FALSE(active_layer()->HighResTiling()->all_tiles_done()); 4713 EXPECT_FALSE(active_layer_->HighResTiling()->all_tiles_done());
4584 4714
4585 { 4715 {
4586 // Set a memory policy that will fit all tiles. 4716 // Set a memory policy that will fit all tiles.
4587 size_t max_tiles = 16; 4717 size_t max_tiles = 16;
4588 size_t memory_limit = max_tiles * tile_mem; 4718 size_t memory_limit = max_tiles * tile_mem;
4589 ManagedMemoryPolicy policy(memory_limit, 4719 ManagedMemoryPolicy policy(memory_limit,
4590 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING, 4720 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING,
4591 max_tiles); 4721 max_tiles);
4592 host_impl()->SetMemoryPolicy(policy); 4722 host_impl_.SetMemoryPolicy(policy);
4593 host_impl()->PrepareTiles(); 4723 host_impl_.PrepareTiles();
4594 4724
4595 EXPECT_TRUE(active_layer()->HighResTiling()->all_tiles_done()); 4725 EXPECT_TRUE(active_layer_->HighResTiling()->all_tiles_done());
4596 } 4726 }
4597 4727
4598 { 4728 {
4599 // Set a memory policy that will cause tile eviction. 4729 // Set a memory policy that will cause tile eviction.
4600 size_t max_tiles = 1; 4730 size_t max_tiles = 1;
4601 size_t memory_limit = max_tiles * tile_mem; 4731 size_t memory_limit = max_tiles * tile_mem;
4602 ManagedMemoryPolicy policy(memory_limit, 4732 ManagedMemoryPolicy policy(memory_limit,
4603 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING, 4733 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING,
4604 max_tiles); 4734 max_tiles);
4605 host_impl()->SetMemoryPolicy(policy); 4735 host_impl_.SetMemoryPolicy(policy);
4606 host_impl()->PrepareTiles(); 4736 host_impl_.PrepareTiles();
4607 4737
4608 EXPECT_FALSE(active_layer()->HighResTiling()->all_tiles_done()); 4738 EXPECT_FALSE(active_layer_->HighResTiling()->all_tiles_done());
4609 } 4739 }
4610 } 4740 }
4611 4741
4612 class TileSizeTest : public PictureLayerImplTest { 4742 class TileSizeSettings : public PictureLayerImplTestSettings {
4613 public: 4743 public:
4614 LayerTreeSettings CreateSettings() override { 4744 TileSizeSettings() {
4615 LayerTreeSettings settings = PictureLayerImplTest::CreateSettings(); 4745 default_tile_size = gfx::Size(100, 100);
4616 settings.default_tile_size = gfx::Size(100, 100); 4746 max_untiled_layer_size = gfx::Size(200, 200);
4617 settings.max_untiled_layer_size = gfx::Size(200, 200);
4618 return settings;
4619 } 4747 }
4620 }; 4748 };
4621 4749
4750 class TileSizeTest : public PictureLayerImplTest {
4751 public:
4752 TileSizeTest() : PictureLayerImplTest(TileSizeSettings()) {}
4753 };
4754
4622 TEST_F(TileSizeTest, TileSizes) { 4755 TEST_F(TileSizeTest, TileSizes) {
4623 host_impl()->CreatePendingTree(); 4756 host_impl_.CreatePendingTree();
4624 4757
4625 LayerTreeImpl* pending_tree = host_impl()->pending_tree(); 4758 LayerTreeImpl* pending_tree = host_impl_.pending_tree();
4626 std::unique_ptr<FakePictureLayerImpl> layer = 4759 std::unique_ptr<FakePictureLayerImpl> layer =
4627 FakePictureLayerImpl::Create(pending_tree, layer_id()); 4760 FakePictureLayerImpl::Create(pending_tree, id_);
4628 4761
4629 host_impl()->SetViewportSize(gfx::Size(1000, 1000)); 4762 host_impl_.SetViewportSize(gfx::Size(1000, 1000));
4630 gfx::Size result; 4763 gfx::Size result;
4631 4764
4632 host_impl()->SetContentIsSuitableForGpuRasterization(true); 4765 host_impl_.SetContentIsSuitableForGpuRasterization(true);
4633 host_impl()->SetHasGpuRasterizationTrigger(false); 4766 host_impl_.SetHasGpuRasterizationTrigger(false);
4634 EXPECT_EQ(host_impl()->gpu_rasterization_status(), 4767 EXPECT_EQ(host_impl_.gpu_rasterization_status(),
4635 GpuRasterizationStatus::OFF_VIEWPORT); 4768 GpuRasterizationStatus::OFF_VIEWPORT);
4636 4769
4637 // Default tile-size for large layers. 4770 // Default tile-size for large layers.
4638 result = layer->CalculateTileSize(gfx::Size(10000, 10000)); 4771 result = layer->CalculateTileSize(gfx::Size(10000, 10000));
4639 EXPECT_EQ(result.width(), 100); 4772 EXPECT_EQ(result.width(), 100);
4640 EXPECT_EQ(result.height(), 100); 4773 EXPECT_EQ(result.height(), 100);
4641 // Don't tile and round-up, when under max_untiled_layer_size. 4774 // Don't tile and round-up, when under max_untiled_layer_size.
4642 result = layer->CalculateTileSize(gfx::Size(42, 42)); 4775 result = layer->CalculateTileSize(gfx::Size(42, 42));
4643 EXPECT_EQ(result.width(), 64); 4776 EXPECT_EQ(result.width(), 64);
4644 EXPECT_EQ(result.height(), 64); 4777 EXPECT_EQ(result.height(), 64);
4645 result = layer->CalculateTileSize(gfx::Size(191, 191)); 4778 result = layer->CalculateTileSize(gfx::Size(191, 191));
4646 EXPECT_EQ(result.width(), 192); 4779 EXPECT_EQ(result.width(), 192);
4647 EXPECT_EQ(result.height(), 192); 4780 EXPECT_EQ(result.height(), 192);
4648 result = layer->CalculateTileSize(gfx::Size(199, 199)); 4781 result = layer->CalculateTileSize(gfx::Size(199, 199));
4649 EXPECT_EQ(result.width(), 200); 4782 EXPECT_EQ(result.width(), 200);
4650 EXPECT_EQ(result.height(), 200); 4783 EXPECT_EQ(result.height(), 200);
4651 4784
4652 // Gpu-rasterization uses 25% viewport-height tiles. 4785 // Gpu-rasterization uses 25% viewport-height tiles.
4653 // The +2's below are for border texels. 4786 // The +2's below are for border texels.
4654 host_impl()->SetHasGpuRasterizationTrigger(true); 4787 host_impl_.SetHasGpuRasterizationTrigger(true);
4655 EXPECT_EQ(host_impl()->gpu_rasterization_status(), 4788 EXPECT_EQ(host_impl_.gpu_rasterization_status(), GpuRasterizationStatus::ON);
4656 GpuRasterizationStatus::ON); 4789 host_impl_.SetViewportSize(gfx::Size(2000, 2000));
4657 host_impl()->SetViewportSize(gfx::Size(2000, 2000));
4658 4790
4659 layer->set_gpu_raster_max_texture_size(host_impl()->device_viewport_size()); 4791 layer->set_gpu_raster_max_texture_size(host_impl_.device_viewport_size());
4660 result = layer->CalculateTileSize(gfx::Size(10000, 10000)); 4792 result = layer->CalculateTileSize(gfx::Size(10000, 10000));
4661 EXPECT_EQ(result.width(), 4793 EXPECT_EQ(result.width(),
4662 MathUtil::UncheckedRoundUp( 4794 MathUtil::UncheckedRoundUp(
4663 2000 + 2 * PictureLayerTiling::kBorderTexels, 4)); 4795 2000 + 2 * PictureLayerTiling::kBorderTexels, 4));
4664 EXPECT_EQ(result.height(), 504); // 500 + 2, 4-byte aligned. 4796 EXPECT_EQ(result.height(), 504); // 500 + 2, 4-byte aligned.
4665 4797
4666 // Clamp and round-up, when smaller than viewport. 4798 // Clamp and round-up, when smaller than viewport.
4667 // Tile-height doubles to 50% when width shrinks to <= 50%. 4799 // Tile-height doubles to 50% when width shrinks to <= 50%.
4668 host_impl()->SetViewportSize(gfx::Size(1000, 1000)); 4800 host_impl_.SetViewportSize(gfx::Size(1000, 1000));
4669 layer->set_gpu_raster_max_texture_size(host_impl()->device_viewport_size()); 4801 layer->set_gpu_raster_max_texture_size(host_impl_.device_viewport_size());
4670 result = layer->CalculateTileSize(gfx::Size(447, 10000)); 4802 result = layer->CalculateTileSize(gfx::Size(447, 10000));
4671 EXPECT_EQ(result.width(), 448); 4803 EXPECT_EQ(result.width(), 448);
4672 EXPECT_EQ(result.height(), 504); // 500 + 2, 4-byte aliged. 4804 EXPECT_EQ(result.height(), 504); // 500 + 2, 4-byte aliged.
4673 4805
4674 // Largest layer is 50% of viewport width (rounded up), and 4806 // Largest layer is 50% of viewport width (rounded up), and
4675 // 50% of viewport in height. 4807 // 50% of viewport in height.
4676 result = layer->CalculateTileSize(gfx::Size(447, 400)); 4808 result = layer->CalculateTileSize(gfx::Size(447, 400));
4677 EXPECT_EQ(result.width(), 448); 4809 EXPECT_EQ(result.width(), 448);
4678 EXPECT_EQ(result.height(), 448); 4810 EXPECT_EQ(result.height(), 448);
4679 result = layer->CalculateTileSize(gfx::Size(500, 499)); 4811 result = layer->CalculateTileSize(gfx::Size(500, 499));
4680 EXPECT_EQ(result.width(), 512); 4812 EXPECT_EQ(result.width(), 512);
4681 EXPECT_EQ(result.height(), 504); // 500 + 2, 4-byte aligned. 4813 EXPECT_EQ(result.height(), 504); // 500 + 2, 4-byte aligned.
4682 } 4814 }
4683 4815
4684 TEST_F(NoLowResPictureLayerImplTest, LowResWasHighResCollision) { 4816 TEST_F(NoLowResPictureLayerImplTest, LowResWasHighResCollision) {
4685 gfx::Size layer_bounds(1300, 1900); 4817 gfx::Size layer_bounds(1300, 1900);
4686 4818
4687 float low_res_factor = host_impl()->settings().low_res_contents_scale_factor; 4819 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
4688 SetupDefaultTrees(layer_bounds); 4820 SetupDefaultTrees(layer_bounds);
4689 ResetTilingsAndRasterScales(); 4821 ResetTilingsAndRasterScales();
4690 4822
4691 float page_scale = 2.f; 4823 float page_scale = 2.f;
4692 SetContentsScaleOnBothLayers(page_scale, 1.0f, page_scale, 1.0f, 0.f, false); 4824 SetContentsScaleOnBothLayers(page_scale, 1.0f, page_scale, 1.0f, 0.f, false);
4693 EXPECT_BOTH_EQ(num_tilings(), 1u); 4825 EXPECT_BOTH_EQ(num_tilings(), 1u);
4694 EXPECT_BOTH_EQ(tilings()->tiling_at(0)->contents_scale(), page_scale); 4826 EXPECT_BOTH_EQ(tilings()->tiling_at(0)->contents_scale(), page_scale);
4695 4827
4696 host_impl()->PinchGestureBegin(); 4828 host_impl_.PinchGestureBegin();
4697 4829
4698 // Zoom out to exactly the low res factor so that the previous high res 4830 // Zoom out to exactly the low res factor so that the previous high res
4699 // would be equal to the current low res (if it were possible to have one). 4831 // would be equal to the current low res (if it were possible to have one).
4700 float zoomed = page_scale / low_res_factor; 4832 float zoomed = page_scale / low_res_factor;
4701 SetContentsScaleOnBothLayers(zoomed, 1.0f, zoomed, 1.0f, 0.f, false); 4833 SetContentsScaleOnBothLayers(zoomed, 1.0f, zoomed, 1.0f, 0.f, false);
4702 EXPECT_EQ(1u, pending_layer()->num_tilings()); 4834 EXPECT_EQ(1u, pending_layer_->num_tilings());
4703 EXPECT_EQ(zoomed, pending_layer()->tilings()->tiling_at(0)->contents_scale()); 4835 EXPECT_EQ(zoomed, pending_layer_->tilings()->tiling_at(0)->contents_scale());
4704 } 4836 }
4705 4837
4706 TEST_F(PictureLayerImplTest, HighResWasLowResCollision) { 4838 TEST_F(PictureLayerImplTest, HighResWasLowResCollision) {
4707 gfx::Size layer_bounds(1300, 1900); 4839 gfx::Size layer_bounds(1300, 1900);
4708 4840
4709 float low_res_factor = host_impl()->settings().low_res_contents_scale_factor; 4841 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
4710 4842
4711 SetupDefaultTrees(layer_bounds); 4843 SetupDefaultTrees(layer_bounds);
4712 ResetTilingsAndRasterScales(); 4844 ResetTilingsAndRasterScales();
4713 4845
4714 float page_scale = 4.f; 4846 float page_scale = 4.f;
4715 float low_res = page_scale * low_res_factor; 4847 float low_res = page_scale * low_res_factor;
4716 float extra_low_res = low_res * low_res_factor; 4848 float extra_low_res = low_res * low_res_factor;
4717 SetupDrawPropertiesAndUpdateTiles(active_layer(), page_scale, 1.0f, 4849 SetupDrawPropertiesAndUpdateTiles(active_layer_, page_scale, 1.0f, page_scale,
4718 page_scale, 1.0f, 0.f, false); 4850 1.0f, 0.f, false);
4719 EXPECT_EQ(2u, active_layer()->tilings()->num_tilings()); 4851 EXPECT_EQ(2u, active_layer_->tilings()->num_tilings());
4720 EXPECT_EQ(page_scale, 4852 EXPECT_EQ(page_scale,
4721 active_layer()->tilings()->tiling_at(0)->contents_scale()); 4853 active_layer_->tilings()->tiling_at(0)->contents_scale());
4722 EXPECT_EQ(low_res, active_layer()->tilings()->tiling_at(1)->contents_scale()); 4854 EXPECT_EQ(low_res, active_layer_->tilings()->tiling_at(1)->contents_scale());
4723 4855
4724 // Grab a current low res tile. 4856 // Grab a current low res tile.
4725 PictureLayerTiling* old_low_res_tiling = 4857 PictureLayerTiling* old_low_res_tiling =
4726 active_layer()->tilings()->tiling_at(1); 4858 active_layer_->tilings()->tiling_at(1);
4727 Tile* old_low_res_tile = 4859 Tile* old_low_res_tile = active_layer_->tilings()->tiling_at(1)->TileAt(0, 0);
4728 active_layer()->tilings()->tiling_at(1)->TileAt(0, 0);
4729 4860
4730 // The tiling knows it has low res content. 4861 // The tiling knows it has low res content.
4731 EXPECT_TRUE(active_layer() 4862 EXPECT_TRUE(active_layer_->tilings()
4732 ->tilings()
4733 ->tiling_at(1) 4863 ->tiling_at(1)
4734 ->may_contain_low_resolution_tiles()); 4864 ->may_contain_low_resolution_tiles());
4735 4865
4736 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); 4866 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
4737 4867
4738 // Zoom in to exactly the low res factor so that the previous low res 4868 // Zoom in to exactly the low res factor so that the previous low res
4739 // would be equal to the current high res. 4869 // would be equal to the current high res.
4740 SetupDrawPropertiesAndUpdateTiles(active_layer(), low_res, 1.0f, low_res, 4870 SetupDrawPropertiesAndUpdateTiles(active_layer_, low_res, 1.0f, low_res, 1.0f,
4741 1.0f, 0.f, false); 4871 0.f, false);
4742 // 3 tilings. The old high res, the new high res (old low res) and the new low 4872 // 3 tilings. The old high res, the new high res (old low res) and the new low
4743 // res. 4873 // res.
4744 EXPECT_EQ(3u, active_layer()->num_tilings()); 4874 EXPECT_EQ(3u, active_layer_->num_tilings());
4745 4875
4746 PictureLayerTilingSet* tilings = active_layer()->tilings(); 4876 PictureLayerTilingSet* tilings = active_layer_->tilings();
4747 EXPECT_EQ(page_scale, tilings->tiling_at(0)->contents_scale()); 4877 EXPECT_EQ(page_scale, tilings->tiling_at(0)->contents_scale());
4748 EXPECT_EQ(low_res, tilings->tiling_at(1)->contents_scale()); 4878 EXPECT_EQ(low_res, tilings->tiling_at(1)->contents_scale());
4749 EXPECT_EQ(extra_low_res, tilings->tiling_at(2)->contents_scale()); 4879 EXPECT_EQ(extra_low_res, tilings->tiling_at(2)->contents_scale());
4750 4880
4751 EXPECT_EQ(NON_IDEAL_RESOLUTION, tilings->tiling_at(0)->resolution()); 4881 EXPECT_EQ(NON_IDEAL_RESOLUTION, tilings->tiling_at(0)->resolution());
4752 EXPECT_EQ(HIGH_RESOLUTION, tilings->tiling_at(1)->resolution()); 4882 EXPECT_EQ(HIGH_RESOLUTION, tilings->tiling_at(1)->resolution());
4753 EXPECT_EQ(LOW_RESOLUTION, tilings->tiling_at(2)->resolution()); 4883 EXPECT_EQ(LOW_RESOLUTION, tilings->tiling_at(2)->resolution());
4754 4884
4755 // The old low res tile was destroyed and replaced. 4885 // The old low res tile was destroyed and replaced.
4756 EXPECT_EQ(old_low_res_tiling, tilings->tiling_at(1)); 4886 EXPECT_EQ(old_low_res_tiling, tilings->tiling_at(1));
4757 EXPECT_NE(old_low_res_tile, tilings->tiling_at(1)->TileAt(0, 0)); 4887 EXPECT_NE(old_low_res_tile, tilings->tiling_at(1)->TileAt(0, 0));
4758 EXPECT_TRUE(tilings->tiling_at(1)->TileAt(0, 0)); 4888 EXPECT_TRUE(tilings->tiling_at(1)->TileAt(0, 0));
4759 4889
4760 // New high res tiling. 4890 // New high res tiling.
4761 EXPECT_FALSE(tilings->tiling_at(0)->may_contain_low_resolution_tiles()); 4891 EXPECT_FALSE(tilings->tiling_at(0)->may_contain_low_resolution_tiles());
4762 // New low res tiling. 4892 // New low res tiling.
4763 EXPECT_TRUE(tilings->tiling_at(2)->may_contain_low_resolution_tiles()); 4893 EXPECT_TRUE(tilings->tiling_at(2)->may_contain_low_resolution_tiles());
4764 4894
4765 // This tiling will be high res now, it won't contain low res content since it 4895 // This tiling will be high res now, it won't contain low res content since it
4766 // was all destroyed. 4896 // was all destroyed.
4767 EXPECT_FALSE(tilings->tiling_at(1)->may_contain_low_resolution_tiles()); 4897 EXPECT_FALSE(tilings->tiling_at(1)->may_contain_low_resolution_tiles());
4768 } 4898 }
4769 4899
4770 } // namespace 4900 } // namespace
4771 } // namespace cc 4901 } // namespace cc
OLDNEW
« no previous file with comments | « cc/cc_tests.gyp ('k') | cc/test/test_layer_tree_host_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698