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

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

Powered by Google App Engine
This is Rietveld 408576698