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

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

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