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

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

Powered by Google App Engine
This is Rietveld 408576698