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

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

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

Powered by Google App Engine
This is Rietveld 408576698