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

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

Issue 812543002: Update from https://crrev.com/308331 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years 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/layers/picture_layer_impl.cc ('k') | cc/layers/texture_layer_impl.cc » ('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 <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
(...skipping 16 matching lines...) Expand all
27 #include "cc/test/test_shared_bitmap_manager.h" 27 #include "cc/test/test_shared_bitmap_manager.h"
28 #include "cc/test/test_web_graphics_context_3d.h" 28 #include "cc/test/test_web_graphics_context_3d.h"
29 #include "cc/trees/layer_tree_impl.h" 29 #include "cc/trees/layer_tree_impl.h"
30 #include "testing/gtest/include/gtest/gtest.h" 30 #include "testing/gtest/include/gtest/gtest.h"
31 #include "ui/gfx/geometry/rect_conversions.h" 31 #include "ui/gfx/geometry/rect_conversions.h"
32 #include "ui/gfx/geometry/size_conversions.h" 32 #include "ui/gfx/geometry/size_conversions.h"
33 33
34 namespace cc { 34 namespace cc {
35 namespace { 35 namespace {
36 36
37 #define EXPECT_BOTH_EQ(expression, x) \
38 do { \
39 EXPECT_EQ(x, pending_layer_->expression); \
40 EXPECT_EQ(x, active_layer_->expression); \
41 } while (false)
42
43 #define EXPECT_BOTH_NE(expression, x) \
44 do { \
45 EXPECT_NE(x, pending_layer_->expression); \
46 EXPECT_NE(x, active_layer_->expression); \
47 } while (false)
48
37 class MockCanvas : public SkCanvas { 49 class MockCanvas : public SkCanvas {
38 public: 50 public:
39 explicit MockCanvas(int w, int h) : SkCanvas(w, h) {} 51 explicit MockCanvas(int w, int h) : SkCanvas(w, h) {}
40 52
41 void drawRect(const SkRect& rect, const SkPaint& paint) override { 53 void drawRect(const SkRect& rect, const SkPaint& paint) override {
42 // Capture calls before SkCanvas quickReject() kicks in. 54 // Capture calls before SkCanvas quickReject() kicks in.
43 rects_.push_back(rect); 55 rects_.push_back(rect);
44 } 56 }
45 57
46 std::vector<SkRect> rects_; 58 std::vector<SkRect> rects_;
47 }; 59 };
48 60
49 class NoLowResTilingsSettings : public ImplSidePaintingSettings {}; 61 class NoLowResTilingsSettings : public ImplSidePaintingSettings {};
50 62
51 class LowResTilingsSettings : public ImplSidePaintingSettings { 63 class LowResTilingsSettings : public ImplSidePaintingSettings {
52 public: 64 public:
53 LowResTilingsSettings() { create_low_res_tiling = true; } 65 LowResTilingsSettings() { create_low_res_tiling = true; }
54 }; 66 };
55 67
56 class PictureLayerImplTest : public testing::Test { 68 class PictureLayerImplTest : public testing::Test {
57 public: 69 public:
58 PictureLayerImplTest() 70 PictureLayerImplTest()
59 : proxy_(base::MessageLoopProxy::current()), 71 : proxy_(base::MessageLoopProxy::current()),
60 host_impl_(LowResTilingsSettings(), &proxy_, &shared_bitmap_manager_), 72 host_impl_(LowResTilingsSettings(), &proxy_, &shared_bitmap_manager_),
73 root_id_(6),
61 id_(7), 74 id_(7),
62 pending_layer_(nullptr), 75 pending_layer_(nullptr),
63 old_pending_layer_(nullptr), 76 old_pending_layer_(nullptr),
64 active_layer_(nullptr) {} 77 active_layer_(nullptr) {
78 host_impl_.SetViewportSize(gfx::Size(10000, 10000));
79 }
65 80
66 explicit PictureLayerImplTest(const LayerTreeSettings& settings) 81 explicit PictureLayerImplTest(const LayerTreeSettings& settings)
67 : proxy_(base::MessageLoopProxy::current()), 82 : proxy_(base::MessageLoopProxy::current()),
68 host_impl_(settings, &proxy_, &shared_bitmap_manager_), 83 host_impl_(settings, &proxy_, &shared_bitmap_manager_),
69 id_(7) {} 84 root_id_(6),
85 id_(7) {
86 host_impl_.SetViewportSize(gfx::Size(10000, 10000));
87 }
70 88
71 virtual ~PictureLayerImplTest() { 89 virtual ~PictureLayerImplTest() {
72 } 90 }
73 91
74 void SetUp() override { InitializeRenderer(); } 92 void SetUp() override { InitializeRenderer(); }
75 93
76 virtual void InitializeRenderer() { 94 virtual void InitializeRenderer() {
77 host_impl_.InitializeRenderer(FakeOutputSurface::Create3d()); 95 host_impl_.InitializeRenderer(FakeOutputSurface::Create3d());
78 } 96 }
79 97
80 void SetupDefaultTrees(const gfx::Size& layer_bounds) { 98 void SetupDefaultTrees(const gfx::Size& layer_bounds) {
81 gfx::Size tile_size(100, 100); 99 gfx::Size tile_size(100, 100);
82 100
83 scoped_refptr<FakePicturePileImpl> pending_pile = 101 scoped_refptr<FakePicturePileImpl> pending_pile =
84 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 102 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
85 scoped_refptr<FakePicturePileImpl> active_pile = 103 scoped_refptr<FakePicturePileImpl> active_pile =
86 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 104 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
87 105
88 SetupTrees(pending_pile, active_pile); 106 SetupTrees(pending_pile, active_pile);
89 } 107 }
90 108
109 void SetupDefaultTreesWithInvalidation(const gfx::Size& layer_bounds,
110 const Region& invalidation) {
111 gfx::Size tile_size(100, 100);
112
113 scoped_refptr<FakePicturePileImpl> pending_pile =
114 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
115 scoped_refptr<FakePicturePileImpl> active_pile =
116 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
117
118 SetupTreesWithInvalidation(pending_pile, active_pile, invalidation);
119 }
120
91 void ActivateTree() { 121 void ActivateTree() {
92 host_impl_.ActivateSyncTree(); 122 host_impl_.ActivateSyncTree();
93 CHECK(!host_impl_.pending_tree()); 123 CHECK(!host_impl_.pending_tree());
94 CHECK(host_impl_.recycle_tree()); 124 CHECK(host_impl_.recycle_tree());
95 old_pending_layer_ = pending_layer_; 125 old_pending_layer_ = pending_layer_;
96 pending_layer_ = nullptr; 126 pending_layer_ = nullptr;
97 active_layer_ = static_cast<FakePictureLayerImpl*>( 127 active_layer_ = static_cast<FakePictureLayerImpl*>(
98 host_impl_.active_tree()->LayerById(id_)); 128 host_impl_.active_tree()->LayerById(id_));
129
130 host_impl_.active_tree()->UpdateDrawProperties();
99 } 131 }
100 132
101 void SetupDefaultTreesWithFixedTileSize(const gfx::Size& layer_bounds, 133 void SetupDefaultTreesWithFixedTileSize(const gfx::Size& layer_bounds,
102 const gfx::Size& tile_size) { 134 const gfx::Size& tile_size,
103 SetupDefaultTrees(layer_bounds); 135 const Region& invalidation) {
104 pending_layer_->set_fixed_tile_size(tile_size); 136 gfx::Size pile_tile_size(100, 100);
105 active_layer_->set_fixed_tile_size(tile_size); 137
138 scoped_refptr<FakePicturePileImpl> pending_pile =
139 FakePicturePileImpl::CreateFilledPile(pile_tile_size, layer_bounds);
140 scoped_refptr<FakePicturePileImpl> active_pile =
141 FakePicturePileImpl::CreateFilledPile(pile_tile_size, layer_bounds);
142
143 SetupTreesWithFixedTileSize(pending_pile, active_pile, tile_size,
144 invalidation);
106 } 145 }
107 146
108 void SetupTrees( 147 void SetupTrees(
109 scoped_refptr<PicturePileImpl> pending_pile, 148 scoped_refptr<PicturePileImpl> pending_pile,
110 scoped_refptr<PicturePileImpl> active_pile) { 149 scoped_refptr<PicturePileImpl> active_pile) {
111 SetupPendingTree(active_pile); 150 SetupPendingTree(active_pile);
112 ActivateTree(); 151 ActivateTree();
113 SetupPendingTree(pending_pile); 152 SetupPendingTreeInternal(pending_pile, gfx::Size(), Region());
114 } 153 }
115 154
116 void CreateHighLowResAndSetAllTilesVisible() { 155 void SetupTreesWithInvalidation(scoped_refptr<PicturePileImpl> pending_pile,
117 // Active layer must get updated first so pending layer can share from it. 156 scoped_refptr<PicturePileImpl> active_pile,
118 active_layer_->CreateDefaultTilingsAndTiles(); 157 const Region& pending_invalidation) {
119 active_layer_->SetAllTilesVisible(); 158 SetupPendingTreeInternal(active_pile, gfx::Size(), Region());
120 pending_layer_->CreateDefaultTilingsAndTiles(); 159 ActivateTree();
121 pending_layer_->SetAllTilesVisible(); 160 SetupPendingTreeInternal(pending_pile, gfx::Size(), pending_invalidation);
122 } 161 }
123 162
124 void AddDefaultTilingsWithInvalidation(const Region& invalidation) { 163 void SetupTreesWithFixedTileSize(scoped_refptr<PicturePileImpl> pending_pile,
125 active_layer_->AddTiling(2.3f); 164 scoped_refptr<PicturePileImpl> active_pile,
126 active_layer_->AddTiling(1.0f); 165 const gfx::Size& tile_size,
127 active_layer_->AddTiling(0.5f); 166 const Region& pending_invalidation) {
128 for (size_t i = 0; i < active_layer_->tilings()->num_tilings(); ++i) 167 SetupPendingTreeInternal(active_pile, tile_size, Region());
129 active_layer_->tilings()->tiling_at(i)->CreateAllTilesForTesting(); 168 ActivateTree();
130 pending_layer_->set_invalidation(invalidation); 169 SetupPendingTreeInternal(pending_pile, tile_size, pending_invalidation);
131 for (size_t i = 0; i < pending_layer_->tilings()->num_tilings(); ++i)
132 pending_layer_->tilings()->tiling_at(i)->CreateAllTilesForTesting();
133 } 170 }
134 171
135 void SetupPendingTree(scoped_refptr<RasterSource> raster_source) { 172 void SetupPendingTree(scoped_refptr<RasterSource> raster_source) {
173 SetupPendingTreeInternal(raster_source, gfx::Size(), Region());
174 }
175
176 void SetupPendingTreeWithInvalidation(
177 scoped_refptr<RasterSource> raster_source,
178 const Region& invalidation) {
179 SetupPendingTreeInternal(raster_source, gfx::Size(), invalidation);
180 }
181
182 void SetupPendingTreeWithFixedTileSize(
183 scoped_refptr<RasterSource> raster_source,
184 const gfx::Size& tile_size,
185 const Region& invalidation) {
186 SetupPendingTreeInternal(raster_source, tile_size, invalidation);
187 }
188
189 void SetupPendingTreeInternal(scoped_refptr<RasterSource> raster_source,
190 const gfx::Size& tile_size,
191 const Region& invalidation) {
136 host_impl_.CreatePendingTree(); 192 host_impl_.CreatePendingTree();
137 host_impl_.pending_tree()->PushPageScaleFromMainThread(1.f, 0.25f, 100.f); 193 host_impl_.pending_tree()->PushPageScaleFromMainThread(1.f, 0.25f, 100.f);
138 LayerTreeImpl* pending_tree = host_impl_.pending_tree(); 194 LayerTreeImpl* pending_tree = host_impl_.pending_tree();
139 195
140 // Steal from the recycled tree. 196 // Steal from the recycled tree if possible.
141 scoped_ptr<LayerImpl> old_pending_root = pending_tree->DetachLayerTree(); 197 scoped_ptr<LayerImpl> pending_root = pending_tree->DetachLayerTree();
142 DCHECK_IMPLIES(old_pending_root, old_pending_root->id() == id_);
143
144 scoped_ptr<FakePictureLayerImpl> pending_layer; 198 scoped_ptr<FakePictureLayerImpl> pending_layer;
145 if (old_pending_root) { 199 DCHECK_IMPLIES(pending_root, pending_root->id() == root_id_);
146 pending_layer.reset( 200 if (!pending_root) {
147 static_cast<FakePictureLayerImpl*>(old_pending_root.release())); 201 pending_root = LayerImpl::Create(pending_tree, root_id_);
148 pending_layer->SetRasterSource(raster_source); 202 pending_layer = FakePictureLayerImpl::Create(pending_tree, id_);
203 if (!tile_size.IsEmpty())
204 pending_layer->set_fixed_tile_size(tile_size);
205 pending_layer->SetDrawsContent(true);
149 } else { 206 } else {
150 pending_layer = FakePictureLayerImpl::CreateWithRasterSource( 207 pending_layer.reset(static_cast<FakePictureLayerImpl*>(
151 pending_tree, id_, raster_source); 208 pending_root->RemoveChild(pending_root->children()[0]).release()));
152 pending_layer->SetDrawsContent(true); 209 if (!tile_size.IsEmpty())
210 pending_layer->set_fixed_tile_size(tile_size);
153 } 211 }
154 // The bounds() just mirror the pile size. 212 // The bounds() just mirror the pile size.
155 pending_layer->SetBounds(pending_layer->raster_source()->GetSize()); 213 pending_layer->SetBounds(raster_source->GetSize());
156 pending_tree->SetRootLayer(pending_layer.Pass()); 214 pending_layer->SetContentBounds(raster_source->GetSize());
215 pending_layer->SetRasterSourceOnPending(raster_source, invalidation);
216
217 pending_root->AddChild(pending_layer.Pass());
218 pending_tree->SetRootLayer(pending_root.Pass());
157 219
158 pending_layer_ = static_cast<FakePictureLayerImpl*>( 220 pending_layer_ = static_cast<FakePictureLayerImpl*>(
159 host_impl_.pending_tree()->LayerById(id_)); 221 host_impl_.pending_tree()->LayerById(id_));
160 pending_layer_->DoPostCommitInitializationIfNeeded(); 222 pending_layer_->DoPostCommitInitializationIfNeeded();
223
224 // Add tilings/tiles for the layer.
225 host_impl_.pending_tree()->UpdateDrawProperties();
161 } 226 }
162 227
163 void SetupDrawPropertiesAndUpdateTiles(FakePictureLayerImpl* layer, 228 void SetupDrawPropertiesAndUpdateTiles(FakePictureLayerImpl* layer,
164 float ideal_contents_scale, 229 float ideal_contents_scale,
165 float device_scale_factor, 230 float device_scale_factor,
166 float page_scale_factor, 231 float page_scale_factor,
167 float maximum_animation_contents_scale, 232 float maximum_animation_contents_scale,
168 bool animating_transform_to_screen) { 233 bool animating_transform_to_screen) {
169 layer->draw_properties().ideal_contents_scale = ideal_contents_scale; 234 layer->draw_properties().ideal_contents_scale = ideal_contents_scale;
170 layer->draw_properties().device_scale_factor = device_scale_factor; 235 layer->draw_properties().device_scale_factor = device_scale_factor;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 contents_scale, 271 contents_scale,
207 device_scale_factor, 272 device_scale_factor,
208 page_scale_factor, 273 page_scale_factor,
209 maximum_animation_contents_scale, 274 maximum_animation_contents_scale,
210 animating_transform); 275 animating_transform);
211 } 276 }
212 277
213 void ResetTilingsAndRasterScales() { 278 void ResetTilingsAndRasterScales() {
214 pending_layer_->ReleaseResources(); 279 pending_layer_->ReleaseResources();
215 active_layer_->ReleaseResources(); 280 active_layer_->ReleaseResources();
281 if (pending_layer_)
282 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
283 if (active_layer_)
284 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
216 } 285 }
217 286
218 void AssertAllTilesRequired(PictureLayerTiling* tiling) { 287 void AssertAllTilesRequired(PictureLayerTiling* tiling) {
219 std::vector<Tile*> tiles = tiling->AllTilesForTesting(); 288 std::vector<Tile*> tiles = tiling->AllTilesForTesting();
220 for (size_t i = 0; i < tiles.size(); ++i) 289 for (size_t i = 0; i < tiles.size(); ++i)
221 EXPECT_TRUE(tiles[i]->required_for_activation()) << "i: " << i; 290 EXPECT_TRUE(tiles[i]->required_for_activation()) << "i: " << i;
222 EXPECT_GT(tiles.size(), 0u); 291 EXPECT_GT(tiles.size(), 0u);
223 } 292 }
224 293
225 void AssertNoTilesRequired(PictureLayerTiling* tiling) { 294 void AssertNoTilesRequired(PictureLayerTiling* tiling) {
226 std::vector<Tile*> tiles = tiling->AllTilesForTesting(); 295 std::vector<Tile*> tiles = tiling->AllTilesForTesting();
227 for (size_t i = 0; i < tiles.size(); ++i) 296 for (size_t i = 0; i < tiles.size(); ++i)
228 EXPECT_FALSE(tiles[i]->required_for_activation()) << "i: " << i; 297 EXPECT_FALSE(tiles[i]->required_for_activation()) << "i: " << i;
229 EXPECT_GT(tiles.size(), 0u); 298 EXPECT_GT(tiles.size(), 0u);
230 } 299 }
231 300
232 protected: 301 protected:
233 void TestTileGridAlignmentCommon() {
234 // Layer to span 4 raster tiles in x and in y
235 ImplSidePaintingSettings settings;
236 gfx::Size layer_size(
237 settings.default_tile_size.width() * 7 / 2,
238 settings.default_tile_size.height() * 7 / 2);
239
240 scoped_refptr<FakePicturePileImpl> pending_pile =
241 FakePicturePileImpl::CreateFilledPile(layer_size, layer_size);
242 scoped_refptr<FakePicturePileImpl> active_pile =
243 FakePicturePileImpl::CreateFilledPile(layer_size, layer_size);
244
245 SetupTrees(pending_pile, active_pile);
246
247 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, 1.f, 1.f, 1.f, false);
248
249 // Add 1x1 rects at the centers of each tile, then re-record pile contents
250 active_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting();
251 std::vector<Tile*> tiles =
252 active_layer_->tilings()->tiling_at(0)->AllTilesForTesting();
253 EXPECT_EQ(16u, tiles.size());
254 std::vector<SkRect> rects;
255 std::vector<Tile*>::const_iterator tile_iter;
256 for (tile_iter = tiles.begin(); tile_iter < tiles.end(); tile_iter++) {
257 gfx::Point tile_center = (*tile_iter)->content_rect().CenterPoint();
258 gfx::Rect rect(tile_center.x(), tile_center.y(), 1, 1);
259 active_pile->add_draw_rect(rect);
260 rects.push_back(SkRect::MakeXYWH(rect.x(), rect.y(), 1, 1));
261 }
262 // Force re-record with newly injected content
263 active_pile->RemoveRecordingAt(0, 0);
264 active_pile->AddRecordingAt(0, 0);
265
266 std::vector<SkRect>::const_iterator rect_iter = rects.begin();
267 for (tile_iter = tiles.begin(); tile_iter < tiles.end(); tile_iter++) {
268 MockCanvas mock_canvas(1000, 1000);
269 active_pile->PlaybackToSharedCanvas(&mock_canvas,
270 (*tile_iter)->content_rect(), 1.0f);
271
272 // This test verifies that when drawing the contents of a specific tile
273 // at content scale 1.0, the playback canvas never receives content from
274 // neighboring tiles which indicates that the tile grid embedded in
275 // SkPicture is perfectly aligned with the compositor's tiles.
276 EXPECT_EQ(1u, mock_canvas.rects_.size());
277 EXPECT_EQ(*rect_iter, mock_canvas.rects_[0]);
278 rect_iter++;
279 }
280 }
281
282 void TestQuadsForSolidColor(bool test_for_solid); 302 void TestQuadsForSolidColor(bool test_for_solid);
283 303
284 FakeImplProxy proxy_; 304 FakeImplProxy proxy_;
285 TestSharedBitmapManager shared_bitmap_manager_; 305 TestSharedBitmapManager shared_bitmap_manager_;
286 FakeLayerTreeHostImpl host_impl_; 306 FakeLayerTreeHostImpl host_impl_;
307 int root_id_;
287 int id_; 308 int id_;
288 FakePictureLayerImpl* pending_layer_; 309 FakePictureLayerImpl* pending_layer_;
289 FakePictureLayerImpl* old_pending_layer_; 310 FakePictureLayerImpl* old_pending_layer_;
290 FakePictureLayerImpl* active_layer_; 311 FakePictureLayerImpl* active_layer_;
291 312
292 private: 313 private:
293 DISALLOW_COPY_AND_ASSIGN(PictureLayerImplTest); 314 DISALLOW_COPY_AND_ASSIGN(PictureLayerImplTest);
294 }; 315 };
295 316
317 class NoLowResPictureLayerImplTest : public PictureLayerImplTest {
318 public:
319 NoLowResPictureLayerImplTest()
320 : PictureLayerImplTest(NoLowResTilingsSettings()) {}
321 };
322
296 TEST_F(PictureLayerImplTest, TileGridAlignment) { 323 TEST_F(PictureLayerImplTest, TileGridAlignment) {
297 host_impl_.SetDeviceScaleFactor(1.f); 324 // Layer to span 4 raster tiles in x and in y
298 TestTileGridAlignmentCommon(); 325 ImplSidePaintingSettings settings;
299 } 326 gfx::Size layer_size(settings.default_tile_size.width() * 7 / 2,
327 settings.default_tile_size.height() * 7 / 2);
300 328
301 TEST_F(PictureLayerImplTest, TileGridAlignmentHiDPI) { 329 scoped_refptr<FakePicturePileImpl> pending_pile =
302 host_impl_.SetDeviceScaleFactor(2.f); 330 FakePicturePileImpl::CreateFilledPile(layer_size, layer_size);
303 TestTileGridAlignmentCommon(); 331 scoped_refptr<FakePicturePileImpl> active_pile =
332 FakePicturePileImpl::CreateFilledPile(layer_size, layer_size);
333
334 SetupTrees(pending_pile, active_pile);
335
336 // Add 1x1 rects at the centers of each tile, then re-record pile contents
337 active_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting();
338 std::vector<Tile*> tiles =
339 active_layer_->tilings()->tiling_at(0)->AllTilesForTesting();
340 EXPECT_EQ(16u, tiles.size());
341 std::vector<SkRect> rects;
342 std::vector<Tile*>::const_iterator tile_iter;
343 for (tile_iter = tiles.begin(); tile_iter < tiles.end(); tile_iter++) {
344 gfx::Point tile_center = (*tile_iter)->content_rect().CenterPoint();
345 gfx::Rect rect(tile_center.x(), tile_center.y(), 1, 1);
346 active_pile->add_draw_rect(rect);
347 rects.push_back(SkRect::MakeXYWH(rect.x(), rect.y(), 1, 1));
348 }
349 // Force re-raster with newly injected content
350 active_pile->RemoveRecordingAt(0, 0);
351 active_pile->AddRecordingAt(0, 0);
352
353 std::vector<SkRect>::const_iterator rect_iter = rects.begin();
354 for (tile_iter = tiles.begin(); tile_iter < tiles.end(); tile_iter++) {
355 MockCanvas mock_canvas(1000, 1000);
356 active_pile->PlaybackToSharedCanvas(&mock_canvas,
357 (*tile_iter)->content_rect(), 1.0f);
358
359 // This test verifies that when drawing the contents of a specific tile
360 // at content scale 1.0, the playback canvas never receives content from
361 // neighboring tiles which indicates that the tile grid embedded in
362 // SkPicture is perfectly aligned with the compositor's tiles.
363 EXPECT_EQ(1u, mock_canvas.rects_.size());
364 EXPECT_EQ(*rect_iter, mock_canvas.rects_[0]);
365 rect_iter++;
366 }
304 } 367 }
305 368
306 TEST_F(PictureLayerImplTest, CloneNoInvalidation) { 369 TEST_F(PictureLayerImplTest, CloneNoInvalidation) {
307 gfx::Size tile_size(100, 100); 370 gfx::Size tile_size(100, 100);
308 gfx::Size layer_bounds(400, 400); 371 gfx::Size layer_bounds(400, 400);
309 372
310 scoped_refptr<FakePicturePileImpl> pending_pile = 373 scoped_refptr<FakePicturePileImpl> pending_pile =
311 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 374 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
312 scoped_refptr<FakePicturePileImpl> active_pile = 375 scoped_refptr<FakePicturePileImpl> active_pile =
313 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 376 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
314 377
315 SetupTrees(pending_pile, active_pile); 378 SetupTreesWithInvalidation(pending_pile, active_pile, Region());
316
317 Region invalidation;
318 AddDefaultTilingsWithInvalidation(invalidation);
319 379
320 EXPECT_EQ(pending_layer_->tilings()->num_tilings(), 380 EXPECT_EQ(pending_layer_->tilings()->num_tilings(),
321 active_layer_->tilings()->num_tilings()); 381 active_layer_->tilings()->num_tilings());
322 382
323 const PictureLayerTilingSet* tilings = pending_layer_->tilings(); 383 const PictureLayerTilingSet* tilings = pending_layer_->tilings();
324 EXPECT_GT(tilings->num_tilings(), 0u); 384 EXPECT_GT(tilings->num_tilings(), 0u);
325 for (size_t i = 0; i < tilings->num_tilings(); ++i) 385 for (size_t i = 0; i < tilings->num_tilings(); ++i)
326 VerifyAllTilesExistAndHavePile(tilings->tiling_at(i), active_pile.get()); 386 VerifyAllTilesExistAndHavePile(tilings->tiling_at(i), pending_pile.get());
327 } 387 }
328 388
329 TEST_F(PictureLayerImplTest, ExternalViewportRectForPrioritizingTiles) { 389 TEST_F(PictureLayerImplTest, ExternalViewportRectForPrioritizingTiles) {
330 base::TimeTicks time_ticks; 390 base::TimeTicks time_ticks;
331 time_ticks += base::TimeDelta::FromMilliseconds(1); 391 time_ticks += base::TimeDelta::FromMilliseconds(1);
332 host_impl_.SetCurrentBeginFrameArgs( 392 host_impl_.SetCurrentBeginFrameArgs(
333 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks)); 393 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
334 gfx::Size tile_size(100, 100); 394 gfx::Size tile_size(100, 100);
335 gfx::Size layer_bounds(400, 400); 395 gfx::Size layer_bounds(400, 400);
336 396
337 scoped_refptr<FakePicturePileImpl> pending_pile = 397 scoped_refptr<FakePicturePileImpl> pending_pile =
338 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 398 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
339 scoped_refptr<FakePicturePileImpl> active_pile = 399 scoped_refptr<FakePicturePileImpl> active_pile =
340 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 400 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
341 401
342 SetupTrees(pending_pile, active_pile); 402 SetupTreesWithInvalidation(pending_pile, active_pile, Region());
343 403
344 Region invalidation;
345 AddDefaultTilingsWithInvalidation(invalidation);
346 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, 1.f, 1.f, 1.f, false); 404 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, 1.f, 1.f, 1.f, false);
347 405
348 time_ticks += base::TimeDelta::FromMilliseconds(200); 406 time_ticks += base::TimeDelta::FromMilliseconds(200);
349 host_impl_.SetCurrentBeginFrameArgs( 407 host_impl_.SetCurrentBeginFrameArgs(
350 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks)); 408 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
351 409
352 // Update tiles with viewport for tile priority as (0, 0, 100, 100) and the 410 // Update tiles with viewport for tile priority as (0, 0, 100, 100) and the
353 // identify transform for tile priority. 411 // identify transform for tile priority.
354 bool resourceless_software_draw = false; 412 bool resourceless_software_draw = false;
355 gfx::Rect viewport = gfx::Rect(layer_bounds), 413 gfx::Rect viewport = gfx::Rect(layer_bounds),
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks)); 487 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
430 488
431 gfx::Size tile_size(100, 100); 489 gfx::Size tile_size(100, 100);
432 gfx::Size layer_bounds(400, 400); 490 gfx::Size layer_bounds(400, 400);
433 491
434 scoped_refptr<FakePicturePileImpl> pending_pile = 492 scoped_refptr<FakePicturePileImpl> pending_pile =
435 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 493 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
436 scoped_refptr<FakePicturePileImpl> active_pile = 494 scoped_refptr<FakePicturePileImpl> active_pile =
437 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 495 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
438 496
439 SetupTrees(pending_pile, active_pile); 497 SetupTreesWithInvalidation(pending_pile, active_pile, Region());
440 498
441 Region invalidation;
442 AddDefaultTilingsWithInvalidation(invalidation);
443 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, 1.f, 1.f, 1.f, false); 499 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, 1.f, 1.f, 1.f, false);
444 500
445 // UpdateTiles with valid viewport. Should update tile viewport. 501 // UpdateTiles with valid viewport. Should update tile viewport.
446 // Note viewport is considered invalid if and only if in resourceless 502 // Note viewport is considered invalid if and only if in resourceless
447 // software draw. 503 // software draw.
448 bool resourceless_software_draw = false; 504 bool resourceless_software_draw = false;
449 gfx::Rect viewport = gfx::Rect(layer_bounds); 505 gfx::Rect viewport = gfx::Rect(layer_bounds);
450 gfx::Transform transform; 506 gfx::Transform transform;
451 host_impl_.SetExternalDrawConstraints(transform, 507 host_impl_.SetExternalDrawConstraints(transform,
452 viewport, 508 viewport,
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 565
510 TEST_F(PictureLayerImplTest, ClonePartialInvalidation) { 566 TEST_F(PictureLayerImplTest, ClonePartialInvalidation) {
511 gfx::Size tile_size(100, 100); 567 gfx::Size tile_size(100, 100);
512 gfx::Size layer_bounds(400, 400); 568 gfx::Size layer_bounds(400, 400);
513 gfx::Rect layer_invalidation(150, 200, 30, 180); 569 gfx::Rect layer_invalidation(150, 200, 30, 180);
514 570
515 scoped_refptr<FakePicturePileImpl> pending_pile = 571 scoped_refptr<FakePicturePileImpl> pending_pile =
516 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 572 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
517 scoped_refptr<FakePicturePileImpl> active_pile = 573 scoped_refptr<FakePicturePileImpl> active_pile =
518 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 574 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
575 scoped_refptr<FakePicturePileImpl> lost_pile =
576 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
519 577
520 SetupTrees(pending_pile, active_pile); 578 SetupPendingTreeWithFixedTileSize(lost_pile, gfx::Size(50, 50), Region());
579 ActivateTree();
580 // Add a non-shared tiling on the active tree.
581 PictureLayerTiling* tiling = active_layer_->AddTiling(3.f);
582 tiling->CreateAllTilesForTesting();
583 // Then setup a new pending tree and activate it.
584 SetupTreesWithFixedTileSize(pending_pile, active_pile, gfx::Size(50, 50),
585 layer_invalidation);
521 586
522 Region invalidation(layer_invalidation); 587 EXPECT_EQ(2u, pending_layer_->num_tilings());
523 AddDefaultTilingsWithInvalidation(invalidation); 588 EXPECT_EQ(3u, active_layer_->num_tilings());
524 589
525 const PictureLayerTilingSet* tilings = pending_layer_->tilings(); 590 const PictureLayerTilingSet* tilings = pending_layer_->tilings();
526 EXPECT_GT(tilings->num_tilings(), 0u); 591 EXPECT_GT(tilings->num_tilings(), 0u);
527 for (size_t i = 0; i < tilings->num_tilings(); ++i) { 592 for (size_t i = 0; i < tilings->num_tilings(); ++i) {
528 const PictureLayerTiling* tiling = tilings->tiling_at(i); 593 const PictureLayerTiling* tiling = tilings->tiling_at(i);
529 gfx::Rect content_invalidation = gfx::ScaleToEnclosingRect( 594 gfx::Rect content_invalidation = gfx::ScaleToEnclosingRect(
530 layer_invalidation, 595 layer_invalidation,
531 tiling->contents_scale()); 596 tiling->contents_scale());
532 for (PictureLayerTiling::CoverageIterator iter( 597 for (PictureLayerTiling::CoverageIterator iter(
533 tiling, 598 tiling,
534 tiling->contents_scale(), 599 tiling->contents_scale(),
535 gfx::Rect(tiling->tiling_size())); 600 gfx::Rect(tiling->tiling_size()));
536 iter; 601 iter;
537 ++iter) { 602 ++iter) {
538 EXPECT_TRUE(*iter); 603 EXPECT_TRUE(*iter);
539 EXPECT_FALSE(iter.geometry_rect().IsEmpty()); 604 EXPECT_FALSE(iter.geometry_rect().IsEmpty());
540 if (iter.geometry_rect().Intersects(content_invalidation)) 605 EXPECT_EQ(pending_pile.get(), iter->raster_source());
541 EXPECT_EQ(pending_pile.get(), iter->raster_source());
542 else
543 EXPECT_EQ(active_pile.get(), iter->raster_source());
544 } 606 }
545 } 607 }
546 }
547 608
548 TEST_F(PictureLayerImplTest, CloneFullInvalidation) { 609 tilings = active_layer_->tilings();
549 gfx::Size tile_size(90, 80);
550 gfx::Size layer_bounds(300, 500);
551
552 scoped_refptr<FakePicturePileImpl> pending_pile =
553 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
554 scoped_refptr<FakePicturePileImpl> active_pile =
555 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
556
557 SetupTrees(pending_pile, active_pile);
558
559 Region invalidation((gfx::Rect(layer_bounds)));
560 AddDefaultTilingsWithInvalidation(invalidation);
561
562 EXPECT_EQ(pending_layer_->tilings()->num_tilings(),
563 active_layer_->tilings()->num_tilings());
564
565 const PictureLayerTilingSet* tilings = pending_layer_->tilings();
566 EXPECT_GT(tilings->num_tilings(), 0u);
567 for (size_t i = 0; i < tilings->num_tilings(); ++i)
568 VerifyAllTilesExistAndHavePile(tilings->tiling_at(i), pending_pile.get());
569 }
570
571 TEST_F(PictureLayerImplTest, NoInvalidationBoundsChange) {
572 gfx::Size tile_size(90, 80);
573 gfx::Size active_layer_bounds(300, 500);
574 gfx::Size pending_layer_bounds(400, 800);
575
576 scoped_refptr<FakePicturePileImpl> pending_pile =
577 FakePicturePileImpl::CreateFilledPile(tile_size,
578 pending_layer_bounds);
579 scoped_refptr<FakePicturePileImpl> active_pile =
580 FakePicturePileImpl::CreateFilledPile(tile_size, active_layer_bounds);
581
582 SetupTrees(pending_pile, active_pile);
583 pending_layer_->set_fixed_tile_size(gfx::Size(100, 100));
584
585 Region invalidation;
586 AddDefaultTilingsWithInvalidation(invalidation);
587
588 const PictureLayerTilingSet* tilings = pending_layer_->tilings();
589 EXPECT_GT(tilings->num_tilings(), 0u); 610 EXPECT_GT(tilings->num_tilings(), 0u);
590 for (size_t i = 0; i < tilings->num_tilings(); ++i) { 611 for (size_t i = 0; i < tilings->num_tilings(); ++i) {
591 const PictureLayerTiling* tiling = tilings->tiling_at(i); 612 const PictureLayerTiling* tiling = tilings->tiling_at(i);
592 gfx::Rect active_content_bounds = gfx::ScaleToEnclosingRect( 613 gfx::Rect content_invalidation =
593 gfx::Rect(active_layer_bounds), 614 gfx::ScaleToEnclosingRect(layer_invalidation, tiling->contents_scale());
594 tiling->contents_scale());
595 for (PictureLayerTiling::CoverageIterator iter( 615 for (PictureLayerTiling::CoverageIterator iter(
596 tiling, 616 tiling,
597 tiling->contents_scale(), 617 tiling->contents_scale(),
598 gfx::Rect(tiling->tiling_size())); 618 gfx::Rect(tiling->tiling_size()));
599 iter; 619 iter;
600 ++iter) { 620 ++iter) {
601 EXPECT_TRUE(*iter); 621 EXPECT_TRUE(*iter);
602 EXPECT_FALSE(iter.geometry_rect().IsEmpty()); 622 EXPECT_FALSE(iter.geometry_rect().IsEmpty());
603 std::vector<Tile*> active_tiles = 623 if (iter.geometry_rect().Intersects(content_invalidation))
604 active_layer_->tilings()->tiling_at(i)->AllTilesForTesting(); 624 EXPECT_EQ(active_pile.get(), iter->raster_source());
605 std::vector<Tile*> pending_tiles = tiling->AllTilesForTesting(); 625 else if (!active_layer_->GetPendingOrActiveTwinTiling(tiling))
606 if (iter.geometry_rect().right() >= active_content_bounds.width() || 626 EXPECT_EQ(active_pile.get(), iter->raster_source());
607 iter.geometry_rect().bottom() >= active_content_bounds.height() || 627 else
608 active_tiles[0]->content_rect().size() !=
609 pending_tiles[0]->content_rect().size()) {
610 EXPECT_EQ(pending_pile.get(), iter->raster_source()); 628 EXPECT_EQ(pending_pile.get(), iter->raster_source());
611 } else {
612 EXPECT_EQ(active_pile.get(), iter->raster_source());
613 }
614 } 629 }
615 } 630 }
616 } 631 }
617 632
618 TEST_F(PictureLayerImplTest, AddTilesFromNewRecording) { 633 TEST_F(PictureLayerImplTest, CloneFullInvalidation) {
619 gfx::Size tile_size(400, 400); 634 gfx::Size tile_size(90, 80);
620 gfx::Size layer_bounds(1300, 1900); 635 gfx::Size layer_bounds(300, 500);
621 636
622 scoped_refptr<FakePicturePileImpl> pending_pile = 637 scoped_refptr<FakePicturePileImpl> pending_pile =
623 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); 638 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
624 scoped_refptr<FakePicturePileImpl> active_pile = 639 scoped_refptr<FakePicturePileImpl> active_pile =
625 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); 640 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
626 641
627 // Fill in some of active pile, but more of pending pile. 642 SetupTreesWithInvalidation(pending_pile, active_pile,
628 int hole_count = 0; 643 gfx::Rect(layer_bounds));
629 for (int x = 0; x < active_pile->tiling().num_tiles_x(); ++x) {
630 for (int y = 0; y < active_pile->tiling().num_tiles_y(); ++y) {
631 if ((x + y) % 2) {
632 pending_pile->AddRecordingAt(x, y);
633 active_pile->AddRecordingAt(x, y);
634 } else {
635 hole_count++;
636 if (hole_count % 2)
637 pending_pile->AddRecordingAt(x, y);
638 }
639 }
640 }
641 644
642 SetupTrees(pending_pile, active_pile); 645 EXPECT_EQ(pending_layer_->tilings()->num_tilings(),
643 Region invalidation; 646 active_layer_->tilings()->num_tilings());
644 AddDefaultTilingsWithInvalidation(invalidation);
645 647
646 const PictureLayerTilingSet* tilings = pending_layer_->tilings(); 648 const PictureLayerTilingSet* tilings = pending_layer_->tilings();
647 EXPECT_GT(tilings->num_tilings(), 0u); 649 EXPECT_GT(tilings->num_tilings(), 0u);
648 for (size_t i = 0; i < tilings->num_tilings(); ++i) { 650 for (size_t i = 0; i < tilings->num_tilings(); ++i)
649 const PictureLayerTiling* tiling = tilings->tiling_at(i); 651 VerifyAllTilesExistAndHavePile(tilings->tiling_at(i), pending_pile.get());
650
651 for (PictureLayerTiling::CoverageIterator iter(
652 tiling,
653 tiling->contents_scale(),
654 gfx::Rect(tiling->tiling_size()));
655 iter;
656 ++iter) {
657 EXPECT_FALSE(iter.full_tile_geometry_rect().IsEmpty());
658 // Ensure there is a recording for this tile.
659 bool in_pending = pending_pile->CoversRect(iter.full_tile_geometry_rect(),
660 tiling->contents_scale());
661 bool in_active = active_pile->CoversRect(iter.full_tile_geometry_rect(),
662 tiling->contents_scale());
663
664 if (in_pending && !in_active)
665 EXPECT_EQ(pending_pile.get(), iter->raster_source());
666 else if (in_active)
667 EXPECT_EQ(active_pile.get(), iter->raster_source());
668 else
669 EXPECT_FALSE(*iter);
670 }
671 }
672 }
673
674 TEST_F(PictureLayerImplTest, ManageTilingsWithNoRecording) {
675 gfx::Size tile_size(400, 400);
676 gfx::Size layer_bounds(1300, 1900);
677
678 scoped_refptr<FakePicturePileImpl> pending_pile =
679 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds);
680 scoped_refptr<FakePicturePileImpl> active_pile =
681 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds);
682
683 SetupTrees(pending_pile, active_pile);
684
685 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.f, 1.f, 1.f, 1.f, false);
686
687 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
688 } 652 }
689 653
690 TEST_F(PictureLayerImplTest, ManageTilingsCreatesTilings) { 654 TEST_F(PictureLayerImplTest, ManageTilingsCreatesTilings) {
691 gfx::Size tile_size(400, 400); 655 gfx::Size tile_size(400, 400);
692 gfx::Size layer_bounds(1300, 1900); 656 gfx::Size layer_bounds(1300, 1900);
693 657
658 scoped_refptr<FakePicturePileImpl> pending_pile =
659 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
660 scoped_refptr<FakePicturePileImpl> active_pile =
661 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
662
663 SetupTrees(pending_pile, active_pile);
664
665 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
666 EXPECT_LT(low_res_factor, 1.f);
667
668 active_layer_->ReleaseResources();
669 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
670
671 SetupDrawPropertiesAndUpdateTiles(active_layer_,
672 6.f, // ideal contents scale
673 3.f, // device scale
674 2.f, // page scale
675 1.f, // maximum animation scale
676 false);
677 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
678 EXPECT_FLOAT_EQ(6.f,
679 active_layer_->tilings()->tiling_at(0)->contents_scale());
680 EXPECT_FLOAT_EQ(6.f * low_res_factor,
681 active_layer_->tilings()->tiling_at(1)->contents_scale());
682
683 // If we change the page scale factor, then we should get new tilings.
684 SetupDrawPropertiesAndUpdateTiles(active_layer_,
685 6.6f, // ideal contents scale
686 3.f, // device scale
687 2.2f, // page scale
688 1.f, // maximum animation scale
689 false);
690 ASSERT_EQ(4u, active_layer_->tilings()->num_tilings());
691 EXPECT_FLOAT_EQ(6.6f,
692 active_layer_->tilings()->tiling_at(0)->contents_scale());
693 EXPECT_FLOAT_EQ(6.6f * low_res_factor,
694 active_layer_->tilings()->tiling_at(2)->contents_scale());
695
696 // If we change the device scale factor, then we should get new tilings.
697 SetupDrawPropertiesAndUpdateTiles(active_layer_,
698 7.26f, // ideal contents scale
699 3.3f, // device scale
700 2.2f, // page scale
701 1.f, // maximum animation scale
702 false);
703 ASSERT_EQ(6u, active_layer_->tilings()->num_tilings());
704 EXPECT_FLOAT_EQ(7.26f,
705 active_layer_->tilings()->tiling_at(0)->contents_scale());
706 EXPECT_FLOAT_EQ(7.26f * low_res_factor,
707 active_layer_->tilings()->tiling_at(3)->contents_scale());
708
709 // If we change the device scale factor, but end up at the same total scale
710 // factor somehow, then we don't get new tilings.
711 SetupDrawPropertiesAndUpdateTiles(active_layer_,
712 7.26f, // ideal contents scale
713 2.2f, // device scale
714 3.3f, // page scale
715 1.f, // maximum animation scale
716 false);
717 ASSERT_EQ(6u, active_layer_->tilings()->num_tilings());
718 EXPECT_FLOAT_EQ(7.26f,
719 active_layer_->tilings()->tiling_at(0)->contents_scale());
720 EXPECT_FLOAT_EQ(7.26f * low_res_factor,
721 active_layer_->tilings()->tiling_at(3)->contents_scale());
722 }
723
724 TEST_F(PictureLayerImplTest, PendingLayerOnlyHasHighAndLowResTiling) {
725 gfx::Size tile_size(400, 400);
726 gfx::Size layer_bounds(1300, 1900);
727
694 scoped_refptr<FakePicturePileImpl> pending_pile = 728 scoped_refptr<FakePicturePileImpl> pending_pile =
695 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 729 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
696 scoped_refptr<FakePicturePileImpl> active_pile = 730 scoped_refptr<FakePicturePileImpl> active_pile =
697 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 731 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
698 732
699 SetupTrees(pending_pile, active_pile); 733 SetupTrees(pending_pile, active_pile);
700 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
701 734
702 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; 735 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
703 EXPECT_LT(low_res_factor, 1.f); 736 EXPECT_LT(low_res_factor, 1.f);
704 737
738 pending_layer_->ReleaseResources();
739 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
740
705 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 741 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
706 6.f, // ideal contents scale 742 6.f, // ideal contents scale
707 3.f, // device scale 743 3.f, // device scale
708 2.f, // page scale 744 2.f, // page scale
709 1.f, // maximum animation scale 745 1.f, // maximum animation scale
710 false); 746 false);
711 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); 747 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
712 EXPECT_FLOAT_EQ(6.f, 748 EXPECT_FLOAT_EQ(6.f,
713 pending_layer_->tilings()->tiling_at(0)->contents_scale()); 749 pending_layer_->tilings()->tiling_at(0)->contents_scale());
714 EXPECT_FLOAT_EQ(6.f * low_res_factor, 750 EXPECT_FLOAT_EQ(6.f * low_res_factor,
715 pending_layer_->tilings()->tiling_at(1)->contents_scale()); 751 pending_layer_->tilings()->tiling_at(1)->contents_scale());
716 752
717 // If we change the page scale factor, then we should get new tilings. 753 // If we change the page scale factor, then we should get new tilings.
718 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 754 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
719 6.6f, // ideal contents scale 755 6.6f, // ideal contents scale
720 3.f, // device scale 756 3.f, // device scale
721 2.2f, // page scale 757 2.2f, // page scale
722 1.f, // maximum animation scale 758 1.f, // maximum animation scale
723 false); 759 false);
724 ASSERT_EQ(4u, pending_layer_->tilings()->num_tilings()); 760 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
725 EXPECT_FLOAT_EQ(6.6f, 761 EXPECT_FLOAT_EQ(6.6f,
726 pending_layer_->tilings()->tiling_at(0)->contents_scale()); 762 pending_layer_->tilings()->tiling_at(0)->contents_scale());
727 EXPECT_FLOAT_EQ(6.6f * low_res_factor, 763 EXPECT_FLOAT_EQ(6.6f * low_res_factor,
728 pending_layer_->tilings()->tiling_at(2)->contents_scale()); 764 pending_layer_->tilings()->tiling_at(1)->contents_scale());
729 765
730 // If we change the device scale factor, then we should get new tilings. 766 // If we change the device scale factor, then we should get new tilings.
731 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 767 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
732 7.26f, // ideal contents scale 768 7.26f, // ideal contents scale
733 3.3f, // device scale 769 3.3f, // device scale
734 2.2f, // page scale 770 2.2f, // page scale
735 1.f, // maximum animation scale 771 1.f, // maximum animation scale
736 false); 772 false);
737 ASSERT_EQ(6u, pending_layer_->tilings()->num_tilings()); 773 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
738 EXPECT_FLOAT_EQ(7.26f, 774 EXPECT_FLOAT_EQ(7.26f,
739 pending_layer_->tilings()->tiling_at(0)->contents_scale()); 775 pending_layer_->tilings()->tiling_at(0)->contents_scale());
740 EXPECT_FLOAT_EQ(7.26f * low_res_factor, 776 EXPECT_FLOAT_EQ(7.26f * low_res_factor,
741 pending_layer_->tilings()->tiling_at(3)->contents_scale()); 777 pending_layer_->tilings()->tiling_at(1)->contents_scale());
742 778
743 // If we change the device scale factor, but end up at the same total scale 779 // If we change the device scale factor, but end up at the same total scale
744 // factor somehow, then we don't get new tilings. 780 // factor somehow, then we don't get new tilings.
745 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 781 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
746 7.26f, // ideal contents scale 782 7.26f, // ideal contents scale
747 2.2f, // device scale 783 2.2f, // device scale
748 3.3f, // page scale 784 3.3f, // page scale
749 1.f, // maximum animation scale 785 1.f, // maximum animation scale
750 false); 786 false);
751 ASSERT_EQ(6u, pending_layer_->tilings()->num_tilings()); 787 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
752 EXPECT_FLOAT_EQ(7.26f, 788 EXPECT_FLOAT_EQ(7.26f,
753 pending_layer_->tilings()->tiling_at(0)->contents_scale()); 789 pending_layer_->tilings()->tiling_at(0)->contents_scale());
754 EXPECT_FLOAT_EQ(7.26f * low_res_factor, 790 EXPECT_FLOAT_EQ(7.26f * low_res_factor,
755 pending_layer_->tilings()->tiling_at(3)->contents_scale()); 791 pending_layer_->tilings()->tiling_at(1)->contents_scale());
756 } 792 }
757 793
758 TEST_F(PictureLayerImplTest, CreateTilingsEvenIfTwinHasNone) { 794 TEST_F(PictureLayerImplTest, CreateTilingsEvenIfTwinHasNone) {
759 // This test makes sure that if a layer can have tilings, then a commit makes 795 // This test makes sure that if a layer can have tilings, then a commit makes
760 // it not able to have tilings (empty size), and then a future commit that 796 // it not able to have tilings (empty size), and then a future commit that
761 // makes it valid again should be able to create tilings. 797 // makes it valid again should be able to create tilings.
762 gfx::Size tile_size(400, 400); 798 gfx::Size tile_size(400, 400);
763 gfx::Size layer_bounds(1300, 1900); 799 gfx::Size layer_bounds(1300, 1900);
764 800
765 scoped_refptr<FakePicturePileImpl> empty_pile = 801 scoped_refptr<FakePicturePileImpl> empty_pile =
766 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); 802 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds);
767 scoped_refptr<FakePicturePileImpl> valid_pile = 803 scoped_refptr<FakePicturePileImpl> valid_pile =
768 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 804 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
769 805
770 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
771 EXPECT_LT(low_res_factor, 1.f);
772
773 float high_res_scale = 1.3f;
774 float low_res_scale = high_res_scale * low_res_factor;
775 float device_scale = 1.7f;
776 float page_scale = 3.2f;
777 float maximum_animation_scale = 1.f;
778
779 SetupPendingTree(valid_pile); 806 SetupPendingTree(valid_pile);
780 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
781 high_res_scale,
782 device_scale,
783 page_scale,
784 maximum_animation_scale,
785 false);
786 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); 807 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
787 EXPECT_FLOAT_EQ(high_res_scale,
788 pending_layer_->HighResTiling()->contents_scale());
789 EXPECT_FLOAT_EQ(low_res_scale,
790 pending_layer_->LowResTiling()->contents_scale());
791 808
792 ActivateTree(); 809 ActivateTree();
793 SetupPendingTree(empty_pile); 810 SetupPendingTree(empty_pile);
794 EXPECT_FALSE(pending_layer_->CanHaveTilings()); 811 EXPECT_FALSE(pending_layer_->CanHaveTilings());
795 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
796 high_res_scale,
797 device_scale,
798 page_scale,
799 maximum_animation_scale,
800 false);
801 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); 812 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
802 ASSERT_EQ(0u, pending_layer_->tilings()->num_tilings()); 813 ASSERT_EQ(0u, pending_layer_->tilings()->num_tilings());
803 814
804 ActivateTree(); 815 ActivateTree();
805 EXPECT_FALSE(active_layer_->CanHaveTilings()); 816 EXPECT_FALSE(active_layer_->CanHaveTilings());
806 SetupDrawPropertiesAndUpdateTiles(active_layer_,
807 high_res_scale,
808 device_scale,
809 page_scale,
810 maximum_animation_scale,
811 false);
812 ASSERT_EQ(0u, active_layer_->tilings()->num_tilings()); 817 ASSERT_EQ(0u, active_layer_->tilings()->num_tilings());
813 818
814 SetupPendingTree(valid_pile); 819 SetupPendingTree(valid_pile);
815 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
816 high_res_scale,
817 device_scale,
818 page_scale,
819 maximum_animation_scale,
820 false);
821 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); 820 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
822 ASSERT_EQ(0u, active_layer_->tilings()->num_tilings()); 821 ASSERT_EQ(0u, active_layer_->tilings()->num_tilings());
823 EXPECT_FLOAT_EQ(high_res_scale,
824 pending_layer_->HighResTiling()->contents_scale());
825 EXPECT_FLOAT_EQ(low_res_scale,
826 pending_layer_->LowResTiling()->contents_scale());
827 } 822 }
828 823
829 TEST_F(PictureLayerImplTest, ZoomOutCrash) { 824 TEST_F(PictureLayerImplTest, ZoomOutCrash) {
830 gfx::Size tile_size(400, 400); 825 gfx::Size tile_size(400, 400);
831 gfx::Size layer_bounds(1300, 1900); 826 gfx::Size layer_bounds(1300, 1900);
832 827
833 // Set up the high and low res tilings before pinch zoom. 828 // Set up the high and low res tilings before pinch zoom.
834 scoped_refptr<FakePicturePileImpl> pending_pile = 829 scoped_refptr<FakePicturePileImpl> pending_pile =
835 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 830 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
836 scoped_refptr<FakePicturePileImpl> active_pile = 831 scoped_refptr<FakePicturePileImpl> active_pile =
837 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 832 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
838 833
839 SetupTrees(pending_pile, active_pile); 834 SetupTrees(pending_pile, active_pile);
835 ResetTilingsAndRasterScales();
840 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings()); 836 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
841 SetContentsScaleOnBothLayers(32.0f, 1.0f, 32.0f, 1.0f, false); 837 SetContentsScaleOnBothLayers(32.0f, 1.0f, 32.0f, 1.0f, false);
838 EXPECT_EQ(32.f, active_layer_->HighResTiling()->contents_scale());
842 host_impl_.PinchGestureBegin(); 839 host_impl_.PinchGestureBegin();
843 SetContentsScaleOnBothLayers(1.0f, 1.0f, 1.0f, 1.0f, false); 840 SetContentsScaleOnBothLayers(1.0f, 1.0f, 1.0f, 1.0f, false);
844 SetContentsScaleOnBothLayers(1.0f, 1.0f, 1.0f, 1.0f, false); 841 SetContentsScaleOnBothLayers(1.0f, 1.0f, 1.0f, 1.0f, false);
845 EXPECT_EQ(active_layer_->tilings()->NumHighResTilings(), 1); 842 EXPECT_EQ(active_layer_->tilings()->NumHighResTilings(), 1);
846 } 843 }
847 844
848 TEST_F(PictureLayerImplTest, PinchGestureTilings) { 845 TEST_F(PictureLayerImplTest, PinchGestureTilings) {
849 gfx::Size tile_size(400, 400); 846 gfx::Size tile_size(400, 400);
850 gfx::Size layer_bounds(1300, 1900); 847 gfx::Size layer_bounds(1300, 1900);
851 848
849 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
850
852 scoped_refptr<FakePicturePileImpl> pending_pile = 851 scoped_refptr<FakePicturePileImpl> pending_pile =
853 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 852 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
854 scoped_refptr<FakePicturePileImpl> active_pile = 853 scoped_refptr<FakePicturePileImpl> active_pile =
855 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 854 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
856 855
857 // Set up the high and low res tilings before pinch zoom. 856 // Set up the high and low res tilings before pinch zoom.
858 SetupTrees(pending_pile, active_pile); 857 SetupTrees(pending_pile, active_pile);
859 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings()); 858 ResetTilingsAndRasterScales();
860 SetContentsScaleOnBothLayers(2.0f, 1.0f, 1.0f, 1.0f, false); 859
861 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; 860 SetContentsScaleOnBothLayers(2.f, 1.0f, 2.f, 1.0f, false);
862 EXPECT_EQ(2u, active_layer_->tilings()->num_tilings()); 861 EXPECT_BOTH_EQ(num_tilings(), 2u);
863 EXPECT_FLOAT_EQ(2.0f, 862 EXPECT_BOTH_EQ(tilings()->tiling_at(0)->contents_scale(), 2.f);
864 active_layer_->tilings()->tiling_at(0)->contents_scale()); 863 EXPECT_BOTH_EQ(tilings()->tiling_at(1)->contents_scale(),
865 EXPECT_FLOAT_EQ(2.0f * low_res_factor, 864 2.f * low_res_factor);
866 active_layer_->tilings()->tiling_at(1)->contents_scale());
867 865
868 // Start a pinch gesture. 866 // Start a pinch gesture.
869 host_impl_.PinchGestureBegin(); 867 host_impl_.PinchGestureBegin();
870 868
871 // Zoom out by a small amount. We should create a tiling at half 869 // Zoom out by a small amount. We should create a tiling at half
872 // the scale (2/kMaxScaleRatioDuringPinch). 870 // the scale (2/kMaxScaleRatioDuringPinch).
873 SetContentsScaleOnBothLayers(1.8f, 1.0f, 0.9f, 1.0f, false); 871 SetContentsScaleOnBothLayers(1.8f, 1.0f, 1.8f, 1.0f, false);
874 EXPECT_EQ(3u, active_layer_->tilings()->num_tilings()); 872 EXPECT_EQ(3u, active_layer_->tilings()->num_tilings());
875 EXPECT_FLOAT_EQ(2.0f, 873 EXPECT_FLOAT_EQ(2.0f,
876 active_layer_->tilings()->tiling_at(0)->contents_scale()); 874 active_layer_->tilings()->tiling_at(0)->contents_scale());
877 EXPECT_FLOAT_EQ(1.0f, 875 EXPECT_FLOAT_EQ(1.0f,
878 active_layer_->tilings()->tiling_at(1)->contents_scale()); 876 active_layer_->tilings()->tiling_at(1)->contents_scale());
879 EXPECT_FLOAT_EQ(2.0f * low_res_factor, 877 EXPECT_FLOAT_EQ(2.0f * low_res_factor,
880 active_layer_->tilings()->tiling_at(2)->contents_scale()); 878 active_layer_->tilings()->tiling_at(2)->contents_scale());
881 879
882 // Zoom out further, close to our low-res scale factor. We should 880 // Zoom out further, close to our low-res scale factor. We should
883 // use that tiling as high-res, and not create a new tiling. 881 // use that tiling as high-res, and not create a new tiling.
884 SetContentsScaleOnBothLayers(low_res_factor * 2.1f, 1.0f, 882 SetContentsScaleOnBothLayers(low_res_factor * 2.1f, 1.0f,
885 low_res_factor * 2.1f, 1.0f, false); 883 low_res_factor * 2.1f, 1.0f, false);
886 EXPECT_EQ(3u, active_layer_->tilings()->num_tilings()); 884 EXPECT_EQ(3u, active_layer_->tilings()->num_tilings());
887 885
888 // Zoom in a lot now. Since we increase by increments of 886 // Zoom in a lot now. Since we increase by increments of
889 // kMaxScaleRatioDuringPinch, this will create a new tiling at 4.0. 887 // kMaxScaleRatioDuringPinch, this will create a new tiling at 4.0.
890 SetContentsScaleOnBothLayers(3.8f, 1.0f, 2.1f, 1.f, false); 888 SetContentsScaleOnBothLayers(3.8f, 1.0f, 3.8f, 1.f, false);
891 EXPECT_EQ(4u, active_layer_->tilings()->num_tilings()); 889 EXPECT_EQ(4u, active_layer_->tilings()->num_tilings());
892 EXPECT_FLOAT_EQ(4.0f, 890 EXPECT_FLOAT_EQ(4.0f,
893 active_layer_->tilings()->tiling_at(0)->contents_scale()); 891 active_layer_->tilings()->tiling_at(0)->contents_scale());
894 } 892 }
895 893
896 TEST_F(PictureLayerImplTest, SnappedTilingDuringZoom) { 894 TEST_F(PictureLayerImplTest, SnappedTilingDuringZoom) {
897 gfx::Size tile_size(300, 300); 895 gfx::Size tile_size(300, 300);
898 gfx::Size layer_bounds(2600, 3800); 896 gfx::Size layer_bounds(2600, 3800);
899 897
900 scoped_refptr<FakePicturePileImpl> pending_pile = 898 scoped_refptr<FakePicturePileImpl> pending_pile =
901 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 899 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
902 scoped_refptr<FakePicturePileImpl> active_pile = 900 scoped_refptr<FakePicturePileImpl> active_pile =
903 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 901 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
904 902
903 SetupTrees(pending_pile, active_pile);
904
905 ResetTilingsAndRasterScales();
906 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
907
905 // Set up the high and low res tilings before pinch zoom. 908 // Set up the high and low res tilings before pinch zoom.
906 SetupTrees(pending_pile, active_pile);
907 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
908 SetContentsScaleOnBothLayers(0.24f, 1.0f, 0.24f, 1.0f, false); 909 SetContentsScaleOnBothLayers(0.24f, 1.0f, 0.24f, 1.0f, false);
909 EXPECT_EQ(2u, active_layer_->tilings()->num_tilings()); 910 EXPECT_EQ(2u, active_layer_->tilings()->num_tilings());
910 EXPECT_FLOAT_EQ(0.24f, 911 EXPECT_FLOAT_EQ(0.24f,
911 active_layer_->tilings()->tiling_at(0)->contents_scale()); 912 active_layer_->tilings()->tiling_at(0)->contents_scale());
912 EXPECT_FLOAT_EQ(0.0625f, 913 EXPECT_FLOAT_EQ(0.0625f,
913 active_layer_->tilings()->tiling_at(1)->contents_scale()); 914 active_layer_->tilings()->tiling_at(1)->contents_scale());
914 915
915 // Start a pinch gesture. 916 // Start a pinch gesture.
916 host_impl_.PinchGestureBegin(); 917 host_impl_.PinchGestureBegin();
917 918
(...skipping 30 matching lines...) Expand all
948 gfx::Size tile_size(400, 400); 949 gfx::Size tile_size(400, 400);
949 gfx::Size layer_bounds(1300, 1900); 950 gfx::Size layer_bounds(1300, 1900);
950 951
951 scoped_refptr<FakePicturePileImpl> pending_pile = 952 scoped_refptr<FakePicturePileImpl> pending_pile =
952 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 953 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
953 scoped_refptr<FakePicturePileImpl> active_pile = 954 scoped_refptr<FakePicturePileImpl> active_pile =
954 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 955 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
955 956
956 std::vector<PictureLayerTiling*> used_tilings; 957 std::vector<PictureLayerTiling*> used_tilings;
957 958
958 SetupTrees(pending_pile, active_pile);
959 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
960
961 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; 959 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
962 EXPECT_LT(low_res_factor, 1.f); 960 EXPECT_LT(low_res_factor, 1.f);
963 961
964 float device_scale = 1.7f;
965 float page_scale = 3.2f;
966 float scale = 1.f; 962 float scale = 1.f;
963 float page_scale = 1.f;
967 964
968 SetContentsScaleOnBothLayers(scale, device_scale, page_scale, 1.f, false); 965 SetupTrees(pending_pile, active_pile);
969 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); 966 EXPECT_EQ(2u, active_layer_->tilings()->num_tilings());
967 EXPECT_EQ(1.f, active_layer_->HighResTiling()->contents_scale());
970 968
971 // We only have ideal tilings, so they aren't removed. 969 // We only have ideal tilings, so they aren't removed.
972 used_tilings.clear(); 970 used_tilings.clear();
973 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); 971 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
974 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); 972 EXPECT_EQ(2u, active_layer_->tilings()->num_tilings());
975 973
976 host_impl_.PinchGestureBegin(); 974 host_impl_.PinchGestureBegin();
977 975
978 // Changing the ideal but not creating new tilings. 976 // Changing the ideal but not creating new tilings.
979 scale *= 1.5f; 977 scale = 1.5f;
980 page_scale *= 1.5f; 978 page_scale = 1.5f;
981 SetContentsScaleOnBothLayers(scale, device_scale, page_scale, 1.f, false); 979 SetContentsScaleOnBothLayers(scale, 1.f, page_scale, 1.f, false);
982 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); 980 EXPECT_EQ(2u, active_layer_->tilings()->num_tilings());
983 981
984 // The tilings are still our target scale, so they aren't removed. 982 // The tilings are still our target scale, so they aren't removed.
985 used_tilings.clear(); 983 used_tilings.clear();
986 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); 984 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
987 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); 985 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
988 986
989 host_impl_.PinchGestureEnd(); 987 host_impl_.PinchGestureEnd();
990 988
991 // Create a 1.2 scale tiling. Now we have 1.0 and 1.2 tilings. Ideal = 1.2. 989 // Create a 1.2 scale tiling. Now we have 1.0 and 1.2 tilings. Ideal = 1.2.
992 scale /= 4.f; 990 scale = 1.2f;
993 page_scale /= 4.f; 991 page_scale = 1.2f;
994 SetContentsScaleOnBothLayers(1.2f, device_scale, page_scale, 1.f, false); 992 SetContentsScaleOnBothLayers(1.2f, 1.f, page_scale, 1.f, false);
995 ASSERT_EQ(4u, active_layer_->tilings()->num_tilings()); 993 ASSERT_EQ(4u, active_layer_->tilings()->num_tilings());
996 EXPECT_FLOAT_EQ( 994 EXPECT_FLOAT_EQ(
997 1.f, 995 1.f,
998 active_layer_->tilings()->tiling_at(1)->contents_scale()); 996 active_layer_->tilings()->tiling_at(1)->contents_scale());
999 EXPECT_FLOAT_EQ( 997 EXPECT_FLOAT_EQ(
1000 1.f * low_res_factor, 998 1.f * low_res_factor,
1001 active_layer_->tilings()->tiling_at(3)->contents_scale()); 999 active_layer_->tilings()->tiling_at(3)->contents_scale());
1002 1000
1003 // Mark the non-ideal tilings as used. They won't be removed. 1001 // Mark the non-ideal tilings as used. They won't be removed.
1004 used_tilings.clear(); 1002 used_tilings.clear();
1005 used_tilings.push_back(active_layer_->tilings()->tiling_at(1)); 1003 used_tilings.push_back(active_layer_->tilings()->tiling_at(1));
1006 used_tilings.push_back(active_layer_->tilings()->tiling_at(3)); 1004 used_tilings.push_back(active_layer_->tilings()->tiling_at(3));
1007 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); 1005 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
1008 ASSERT_EQ(4u, active_layer_->tilings()->num_tilings()); 1006 ASSERT_EQ(4u, active_layer_->tilings()->num_tilings());
1009 1007
1010 // Now move the ideal scale to 0.5. Our target stays 1.2. 1008 // Now move the ideal scale to 0.5. Our target stays 1.2.
1011 SetContentsScaleOnBothLayers(0.5f, device_scale, page_scale, 1.f, false); 1009 SetContentsScaleOnBothLayers(0.5f, 1.f, page_scale, 1.f, false);
1012 1010
1013 // The high resolution tiling is between target and ideal, so is not 1011 // The high resolution tiling is between target and ideal, so is not
1014 // removed. The low res tiling for the old ideal=1.0 scale is removed. 1012 // removed. The low res tiling for the old ideal=1.0 scale is removed.
1015 used_tilings.clear(); 1013 used_tilings.clear();
1016 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); 1014 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
1017 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings()); 1015 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings());
1018 1016
1019 // Now move the ideal scale to 1.0. Our target stays 1.2. 1017 // Now move the ideal scale to 1.0. Our target stays 1.2.
1020 SetContentsScaleOnBothLayers(1.f, device_scale, page_scale, 1.f, false); 1018 SetContentsScaleOnBothLayers(1.f, 1.f, page_scale, 1.f, false);
1021 1019
1022 // All the tilings are between are target and the ideal, so they are not 1020 // All the tilings are between are target and the ideal, so they are not
1023 // removed. 1021 // removed.
1024 used_tilings.clear(); 1022 used_tilings.clear();
1025 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); 1023 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
1026 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings()); 1024 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings());
1027 1025
1028 // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2. 1026 // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2.
1029 SetupDrawPropertiesAndUpdateTiles( 1027 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.1f, 1.f, page_scale, 1.f,
1030 active_layer_, 1.1f, device_scale, page_scale, 1.f, false); 1028 false);
1031 1029
1032 // Because the pending layer's ideal scale is still 1.0, our tilings fall 1030 // Because the pending layer's ideal scale is still 1.0, our tilings fall
1033 // in the range [1.0,1.2] and are kept. 1031 // in the range [1.0,1.2] and are kept.
1034 used_tilings.clear(); 1032 used_tilings.clear();
1035 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); 1033 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
1036 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings()); 1034 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings());
1037 1035
1038 // Move the ideal scale on the pending layer to 1.1 as well. Our target stays 1036 // Move the ideal scale on the pending layer to 1.1 as well. Our target stays
1039 // 1.2 still. 1037 // 1.2 still.
1040 SetupDrawPropertiesAndUpdateTiles( 1038 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.1f, 1.f, page_scale, 1.f,
1041 pending_layer_, 1.1f, device_scale, page_scale, 1.f, false); 1039 false);
1042 1040
1043 // Our 1.0 tiling now falls outside the range between our ideal scale and our 1041 // Our 1.0 tiling now falls outside the range between our ideal scale and our
1044 // target raster scale. But it is in our used tilings set, so nothing is 1042 // target raster scale. But it is in our used tilings set, so nothing is
1045 // deleted. 1043 // deleted.
1046 used_tilings.clear(); 1044 used_tilings.clear();
1047 used_tilings.push_back(active_layer_->tilings()->tiling_at(1)); 1045 used_tilings.push_back(active_layer_->tilings()->tiling_at(1));
1048 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); 1046 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
1049 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings()); 1047 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings());
1050 1048
1051 // If we remove it from our used tilings set, it is outside the range to keep 1049 // If we remove it from our used tilings set, it is outside the range to keep
1052 // so it is deleted. 1050 // so it is deleted.
1053 used_tilings.clear(); 1051 used_tilings.clear();
1054 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); 1052 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
1055 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); 1053 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
1056 } 1054 }
1057 1055
1058 #define EXPECT_BOTH_EQ(expression, x) \
1059 do { \
1060 EXPECT_EQ(x, pending_layer_->expression); \
1061 EXPECT_EQ(x, active_layer_->expression); \
1062 } while (false)
1063
1064 #define EXPECT_BOTH_NE(expression, x) \
1065 do { \
1066 EXPECT_NE(x, pending_layer_->expression); \
1067 EXPECT_NE(x, active_layer_->expression); \
1068 } while (false)
1069
1070 TEST_F(PictureLayerImplTest, DontAddLowResDuringAnimation) { 1056 TEST_F(PictureLayerImplTest, DontAddLowResDuringAnimation) {
1071 // Make sure this layer covers multiple tiles, since otherwise low 1057 // Make sure this layer covers multiple tiles, since otherwise low
1072 // res won't get created because it is too small. 1058 // res won't get created because it is too small.
1073 gfx::Size tile_size(host_impl_.settings().default_tile_size); 1059 gfx::Size tile_size(host_impl_.settings().default_tile_size);
1074 SetupDefaultTrees(gfx::Size(tile_size.width() + 1, tile_size.height() + 1));
1075 // Avoid max untiled layer size heuristics via fixed tile size. 1060 // Avoid max untiled layer size heuristics via fixed tile size.
1076 pending_layer_->set_fixed_tile_size(tile_size); 1061 gfx::Size layer_bounds(tile_size.width() + 1, tile_size.height() + 1);
1077 active_layer_->set_fixed_tile_size(tile_size); 1062 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, Region());
1078 1063
1079 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; 1064 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
1080 float contents_scale = 1.f; 1065 float contents_scale = 1.f;
1081 float device_scale = 1.f; 1066 float device_scale = 1.f;
1082 float page_scale = 1.f; 1067 float page_scale = 1.f;
1083 float maximum_animation_scale = 1.f; 1068 float maximum_animation_scale = 1.f;
1084 bool animating_transform = true; 1069 bool animating_transform = true;
1085 1070
1071 ResetTilingsAndRasterScales();
1072
1086 // Animating, so don't create low res even if there isn't one already. 1073 // Animating, so don't create low res even if there isn't one already.
1087 SetContentsScaleOnBothLayers(contents_scale, 1074 SetContentsScaleOnBothLayers(contents_scale,
1088 device_scale, 1075 device_scale,
1089 page_scale, 1076 page_scale,
1090 maximum_animation_scale, 1077 maximum_animation_scale,
1091 animating_transform); 1078 animating_transform);
1092 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f); 1079 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f);
1093 EXPECT_BOTH_EQ(num_tilings(), 1u); 1080 EXPECT_BOTH_EQ(num_tilings(), 1u);
1094 1081
1095 // Stop animating, low res gets created. 1082 // Stop animating, low res gets created.
1096 animating_transform = false; 1083 animating_transform = false;
1097 SetContentsScaleOnBothLayers(contents_scale, 1084 SetContentsScaleOnBothLayers(contents_scale,
1098 device_scale, 1085 device_scale,
1099 page_scale, 1086 page_scale,
1100 maximum_animation_scale, 1087 maximum_animation_scale,
1101 animating_transform); 1088 animating_transform);
1102 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f); 1089 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f);
1103 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(), low_res_factor); 1090 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(), low_res_factor);
1104 EXPECT_BOTH_EQ(num_tilings(), 2u); 1091 EXPECT_BOTH_EQ(num_tilings(), 2u);
1105 1092
1106 // Page scale animation, new high res, but no low res. We still have 1093 // Page scale animation, new high res, but no low res. We still have
1107 // a tiling at the previous scale, it's just not marked as low res. 1094 // a tiling at the previous scale, it's just not marked as low res on the
1095 // active layer. The pending layer drops non-ideal tilings.
1108 contents_scale = 2.f; 1096 contents_scale = 2.f;
1109 page_scale = 2.f; 1097 page_scale = 2.f;
1110 maximum_animation_scale = 2.f; 1098 maximum_animation_scale = 2.f;
1111 animating_transform = true; 1099 animating_transform = true;
1112 SetContentsScaleOnBothLayers(contents_scale, 1100 SetContentsScaleOnBothLayers(contents_scale,
1113 device_scale, 1101 device_scale,
1114 page_scale, 1102 page_scale,
1115 maximum_animation_scale, 1103 maximum_animation_scale,
1116 animating_transform); 1104 animating_transform);
1117 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f); 1105 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f);
1118 EXPECT_FALSE(active_layer_->LowResTiling()); 1106 EXPECT_FALSE(active_layer_->LowResTiling());
1119 EXPECT_FALSE(pending_layer_->LowResTiling()); 1107 EXPECT_FALSE(pending_layer_->LowResTiling());
1120 EXPECT_BOTH_EQ(num_tilings(), 3u); 1108 EXPECT_EQ(3u, active_layer_->num_tilings());
1109 EXPECT_EQ(1u, pending_layer_->num_tilings());
1121 1110
1122 // Stop animating, new low res gets created for final page scale. 1111 // Stop animating, new low res gets created for final page scale.
1123 animating_transform = false; 1112 animating_transform = false;
1124 SetContentsScaleOnBothLayers(contents_scale, 1113 SetContentsScaleOnBothLayers(contents_scale,
1125 device_scale, 1114 device_scale,
1126 page_scale, 1115 page_scale,
1127 maximum_animation_scale, 1116 maximum_animation_scale,
1128 animating_transform); 1117 animating_transform);
1129 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f); 1118 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f);
1130 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(), 2.f * low_res_factor); 1119 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(), 2.f * low_res_factor);
1131 EXPECT_BOTH_EQ(num_tilings(), 4u); 1120 EXPECT_EQ(4u, active_layer_->num_tilings());
1121 EXPECT_EQ(2u, pending_layer_->num_tilings());
1132 } 1122 }
1133 1123
1134 TEST_F(PictureLayerImplTest, DontAddLowResForSmallLayers) { 1124 TEST_F(PictureLayerImplTest, DontAddLowResForSmallLayers) {
1135 gfx::Size layer_bounds(host_impl_.settings().default_tile_size); 1125 gfx::Size layer_bounds(host_impl_.settings().default_tile_size);
1136 gfx::Size tile_size(100, 100); 1126 gfx::Size tile_size(100, 100);
1137 1127
1138 scoped_refptr<FakePicturePileImpl> pending_pile = 1128 scoped_refptr<FakePicturePileImpl> pending_pile =
1139 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 1129 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1140 scoped_refptr<FakePicturePileImpl> active_pile = 1130 scoped_refptr<FakePicturePileImpl> active_pile =
1141 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 1131 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1178 SetContentsScaleOnBothLayers(contents_scale, 1168 SetContentsScaleOnBothLayers(contents_scale,
1179 device_scale, 1169 device_scale,
1180 page_scale, 1170 page_scale,
1181 maximum_animation_scale, 1171 maximum_animation_scale,
1182 animating_transform); 1172 animating_transform);
1183 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale); 1173 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale);
1184 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(), 1174 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(),
1185 contents_scale * low_res_factor); 1175 contents_scale * low_res_factor);
1186 EXPECT_BOTH_EQ(num_tilings(), 2u); 1176 EXPECT_BOTH_EQ(num_tilings(), 2u);
1187 1177
1188 ResetTilingsAndRasterScales(); 1178 // Mask layers dont create low res since they always fit on one tile.
1179 scoped_ptr<FakePictureLayerImpl> mask =
1180 FakePictureLayerImpl::CreateMaskWithRasterSource(
1181 host_impl_.pending_tree(), 3, pending_pile);
1182 mask->SetBounds(layer_bounds);
1183 mask->SetContentBounds(layer_bounds);
1184 mask->SetDrawsContent(true);
1189 1185
1190 // Mask layers dont create low res since they always fit on one tile. 1186 SetupDrawPropertiesAndUpdateTiles(mask.get(), contents_scale, device_scale,
1191 pending_layer_->set_is_mask(true); 1187 page_scale, maximum_animation_scale,
1192 active_layer_->set_is_mask(true); 1188 animating_transform);
1193 SetContentsScaleOnBothLayers(contents_scale, 1189 EXPECT_EQ(mask->HighResTiling()->contents_scale(), contents_scale);
1194 device_scale, 1190 EXPECT_EQ(mask->num_tilings(), 1u);
1195 page_scale,
1196 maximum_animation_scale,
1197 animating_transform);
1198 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale);
1199 EXPECT_BOTH_EQ(num_tilings(), 1u);
1200 } 1191 }
1201 1192
1202 TEST_F(PictureLayerImplTest, HugeMasksDontGetTiles) { 1193 TEST_F(PictureLayerImplTest, HugeMasksDontGetTiles) {
1194 base::TimeTicks time_ticks;
1195 time_ticks += base::TimeDelta::FromMilliseconds(1);
1196 host_impl_.SetCurrentBeginFrameArgs(
1197 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
1198
1203 gfx::Size tile_size(100, 100); 1199 gfx::Size tile_size(100, 100);
1200 gfx::Size layer_bounds(1000, 1000);
1204 1201
1205 scoped_refptr<FakePicturePileImpl> valid_pile = 1202 scoped_refptr<FakePicturePileImpl> valid_pile =
1206 FakePicturePileImpl::CreateFilledPile(tile_size, gfx::Size(1000, 1000)); 1203 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1207 SetupPendingTree(valid_pile); 1204 SetupPendingTree(valid_pile);
1208 pending_layer_->set_is_mask(true);
1209 1205
1210 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.f, 1.f, 1.f, 1.f, false); 1206 scoped_ptr<FakePictureLayerImpl> mask_ptr =
1211 EXPECT_EQ(1.f, pending_layer_->HighResTiling()->contents_scale()); 1207 FakePictureLayerImpl::CreateMaskWithRasterSource(
1212 EXPECT_EQ(1u, pending_layer_->num_tilings()); 1208 host_impl_.pending_tree(), 3, valid_pile);
1209 mask_ptr->SetBounds(layer_bounds);
1210 mask_ptr->SetContentBounds(layer_bounds);
1211 mask_ptr->SetDrawsContent(true);
1212 pending_layer_->SetMaskLayer(mask_ptr.Pass());
1213 1213
1214 pending_layer_->HighResTiling()->CreateAllTilesForTesting(); 1214 time_ticks += base::TimeDelta::FromMilliseconds(1);
1215 host_impl_.SetCurrentBeginFrameArgs(
1216 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
1217 host_impl_.pending_tree()->UpdateDrawProperties();
1218
1219 FakePictureLayerImpl* pending_mask =
1220 static_cast<FakePictureLayerImpl*>(pending_layer_->mask_layer());
1221
1222 EXPECT_EQ(1.f, pending_mask->HighResTiling()->contents_scale());
1223 EXPECT_EQ(1u, pending_mask->num_tilings());
1224
1215 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting( 1225 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(
1216 pending_layer_->HighResTiling()->AllTilesForTesting()); 1226 pending_mask->HighResTiling()->AllTilesForTesting());
1217 1227
1218 ActivateTree(); 1228 ActivateTree();
1219 1229
1230 FakePictureLayerImpl* active_mask =
1231 static_cast<FakePictureLayerImpl*>(active_layer_->mask_layer());
1232
1220 // Mask layers have a tiling with a single tile in it. 1233 // Mask layers have a tiling with a single tile in it.
1221 EXPECT_EQ(1u, active_layer_->HighResTiling()->AllTilesForTesting().size()); 1234 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size());
1222 // The mask resource exists. 1235 // The mask resource exists.
1223 ResourceProvider::ResourceId mask_resource_id; 1236 ResourceProvider::ResourceId mask_resource_id;
1224 gfx::Size mask_texture_size; 1237 gfx::Size mask_texture_size;
1225 active_layer_->GetContentsResourceId(&mask_resource_id, &mask_texture_size); 1238 active_mask->GetContentsResourceId(&mask_resource_id, &mask_texture_size);
1239 EXPECT_NE(0u, mask_resource_id);
1240 EXPECT_EQ(mask_texture_size, active_mask->bounds());
1241
1242 // Drop resources and recreate them, still the same.
1243 pending_mask->ReleaseResources();
1244 active_mask->ReleaseResources();
1245 SetupDrawPropertiesAndUpdateTiles(active_mask, 1.f, 1.f, 1.f, 1.f, false);
1246 active_mask->HighResTiling()->CreateAllTilesForTesting();
1247 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size());
1226 EXPECT_NE(0u, mask_resource_id); 1248 EXPECT_NE(0u, mask_resource_id);
1227 EXPECT_EQ(mask_texture_size, active_layer_->bounds()); 1249 EXPECT_EQ(mask_texture_size, active_layer_->bounds());
1228 1250
1229 // Drop resources and recreate them, still the same. 1251 // Drop resources and recreate them, still the same.
1230 old_pending_layer_->ReleaseResources(); 1252 pending_mask->ReleaseResources();
1231 active_layer_->ReleaseResources(); 1253 active_mask->ReleaseResources();
1232 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, 1.f, 1.f, 1.f, false); 1254 SetupDrawPropertiesAndUpdateTiles(active_mask, 1.f, 1.f, 1.f, 1.f, false);
1233 active_layer_->HighResTiling()->CreateAllTilesForTesting(); 1255 active_mask->HighResTiling()->CreateAllTilesForTesting();
1234 EXPECT_EQ(1u, active_layer_->HighResTiling()->AllTilesForTesting().size()); 1256 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size());
1235 EXPECT_NE(0u, mask_resource_id); 1257 EXPECT_NE(0u, mask_resource_id);
1236 EXPECT_EQ(mask_texture_size, active_layer_->bounds()); 1258 EXPECT_EQ(mask_texture_size, active_mask->bounds());
1237 1259
1238 // Resize larger than the max texture size. 1260 // Resize larger than the max texture size.
1239 int max_texture_size = host_impl_.GetRendererCapabilities().max_texture_size; 1261 int max_texture_size = host_impl_.GetRendererCapabilities().max_texture_size;
1262 gfx::Size huge_bounds(max_texture_size + 1, 10);
1240 scoped_refptr<FakePicturePileImpl> huge_pile = 1263 scoped_refptr<FakePicturePileImpl> huge_pile =
1241 FakePicturePileImpl::CreateFilledPile( 1264 FakePicturePileImpl::CreateFilledPile(tile_size, huge_bounds);
1242 tile_size, gfx::Size(max_texture_size + 1, 10)); 1265
1243 SetupPendingTree(huge_pile); 1266 SetupPendingTree(huge_pile);
1244 pending_layer_->set_is_mask(true); 1267 pending_mask->SetBounds(huge_bounds);
1268 pending_mask->SetContentBounds(huge_bounds);
1269 pending_mask->SetRasterSourceOnPending(huge_pile, Region());
1245 1270
1246 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.f, 1.f, 1.f, 1.f, false); 1271 time_ticks += base::TimeDelta::FromMilliseconds(1);
1247 EXPECT_EQ(1.f, pending_layer_->HighResTiling()->contents_scale()); 1272 host_impl_.SetCurrentBeginFrameArgs(
1248 EXPECT_EQ(1u, pending_layer_->num_tilings()); 1273 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
1274 host_impl_.pending_tree()->UpdateDrawProperties();
1249 1275
1250 pending_layer_->HighResTiling()->CreateAllTilesForTesting(); 1276 EXPECT_EQ(1.f, pending_mask->HighResTiling()->contents_scale());
1277 EXPECT_EQ(1u, pending_mask->num_tilings());
1278
1251 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting( 1279 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(
1252 pending_layer_->HighResTiling()->AllTilesForTesting()); 1280 pending_mask->HighResTiling()->AllTilesForTesting());
1253 1281
1254 ActivateTree(); 1282 ActivateTree();
1255 1283
1256 // Mask layers have a tiling, but there should be no tiles in it. 1284 // Mask layers have a tiling, but there should be no tiles in it.
1257 EXPECT_EQ(0u, active_layer_->HighResTiling()->AllTilesForTesting().size()); 1285 EXPECT_EQ(0u, active_mask->HighResTiling()->AllTilesForTesting().size());
1258 // The mask resource is empty. 1286 // The mask resource is empty.
1259 active_layer_->GetContentsResourceId(&mask_resource_id, &mask_texture_size); 1287 active_layer_->GetContentsResourceId(&mask_resource_id, &mask_texture_size);
1260 EXPECT_EQ(0u, mask_resource_id); 1288 EXPECT_EQ(0u, mask_resource_id);
1261 1289
1262 // Drop resources and recreate them, still the same. 1290 // Drop resources and recreate them, still the same.
1263 old_pending_layer_->ReleaseResources(); 1291 pending_mask->ReleaseResources();
1264 active_layer_->ReleaseResources(); 1292 active_mask->ReleaseResources();
1265 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, 1.f, 1.f, 1.f, false); 1293 SetupDrawPropertiesAndUpdateTiles(active_mask, 1.f, 1.f, 1.f, 1.f, false);
1266 active_layer_->HighResTiling()->CreateAllTilesForTesting(); 1294 active_mask->HighResTiling()->CreateAllTilesForTesting();
1267 EXPECT_EQ(0u, active_layer_->HighResTiling()->AllTilesForTesting().size()); 1295 EXPECT_EQ(0u, active_mask->HighResTiling()->AllTilesForTesting().size());
1296 active_mask->GetContentsResourceId(&mask_resource_id, &mask_texture_size);
1297 EXPECT_EQ(0u, mask_resource_id);
1298
1299 // Do another activate, the same holds.
1300 SetupPendingTree(huge_pile);
1301 ActivateTree();
1302 EXPECT_EQ(0u, active_mask->HighResTiling()->AllTilesForTesting().size());
1268 active_layer_->GetContentsResourceId(&mask_resource_id, &mask_texture_size); 1303 active_layer_->GetContentsResourceId(&mask_resource_id, &mask_texture_size);
1269 EXPECT_EQ(0u, mask_resource_id); 1304 EXPECT_EQ(0u, mask_resource_id);
1270 } 1305 }
1271 1306
1272 TEST_F(PictureLayerImplTest, ScaledMaskLayer) { 1307 TEST_F(PictureLayerImplTest, ScaledMaskLayer) {
1308 base::TimeTicks time_ticks;
1309 time_ticks += base::TimeDelta::FromMilliseconds(1);
1310 host_impl_.SetCurrentBeginFrameArgs(
1311 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
1312
1273 gfx::Size tile_size(100, 100); 1313 gfx::Size tile_size(100, 100);
1314 gfx::Size layer_bounds(1000, 1000);
1315
1316 host_impl_.SetDeviceScaleFactor(1.3f);
1274 1317
1275 scoped_refptr<FakePicturePileImpl> valid_pile = 1318 scoped_refptr<FakePicturePileImpl> valid_pile =
1276 FakePicturePileImpl::CreateFilledPile(tile_size, gfx::Size(1000, 1000)); 1319 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1277 SetupPendingTree(valid_pile); 1320 SetupPendingTree(valid_pile);
1278 pending_layer_->set_is_mask(true);
1279 1321
1280 float ideal_contents_scale = 1.3f; 1322 scoped_ptr<FakePictureLayerImpl> mask_ptr =
1281 SetupDrawPropertiesAndUpdateTiles( 1323 FakePictureLayerImpl::CreateMaskWithRasterSource(
1282 pending_layer_, ideal_contents_scale, 1.f, 1.f, 1.f, false); 1324 host_impl_.pending_tree(), 3, valid_pile);
1283 EXPECT_EQ(ideal_contents_scale, 1325 mask_ptr->SetBounds(layer_bounds);
1284 pending_layer_->HighResTiling()->contents_scale()); 1326 mask_ptr->SetContentBounds(layer_bounds);
1285 EXPECT_EQ(1u, pending_layer_->num_tilings()); 1327 mask_ptr->SetDrawsContent(true);
1328 pending_layer_->SetMaskLayer(mask_ptr.Pass());
1286 1329
1287 pending_layer_->HighResTiling()->CreateAllTilesForTesting(); 1330 time_ticks += base::TimeDelta::FromMilliseconds(1);
1331 host_impl_.SetCurrentBeginFrameArgs(
1332 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
1333 host_impl_.pending_tree()->UpdateDrawProperties();
1334
1335 FakePictureLayerImpl* pending_mask =
1336 static_cast<FakePictureLayerImpl*>(pending_layer_->mask_layer());
1337
1338 // Masks are scaled, and do not have a low res tiling.
1339 EXPECT_EQ(1.3f, pending_mask->HighResTiling()->contents_scale());
1340 EXPECT_EQ(1u, pending_mask->num_tilings());
1341
1288 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting( 1342 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(
1289 pending_layer_->HighResTiling()->AllTilesForTesting()); 1343 pending_mask->HighResTiling()->AllTilesForTesting());
1290 1344
1291 ActivateTree(); 1345 ActivateTree();
1292 1346
1347 FakePictureLayerImpl* active_mask =
1348 static_cast<FakePictureLayerImpl*>(active_layer_->mask_layer());
1349
1293 // Mask layers have a tiling with a single tile in it. 1350 // Mask layers have a tiling with a single tile in it.
1294 EXPECT_EQ(1u, active_layer_->HighResTiling()->AllTilesForTesting().size()); 1351 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size());
1295 // The mask resource exists. 1352 // The mask resource exists.
1296 ResourceProvider::ResourceId mask_resource_id; 1353 ResourceProvider::ResourceId mask_resource_id;
1297 gfx::Size mask_texture_size; 1354 gfx::Size mask_texture_size;
1298 active_layer_->GetContentsResourceId(&mask_resource_id, &mask_texture_size); 1355 active_mask->GetContentsResourceId(&mask_resource_id, &mask_texture_size);
1299 EXPECT_NE(0u, mask_resource_id); 1356 EXPECT_NE(0u, mask_resource_id);
1300 gfx::Size expected_mask_texture_size = gfx::ToCeiledSize( 1357 gfx::Size expected_mask_texture_size =
1301 gfx::ScaleSize(active_layer_->bounds(), ideal_contents_scale)); 1358 gfx::ToCeiledSize(gfx::ScaleSize(active_mask->bounds(), 1.3f));
1302 EXPECT_EQ(mask_texture_size, expected_mask_texture_size); 1359 EXPECT_EQ(mask_texture_size, expected_mask_texture_size);
1303 } 1360 }
1304 1361
1305 TEST_F(PictureLayerImplTest, ReleaseResources) { 1362 TEST_F(PictureLayerImplTest, ReleaseResources) {
1306 gfx::Size tile_size(400, 400); 1363 gfx::Size tile_size(400, 400);
1307 gfx::Size layer_bounds(1300, 1900); 1364 gfx::Size layer_bounds(1300, 1900);
1308 1365
1309 scoped_refptr<FakePicturePileImpl> pending_pile = 1366 scoped_refptr<FakePicturePileImpl> pending_pile =
1310 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 1367 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1311 scoped_refptr<FakePicturePileImpl> active_pile = 1368 scoped_refptr<FakePicturePileImpl> active_pile =
1312 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 1369 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1313 1370
1314 SetupTrees(pending_pile, active_pile); 1371 SetupTrees(pending_pile, active_pile);
1315 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
1316
1317 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
1318 1.3f, // ideal contents scale
1319 2.7f, // device scale
1320 3.2f, // page scale
1321 1.f, // maximum animation scale
1322 false);
1323 EXPECT_EQ(2u, pending_layer_->tilings()->num_tilings()); 1372 EXPECT_EQ(2u, pending_layer_->tilings()->num_tilings());
1324 1373
1325 // All tilings should be removed when losing output surface. 1374 // All tilings should be removed when losing output surface.
1326 active_layer_->ReleaseResources(); 1375 active_layer_->ReleaseResources();
1327 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings()); 1376 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
1328 pending_layer_->ReleaseResources(); 1377 pending_layer_->ReleaseResources();
1329 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); 1378 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
1330 1379
1331 // This should create new tilings. 1380 // This should create new tilings.
1332 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1381 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
1333 1.3f, // ideal contents scale 1382 1.f, // ideal contents scale
1334 2.7f, // device scale 1383 1.f, // device scale
1335 3.2f, // page scale 1384 1.f, // page scale
1336 1.f, // maximum animation scale 1385 1.f, // maximum animation scale
1337 false); 1386 false);
1338 EXPECT_EQ(2u, pending_layer_->tilings()->num_tilings()); 1387 EXPECT_EQ(2u, pending_layer_->tilings()->num_tilings());
1339 } 1388 }
1340 1389
1341 TEST_F(PictureLayerImplTest, ClampTilesToToMaxTileSize) { 1390 TEST_F(PictureLayerImplTest, ClampTilesToToMaxTileSize) {
1342 // The default max tile size is larger than 400x400. 1391 // The default max tile size is larger than 400x400.
1343 gfx::Size tile_size(400, 400); 1392 gfx::Size tile_size(400, 400);
1344 gfx::Size layer_bounds(5000, 5000); 1393 gfx::Size layer_bounds(5000, 5000);
1345 1394
1346 scoped_refptr<FakePicturePileImpl> pending_pile = 1395 scoped_refptr<FakePicturePileImpl> pending_pile =
1347 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 1396 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1348 scoped_refptr<FakePicturePileImpl> active_pile = 1397 scoped_refptr<FakePicturePileImpl> active_pile =
1349 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 1398 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1350 1399
1351 SetupTrees(pending_pile, active_pile); 1400 SetupTrees(pending_pile, active_pile);
1352 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); 1401 EXPECT_GE(pending_layer_->tilings()->num_tilings(), 1u);
1353
1354 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.f, 1.f, 1.f, 1.f, false);
1355 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
1356 1402
1357 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting(); 1403 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1358 1404
1359 // The default value. 1405 // The default value.
1360 EXPECT_EQ(gfx::Size(256, 256).ToString(), 1406 EXPECT_EQ(gfx::Size(256, 256).ToString(),
1361 host_impl_.settings().default_tile_size.ToString()); 1407 host_impl_.settings().default_tile_size.ToString());
1362 1408
1363 Tile* tile = pending_layer_->tilings()->tiling_at(0)->AllTilesForTesting()[0]; 1409 Tile* tile = pending_layer_->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1364 EXPECT_EQ(gfx::Size(256, 256).ToString(), 1410 EXPECT_EQ(gfx::Size(256, 256).ToString(),
1365 tile->content_rect().size().ToString()); 1411 tile->content_rect().size().ToString());
1366 1412
1367 pending_layer_->ReleaseResources(); 1413 ResetTilingsAndRasterScales();
1368 1414
1369 // Change the max texture size on the output surface context. 1415 // Change the max texture size on the output surface context.
1370 scoped_ptr<TestWebGraphicsContext3D> context = 1416 scoped_ptr<TestWebGraphicsContext3D> context =
1371 TestWebGraphicsContext3D::Create(); 1417 TestWebGraphicsContext3D::Create();
1372 context->set_max_texture_size(140); 1418 context->set_max_texture_size(140);
1373 host_impl_.DidLoseOutputSurface(); 1419 host_impl_.DidLoseOutputSurface();
1374 host_impl_.InitializeRenderer( 1420 host_impl_.InitializeRenderer(
1375 FakeOutputSurface::Create3d(context.Pass()).Pass()); 1421 FakeOutputSurface::Create3d(context.Pass()).Pass());
1376 1422
1377 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.f, 1.f, 1.f, 1.f, false); 1423 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.f, 1.f, 1.f, 1.f, false);
(...skipping 11 matching lines...) Expand all
1389 // The default max tile size is larger than 400x400. 1435 // The default max tile size is larger than 400x400.
1390 gfx::Size tile_size(400, 400); 1436 gfx::Size tile_size(400, 400);
1391 gfx::Size layer_bounds(500, 500); 1437 gfx::Size layer_bounds(500, 500);
1392 1438
1393 scoped_refptr<FakePicturePileImpl> pending_pile = 1439 scoped_refptr<FakePicturePileImpl> pending_pile =
1394 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 1440 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1395 scoped_refptr<FakePicturePileImpl> active_pile = 1441 scoped_refptr<FakePicturePileImpl> active_pile =
1396 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 1442 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1397 1443
1398 SetupTrees(pending_pile, active_pile); 1444 SetupTrees(pending_pile, active_pile);
1399 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); 1445 EXPECT_GE(pending_layer_->tilings()->num_tilings(), 1u);
1400
1401 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.f, 1.f, 1.f, 1.f, false);
1402 ASSERT_LE(1u, pending_layer_->tilings()->num_tilings());
1403 1446
1404 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting(); 1447 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1405 1448
1406 // The default value. The layer is smaller than this. 1449 // The default value. The layer is smaller than this.
1407 EXPECT_EQ(gfx::Size(512, 512).ToString(), 1450 EXPECT_EQ(gfx::Size(512, 512).ToString(),
1408 host_impl_.settings().max_untiled_layer_size.ToString()); 1451 host_impl_.settings().max_untiled_layer_size.ToString());
1409 1452
1410 // There should be a single tile since the layer is small. 1453 // There should be a single tile since the layer is small.
1411 PictureLayerTiling* high_res_tiling = pending_layer_->tilings()->tiling_at(0); 1454 PictureLayerTiling* high_res_tiling = pending_layer_->tilings()->tiling_at(0);
1412 EXPECT_EQ(1u, high_res_tiling->AllTilesForTesting().size()); 1455 EXPECT_EQ(1u, high_res_tiling->AllTilesForTesting().size());
1413 1456
1414 pending_layer_->ReleaseResources(); 1457 ResetTilingsAndRasterScales();
1415 1458
1416 // Change the max texture size on the output surface context. 1459 // Change the max texture size on the output surface context.
1417 scoped_ptr<TestWebGraphicsContext3D> context = 1460 scoped_ptr<TestWebGraphicsContext3D> context =
1418 TestWebGraphicsContext3D::Create(); 1461 TestWebGraphicsContext3D::Create();
1419 context->set_max_texture_size(140); 1462 context->set_max_texture_size(140);
1420 host_impl_.DidLoseOutputSurface(); 1463 host_impl_.DidLoseOutputSurface();
1421 host_impl_.InitializeRenderer( 1464 host_impl_.InitializeRenderer(
1422 FakeOutputSurface::Create3d(context.Pass()).Pass()); 1465 FakeOutputSurface::Create3d(context.Pass()).Pass());
1423 1466
1424 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.f, 1.f, 1.f, 1.f, false); 1467 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.f, 1.f, 1.f, 1.f, false);
(...skipping 16 matching lines...) Expand all
1441 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); 1484 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
1442 1485
1443 gfx::Size tile_size(400, 400); 1486 gfx::Size tile_size(400, 400);
1444 gfx::Size layer_bounds(1300, 1900); 1487 gfx::Size layer_bounds(1300, 1900);
1445 1488
1446 scoped_refptr<FakePicturePileImpl> pending_pile = 1489 scoped_refptr<FakePicturePileImpl> pending_pile =
1447 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 1490 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1448 scoped_refptr<FakePicturePileImpl> active_pile = 1491 scoped_refptr<FakePicturePileImpl> active_pile =
1449 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 1492 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1450 1493
1451 SetupTrees(pending_pile, active_pile); 1494 gfx::Rect layer_invalidation(150, 200, 30, 180);
1495 SetupTreesWithInvalidation(pending_pile, active_pile, layer_invalidation);
1452 1496
1453 active_layer_->draw_properties().visible_content_rect = 1497 active_layer_->draw_properties().visible_content_rect =
1454 gfx::Rect(layer_bounds); 1498 gfx::Rect(layer_bounds);
1455 1499
1456 gfx::Rect layer_invalidation(150, 200, 30, 180);
1457 Region invalidation(layer_invalidation);
1458 AddDefaultTilingsWithInvalidation(invalidation);
1459
1460 AppendQuadsData data; 1500 AppendQuadsData data;
1461 active_layer_->WillDraw(DRAW_MODE_RESOURCELESS_SOFTWARE, nullptr); 1501 active_layer_->WillDraw(DRAW_MODE_RESOURCELESS_SOFTWARE, nullptr);
1462 active_layer_->AppendQuads(render_pass.get(), Occlusion(), &data); 1502 active_layer_->AppendQuads(render_pass.get(), Occlusion(), &data);
1463 active_layer_->DidDraw(nullptr); 1503 active_layer_->DidDraw(nullptr);
1464 1504
1465 ASSERT_EQ(1U, render_pass->quad_list.size()); 1505 ASSERT_EQ(1U, render_pass->quad_list.size());
1466 EXPECT_EQ(DrawQuad::PICTURE_CONTENT, 1506 EXPECT_EQ(DrawQuad::PICTURE_CONTENT,
1467 render_pass->quad_list.front()->material); 1507 render_pass->quad_list.front()->material);
1468 } 1508 }
1469 1509
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1507 scoped_refptr<FakePicturePileImpl> pending_pile = 1547 scoped_refptr<FakePicturePileImpl> pending_pile =
1508 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings( 1548 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings(
1509 tile_size, layer_bounds); 1549 tile_size, layer_bounds);
1510 scoped_refptr<FakePicturePileImpl> active_pile = 1550 scoped_refptr<FakePicturePileImpl> active_pile =
1511 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings( 1551 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings(
1512 tile_size, layer_bounds); 1552 tile_size, layer_bounds);
1513 1553
1514 pending_pile->set_is_solid_color(false); 1554 pending_pile->set_is_solid_color(false);
1515 active_pile->set_is_solid_color(true); 1555 active_pile->set_is_solid_color(true);
1516 SetupTrees(pending_pile, active_pile); 1556 SetupTrees(pending_pile, active_pile);
1517 // Solid color layer should not have tilings. 1557 // Solid color pile should not allow tilings at any scale.
1518 ASSERT_FALSE(active_layer_->CanHaveTilings());
1519
1520 // Update properties with solid color pile should not allow tilings at any
1521 // scale.
1522 host_impl_.active_tree()->UpdateDrawProperties();
1523 EXPECT_FALSE(active_layer_->CanHaveTilings()); 1558 EXPECT_FALSE(active_layer_->CanHaveTilings());
1524 EXPECT_EQ(0.f, active_layer_->ideal_contents_scale()); 1559 EXPECT_EQ(0.f, active_layer_->ideal_contents_scale());
1525 1560
1526 // Push non-solid-color pending pile makes active layer can have tilings. 1561 // Activate non-solid-color pending pile makes active layer can have tilings.
1527 active_layer_->UpdateRasterSource(pending_pile); 1562 ActivateTree();
1528 ASSERT_TRUE(active_layer_->CanHaveTilings());
1529
1530 // Update properties with non-solid color pile should allow tilings.
1531 host_impl_.active_tree()->UpdateDrawProperties();
1532 EXPECT_TRUE(active_layer_->CanHaveTilings()); 1563 EXPECT_TRUE(active_layer_->CanHaveTilings());
1533 EXPECT_GT(active_layer_->ideal_contents_scale(), 0.f); 1564 EXPECT_GT(active_layer_->ideal_contents_scale(), 0.f);
1534 } 1565 }
1535 1566
1536 TEST_F(PictureLayerImplTest, MarkRequiredOffscreenTiles) { 1567 TEST_F(NoLowResPictureLayerImplTest, MarkRequiredOffscreenTiles) {
1537 gfx::Size tile_size(100, 100); 1568 gfx::Size tile_size(100, 100);
1538 gfx::Size layer_bounds(200, 200); 1569 gfx::Size layer_bounds(200, 200);
1539 1570
1540 scoped_refptr<FakePicturePileImpl> pending_pile =
1541 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1542 SetupPendingTree(pending_pile);
1543
1544 gfx::Transform transform; 1571 gfx::Transform transform;
1545 gfx::Transform transform_for_tile_priority; 1572 gfx::Transform transform_for_tile_priority;
1546 bool resourceless_software_draw = false; 1573 bool resourceless_software_draw = false;
1547 gfx::Rect viewport(0, 0, 100, 200); 1574 gfx::Rect viewport(0, 0, 100, 200);
1548 host_impl_.SetExternalDrawConstraints(transform, 1575 host_impl_.SetExternalDrawConstraints(transform,
1549 viewport, 1576 viewport,
1550 viewport, 1577 viewport,
1551 viewport, 1578 viewport,
1552 transform, 1579 transform,
1553 resourceless_software_draw); 1580 resourceless_software_draw);
1554 1581
1555 pending_layer_->set_fixed_tile_size(tile_size); 1582 scoped_refptr<FakePicturePileImpl> pending_pile =
1556 ASSERT_TRUE(pending_layer_->CanHaveTilings()); 1583 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1557 PictureLayerTiling* tiling = pending_layer_->AddTiling(1.f); 1584 SetupPendingTreeWithFixedTileSize(pending_pile, tile_size, Region());
1558 host_impl_.pending_tree()->UpdateDrawProperties(); 1585
1586 EXPECT_EQ(1u, pending_layer_->num_tilings());
1559 EXPECT_EQ(viewport, pending_layer_->visible_rect_for_tile_priority()); 1587 EXPECT_EQ(viewport, pending_layer_->visible_rect_for_tile_priority());
1560 1588
1561 base::TimeTicks time_ticks; 1589 base::TimeTicks time_ticks;
1562 time_ticks += base::TimeDelta::FromMilliseconds(1); 1590 time_ticks += base::TimeDelta::FromMilliseconds(1);
1563 host_impl_.SetCurrentBeginFrameArgs( 1591 host_impl_.SetCurrentBeginFrameArgs(
1564 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks)); 1592 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
1565 pending_layer_->UpdateTiles(Occlusion(), resourceless_software_draw); 1593 pending_layer_->UpdateTiles(Occlusion(), resourceless_software_draw);
1566 EXPECT_EQ(HIGH_RESOLUTION, tiling->resolution());
1567 1594
1568 int num_visible = 0; 1595 int num_visible = 0;
1569 int num_offscreen = 0; 1596 int num_offscreen = 0;
1570 1597
1571 for (PictureLayerTiling::TilingRasterTileIterator iter(tiling); iter; 1598 for (PictureLayerTiling::TilingRasterTileIterator iter(
1572 ++iter) { 1599 pending_layer_->HighResTiling());
1600 iter; ++iter) {
1573 const Tile* tile = *iter; 1601 const Tile* tile = *iter;
1574 DCHECK(tile); 1602 DCHECK(tile);
1575 if (tile->priority(PENDING_TREE).distance_to_visible == 0.f) { 1603 if (tile->priority(PENDING_TREE).distance_to_visible == 0.f) {
1576 EXPECT_TRUE(tile->required_for_activation()); 1604 EXPECT_TRUE(tile->required_for_activation());
1577 num_visible++; 1605 num_visible++;
1578 } else { 1606 } else {
1579 EXPECT_FALSE(tile->required_for_activation()); 1607 EXPECT_FALSE(tile->required_for_activation());
1580 num_offscreen++; 1608 num_offscreen++;
1581 } 1609 }
1582 } 1610 }
1583 1611
1584 EXPECT_GT(num_visible, 0); 1612 EXPECT_GT(num_visible, 0);
1585 EXPECT_GT(num_offscreen, 0); 1613 EXPECT_GT(num_offscreen, 0);
1586 } 1614 }
1587 1615
1588 TEST_F(PictureLayerImplTest, TileOutsideOfViewportForTilePriorityNotRequired) { 1616 TEST_F(NoLowResPictureLayerImplTest,
1617 TileOutsideOfViewportForTilePriorityNotRequired) {
1589 base::TimeTicks time_ticks; 1618 base::TimeTicks time_ticks;
1590 time_ticks += base::TimeDelta::FromMilliseconds(1); 1619 time_ticks += base::TimeDelta::FromMilliseconds(1);
1591 host_impl_.SetCurrentBeginFrameArgs( 1620 host_impl_.SetCurrentBeginFrameArgs(
1592 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks)); 1621 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
1593 1622
1594 gfx::Size tile_size(100, 100); 1623 gfx::Size tile_size(100, 100);
1595 gfx::Size layer_bounds(400, 400); 1624 gfx::Size layer_bounds(400, 400);
1596 gfx::Rect external_viewport_for_tile_priority(400, 200); 1625 gfx::Rect external_viewport_for_tile_priority(400, 200);
1597 gfx::Rect visible_content_rect(200, 400); 1626 gfx::Rect visible_content_rect(200, 400);
1598 1627
1599 scoped_refptr<FakePicturePileImpl> active_pile = 1628 scoped_refptr<FakePicturePileImpl> active_pile =
1600 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 1629 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1601 scoped_refptr<FakePicturePileImpl> pending_pile = 1630 scoped_refptr<FakePicturePileImpl> pending_pile =
1602 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 1631 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1603 SetupTrees(pending_pile, active_pile); 1632 SetupTreesWithFixedTileSize(pending_pile, active_pile, tile_size, Region());
1604 1633
1605 active_layer_->set_fixed_tile_size(tile_size); 1634 ASSERT_EQ(1u, pending_layer_->num_tilings());
1606 pending_layer_->set_fixed_tile_size(tile_size); 1635 ASSERT_EQ(1.f, pending_layer_->HighResTiling()->contents_scale());
1607 ASSERT_TRUE(pending_layer_->CanHaveTilings());
1608 PictureLayerTiling* tiling = pending_layer_->AddTiling(1.f);
1609 1636
1610 // Set external viewport for tile priority. 1637 // Set external viewport for tile priority.
1611 gfx::Rect viewport = gfx::Rect(layer_bounds); 1638 gfx::Rect viewport = gfx::Rect(layer_bounds);
1612 gfx::Transform transform; 1639 gfx::Transform transform;
1613 gfx::Transform transform_for_tile_priority; 1640 gfx::Transform transform_for_tile_priority;
1614 bool resourceless_software_draw = false; 1641 bool resourceless_software_draw = false;
1615 host_impl_.SetExternalDrawConstraints(transform, 1642 host_impl_.SetExternalDrawConstraints(transform,
1616 viewport, 1643 viewport,
1617 viewport, 1644 viewport,
1618 external_viewport_for_tile_priority, 1645 external_viewport_for_tile_priority,
1619 transform_for_tile_priority, 1646 transform_for_tile_priority,
1620 resourceless_software_draw); 1647 resourceless_software_draw);
1648 time_ticks += base::TimeDelta::FromMilliseconds(1);
1649 host_impl_.SetCurrentBeginFrameArgs(
1650 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
1621 host_impl_.pending_tree()->UpdateDrawProperties(); 1651 host_impl_.pending_tree()->UpdateDrawProperties();
1622 1652
1623 // Set visible content rect that is different from 1653 // Set visible content rect that is different from
1624 // external_viewport_for_tile_priority. 1654 // external_viewport_for_tile_priority.
1625 pending_layer_->draw_properties().visible_content_rect = visible_content_rect; 1655 pending_layer_->draw_properties().visible_content_rect = visible_content_rect;
1626 time_ticks += base::TimeDelta::FromMilliseconds(200); 1656 time_ticks += base::TimeDelta::FromMilliseconds(200);
1627 host_impl_.SetCurrentBeginFrameArgs( 1657 host_impl_.SetCurrentBeginFrameArgs(
1628 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks)); 1658 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
1629 pending_layer_->UpdateTiles(Occlusion(), resourceless_software_draw); 1659 pending_layer_->UpdateTiles(Occlusion(), resourceless_software_draw);
1630 1660
1631 // Intersect the two rects. Any tile outside should not be required for 1661 // Intersect the two rects. Any tile outside should not be required for
1632 // activation. 1662 // activation.
1633 gfx::Rect viewport_for_tile_priority = 1663 gfx::Rect viewport_for_tile_priority =
1634 pending_layer_->GetViewportForTilePriorityInContentSpace(); 1664 pending_layer_->GetViewportForTilePriorityInContentSpace();
1635 viewport_for_tile_priority.Intersect(pending_layer_->visible_content_rect()); 1665 viewport_for_tile_priority.Intersect(pending_layer_->visible_content_rect());
1636 1666
1637 int num_inside = 0; 1667 int num_inside = 0;
1638 int num_outside = 0; 1668 int num_outside = 0;
1639 for (PictureLayerTiling::CoverageIterator iter( 1669 for (PictureLayerTiling::CoverageIterator iter(
1640 tiling, pending_layer_->contents_scale_x(), gfx::Rect(layer_bounds)); 1670 pending_layer_->HighResTiling(), 1.f, gfx::Rect(layer_bounds));
1641 iter; 1671 iter; ++iter) {
1642 ++iter) {
1643 if (!*iter) 1672 if (!*iter)
1644 continue; 1673 continue;
1645 Tile* tile = *iter; 1674 Tile* tile = *iter;
1646 if (viewport_for_tile_priority.Intersects(iter.geometry_rect())) { 1675 if (viewport_for_tile_priority.Intersects(iter.geometry_rect())) {
1647 num_inside++; 1676 num_inside++;
1648 // Mark everything in viewport for tile priority as ready to draw. 1677 // Mark everything in viewport for tile priority as ready to draw.
1649 ManagedTileState::DrawInfo& draw_info = tile->draw_info(); 1678 ManagedTileState::DrawInfo& draw_info = tile->draw_info();
1650 draw_info.SetSolidColorForTesting(SK_ColorRED); 1679 draw_info.SetSolidColorForTesting(SK_ColorRED);
1651 } else { 1680 } else {
1652 num_outside++; 1681 num_outside++;
(...skipping 23 matching lines...) Expand all
1676 1705
1677 TEST_F(PictureLayerImplTest, HighResTileIsComplete) { 1706 TEST_F(PictureLayerImplTest, HighResTileIsComplete) {
1678 base::TimeTicks time_ticks; 1707 base::TimeTicks time_ticks;
1679 time_ticks += base::TimeDelta::FromMilliseconds(1); 1708 time_ticks += base::TimeDelta::FromMilliseconds(1);
1680 host_impl_.SetCurrentBeginFrameArgs( 1709 host_impl_.SetCurrentBeginFrameArgs(
1681 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks)); 1710 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
1682 1711
1683 gfx::Size tile_size(100, 100); 1712 gfx::Size tile_size(100, 100);
1684 gfx::Size layer_bounds(200, 200); 1713 gfx::Size layer_bounds(200, 200);
1685 1714
1686 host_impl_.SetViewportSize(layer_bounds);
1687
1688 scoped_refptr<FakePicturePileImpl> pending_pile = 1715 scoped_refptr<FakePicturePileImpl> pending_pile =
1689 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 1716 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1690 SetupPendingTree(pending_pile); 1717
1718 SetupPendingTreeWithFixedTileSize(pending_pile, tile_size, Region());
1691 ActivateTree(); 1719 ActivateTree();
1692 1720
1693 // All high res tiles have resources. 1721 // All high res tiles have resources.
1694 active_layer_->set_fixed_tile_size(tile_size);
1695 host_impl_.active_tree()->UpdateDrawProperties();
1696 std::vector<Tile*> tiles = 1722 std::vector<Tile*> tiles =
1697 active_layer_->tilings()->tiling_at(0)->AllTilesForTesting(); 1723 active_layer_->tilings()->tiling_at(0)->AllTilesForTesting();
1698 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(tiles); 1724 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(tiles);
1699 1725
1700 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); 1726 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
1701 AppendQuadsData data; 1727 AppendQuadsData data;
1702 active_layer_->WillDraw(DRAW_MODE_SOFTWARE, nullptr); 1728 active_layer_->WillDraw(DRAW_MODE_SOFTWARE, nullptr);
1703 active_layer_->AppendQuads(render_pass.get(), Occlusion(), &data); 1729 active_layer_->AppendQuads(render_pass.get(), Occlusion(), &data);
1704 active_layer_->DidDraw(nullptr); 1730 active_layer_->DidDraw(nullptr);
1705 1731
1706 // All high res tiles drew, nothing was incomplete. 1732 // All high res tiles drew, nothing was incomplete.
1707 EXPECT_EQ(9u, render_pass->quad_list.size()); 1733 EXPECT_EQ(9u, render_pass->quad_list.size());
1708 EXPECT_EQ(0u, data.num_missing_tiles); 1734 EXPECT_EQ(0u, data.num_missing_tiles);
1709 EXPECT_EQ(0u, data.num_incomplete_tiles); 1735 EXPECT_EQ(0u, data.num_incomplete_tiles);
1710 EXPECT_FALSE(active_layer_->only_used_low_res_last_append_quads()); 1736 EXPECT_FALSE(active_layer_->only_used_low_res_last_append_quads());
1711 } 1737 }
1712 1738
1713 TEST_F(PictureLayerImplTest, HighResTileIsIncomplete) { 1739 TEST_F(PictureLayerImplTest, HighResTileIsIncomplete) {
1714 base::TimeTicks time_ticks; 1740 base::TimeTicks time_ticks;
1715 time_ticks += base::TimeDelta::FromMilliseconds(1); 1741 time_ticks += base::TimeDelta::FromMilliseconds(1);
1716 host_impl_.SetCurrentBeginFrameArgs( 1742 host_impl_.SetCurrentBeginFrameArgs(
1717 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks)); 1743 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
1718 1744
1719 gfx::Size tile_size(100, 100); 1745 gfx::Size tile_size(100, 100);
1720 gfx::Size layer_bounds(200, 200); 1746 gfx::Size layer_bounds(200, 200);
1721 1747
1722 host_impl_.SetViewportSize(layer_bounds);
1723
1724 scoped_refptr<FakePicturePileImpl> pending_pile = 1748 scoped_refptr<FakePicturePileImpl> pending_pile =
1725 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 1749 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1726 SetupPendingTree(pending_pile); 1750 SetupPendingTreeWithFixedTileSize(pending_pile, tile_size, Region());
1727 ActivateTree(); 1751 ActivateTree();
1728 1752
1729 active_layer_->set_fixed_tile_size(tile_size);
1730 host_impl_.active_tree()->UpdateDrawProperties();
1731
1732 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); 1753 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
1733 AppendQuadsData data; 1754 AppendQuadsData data;
1734 active_layer_->WillDraw(DRAW_MODE_SOFTWARE, nullptr); 1755 active_layer_->WillDraw(DRAW_MODE_SOFTWARE, nullptr);
1735 active_layer_->AppendQuads(render_pass.get(), Occlusion(), &data); 1756 active_layer_->AppendQuads(render_pass.get(), Occlusion(), &data);
1736 active_layer_->DidDraw(nullptr); 1757 active_layer_->DidDraw(nullptr);
1737 1758
1738 EXPECT_EQ(1u, render_pass->quad_list.size()); 1759 EXPECT_EQ(1u, render_pass->quad_list.size());
1739 EXPECT_EQ(1u, data.num_missing_tiles); 1760 EXPECT_EQ(1u, data.num_missing_tiles);
1740 EXPECT_EQ(0u, data.num_incomplete_tiles); 1761 EXPECT_EQ(0u, data.num_incomplete_tiles);
1741 EXPECT_TRUE(active_layer_->only_used_low_res_last_append_quads()); 1762 EXPECT_TRUE(active_layer_->only_used_low_res_last_append_quads());
1742 } 1763 }
1743 1764
1744 TEST_F(PictureLayerImplTest, HighResTileIsIncompleteLowResComplete) { 1765 TEST_F(PictureLayerImplTest, HighResTileIsIncompleteLowResComplete) {
1745 base::TimeTicks time_ticks; 1766 base::TimeTicks time_ticks;
1746 time_ticks += base::TimeDelta::FromMilliseconds(1); 1767 time_ticks += base::TimeDelta::FromMilliseconds(1);
1747 host_impl_.SetCurrentBeginFrameArgs( 1768 host_impl_.SetCurrentBeginFrameArgs(
1748 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks)); 1769 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
1749 1770
1750 gfx::Size tile_size(100, 100); 1771 gfx::Size tile_size(100, 100);
1751 gfx::Size layer_bounds(200, 200); 1772 gfx::Size layer_bounds(200, 200);
1752 1773
1753 host_impl_.SetViewportSize(layer_bounds);
1754
1755 scoped_refptr<FakePicturePileImpl> pending_pile = 1774 scoped_refptr<FakePicturePileImpl> pending_pile =
1756 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 1775 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1757 SetupPendingTree(pending_pile); 1776 SetupPendingTreeWithFixedTileSize(pending_pile, tile_size, Region());
1758 ActivateTree(); 1777 ActivateTree();
1759 1778
1760 active_layer_->set_fixed_tile_size(tile_size);
1761 host_impl_.active_tree()->UpdateDrawProperties();
1762 std::vector<Tile*> low_tiles = 1779 std::vector<Tile*> low_tiles =
1763 active_layer_->tilings()->tiling_at(1)->AllTilesForTesting(); 1780 active_layer_->tilings()->tiling_at(1)->AllTilesForTesting();
1764 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(low_tiles); 1781 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(low_tiles);
1765 1782
1766 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); 1783 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
1767 AppendQuadsData data; 1784 AppendQuadsData data;
1768 active_layer_->WillDraw(DRAW_MODE_SOFTWARE, nullptr); 1785 active_layer_->WillDraw(DRAW_MODE_SOFTWARE, nullptr);
1769 active_layer_->AppendQuads(render_pass.get(), Occlusion(), &data); 1786 active_layer_->AppendQuads(render_pass.get(), Occlusion(), &data);
1770 active_layer_->DidDraw(nullptr); 1787 active_layer_->DidDraw(nullptr);
1771 1788
1772 EXPECT_EQ(1u, render_pass->quad_list.size()); 1789 EXPECT_EQ(1u, render_pass->quad_list.size());
1773 EXPECT_EQ(0u, data.num_missing_tiles); 1790 EXPECT_EQ(0u, data.num_missing_tiles);
1774 EXPECT_EQ(1u, data.num_incomplete_tiles); 1791 EXPECT_EQ(1u, data.num_incomplete_tiles);
1775 EXPECT_TRUE(active_layer_->only_used_low_res_last_append_quads()); 1792 EXPECT_TRUE(active_layer_->only_used_low_res_last_append_quads());
1776 } 1793 }
1777 1794
1778 TEST_F(PictureLayerImplTest, LowResTileIsIncomplete) { 1795 TEST_F(PictureLayerImplTest, LowResTileIsIncomplete) {
1779 base::TimeTicks time_ticks; 1796 base::TimeTicks time_ticks;
1780 time_ticks += base::TimeDelta::FromMilliseconds(1); 1797 time_ticks += base::TimeDelta::FromMilliseconds(1);
1781 host_impl_.SetCurrentBeginFrameArgs( 1798 host_impl_.SetCurrentBeginFrameArgs(
1782 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks)); 1799 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
1783 1800
1784 gfx::Size tile_size(100, 100); 1801 gfx::Size tile_size(100, 100);
1785 gfx::Size layer_bounds(200, 200); 1802 gfx::Size layer_bounds(200, 200);
1786 1803
1787 host_impl_.SetViewportSize(layer_bounds);
1788
1789 scoped_refptr<FakePicturePileImpl> pending_pile = 1804 scoped_refptr<FakePicturePileImpl> pending_pile =
1790 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 1805 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1791 SetupPendingTree(pending_pile); 1806 SetupPendingTreeWithFixedTileSize(pending_pile, tile_size, Region());
1792 ActivateTree(); 1807 ActivateTree();
1793 1808
1794 // All high res tiles have resources except one. 1809 // All high res tiles have resources except one.
1795 active_layer_->set_fixed_tile_size(tile_size);
1796 host_impl_.active_tree()->UpdateDrawProperties();
1797 std::vector<Tile*> high_tiles = 1810 std::vector<Tile*> high_tiles =
1798 active_layer_->tilings()->tiling_at(0)->AllTilesForTesting(); 1811 active_layer_->tilings()->tiling_at(0)->AllTilesForTesting();
1799 high_tiles.erase(high_tiles.begin()); 1812 high_tiles.erase(high_tiles.begin());
1800 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(high_tiles); 1813 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(high_tiles);
1801 1814
1802 // All low res tiles have resources. 1815 // All low res tiles have resources.
1803 std::vector<Tile*> low_tiles = 1816 std::vector<Tile*> low_tiles =
1804 active_layer_->tilings()->tiling_at(1)->AllTilesForTesting(); 1817 active_layer_->tilings()->tiling_at(1)->AllTilesForTesting();
1805 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(low_tiles); 1818 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(low_tiles);
1806 1819
(...skipping 12 matching lines...) Expand all
1819 1832
1820 TEST_F(PictureLayerImplTest, 1833 TEST_F(PictureLayerImplTest,
1821 HighResAndIdealResTileIsCompleteWhenRasterScaleIsNotIdeal) { 1834 HighResAndIdealResTileIsCompleteWhenRasterScaleIsNotIdeal) {
1822 base::TimeTicks time_ticks; 1835 base::TimeTicks time_ticks;
1823 time_ticks += base::TimeDelta::FromMilliseconds(1); 1836 time_ticks += base::TimeDelta::FromMilliseconds(1);
1824 host_impl_.SetCurrentBeginFrameArgs( 1837 host_impl_.SetCurrentBeginFrameArgs(
1825 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks)); 1838 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
1826 1839
1827 gfx::Size tile_size(100, 100); 1840 gfx::Size tile_size(100, 100);
1828 gfx::Size layer_bounds(200, 200); 1841 gfx::Size layer_bounds(200, 200);
1842 gfx::Size viewport_size(400, 400);
1829 1843
1830 host_impl_.SetViewportSize(layer_bounds); 1844 host_impl_.SetViewportSize(viewport_size);
1845 host_impl_.SetDeviceScaleFactor(2.f);
1831 1846
1832 scoped_refptr<FakePicturePileImpl> pending_pile = 1847 scoped_refptr<FakePicturePileImpl> pending_pile =
1833 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 1848 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1834 scoped_refptr<FakePicturePileImpl> active_pile = 1849 scoped_refptr<FakePicturePileImpl> active_pile =
1835 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 1850 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1836 SetupTrees(pending_pile, active_pile); 1851 SetupTreesWithFixedTileSize(pending_pile, active_pile, tile_size, Region());
1837
1838 active_layer_->set_fixed_tile_size(tile_size);
1839
1840 active_layer_->draw_properties().visible_content_rect =
1841 gfx::Rect(layer_bounds);
1842 SetupDrawPropertiesAndUpdateTiles(active_layer_, 2.f, 1.f, 1.f, 1.f, false);
1843 1852
1844 // One ideal tile exists, this will get used when drawing. 1853 // One ideal tile exists, this will get used when drawing.
1845 std::vector<Tile*> ideal_tiles; 1854 std::vector<Tile*> ideal_tiles;
1846 EXPECT_EQ(2.f, active_layer_->HighResTiling()->contents_scale()); 1855 EXPECT_EQ(2.f, active_layer_->HighResTiling()->contents_scale());
1847 ideal_tiles.push_back(active_layer_->HighResTiling()->TileAt(0, 0)); 1856 ideal_tiles.push_back(active_layer_->HighResTiling()->TileAt(0, 0));
1848 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting( 1857 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(
1849 ideal_tiles); 1858 ideal_tiles);
1850 1859
1851 // Due to layer scale throttling, the raster contents scale is changed to 1, 1860 // Due to layer scale throttling, the raster contents scale is changed to 1,
1852 // while the ideal is still 2. 1861 // while the ideal is still 2.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1884 // Neither the high res nor the ideal tiles were considered as incomplete. 1893 // Neither the high res nor the ideal tiles were considered as incomplete.
1885 EXPECT_EQ(0u, data.num_missing_tiles); 1894 EXPECT_EQ(0u, data.num_missing_tiles);
1886 EXPECT_EQ(0u, data.num_incomplete_tiles); 1895 EXPECT_EQ(0u, data.num_incomplete_tiles);
1887 EXPECT_FALSE(active_layer_->only_used_low_res_last_append_quads()); 1896 EXPECT_FALSE(active_layer_->only_used_low_res_last_append_quads());
1888 } 1897 }
1889 1898
1890 TEST_F(PictureLayerImplTest, HighResRequiredWhenUnsharedActiveAllReady) { 1899 TEST_F(PictureLayerImplTest, HighResRequiredWhenUnsharedActiveAllReady) {
1891 gfx::Size layer_bounds(400, 400); 1900 gfx::Size layer_bounds(400, 400);
1892 gfx::Size tile_size(100, 100); 1901 gfx::Size tile_size(100, 100);
1893 1902
1894 host_impl_.SetViewportSize(layer_bounds);
1895
1896 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size);
1897
1898 // No tiles shared. 1903 // No tiles shared.
1899 pending_layer_->set_invalidation(gfx::Rect(layer_bounds)); 1904 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size,
1900 1905 gfx::Rect(layer_bounds));
1901 CreateHighLowResAndSetAllTilesVisible();
1902 1906
1903 active_layer_->SetAllTilesReady(); 1907 active_layer_->SetAllTilesReady();
1904 1908
1905 // No shared tiles and all active tiles ready, so pending can only 1909 // No shared tiles and all active tiles ready, so pending can only
1906 // activate with all high res tiles. 1910 // activate with all high res tiles.
1907 pending_layer_->HighResTiling()->UpdateAllTilePrioritiesForTesting(); 1911 pending_layer_->HighResTiling()->UpdateAllTilePrioritiesForTesting();
1908 pending_layer_->LowResTiling()->UpdateAllTilePrioritiesForTesting(); 1912 pending_layer_->LowResTiling()->UpdateAllTilePrioritiesForTesting();
1909 1913
1910 AssertAllTilesRequired(pending_layer_->HighResTiling()); 1914 AssertAllTilesRequired(pending_layer_->HighResTiling());
1911 AssertNoTilesRequired(pending_layer_->LowResTiling()); 1915 AssertNoTilesRequired(pending_layer_->LowResTiling());
1912 } 1916 }
1913 1917
1914 TEST_F(PictureLayerImplTest, HighResRequiredWhenMissingHighResFlagOn) { 1918 TEST_F(PictureLayerImplTest, HighResRequiredWhenMissingHighResFlagOn) {
1915 gfx::Size layer_bounds(400, 400); 1919 gfx::Size layer_bounds(400, 400);
1916 gfx::Size tile_size(100, 100); 1920 gfx::Size tile_size(100, 100);
1917 1921
1918 host_impl_.SetViewportSize(layer_bounds);
1919
1920 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size);
1921
1922 // All tiles shared (no invalidation). 1922 // All tiles shared (no invalidation).
1923 CreateHighLowResAndSetAllTilesVisible(); 1923 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, Region());
1924 1924
1925 // Verify active tree not ready. 1925 // Verify active tree not ready.
1926 Tile* some_active_tile = 1926 Tile* some_active_tile =
1927 active_layer_->HighResTiling()->AllTilesForTesting()[0]; 1927 active_layer_->HighResTiling()->AllTilesForTesting()[0];
1928 EXPECT_FALSE(some_active_tile->IsReadyToDraw()); 1928 EXPECT_FALSE(some_active_tile->IsReadyToDraw());
1929 1929
1930 // When high res are required, even if the active tree is not ready, 1930 // When high res are required, even if the active tree is not ready,
1931 // the high res tiles must be ready. 1931 // the high res tiles must be ready.
1932 host_impl_.SetRequiresHighResToDraw(); 1932 host_impl_.SetRequiresHighResToDraw();
1933 1933
1934 pending_layer_->HighResTiling()->UpdateAllTilePrioritiesForTesting(); 1934 pending_layer_->HighResTiling()->UpdateAllTilePrioritiesForTesting();
1935 pending_layer_->LowResTiling()->UpdateAllTilePrioritiesForTesting(); 1935 pending_layer_->LowResTiling()->UpdateAllTilePrioritiesForTesting();
1936 1936
1937 AssertAllTilesRequired(pending_layer_->HighResTiling()); 1937 AssertAllTilesRequired(pending_layer_->HighResTiling());
1938 AssertNoTilesRequired(pending_layer_->LowResTiling()); 1938 AssertNoTilesRequired(pending_layer_->LowResTiling());
1939 } 1939 }
1940 1940
1941 TEST_F(PictureLayerImplTest, AllHighResRequiredEvenIfShared) { 1941 TEST_F(PictureLayerImplTest, AllHighResRequiredEvenIfShared) {
1942 gfx::Size layer_bounds(400, 400); 1942 gfx::Size layer_bounds(400, 400);
1943 gfx::Size tile_size(100, 100); 1943 gfx::Size tile_size(100, 100);
1944 1944
1945 host_impl_.SetViewportSize(layer_bounds); 1945 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, Region());
1946
1947 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size);
1948
1949 CreateHighLowResAndSetAllTilesVisible();
1950 1946
1951 Tile* some_active_tile = 1947 Tile* some_active_tile =
1952 active_layer_->HighResTiling()->AllTilesForTesting()[0]; 1948 active_layer_->HighResTiling()->AllTilesForTesting()[0];
1953 EXPECT_FALSE(some_active_tile->IsReadyToDraw()); 1949 EXPECT_FALSE(some_active_tile->IsReadyToDraw());
1954 1950
1955 // All tiles shared (no invalidation), so even though the active tree's 1951 // All tiles shared (no invalidation), so even though the active tree's
1956 // tiles aren't ready, the high res tiles are required for activation. 1952 // tiles aren't ready, the high res tiles are required for activation.
1957 pending_layer_->HighResTiling()->UpdateAllTilePrioritiesForTesting(); 1953 pending_layer_->HighResTiling()->UpdateAllTilePrioritiesForTesting();
1958 pending_layer_->LowResTiling()->UpdateAllTilePrioritiesForTesting(); 1954 pending_layer_->LowResTiling()->UpdateAllTilePrioritiesForTesting();
1959 1955
1960 AssertAllTilesRequired(pending_layer_->HighResTiling()); 1956 AssertAllTilesRequired(pending_layer_->HighResTiling());
1961 AssertNoTilesRequired(pending_layer_->LowResTiling()); 1957 AssertNoTilesRequired(pending_layer_->LowResTiling());
1962 } 1958 }
1963 1959
1964 TEST_F(PictureLayerImplTest, DisallowRequiredForActivation) { 1960 TEST_F(PictureLayerImplTest, DisallowRequiredForActivation) {
1965 gfx::Size layer_bounds(400, 400); 1961 gfx::Size layer_bounds(400, 400);
1966 gfx::Size tile_size(100, 100); 1962 gfx::Size tile_size(100, 100);
1967 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size);
1968 1963
1969 CreateHighLowResAndSetAllTilesVisible(); 1964 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, Region());
1970 1965
1971 Tile* some_active_tile = 1966 Tile* some_active_tile =
1972 active_layer_->HighResTiling()->AllTilesForTesting()[0]; 1967 active_layer_->HighResTiling()->AllTilesForTesting()[0];
1973 EXPECT_FALSE(some_active_tile->IsReadyToDraw()); 1968 EXPECT_FALSE(some_active_tile->IsReadyToDraw());
1974 1969
1975 pending_layer_->HighResTiling()->set_can_require_tiles_for_activation(false); 1970 pending_layer_->HighResTiling()->set_can_require_tiles_for_activation(false);
1976 pending_layer_->LowResTiling()->set_can_require_tiles_for_activation(false); 1971 pending_layer_->LowResTiling()->set_can_require_tiles_for_activation(false);
1977 1972
1978 // If we disallow required for activation, no tiles can be required. 1973 // If we disallow required for activation, no tiles can be required.
1979 pending_layer_->HighResTiling()->UpdateAllTilePrioritiesForTesting(); 1974 pending_layer_->HighResTiling()->UpdateAllTilePrioritiesForTesting();
1980 pending_layer_->LowResTiling()->UpdateAllTilePrioritiesForTesting(); 1975 pending_layer_->LowResTiling()->UpdateAllTilePrioritiesForTesting();
1981 1976
1982 AssertNoTilesRequired(pending_layer_->HighResTiling()); 1977 AssertNoTilesRequired(pending_layer_->HighResTiling());
1983 AssertNoTilesRequired(pending_layer_->LowResTiling()); 1978 AssertNoTilesRequired(pending_layer_->LowResTiling());
1984 } 1979 }
1985 1980
1986 TEST_F(PictureLayerImplTest, NothingRequiredIfActiveMissingTiles) { 1981 TEST_F(PictureLayerImplTest, NothingRequiredIfActiveMissingTiles) {
1987 gfx::Size layer_bounds(400, 400); 1982 gfx::Size layer_bounds(400, 400);
1988 gfx::Size tile_size(100, 100); 1983 gfx::Size tile_size(100, 100);
1984
1989 scoped_refptr<FakePicturePileImpl> pending_pile = 1985 scoped_refptr<FakePicturePileImpl> pending_pile =
1990 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 1986 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1991 // This pile will create tilings, but has no recordings so will not create any 1987 // This pile will create tilings, but has no recordings so will not create any
1992 // tiles. This is attempting to simulate scrolling past the end of recorded 1988 // tiles. This is attempting to simulate scrolling past the end of recorded
1993 // content on the active layer, where the recordings are so far away that 1989 // content on the active layer, where the recordings are so far away that
1994 // no tiles are created. 1990 // no tiles are created.
1995 scoped_refptr<FakePicturePileImpl> active_pile = 1991 scoped_refptr<FakePicturePileImpl> active_pile =
1996 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings( 1992 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings(
1997 tile_size, layer_bounds); 1993 tile_size, layer_bounds);
1998 SetupTrees(pending_pile, active_pile);
1999 pending_layer_->set_fixed_tile_size(tile_size);
2000 active_layer_->set_fixed_tile_size(tile_size);
2001 1994
2002 CreateHighLowResAndSetAllTilesVisible(); 1995 SetupTreesWithFixedTileSize(pending_pile, active_pile, tile_size, Region());
2003 1996
2004 // Active layer has tilings, but no tiles due to missing recordings. 1997 // Active layer has tilings, but no tiles due to missing recordings.
2005 EXPECT_TRUE(active_layer_->CanHaveTilings()); 1998 EXPECT_TRUE(active_layer_->CanHaveTilings());
2006 EXPECT_EQ(active_layer_->tilings()->num_tilings(), 2u); 1999 EXPECT_EQ(active_layer_->tilings()->num_tilings(), 2u);
2007 EXPECT_EQ(active_layer_->HighResTiling()->AllTilesForTesting().size(), 0u); 2000 EXPECT_EQ(active_layer_->HighResTiling()->AllTilesForTesting().size(), 0u);
2008 2001
2009 // Since the active layer has no tiles at all, the pending layer doesn't 2002 // Since the active layer has no tiles at all, the pending layer doesn't
2010 // need content in order to activate. 2003 // need content in order to activate.
2011 pending_layer_->HighResTiling()->UpdateAllTilePrioritiesForTesting(); 2004 pending_layer_->HighResTiling()->UpdateAllTilePrioritiesForTesting();
2012 pending_layer_->LowResTiling()->UpdateAllTilePrioritiesForTesting(); 2005 pending_layer_->LowResTiling()->UpdateAllTilePrioritiesForTesting();
2013 2006
2014 AssertNoTilesRequired(pending_layer_->HighResTiling()); 2007 AssertNoTilesRequired(pending_layer_->HighResTiling());
2015 AssertNoTilesRequired(pending_layer_->LowResTiling()); 2008 AssertNoTilesRequired(pending_layer_->LowResTiling());
2016 } 2009 }
2017 2010
2018 TEST_F(PictureLayerImplTest, HighResRequiredIfActiveCantHaveTiles) { 2011 TEST_F(PictureLayerImplTest, HighResRequiredIfActiveCantHaveTiles) {
2019 gfx::Size layer_bounds(400, 400); 2012 gfx::Size layer_bounds(400, 400);
2020 gfx::Size tile_size(100, 100); 2013 gfx::Size tile_size(100, 100);
2021 2014
2022 host_impl_.SetViewportSize(layer_bounds);
2023
2024 scoped_refptr<FakePicturePileImpl> pending_pile = 2015 scoped_refptr<FakePicturePileImpl> pending_pile =
2025 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 2016 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2026 scoped_refptr<FakePicturePileImpl> active_pile = 2017 scoped_refptr<FakePicturePileImpl> active_pile =
2027 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); 2018 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds);
2028 SetupTrees(pending_pile, active_pile); 2019 SetupTreesWithFixedTileSize(pending_pile, active_pile, tile_size, Region());
2029 pending_layer_->set_fixed_tile_size(tile_size);
2030 active_layer_->set_fixed_tile_size(tile_size);
2031
2032 CreateHighLowResAndSetAllTilesVisible();
2033 2020
2034 // Active layer can't have tiles. 2021 // Active layer can't have tiles.
2035 EXPECT_FALSE(active_layer_->CanHaveTilings()); 2022 EXPECT_FALSE(active_layer_->CanHaveTilings());
2036 2023
2037 // All high res tiles required. This should be considered identical 2024 // All high res tiles required. This should be considered identical
2038 // to the case where there is no active layer, to avoid flashing content. 2025 // to the case where there is no active layer, to avoid flashing content.
2039 // This can happen if a layer exists for a while and switches from 2026 // This can happen if a layer exists for a while and switches from
2040 // not being able to have content to having content. 2027 // not being able to have content to having content.
2041 pending_layer_->HighResTiling()->UpdateAllTilePrioritiesForTesting(); 2028 pending_layer_->HighResTiling()->UpdateAllTilePrioritiesForTesting();
2042 pending_layer_->LowResTiling()->UpdateAllTilePrioritiesForTesting(); 2029 pending_layer_->LowResTiling()->UpdateAllTilePrioritiesForTesting();
2043 2030
2044 AssertAllTilesRequired(pending_layer_->HighResTiling()); 2031 AssertAllTilesRequired(pending_layer_->HighResTiling());
2045 AssertNoTilesRequired(pending_layer_->LowResTiling()); 2032 AssertNoTilesRequired(pending_layer_->LowResTiling());
2046 } 2033 }
2047 2034
2048 TEST_F(PictureLayerImplTest, HighResRequiredWhenActiveHasDifferentBounds) { 2035 TEST_F(PictureLayerImplTest, HighResRequiredWhenActiveHasDifferentBounds) {
2049 gfx::Size layer_bounds(200, 200); 2036 gfx::Size pending_layer_bounds(400, 400);
2037 gfx::Size active_layer_bounds(200, 200);
2050 gfx::Size tile_size(100, 100); 2038 gfx::Size tile_size(100, 100);
2051 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size);
2052 2039
2053 gfx::Size pending_layer_bounds(400, 400); 2040 scoped_refptr<FakePicturePileImpl> pending_pile =
2054 pending_layer_->SetBounds(pending_layer_bounds); 2041 FakePicturePileImpl::CreateFilledPile(tile_size, pending_layer_bounds);
2042 scoped_refptr<FakePicturePileImpl> active_pile =
2043 FakePicturePileImpl::CreateFilledPile(tile_size, active_layer_bounds);
2055 2044
2056 CreateHighLowResAndSetAllTilesVisible(); 2045 SetupTreesWithFixedTileSize(pending_pile, active_pile, tile_size, Region());
2057 // TODO(vmpstr): This is confusing. Rework the test to create different bounds
2058 // on different trees instead of fudging tilings.
2059 pending_layer_->HighResTiling()->ComputeTilePriorityRects(
2060 gfx::Rect(pending_layer_bounds), 1.f, 1.f, Occlusion());
2061
2062 pending_layer_->HighResTiling()->UpdateAllTilePrioritiesForTesting();
2063 active_layer_->SetAllTilesReady();
2064 2046
2065 // Since the active layer has different bounds, the pending layer needs all 2047 // Since the active layer has different bounds, the pending layer needs all
2066 // high res tiles in order to activate. 2048 // high res tiles in order to activate.
2067 pending_layer_->HighResTiling()->UpdateAllTilePrioritiesForTesting(); 2049 pending_layer_->HighResTiling()->UpdateAllTilePrioritiesForTesting();
2068 pending_layer_->LowResTiling()->UpdateAllTilePrioritiesForTesting(); 2050 pending_layer_->LowResTiling()->UpdateAllTilePrioritiesForTesting();
2069 2051
2070 AssertAllTilesRequired(pending_layer_->HighResTiling()); 2052 AssertAllTilesRequired(pending_layer_->HighResTiling());
2071 AssertNoTilesRequired(pending_layer_->LowResTiling()); 2053 AssertNoTilesRequired(pending_layer_->LowResTiling());
2072 } 2054 }
2073 2055
(...skipping 27 matching lines...) Expand all
2101 2083
2102 active_layer_ = static_cast<FakePictureLayerImpl*>( 2084 active_layer_ = static_cast<FakePictureLayerImpl*>(
2103 host_impl_.active_tree()->LayerById(id_)); 2085 host_impl_.active_tree()->LayerById(id_));
2104 2086
2105 EXPECT_EQ(0u, active_layer_->num_tilings()); 2087 EXPECT_EQ(0u, active_layer_->num_tilings());
2106 EXPECT_EQ(raster_page_scale, active_layer_->raster_page_scale()); 2088 EXPECT_EQ(raster_page_scale, active_layer_->raster_page_scale());
2107 EXPECT_FALSE(active_layer_->needs_post_commit_initialization()); 2089 EXPECT_FALSE(active_layer_->needs_post_commit_initialization());
2108 } 2090 }
2109 2091
2110 TEST_F(PictureLayerImplTest, ShareTilesOnNextFrame) { 2092 TEST_F(PictureLayerImplTest, ShareTilesOnNextFrame) {
2111 SetupDefaultTrees(gfx::Size(1500, 1500)); 2093 gfx::Size layer_bounds(1500, 1500);
2094 gfx::Size tile_size(100, 100);
2112 2095
2113 PictureLayerTiling* tiling = pending_layer_->AddTiling(1.f); 2096 scoped_refptr<FakePicturePileImpl> pending_pile =
2097 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2098
2099 SetupPendingTree(pending_pile);
2100
2101 PictureLayerTiling* tiling = pending_layer_->HighResTiling();
2114 gfx::Rect first_invalidate = tiling->TilingDataForTesting().TileBounds(0, 0); 2102 gfx::Rect first_invalidate = tiling->TilingDataForTesting().TileBounds(0, 0);
2115 first_invalidate.Inset(tiling->TilingDataForTesting().border_texels(), 2103 first_invalidate.Inset(tiling->TilingDataForTesting().border_texels(),
2116 tiling->TilingDataForTesting().border_texels()); 2104 tiling->TilingDataForTesting().border_texels());
2117 gfx::Rect second_invalidate = tiling->TilingDataForTesting().TileBounds(1, 1); 2105 gfx::Rect second_invalidate = tiling->TilingDataForTesting().TileBounds(1, 1);
2118 second_invalidate.Inset(tiling->TilingDataForTesting().border_texels(), 2106 second_invalidate.Inset(tiling->TilingDataForTesting().border_texels(),
2119 tiling->TilingDataForTesting().border_texels()); 2107 tiling->TilingDataForTesting().border_texels());
2120 2108
2109 ActivateTree();
2110
2121 // Make a pending tree with an invalidated raster tile 0,0. 2111 // Make a pending tree with an invalidated raster tile 0,0.
2122 tiling->CreateAllTilesForTesting(); 2112 SetupPendingTreeWithInvalidation(pending_pile, first_invalidate);
2123 pending_layer_->set_invalidation(first_invalidate);
2124 2113
2125 // Activate and make a pending tree with an invalidated raster tile 1,1. 2114 // Activate and make a pending tree with an invalidated raster tile 1,1.
2126 ActivateTree(); 2115 ActivateTree();
2127 2116
2128 host_impl_.CreatePendingTree(); 2117 SetupPendingTreeWithInvalidation(pending_pile, second_invalidate);
2129 pending_layer_ = static_cast<FakePictureLayerImpl*>(
2130 host_impl_.pending_tree()->root_layer());
2131 pending_layer_->set_invalidation(second_invalidate);
2132 2118
2133 PictureLayerTiling* pending_tiling = pending_layer_->tilings()->tiling_at(0); 2119 PictureLayerTiling* pending_tiling = pending_layer_->tilings()->tiling_at(0);
2134 PictureLayerTiling* active_tiling = active_layer_->tilings()->tiling_at(0); 2120 PictureLayerTiling* active_tiling = active_layer_->tilings()->tiling_at(0);
2135 2121
2136 pending_tiling->CreateAllTilesForTesting(); 2122 // pending_tiling->CreateAllTilesForTesting();
2137 2123
2138 // Tile 0,0 should be shared, but tile 1,1 should not be. 2124 // Tile 0,0 should be shared, but tile 1,1 should not be.
2139 EXPECT_EQ(active_tiling->TileAt(0, 0), pending_tiling->TileAt(0, 0)); 2125 EXPECT_EQ(active_tiling->TileAt(0, 0), pending_tiling->TileAt(0, 0));
2140 EXPECT_EQ(active_tiling->TileAt(1, 0), pending_tiling->TileAt(1, 0)); 2126 EXPECT_EQ(active_tiling->TileAt(1, 0), pending_tiling->TileAt(1, 0));
2141 EXPECT_EQ(active_tiling->TileAt(0, 1), pending_tiling->TileAt(0, 1)); 2127 EXPECT_EQ(active_tiling->TileAt(0, 1), pending_tiling->TileAt(0, 1));
2142 EXPECT_NE(active_tiling->TileAt(1, 1), pending_tiling->TileAt(1, 1)); 2128 EXPECT_NE(active_tiling->TileAt(1, 1), pending_tiling->TileAt(1, 1));
2143 EXPECT_TRUE(pending_tiling->TileAt(0, 0)->is_shared()); 2129 EXPECT_TRUE(pending_tiling->TileAt(0, 0)->is_shared());
2144 EXPECT_TRUE(pending_tiling->TileAt(1, 0)->is_shared()); 2130 EXPECT_TRUE(pending_tiling->TileAt(1, 0)->is_shared());
2145 EXPECT_TRUE(pending_tiling->TileAt(0, 1)->is_shared()); 2131 EXPECT_TRUE(pending_tiling->TileAt(0, 1)->is_shared());
2146 EXPECT_FALSE(pending_tiling->TileAt(1, 1)->is_shared()); 2132 EXPECT_FALSE(pending_tiling->TileAt(1, 1)->is_shared());
2147 2133
2148 // Drop the tiles on the active tree and recreate them. The same tiles 2134 // Drop the tiles on the active tree and recreate them. The same tiles
2149 // should be shared or not. 2135 // should be shared or not.
2150 active_tiling->ComputeTilePriorityRects(gfx::Rect(), 1.f, 1.0, Occlusion()); 2136 active_tiling->ComputeTilePriorityRects(gfx::Rect(), 1.f, 1.0, Occlusion());
2151 EXPECT_TRUE(active_tiling->AllTilesForTesting().empty()); 2137 EXPECT_TRUE(active_tiling->AllTilesForTesting().empty());
2152 active_tiling->CreateAllTilesForTesting(); 2138 active_tiling->CreateAllTilesForTesting();
2153 2139
2154 // Tile 0,0 should be shared, but tile 1,1 should not be. 2140 // Tile 0,0 should be shared, but tile 1,1 should not be.
2155 EXPECT_EQ(active_tiling->TileAt(0, 0), pending_tiling->TileAt(0, 0)); 2141 EXPECT_EQ(active_tiling->TileAt(0, 0), pending_tiling->TileAt(0, 0));
2156 EXPECT_EQ(active_tiling->TileAt(1, 0), pending_tiling->TileAt(1, 0)); 2142 EXPECT_EQ(active_tiling->TileAt(1, 0), pending_tiling->TileAt(1, 0));
2157 EXPECT_EQ(active_tiling->TileAt(0, 1), pending_tiling->TileAt(0, 1)); 2143 EXPECT_EQ(active_tiling->TileAt(0, 1), pending_tiling->TileAt(0, 1));
2158 EXPECT_NE(active_tiling->TileAt(1, 1), pending_tiling->TileAt(1, 1)); 2144 EXPECT_NE(active_tiling->TileAt(1, 1), pending_tiling->TileAt(1, 1));
2159 EXPECT_TRUE(pending_tiling->TileAt(0, 0)->is_shared()); 2145 EXPECT_TRUE(pending_tiling->TileAt(0, 0)->is_shared());
2160 EXPECT_TRUE(pending_tiling->TileAt(1, 0)->is_shared()); 2146 EXPECT_TRUE(pending_tiling->TileAt(1, 0)->is_shared());
2161 EXPECT_TRUE(pending_tiling->TileAt(0, 1)->is_shared()); 2147 EXPECT_TRUE(pending_tiling->TileAt(0, 1)->is_shared());
2162 EXPECT_FALSE(pending_tiling->TileAt(1, 1)->is_shared()); 2148 EXPECT_FALSE(pending_tiling->TileAt(1, 1)->is_shared());
2163 } 2149 }
2164 2150
2165 TEST_F(PictureLayerImplTest, ShareTilesOnSync) { 2151 TEST_F(PictureLayerImplTest, ShareTilesWithNoInvalidation) {
2166 SetupDefaultTrees(gfx::Size(1500, 1500)); 2152 SetupDefaultTrees(gfx::Size(1500, 1500));
2167 AddDefaultTilingsWithInvalidation(gfx::Rect());
2168 2153
2169 host_impl_.ActivateSyncTree(); 2154 EXPECT_GE(active_layer_->num_tilings(), 1u);
2170 host_impl_.CreatePendingTree(); 2155 EXPECT_GE(pending_layer_->num_tilings(), 1u);
2171 active_layer_ = static_cast<FakePictureLayerImpl*>(
2172 host_impl_.active_tree()->LayerById(id_));
2173 2156
2174 // Force the active tree to sync to the pending tree "post-commit". 2157 // No invalidation, so all tiles are shared.
2175 pending_layer_->DoPostCommitInitializationIfNeeded(); 2158 PictureLayerTiling* active_tiling = active_layer_->tilings()->tiling_at(0);
2159 PictureLayerTiling* pending_tiling = pending_layer_->tilings()->tiling_at(0);
2160 ASSERT_TRUE(active_tiling);
2161 ASSERT_TRUE(pending_tiling);
2176 2162
2177 // Both invalidations should drop tiles from the pending tree. 2163 EXPECT_TRUE(active_tiling->TileAt(0, 0));
2178 EXPECT_EQ(3u, active_layer_->num_tilings()); 2164 EXPECT_TRUE(active_tiling->TileAt(1, 0));
2179 EXPECT_EQ(3u, pending_layer_->num_tilings()); 2165 EXPECT_TRUE(active_tiling->TileAt(0, 1));
2180 for (size_t i = 0; i < active_layer_->num_tilings(); ++i) { 2166 EXPECT_TRUE(active_tiling->TileAt(1, 1));
2181 PictureLayerTiling* active_tiling = active_layer_->tilings()->tiling_at(i);
2182 PictureLayerTiling* pending_tiling =
2183 pending_layer_->tilings()->tiling_at(i);
2184 2167
2185 ASSERT_TRUE(active_tiling); 2168 EXPECT_TRUE(pending_tiling->TileAt(0, 0));
2186 ASSERT_TRUE(pending_tiling); 2169 EXPECT_TRUE(pending_tiling->TileAt(1, 0));
2170 EXPECT_TRUE(pending_tiling->TileAt(0, 1));
2171 EXPECT_TRUE(pending_tiling->TileAt(1, 1));
2187 2172
2188 EXPECT_TRUE(active_tiling->TileAt(0, 0)); 2173 EXPECT_EQ(active_tiling->TileAt(0, 0), pending_tiling->TileAt(0, 0));
2189 EXPECT_TRUE(active_tiling->TileAt(1, 0)); 2174 EXPECT_TRUE(active_tiling->TileAt(0, 0)->is_shared());
2190 EXPECT_TRUE(active_tiling->TileAt(0, 1)); 2175 EXPECT_EQ(active_tiling->TileAt(1, 0), pending_tiling->TileAt(1, 0));
2191 EXPECT_TRUE(active_tiling->TileAt(1, 1)); 2176 EXPECT_TRUE(active_tiling->TileAt(1, 0)->is_shared());
2192 2177 EXPECT_EQ(active_tiling->TileAt(0, 1), pending_tiling->TileAt(0, 1));
2193 EXPECT_TRUE(pending_tiling->TileAt(0, 0)); 2178 EXPECT_TRUE(active_tiling->TileAt(0, 1)->is_shared());
2194 EXPECT_TRUE(pending_tiling->TileAt(1, 0)); 2179 EXPECT_EQ(active_tiling->TileAt(1, 1), pending_tiling->TileAt(1, 1));
2195 EXPECT_TRUE(pending_tiling->TileAt(0, 1)); 2180 EXPECT_TRUE(active_tiling->TileAt(1, 1)->is_shared());
2196 EXPECT_TRUE(pending_tiling->TileAt(1, 1));
2197
2198 EXPECT_EQ(active_tiling->TileAt(0, 0), pending_tiling->TileAt(0, 0));
2199 EXPECT_TRUE(active_tiling->TileAt(0, 0)->is_shared());
2200 EXPECT_EQ(active_tiling->TileAt(1, 0), pending_tiling->TileAt(1, 0));
2201 EXPECT_TRUE(active_tiling->TileAt(1, 0)->is_shared());
2202 EXPECT_EQ(active_tiling->TileAt(0, 1), pending_tiling->TileAt(0, 1));
2203 EXPECT_TRUE(active_tiling->TileAt(0, 1)->is_shared());
2204 EXPECT_EQ(active_tiling->TileAt(1, 1), pending_tiling->TileAt(1, 1));
2205 EXPECT_TRUE(active_tiling->TileAt(1, 1)->is_shared());
2206 }
2207 } 2181 }
2208 2182
2209 TEST_F(PictureLayerImplTest, ShareInvalidActiveTreeTilesOnSync) { 2183 TEST_F(PictureLayerImplTest, ShareInvalidActiveTreeTiles) {
2210 SetupDefaultTrees(gfx::Size(1500, 1500)); 2184 gfx::Size tile_size(100, 100);
2211 AddDefaultTilingsWithInvalidation(gfx::Rect(0, 0, 1, 1)); 2185 gfx::Size layer_bounds(1500, 1500);
2212 2186
2213 // This activates the 0,0,1,1 invalidation. 2187 scoped_refptr<FakePicturePileImpl> pending_pile =
2214 host_impl_.ActivateSyncTree(); 2188 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2215 host_impl_.CreatePendingTree(); 2189 scoped_refptr<FakePicturePileImpl> active_pile =
2216 active_layer_ = static_cast<FakePictureLayerImpl*>( 2190 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2217 host_impl_.active_tree()->LayerById(id_)); 2191 SetupTreesWithInvalidation(pending_pile, active_pile, gfx::Rect(1, 1));
2192 // Activate the invalidation.
2193 ActivateTree();
2194 // Make another pending tree without any invalidation in it.
2195 scoped_refptr<FakePicturePileImpl> pending_pile2 =
2196 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2197 SetupPendingTree(pending_pile2);
2218 2198
2219 // Force the active tree to sync to the pending tree "post-commit". 2199 EXPECT_GE(active_layer_->num_tilings(), 1u);
2220 pending_layer_->DoPostCommitInitializationIfNeeded(); 2200 EXPECT_GE(pending_layer_->num_tilings(), 1u);
2221 2201
2222 // The active tree invalidation was handled by the active tiles, so they 2202 // The active tree invalidation was handled by the active tiles, so they
2223 // can be shared with the pending tree. 2203 // can be shared with the pending tree.
2224 EXPECT_EQ(3u, active_layer_->num_tilings()); 2204 PictureLayerTiling* active_tiling = active_layer_->tilings()->tiling_at(0);
2225 EXPECT_EQ(3u, pending_layer_->num_tilings()); 2205 PictureLayerTiling* pending_tiling = pending_layer_->tilings()->tiling_at(0);
2226 for (size_t i = 0; i < active_layer_->num_tilings(); ++i) { 2206 ASSERT_TRUE(active_tiling);
2227 PictureLayerTiling* active_tiling = active_layer_->tilings()->tiling_at(i); 2207 ASSERT_TRUE(pending_tiling);
2228 PictureLayerTiling* pending_tiling =
2229 pending_layer_->tilings()->tiling_at(i);
2230 2208
2231 ASSERT_TRUE(active_tiling); 2209 EXPECT_TRUE(active_tiling->TileAt(0, 0));
2232 ASSERT_TRUE(pending_tiling); 2210 EXPECT_TRUE(active_tiling->TileAt(1, 0));
2211 EXPECT_TRUE(active_tiling->TileAt(0, 1));
2212 EXPECT_TRUE(active_tiling->TileAt(1, 1));
2233 2213
2234 EXPECT_TRUE(active_tiling->TileAt(0, 0)); 2214 EXPECT_TRUE(pending_tiling->TileAt(0, 0));
2235 EXPECT_TRUE(active_tiling->TileAt(1, 0)); 2215 EXPECT_TRUE(pending_tiling->TileAt(1, 0));
2236 EXPECT_TRUE(active_tiling->TileAt(0, 1)); 2216 EXPECT_TRUE(pending_tiling->TileAt(0, 1));
2237 EXPECT_TRUE(active_tiling->TileAt(1, 1)); 2217 EXPECT_TRUE(pending_tiling->TileAt(1, 1));
2238 2218
2239 EXPECT_TRUE(pending_tiling->TileAt(0, 0)); 2219 EXPECT_EQ(active_tiling->TileAt(0, 0), pending_tiling->TileAt(0, 0));
2240 EXPECT_TRUE(pending_tiling->TileAt(1, 0)); 2220 EXPECT_TRUE(active_tiling->TileAt(0, 0)->is_shared());
2241 EXPECT_TRUE(pending_tiling->TileAt(0, 1)); 2221 EXPECT_EQ(active_tiling->TileAt(1, 0), pending_tiling->TileAt(1, 0));
2242 EXPECT_TRUE(pending_tiling->TileAt(1, 1)); 2222 EXPECT_TRUE(active_tiling->TileAt(1, 0)->is_shared());
2243 2223 EXPECT_EQ(active_tiling->TileAt(0, 1), pending_tiling->TileAt(0, 1));
2244 EXPECT_EQ(active_tiling->TileAt(0, 0), pending_tiling->TileAt(0, 0)); 2224 EXPECT_TRUE(active_tiling->TileAt(0, 1)->is_shared());
2245 EXPECT_TRUE(active_tiling->TileAt(0, 0)->is_shared()); 2225 EXPECT_EQ(active_tiling->TileAt(1, 1), pending_tiling->TileAt(1, 1));
2246 EXPECT_EQ(active_tiling->TileAt(1, 0), pending_tiling->TileAt(1, 0)); 2226 EXPECT_TRUE(active_tiling->TileAt(1, 1)->is_shared());
2247 EXPECT_TRUE(active_tiling->TileAt(1, 0)->is_shared());
2248 EXPECT_EQ(active_tiling->TileAt(0, 1), pending_tiling->TileAt(0, 1));
2249 EXPECT_TRUE(active_tiling->TileAt(0, 1)->is_shared());
2250 EXPECT_EQ(active_tiling->TileAt(1, 1), pending_tiling->TileAt(1, 1));
2251 EXPECT_TRUE(active_tiling->TileAt(1, 1)->is_shared());
2252 }
2253 } 2227 }
2254 2228
2255 TEST_F(PictureLayerImplTest, RemoveInvalidPendingTreeTilesOnSync) { 2229 TEST_F(PictureLayerImplTest, RecreateInvalidPendingTreeTiles) {
2256 SetupDefaultTrees(gfx::Size(1500, 1500)); 2230 // Set some invalidation on the pending tree. We should replace raster tiles
2257 AddDefaultTilingsWithInvalidation(gfx::Rect()); 2231 // that touch this.
2232 SetupDefaultTreesWithInvalidation(gfx::Size(1500, 1500), gfx::Rect(1, 1));
2258 2233
2259 host_impl_.ActivateSyncTree(); 2234 EXPECT_GE(active_layer_->num_tilings(), 1u);
2260 host_impl_.CreatePendingTree(); 2235 EXPECT_GE(pending_layer_->num_tilings(), 1u);
2261 active_layer_ = static_cast<FakePictureLayerImpl*>(
2262 host_impl_.active_tree()->LayerById(id_));
2263
2264 // Set some invalidation on the pending tree "during commit". We should
2265 // replace raster tiles that touch this.
2266 pending_layer_->set_invalidation(gfx::Rect(1, 1));
2267
2268 // Force the active tree to sync to the pending tree "post-commit".
2269 pending_layer_->DoPostCommitInitializationIfNeeded();
2270 2236
2271 // The pending tree invalidation means tiles can not be shared with the 2237 // The pending tree invalidation means tiles can not be shared with the
2272 // active tree. 2238 // active tree.
2273 EXPECT_EQ(3u, active_layer_->num_tilings()); 2239 PictureLayerTiling* active_tiling = active_layer_->tilings()->tiling_at(0);
2274 EXPECT_EQ(3u, pending_layer_->num_tilings()); 2240 PictureLayerTiling* pending_tiling = pending_layer_->tilings()->tiling_at(0);
2275 for (size_t i = 0; i < active_layer_->num_tilings(); ++i) { 2241 ASSERT_TRUE(active_tiling);
2276 PictureLayerTiling* active_tiling = active_layer_->tilings()->tiling_at(i); 2242 ASSERT_TRUE(pending_tiling);
2277 PictureLayerTiling* pending_tiling =
2278 pending_layer_->tilings()->tiling_at(i);
2279 2243
2280 ASSERT_TRUE(active_tiling); 2244 EXPECT_TRUE(active_tiling->TileAt(0, 0));
2281 ASSERT_TRUE(pending_tiling); 2245 EXPECT_TRUE(active_tiling->TileAt(1, 0));
2246 EXPECT_TRUE(active_tiling->TileAt(0, 1));
2247 EXPECT_TRUE(active_tiling->TileAt(1, 1));
2282 2248
2283 EXPECT_TRUE(active_tiling->TileAt(0, 0)); 2249 EXPECT_TRUE(pending_tiling->TileAt(0, 0));
2284 EXPECT_TRUE(active_tiling->TileAt(1, 0)); 2250 EXPECT_TRUE(pending_tiling->TileAt(1, 0));
2285 EXPECT_TRUE(active_tiling->TileAt(0, 1)); 2251 EXPECT_TRUE(pending_tiling->TileAt(0, 1));
2286 EXPECT_TRUE(active_tiling->TileAt(1, 1)); 2252 EXPECT_TRUE(pending_tiling->TileAt(1, 1));
2287 2253
2288 EXPECT_TRUE(pending_tiling->TileAt(0, 0)); 2254 EXPECT_NE(active_tiling->TileAt(0, 0), pending_tiling->TileAt(0, 0));
2289 EXPECT_TRUE(pending_tiling->TileAt(1, 0)); 2255 EXPECT_FALSE(active_tiling->TileAt(0, 0)->is_shared());
2290 EXPECT_TRUE(pending_tiling->TileAt(0, 1)); 2256 EXPECT_FALSE(pending_tiling->TileAt(0, 0)->is_shared());
2291 EXPECT_TRUE(pending_tiling->TileAt(1, 1)); 2257 EXPECT_EQ(active_tiling->TileAt(1, 0), pending_tiling->TileAt(1, 0));
2292 2258 EXPECT_TRUE(active_tiling->TileAt(1, 0)->is_shared());
2293 EXPECT_NE(active_tiling->TileAt(0, 0), pending_tiling->TileAt(0, 0)); 2259 EXPECT_EQ(active_tiling->TileAt(0, 1), pending_tiling->TileAt(0, 1));
2294 EXPECT_FALSE(active_tiling->TileAt(0, 0)->is_shared()); 2260 EXPECT_TRUE(active_tiling->TileAt(1, 1)->is_shared());
2295 EXPECT_FALSE(pending_tiling->TileAt(0, 0)->is_shared()); 2261 EXPECT_EQ(active_tiling->TileAt(1, 1), pending_tiling->TileAt(1, 1));
2296 EXPECT_EQ(active_tiling->TileAt(1, 0), pending_tiling->TileAt(1, 0)); 2262 EXPECT_TRUE(active_tiling->TileAt(1, 1)->is_shared());
2297 EXPECT_TRUE(active_tiling->TileAt(1, 0)->is_shared());
2298 EXPECT_EQ(active_tiling->TileAt(0, 1), pending_tiling->TileAt(0, 1));
2299 EXPECT_TRUE(active_tiling->TileAt(1, 1)->is_shared());
2300 EXPECT_EQ(active_tiling->TileAt(1, 1), pending_tiling->TileAt(1, 1));
2301 EXPECT_TRUE(active_tiling->TileAt(1, 1)->is_shared());
2302 }
2303 }
2304
2305 TEST_F(PictureLayerImplTest, SyncTilingAfterReleaseResource) {
2306 SetupDefaultTrees(gfx::Size(10, 10));
2307 host_impl_.active_tree()->UpdateDrawProperties();
2308 EXPECT_FALSE(host_impl_.active_tree()->needs_update_draw_properties());
2309
2310 // Contrived unit test of a real crash. A layer is transparent during a
2311 // context loss, and later becomes opaque, causing active layer SyncTiling to
2312 // be called.
2313 float new_scale = 1.f;
2314 active_layer_->ReleaseResources();
2315 pending_layer_->ReleaseResources();
2316 EXPECT_FALSE(active_layer_->tilings()->FindTilingWithScale(new_scale));
2317 pending_layer_->AddTiling(new_scale);
2318 EXPECT_TRUE(active_layer_->tilings()->FindTilingWithScale(new_scale));
2319
2320 // UpdateDrawProperties early-outs if the tree doesn't need it. It is also
2321 // responsible for calling ManageTilings. These checks verify that
2322 // ReleaseResources has set needs update draw properties so that the
2323 // new tiling gets the appropriate resolution set in ManageTilings.
2324 EXPECT_TRUE(host_impl_.active_tree()->needs_update_draw_properties());
2325 host_impl_.active_tree()->UpdateDrawProperties();
2326 PictureLayerTiling* high_res =
2327 active_layer_->tilings()->FindTilingWithScale(new_scale);
2328 ASSERT_TRUE(!!high_res);
2329 EXPECT_EQ(HIGH_RESOLUTION, high_res->resolution());
2330 } 2263 }
2331 2264
2332 TEST_F(PictureLayerImplTest, SyncTilingAfterGpuRasterizationToggles) { 2265 TEST_F(PictureLayerImplTest, SyncTilingAfterGpuRasterizationToggles) {
2333 SetupDefaultTrees(gfx::Size(10, 10)); 2266 base::TimeTicks time_ticks;
2267 time_ticks += base::TimeDelta::FromMilliseconds(1);
2268 host_impl_.SetCurrentBeginFrameArgs(
2269 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
2334 2270
2335 const float kScale = 1.f; 2271 gfx::Size tile_size(100, 100);
2336 pending_layer_->AddTiling(kScale); 2272 gfx::Size layer_bounds(10, 10);
2337 EXPECT_TRUE(pending_layer_->tilings()->FindTilingWithScale(kScale)); 2273
2338 EXPECT_TRUE(active_layer_->tilings()->FindTilingWithScale(kScale)); 2274 scoped_refptr<FakePicturePileImpl> pending_pile =
2275 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2276 scoped_refptr<FakePicturePileImpl> active_pile =
2277 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2278
2279 SetupTrees(pending_pile, active_pile);
2280
2281 EXPECT_TRUE(pending_layer_->tilings()->FindTilingWithScale(1.f));
2282 EXPECT_TRUE(active_layer_->tilings()->FindTilingWithScale(1.f));
2339 2283
2340 // Gpu rasterization is disabled by default. 2284 // Gpu rasterization is disabled by default.
2341 EXPECT_FALSE(host_impl_.use_gpu_rasterization()); 2285 EXPECT_FALSE(host_impl_.use_gpu_rasterization());
2342 // Toggling the gpu rasterization clears all tilings on both trees. 2286 // Toggling the gpu rasterization clears all tilings on both trees.
2343 host_impl_.SetUseGpuRasterization(true); 2287 host_impl_.SetUseGpuRasterization(true);
2344 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); 2288 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
2345 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings()); 2289 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
2346 2290
2347 // Make sure that we can still add tiling to the pending layer, 2291 // Make sure that we can still add tiling to the pending layer,
2348 // that gets synced to the active layer. 2292 // that gets synced to the active layer.
2349 pending_layer_->AddTiling(kScale); 2293 time_ticks += base::TimeDelta::FromMilliseconds(1);
2350 EXPECT_TRUE(pending_layer_->tilings()->FindTilingWithScale(kScale)); 2294 host_impl_.SetCurrentBeginFrameArgs(
2351 EXPECT_TRUE(active_layer_->tilings()->FindTilingWithScale(kScale)); 2295 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
2296 host_impl_.pending_tree()->UpdateDrawProperties();
2297 EXPECT_TRUE(pending_layer_->tilings()->FindTilingWithScale(1.f));
2298
2299 ActivateTree();
2300 EXPECT_TRUE(active_layer_->tilings()->FindTilingWithScale(1.f));
2301
2302 SetupPendingTree(pending_pile);
2303 EXPECT_TRUE(pending_layer_->tilings()->FindTilingWithScale(1.f));
2352 2304
2353 // Toggling the gpu rasterization clears all tilings on both trees. 2305 // Toggling the gpu rasterization clears all tilings on both trees.
2354 EXPECT_TRUE(host_impl_.use_gpu_rasterization()); 2306 EXPECT_TRUE(host_impl_.use_gpu_rasterization());
2355 host_impl_.SetUseGpuRasterization(false); 2307 host_impl_.SetUseGpuRasterization(false);
2356 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); 2308 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
2357 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings()); 2309 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
2358 } 2310 }
2359 2311
2360 TEST_F(PictureLayerImplTest, HighResCreatedWhenBoundsShrink) { 2312 TEST_F(PictureLayerImplTest, HighResCreatedWhenBoundsShrink) {
2361 gfx::Size tile_size(100, 100); 2313 gfx::Size tile_size(100, 100);
2362 2314
2363 scoped_refptr<FakePicturePileImpl> active_pile = 2315 // Put 0.5 as high res.
2316 host_impl_.SetDeviceScaleFactor(0.5f);
2317
2318 scoped_refptr<FakePicturePileImpl> pending_pile =
2364 FakePicturePileImpl::CreateFilledPile(tile_size, gfx::Size(10, 10)); 2319 FakePicturePileImpl::CreateFilledPile(tile_size, gfx::Size(10, 10));
2365 SetupPendingTree(active_pile); 2320 SetupPendingTree(pending_pile);
2366 ActivateTree();
2367 host_impl_.active_tree()->UpdateDrawProperties();
2368 EXPECT_FALSE(host_impl_.active_tree()->needs_update_draw_properties());
2369
2370 SetupDrawPropertiesAndUpdateTiles(
2371 active_layer_, 0.5f, 0.5f, 0.5f, 0.5f, false);
2372 active_layer_->tilings()->RemoveAllTilings();
2373 PictureLayerTiling* tiling = active_layer_->AddTiling(0.5f);
2374 active_layer_->AddTiling(1.5f);
2375 active_layer_->AddTiling(0.25f);
2376 tiling->set_resolution(HIGH_RESOLUTION);
2377 2321
2378 // Sanity checks. 2322 // Sanity checks.
2379 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings()); 2323 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings());
2380 ASSERT_EQ(tiling, active_layer_->tilings()->FindTilingWithScale(0.5f)); 2324 EXPECT_TRUE(pending_layer_->tilings()->FindTilingWithScale(0.5f));
2381 2325
2382 // Now, set the bounds to be 1x1 (so that minimum contents scale becomes 2326 ActivateTree();
2383 // 1.0f). Note that we should also ensure that the pending layer needs post 2327
2384 // commit initialization, since this is what would happen during commit. In 2328 // Now, set the bounds to be 1x1, so that minimum contents scale becomes 1.
2385 // other words we want the pending layer to sync from the active layer. 2329 pending_pile =
2386 scoped_refptr<FakePicturePileImpl> pending_pile =
2387 FakePicturePileImpl::CreateFilledPile(tile_size, gfx::Size(1, 1)); 2330 FakePicturePileImpl::CreateFilledPile(tile_size, gfx::Size(1, 1));
2388 SetupPendingTree(pending_pile); 2331 SetupPendingTree(pending_pile);
2389 2332
2390 // Update the draw properties: sync from active tree should happen here. 2333 // Another sanity check.
2391 host_impl_.pending_tree()->UpdateDrawProperties(); 2334 EXPECT_EQ(1.f, pending_layer_->MinimumContentsScale());
2392 EXPECT_FALSE(pending_layer_->needs_post_commit_initialization());
2393 2335
2394 // Another sanity check. 2336 // Since the MinContentsScale is 1, the 0.5 tiling should be replaced by a 1.0
2395 ASSERT_EQ(1.f, pending_layer_->MinimumContentsScale()); 2337 // tiling.
2338 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 0.5f, 1.f, 1.f, 1.f, false);
2396 2339
2397 // Now we should've synced 1.5f tiling, since that's the only one that doesn't 2340 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings());
2398 // violate minimum contents scale. At the same time, we should've created a 2341 PictureLayerTiling* tiling =
2399 // new high res tiling at scale 1.0f. 2342 pending_layer_->tilings()->FindTilingWithScale(1.0f);
2343 ASSERT_TRUE(tiling);
2344 EXPECT_EQ(HIGH_RESOLUTION, tiling->resolution());
2345 }
2346
2347 TEST_F(PictureLayerImplTest, LowResTilingWithoutGpuRasterization) {
2348 gfx::Size default_tile_size(host_impl_.settings().default_tile_size);
2349 gfx::Size layer_bounds(default_tile_size.width() * 4,
2350 default_tile_size.height() * 4);
2351
2352 host_impl_.SetUseGpuRasterization(false);
2353
2354 SetupDefaultTrees(layer_bounds);
2355 EXPECT_FALSE(host_impl_.use_gpu_rasterization());
2356 // Should have a low-res and a high-res tiling.
2400 EXPECT_EQ(2u, pending_layer_->tilings()->num_tilings()); 2357 EXPECT_EQ(2u, pending_layer_->tilings()->num_tilings());
2401 ASSERT_TRUE(pending_layer_->tilings()->FindTilingWithScale(1.0f));
2402 EXPECT_EQ(HIGH_RESOLUTION,
2403 pending_layer_->tilings()->FindTilingWithScale(1.0f)->resolution());
2404 ASSERT_TRUE(pending_layer_->tilings()->FindTilingWithScale(1.5f));
2405 EXPECT_EQ(NON_IDEAL_RESOLUTION,
2406 pending_layer_->tilings()->FindTilingWithScale(1.5f)->resolution());
2407 } 2358 }
2408 2359
2409 TEST_F(PictureLayerImplTest, NoLowResTilingWithGpuRasterization) { 2360 TEST_F(PictureLayerImplTest, NoLowResTilingWithGpuRasterization) {
2410 gfx::Size default_tile_size(host_impl_.settings().default_tile_size); 2361 gfx::Size default_tile_size(host_impl_.settings().default_tile_size);
2411 gfx::Size layer_bounds(default_tile_size.width() * 4, 2362 gfx::Size layer_bounds(default_tile_size.width() * 4,
2412 default_tile_size.height() * 4); 2363 default_tile_size.height() * 4);
2413 2364
2365 host_impl_.SetUseGpuRasterization(true);
2366
2414 SetupDefaultTrees(layer_bounds); 2367 SetupDefaultTrees(layer_bounds);
2415 EXPECT_FALSE(host_impl_.use_gpu_rasterization());
2416 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
2417 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.f, 1.f, 1.f, 1.f, false);
2418 // Should have a low-res and a high-res tiling.
2419 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
2420
2421 ResetTilingsAndRasterScales();
2422
2423 host_impl_.SetUseGpuRasterization(true);
2424 EXPECT_TRUE(host_impl_.use_gpu_rasterization()); 2368 EXPECT_TRUE(host_impl_.use_gpu_rasterization());
2425 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.f, 1.f, 1.f, 1.f, false);
2426
2427 // Should only have the high-res tiling. 2369 // Should only have the high-res tiling.
2428 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings()); 2370 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings());
2429 } 2371 }
2430 2372
2431 TEST_F(PictureLayerImplTest, NoTilingIfDoesNotDrawContent) { 2373 TEST_F(PictureLayerImplTest, NoTilingIfDoesNotDrawContent) {
2432 // Set up layers with tilings. 2374 // Set up layers with tilings.
2433 SetupDefaultTrees(gfx::Size(10, 10)); 2375 SetupDefaultTrees(gfx::Size(10, 10));
2434 SetContentsScaleOnBothLayers(1.f, 1.f, 1.f, 1.f, false); 2376 SetContentsScaleOnBothLayers(1.f, 1.f, 1.f, 1.f, false);
2435 pending_layer_->PushPropertiesTo(active_layer_); 2377 pending_layer_->PushPropertiesTo(active_layer_);
2436 EXPECT_TRUE(pending_layer_->DrawsContent()); 2378 EXPECT_TRUE(pending_layer_->DrawsContent());
2437 EXPECT_TRUE(pending_layer_->CanHaveTilings()); 2379 EXPECT_TRUE(pending_layer_->CanHaveTilings());
2438 EXPECT_GE(pending_layer_->num_tilings(), 0u); 2380 EXPECT_GE(pending_layer_->num_tilings(), 0u);
2439 EXPECT_GE(active_layer_->num_tilings(), 0u); 2381 EXPECT_GE(active_layer_->num_tilings(), 0u);
2440 2382
2441 // Set content to false, which should make CanHaveTilings return false. 2383 // Set content to false, which should make CanHaveTilings return false.
2442 pending_layer_->SetDrawsContent(false); 2384 pending_layer_->SetDrawsContent(false);
2443 EXPECT_FALSE(pending_layer_->DrawsContent()); 2385 EXPECT_FALSE(pending_layer_->DrawsContent());
2444 EXPECT_FALSE(pending_layer_->CanHaveTilings()); 2386 EXPECT_FALSE(pending_layer_->CanHaveTilings());
2445 2387
2446 // No tilings should be pushed to active layer. 2388 // No tilings should be pushed to active layer.
2447 pending_layer_->PushPropertiesTo(active_layer_); 2389 pending_layer_->PushPropertiesTo(active_layer_);
2448 EXPECT_EQ(0u, active_layer_->num_tilings()); 2390 EXPECT_EQ(0u, active_layer_->num_tilings());
2449 } 2391 }
2450 2392
2451 TEST_F(PictureLayerImplTest, FirstTilingDuringPinch) { 2393 TEST_F(PictureLayerImplTest, FirstTilingDuringPinch) {
2452 SetupDefaultTrees(gfx::Size(10, 10)); 2394 SetupDefaultTrees(gfx::Size(10, 10));
2395
2396 // We start with a tiling at scale 1.
2397 EXPECT_EQ(1.f, pending_layer_->HighResTiling()->contents_scale());
2398
2399 // When we scale up by 2.3, we get a new tiling that is a power of 2, in this
2400 // case 4.
2453 host_impl_.PinchGestureBegin(); 2401 host_impl_.PinchGestureBegin();
2454 float high_res_scale = 2.3f; 2402 float high_res_scale = 2.3f;
2455 SetContentsScaleOnBothLayers(high_res_scale, 1.f, 1.f, 1.f, false); 2403 SetContentsScaleOnBothLayers(high_res_scale, 1.f, 1.f, 1.f, false);
2456 2404 EXPECT_EQ(4.f, pending_layer_->HighResTiling()->contents_scale());
2457 ASSERT_GE(pending_layer_->num_tilings(), 0u);
2458 EXPECT_FLOAT_EQ(high_res_scale,
2459 pending_layer_->HighResTiling()->contents_scale());
2460 }
2461
2462 TEST_F(PictureLayerImplTest, FirstTilingTooSmall) {
2463 SetupDefaultTrees(gfx::Size(10, 10));
2464 host_impl_.PinchGestureBegin();
2465 float high_res_scale = 0.0001f;
2466 EXPECT_GT(pending_layer_->MinimumContentsScale(), high_res_scale);
2467
2468 SetContentsScaleOnBothLayers(high_res_scale, 1.f, 1.f, 1.f, false);
2469
2470 ASSERT_GE(pending_layer_->num_tilings(), 0u);
2471 EXPECT_FLOAT_EQ(pending_layer_->MinimumContentsScale(),
2472 pending_layer_->HighResTiling()->contents_scale());
2473 } 2405 }
2474 2406
2475 TEST_F(PictureLayerImplTest, PinchingTooSmall) { 2407 TEST_F(PictureLayerImplTest, PinchingTooSmall) {
2476 SetupDefaultTrees(gfx::Size(10, 10)); 2408 SetupDefaultTrees(gfx::Size(10, 10));
2477 2409
2410 // We start with a tiling at scale 1.
2411 EXPECT_EQ(1.f, pending_layer_->HighResTiling()->contents_scale());
2412
2413 host_impl_.PinchGestureBegin();
2414 float high_res_scale = 0.0001f;
2415 EXPECT_LT(high_res_scale, pending_layer_->MinimumContentsScale());
2416
2417 SetContentsScaleOnBothLayers(high_res_scale, 1.f, high_res_scale, 1.f, false);
2418 EXPECT_FLOAT_EQ(pending_layer_->MinimumContentsScale(),
2419 pending_layer_->HighResTiling()->contents_scale());
2420 }
2421
2422 TEST_F(PictureLayerImplTest, PinchingTooSmallWithContentsScale) {
2423 SetupDefaultTrees(gfx::Size(10, 10));
2424
2425 ResetTilingsAndRasterScales();
2426
2478 float contents_scale = 0.15f; 2427 float contents_scale = 0.15f;
2479 SetContentsScaleOnBothLayers(contents_scale, 1.f, 1.f, 1.f, false); 2428 SetContentsScaleOnBothLayers(contents_scale, 1.f, 1.f, 1.f, false);
2480 2429
2481 ASSERT_GE(pending_layer_->num_tilings(), 0u); 2430 ASSERT_GE(pending_layer_->num_tilings(), 0u);
2482 EXPECT_FLOAT_EQ(contents_scale, 2431 EXPECT_FLOAT_EQ(contents_scale,
2483 pending_layer_->HighResTiling()->contents_scale()); 2432 pending_layer_->HighResTiling()->contents_scale());
2484 2433
2485 host_impl_.PinchGestureBegin(); 2434 host_impl_.PinchGestureBegin();
2486 2435
2487 float page_scale = 0.0001f; 2436 float page_scale = 0.0001f;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
2535 ASSERT_TRUE(fake_output_surface->InitializeAndSetContext3d( 2484 ASSERT_TRUE(fake_output_surface->InitializeAndSetContext3d(
2536 TestContextProvider::Create())); 2485 TestContextProvider::Create()));
2537 2486
2538 // These will crash PictureLayerImpl if this is not true. 2487 // These will crash PictureLayerImpl if this is not true.
2539 ASSERT_TRUE(host_impl_.pending_tree()->needs_update_draw_properties()); 2488 ASSERT_TRUE(host_impl_.pending_tree()->needs_update_draw_properties());
2540 ASSERT_TRUE(host_impl_.active_tree()->needs_update_draw_properties()); 2489 ASSERT_TRUE(host_impl_.active_tree()->needs_update_draw_properties());
2541 host_impl_.active_tree()->UpdateDrawProperties(); 2490 host_impl_.active_tree()->UpdateDrawProperties();
2542 } 2491 }
2543 2492
2544 TEST_F(PictureLayerImplTest, HighResTilingDuringAnimationForCpuRasterization) { 2493 TEST_F(PictureLayerImplTest, HighResTilingDuringAnimationForCpuRasterization) {
2545 gfx::Size layer_bounds(100, 100);
2546 gfx::Size viewport_size(1000, 1000); 2494 gfx::Size viewport_size(1000, 1000);
2547 SetupDefaultTrees(layer_bounds);
2548 host_impl_.SetViewportSize(viewport_size); 2495 host_impl_.SetViewportSize(viewport_size);
2549 2496
2497 gfx::Size layer_bounds(100, 100);
2498 SetupDefaultTrees(layer_bounds);
2499
2550 float contents_scale = 1.f; 2500 float contents_scale = 1.f;
2551 float device_scale = 1.3f; 2501 float device_scale = 1.f;
2552 float page_scale = 1.4f; 2502 float page_scale = 1.f;
2553 float maximum_animation_scale = 1.f; 2503 float maximum_animation_scale = 1.f;
2554 bool animating_transform = false; 2504 bool animating_transform = false;
2555 2505
2556 SetContentsScaleOnBothLayers(contents_scale,
2557 device_scale,
2558 page_scale,
2559 maximum_animation_scale,
2560 animating_transform);
2561 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f); 2506 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f);
2562 2507
2563 // Since we're CPU-rasterizing, starting an animation should cause tiling 2508 // Since we're CPU-rasterizing, starting an animation should cause tiling
2564 // resolution to get set to the maximum animation scale factor. 2509 // resolution to get set to the maximum animation scale factor.
2565 animating_transform = true; 2510 animating_transform = true;
2566 maximum_animation_scale = 3.f; 2511 maximum_animation_scale = 3.f;
2567 contents_scale = 2.f; 2512 contents_scale = 2.f;
2568 2513
2569 SetContentsScaleOnBothLayers(contents_scale, 2514 SetContentsScaleOnBothLayers(contents_scale,
2570 device_scale, 2515 device_scale,
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
2774 animating_transform); 2719 animating_transform);
2775 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f); 2720 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f);
2776 } 2721 }
2777 2722
2778 TEST_F(PictureLayerImplTest, TilingSetRasterQueue) { 2723 TEST_F(PictureLayerImplTest, TilingSetRasterQueue) {
2779 base::TimeTicks time_ticks; 2724 base::TimeTicks time_ticks;
2780 time_ticks += base::TimeDelta::FromMilliseconds(1); 2725 time_ticks += base::TimeDelta::FromMilliseconds(1);
2781 host_impl_.SetCurrentBeginFrameArgs( 2726 host_impl_.SetCurrentBeginFrameArgs(
2782 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks)); 2727 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
2783 2728
2729 host_impl_.SetViewportSize(gfx::Size(500, 500));
2730
2784 gfx::Size tile_size(100, 100); 2731 gfx::Size tile_size(100, 100);
2785 gfx::Size layer_bounds(1000, 1000); 2732 gfx::Size layer_bounds(1000, 1000);
2786 2733
2787 scoped_refptr<FakePicturePileImpl> pending_pile = 2734 scoped_refptr<FakePicturePileImpl> pending_pile =
2788 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 2735 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2789 2736
2790 SetupPendingTree(pending_pile); 2737 SetupPendingTree(pending_pile);
2738 EXPECT_EQ(2u, pending_layer_->num_tilings());
2791 2739
2792 ASSERT_TRUE(pending_layer_->CanHaveTilings());
2793
2794 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
2795
2796 // No tilings.
2797 scoped_ptr<TilingSetRasterQueue> queue = 2740 scoped_ptr<TilingSetRasterQueue> queue =
2798 pending_layer_->CreateRasterQueue(false); 2741 pending_layer_->CreateRasterQueue(false);
2799 EXPECT_TRUE(queue->IsEmpty());
2800
2801 pending_layer_->AddTiling(low_res_factor);
2802 pending_layer_->AddTiling(0.3f);
2803 pending_layer_->AddTiling(0.7f);
2804 PictureLayerTiling* high_res_tiling = pending_layer_->AddTiling(1.0f);
2805 pending_layer_->AddTiling(2.0f);
2806
2807 host_impl_.SetViewportSize(gfx::Size(500, 500));
2808 host_impl_.pending_tree()->UpdateDrawProperties();
2809 2742
2810 std::set<Tile*> unique_tiles; 2743 std::set<Tile*> unique_tiles;
2811 bool reached_prepaint = false; 2744 bool reached_prepaint = false;
2812 size_t non_ideal_tile_count = 0u; 2745 size_t non_ideal_tile_count = 0u;
2813 size_t low_res_tile_count = 0u; 2746 size_t low_res_tile_count = 0u;
2814 size_t high_res_tile_count = 0u; 2747 size_t high_res_tile_count = 0u;
2815 queue = pending_layer_->CreateRasterQueue(false); 2748 queue = pending_layer_->CreateRasterQueue(false);
2816 while (!queue->IsEmpty()) { 2749 while (!queue->IsEmpty()) {
2817 Tile* tile = queue->Top(); 2750 Tile* tile = queue->Top();
2818 TilePriority priority = tile->priority(PENDING_TREE); 2751 TilePriority priority = tile->priority(PENDING_TREE);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
2876 EXPECT_EQ(high_res_tile_count, unique_tiles.size()); 2809 EXPECT_EQ(high_res_tile_count, unique_tiles.size());
2877 2810
2878 time_ticks += base::TimeDelta::FromMilliseconds(200); 2811 time_ticks += base::TimeDelta::FromMilliseconds(200);
2879 host_impl_.SetCurrentBeginFrameArgs( 2812 host_impl_.SetCurrentBeginFrameArgs(
2880 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks)); 2813 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
2881 2814
2882 pending_layer_->draw_properties().visible_content_rect = 2815 pending_layer_->draw_properties().visible_content_rect =
2883 gfx::Rect(0, 0, 500, 500); 2816 gfx::Rect(0, 0, 500, 500);
2884 pending_layer_->UpdateTiles(Occlusion(), resourceless_software_draw); 2817 pending_layer_->UpdateTiles(Occlusion(), resourceless_software_draw);
2885 2818
2886 std::vector<Tile*> high_res_tiles = high_res_tiling->AllTilesForTesting(); 2819 std::vector<Tile*> high_res_tiles =
2820 pending_layer_->HighResTiling()->AllTilesForTesting();
2887 for (std::vector<Tile*>::iterator tile_it = high_res_tiles.begin(); 2821 for (std::vector<Tile*>::iterator tile_it = high_res_tiles.begin();
2888 tile_it != high_res_tiles.end(); 2822 tile_it != high_res_tiles.end();
2889 ++tile_it) { 2823 ++tile_it) {
2890 Tile* tile = *tile_it; 2824 Tile* tile = *tile_it;
2891 ManagedTileState::DrawInfo& draw_info = tile->draw_info(); 2825 ManagedTileState::DrawInfo& draw_info = tile->draw_info();
2892 draw_info.SetSolidColorForTesting(SK_ColorRED); 2826 draw_info.SetSolidColorForTesting(SK_ColorRED);
2893 } 2827 }
2894 2828
2895 non_ideal_tile_count = 0; 2829 non_ideal_tile_count = 0;
2896 low_res_tile_count = 0; 2830 low_res_tile_count = 0;
(...skipping 12 matching lines...) Expand all
2909 } 2843 }
2910 2844
2911 EXPECT_EQ(0u, non_ideal_tile_count); 2845 EXPECT_EQ(0u, non_ideal_tile_count);
2912 EXPECT_EQ(1u, low_res_tile_count); 2846 EXPECT_EQ(1u, low_res_tile_count);
2913 EXPECT_EQ(0u, high_res_tile_count); 2847 EXPECT_EQ(0u, high_res_tile_count);
2914 } 2848 }
2915 2849
2916 TEST_F(PictureLayerImplTest, TilingSetEvictionQueue) { 2850 TEST_F(PictureLayerImplTest, TilingSetEvictionQueue) {
2917 gfx::Size tile_size(100, 100); 2851 gfx::Size tile_size(100, 100);
2918 gfx::Size layer_bounds(1000, 1000); 2852 gfx::Size layer_bounds(1000, 1000);
2853 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
2854
2855 host_impl_.SetViewportSize(gfx::Size(500, 500));
2919 2856
2920 scoped_refptr<FakePicturePileImpl> pending_pile = 2857 scoped_refptr<FakePicturePileImpl> pending_pile =
2921 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 2858 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2922 2859
2860 // TODO(vmpstr): Add a test with tilings other than high/low res on the active
2861 // tree.
2923 SetupPendingTree(pending_pile); 2862 SetupPendingTree(pending_pile);
2924 2863 EXPECT_EQ(2u, pending_layer_->num_tilings());
2925 ASSERT_TRUE(pending_layer_->CanHaveTilings());
2926
2927 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
2928
2929 std::vector<PictureLayerTiling*> tilings;
2930 tilings.push_back(pending_layer_->AddTiling(low_res_factor));
2931 tilings.push_back(pending_layer_->AddTiling(0.3f));
2932 tilings.push_back(pending_layer_->AddTiling(0.7f));
2933 tilings.push_back(pending_layer_->AddTiling(1.0f));
2934 tilings.push_back(pending_layer_->AddTiling(2.0f));
2935
2936 host_impl_.SetViewportSize(gfx::Size(500, 500));
2937 host_impl_.pending_tree()->UpdateDrawProperties();
2938 2864
2939 std::vector<Tile*> all_tiles; 2865 std::vector<Tile*> all_tiles;
2940 for (std::vector<PictureLayerTiling*>::iterator tiling_iterator = 2866 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) {
2941 tilings.begin(); 2867 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i);
2942 tiling_iterator != tilings.end(); 2868 std::vector<Tile*> tiles = tiling->AllTilesForTesting();
2943 ++tiling_iterator) { 2869 all_tiles.insert(all_tiles.end(), tiles.begin(), tiles.end());
2944 std::vector<Tile*> tiles = (*tiling_iterator)->AllTilesForTesting();
2945 std::copy(tiles.begin(), tiles.end(), std::back_inserter(all_tiles));
2946 } 2870 }
2947 2871
2948 std::set<Tile*> all_tiles_set(all_tiles.begin(), all_tiles.end()); 2872 std::set<Tile*> all_tiles_set(all_tiles.begin(), all_tiles.end());
2949 2873
2950 bool mark_required = false; 2874 bool mark_required = false;
2951 size_t number_of_marked_tiles = 0u; 2875 size_t number_of_marked_tiles = 0u;
2952 size_t number_of_unmarked_tiles = 0u; 2876 size_t number_of_unmarked_tiles = 0u;
2953 for (size_t i = 0; i < tilings.size(); ++i) { 2877 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) {
2954 PictureLayerTiling* tiling = tilings.at(i); 2878 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i);
2955 for (PictureLayerTiling::CoverageIterator iter( 2879 for (PictureLayerTiling::CoverageIterator iter(
2956 tiling, 2880 tiling,
2957 pending_layer_->contents_scale_x(), 2881 pending_layer_->contents_scale_x(),
2958 pending_layer_->visible_content_rect()); 2882 pending_layer_->visible_content_rect());
2959 iter; 2883 iter;
2960 ++iter) { 2884 ++iter) {
2961 if (mark_required) { 2885 if (mark_required) {
2962 number_of_marked_tiles++; 2886 number_of_marked_tiles++;
2963 iter->set_required_for_activation(true); 2887 iter->set_required_for_activation(true);
2964 } else { 2888 } else {
2965 number_of_unmarked_tiles++; 2889 number_of_unmarked_tiles++;
2966 } 2890 }
2967 mark_required = !mark_required; 2891 mark_required = !mark_required;
2968 } 2892 }
2969 } 2893 }
2970 2894
2971 // Sanity checks. 2895 // Sanity checks.
2972 EXPECT_EQ(91u, all_tiles.size()); 2896 EXPECT_EQ(17u, all_tiles.size());
2973 EXPECT_EQ(91u, all_tiles_set.size()); 2897 EXPECT_EQ(17u, all_tiles_set.size());
2974 EXPECT_GT(number_of_marked_tiles, 1u); 2898 EXPECT_GT(number_of_marked_tiles, 1u);
2975 EXPECT_GT(number_of_unmarked_tiles, 1u); 2899 EXPECT_GT(number_of_unmarked_tiles, 1u);
2976 2900
2977 // Tiles don't have resources yet. 2901 // Tiles don't have resources yet.
2978 scoped_ptr<TilingSetEvictionQueue> queue = 2902 scoped_ptr<TilingSetEvictionQueue> queue =
2979 pending_layer_->CreateEvictionQueue(SAME_PRIORITY_FOR_BOTH_TREES); 2903 pending_layer_->CreateEvictionQueue(SAME_PRIORITY_FOR_BOTH_TREES);
2980 EXPECT_TRUE(queue->IsEmpty()); 2904 EXPECT_TRUE(queue->IsEmpty());
2981 2905
2982 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles); 2906 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles);
2983 2907
2984 std::set<Tile*> unique_tiles; 2908 std::set<Tile*> unique_tiles;
2985 float expected_scales[] = {2.0f, 0.3f, 0.7f, low_res_factor, 1.0f}; 2909 float expected_scales[] = {low_res_factor, 1.f};
2986 size_t scale_index = 0; 2910 size_t scale_index = 0;
2987 bool reached_visible = false; 2911 bool reached_visible = false;
2988 Tile* last_tile = nullptr; 2912 Tile* last_tile = nullptr;
2913 size_t distance_decreasing = 0;
2914 size_t distance_increasing = 0;
2989 queue = pending_layer_->CreateEvictionQueue(SAME_PRIORITY_FOR_BOTH_TREES); 2915 queue = pending_layer_->CreateEvictionQueue(SAME_PRIORITY_FOR_BOTH_TREES);
2990 while (!queue->IsEmpty()) { 2916 while (!queue->IsEmpty()) {
2991 Tile* tile = queue->Top(); 2917 Tile* tile = queue->Top();
2992 if (!last_tile) 2918 if (!last_tile)
2993 last_tile = tile; 2919 last_tile = tile;
2994 2920
2995 EXPECT_TRUE(tile); 2921 EXPECT_TRUE(tile);
2996 2922
2997 TilePriority priority = tile->priority(PENDING_TREE); 2923 TilePriority priority = tile->priority(PENDING_TREE);
2998 2924
2999 if (priority.priority_bin == TilePriority::NOW) { 2925 if (priority.priority_bin == TilePriority::NOW) {
3000 reached_visible = true; 2926 reached_visible = true;
3001 last_tile = tile; 2927 last_tile = tile;
3002 break; 2928 break;
3003 } 2929 }
3004 2930
3005 EXPECT_FALSE(tile->required_for_activation()); 2931 EXPECT_FALSE(tile->required_for_activation());
3006 2932
3007 while (std::abs(tile->contents_scale() - expected_scales[scale_index]) > 2933 while (std::abs(tile->contents_scale() - expected_scales[scale_index]) >
3008 std::numeric_limits<float>::epsilon()) { 2934 std::numeric_limits<float>::epsilon()) {
3009 ++scale_index; 2935 ++scale_index;
3010 ASSERT_LT(scale_index, arraysize(expected_scales)); 2936 ASSERT_LT(scale_index, arraysize(expected_scales));
3011 } 2937 }
3012 2938
3013 EXPECT_FLOAT_EQ(tile->contents_scale(), expected_scales[scale_index]); 2939 EXPECT_FLOAT_EQ(tile->contents_scale(), expected_scales[scale_index]);
3014 unique_tiles.insert(tile); 2940 unique_tiles.insert(tile);
3015 2941
3016 // If the tile is the same rough bin as last tile (same activation, bin, and
3017 // scale), then distance should be decreasing.
3018 if (tile->required_for_activation() == 2942 if (tile->required_for_activation() ==
3019 last_tile->required_for_activation() && 2943 last_tile->required_for_activation() &&
3020 priority.priority_bin == 2944 priority.priority_bin ==
3021 last_tile->priority(PENDING_TREE).priority_bin && 2945 last_tile->priority(PENDING_TREE).priority_bin &&
3022 std::abs(tile->contents_scale() - last_tile->contents_scale()) < 2946 std::abs(tile->contents_scale() - last_tile->contents_scale()) <
3023 std::numeric_limits<float>::epsilon()) { 2947 std::numeric_limits<float>::epsilon()) {
3024 EXPECT_LE(priority.distance_to_visible, 2948 if (priority.distance_to_visible <=
3025 last_tile->priority(PENDING_TREE).distance_to_visible); 2949 last_tile->priority(PENDING_TREE).distance_to_visible)
2950 ++distance_decreasing;
2951 else
2952 ++distance_increasing;
3026 } 2953 }
3027 2954
3028 last_tile = tile; 2955 last_tile = tile;
3029 queue->Pop(); 2956 queue->Pop();
3030 } 2957 }
3031 2958
2959 // 4 high res tiles are inside the viewport, the rest are evicted.
3032 EXPECT_TRUE(reached_visible); 2960 EXPECT_TRUE(reached_visible);
3033 EXPECT_EQ(65u, unique_tiles.size()); 2961 EXPECT_EQ(12u, unique_tiles.size());
2962 EXPECT_EQ(1u, distance_increasing);
2963 EXPECT_EQ(11u, distance_decreasing);
3034 2964
3035 scale_index = 0; 2965 scale_index = 0;
3036 bool reached_required = false; 2966 bool reached_required = false;
3037 while (!queue->IsEmpty()) { 2967 while (!queue->IsEmpty()) {
3038 Tile* tile = queue->Top(); 2968 Tile* tile = queue->Top();
3039 EXPECT_TRUE(tile); 2969 EXPECT_TRUE(tile);
3040 2970
3041 TilePriority priority = tile->priority(PENDING_TREE); 2971 TilePriority priority = tile->priority(PENDING_TREE);
3042 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); 2972 EXPECT_EQ(TilePriority::NOW, priority.priority_bin);
3043 2973
(...skipping 18 matching lines...) Expand all
3062 EXPECT_TRUE(reached_required); 2992 EXPECT_TRUE(reached_required);
3063 EXPECT_EQ(all_tiles_set.size(), unique_tiles.size()); 2993 EXPECT_EQ(all_tiles_set.size(), unique_tiles.size());
3064 } 2994 }
3065 2995
3066 TEST_F(PictureLayerImplTest, Occlusion) { 2996 TEST_F(PictureLayerImplTest, Occlusion) {
3067 gfx::Size tile_size(102, 102); 2997 gfx::Size tile_size(102, 102);
3068 gfx::Size layer_bounds(1000, 1000); 2998 gfx::Size layer_bounds(1000, 1000);
3069 gfx::Size viewport_size(1000, 1000); 2999 gfx::Size viewport_size(1000, 1000);
3070 3000
3071 LayerTestCommon::LayerImplTest impl; 3001 LayerTestCommon::LayerImplTest impl;
3002 host_impl_.SetViewportSize(viewport_size);
3072 3003
3073 scoped_refptr<FakePicturePileImpl> pending_pile = 3004 scoped_refptr<FakePicturePileImpl> pending_pile =
3074 FakePicturePileImpl::CreateFilledPile(layer_bounds, layer_bounds); 3005 FakePicturePileImpl::CreateFilledPile(layer_bounds, layer_bounds);
3075 SetupPendingTree(pending_pile); 3006 SetupPendingTreeWithFixedTileSize(pending_pile, tile_size, Region());
3076 pending_layer_->SetBounds(layer_bounds);
3077 ActivateTree(); 3007 ActivateTree();
3078 active_layer_->set_fixed_tile_size(tile_size);
3079
3080 host_impl_.SetViewportSize(viewport_size);
3081 host_impl_.active_tree()->UpdateDrawProperties();
3082 3008
3083 std::vector<Tile*> tiles = 3009 std::vector<Tile*> tiles =
3084 active_layer_->HighResTiling()->AllTilesForTesting(); 3010 active_layer_->HighResTiling()->AllTilesForTesting();
3085 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(tiles); 3011 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(tiles);
3086 3012
3087 { 3013 {
3088 SCOPED_TRACE("No occlusion"); 3014 SCOPED_TRACE("No occlusion");
3089 gfx::Rect occluded; 3015 gfx::Rect occluded;
3090 impl.AppendQuadsWithOcclusion(active_layer_, occluded); 3016 impl.AppendQuadsWithOcclusion(active_layer_, occluded);
3091 3017
(...skipping 22 matching lines...) Expand all
3114 // The layer outputs one quad, which is partially occluded. 3040 // The layer outputs one quad, which is partially occluded.
3115 EXPECT_EQ(100u - 10u, impl.quad_list().size()); 3041 EXPECT_EQ(100u - 10u, impl.quad_list().size());
3116 EXPECT_EQ(10u + 10u, partially_occluded_count); 3042 EXPECT_EQ(10u + 10u, partially_occluded_count);
3117 } 3043 }
3118 } 3044 }
3119 3045
3120 TEST_F(PictureLayerImplTest, RasterScaleChangeWithoutAnimation) { 3046 TEST_F(PictureLayerImplTest, RasterScaleChangeWithoutAnimation) {
3121 gfx::Size tile_size(host_impl_.settings().default_tile_size); 3047 gfx::Size tile_size(host_impl_.settings().default_tile_size);
3122 SetupDefaultTrees(tile_size); 3048 SetupDefaultTrees(tile_size);
3123 3049
3050 ResetTilingsAndRasterScales();
3051
3124 float contents_scale = 2.f; 3052 float contents_scale = 2.f;
3125 float device_scale = 1.f; 3053 float device_scale = 1.f;
3126 float page_scale = 1.f; 3054 float page_scale = 1.f;
3127 float maximum_animation_scale = 1.f; 3055 float maximum_animation_scale = 1.f;
3128 bool animating_transform = false; 3056 bool animating_transform = false;
3129 3057
3130 SetContentsScaleOnBothLayers(contents_scale, 3058 SetContentsScaleOnBothLayers(contents_scale,
3131 device_scale, 3059 device_scale,
3132 page_scale, 3060 page_scale,
3133 maximum_animation_scale, 3061 maximum_animation_scale,
(...skipping 20 matching lines...) Expand all
3154 page_scale, 3082 page_scale,
3155 maximum_animation_scale, 3083 maximum_animation_scale,
3156 animating_transform); 3084 animating_transform);
3157 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f); 3085 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f);
3158 } 3086 }
3159 3087
3160 TEST_F(PictureLayerImplTest, LowResReadyToDrawNotEnoughToActivate) { 3088 TEST_F(PictureLayerImplTest, LowResReadyToDrawNotEnoughToActivate) {
3161 gfx::Size tile_size(100, 100); 3089 gfx::Size tile_size(100, 100);
3162 gfx::Size layer_bounds(1000, 1000); 3090 gfx::Size layer_bounds(1000, 1000);
3163 3091
3164 host_impl_.SetViewportSize(layer_bounds);
3165
3166 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size);
3167
3168 // Make sure some tiles are not shared. 3092 // Make sure some tiles are not shared.
3169 pending_layer_->set_invalidation(gfx::Rect(gfx::Point(50, 50), tile_size)); 3093 gfx::Rect invalidation(gfx::Point(50, 50), tile_size);
3170 3094 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, invalidation);
3171 CreateHighLowResAndSetAllTilesVisible();
3172 active_layer_->SetAllTilesReady();
3173 3095
3174 // All pending layer tiles required are not ready. 3096 // All pending layer tiles required are not ready.
3175 EXPECT_FALSE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw()); 3097 EXPECT_FALSE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw());
3176 3098
3177 // Initialize all low-res tiles. 3099 // Initialize all low-res tiles.
3178 pending_layer_->SetAllTilesReadyInTiling(pending_layer_->LowResTiling()); 3100 pending_layer_->SetAllTilesReadyInTiling(pending_layer_->LowResTiling());
3179 3101
3180 // Low-res tiles should not be enough. 3102 // Low-res tiles should not be enough.
3181 EXPECT_FALSE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw()); 3103 EXPECT_FALSE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw());
3182 3104
3183 // Initialize remaining tiles. 3105 // Initialize remaining tiles.
3184 pending_layer_->SetAllTilesReady(); 3106 pending_layer_->SetAllTilesReady();
3185 3107
3186 EXPECT_TRUE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw()); 3108 EXPECT_TRUE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw());
3187 } 3109 }
3188 3110
3189 TEST_F(PictureLayerImplTest, HighResReadyToDrawEnoughToActivate) { 3111 TEST_F(PictureLayerImplTest, HighResReadyToDrawEnoughToActivate) {
3190 gfx::Size tile_size(100, 100); 3112 gfx::Size tile_size(100, 100);
3191 gfx::Size layer_bounds(1000, 1000); 3113 gfx::Size layer_bounds(1000, 1000);
3192 3114
3193 host_impl_.SetViewportSize(layer_bounds);
3194
3195 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size);
3196
3197 // Make sure some tiles are not shared. 3115 // Make sure some tiles are not shared.
3198 pending_layer_->set_invalidation(gfx::Rect(gfx::Point(50, 50), tile_size)); 3116 gfx::Rect invalidation(gfx::Point(50, 50), tile_size);
3199 3117 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, invalidation);
3200 CreateHighLowResAndSetAllTilesVisible();
3201 active_layer_->SetAllTilesReady();
3202 3118
3203 // All pending layer tiles required are not ready. 3119 // All pending layer tiles required are not ready.
3204 EXPECT_FALSE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw()); 3120 EXPECT_FALSE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw());
3205 3121
3206 // Initialize all high-res tiles. 3122 // Initialize all high-res tiles.
3207 pending_layer_->SetAllTilesReadyInTiling(pending_layer_->HighResTiling()); 3123 pending_layer_->SetAllTilesReadyInTiling(pending_layer_->HighResTiling());
3208 3124
3209 // High-res tiles should be enough, since they cover everything visible. 3125 // High-res tiles should be enough, since they cover everything visible.
3210 EXPECT_TRUE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw()); 3126 EXPECT_TRUE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw());
3211 } 3127 }
3212 3128
3213 TEST_F(PictureLayerImplTest, 3129 TEST_F(PictureLayerImplTest,
3214 SharedActiveHighResReadyAndPendingLowResReadyNotEnoughToActivate) { 3130 SharedActiveHighResReadyAndPendingLowResReadyNotEnoughToActivate) {
3215 gfx::Size tile_size(100, 100); 3131 gfx::Size tile_size(100, 100);
3216 gfx::Size layer_bounds(1000, 1000); 3132 gfx::Size layer_bounds(1000, 1000);
3217 3133
3218 host_impl_.SetViewportSize(layer_bounds);
3219
3220 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size);
3221
3222 // Make sure some tiles are not shared. 3134 // Make sure some tiles are not shared.
3223 pending_layer_->set_invalidation(gfx::Rect(gfx::Point(50, 50), tile_size)); 3135 gfx::Rect invalidation(gfx::Point(50, 50), tile_size);
3224 3136 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, invalidation);
3225 CreateHighLowResAndSetAllTilesVisible();
3226 3137
3227 // Initialize all high-res tiles in the active layer. 3138 // Initialize all high-res tiles in the active layer.
3228 active_layer_->SetAllTilesReadyInTiling(active_layer_->HighResTiling()); 3139 active_layer_->SetAllTilesReadyInTiling(active_layer_->HighResTiling());
3229 // And all the low-res tiles in the pending layer. 3140 // And all the low-res tiles in the pending layer.
3230 pending_layer_->SetAllTilesReadyInTiling(pending_layer_->LowResTiling()); 3141 pending_layer_->SetAllTilesReadyInTiling(pending_layer_->LowResTiling());
3231 3142
3232 // The unshared high-res tiles are not ready, so we cannot activate. 3143 // The unshared high-res tiles are not ready, so we cannot activate.
3233 EXPECT_FALSE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw()); 3144 EXPECT_FALSE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw());
3234 3145
3235 // When the unshared pending high-res tiles are ready, we can activate. 3146 // When the unshared pending high-res tiles are ready, we can activate.
3236 pending_layer_->SetAllTilesReadyInTiling(pending_layer_->HighResTiling()); 3147 pending_layer_->SetAllTilesReadyInTiling(pending_layer_->HighResTiling());
3237 EXPECT_TRUE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw()); 3148 EXPECT_TRUE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw());
3238 } 3149 }
3239 3150
3240 TEST_F(PictureLayerImplTest, SharedActiveHighResReadyNotEnoughToActivate) { 3151 TEST_F(PictureLayerImplTest, SharedActiveHighResReadyNotEnoughToActivate) {
3241 gfx::Size tile_size(100, 100); 3152 gfx::Size tile_size(100, 100);
3242 gfx::Size layer_bounds(1000, 1000); 3153 gfx::Size layer_bounds(1000, 1000);
3243 3154
3244 host_impl_.SetViewportSize(layer_bounds);
3245
3246 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size);
3247
3248 // Make sure some tiles are not shared. 3155 // Make sure some tiles are not shared.
3249 pending_layer_->set_invalidation(gfx::Rect(gfx::Point(50, 50), tile_size)); 3156 gfx::Rect invalidation(gfx::Point(50, 50), tile_size);
3250 3157 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, invalidation);
3251 CreateHighLowResAndSetAllTilesVisible();
3252 3158
3253 // Initialize all high-res tiles in the active layer. 3159 // Initialize all high-res tiles in the active layer.
3254 active_layer_->SetAllTilesReadyInTiling(active_layer_->HighResTiling()); 3160 active_layer_->SetAllTilesReadyInTiling(active_layer_->HighResTiling());
3255 3161
3256 // The unshared high-res tiles are not ready, so we cannot activate. 3162 // The unshared high-res tiles are not ready, so we cannot activate.
3257 EXPECT_FALSE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw()); 3163 EXPECT_FALSE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw());
3258 3164
3259 // When the unshared pending high-res tiles are ready, we can activate. 3165 // When the unshared pending high-res tiles are ready, we can activate.
3260 pending_layer_->SetAllTilesReadyInTiling(pending_layer_->HighResTiling()); 3166 pending_layer_->SetAllTilesReadyInTiling(pending_layer_->HighResTiling());
3261 EXPECT_TRUE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw()); 3167 EXPECT_TRUE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw());
3262 } 3168 }
3263 3169
3264 class NoLowResPictureLayerImplTest : public PictureLayerImplTest {
3265 public:
3266 NoLowResPictureLayerImplTest()
3267 : PictureLayerImplTest(NoLowResTilingsSettings()) {}
3268 };
3269
3270 TEST_F(NoLowResPictureLayerImplTest, ManageTilingsCreatesTilings) { 3170 TEST_F(NoLowResPictureLayerImplTest, ManageTilingsCreatesTilings) {
3271 gfx::Size tile_size(400, 400); 3171 gfx::Size tile_size(400, 400);
3272 gfx::Size layer_bounds(1300, 1900); 3172 gfx::Size layer_bounds(1300, 1900);
3273 3173
3174 scoped_refptr<FakePicturePileImpl> pending_pile =
3175 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3176 scoped_refptr<FakePicturePileImpl> active_pile =
3177 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3178
3179 SetupTrees(pending_pile, active_pile);
3180
3181 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
3182 EXPECT_LT(low_res_factor, 1.f);
3183
3184 ResetTilingsAndRasterScales();
3185
3186 SetupDrawPropertiesAndUpdateTiles(active_layer_,
3187 6.f, // ideal contents scale
3188 3.f, // device scale
3189 2.f, // page scale
3190 1.f, // maximum animation scale
3191 false);
3192 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings());
3193 EXPECT_FLOAT_EQ(6.f,
3194 active_layer_->tilings()->tiling_at(0)->contents_scale());
3195
3196 // If we change the page scale factor, then we should get new tilings.
3197 SetupDrawPropertiesAndUpdateTiles(active_layer_,
3198 6.6f, // ideal contents scale
3199 3.f, // device scale
3200 2.2f, // page scale
3201 1.f, // maximum animation scale
3202 false);
3203 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
3204 EXPECT_FLOAT_EQ(6.6f,
3205 active_layer_->tilings()->tiling_at(0)->contents_scale());
3206
3207 // If we change the device scale factor, then we should get new tilings.
3208 SetupDrawPropertiesAndUpdateTiles(active_layer_,
3209 7.26f, // ideal contents scale
3210 3.3f, // device scale
3211 2.2f, // page scale
3212 1.f, // maximum animation scale
3213 false);
3214 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings());
3215 EXPECT_FLOAT_EQ(7.26f,
3216 active_layer_->tilings()->tiling_at(0)->contents_scale());
3217
3218 // If we change the device scale factor, but end up at the same total scale
3219 // factor somehow, then we don't get new tilings.
3220 SetupDrawPropertiesAndUpdateTiles(active_layer_,
3221 7.26f, // ideal contents scale
3222 2.2f, // device scale
3223 3.3f, // page scale
3224 1.f, // maximum animation scale
3225 false);
3226 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings());
3227 EXPECT_FLOAT_EQ(7.26f,
3228 active_layer_->tilings()->tiling_at(0)->contents_scale());
3229 }
3230
3231 TEST_F(NoLowResPictureLayerImplTest, PendingLayerOnlyHasHighResTiling) {
3232 gfx::Size tile_size(400, 400);
3233 gfx::Size layer_bounds(1300, 1900);
3234
3274 scoped_refptr<FakePicturePileImpl> pending_pile = 3235 scoped_refptr<FakePicturePileImpl> pending_pile =
3275 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 3236 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3276 scoped_refptr<FakePicturePileImpl> active_pile = 3237 scoped_refptr<FakePicturePileImpl> active_pile =
3277 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 3238 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3278 3239
3279 SetupTrees(pending_pile, active_pile); 3240 SetupTrees(pending_pile, active_pile);
3280 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
3281 3241
3282 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; 3242 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
3283 EXPECT_LT(low_res_factor, 1.f); 3243 EXPECT_LT(low_res_factor, 1.f);
3284 3244
3245 ResetTilingsAndRasterScales();
3246
3285 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 3247 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
3286 6.f, // ideal contents scale 3248 6.f, // ideal contents scale
3287 3.f, // device scale 3249 3.f, // device scale
3288 2.f, // page scale 3250 2.f, // page scale
3289 1.f, // maximum animation scale 3251 1.f, // maximum animation scale
3290 false); 3252 false);
3291 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings()); 3253 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
3292 EXPECT_FLOAT_EQ(6.f, 3254 EXPECT_FLOAT_EQ(6.f,
3293 pending_layer_->tilings()->tiling_at(0)->contents_scale()); 3255 pending_layer_->tilings()->tiling_at(0)->contents_scale());
3294 3256
3295 // If we change the page scale factor, then we should get new tilings. 3257 // If we change the page scale factor, then we should get new tilings.
3296 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 3258 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
3297 6.6f, // ideal contents scale 3259 6.6f, // ideal contents scale
3298 3.f, // device scale 3260 3.f, // device scale
3299 2.2f, // page scale 3261 2.2f, // page scale
3300 1.f, // maximum animation scale 3262 1.f, // maximum animation scale
3301 false); 3263 false);
3302 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); 3264 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
3303 EXPECT_FLOAT_EQ(6.6f, 3265 EXPECT_FLOAT_EQ(6.6f,
3304 pending_layer_->tilings()->tiling_at(0)->contents_scale()); 3266 pending_layer_->tilings()->tiling_at(0)->contents_scale());
3305 3267
3306 // If we change the device scale factor, then we should get new tilings. 3268 // If we change the device scale factor, then we should get new tilings.
3307 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 3269 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
3308 7.26f, // ideal contents scale 3270 7.26f, // ideal contents scale
3309 3.3f, // device scale 3271 3.3f, // device scale
3310 2.2f, // page scale 3272 2.2f, // page scale
3311 1.f, // maximum animation scale 3273 1.f, // maximum animation scale
3312 false); 3274 false);
3313 ASSERT_EQ(3u, pending_layer_->tilings()->num_tilings()); 3275 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
3314 EXPECT_FLOAT_EQ(7.26f, 3276 EXPECT_FLOAT_EQ(7.26f,
3315 pending_layer_->tilings()->tiling_at(0)->contents_scale()); 3277 pending_layer_->tilings()->tiling_at(0)->contents_scale());
3316 3278
3317 // If we change the device scale factor, but end up at the same total scale 3279 // If we change the device scale factor, but end up at the same total scale
3318 // factor somehow, then we don't get new tilings. 3280 // factor somehow, then we don't get new tilings.
3319 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 3281 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
3320 7.26f, // ideal contents scale 3282 7.26f, // ideal contents scale
3321 2.2f, // device scale 3283 2.2f, // device scale
3322 3.3f, // page scale 3284 3.3f, // page scale
3323 1.f, // maximum animation scale 3285 1.f, // maximum animation scale
3324 false); 3286 false);
3325 ASSERT_EQ(3u, pending_layer_->tilings()->num_tilings()); 3287 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
3326 EXPECT_FLOAT_EQ(7.26f, 3288 EXPECT_FLOAT_EQ(7.26f,
3327 pending_layer_->tilings()->tiling_at(0)->contents_scale()); 3289 pending_layer_->tilings()->tiling_at(0)->contents_scale());
3328 } 3290 }
3329 3291
3330 TEST_F(NoLowResPictureLayerImplTest, AllHighResRequiredEvenIfShared) { 3292 TEST_F(NoLowResPictureLayerImplTest, AllHighResRequiredEvenIfShared) {
3331 gfx::Size layer_bounds(400, 400); 3293 gfx::Size layer_bounds(400, 400);
3332 gfx::Size tile_size(100, 100); 3294 gfx::Size tile_size(100, 100);
3333 3295
3334 host_impl_.SetViewportSize(layer_bounds); 3296 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, Region());
3335
3336 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size);
3337
3338 CreateHighLowResAndSetAllTilesVisible();
3339 3297
3340 Tile* some_active_tile = 3298 Tile* some_active_tile =
3341 active_layer_->HighResTiling()->AllTilesForTesting()[0]; 3299 active_layer_->HighResTiling()->AllTilesForTesting()[0];
3342 EXPECT_FALSE(some_active_tile->IsReadyToDraw()); 3300 EXPECT_FALSE(some_active_tile->IsReadyToDraw());
3343 3301
3344 // All tiles shared (no invalidation), so even though the active tree's 3302 // All tiles shared (no invalidation), so even though the active tree's
3345 // tiles aren't ready, there is nothing required. 3303 // tiles aren't ready, there is nothing required.
3346 pending_layer_->HighResTiling()->UpdateAllTilePrioritiesForTesting(); 3304 pending_layer_->HighResTiling()->UpdateAllTilePrioritiesForTesting();
3347 if (host_impl_.settings().create_low_res_tiling) 3305 if (host_impl_.settings().create_low_res_tiling)
3348 pending_layer_->LowResTiling()->UpdateAllTilePrioritiesForTesting(); 3306 pending_layer_->LowResTiling()->UpdateAllTilePrioritiesForTesting();
3349 3307
3350 AssertAllTilesRequired(pending_layer_->HighResTiling()); 3308 AssertAllTilesRequired(pending_layer_->HighResTiling());
3351 if (host_impl_.settings().create_low_res_tiling) 3309 if (host_impl_.settings().create_low_res_tiling)
3352 AssertNoTilesRequired(pending_layer_->LowResTiling()); 3310 AssertNoTilesRequired(pending_layer_->LowResTiling());
3353 } 3311 }
3354 3312
3355 TEST_F(NoLowResPictureLayerImplTest, NothingRequiredIfActiveMissingTiles) { 3313 TEST_F(NoLowResPictureLayerImplTest, NothingRequiredIfActiveMissingTiles) {
3356 gfx::Size layer_bounds(400, 400); 3314 gfx::Size layer_bounds(400, 400);
3357 gfx::Size tile_size(100, 100); 3315 gfx::Size tile_size(100, 100);
3316
3358 scoped_refptr<FakePicturePileImpl> pending_pile = 3317 scoped_refptr<FakePicturePileImpl> pending_pile =
3359 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 3318 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3360 // This pile will create tilings, but has no recordings so will not create any 3319 // This pile will create tilings, but has no recordings so will not create any
3361 // tiles. This is attempting to simulate scrolling past the end of recorded 3320 // tiles. This is attempting to simulate scrolling past the end of recorded
3362 // content on the active layer, where the recordings are so far away that 3321 // content on the active layer, where the recordings are so far away that
3363 // no tiles are created. 3322 // no tiles are created.
3364 scoped_refptr<FakePicturePileImpl> active_pile = 3323 scoped_refptr<FakePicturePileImpl> active_pile =
3365 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings( 3324 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings(
3366 tile_size, layer_bounds); 3325 tile_size, layer_bounds);
3367 SetupTrees(pending_pile, active_pile);
3368 pending_layer_->set_fixed_tile_size(tile_size);
3369 active_layer_->set_fixed_tile_size(tile_size);
3370 3326
3371 CreateHighLowResAndSetAllTilesVisible(); 3327 SetupTreesWithFixedTileSize(pending_pile, active_pile, tile_size, Region());
3372 3328
3373 // Active layer has tilings, but no tiles due to missing recordings. 3329 // Active layer has tilings, but no tiles due to missing recordings.
3374 EXPECT_TRUE(active_layer_->CanHaveTilings()); 3330 EXPECT_TRUE(active_layer_->CanHaveTilings());
3375 EXPECT_EQ(active_layer_->tilings()->num_tilings(), 3331 EXPECT_EQ(active_layer_->tilings()->num_tilings(),
3376 host_impl_.settings().create_low_res_tiling ? 2u : 1u); 3332 host_impl_.settings().create_low_res_tiling ? 2u : 1u);
3377 EXPECT_EQ(active_layer_->HighResTiling()->AllTilesForTesting().size(), 0u); 3333 EXPECT_EQ(active_layer_->HighResTiling()->AllTilesForTesting().size(), 0u);
3378 3334
3379 // Since the active layer has no tiles at all, the pending layer doesn't 3335 // Since the active layer has no tiles at all, the pending layer doesn't
3380 // need content in order to activate. 3336 // need content in order to activate.
3381 pending_layer_->HighResTiling()->UpdateAllTilePrioritiesForTesting(); 3337 pending_layer_->HighResTiling()->UpdateAllTilePrioritiesForTesting();
(...skipping 12 matching lines...) Expand all
3394 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks)); 3350 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
3395 3351
3396 gfx::Size tile_size(100, 100); 3352 gfx::Size tile_size(100, 100);
3397 gfx::Size layer_bounds(400, 400); 3353 gfx::Size layer_bounds(400, 400);
3398 3354
3399 scoped_refptr<FakePicturePileImpl> pending_pile = 3355 scoped_refptr<FakePicturePileImpl> pending_pile =
3400 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 3356 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3401 scoped_refptr<FakePicturePileImpl> active_pile = 3357 scoped_refptr<FakePicturePileImpl> active_pile =
3402 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 3358 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3403 3359
3404 SetupTrees(pending_pile, active_pile); 3360 SetupTreesWithInvalidation(pending_pile, active_pile, Region());
3405 3361
3406 Region invalidation;
3407 AddDefaultTilingsWithInvalidation(invalidation);
3408 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, 1.f, 1.f, 1.f, false); 3362 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, 1.f, 1.f, 1.f, false);
3409 3363
3410 // UpdateTiles with valid viewport. Should update tile viewport. 3364 // UpdateTiles with valid viewport. Should update tile viewport.
3411 // Note viewport is considered invalid if and only if in resourceless 3365 // Note viewport is considered invalid if and only if in resourceless
3412 // software draw. 3366 // software draw.
3413 bool resourceless_software_draw = false; 3367 bool resourceless_software_draw = false;
3414 gfx::Rect viewport = gfx::Rect(layer_bounds); 3368 gfx::Rect viewport = gfx::Rect(layer_bounds);
3415 gfx::Transform transform; 3369 gfx::Transform transform;
3416 host_impl_.SetExternalDrawConstraints(transform, 3370 host_impl_.SetExternalDrawConstraints(transform,
3417 viewport, 3371 viewport,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
3477 gfx::Size layer_bounds(1300, 1900); 3431 gfx::Size layer_bounds(1300, 1900);
3478 3432
3479 scoped_refptr<FakePicturePileImpl> pending_pile = 3433 scoped_refptr<FakePicturePileImpl> pending_pile =
3480 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 3434 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3481 scoped_refptr<FakePicturePileImpl> active_pile = 3435 scoped_refptr<FakePicturePileImpl> active_pile =
3482 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 3436 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3483 3437
3484 std::vector<PictureLayerTiling*> used_tilings; 3438 std::vector<PictureLayerTiling*> used_tilings;
3485 3439
3486 SetupTrees(pending_pile, active_pile); 3440 SetupTrees(pending_pile, active_pile);
3487 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
3488 3441
3489 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; 3442 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
3490 EXPECT_LT(low_res_factor, 1.f); 3443 EXPECT_LT(low_res_factor, 1.f);
3491 3444
3492 float device_scale = 1.7f; 3445 float device_scale = 1.7f;
3493 float page_scale = 3.2f; 3446 float page_scale = 3.2f;
3494 float scale = 1.f; 3447 float scale = 1.f;
3495 3448
3449 ResetTilingsAndRasterScales();
3450
3496 SetContentsScaleOnBothLayers(scale, device_scale, page_scale, 1.f, false); 3451 SetContentsScaleOnBothLayers(scale, device_scale, page_scale, 1.f, false);
3497 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings()); 3452 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings());
3498 3453
3499 // We only have ideal tilings, so they aren't removed. 3454 // We only have ideal tilings, so they aren't removed.
3500 used_tilings.clear(); 3455 used_tilings.clear();
3501 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); 3456 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
3502 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings()); 3457 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings());
3503 3458
3504 host_impl_.PinchGestureBegin(); 3459 host_impl_.PinchGestureBegin();
3505 3460
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
3571 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); 3526 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
3572 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); 3527 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
3573 3528
3574 // If we remove it from our used tilings set, it is outside the range to keep 3529 // If we remove it from our used tilings set, it is outside the range to keep
3575 // so it is deleted. 3530 // so it is deleted.
3576 used_tilings.clear(); 3531 used_tilings.clear();
3577 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); 3532 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
3578 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings()); 3533 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings());
3579 } 3534 }
3580 3535
3581 TEST_F(PictureLayerImplTest, ScaleCollision) {
3582 gfx::Size tile_size(400, 400);
3583 gfx::Size layer_bounds(1300, 1900);
3584
3585 scoped_refptr<FakePicturePileImpl> pending_pile =
3586 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3587 scoped_refptr<FakePicturePileImpl> active_pile =
3588 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3589
3590 std::vector<PictureLayerTiling*> used_tilings;
3591
3592 SetupTrees(pending_pile, active_pile);
3593
3594 float pending_contents_scale = 1.f;
3595 float active_contents_scale = 2.f;
3596 float device_scale_factor = 1.f;
3597 float page_scale_factor = 1.f;
3598 float maximum_animation_contents_scale = 1.f;
3599 bool animating_transform = false;
3600
3601 EXPECT_TRUE(host_impl_.settings().create_low_res_tiling);
3602 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
3603 EXPECT_LT(low_res_factor, 1.f);
3604
3605 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
3606 pending_contents_scale,
3607 device_scale_factor,
3608 page_scale_factor,
3609 maximum_animation_contents_scale,
3610 animating_transform);
3611 SetupDrawPropertiesAndUpdateTiles(active_layer_,
3612 active_contents_scale,
3613 device_scale_factor,
3614 page_scale_factor,
3615 maximum_animation_contents_scale,
3616 animating_transform);
3617
3618 ASSERT_EQ(4u, pending_layer_->tilings()->num_tilings());
3619 ASSERT_EQ(4u, active_layer_->tilings()->num_tilings());
3620
3621 EXPECT_EQ(active_contents_scale,
3622 pending_layer_->tilings()->tiling_at(0)->contents_scale());
3623 EXPECT_EQ(pending_contents_scale,
3624 pending_layer_->tilings()->tiling_at(1)->contents_scale());
3625 EXPECT_EQ(active_contents_scale * low_res_factor,
3626 pending_layer_->tilings()->tiling_at(2)->contents_scale());
3627 EXPECT_EQ(pending_contents_scale * low_res_factor,
3628 pending_layer_->tilings()->tiling_at(3)->contents_scale());
3629
3630 EXPECT_EQ(active_contents_scale,
3631 active_layer_->tilings()->tiling_at(0)->contents_scale());
3632 EXPECT_EQ(pending_contents_scale,
3633 active_layer_->tilings()->tiling_at(1)->contents_scale());
3634 EXPECT_EQ(active_contents_scale * low_res_factor,
3635 active_layer_->tilings()->tiling_at(2)->contents_scale());
3636 EXPECT_EQ(pending_contents_scale * low_res_factor,
3637 active_layer_->tilings()->tiling_at(3)->contents_scale());
3638
3639 // The unused low res tiling from the pending tree must be kept or we may add
3640 // it again on the active tree and collide with the pending tree.
3641 used_tilings.push_back(active_layer_->tilings()->tiling_at(1));
3642 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
3643 ASSERT_EQ(4u, active_layer_->tilings()->num_tilings());
3644
3645 EXPECT_EQ(active_contents_scale,
3646 active_layer_->tilings()->tiling_at(0)->contents_scale());
3647 EXPECT_EQ(pending_contents_scale,
3648 active_layer_->tilings()->tiling_at(1)->contents_scale());
3649 EXPECT_EQ(active_contents_scale * low_res_factor,
3650 active_layer_->tilings()->tiling_at(2)->contents_scale());
3651 EXPECT_EQ(pending_contents_scale * low_res_factor,
3652 active_layer_->tilings()->tiling_at(3)->contents_scale());
3653 }
3654
3655 TEST_F(NoLowResPictureLayerImplTest, ReleaseResources) { 3536 TEST_F(NoLowResPictureLayerImplTest, ReleaseResources) {
3656 gfx::Size tile_size(400, 400); 3537 gfx::Size tile_size(400, 400);
3657 gfx::Size layer_bounds(1300, 1900); 3538 gfx::Size layer_bounds(1300, 1900);
3658 3539
3659 scoped_refptr<FakePicturePileImpl> pending_pile = 3540 scoped_refptr<FakePicturePileImpl> pending_pile =
3660 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 3541 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3661 scoped_refptr<FakePicturePileImpl> active_pile = 3542 scoped_refptr<FakePicturePileImpl> active_pile =
3662 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 3543 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3663 3544
3664 SetupTrees(pending_pile, active_pile); 3545 SetupTrees(pending_pile, active_pile);
3665 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
3666
3667 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
3668 1.3f, // ideal contents scale
3669 2.7f, // device scale
3670 3.2f, // page scale
3671 1.f, // maximum animation scale
3672 false);
3673 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings()); 3546 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings());
3547 EXPECT_EQ(1u, active_layer_->tilings()->num_tilings());
3674 3548
3675 // All tilings should be removed when losing output surface. 3549 // All tilings should be removed when losing output surface.
3676 active_layer_->ReleaseResources(); 3550 active_layer_->ReleaseResources();
3677 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings()); 3551 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
3678 pending_layer_->ReleaseResources(); 3552 pending_layer_->ReleaseResources();
3679 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); 3553 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
3680 3554
3681 // This should create new tilings. 3555 // This should create new tilings.
3682 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 3556 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
3683 1.3f, // ideal contents scale 3557 1.3f, // ideal contents scale
3684 2.7f, // device scale 3558 2.7f, // device scale
3685 3.2f, // page scale 3559 3.2f, // page scale
3686 1.f, // maximum animation scale 3560 1.f, // maximum animation scale
3687 false); 3561 false);
3688 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings()); 3562 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings());
3689 } 3563 }
3690 3564
3691 TEST_F(PictureLayerImplTest, SharedQuadStateContainsMaxTilingScale) { 3565 TEST_F(PictureLayerImplTest, SharedQuadStateContainsMaxTilingScale) {
3692 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); 3566 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
3693 3567
3694 gfx::Size tile_size(400, 400); 3568 gfx::Size tile_size(400, 400);
3695 gfx::Size layer_bounds(1000, 2000); 3569 gfx::Size layer_bounds(1000, 2000);
3696 3570
3697 host_impl_.SetViewportSize(layer_bounds); 3571 host_impl_.SetViewportSize(gfx::Size(10000, 20000));
3698 3572
3699 scoped_refptr<FakePicturePileImpl> pending_pile = 3573 scoped_refptr<FakePicturePileImpl> pending_pile =
3700 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 3574 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3701 scoped_refptr<FakePicturePileImpl> active_pile = 3575 scoped_refptr<FakePicturePileImpl> active_pile =
3702 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 3576 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3703 3577
3704 SetupTrees(pending_pile, active_pile); 3578 SetupTrees(pending_pile, active_pile);
3705 3579
3706 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 2.5f, 1.f, 1.f, 1.f, false); 3580 ResetTilingsAndRasterScales();
3707 host_impl_.pending_tree()->UpdateDrawProperties(); 3581 SetupDrawPropertiesAndUpdateTiles(active_layer_, 2.5f, 1.f, 1.f, 1.f, false);
3708
3709 active_layer_->draw_properties().visible_content_rect =
3710 gfx::Rect(layer_bounds);
3711 host_impl_.active_tree()->UpdateDrawProperties();
3712 3582
3713 float max_contents_scale = active_layer_->MaximumTilingContentsScale(); 3583 float max_contents_scale = active_layer_->MaximumTilingContentsScale();
3584 EXPECT_EQ(2.5f, max_contents_scale);
3585
3714 gfx::Transform scaled_draw_transform = active_layer_->draw_transform(); 3586 gfx::Transform scaled_draw_transform = active_layer_->draw_transform();
3715 scaled_draw_transform.Scale(SK_MScalar1 / max_contents_scale, 3587 scaled_draw_transform.Scale(SK_MScalar1 / max_contents_scale,
3716 SK_MScalar1 / max_contents_scale); 3588 SK_MScalar1 / max_contents_scale);
3717 3589
3718 AppendQuadsData data; 3590 AppendQuadsData data;
3719 active_layer_->AppendQuads(render_pass.get(), Occlusion(), &data); 3591 active_layer_->AppendQuads(render_pass.get(), Occlusion(), &data);
3720 3592
3721 // SharedQuadState should have be of size 1, as we are doing AppenQuad once. 3593 // SharedQuadState should have be of size 1, as we are doing AppenQuad once.
3722 EXPECT_EQ(1u, render_pass->shared_quad_state_list.size()); 3594 EXPECT_EQ(1u, render_pass->shared_quad_state_list.size());
3723 // The content_to_target_transform should be scaled by the 3595 // The content_to_target_transform should be scaled by the
(...skipping 16 matching lines...) Expand all
3740 TEST_F(PictureLayerImplTest, UpdateTilesForMasksWithNoVisibleContent) { 3612 TEST_F(PictureLayerImplTest, UpdateTilesForMasksWithNoVisibleContent) {
3741 gfx::Size tile_size(400, 400); 3613 gfx::Size tile_size(400, 400);
3742 gfx::Size bounds(100000, 100); 3614 gfx::Size bounds(100000, 100);
3743 3615
3744 host_impl_.CreatePendingTree(); 3616 host_impl_.CreatePendingTree();
3745 3617
3746 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_.pending_tree(), 1); 3618 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_.pending_tree(), 1);
3747 3619
3748 scoped_ptr<FakePictureLayerImpl> layer_with_mask = 3620 scoped_ptr<FakePictureLayerImpl> layer_with_mask =
3749 FakePictureLayerImpl::Create(host_impl_.pending_tree(), 2); 3621 FakePictureLayerImpl::Create(host_impl_.pending_tree(), 2);
3750
3751 layer_with_mask->SetBounds(bounds); 3622 layer_with_mask->SetBounds(bounds);
3752 layer_with_mask->SetContentBounds(bounds); 3623 layer_with_mask->SetContentBounds(bounds);
3753 3624
3754 scoped_refptr<FakePicturePileImpl> pending_pile = 3625 scoped_refptr<FakePicturePileImpl> pending_pile =
3755 FakePicturePileImpl::CreateFilledPile(tile_size, bounds); 3626 FakePicturePileImpl::CreateFilledPile(tile_size, bounds);
3756 scoped_ptr<FakePictureLayerImpl> mask = 3627 scoped_ptr<FakePictureLayerImpl> mask =
3757 FakePictureLayerImpl::CreateWithRasterSource(host_impl_.pending_tree(), 3, 3628 FakePictureLayerImpl::CreateMaskWithRasterSource(
3758 pending_pile); 3629 host_impl_.pending_tree(), 3, pending_pile);
3759 mask->set_is_mask(true);
3760
3761 mask->SetBounds(bounds); 3630 mask->SetBounds(bounds);
3762 mask->SetContentBounds(bounds); 3631 mask->SetContentBounds(bounds);
3763 mask->SetDrawsContent(true); 3632 mask->SetDrawsContent(true);
3633 layer_with_mask->SetMaskLayer(mask.Pass());
3764 3634
3765 FakePictureLayerImpl* pending_mask_content = mask.get(); 3635 FakePictureLayerImpl* pending_mask =
3766 layer_with_mask->SetMaskLayer(mask.Pass()); 3636 static_cast<FakePictureLayerImpl*>(layer_with_mask->mask_layer());
3767 3637
3768 scoped_ptr<FakePictureLayerImpl> child_of_layer_with_mask = 3638 scoped_ptr<FakePictureLayerImpl> child_of_layer_with_mask =
3769 FakePictureLayerImpl::Create(host_impl_.pending_tree(), 4); 3639 FakePictureLayerImpl::Create(host_impl_.pending_tree(), 4);
3770
3771 child_of_layer_with_mask->SetBounds(bounds); 3640 child_of_layer_with_mask->SetBounds(bounds);
3772 child_of_layer_with_mask->SetContentBounds(bounds); 3641 child_of_layer_with_mask->SetContentBounds(bounds);
3773 child_of_layer_with_mask->SetDrawsContent(true); 3642 child_of_layer_with_mask->SetDrawsContent(true);
3774
3775 layer_with_mask->AddChild(child_of_layer_with_mask.Pass()); 3643 layer_with_mask->AddChild(child_of_layer_with_mask.Pass());
3776
3777 root->AddChild(layer_with_mask.Pass()); 3644 root->AddChild(layer_with_mask.Pass());
3778 3645
3779 host_impl_.pending_tree()->SetRootLayer(root.Pass()); 3646 host_impl_.pending_tree()->SetRootLayer(root.Pass());
3780 3647
3781 EXPECT_FALSE(pending_mask_content->tilings()); 3648 EXPECT_EQ(0u, pending_mask->num_tilings());
3782 host_impl_.pending_tree()->UpdateDrawProperties(); 3649 host_impl_.pending_tree()->UpdateDrawProperties();
3783 EXPECT_NE(0u, pending_mask_content->num_tilings()); 3650 EXPECT_NE(0u, pending_mask->num_tilings());
3784 } 3651 }
3785 3652
3786 class PictureLayerImplTestWithDelegatingRenderer : public PictureLayerImplTest { 3653 class PictureLayerImplTestWithDelegatingRenderer : public PictureLayerImplTest {
3787 public: 3654 public:
3788 PictureLayerImplTestWithDelegatingRenderer() : PictureLayerImplTest() {} 3655 PictureLayerImplTestWithDelegatingRenderer() : PictureLayerImplTest() {}
3789 3656
3790 void InitializeRenderer() override { 3657 void InitializeRenderer() override {
3791 host_impl_.InitializeRenderer(FakeOutputSurface::CreateDelegating3d()); 3658 host_impl_.InitializeRenderer(FakeOutputSurface::CreateDelegating3d());
3792 } 3659 }
3793 }; 3660 };
3794 3661
3795 TEST_F(PictureLayerImplTestWithDelegatingRenderer, 3662 TEST_F(PictureLayerImplTestWithDelegatingRenderer,
3796 DelegatingRendererWithTileOOM) { 3663 DelegatingRendererWithTileOOM) {
3797 // This test is added for crbug.com/402321, where quad should be produced when 3664 // This test is added for crbug.com/402321, where quad should be produced when
3798 // raster on demand is not allowed and tile is OOM. 3665 // raster on demand is not allowed and tile is OOM.
3799 gfx::Size tile_size = host_impl_.settings().default_tile_size; 3666 gfx::Size tile_size = host_impl_.settings().default_tile_size;
3800 gfx::Size layer_bounds(1000, 1000); 3667 gfx::Size layer_bounds(1000, 1000);
3801 3668
3802 // Create tiles. 3669 // Create tiles.
3803 scoped_refptr<FakePicturePileImpl> pending_pile = 3670 scoped_refptr<FakePicturePileImpl> pending_pile =
3804 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 3671 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3805 SetupPendingTree(pending_pile); 3672 SetupPendingTree(pending_pile);
3806 pending_layer_->SetBounds(layer_bounds); 3673 pending_layer_->SetBounds(layer_bounds);
3807 host_impl_.SetViewportSize(layer_bounds);
3808 ActivateTree(); 3674 ActivateTree();
3809 host_impl_.active_tree()->UpdateDrawProperties(); 3675 host_impl_.active_tree()->UpdateDrawProperties();
3810 std::vector<Tile*> tiles = 3676 std::vector<Tile*> tiles =
3811 active_layer_->HighResTiling()->AllTilesForTesting(); 3677 active_layer_->HighResTiling()->AllTilesForTesting();
3812 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(tiles); 3678 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(tiles);
3813 3679
3814 // Force tiles after max_tiles to be OOM. TileManager uses 3680 // Force tiles after max_tiles to be OOM. TileManager uses
3815 // GlobalStateThatImpactsTilesPriority from LayerTreeHostImpl, and we cannot 3681 // GlobalStateThatImpactsTilesPriority from LayerTreeHostImpl, and we cannot
3816 // directly set state to host_impl_, so we set policy that would change the 3682 // directly set state to host_impl_, so we set policy that would change the
3817 // state. We also need to update tree priority separately. 3683 // state. We also need to update tree priority separately.
(...skipping 26 matching lines...) Expand all
3844 class OcclusionTrackingSettings : public LowResTilingsSettings { 3710 class OcclusionTrackingSettings : public LowResTilingsSettings {
3845 public: 3711 public:
3846 OcclusionTrackingSettings() { use_occlusion_for_tile_prioritization = true; } 3712 OcclusionTrackingSettings() { use_occlusion_for_tile_prioritization = true; }
3847 }; 3713 };
3848 3714
3849 class OcclusionTrackingPictureLayerImplTest : public PictureLayerImplTest { 3715 class OcclusionTrackingPictureLayerImplTest : public PictureLayerImplTest {
3850 public: 3716 public:
3851 OcclusionTrackingPictureLayerImplTest() 3717 OcclusionTrackingPictureLayerImplTest()
3852 : PictureLayerImplTest(OcclusionTrackingSettings()) {} 3718 : PictureLayerImplTest(OcclusionTrackingSettings()) {}
3853 3719
3854 void VerifyEvictionConsidersOcclusion( 3720 void VerifyEvictionConsidersOcclusion(FakePictureLayerImpl* layer,
3855 PictureLayerImpl* layer, 3721 FakePictureLayerImpl* twin_layer,
3856 size_t expected_occluded_tile_count[NUM_TREE_PRIORITIES]) { 3722 WhichTree tree,
3723 size_t expected_occluded_tile_count) {
3724 WhichTree twin_tree = tree == ACTIVE_TREE ? PENDING_TREE : ACTIVE_TREE;
3857 for (int priority_count = 0; priority_count < NUM_TREE_PRIORITIES; 3725 for (int priority_count = 0; priority_count < NUM_TREE_PRIORITIES;
3858 ++priority_count) { 3726 ++priority_count) {
3859 TreePriority tree_priority = static_cast<TreePriority>(priority_count); 3727 TreePriority tree_priority = static_cast<TreePriority>(priority_count);
3860 size_t occluded_tile_count = 0u; 3728 size_t occluded_tile_count = 0u;
3861 Tile* last_tile = nullptr; 3729 Tile* last_tile = nullptr;
3730 std::set<Tile*> shared_tiles;
3862 3731
3863 scoped_ptr<TilingSetEvictionQueue> queue = 3732 scoped_ptr<TilingSetEvictionQueue> queue =
3864 layer->CreateEvictionQueue(tree_priority); 3733 layer->CreateEvictionQueue(tree_priority);
3865 while (!queue->IsEmpty()) { 3734 while (!queue->IsEmpty()) {
3866 Tile* tile = queue->Top(); 3735 Tile* tile = queue->Top();
3867 if (!last_tile) 3736 if (!last_tile)
3868 last_tile = tile; 3737 last_tile = tile;
3738 if (tile->is_shared())
3739 EXPECT_TRUE(shared_tiles.insert(tile).second);
3869 3740
3870 // The only way we will encounter an occluded tile after an unoccluded 3741 // The only way we will encounter an occluded tile after an unoccluded
3871 // tile is if the priorty bin decreased, the tile is required for 3742 // tile is if the priorty bin decreased, the tile is required for
3872 // activation, or the scale changed. 3743 // activation, or the scale changed.
3873 bool tile_is_occluded = 3744 bool tile_is_occluded = tile->is_occluded(tree);
3874 tile->is_occluded_for_tree_priority(tree_priority);
3875 if (tile_is_occluded) { 3745 if (tile_is_occluded) {
3876 occluded_tile_count++; 3746 occluded_tile_count++;
3877 3747
3878 bool last_tile_is_occluded = 3748 bool last_tile_is_occluded = last_tile->is_occluded(tree);
3879 last_tile->is_occluded_for_tree_priority(tree_priority);
3880 if (!last_tile_is_occluded) { 3749 if (!last_tile_is_occluded) {
3881 TilePriority::PriorityBin tile_priority_bin = 3750 TilePriority::PriorityBin tile_priority_bin =
3882 tile->priority_for_tree_priority(tree_priority).priority_bin; 3751 tile->priority(tree).priority_bin;
3883 TilePriority::PriorityBin last_tile_priority_bin = 3752 TilePriority::PriorityBin last_tile_priority_bin =
3884 last_tile->priority_for_tree_priority(tree_priority) 3753 last_tile->priority(tree).priority_bin;
3885 .priority_bin;
3886 3754
3887 EXPECT_TRUE( 3755 EXPECT_TRUE(
3888 (tile_priority_bin < last_tile_priority_bin) || 3756 (tile_priority_bin < last_tile_priority_bin) ||
3889 tile->required_for_activation() || 3757 tile->required_for_activation() ||
3890 (tile->contents_scale() != last_tile->contents_scale())); 3758 (tile->contents_scale() != last_tile->contents_scale()));
3891 } 3759 }
3892 } 3760 }
3893 last_tile = tile; 3761 last_tile = tile;
3894 queue->Pop(); 3762 queue->Pop();
3895 } 3763 }
3896 EXPECT_EQ(expected_occluded_tile_count[priority_count], 3764 // Count also shared tiles which are occluded in the tree but which were
3897 occluded_tile_count); 3765 // not returned by the tiling set eviction queue. Those shared tiles
3766 // shall be returned by the twin tiling set eviction queue.
3767 queue = twin_layer->CreateEvictionQueue(tree_priority);
3768 while (!queue->IsEmpty()) {
3769 Tile* tile = queue->Top();
3770 if (tile->is_shared()) {
3771 EXPECT_TRUE(shared_tiles.insert(tile).second);
3772 if (tile->is_occluded(tree))
3773 ++occluded_tile_count;
3774 // Check the reasons why the shared tile was not returned by
3775 // the first tiling set eviction queue.
3776 switch (tree_priority) {
3777 case SAME_PRIORITY_FOR_BOTH_TREES: {
3778 const TilePriority& priority = tile->priority(tree);
3779 const TilePriority& priority_for_tree_priority =
3780 tile->priority_for_tree_priority(tree_priority);
3781 const TilePriority& twin_priority = tile->priority(twin_tree);
3782 // Check if the shared tile was not returned by the first tiling
3783 // set eviction queue because it was out of order for the first
3784 // tiling set eviction queue but not for the twin tiling set
3785 // eviction queue.
3786 if (priority.priority_bin != twin_priority.priority_bin) {
3787 EXPECT_LT(priority_for_tree_priority.priority_bin,
3788 priority.priority_bin);
3789 EXPECT_EQ(priority_for_tree_priority.priority_bin,
3790 twin_priority.priority_bin);
3791 EXPECT_TRUE(priority_for_tree_priority.priority_bin <
3792 priority.priority_bin);
3793 } else if (tile->is_occluded(tree) !=
3794 tile->is_occluded(twin_tree)) {
3795 EXPECT_TRUE(tile->is_occluded(tree));
3796 EXPECT_FALSE(tile->is_occluded(twin_tree));
3797 EXPECT_FALSE(
3798 tile->is_occluded_for_tree_priority(tree_priority));
3799 } else if (priority.distance_to_visible !=
3800 twin_priority.distance_to_visible) {
3801 EXPECT_LT(priority_for_tree_priority.distance_to_visible,
3802 priority.distance_to_visible);
3803 EXPECT_EQ(priority_for_tree_priority.distance_to_visible,
3804 twin_priority.distance_to_visible);
3805 EXPECT_TRUE(priority_for_tree_priority.distance_to_visible <
3806 priority.distance_to_visible);
3807 } else {
3808 // Shared tiles having the same active and pending priorities
3809 // should be returned only by a pending tree eviction queue.
3810 EXPECT_EQ(ACTIVE_TREE, tree);
3811 }
3812 break;
3813 }
3814 case SMOOTHNESS_TAKES_PRIORITY:
3815 // Shared tiles should be returned only by an active tree
3816 // eviction queue.
3817 EXPECT_EQ(PENDING_TREE, tree);
3818 break;
3819 case NEW_CONTENT_TAKES_PRIORITY:
3820 // Shared tiles should be returned only by a pending tree
3821 // eviction queue.
3822 EXPECT_EQ(ACTIVE_TREE, tree);
3823 break;
3824 case NUM_TREE_PRIORITIES:
3825 NOTREACHED();
3826 break;
3827 }
3828 }
3829 queue->Pop();
3830 }
3831 EXPECT_EQ(expected_occluded_tile_count, occluded_tile_count);
3898 } 3832 }
3899 } 3833 }
3900 }; 3834 };
3901 3835
3902 TEST_F(OcclusionTrackingPictureLayerImplTest, 3836 TEST_F(OcclusionTrackingPictureLayerImplTest,
3903 OccludedTilesSkippedDuringRasterization) { 3837 OccludedTilesSkippedDuringRasterization) {
3904 base::TimeTicks time_ticks; 3838 base::TimeTicks time_ticks;
3905 time_ticks += base::TimeDelta::FromMilliseconds(1); 3839 time_ticks += base::TimeDelta::FromMilliseconds(1);
3906 host_impl_.SetCurrentBeginFrameArgs( 3840 host_impl_.SetCurrentBeginFrameArgs(
3907 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks)); 3841 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
3908 3842
3909 gfx::Size tile_size(102, 102); 3843 gfx::Size tile_size(102, 102);
3910 gfx::Size layer_bounds(1000, 1000); 3844 gfx::Size layer_bounds(1000, 1000);
3911 gfx::Size viewport_size(500, 500); 3845 gfx::Size viewport_size(500, 500);
3912 gfx::Point occluding_layer_position(310, 0); 3846 gfx::Point occluding_layer_position(310, 0);
3913 3847
3848 host_impl_.SetViewportSize(viewport_size);
3849
3914 scoped_refptr<FakePicturePileImpl> pending_pile = 3850 scoped_refptr<FakePicturePileImpl> pending_pile =
3915 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 3851 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3916 SetupPendingTree(pending_pile); 3852 SetupPendingTreeWithFixedTileSize(pending_pile, tile_size, Region());
3917 pending_layer_->set_fixed_tile_size(tile_size);
3918
3919 host_impl_.SetViewportSize(viewport_size);
3920 host_impl_.pending_tree()->UpdateDrawProperties();
3921 3853
3922 // No occlusion. 3854 // No occlusion.
3923 int unoccluded_tile_count = 0; 3855 int unoccluded_tile_count = 0;
3924 scoped_ptr<TilingSetRasterQueue> queue = 3856 scoped_ptr<TilingSetRasterQueue> queue =
3925 pending_layer_->CreateRasterQueue(false); 3857 pending_layer_->CreateRasterQueue(false);
3926 while (!queue->IsEmpty()) { 3858 while (!queue->IsEmpty()) {
3927 Tile* tile = queue->Top(); 3859 Tile* tile = queue->Top();
3928 3860
3929 // Occluded tiles should not be iterated over. 3861 // Occluded tiles should not be iterated over.
3930 EXPECT_FALSE(tile->is_occluded(PENDING_TREE)); 3862 EXPECT_FALSE(tile->is_occluded(PENDING_TREE));
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
3997 base::TimeTicks time_ticks; 3929 base::TimeTicks time_ticks;
3998 time_ticks += base::TimeDelta::FromMilliseconds(1); 3930 time_ticks += base::TimeDelta::FromMilliseconds(1);
3999 host_impl_.SetCurrentBeginFrameArgs( 3931 host_impl_.SetCurrentBeginFrameArgs(
4000 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks)); 3932 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
4001 3933
4002 gfx::Size tile_size(102, 102); 3934 gfx::Size tile_size(102, 102);
4003 gfx::Size layer_bounds(1000, 1000); 3935 gfx::Size layer_bounds(1000, 1000);
4004 gfx::Size viewport_size(500, 500); 3936 gfx::Size viewport_size(500, 500);
4005 gfx::Point occluding_layer_position(310, 0); 3937 gfx::Point occluding_layer_position(310, 0);
4006 3938
3939 host_impl_.SetViewportSize(viewport_size);
3940
4007 scoped_refptr<FakePicturePileImpl> pending_pile = 3941 scoped_refptr<FakePicturePileImpl> pending_pile =
4008 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 3942 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4009 SetupPendingTree(pending_pile); 3943 SetupPendingTreeWithFixedTileSize(pending_pile, tile_size, Region());
4010 pending_layer_->set_fixed_tile_size(tile_size);
4011
4012 host_impl_.SetViewportSize(viewport_size);
4013 host_impl_.pending_tree()->UpdateDrawProperties();
4014 3944
4015 // No occlusion. 3945 // No occlusion.
4016 int occluded_tile_count = 0; 3946 int occluded_tile_count = 0;
4017 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) { 3947 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) {
4018 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i); 3948 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i);
4019 3949
4020 occluded_tile_count = 0; 3950 occluded_tile_count = 0;
4021 for (PictureLayerTiling::CoverageIterator iter( 3951 for (PictureLayerTiling::CoverageIterator iter(
4022 tiling, 3952 tiling,
4023 pending_layer_->contents_scale_x(), 3953 pending_layer_->contents_scale_x(),
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
4118 case 1: 4048 case 1:
4119 EXPECT_EQ(4, occluded_tile_count); 4049 EXPECT_EQ(4, occluded_tile_count);
4120 break; 4050 break;
4121 default: 4051 default:
4122 NOTREACHED(); 4052 NOTREACHED();
4123 } 4053 }
4124 } 4054 }
4125 } 4055 }
4126 4056
4127 TEST_F(OcclusionTrackingPictureLayerImplTest, OcclusionForDifferentScales) { 4057 TEST_F(OcclusionTrackingPictureLayerImplTest, OcclusionForDifferentScales) {
4058 base::TimeTicks time_ticks;
4059 time_ticks += base::TimeDelta::FromMilliseconds(1);
4060 host_impl_.SetCurrentBeginFrameArgs(
4061 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
4062
4128 gfx::Size tile_size(102, 102); 4063 gfx::Size tile_size(102, 102);
4129 gfx::Size layer_bounds(1000, 1000); 4064 gfx::Size layer_bounds(1000, 1000);
4130 gfx::Size viewport_size(500, 500); 4065 gfx::Size viewport_size(500, 500);
4131 gfx::Point occluding_layer_position(310, 0); 4066 gfx::Point occluding_layer_position(310, 0);
4132 4067
4133 scoped_refptr<FakePicturePileImpl> pending_pile = 4068 scoped_refptr<FakePicturePileImpl> pending_pile =
4134 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 4069 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4135 SetupPendingTree(pending_pile);
4136 pending_layer_->set_fixed_tile_size(tile_size);
4137 4070
4071 host_impl_.SetViewportSize(viewport_size);
4072
4073 SetupPendingTreeWithFixedTileSize(pending_pile, tile_size, Region());
4138 ASSERT_TRUE(pending_layer_->CanHaveTilings()); 4074 ASSERT_TRUE(pending_layer_->CanHaveTilings());
4139 4075
4140 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
4141
4142 std::vector<PictureLayerTiling*> tilings;
4143 tilings.push_back(pending_layer_->AddTiling(low_res_factor));
4144 tilings.push_back(pending_layer_->AddTiling(0.3f));
4145 tilings.push_back(pending_layer_->AddTiling(0.7f));
4146 tilings.push_back(pending_layer_->AddTiling(1.0f));
4147 tilings.push_back(pending_layer_->AddTiling(2.0f));
4148
4149 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 1)); 4076 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 1));
4150 LayerImpl* layer1 = pending_layer_->children()[0]; 4077 LayerImpl* layer1 = pending_layer_->children()[0];
4151 layer1->SetBounds(layer_bounds); 4078 layer1->SetBounds(layer_bounds);
4152 layer1->SetContentBounds(layer_bounds); 4079 layer1->SetContentBounds(layer_bounds);
4153 layer1->SetDrawsContent(true); 4080 layer1->SetDrawsContent(true);
4154 layer1->SetContentsOpaque(true); 4081 layer1->SetContentsOpaque(true);
4155 layer1->SetPosition(occluding_layer_position); 4082 layer1->SetPosition(occluding_layer_position);
4156 4083
4157 host_impl_.SetViewportSize(viewport_size); 4084 pending_layer_->tilings()->RemoveAllTilings();
4085 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
4086 pending_layer_->AddTiling(low_res_factor);
4087 pending_layer_->AddTiling(0.3f);
4088 pending_layer_->AddTiling(0.7f);
4089 pending_layer_->AddTiling(1.0f);
4090 pending_layer_->AddTiling(2.0f);
4091
4092 time_ticks += base::TimeDelta::FromMilliseconds(1);
4093 host_impl_.SetCurrentBeginFrameArgs(
4094 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
4095 // UpdateDrawProperties with the occluding layer.
4158 host_impl_.pending_tree()->UpdateDrawProperties(); 4096 host_impl_.pending_tree()->UpdateDrawProperties();
4159 4097
4160 int tiling_count = 0; 4098 EXPECT_EQ(5u, pending_layer_->num_tilings());
4099
4161 int occluded_tile_count = 0; 4100 int occluded_tile_count = 0;
4162 for (std::vector<PictureLayerTiling*>::iterator tiling_iterator = 4101 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) {
4163 tilings.begin(); 4102 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i);
4164 tiling_iterator != tilings.end(); 4103 tiling->UpdateAllTilePrioritiesForTesting();
4165 ++tiling_iterator) { 4104 std::vector<Tile*> tiles = tiling->AllTilesForTesting();
4166 (*tiling_iterator)->UpdateAllTilePrioritiesForTesting();
4167 std::vector<Tile*> tiles = (*tiling_iterator)->AllTilesForTesting();
4168 4105
4169 occluded_tile_count = 0; 4106 occluded_tile_count = 0;
4170 for (size_t i = 0; i < tiles.size(); ++i) { 4107 for (size_t j = 0; j < tiles.size(); ++j) {
4171 if (tiles[i]->is_occluded(PENDING_TREE)) { 4108 if (tiles[j]->is_occluded(PENDING_TREE)) {
4172 gfx::Rect scaled_content_rect = ScaleToEnclosingRect( 4109 gfx::Rect scaled_content_rect = ScaleToEnclosingRect(
4173 tiles[i]->content_rect(), 1.0f / tiles[i]->contents_scale()); 4110 tiles[j]->content_rect(), 1.0f / tiles[j]->contents_scale());
4174 EXPECT_GE(scaled_content_rect.x(), occluding_layer_position.x()); 4111 EXPECT_GE(scaled_content_rect.x(), occluding_layer_position.x());
4175 occluded_tile_count++; 4112 occluded_tile_count++;
4176 } 4113 }
4177 } 4114 }
4178 switch (tiling_count) { 4115
4116 switch (i) {
4179 case 0: 4117 case 0:
4118 EXPECT_EQ(occluded_tile_count, 30);
4119 break;
4180 case 1: 4120 case 1:
4181 EXPECT_EQ(occluded_tile_count, 2); 4121 EXPECT_EQ(occluded_tile_count, 5);
4182 break; 4122 break;
4183 case 2: 4123 case 2:
4184 EXPECT_EQ(occluded_tile_count, 4); 4124 EXPECT_EQ(occluded_tile_count, 4);
4185 break; 4125 break;
4126 case 4:
4186 case 3: 4127 case 3:
4187 EXPECT_EQ(occluded_tile_count, 5); 4128 EXPECT_EQ(occluded_tile_count, 2);
4188 break;
4189 case 4:
4190 EXPECT_EQ(occluded_tile_count, 30);
4191 break; 4129 break;
4192 default: 4130 default:
4193 NOTREACHED(); 4131 NOTREACHED();
4194 } 4132 }
4195
4196 tiling_count++;
4197 } 4133 }
4198
4199 EXPECT_EQ(tiling_count, 5);
4200 } 4134 }
4201 4135
4202 TEST_F(OcclusionTrackingPictureLayerImplTest, DifferentOcclusionOnTrees) { 4136 TEST_F(OcclusionTrackingPictureLayerImplTest, DifferentOcclusionOnTrees) {
4203 gfx::Size tile_size(102, 102); 4137 gfx::Size tile_size(102, 102);
4204 gfx::Size layer_bounds(1000, 1000); 4138 gfx::Size layer_bounds(1000, 1000);
4205 gfx::Size viewport_size(1000, 1000); 4139 gfx::Size viewport_size(1000, 1000);
4206 gfx::Point occluding_layer_position(310, 0); 4140 gfx::Point occluding_layer_position(310, 0);
4207 gfx::Rect invalidation_rect(230, 230, 102, 102); 4141 gfx::Rect invalidation_rect(230, 230, 102, 102);
4208 4142
4209 scoped_refptr<FakePicturePileImpl> pending_pile = 4143 scoped_refptr<FakePicturePileImpl> pending_pile =
4210 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 4144 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4211 scoped_refptr<FakePicturePileImpl> active_pile = 4145 scoped_refptr<FakePicturePileImpl> active_pile =
4212 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 4146 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4213 SetupTrees(pending_pile, active_pile); 4147
4148 host_impl_.SetViewportSize(viewport_size);
4149 SetupPendingTree(active_pile);
4214 4150
4215 // Partially occlude the active layer. 4151 // Partially occlude the active layer.
4216 active_layer_->AddChild(LayerImpl::Create(host_impl_.active_tree(), 2)); 4152 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 2));
4217 LayerImpl* layer1 = active_layer_->children()[0]; 4153 LayerImpl* layer1 = pending_layer_->children()[0];
4218 layer1->SetBounds(layer_bounds); 4154 layer1->SetBounds(layer_bounds);
4219 layer1->SetContentBounds(layer_bounds); 4155 layer1->SetContentBounds(layer_bounds);
4220 layer1->SetDrawsContent(true); 4156 layer1->SetDrawsContent(true);
4221 layer1->SetContentsOpaque(true); 4157 layer1->SetContentsOpaque(true);
4222 layer1->SetPosition(occluding_layer_position); 4158 layer1->SetPosition(occluding_layer_position);
4223 4159
4160 ActivateTree();
4161
4224 // Partially invalidate the pending layer. 4162 // Partially invalidate the pending layer.
4225 pending_layer_->set_invalidation(invalidation_rect); 4163 SetupPendingTreeWithInvalidation(pending_pile, invalidation_rect);
4226
4227 host_impl_.SetViewportSize(viewport_size);
4228
4229 active_layer_->CreateDefaultTilingsAndTiles();
4230 pending_layer_->CreateDefaultTilingsAndTiles();
4231 4164
4232 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) { 4165 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) {
4233 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i); 4166 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i);
4234 tiling->UpdateAllTilePrioritiesForTesting(); 4167 tiling->UpdateAllTilePrioritiesForTesting();
4235 4168
4236 for (PictureLayerTiling::CoverageIterator iter( 4169 for (PictureLayerTiling::CoverageIterator iter(
4237 tiling, 4170 tiling,
4238 pending_layer_->contents_scale_x(), 4171 pending_layer_->contents_scale_x(),
4239 gfx::Rect(layer_bounds)); 4172 gfx::Rect(layer_bounds));
4240 iter; 4173 iter;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
4299 // the occluding layer. 4232 // the occluding layer.
4300 EXPECT_EQ(tile->is_occluded(ACTIVE_TREE), 4233 EXPECT_EQ(tile->is_occluded(ACTIVE_TREE),
4301 scaled_content_rect.x() >= occluding_layer_position.x()); 4234 scaled_content_rect.x() >= occluding_layer_position.x());
4302 } 4235 }
4303 } 4236 }
4304 } 4237 }
4305 } 4238 }
4306 4239
4307 TEST_F(OcclusionTrackingPictureLayerImplTest, 4240 TEST_F(OcclusionTrackingPictureLayerImplTest,
4308 OccludedTilesConsideredDuringEviction) { 4241 OccludedTilesConsideredDuringEviction) {
4242 base::TimeTicks time_ticks;
4243 time_ticks += base::TimeDelta::FromMilliseconds(1);
4244 host_impl_.SetCurrentBeginFrameArgs(
4245 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
4246
4309 gfx::Size tile_size(102, 102); 4247 gfx::Size tile_size(102, 102);
4310 gfx::Size layer_bounds(1000, 1000); 4248 gfx::Size layer_bounds(1000, 1000);
4311 gfx::Size viewport_size(500, 500); 4249 gfx::Size viewport_size(1000, 1000);
4312 gfx::Point pending_occluding_layer_position(310, 0); 4250 gfx::Point pending_occluding_layer_position(310, 0);
4313 gfx::Point active_occluding_layer_position(0, 310); 4251 gfx::Point active_occluding_layer_position(0, 310);
4314 gfx::Rect invalidation_rect(230, 230, 102, 102); 4252 gfx::Rect invalidation_rect(230, 230, 102, 102);
4315 4253
4254 host_impl_.SetViewportSize(viewport_size);
4255 host_impl_.SetDeviceScaleFactor(2.f);
4256
4316 scoped_refptr<FakePicturePileImpl> pending_pile = 4257 scoped_refptr<FakePicturePileImpl> pending_pile =
4317 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 4258 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4318 scoped_refptr<FakePicturePileImpl> active_pile = 4259 scoped_refptr<FakePicturePileImpl> active_pile =
4319 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 4260 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4320 SetupTrees(pending_pile, active_pile);
4321 4261
4322 pending_layer_->set_fixed_tile_size(tile_size); 4262 SetupPendingTreeWithFixedTileSize(active_pile, tile_size, Region());
4323 active_layer_->set_fixed_tile_size(tile_size);
4324 4263
4325 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; 4264 // Partially occlude the active layer.
4265 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 2));
4266 LayerImpl* active_occluding_layer = pending_layer_->children()[0];
4267 active_occluding_layer->SetBounds(layer_bounds);
4268 active_occluding_layer->SetContentBounds(layer_bounds);
4269 active_occluding_layer->SetDrawsContent(true);
4270 active_occluding_layer->SetContentsOpaque(true);
4271 active_occluding_layer->SetPosition(active_occluding_layer_position);
4326 4272
4327 std::vector<PictureLayerTiling*> tilings; 4273 ActivateTree();
4328 tilings.push_back(pending_layer_->AddTiling(low_res_factor));
4329 tilings.push_back(pending_layer_->AddTiling(0.3f));
4330 tilings.push_back(pending_layer_->AddTiling(0.7f));
4331 tilings.push_back(pending_layer_->AddTiling(1.0f));
4332 tilings.push_back(pending_layer_->AddTiling(2.0f));
4333 4274
4334 EXPECT_EQ(5u, pending_layer_->num_tilings()); 4275 // Partially invalidate the pending layer. Tiles inside the invalidation rect
4335 EXPECT_EQ(5u, active_layer_->num_tilings()); 4276 // are not shared between trees.
4277 SetupPendingTreeWithFixedTileSize(pending_pile, tile_size, invalidation_rect);
4336 4278
4337 // Partially occlude the pending layer. 4279 // Partially occlude the pending layer in a different way.
4338 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 1)); 4280 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 3));
4339 LayerImpl* pending_occluding_layer = pending_layer_->children()[0]; 4281 LayerImpl* pending_occluding_layer = pending_layer_->children()[0];
4340 pending_occluding_layer->SetBounds(layer_bounds); 4282 pending_occluding_layer->SetBounds(layer_bounds);
4341 pending_occluding_layer->SetContentBounds(layer_bounds); 4283 pending_occluding_layer->SetContentBounds(layer_bounds);
4342 pending_occluding_layer->SetDrawsContent(true); 4284 pending_occluding_layer->SetDrawsContent(true);
4343 pending_occluding_layer->SetContentsOpaque(true); 4285 pending_occluding_layer->SetContentsOpaque(true);
4344 pending_occluding_layer->SetPosition(pending_occluding_layer_position); 4286 pending_occluding_layer->SetPosition(pending_occluding_layer_position);
4345 4287
4346 // Partially occlude the active layer. 4288 EXPECT_EQ(2u, pending_layer_->num_tilings());
4347 active_layer_->AddChild(LayerImpl::Create(host_impl_.active_tree(), 2)); 4289 EXPECT_EQ(2u, active_layer_->num_tilings());
4348 LayerImpl* active_occluding_layer = active_layer_->children()[0];
4349 active_occluding_layer->SetBounds(layer_bounds);
4350 active_occluding_layer->SetContentBounds(layer_bounds);
4351 active_occluding_layer->SetDrawsContent(true);
4352 active_occluding_layer->SetContentsOpaque(true);
4353 active_occluding_layer->SetPosition(active_occluding_layer_position);
4354 4290
4355 // Partially invalidate the pending layer. Tiles inside the invalidation rect 4291 time_ticks += base::TimeDelta::FromMilliseconds(1);
4356 // are not shared between trees. 4292 host_impl_.SetCurrentBeginFrameArgs(
4357 pending_layer_->set_invalidation(invalidation_rect); 4293 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
4358 4294 // UpdateDrawProperties with the occluding layer.
4359 host_impl_.SetViewportSize(viewport_size);
4360 host_impl_.active_tree()->UpdateDrawProperties();
4361 host_impl_.pending_tree()->UpdateDrawProperties(); 4295 host_impl_.pending_tree()->UpdateDrawProperties();
4362 4296
4363 // The expected number of occluded tiles on each of the 5 tilings for each of 4297 // The expected number of occluded tiles on each of the 2 tilings for each of
4364 // the 3 tree priorities. 4298 // the 3 tree priorities.
4365 size_t expected_occluded_tile_count_on_both[] = {9u, 1u, 1u, 1u, 1u}; 4299 size_t expected_occluded_tile_count_on_both[] = {9u, 1u};
4366 size_t expected_occluded_tile_count_on_active[] = {30u, 5u, 4u, 2u, 2u}; 4300 size_t expected_occluded_tile_count_on_active[] = {30u, 3u};
4367 size_t expected_occluded_tile_count_on_pending[] = {30u, 5u, 4u, 2u, 2u}; 4301 size_t expected_occluded_tile_count_on_pending[] = {30u, 3u};
4368 4302
4369 // The total expected number of occluded tiles on all tilings for each of the 4303 size_t total_expected_occluded_tile_count_on_trees[] = {33u, 33u};
4370 // 3 tree priorities.
4371 size_t total_expected_occluded_tile_count[] = {13u, 43u, 43u};
4372
4373 ASSERT_EQ(arraysize(total_expected_occluded_tile_count), NUM_TREE_PRIORITIES);
4374 4304
4375 // Verify number of occluded tiles on the pending layer for each tiling. 4305 // Verify number of occluded tiles on the pending layer for each tiling.
4376 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) { 4306 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) {
4377 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i); 4307 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i);
4378 tiling->CreateAllTilesForTesting();
4379 tiling->UpdateAllTilePrioritiesForTesting(); 4308 tiling->UpdateAllTilePrioritiesForTesting();
4380 4309
4381 size_t occluded_tile_count_on_pending = 0u; 4310 size_t occluded_tile_count_on_pending = 0u;
4382 size_t occluded_tile_count_on_active = 0u; 4311 size_t occluded_tile_count_on_active = 0u;
4383 size_t occluded_tile_count_on_both = 0u; 4312 size_t occluded_tile_count_on_both = 0u;
4384 for (PictureLayerTiling::CoverageIterator iter( 4313 for (PictureLayerTiling::CoverageIterator iter(tiling, 1.f,
4385 tiling, 4314 gfx::Rect(layer_bounds));
4386 pending_layer_->contents_scale_x(), 4315 iter; ++iter) {
4387 gfx::Rect(layer_bounds));
4388 iter;
4389 ++iter) {
4390 Tile* tile = *iter; 4316 Tile* tile = *iter;
4391 4317
4318 if (!tile)
4319 continue;
4392 if (tile->is_occluded(PENDING_TREE)) 4320 if (tile->is_occluded(PENDING_TREE))
4393 occluded_tile_count_on_pending++; 4321 occluded_tile_count_on_pending++;
4394 if (tile->is_occluded(ACTIVE_TREE)) 4322 if (tile->is_occluded(ACTIVE_TREE))
4395 occluded_tile_count_on_active++; 4323 occluded_tile_count_on_active++;
4396 if (tile->is_occluded(PENDING_TREE) && tile->is_occluded(ACTIVE_TREE)) 4324 if (tile->is_occluded(PENDING_TREE) && tile->is_occluded(ACTIVE_TREE))
4397 occluded_tile_count_on_both++; 4325 occluded_tile_count_on_both++;
4398 } 4326 }
4399 EXPECT_EQ(expected_occluded_tile_count_on_pending[i], 4327 EXPECT_EQ(expected_occluded_tile_count_on_pending[i],
4400 occluded_tile_count_on_pending) 4328 occluded_tile_count_on_pending)
4401 << i; 4329 << tiling->contents_scale();
4402 EXPECT_EQ(expected_occluded_tile_count_on_active[i], 4330 EXPECT_EQ(expected_occluded_tile_count_on_active[i],
4403 occluded_tile_count_on_active) 4331 occluded_tile_count_on_active)
4404 << i; 4332 << tiling->contents_scale();
4405 EXPECT_EQ(expected_occluded_tile_count_on_both[i], 4333 EXPECT_EQ(expected_occluded_tile_count_on_both[i],
4406 occluded_tile_count_on_both) 4334 occluded_tile_count_on_both)
4407 << i; 4335 << tiling->contents_scale();
4408 } 4336 }
4409 4337
4410 // Verify number of occluded tiles on the active layer for each tiling. 4338 // Verify number of occluded tiles on the active layer for each tiling.
4411 for (size_t i = 0; i < active_layer_->num_tilings(); ++i) { 4339 for (size_t i = 0; i < active_layer_->num_tilings(); ++i) {
4412 PictureLayerTiling* tiling = active_layer_->tilings()->tiling_at(i); 4340 PictureLayerTiling* tiling = active_layer_->tilings()->tiling_at(i);
4413 tiling->CreateAllTilesForTesting();
4414 tiling->UpdateAllTilePrioritiesForTesting(); 4341 tiling->UpdateAllTilePrioritiesForTesting();
4415 4342
4416 size_t occluded_tile_count_on_pending = 0u; 4343 size_t occluded_tile_count_on_pending = 0u;
4417 size_t occluded_tile_count_on_active = 0u; 4344 size_t occluded_tile_count_on_active = 0u;
4418 size_t occluded_tile_count_on_both = 0u; 4345 size_t occluded_tile_count_on_both = 0u;
4419 for (PictureLayerTiling::CoverageIterator iter( 4346 for (PictureLayerTiling::CoverageIterator iter(
4420 tiling, 4347 tiling,
4421 pending_layer_->contents_scale_x(), 4348 pending_layer_->contents_scale_x(),
4422 gfx::Rect(layer_bounds)); 4349 gfx::Rect(layer_bounds));
4423 iter; 4350 iter;
4424 ++iter) { 4351 ++iter) {
4425 Tile* tile = *iter; 4352 Tile* tile = *iter;
4426 4353
4354 if (!tile)
4355 continue;
4427 if (tile->is_occluded(PENDING_TREE)) 4356 if (tile->is_occluded(PENDING_TREE))
4428 occluded_tile_count_on_pending++; 4357 occluded_tile_count_on_pending++;
4429 if (tile->is_occluded(ACTIVE_TREE)) 4358 if (tile->is_occluded(ACTIVE_TREE))
4430 occluded_tile_count_on_active++; 4359 occluded_tile_count_on_active++;
4431 if (tile->is_occluded(PENDING_TREE) && tile->is_occluded(ACTIVE_TREE)) 4360 if (tile->is_occluded(PENDING_TREE) && tile->is_occluded(ACTIVE_TREE))
4432 occluded_tile_count_on_both++; 4361 occluded_tile_count_on_both++;
4433 } 4362 }
4434 EXPECT_EQ(expected_occluded_tile_count_on_pending[i], 4363 EXPECT_EQ(expected_occluded_tile_count_on_pending[i],
4435 occluded_tile_count_on_pending) 4364 occluded_tile_count_on_pending)
4436 << i; 4365 << i;
4437 EXPECT_EQ(expected_occluded_tile_count_on_active[i], 4366 EXPECT_EQ(expected_occluded_tile_count_on_active[i],
4438 occluded_tile_count_on_active) 4367 occluded_tile_count_on_active)
4439 << i; 4368 << i;
4440 EXPECT_EQ(expected_occluded_tile_count_on_both[i], 4369 EXPECT_EQ(expected_occluded_tile_count_on_both[i],
4441 occluded_tile_count_on_both) 4370 occluded_tile_count_on_both)
4442 << i; 4371 << i;
4443 } 4372 }
4444 4373
4445 std::vector<Tile*> all_tiles; 4374 std::vector<Tile*> all_tiles;
4446 for (std::vector<PictureLayerTiling*>::iterator tiling_iterator = 4375 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) {
4447 tilings.begin(); 4376 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i);
4448 tiling_iterator != tilings.end(); 4377 std::vector<Tile*> tiles = tiling->AllTilesForTesting();
4449 ++tiling_iterator) { 4378 all_tiles.insert(all_tiles.end(), tiles.begin(), tiles.end());
4450 std::vector<Tile*> tiles = (*tiling_iterator)->AllTilesForTesting();
4451 std::copy(tiles.begin(), tiles.end(), std::back_inserter(all_tiles));
4452 } 4379 }
4453 4380
4454 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles); 4381 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles);
4455 4382
4456 VerifyEvictionConsidersOcclusion(pending_layer_, 4383 VerifyEvictionConsidersOcclusion(
4457 total_expected_occluded_tile_count); 4384 pending_layer_, active_layer_, PENDING_TREE,
4458 VerifyEvictionConsidersOcclusion(active_layer_, 4385 total_expected_occluded_tile_count_on_trees[PENDING_TREE]);
4459 total_expected_occluded_tile_count); 4386 VerifyEvictionConsidersOcclusion(
4387 active_layer_, pending_layer_, ACTIVE_TREE,
4388 total_expected_occluded_tile_count_on_trees[ACTIVE_TREE]);
4389
4390 // Repeat the tests without valid active tree priorities.
4391 active_layer_->set_has_valid_tile_priorities(false);
4392 VerifyEvictionConsidersOcclusion(
4393 pending_layer_, active_layer_, PENDING_TREE,
4394 total_expected_occluded_tile_count_on_trees[PENDING_TREE]);
4395 VerifyEvictionConsidersOcclusion(
4396 active_layer_, pending_layer_, ACTIVE_TREE, 0u);
4397 active_layer_->set_has_valid_tile_priorities(true);
4398
4399 // Repeat the tests without valid pending tree priorities.
4400 pending_layer_->set_has_valid_tile_priorities(false);
4401 VerifyEvictionConsidersOcclusion(
4402 active_layer_, pending_layer_, ACTIVE_TREE,
4403 total_expected_occluded_tile_count_on_trees[ACTIVE_TREE]);
4404 VerifyEvictionConsidersOcclusion(
4405 pending_layer_, active_layer_, PENDING_TREE, 0u);
4406 pending_layer_->set_has_valid_tile_priorities(true);
4460 } 4407 }
4461 4408
4462 TEST_F(PictureLayerImplTest, PendingOrActiveTwinLayer) { 4409 TEST_F(PictureLayerImplTest, PendingOrActiveTwinLayer) {
4463 gfx::Size tile_size(102, 102); 4410 gfx::Size tile_size(102, 102);
4464 gfx::Size layer_bounds(1000, 1000); 4411 gfx::Size layer_bounds(1000, 1000);
4465 4412
4466 scoped_refptr<FakePicturePileImpl> pile = 4413 scoped_refptr<FakePicturePileImpl> pile =
4467 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 4414 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4468 SetupPendingTree(pile); 4415 SetupPendingTree(pile);
4469 EXPECT_FALSE(pending_layer_->GetPendingOrActiveTwinLayer()); 4416 EXPECT_FALSE(pending_layer_->GetPendingOrActiveTwinLayer());
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
4523 gfx::Size layer_bounds(200, 200); 4470 gfx::Size layer_bounds(200, 200);
4524 gfx::Rect layer_rect(layer_bounds); 4471 gfx::Rect layer_rect(layer_bounds);
4525 4472
4526 FakeContentLayerClient client; 4473 FakeContentLayerClient client;
4527 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client); 4474 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client);
4528 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); 4475 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D);
4529 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&host_client); 4476 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&host_client);
4530 host->SetRootLayer(layer); 4477 host->SetRootLayer(layer);
4531 RecordingSource* recording_source = layer->GetRecordingSourceForTesting(); 4478 RecordingSource* recording_source = layer->GetRecordingSourceForTesting();
4532 4479
4533 host_impl_.SetViewportSize(layer_bounds);
4534
4535 int frame_number = 0; 4480 int frame_number = 0;
4536 4481
4537 client.set_fill_with_nonsolid_color(!test_for_solid); 4482 client.set_fill_with_nonsolid_color(!test_for_solid);
4538 4483
4539 Region invalidation(layer_rect); 4484 Region invalidation(layer_rect);
4540 recording_source->UpdateAndExpandInvalidation( 4485 recording_source->UpdateAndExpandInvalidation(
4541 &client, &invalidation, false, layer_bounds, layer_rect, frame_number++, 4486 &client, &invalidation, false, layer_bounds, layer_rect, frame_number++,
4542 Picture::RECORD_NORMALLY); 4487 Picture::RECORD_NORMALLY);
4543 4488
4544 scoped_refptr<RasterSource> pending_raster_source = 4489 scoped_refptr<RasterSource> pending_raster_source =
4545 recording_source->CreateRasterSource(); 4490 recording_source->CreateRasterSource();
4546 4491
4547 SetupPendingTree(pending_raster_source); 4492 SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size, Region());
4548 ActivateTree(); 4493 ActivateTree();
4549 4494
4550 active_layer_->set_fixed_tile_size(tile_size);
4551 host_impl_.active_tree()->UpdateDrawProperties();
4552 if (test_for_solid) { 4495 if (test_for_solid) {
4553 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings()); 4496 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
4554 } else { 4497 } else {
4555 ASSERT_TRUE(active_layer_->tilings()); 4498 ASSERT_TRUE(active_layer_->tilings());
4556 ASSERT_GT(active_layer_->tilings()->num_tilings(), 0u); 4499 ASSERT_GT(active_layer_->tilings()->num_tilings(), 0u);
4557 std::vector<Tile*> tiles = 4500 std::vector<Tile*> tiles =
4558 active_layer_->tilings()->tiling_at(0)->AllTilesForTesting(); 4501 active_layer_->tilings()->tiling_at(0)->AllTilesForTesting();
4559 EXPECT_FALSE(tiles.empty()); 4502 EXPECT_FALSE(tiles.empty());
4560 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(tiles); 4503 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(tiles);
4561 } 4504 }
(...skipping 28 matching lines...) Expand all
4590 gfx::Size layer_bounds(200, 200); 4533 gfx::Size layer_bounds(200, 200);
4591 gfx::Rect layer_rect(layer_bounds); 4534 gfx::Rect layer_rect(layer_bounds);
4592 4535
4593 FakeContentLayerClient client; 4536 FakeContentLayerClient client;
4594 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client); 4537 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client);
4595 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); 4538 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D);
4596 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&host_client); 4539 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&host_client);
4597 host->SetRootLayer(layer); 4540 host->SetRootLayer(layer);
4598 RecordingSource* recording_source = layer->GetRecordingSourceForTesting(); 4541 RecordingSource* recording_source = layer->GetRecordingSourceForTesting();
4599 4542
4600 host_impl_.SetViewportSize(layer_bounds);
4601
4602 int frame_number = 0; 4543 int frame_number = 0;
4603 4544
4604 client.set_fill_with_nonsolid_color(true); 4545 client.set_fill_with_nonsolid_color(true);
4605 4546
4606 Region invalidation1(layer_rect); 4547 Region invalidation1(layer_rect);
4607 recording_source->UpdateAndExpandInvalidation( 4548 recording_source->UpdateAndExpandInvalidation(
4608 &client, &invalidation1, false, layer_bounds, layer_rect, frame_number++, 4549 &client, &invalidation1, false, layer_bounds, layer_rect, frame_number++,
4609 Picture::RECORD_NORMALLY); 4550 Picture::RECORD_NORMALLY);
4610 4551
4611 scoped_refptr<RasterSource> raster_source1 = 4552 scoped_refptr<RasterSource> raster_source1 =
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
4689 if (*iter) 4630 if (*iter)
4690 tiles.push_back(*iter); 4631 tiles.push_back(*iter);
4691 } 4632 }
4692 4633
4693 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(tiles); 4634 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(tiles);
4694 4635
4695 // Ensure we can activate. 4636 // Ensure we can activate.
4696 EXPECT_TRUE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw()); 4637 EXPECT_TRUE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw());
4697 } 4638 }
4698 4639
4640 TEST_F(PictureLayerImplTest, CloneMissingRecordings) {
4641 gfx::Size tile_size(100, 100);
4642 gfx::Size layer_bounds(400, 400);
4643
4644 scoped_refptr<FakePicturePileImpl> filled_pile =
4645 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4646 scoped_refptr<FakePicturePileImpl> partial_pile =
4647 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds);
4648 for (int i = 1; i < partial_pile->tiling().num_tiles_x(); ++i) {
4649 for (int j = 1; j < partial_pile->tiling().num_tiles_y(); ++j)
4650 partial_pile->AddRecordingAt(i, j);
4651 }
4652
4653 SetupPendingTreeWithFixedTileSize(filled_pile, tile_size, Region());
4654 ActivateTree();
4655
4656 PictureLayerTiling* pending_tiling = old_pending_layer_->HighResTiling();
4657 PictureLayerTiling* active_tiling = active_layer_->HighResTiling();
4658
4659 // We should have all tiles in both tile sets.
4660 EXPECT_EQ(5u * 5u, pending_tiling->AllTilesForTesting().size());
4661 EXPECT_EQ(5u * 5u, active_tiling->AllTilesForTesting().size());
4662
4663 // Now put a partially-recorded pile on the pending tree (and invalidate
4664 // everything, since the main thread PicturePile will invalidate dropped
4665 // recordings). This will cause us to be missing some tiles.
4666 SetupPendingTreeWithFixedTileSize(partial_pile, tile_size,
4667 Region(gfx::Rect(layer_bounds)));
4668 EXPECT_EQ(3u * 3u, pending_tiling->AllTilesForTesting().size());
4669 EXPECT_FALSE(pending_tiling->TileAt(0, 0));
4670 EXPECT_FALSE(pending_tiling->TileAt(1, 1));
4671 EXPECT_TRUE(pending_tiling->TileAt(2, 2));
4672
4673 // Active is not affected yet.
4674 EXPECT_EQ(5u * 5u, active_tiling->AllTilesForTesting().size());
4675
4676 // Activate the tree. The same tiles go missing on the active tree.
4677 ActivateTree();
4678 EXPECT_EQ(3u * 3u, active_tiling->AllTilesForTesting().size());
4679 EXPECT_FALSE(active_tiling->TileAt(0, 0));
4680 EXPECT_FALSE(active_tiling->TileAt(1, 1));
4681 EXPECT_TRUE(active_tiling->TileAt(2, 2));
4682
4683 // Now put a full recording on the pending tree again. We'll get all our tiles
4684 // back.
4685 SetupPendingTreeWithFixedTileSize(filled_pile, tile_size,
4686 Region(gfx::Rect(layer_bounds)));
4687 EXPECT_EQ(5u * 5u, pending_tiling->AllTilesForTesting().size());
4688
4689 // Active is not affected yet.
4690 EXPECT_EQ(3u * 3u, active_tiling->AllTilesForTesting().size());
4691
4692 // Activate the tree. The tiles are created and shared on the active tree.
4693 ActivateTree();
4694 EXPECT_EQ(5u * 5u, active_tiling->AllTilesForTesting().size());
4695 EXPECT_TRUE(active_tiling->TileAt(0, 0)->is_shared());
4696 EXPECT_TRUE(active_tiling->TileAt(1, 1)->is_shared());
4697 EXPECT_TRUE(active_tiling->TileAt(2, 2)->is_shared());
4698 }
4699
4699 class TileSizeSettings : public ImplSidePaintingSettings { 4700 class TileSizeSettings : public ImplSidePaintingSettings {
4700 public: 4701 public:
4701 TileSizeSettings() { 4702 TileSizeSettings() {
4702 default_tile_size = gfx::Size(100, 100); 4703 default_tile_size = gfx::Size(100, 100);
4703 max_untiled_layer_size = gfx::Size(200, 200); 4704 max_untiled_layer_size = gfx::Size(200, 200);
4704 } 4705 }
4705 }; 4706 };
4706 4707
4707 class TileSizeTest : public PictureLayerImplTest { 4708 class TileSizeTest : public PictureLayerImplTest {
4708 public: 4709 public:
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
4756 result = layer->CalculateTileSize(gfx::Size(447, 400)); 4757 result = layer->CalculateTileSize(gfx::Size(447, 400));
4757 EXPECT_EQ(result.width(), 448); 4758 EXPECT_EQ(result.width(), 448);
4758 EXPECT_EQ(result.height(), 448); 4759 EXPECT_EQ(result.height(), 448);
4759 result = layer->CalculateTileSize(gfx::Size(500, 499)); 4760 result = layer->CalculateTileSize(gfx::Size(500, 499));
4760 EXPECT_EQ(result.width(), 512); 4761 EXPECT_EQ(result.width(), 512);
4761 EXPECT_EQ(result.height(), 500 + 2); 4762 EXPECT_EQ(result.height(), 500 + 2);
4762 } 4763 }
4763 4764
4764 } // namespace 4765 } // namespace
4765 } // namespace cc 4766 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/picture_layer_impl.cc ('k') | cc/layers/texture_layer_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698