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

Side by Side Diff: cc/tiled_layer_unittest.cc

Issue 11264056: cc: Use gfx:: Geometry types for positions, bounds, and related things. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: some missed intstuff Created 8 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 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 "config.h" 5 #include "config.h"
6 6
7 #include "cc/tiled_layer.h" 7 #include "cc/tiled_layer.h"
8 8
9 #include "cc/bitmap_canvas_layer_updater.h" 9 #include "cc/bitmap_canvas_layer_updater.h"
10 #include "cc/layer_painter.h" 10 #include "cc/layer_painter.h"
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 scoped_ptr<PrioritizedTextureManager> m_textureManager; 166 scoped_ptr<PrioritizedTextureManager> m_textureManager;
167 TestOcclusionTracker* m_occlusion; 167 TestOcclusionTracker* m_occlusion;
168 }; 168 };
169 169
170 TEST_F(TiledLayerTest, pushDirtyTiles) 170 TEST_F(TiledLayerTest, pushDirtyTiles)
171 { 171 {
172 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get())); 172 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get()));
173 ScopedFakeTiledLayerImpl layerImpl(1); 173 ScopedFakeTiledLayerImpl layerImpl(1);
174 174
175 // The tile size is 100x100, so this invalidates and then paints two tiles. 175 // The tile size is 100x100, so this invalidates and then paints two tiles.
176 layer->setBounds(IntSize(100, 200)); 176 layer->setBounds(gfx::Size(100, 200));
177 layer->setVisibleContentRect(IntRect(0, 0, 100, 200)); 177 layer->setVisibleContentRect(gfx::Rect(0, 0, 100, 200));
178 layer->invalidateContentRect(IntRect(0, 0, 100, 200)); 178 layer->invalidateContentRect(gfx::Rect(0, 0, 100, 200));
179 updateAndPush(layer.get(), layerImpl.get()); 179 updateAndPush(layer.get(), layerImpl.get());
180 180
181 // We should have both tiles on the impl side. 181 // We should have both tiles on the impl side.
182 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(0, 0)); 182 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(0, 0));
183 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(0, 1)); 183 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(0, 1));
184 184
185 // Invalidates both tiles, but then only update one of them. 185 // Invalidates both tiles, but then only update one of them.
186 layer->setBounds(IntSize(100, 200)); 186 layer->setBounds(gfx::Size(100, 200));
187 layer->setVisibleContentRect(IntRect(0, 0, 100, 100)); 187 layer->setVisibleContentRect(gfx::Rect(0, 0, 100, 100));
188 layer->invalidateContentRect(IntRect(0, 0, 100, 200)); 188 layer->invalidateContentRect(gfx::Rect(0, 0, 100, 200));
189 updateAndPush(layer.get(), layerImpl.get()); 189 updateAndPush(layer.get(), layerImpl.get());
190 190
191 // We should only have the first tile since the other tile was invalidated b ut not painted. 191 // We should only have the first tile since the other tile was invalidated b ut not painted.
192 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(0, 0)); 192 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(0, 0));
193 EXPECT_FALSE(layerImpl->hasResourceIdForTileAt(0, 1)); 193 EXPECT_FALSE(layerImpl->hasResourceIdForTileAt(0, 1));
194 } 194 }
195 195
196 TEST_F(TiledLayerTest, pushOccludedDirtyTiles) 196 TEST_F(TiledLayerTest, pushOccludedDirtyTiles)
197 { 197 {
198 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get())); 198 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get()));
199 ScopedFakeTiledLayerImpl layerImpl(1); 199 ScopedFakeTiledLayerImpl layerImpl(1);
200 TestOcclusionTracker occluded; 200 TestOcclusionTracker occluded;
201 m_occlusion = &occluded; 201 m_occlusion = &occluded;
202 202
203 // The tile size is 100x100, so this invalidates and then paints two tiles. 203 // The tile size is 100x100, so this invalidates and then paints two tiles.
204 layer->setBounds(IntSize(100, 200)); 204 layer->setBounds(gfx::Size(100, 200));
205 layer->setVisibleContentRect(IntRect(0, 0, 100, 200)); 205 layer->setVisibleContentRect(gfx::Rect(0, 0, 100, 200));
206 layer->invalidateContentRect(IntRect(0, 0, 100, 200)); 206 layer->invalidateContentRect(gfx::Rect(0, 0, 100, 200));
207 updateAndPush(layer.get(), layerImpl.get()); 207 updateAndPush(layer.get(), layerImpl.get());
208 208
209 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1); 209 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1);
210 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 20000, 1 ); 210 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 20000, 1 );
211 EXPECT_EQ(0, occluded.overdrawMetrics().tilesCulledForUpload()); 211 EXPECT_EQ(0, occluded.overdrawMetrics().tilesCulledForUpload());
212 212
213 // We should have both tiles on the impl side. 213 // We should have both tiles on the impl side.
214 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(0, 0)); 214 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(0, 0));
215 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(0, 1)); 215 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(0, 1));
216 216
217 // Invalidates part of the top tile... 217 // Invalidates part of the top tile...
218 layer->invalidateContentRect(IntRect(0, 0, 50, 50)); 218 layer->invalidateContentRect(gfx::Rect(0, 0, 50, 50));
219 // ....but the area is occluded. 219 // ....but the area is occluded.
220 occluded.setOcclusion(IntRect(0, 0, 50, 50)); 220 occluded.setOcclusion(cc::IntRect(0, 0, 50, 50));
221 updateAndPush(layer.get(), layerImpl.get()); 221 updateAndPush(layer.get(), layerImpl.get());
222 222
223 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1); 223 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1);
224 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 20000 + 2500, 1); 224 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 20000 + 2500, 1);
225 EXPECT_EQ(0, occluded.overdrawMetrics().tilesCulledForUpload()); 225 EXPECT_EQ(0, occluded.overdrawMetrics().tilesCulledForUpload());
226 226
227 // We should still have both tiles, as part of the top tile is still unocclu ded. 227 // We should still have both tiles, as part of the top tile is still unocclu ded.
228 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(0, 0)); 228 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(0, 0));
229 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(0, 1)); 229 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(0, 1));
230 } 230 }
231 231
232 TEST_F(TiledLayerTest, pushDeletedTiles) 232 TEST_F(TiledLayerTest, pushDeletedTiles)
233 { 233 {
234 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get())); 234 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get()));
235 ScopedFakeTiledLayerImpl layerImpl(1); 235 ScopedFakeTiledLayerImpl layerImpl(1);
236 236
237 // The tile size is 100x100, so this invalidates and then paints two tiles. 237 // The tile size is 100x100, so this invalidates and then paints two tiles.
238 layer->setBounds(IntSize(100, 200)); 238 layer->setBounds(gfx::Size(100, 200));
239 layer->setVisibleContentRect(IntRect(0, 0, 100, 200)); 239 layer->setVisibleContentRect(gfx::Rect(0, 0, 100, 200));
240 layer->invalidateContentRect(IntRect(0, 0, 100, 200)); 240 layer->invalidateContentRect(gfx::Rect(0, 0, 100, 200));
241 updateAndPush(layer.get(), layerImpl.get()); 241 updateAndPush(layer.get(), layerImpl.get());
242 242
243 // We should have both tiles on the impl side. 243 // We should have both tiles on the impl side.
244 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(0, 0)); 244 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(0, 0));
245 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(0, 1)); 245 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(0, 1));
246 246
247 m_textureManager->clearPriorities(); 247 m_textureManager->clearPriorities();
248 textureManagerClearAllMemory(m_textureManager.get(), m_resourceProvider.get( )); 248 textureManagerClearAllMemory(m_textureManager.get(), m_resourceProvider.get( ));
249 m_textureManager->setMaxMemoryLimitBytes(4*1024*1024); 249 m_textureManager->setMaxMemoryLimitBytes(4*1024*1024);
250 250
251 // This should drop the tiles on the impl thread. 251 // This should drop the tiles on the impl thread.
252 layerPushPropertiesTo(layer.get(), layerImpl.get()); 252 layerPushPropertiesTo(layer.get(), layerImpl.get());
253 253
254 // We should now have no textures on the impl thread. 254 // We should now have no textures on the impl thread.
255 EXPECT_FALSE(layerImpl->hasResourceIdForTileAt(0, 0)); 255 EXPECT_FALSE(layerImpl->hasResourceIdForTileAt(0, 0));
256 EXPECT_FALSE(layerImpl->hasResourceIdForTileAt(0, 1)); 256 EXPECT_FALSE(layerImpl->hasResourceIdForTileAt(0, 1));
257 257
258 // This should recreate and update one of the deleted textures. 258 // This should recreate and update one of the deleted textures.
259 layer->setVisibleContentRect(IntRect(0, 0, 100, 100)); 259 layer->setVisibleContentRect(gfx::Rect(0, 0, 100, 100));
260 updateAndPush(layer.get(), layerImpl.get()); 260 updateAndPush(layer.get(), layerImpl.get());
261 261
262 // We should have one tiles on the impl side. 262 // We should have one tiles on the impl side.
263 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(0, 0)); 263 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(0, 0));
264 EXPECT_FALSE(layerImpl->hasResourceIdForTileAt(0, 1)); 264 EXPECT_FALSE(layerImpl->hasResourceIdForTileAt(0, 1));
265 } 265 }
266 266
267 TEST_F(TiledLayerTest, pushIdlePaintTiles) 267 TEST_F(TiledLayerTest, pushIdlePaintTiles)
268 { 268 {
269 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get())); 269 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get()));
270 ScopedFakeTiledLayerImpl layerImpl(1); 270 ScopedFakeTiledLayerImpl layerImpl(1);
271 271
272 // The tile size is 100x100. Setup 5x5 tiles with one visible tile in the ce nter. 272 // The tile size is 100x100. Setup 5x5 tiles with one visible tile in the ce nter.
273 // This paints 1 visible of the 25 invalid tiles. 273 // This paints 1 visible of the 25 invalid tiles.
274 layer->setBounds(IntSize(500, 500)); 274 layer->setBounds(gfx::Size(500, 500));
275 layer->setVisibleContentRect(IntRect(200, 200, 100, 100)); 275 layer->setVisibleContentRect(gfx::Rect(200, 200, 100, 100));
276 layer->invalidateContentRect(IntRect(0, 0, 500, 500)); 276 layer->invalidateContentRect(gfx::Rect(0, 0, 500, 500));
277 bool needsUpdate = updateAndPush(layer.get(), layerImpl.get()); 277 bool needsUpdate = updateAndPush(layer.get(), layerImpl.get());
278 // We should need idle-painting for surrounding tiles. 278 // We should need idle-painting for surrounding tiles.
279 EXPECT_TRUE(needsUpdate); 279 EXPECT_TRUE(needsUpdate);
280 280
281 // We should have one tile on the impl side. 281 // We should have one tile on the impl side.
282 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(2, 2)); 282 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(2, 2));
283 283
284 // For the next four updates, we should detect we still need idle painting. 284 // For the next four updates, we should detect we still need idle painting.
285 for (int i = 0; i < 4; i++) { 285 for (int i = 0; i < 4; i++) {
286 needsUpdate = updateAndPush(layer.get(), layerImpl.get()); 286 needsUpdate = updateAndPush(layer.get(), layerImpl.get());
(...skipping 13 matching lines...) Expand all
300 EXPECT_FALSE(needsUpdate); 300 EXPECT_FALSE(needsUpdate);
301 } 301 }
302 302
303 TEST_F(TiledLayerTest, predictivePainting) 303 TEST_F(TiledLayerTest, predictivePainting)
304 { 304 {
305 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get())); 305 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get()));
306 ScopedFakeTiledLayerImpl layerImpl(1); 306 ScopedFakeTiledLayerImpl layerImpl(1);
307 307
308 // Prepainting should occur in the scroll direction first, and the 308 // Prepainting should occur in the scroll direction first, and the
309 // visible rect should be extruded only along the dominant axis. 309 // visible rect should be extruded only along the dominant axis.
310 IntSize directions[6] = { IntSize(-10, 0), 310 gfx::Vector2d directions[6] = { gfx::Vector2d(-10, 0),
311 IntSize(10, 0), 311 gfx::Vector2d(10, 0),
312 IntSize(0, -10), 312 gfx::Vector2d(0, -10),
313 IntSize(0, 10), 313 gfx::Vector2d(0, 10),
314 IntSize(10, 20), 314 gfx::Vector2d(10, 20),
315 IntSize(-20, 10) }; 315 gfx::Vector2d(-20, 10) };
316 // We should push all tiles that touch the extruded visible rect. 316 // We should push all tiles that touch the extruded visible rect.
317 IntRect pushedVisibleTiles[6] = { IntRect(2, 2, 2, 1), 317 gfx::Rect pushedVisibleTiles[6] = { gfx::Rect(2, 2, 2, 1),
318 IntRect(1, 2, 2, 1), 318 gfx::Rect(1, 2, 2, 1),
319 IntRect(2, 2, 1, 2), 319 gfx::Rect(2, 2, 1, 2),
320 IntRect(2, 1, 1, 2), 320 gfx::Rect(2, 1, 1, 2),
321 IntRect(2, 1, 1, 2), 321 gfx::Rect(2, 1, 1, 2),
322 IntRect(2, 2, 2, 1) }; 322 gfx::Rect(2, 2, 2, 1) };
323 // The first pre-paint should also paint first in the scroll 323 // The first pre-paint should also paint first in the scroll
324 // direction so we should find one additional tile in the scroll direction. 324 // direction so we should find one additional tile in the scroll direction.
325 IntRect pushedPrepaintTiles[6] = { IntRect(2, 2, 3, 1), 325 gfx::Rect pushedPrepaintTiles[6] = { gfx::Rect(2, 2, 3, 1),
326 IntRect(0, 2, 3, 1), 326 gfx::Rect(0, 2, 3, 1),
327 IntRect(2, 2, 1, 3), 327 gfx::Rect(2, 2, 1, 3),
328 IntRect(2, 0, 1, 3), 328 gfx::Rect(2, 0, 1, 3),
329 IntRect(2, 0, 1, 3), 329 gfx::Rect(2, 0, 1, 3),
330 IntRect(2, 2, 3, 1) }; 330 gfx::Rect(2, 2, 3, 1) };
331 for(int k = 0; k < 6; k++) { 331 for(int k = 0; k < 6; k++) {
332 // The tile size is 100x100. Setup 5x5 tiles with one visible tile 332 // The tile size is 100x100. Setup 5x5 tiles with one visible tile
333 // in the center. 333 // in the center.
334 IntSize contentBounds = IntSize(500, 500); 334 gfx::Size contentBounds = gfx::Size(500, 500);
335 IntRect contentRect = IntRect(0, 0, 500, 500); 335 gfx::Rect contentRect = gfx::Rect(0, 0, 500, 500);
336 IntRect visibleRect = IntRect(200, 200, 100, 100); 336 gfx::Rect visibleRect = gfx::Rect(200, 200, 100, 100);
337 IntRect previousVisibleRect = IntRect(visibleRect.location() + direction s[k], visibleRect.size()); 337 gfx::Rect previousVisibleRect = gfx::Rect(visibleRect.origin() + directi ons[k], visibleRect.size());
338 IntRect nextVisibleRect = IntRect(visibleRect.location() - directions[k] , visibleRect.size()); 338 gfx::Rect nextVisibleRect = gfx::Rect(visibleRect.origin() - directions[ k], visibleRect.size());
339 339
340 // Setup. Use the previousVisibleRect to setup the prediction for next f rame. 340 // Setup. Use the previousVisibleRect to setup the prediction for next f rame.
341 layer->setBounds(contentBounds); 341 layer->setBounds(contentBounds);
342 layer->setVisibleContentRect(previousVisibleRect); 342 layer->setVisibleContentRect(previousVisibleRect);
343 layer->invalidateContentRect(contentRect); 343 layer->invalidateContentRect(contentRect);
344 bool needsUpdate = updateAndPush(layer.get(), layerImpl.get()); 344 bool needsUpdate = updateAndPush(layer.get(), layerImpl.get());
345 345
346 // Invalidate and move the visibleRect in the scroll direction. 346 // Invalidate and move the visibleRect in the scroll direction.
347 // Check that the correct tiles have been painted in the visible pass. 347 // Check that the correct tiles have been painted in the visible pass.
348 layer->invalidateContentRect(contentRect); 348 layer->invalidateContentRect(contentRect);
349 layer->setVisibleContentRect(visibleRect); 349 layer->setVisibleContentRect(visibleRect);
350 needsUpdate = updateAndPush(layer.get(), layerImpl.get()); 350 needsUpdate = updateAndPush(layer.get(), layerImpl.get());
351 for (int i = 0; i < 5; i++) { 351 for (int i = 0; i < 5; i++) {
352 for (int j = 0; j < 5; j++) 352 for (int j = 0; j < 5; j++)
353 EXPECT_EQ(layerImpl->hasResourceIdForTileAt(i, j), pushedVisible Tiles[k].contains(i, j)); 353 EXPECT_EQ(layerImpl->hasResourceIdForTileAt(i, j), pushedVisible Tiles[k].Contains(i, j));
354 } 354 }
355 355
356 // Move the transform in the same direction without invalidating. 356 // Move the transform in the same direction without invalidating.
357 // Check that non-visible pre-painting occured in the correct direction. 357 // Check that non-visible pre-painting occured in the correct direction.
358 // Ignore diagonal scrolls here (k > 3) as these have new visible conten t now. 358 // Ignore diagonal scrolls here (k > 3) as these have new visible conten t now.
359 if (k <= 3) { 359 if (k <= 3) {
360 layer->setVisibleContentRect(nextVisibleRect); 360 layer->setVisibleContentRect(nextVisibleRect);
361 needsUpdate = updateAndPush(layer.get(), layerImpl.get()); 361 needsUpdate = updateAndPush(layer.get(), layerImpl.get());
362 for (int i = 0; i < 5; i++) { 362 for (int i = 0; i < 5; i++) {
363 for (int j = 0; j < 5; j++) 363 for (int j = 0; j < 5; j++)
364 EXPECT_EQ(layerImpl->hasResourceIdForTileAt(i, j), pushedPre paintTiles[k].contains(i, j)); 364 EXPECT_EQ(layerImpl->hasResourceIdForTileAt(i, j), pushedPre paintTiles[k].Contains(i, j));
365 } 365 }
366 } 366 }
367 367
368 // We should always finish painting eventually. 368 // We should always finish painting eventually.
369 for (int i = 0; i < 20; i++) 369 for (int i = 0; i < 20; i++)
370 needsUpdate = updateAndPush(layer.get(), layerImpl.get()); 370 needsUpdate = updateAndPush(layer.get(), layerImpl.get());
371 EXPECT_FALSE(needsUpdate); 371 EXPECT_FALSE(needsUpdate);
372 } 372 }
373 } 373 }
374 374
375 TEST_F(TiledLayerTest, pushTilesAfterIdlePaintFailed) 375 TEST_F(TiledLayerTest, pushTilesAfterIdlePaintFailed)
376 { 376 {
377 // Start with 2mb of memory, but the test is going to try to use just more t han 1mb, so we reduce to 1mb later. 377 // Start with 2mb of memory, but the test is going to try to use just more t han 1mb, so we reduce to 1mb later.
378 m_textureManager->setMaxMemoryLimitBytes(2 * 1024 * 1024); 378 m_textureManager->setMaxMemoryLimitBytes(2 * 1024 * 1024);
379 scoped_refptr<FakeTiledLayer> layer1 = make_scoped_refptr(new FakeTiledLayer (m_textureManager.get())); 379 scoped_refptr<FakeTiledLayer> layer1 = make_scoped_refptr(new FakeTiledLayer (m_textureManager.get()));
380 ScopedFakeTiledLayerImpl layerImpl1(1); 380 ScopedFakeTiledLayerImpl layerImpl1(1);
381 scoped_refptr<FakeTiledLayer> layer2 = make_scoped_refptr(new FakeTiledLayer (m_textureManager.get())); 381 scoped_refptr<FakeTiledLayer> layer2 = make_scoped_refptr(new FakeTiledLayer (m_textureManager.get()));
382 ScopedFakeTiledLayerImpl layerImpl2(2); 382 ScopedFakeTiledLayerImpl layerImpl2(2);
383 383
384 // For this test we have two layers. layer1 exhausts most texture memory, le aving room for 2 more tiles from 384 // For this test we have two layers. layer1 exhausts most texture memory, le aving room for 2 more tiles from
385 // layer2, but not all three tiles. First we paint layer1, and one tile from layer2. Then when we idle paint 385 // layer2, but not all three tiles. First we paint layer1, and one tile from layer2. Then when we idle paint
386 // layer2, we will fail on the third tile of layer2, and this should not lea ve the second tile in a bad state. 386 // layer2, we will fail on the third tile of layer2, and this should not lea ve the second tile in a bad state.
387 387
388 // This uses 960000 bytes, leaving 88576 bytes of memory left, which is enou gh for 2 tiles only in the other layer. 388 // This uses 960000 bytes, leaving 88576 bytes of memory left, which is enou gh for 2 tiles only in the other layer.
389 IntRect layer1Rect(0, 0, 100, 2400); 389 gfx::Rect layer1Rect(0, 0, 100, 2400);
390 390
391 // This requires 4*30000 bytes of memory. 391 // This requires 4*30000 bytes of memory.
392 IntRect layer2Rect(0, 0, 100, 300); 392 gfx::Rect layer2Rect(0, 0, 100, 300);
393 393
394 // Paint a single tile in layer2 so that it will idle paint. 394 // Paint a single tile in layer2 so that it will idle paint.
395 layer1->setBounds(layer1Rect.size()); 395 layer1->setBounds(layer1Rect.size());
396 layer1->setVisibleContentRect(layer1Rect); 396 layer1->setVisibleContentRect(layer1Rect);
397 layer2->setBounds(layer2Rect.size()); 397 layer2->setBounds(layer2Rect.size());
398 layer2->setVisibleContentRect(IntRect(0, 0, 100, 100)); 398 layer2->setVisibleContentRect(gfx::Rect(0, 0, 100, 100));
399 bool needsUpdate = updateAndPush(layer1.get(), layerImpl1.get(), 399 bool needsUpdate = updateAndPush(layer1.get(), layerImpl1.get(),
400 layer2.get(), layerImpl2.get()); 400 layer2.get(), layerImpl2.get());
401 // We should need idle-painting for both remaining tiles in layer2. 401 // We should need idle-painting for both remaining tiles in layer2.
402 EXPECT_TRUE(needsUpdate); 402 EXPECT_TRUE(needsUpdate);
403 403
404 // Reduce our memory limits to 1mb. 404 // Reduce our memory limits to 1mb.
405 m_textureManager->setMaxMemoryLimitBytes(1024 * 1024); 405 m_textureManager->setMaxMemoryLimitBytes(1024 * 1024);
406 406
407 // Now idle paint layer2. We are going to run out of memory though! 407 // Now idle paint layer2. We are going to run out of memory though!
408 // Oh well, commit the frame and push. 408 // Oh well, commit the frame and push.
(...skipping 18 matching lines...) Expand all
427 } 427 }
428 428
429 TEST_F(TiledLayerTest, pushIdlePaintedOccludedTiles) 429 TEST_F(TiledLayerTest, pushIdlePaintedOccludedTiles)
430 { 430 {
431 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get())); 431 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get()));
432 ScopedFakeTiledLayerImpl layerImpl(1); 432 ScopedFakeTiledLayerImpl layerImpl(1);
433 TestOcclusionTracker occluded; 433 TestOcclusionTracker occluded;
434 m_occlusion = &occluded; 434 m_occlusion = &occluded;
435 435
436 // The tile size is 100x100, so this invalidates one occluded tile, culls it during paint, but prepaints it. 436 // The tile size is 100x100, so this invalidates one occluded tile, culls it during paint, but prepaints it.
437 occluded.setOcclusion(IntRect(0, 0, 100, 100)); 437 occluded.setOcclusion(cc::IntRect(0, 0, 100, 100));
438 438
439 layer->setBounds(IntSize(100, 100)); 439 layer->setBounds(gfx::Size(100, 100));
440 layer->setVisibleContentRect(IntRect(0, 0, 100, 100)); 440 layer->setVisibleContentRect(gfx::Rect(0, 0, 100, 100));
441 updateAndPush(layer.get(), layerImpl.get()); 441 updateAndPush(layer.get(), layerImpl.get());
442 442
443 // We should have the prepainted tile on the impl side, but culled it during paint. 443 // We should have the prepainted tile on the impl side, but culled it during paint.
444 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(0, 0)); 444 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(0, 0));
445 EXPECT_EQ(1, occluded.overdrawMetrics().tilesCulledForUpload()); 445 EXPECT_EQ(1, occluded.overdrawMetrics().tilesCulledForUpload());
446 } 446 }
447 447
448 TEST_F(TiledLayerTest, pushTilesMarkedDirtyDuringPaint) 448 TEST_F(TiledLayerTest, pushTilesMarkedDirtyDuringPaint)
449 { 449 {
450 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get())); 450 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get()));
451 ScopedFakeTiledLayerImpl layerImpl(1); 451 ScopedFakeTiledLayerImpl layerImpl(1);
452 452
453 // The tile size is 100x100, so this invalidates and then paints two tiles. 453 // The tile size is 100x100, so this invalidates and then paints two tiles.
454 // However, during the paint, we invalidate one of the tiles. This should 454 // However, during the paint, we invalidate one of the tiles. This should
455 // not prevent the tile from being pushed. 455 // not prevent the tile from being pushed.
456 layer->fakeLayerUpdater()->setRectToInvalidate(IntRect(0, 50, 100, 50), laye r.get()); 456 layer->fakeLayerUpdater()->setRectToInvalidate(gfx::Rect(0, 50, 100, 50), la yer.get());
457 layer->setBounds(IntSize(100, 200)); 457 layer->setBounds(gfx::Size(100, 200));
458 layer->setVisibleContentRect(IntRect(0, 0, 100, 200)); 458 layer->setVisibleContentRect(gfx::Rect(0, 0, 100, 200));
459 updateAndPush(layer.get(), layerImpl.get()); 459 updateAndPush(layer.get(), layerImpl.get());
460 460
461 // We should have both tiles on the impl side. 461 // We should have both tiles on the impl side.
462 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(0, 0)); 462 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(0, 0));
463 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(0, 1)); 463 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(0, 1));
464 } 464 }
465 465
466 TEST_F(TiledLayerTest, pushTilesLayerMarkedDirtyDuringPaintOnNextLayer) 466 TEST_F(TiledLayerTest, pushTilesLayerMarkedDirtyDuringPaintOnNextLayer)
467 { 467 {
468 scoped_refptr<FakeTiledLayer> layer1 = make_scoped_refptr(new FakeTiledLayer (m_textureManager.get())); 468 scoped_refptr<FakeTiledLayer> layer1 = make_scoped_refptr(new FakeTiledLayer (m_textureManager.get()));
469 scoped_refptr<FakeTiledLayer> layer2 = make_scoped_refptr(new FakeTiledLayer (m_textureManager.get())); 469 scoped_refptr<FakeTiledLayer> layer2 = make_scoped_refptr(new FakeTiledLayer (m_textureManager.get()));
470 ScopedFakeTiledLayerImpl layer1Impl(1); 470 ScopedFakeTiledLayerImpl layer1Impl(1);
471 ScopedFakeTiledLayerImpl layer2Impl(2); 471 ScopedFakeTiledLayerImpl layer2Impl(2);
472 472
473 // Invalidate a tile on layer1, during update of layer 2. 473 // Invalidate a tile on layer1, during update of layer 2.
474 layer2->fakeLayerUpdater()->setRectToInvalidate(IntRect(0, 50, 100, 50), lay er1.get()); 474 layer2->fakeLayerUpdater()->setRectToInvalidate(gfx::Rect(0, 50, 100, 50), l ayer1.get());
475 layer1->setBounds(IntSize(100, 200)); 475 layer1->setBounds(gfx::Size(100, 200));
476 layer1->setVisibleContentRect(IntRect(0, 0, 100, 200)); 476 layer1->setVisibleContentRect(gfx::Rect(0, 0, 100, 200));
477 layer2->setBounds(IntSize(100, 200)); 477 layer2->setBounds(gfx::Size(100, 200));
478 layer2->setVisibleContentRect(IntRect(0, 0, 100, 200)); 478 layer2->setVisibleContentRect(gfx::Rect(0, 0, 100, 200));
479 updateAndPush(layer1.get(), layer1Impl.get(), 479 updateAndPush(layer1.get(), layer1Impl.get(),
480 layer2.get(), layer2Impl.get()); 480 layer2.get(), layer2Impl.get());
481 481
482 // We should have both tiles on the impl side for all layers. 482 // We should have both tiles on the impl side for all layers.
483 EXPECT_TRUE(layer1Impl->hasResourceIdForTileAt(0, 0)); 483 EXPECT_TRUE(layer1Impl->hasResourceIdForTileAt(0, 0));
484 EXPECT_TRUE(layer1Impl->hasResourceIdForTileAt(0, 1)); 484 EXPECT_TRUE(layer1Impl->hasResourceIdForTileAt(0, 1));
485 EXPECT_TRUE(layer2Impl->hasResourceIdForTileAt(0, 0)); 485 EXPECT_TRUE(layer2Impl->hasResourceIdForTileAt(0, 0));
486 EXPECT_TRUE(layer2Impl->hasResourceIdForTileAt(0, 1)); 486 EXPECT_TRUE(layer2Impl->hasResourceIdForTileAt(0, 1));
487 } 487 }
488 488
489 TEST_F(TiledLayerTest, pushTilesLayerMarkedDirtyDuringPaintOnPreviousLayer) 489 TEST_F(TiledLayerTest, pushTilesLayerMarkedDirtyDuringPaintOnPreviousLayer)
490 { 490 {
491 scoped_refptr<FakeTiledLayer> layer1 = make_scoped_refptr(new FakeTiledLayer (m_textureManager.get())); 491 scoped_refptr<FakeTiledLayer> layer1 = make_scoped_refptr(new FakeTiledLayer (m_textureManager.get()));
492 scoped_refptr<FakeTiledLayer> layer2 = make_scoped_refptr(new FakeTiledLayer (m_textureManager.get())); 492 scoped_refptr<FakeTiledLayer> layer2 = make_scoped_refptr(new FakeTiledLayer (m_textureManager.get()));
493 ScopedFakeTiledLayerImpl layer1Impl(1); 493 ScopedFakeTiledLayerImpl layer1Impl(1);
494 ScopedFakeTiledLayerImpl layer2Impl(2); 494 ScopedFakeTiledLayerImpl layer2Impl(2);
495 495
496 layer1->fakeLayerUpdater()->setRectToInvalidate(IntRect(0, 50, 100, 50), lay er2.get()); 496 layer1->fakeLayerUpdater()->setRectToInvalidate(gfx::Rect(0, 50, 100, 50), l ayer2.get());
497 layer1->setBounds(IntSize(100, 200)); 497 layer1->setBounds(gfx::Size(100, 200));
498 layer1->setVisibleContentRect(IntRect(0, 0, 100, 200)); 498 layer1->setVisibleContentRect(gfx::Rect(0, 0, 100, 200));
499 layer2->setBounds(IntSize(100, 200)); 499 layer2->setBounds(gfx::Size(100, 200));
500 layer2->setVisibleContentRect(IntRect(0, 0, 100, 200)); 500 layer2->setVisibleContentRect(gfx::Rect(0, 0, 100, 200));
501 updateAndPush(layer1.get(), layer1Impl.get(), 501 updateAndPush(layer1.get(), layer1Impl.get(),
502 layer2.get(), layer2Impl.get()); 502 layer2.get(), layer2Impl.get());
503 503
504 // We should have both tiles on the impl side for all layers. 504 // We should have both tiles on the impl side for all layers.
505 EXPECT_TRUE(layer1Impl->hasResourceIdForTileAt(0, 0)); 505 EXPECT_TRUE(layer1Impl->hasResourceIdForTileAt(0, 0));
506 EXPECT_TRUE(layer1Impl->hasResourceIdForTileAt(0, 1)); 506 EXPECT_TRUE(layer1Impl->hasResourceIdForTileAt(0, 1));
507 EXPECT_TRUE(layer2Impl->hasResourceIdForTileAt(0, 0)); 507 EXPECT_TRUE(layer2Impl->hasResourceIdForTileAt(0, 0));
508 EXPECT_TRUE(layer2Impl->hasResourceIdForTileAt(0, 1)); 508 EXPECT_TRUE(layer2Impl->hasResourceIdForTileAt(0, 1));
509 } 509 }
510 510
511 TEST_F(TiledLayerTest, paintSmallAnimatedLayersImmediately) 511 TEST_F(TiledLayerTest, paintSmallAnimatedLayersImmediately)
512 { 512 {
513 // Create a LayerTreeHost that has the right viewportsize, 513 // Create a LayerTreeHost that has the right viewportsize,
514 // so the layer is considered small enough. 514 // so the layer is considered small enough.
515 FakeLayerImplTreeHostClient fakeLayerImplTreeHostClient; 515 FakeLayerImplTreeHostClient fakeLayerImplTreeHostClient;
516 scoped_ptr<LayerTreeHost> layerTreeHost = LayerTreeHost::create(&fakeLayerIm plTreeHostClient, LayerTreeSettings()); 516 scoped_ptr<LayerTreeHost> layerTreeHost = LayerTreeHost::create(&fakeLayerIm plTreeHostClient, LayerTreeSettings());
517 517
518 bool runOutOfMemory[2] = {false, true}; 518 bool runOutOfMemory[2] = {false, true};
519 for (int i = 0; i < 2; i++) { 519 for (int i = 0; i < 2; i++) {
520 // Create a layer with 4x4 tiles. 520 // Create a layer with 4x4 tiles.
521 int layerWidth = 4 * FakeTiledLayer::tileSize().width(); 521 int layerWidth = 4 * FakeTiledLayer::tileSize().width();
522 int layerHeight = 4 * FakeTiledLayer::tileSize().height(); 522 int layerHeight = 4 * FakeTiledLayer::tileSize().height();
523 int memoryForLayer = layerWidth * layerHeight * 4; 523 int memoryForLayer = layerWidth * layerHeight * 4;
524 IntSize viewportSize = IntSize(layerWidth, layerHeight); 524 gfx::Size viewportSize = gfx::Size(layerWidth, layerHeight);
525 layerTreeHost->setViewportSize(viewportSize, viewportSize); 525 layerTreeHost->setViewportSize(viewportSize, viewportSize);
526 526
527 // Use 8x4 tiles to run out of memory. 527 // Use 8x4 tiles to run out of memory.
528 if (runOutOfMemory[i]) 528 if (runOutOfMemory[i])
529 layerWidth *= 2; 529 layerWidth *= 2;
530 530
531 m_textureManager->setMaxMemoryLimitBytes(memoryForLayer); 531 m_textureManager->setMaxMemoryLimitBytes(memoryForLayer);
532 532
533 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLa yer(m_textureManager.get())); 533 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLa yer(m_textureManager.get()));
534 ScopedFakeTiledLayerImpl layerImpl(1); 534 ScopedFakeTiledLayerImpl layerImpl(1);
535 535
536 // Full size layer with half being visible. 536 // Full size layer with half being visible.
537 IntSize contentBounds(layerWidth, layerHeight); 537 gfx::Size contentBounds(layerWidth, layerHeight);
538 IntRect contentRect(IntPoint::zero(), contentBounds); 538 gfx::Rect contentRect(gfx::Point(), contentBounds);
539 IntRect visibleRect(IntPoint::zero(), IntSize(layerWidth / 2, layerHeigh t)); 539 gfx::Rect visibleRect(gfx::Point(), gfx::Size(layerWidth / 2, layerHeigh t));
540 540
541 // Pretend the layer is animating. 541 // Pretend the layer is animating.
542 layer->setDrawTransformIsAnimating(true); 542 layer->setDrawTransformIsAnimating(true);
543 layer->setBounds(contentBounds); 543 layer->setBounds(contentBounds);
544 layer->setVisibleContentRect(visibleRect); 544 layer->setVisibleContentRect(visibleRect);
545 layer->invalidateContentRect(contentRect); 545 layer->invalidateContentRect(contentRect);
546 layer->setLayerTreeHost(layerTreeHost.get()); 546 layer->setLayerTreeHost(layerTreeHost.get());
547 547
548 // The layer should paint it's entire contents on the first paint 548 // The layer should paint it's entire contents on the first paint
549 // if it is close to the viewport size and has the available memory. 549 // if it is close to the viewport size and has the available memory.
(...skipping 24 matching lines...) Expand all
574 { 574 {
575 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get())); 575 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get()));
576 ScopedFakeTiledLayerImpl layerImpl(1); 576 ScopedFakeTiledLayerImpl layerImpl(1);
577 577
578 // We have enough memory for only the visible rect, so we will run out of me mory in first idle paint. 578 // We have enough memory for only the visible rect, so we will run out of me mory in first idle paint.
579 int memoryLimit = 4 * 100 * 100; // 1 tiles, 4 bytes per pixel. 579 int memoryLimit = 4 * 100 * 100; // 1 tiles, 4 bytes per pixel.
580 m_textureManager->setMaxMemoryLimitBytes(memoryLimit); 580 m_textureManager->setMaxMemoryLimitBytes(memoryLimit);
581 581
582 // The tile size is 100x100, so this invalidates and then paints two tiles. 582 // The tile size is 100x100, so this invalidates and then paints two tiles.
583 bool needsUpdate = false; 583 bool needsUpdate = false;
584 layer->setBounds(IntSize(300, 300)); 584 layer->setBounds(gfx::Size(300, 300));
585 layer->setVisibleContentRect(IntRect(100, 100, 100, 100)); 585 layer->setVisibleContentRect(gfx::Rect(100, 100, 100, 100));
586 for (int i = 0; i < 2; i++) 586 for (int i = 0; i < 2; i++)
587 needsUpdate = updateAndPush(layer.get(), layerImpl.get()); 587 needsUpdate = updateAndPush(layer.get(), layerImpl.get());
588 588
589 // Idle-painting should see no more priority tiles for painting. 589 // Idle-painting should see no more priority tiles for painting.
590 EXPECT_FALSE(needsUpdate); 590 EXPECT_FALSE(needsUpdate);
591 591
592 // We should have one tile on the impl side. 592 // We should have one tile on the impl side.
593 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(1, 1)); 593 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(1, 1));
594 } 594 }
595 595
596 TEST_F(TiledLayerTest, idlePaintZeroSizedLayer) 596 TEST_F(TiledLayerTest, idlePaintZeroSizedLayer)
597 { 597 {
598 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get())); 598 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get()));
599 ScopedFakeTiledLayerImpl layerImpl(1); 599 ScopedFakeTiledLayerImpl layerImpl(1);
600 600
601 bool animating[2] = {false, true}; 601 bool animating[2] = {false, true};
602 for (int i = 0; i < 2; i++) { 602 for (int i = 0; i < 2; i++) {
603 // Pretend the layer is animating. 603 // Pretend the layer is animating.
604 layer->setDrawTransformIsAnimating(animating[i]); 604 layer->setDrawTransformIsAnimating(animating[i]);
605 605
606 // The layer's bounds are empty. 606 // The layer's bounds are empty.
607 // Empty layers don't paint or idle-paint. 607 // Empty layers don't paint or idle-paint.
608 layer->setBounds(IntSize()); 608 layer->setBounds(gfx::Size());
609 layer->setVisibleContentRect(IntRect()); 609 layer->setVisibleContentRect(gfx::Rect());
610 bool needsUpdate = updateAndPush(layer.get(), layerImpl.get()); 610 bool needsUpdate = updateAndPush(layer.get(), layerImpl.get());
611 611
612 // Empty layers don't have tiles. 612 // Empty layers don't have tiles.
613 EXPECT_EQ(0u, layer->numPaintedTiles()); 613 EXPECT_EQ(0u, layer->numPaintedTiles());
614 614
615 // Empty layers don't need prepaint. 615 // Empty layers don't need prepaint.
616 EXPECT_FALSE(needsUpdate); 616 EXPECT_FALSE(needsUpdate);
617 617
618 // Empty layers don't have tiles. 618 // Empty layers don't have tiles.
619 EXPECT_FALSE(layerImpl->hasResourceIdForTileAt(0, 0)); 619 EXPECT_FALSE(layerImpl->hasResourceIdForTileAt(0, 0));
620 } 620 }
621 } 621 }
622 622
623 TEST_F(TiledLayerTest, idlePaintNonVisibleLayers) 623 TEST_F(TiledLayerTest, idlePaintNonVisibleLayers)
624 { 624 {
625 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get())); 625 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get()));
626 ScopedFakeTiledLayerImpl layerImpl(1); 626 ScopedFakeTiledLayerImpl layerImpl(1);
627 627
628 // Alternate between not visible and visible. 628 // Alternate between not visible and visible.
629 IntRect v(0, 0, 100, 100); 629 gfx::Rect v(0, 0, 100, 100);
630 IntRect nv(0, 0, 0, 0); 630 gfx::Rect nv(0, 0, 0, 0);
631 IntRect visibleRect[10] = {nv, nv, v, v, nv, nv, v, v, nv, nv}; 631 gfx::Rect visibleRect[10] = {nv, nv, v, v, nv, nv, v, v, nv, nv};
632 bool invalidate[10] = {true, true, true, true, true, true, true, true, fals e, false }; 632 bool invalidate[10] = {true, true, true, true, true, true, true, true, fals e, false };
633 633
634 // We should not have any tiles except for when the layer was visible 634 // We should not have any tiles except for when the layer was visible
635 // or after the layer was visible and we didn't invalidate. 635 // or after the layer was visible and we didn't invalidate.
636 bool haveTile[10] = { false, false, true, true, false, false, true, true, tr ue, true }; 636 bool haveTile[10] = { false, false, true, true, false, false, true, true, tr ue, true };
637 637
638 for (int i = 0; i < 10; i++) { 638 for (int i = 0; i < 10; i++) {
639 layer->setBounds(IntSize(100, 100)); 639 layer->setBounds(gfx::Size(100, 100));
640 layer->setVisibleContentRect(visibleRect[i]); 640 layer->setVisibleContentRect(visibleRect[i]);
641 641
642 if (invalidate[i]) 642 if (invalidate[i])
643 layer->invalidateContentRect(IntRect(0, 0, 100, 100)); 643 layer->invalidateContentRect(gfx::Rect(0, 0, 100, 100));
644 bool needsUpdate = updateAndPush(layer.get(), layerImpl.get()); 644 bool needsUpdate = updateAndPush(layer.get(), layerImpl.get());
645 645
646 // We should never signal idle paint, as we painted the entire layer 646 // We should never signal idle paint, as we painted the entire layer
647 // or the layer was not visible. 647 // or the layer was not visible.
648 EXPECT_FALSE(needsUpdate); 648 EXPECT_FALSE(needsUpdate);
649 EXPECT_EQ(layerImpl->hasResourceIdForTileAt(0, 0), haveTile[i]); 649 EXPECT_EQ(layerImpl->hasResourceIdForTileAt(0, 0), haveTile[i]);
650 } 650 }
651 } 651 }
652 652
653 TEST_F(TiledLayerTest, invalidateFromPrepare) 653 TEST_F(TiledLayerTest, invalidateFromPrepare)
654 { 654 {
655 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get())); 655 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get()));
656 ScopedFakeTiledLayerImpl layerImpl(1); 656 ScopedFakeTiledLayerImpl layerImpl(1);
657 657
658 // The tile size is 100x100, so this invalidates and then paints two tiles. 658 // The tile size is 100x100, so this invalidates and then paints two tiles.
659 layer->setBounds(IntSize(100, 200)); 659 layer->setBounds(gfx::Size(100, 200));
660 layer->setVisibleContentRect(IntRect(0, 0, 100, 200)); 660 layer->setVisibleContentRect(gfx::Rect(0, 0, 100, 200));
661 updateAndPush(layer.get(), layerImpl.get()); 661 updateAndPush(layer.get(), layerImpl.get());
662 662
663 // We should have both tiles on the impl side. 663 // We should have both tiles on the impl side.
664 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(0, 0)); 664 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(0, 0));
665 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(0, 1)); 665 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(0, 1));
666 666
667 layer->fakeLayerUpdater()->clearPrepareCount(); 667 layer->fakeLayerUpdater()->clearPrepareCount();
668 // Invoke update again. As the layer is valid update shouldn't be invoked on 668 // Invoke update again. As the layer is valid update shouldn't be invoked on
669 // the LayerUpdater. 669 // the LayerUpdater.
670 updateAndPush(layer.get(), layerImpl.get()); 670 updateAndPush(layer.get(), layerImpl.get());
671 EXPECT_EQ(0, layer->fakeLayerUpdater()->prepareCount()); 671 EXPECT_EQ(0, layer->fakeLayerUpdater()->prepareCount());
672 672
673 // setRectToInvalidate triggers invalidateContentRect() being invoked from u pdate. 673 // setRectToInvalidate triggers invalidateContentRect() being invoked from u pdate.
674 layer->fakeLayerUpdater()->setRectToInvalidate(IntRect(25, 25, 50, 50), laye r.get()); 674 layer->fakeLayerUpdater()->setRectToInvalidate(gfx::Rect(25, 25, 50, 50), la yer.get());
675 layer->fakeLayerUpdater()->clearPrepareCount(); 675 layer->fakeLayerUpdater()->clearPrepareCount();
676 layer->invalidateContentRect(IntRect(0, 0, 50, 50)); 676 layer->invalidateContentRect(gfx::Rect(0, 0, 50, 50));
677 updateAndPush(layer.get(), layerImpl.get()); 677 updateAndPush(layer.get(), layerImpl.get());
678 EXPECT_EQ(1, layer->fakeLayerUpdater()->prepareCount()); 678 EXPECT_EQ(1, layer->fakeLayerUpdater()->prepareCount());
679 layer->fakeLayerUpdater()->clearPrepareCount(); 679 layer->fakeLayerUpdater()->clearPrepareCount();
680 680
681 // The layer should still be invalid as update invoked invalidate. 681 // The layer should still be invalid as update invoked invalidate.
682 updateAndPush(layer.get(), layerImpl.get()); // visible 682 updateAndPush(layer.get(), layerImpl.get()); // visible
683 EXPECT_EQ(1, layer->fakeLayerUpdater()->prepareCount()); 683 EXPECT_EQ(1, layer->fakeLayerUpdater()->prepareCount());
684 } 684 }
685 685
686 TEST_F(TiledLayerTest, verifyUpdateRectWhenContentBoundsAreScaled) 686 TEST_F(TiledLayerTest, verifyUpdateRectWhenContentBoundsAreScaled)
687 { 687 {
688 // The updateRect (that indicates what was actually painted) should be in 688 // The updateRect (that indicates what was actually painted) should be in
689 // layer space, not the content space. 689 // layer space, not the content space.
690 scoped_refptr<FakeTiledLayerWithScaledBounds> layer = make_scoped_refptr(new FakeTiledLayerWithScaledBounds(m_textureManager.get())); 690 scoped_refptr<FakeTiledLayerWithScaledBounds> layer = make_scoped_refptr(new FakeTiledLayerWithScaledBounds(m_textureManager.get()));
691 691
692 IntRect layerBounds(0, 0, 300, 200); 692 gfx::Rect layerBounds(0, 0, 300, 200);
693 IntRect contentBounds(0, 0, 200, 250); 693 gfx::Rect contentBounds(0, 0, 200, 250);
694 694
695 layer->setBounds(layerBounds.size()); 695 layer->setBounds(layerBounds.size());
696 layer->setContentBounds(contentBounds.size()); 696 layer->setContentBounds(contentBounds.size());
697 layer->setVisibleContentRect(contentBounds); 697 layer->setVisibleContentRect(contentBounds);
698 698
699 // On first update, the updateRect includes all tiles, even beyond the bound aries of the layer. 699 // On first update, the updateRect includes all tiles, even beyond the bound aries of the layer.
700 // However, it should still be in layer space, not content space. 700 // However, it should still be in layer space, not content space.
701 layer->invalidateContentRect(contentBounds); 701 layer->invalidateContentRect(contentBounds);
702 702
703 layer->setTexturePriorities(m_priorityCalculator); 703 layer->setTexturePriorities(m_priorityCalculator);
704 m_textureManager->prioritizeTextures(); 704 m_textureManager->prioritizeTextures();
705 layer->update(*m_queue.get(), 0, m_stats); 705 layer->update(*m_queue.get(), 0, m_stats);
706 EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 300, 300 * 0.8), layer->updateRect()); 706 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 300, 300 * 0.8), layer->updateRect());
707 updateTextures(); 707 updateTextures();
708 708
709 // After the tiles are updated once, another invalidate only needs to update the bounds of the layer. 709 // After the tiles are updated once, another invalidate only needs to update the bounds of the layer.
710 layer->setTexturePriorities(m_priorityCalculator); 710 layer->setTexturePriorities(m_priorityCalculator);
711 m_textureManager->prioritizeTextures(); 711 m_textureManager->prioritizeTextures();
712 layer->invalidateContentRect(contentBounds); 712 layer->invalidateContentRect(contentBounds);
713 layer->update(*m_queue.get(), 0, m_stats); 713 layer->update(*m_queue.get(), 0, m_stats);
714 EXPECT_FLOAT_RECT_EQ(FloatRect(layerBounds), layer->updateRect()); 714 EXPECT_FLOAT_RECT_EQ(gfx::RectF(layerBounds), layer->updateRect());
715 updateTextures(); 715 updateTextures();
716 716
717 // Partial re-paint should also be represented by the updateRect in layer sp ace, not content space. 717 // Partial re-paint should also be represented by the updateRect in layer sp ace, not content space.
718 IntRect partialDamage(30, 100, 10, 10); 718 gfx::Rect partialDamage(30, 100, 10, 10);
719 layer->invalidateContentRect(partialDamage); 719 layer->invalidateContentRect(partialDamage);
720 layer->setTexturePriorities(m_priorityCalculator); 720 layer->setTexturePriorities(m_priorityCalculator);
721 m_textureManager->prioritizeTextures(); 721 m_textureManager->prioritizeTextures();
722 layer->update(*m_queue.get(), 0, m_stats); 722 layer->update(*m_queue.get(), 0, m_stats);
723 EXPECT_FLOAT_RECT_EQ(FloatRect(45, 80, 15, 8), layer->updateRect()); 723 EXPECT_FLOAT_RECT_EQ(gfx::RectF(45, 80, 15, 8), layer->updateRect());
724 } 724 }
725 725
726 TEST_F(TiledLayerTest, verifyInvalidationWhenContentsScaleChanges) 726 TEST_F(TiledLayerTest, verifyInvalidationWhenContentsScaleChanges)
727 { 727 {
728 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get())); 728 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get()));
729 ScopedFakeTiledLayerImpl layerImpl(1); 729 ScopedFakeTiledLayerImpl layerImpl(1);
730 730
731 // Create a layer with one tile. 731 // Create a layer with one tile.
732 layer->setBounds(IntSize(100, 100)); 732 layer->setBounds(gfx::Size(100, 100));
733 layer->setVisibleContentRect(IntRect(0, 0, 100, 100)); 733 layer->setVisibleContentRect(gfx::Rect(0, 0, 100, 100));
734 734
735 // Invalidate the entire layer. 735 // Invalidate the entire layer.
736 layer->setNeedsDisplay(); 736 layer->setNeedsDisplay();
737 EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 100, 100), layer->lastNeedsDisplayRect( )); 737 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 100, 100), layer->lastNeedsDisplayRect ());
738 738
739 // Push the tiles to the impl side and check that there is exactly one. 739 // Push the tiles to the impl side and check that there is exactly one.
740 layer->setTexturePriorities(m_priorityCalculator); 740 layer->setTexturePriorities(m_priorityCalculator);
741 m_textureManager->prioritizeTextures(); 741 m_textureManager->prioritizeTextures();
742 layer->update(*m_queue.get(), 0, m_stats); 742 layer->update(*m_queue.get(), 0, m_stats);
743 updateTextures(); 743 updateTextures();
744 layerPushPropertiesTo(layer.get(), layerImpl.get()); 744 layerPushPropertiesTo(layer.get(), layerImpl.get());
745 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(0, 0)); 745 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(0, 0));
746 EXPECT_FALSE(layerImpl->hasResourceIdForTileAt(0, 1)); 746 EXPECT_FALSE(layerImpl->hasResourceIdForTileAt(0, 1));
747 EXPECT_FALSE(layerImpl->hasResourceIdForTileAt(1, 0)); 747 EXPECT_FALSE(layerImpl->hasResourceIdForTileAt(1, 0));
748 EXPECT_FALSE(layerImpl->hasResourceIdForTileAt(1, 1)); 748 EXPECT_FALSE(layerImpl->hasResourceIdForTileAt(1, 1));
749 749
750 // Change the contents scale and verify that the content rectangle requiring painting 750 // Change the contents scale and verify that the content rectangle requiring painting
751 // is not scaled. 751 // is not scaled.
752 layer->setContentsScale(2); 752 layer->setContentsScale(2);
753 layer->setVisibleContentRect(IntRect(0, 0, 200, 200)); 753 layer->setVisibleContentRect(gfx::Rect(0, 0, 200, 200));
754 EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 100, 100), layer->lastNeedsDisplayRect( )); 754 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 100, 100), layer->lastNeedsDisplayRect ());
755 755
756 // The impl side should get 2x2 tiles now. 756 // The impl side should get 2x2 tiles now.
757 layer->setTexturePriorities(m_priorityCalculator); 757 layer->setTexturePriorities(m_priorityCalculator);
758 m_textureManager->prioritizeTextures(); 758 m_textureManager->prioritizeTextures();
759 layer->update(*m_queue.get(), 0, m_stats); 759 layer->update(*m_queue.get(), 0, m_stats);
760 updateTextures(); 760 updateTextures();
761 layerPushPropertiesTo(layer.get(), layerImpl.get()); 761 layerPushPropertiesTo(layer.get(), layerImpl.get());
762 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(0, 0)); 762 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(0, 0));
763 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(0, 1)); 763 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(0, 1));
764 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(1, 0)); 764 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(1, 0));
(...skipping 12 matching lines...) Expand all
777 EXPECT_FALSE(layerImpl->hasResourceIdForTileAt(1, 1)); 777 EXPECT_FALSE(layerImpl->hasResourceIdForTileAt(1, 1));
778 } 778 }
779 779
780 TEST_F(TiledLayerTest, skipsDrawGetsReset) 780 TEST_F(TiledLayerTest, skipsDrawGetsReset)
781 { 781 {
782 FakeLayerImplTreeHostClient fakeLayerImplTreeHostClient; 782 FakeLayerImplTreeHostClient fakeLayerImplTreeHostClient;
783 scoped_ptr<LayerTreeHost> layerTreeHost = LayerTreeHost::create(&fakeLayerIm plTreeHostClient, LayerTreeSettings()); 783 scoped_ptr<LayerTreeHost> layerTreeHost = LayerTreeHost::create(&fakeLayerIm plTreeHostClient, LayerTreeSettings());
784 ASSERT_TRUE(layerTreeHost->initializeRendererIfNeeded()); 784 ASSERT_TRUE(layerTreeHost->initializeRendererIfNeeded());
785 785
786 // Create two 300 x 300 tiled layers. 786 // Create two 300 x 300 tiled layers.
787 IntSize contentBounds(300, 300); 787 gfx::Size contentBounds(300, 300);
788 IntRect contentRect(IntPoint::zero(), contentBounds); 788 gfx::Rect contentRect(gfx::Point(), contentBounds);
789 789
790 // We have enough memory for only one of the two layers. 790 // We have enough memory for only one of the two layers.
791 int memoryLimit = 4 * 300 * 300; // 4 bytes per pixel. 791 int memoryLimit = 4 * 300 * 300; // 4 bytes per pixel.
792 792
793 scoped_refptr<FakeTiledLayer> rootLayer = make_scoped_refptr(new FakeTiledLa yer(layerTreeHost->contentsTextureManager())); 793 scoped_refptr<FakeTiledLayer> rootLayer = make_scoped_refptr(new FakeTiledLa yer(layerTreeHost->contentsTextureManager()));
794 scoped_refptr<FakeTiledLayer> childLayer = make_scoped_refptr(new FakeTiledL ayer(layerTreeHost->contentsTextureManager())); 794 scoped_refptr<FakeTiledLayer> childLayer = make_scoped_refptr(new FakeTiledL ayer(layerTreeHost->contentsTextureManager()));
795 rootLayer->addChild(childLayer); 795 rootLayer->addChild(childLayer);
796 796
797 rootLayer->setBounds(contentBounds); 797 rootLayer->setBounds(contentBounds);
798 rootLayer->setVisibleContentRect(contentRect); 798 rootLayer->setVisibleContentRect(contentRect);
799 rootLayer->setPosition(FloatPoint(0, 0)); 799 rootLayer->setPosition(gfx::PointF(0, 0));
800 childLayer->setBounds(contentBounds); 800 childLayer->setBounds(contentBounds);
801 childLayer->setVisibleContentRect(contentRect); 801 childLayer->setVisibleContentRect(contentRect);
802 childLayer->setPosition(FloatPoint(0, 0)); 802 childLayer->setPosition(gfx::PointF(0, 0));
803 rootLayer->invalidateContentRect(contentRect); 803 rootLayer->invalidateContentRect(contentRect);
804 childLayer->invalidateContentRect(contentRect); 804 childLayer->invalidateContentRect(contentRect);
805 805
806 layerTreeHost->setRootLayer(rootLayer); 806 layerTreeHost->setRootLayer(rootLayer);
807 layerTreeHost->setViewportSize(IntSize(300, 300), IntSize(300, 300)); 807 layerTreeHost->setViewportSize(gfx::Size(300, 300), gfx::Size(300, 300));
808 808
809 layerTreeHost->updateLayers(*m_queue.get(), memoryLimit); 809 layerTreeHost->updateLayers(*m_queue.get(), memoryLimit);
810 810
811 // We'll skip the root layer. 811 // We'll skip the root layer.
812 EXPECT_TRUE(rootLayer->skipsDraw()); 812 EXPECT_TRUE(rootLayer->skipsDraw());
813 EXPECT_FALSE(childLayer->skipsDraw()); 813 EXPECT_FALSE(childLayer->skipsDraw());
814 814
815 layerTreeHost->commitComplete(); 815 layerTreeHost->commitComplete();
816 816
817 // Remove the child layer. 817 // Remove the child layer.
818 rootLayer->removeAllChildren(); 818 rootLayer->removeAllChildren();
819 819
820 layerTreeHost->updateLayers(*m_queue.get(), memoryLimit); 820 layerTreeHost->updateLayers(*m_queue.get(), memoryLimit);
821 EXPECT_FALSE(rootLayer->skipsDraw()); 821 EXPECT_FALSE(rootLayer->skipsDraw());
822 822
823 textureManagerClearAllMemory(layerTreeHost->contentsTextureManager(), m_reso urceProvider.get()); 823 textureManagerClearAllMemory(layerTreeHost->contentsTextureManager(), m_reso urceProvider.get());
824 layerTreeHost->setRootLayer(0); 824 layerTreeHost->setRootLayer(0);
825 } 825 }
826 826
827 TEST_F(TiledLayerTest, resizeToSmaller) 827 TEST_F(TiledLayerTest, resizeToSmaller)
828 { 828 {
829 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get())); 829 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get()));
830 830
831 layer->setBounds(IntSize(700, 700)); 831 layer->setBounds(gfx::Size(700, 700));
832 layer->setVisibleContentRect(IntRect(0, 0, 700, 700)); 832 layer->setVisibleContentRect(gfx::Rect(0, 0, 700, 700));
833 layer->invalidateContentRect(IntRect(0, 0, 700, 700)); 833 layer->invalidateContentRect(gfx::Rect(0, 0, 700, 700));
834 834
835 layer->setTexturePriorities(m_priorityCalculator); 835 layer->setTexturePriorities(m_priorityCalculator);
836 m_textureManager->prioritizeTextures(); 836 m_textureManager->prioritizeTextures();
837 layer->update(*m_queue.get(), 0, m_stats); 837 layer->update(*m_queue.get(), 0, m_stats);
838 838
839 layer->setBounds(IntSize(200, 200)); 839 layer->setBounds(gfx::Size(200, 200));
840 layer->invalidateContentRect(IntRect(0, 0, 200, 200)); 840 layer->invalidateContentRect(gfx::Rect(0, 0, 200, 200));
841 } 841 }
842 842
843 TEST_F(TiledLayerTest, hugeLayerUpdateCrash) 843 TEST_F(TiledLayerTest, hugeLayerUpdateCrash)
844 { 844 {
845 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get())); 845 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get()));
846 846
847 int size = 1 << 30; 847 int size = 1 << 30;
848 layer->setBounds(IntSize(size, size)); 848 layer->setBounds(gfx::Size(size, size));
849 layer->setVisibleContentRect(IntRect(0, 0, 700, 700)); 849 layer->setVisibleContentRect(gfx::Rect(0, 0, 700, 700));
850 layer->invalidateContentRect(IntRect(0, 0, size, size)); 850 layer->invalidateContentRect(gfx::Rect(0, 0, size, size));
851 851
852 // Ensure no crash for bounds where size * size would overflow an int. 852 // Ensure no crash for bounds where size * size would overflow an int.
853 layer->setTexturePriorities(m_priorityCalculator); 853 layer->setTexturePriorities(m_priorityCalculator);
854 m_textureManager->prioritizeTextures(); 854 m_textureManager->prioritizeTextures();
855 layer->update(*m_queue.get(), 0, m_stats); 855 layer->update(*m_queue.get(), 0, m_stats);
856 } 856 }
857 857
858 TEST_F(TiledLayerTest, partialUpdates) 858 TEST_F(TiledLayerTest, partialUpdates)
859 { 859 {
860 LayerTreeSettings settings; 860 LayerTreeSettings settings;
861 settings.maxPartialTextureUpdates = 4; 861 settings.maxPartialTextureUpdates = 4;
862 862
863 FakeLayerImplTreeHostClient fakeLayerImplTreeHostClient; 863 FakeLayerImplTreeHostClient fakeLayerImplTreeHostClient;
864 scoped_ptr<LayerTreeHost> layerTreeHost = LayerTreeHost::create(&fakeLayerIm plTreeHostClient, settings); 864 scoped_ptr<LayerTreeHost> layerTreeHost = LayerTreeHost::create(&fakeLayerIm plTreeHostClient, settings);
865 ASSERT_TRUE(layerTreeHost->initializeRendererIfNeeded()); 865 ASSERT_TRUE(layerTreeHost->initializeRendererIfNeeded());
866 866
867 // Create one 300 x 200 tiled layer with 3 x 2 tiles. 867 // Create one 300 x 200 tiled layer with 3 x 2 tiles.
868 IntSize contentBounds(300, 200); 868 gfx::Size contentBounds(300, 200);
869 IntRect contentRect(IntPoint::zero(), contentBounds); 869 gfx::Rect contentRect(gfx::Point(), contentBounds);
870 870
871 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( layerTreeHost->contentsTextureManager())); 871 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( layerTreeHost->contentsTextureManager()));
872 layer->setBounds(contentBounds); 872 layer->setBounds(contentBounds);
873 layer->setPosition(FloatPoint(0, 0)); 873 layer->setPosition(gfx::PointF(0, 0));
874 layer->setVisibleContentRect(contentRect); 874 layer->setVisibleContentRect(contentRect);
875 layer->invalidateContentRect(contentRect); 875 layer->invalidateContentRect(contentRect);
876 876
877 layerTreeHost->setRootLayer(layer); 877 layerTreeHost->setRootLayer(layer);
878 layerTreeHost->setViewportSize(IntSize(300, 200), IntSize(300, 200)); 878 layerTreeHost->setViewportSize(gfx::Size(300, 200), gfx::Size(300, 200));
879 879
880 // Full update of all 6 tiles. 880 // Full update of all 6 tiles.
881 layerTreeHost->updateLayers( 881 layerTreeHost->updateLayers(
882 *m_queue.get(), std::numeric_limits<size_t>::max()); 882 *m_queue.get(), std::numeric_limits<size_t>::max());
883 { 883 {
884 ScopedFakeTiledLayerImpl layerImpl(1); 884 ScopedFakeTiledLayerImpl layerImpl(1);
885 EXPECT_EQ(6, m_queue->fullUploadSize()); 885 EXPECT_EQ(6, m_queue->fullUploadSize());
886 EXPECT_EQ(0, m_queue->partialUploadSize()); 886 EXPECT_EQ(0, m_queue->partialUploadSize());
887 updateTextures(); 887 updateTextures();
888 EXPECT_EQ(6, layer->fakeLayerUpdater()->updateCount()); 888 EXPECT_EQ(6, layer->fakeLayerUpdater()->updateCount());
889 EXPECT_FALSE(m_queue->hasMoreUpdates()); 889 EXPECT_FALSE(m_queue->hasMoreUpdates());
890 layer->fakeLayerUpdater()->clearUpdateCount(); 890 layer->fakeLayerUpdater()->clearUpdateCount();
891 layerPushPropertiesTo(layer.get(), layerImpl.get()); 891 layerPushPropertiesTo(layer.get(), layerImpl.get());
892 } 892 }
893 layerTreeHost->commitComplete(); 893 layerTreeHost->commitComplete();
894 894
895 // Full update of 3 tiles and partial update of 3 tiles. 895 // Full update of 3 tiles and partial update of 3 tiles.
896 layer->invalidateContentRect(IntRect(0, 0, 300, 150)); 896 layer->invalidateContentRect(gfx::Rect(0, 0, 300, 150));
897 layerTreeHost->updateLayers(*m_queue.get(), std::numeric_limits<size_t>::max ()); 897 layerTreeHost->updateLayers(*m_queue.get(), std::numeric_limits<size_t>::max ());
898 { 898 {
899 ScopedFakeTiledLayerImpl layerImpl(1); 899 ScopedFakeTiledLayerImpl layerImpl(1);
900 EXPECT_EQ(3, m_queue->fullUploadSize()); 900 EXPECT_EQ(3, m_queue->fullUploadSize());
901 EXPECT_EQ(3, m_queue->partialUploadSize()); 901 EXPECT_EQ(3, m_queue->partialUploadSize());
902 updateTextures(); 902 updateTextures();
903 EXPECT_EQ(6, layer->fakeLayerUpdater()->updateCount()); 903 EXPECT_EQ(6, layer->fakeLayerUpdater()->updateCount());
904 EXPECT_FALSE(m_queue->hasMoreUpdates()); 904 EXPECT_FALSE(m_queue->hasMoreUpdates());
905 layer->fakeLayerUpdater()->clearUpdateCount(); 905 layer->fakeLayerUpdater()->clearUpdateCount();
906 layerPushPropertiesTo(layer.get(), layerImpl.get()); 906 layerPushPropertiesTo(layer.get(), layerImpl.get());
907 } 907 }
908 layerTreeHost->commitComplete(); 908 layerTreeHost->commitComplete();
909 909
910 // Partial update of 6 tiles. 910 // Partial update of 6 tiles.
911 layer->invalidateContentRect(IntRect(50, 50, 200, 100)); 911 layer->invalidateContentRect(gfx::Rect(50, 50, 200, 100));
912 { 912 {
913 ScopedFakeTiledLayerImpl layerImpl(1); 913 ScopedFakeTiledLayerImpl layerImpl(1);
914 layerTreeHost->updateLayers(*m_queue.get(), std::numeric_limits<size_t>: :max()); 914 layerTreeHost->updateLayers(*m_queue.get(), std::numeric_limits<size_t>: :max());
915 EXPECT_EQ(2, m_queue->fullUploadSize()); 915 EXPECT_EQ(2, m_queue->fullUploadSize());
916 EXPECT_EQ(4, m_queue->partialUploadSize()); 916 EXPECT_EQ(4, m_queue->partialUploadSize());
917 updateTextures(); 917 updateTextures();
918 EXPECT_EQ(6, layer->fakeLayerUpdater()->updateCount()); 918 EXPECT_EQ(6, layer->fakeLayerUpdater()->updateCount());
919 EXPECT_FALSE(m_queue->hasMoreUpdates()); 919 EXPECT_FALSE(m_queue->hasMoreUpdates());
920 layer->fakeLayerUpdater()->clearUpdateCount(); 920 layer->fakeLayerUpdater()->clearUpdateCount();
921 layerPushPropertiesTo(layer.get(), layerImpl.get()); 921 layerPushPropertiesTo(layer.get(), layerImpl.get());
922 } 922 }
923 layerTreeHost->commitComplete(); 923 layerTreeHost->commitComplete();
924 924
925 // Checkerboard all tiles. 925 // Checkerboard all tiles.
926 layer->invalidateContentRect(IntRect(0, 0, 300, 200)); 926 layer->invalidateContentRect(gfx::Rect(0, 0, 300, 200));
927 { 927 {
928 ScopedFakeTiledLayerImpl layerImpl(1); 928 ScopedFakeTiledLayerImpl layerImpl(1);
929 layerPushPropertiesTo(layer.get(), layerImpl.get()); 929 layerPushPropertiesTo(layer.get(), layerImpl.get());
930 } 930 }
931 layerTreeHost->commitComplete(); 931 layerTreeHost->commitComplete();
932 932
933 // Partial update of 6 checkerboard tiles. 933 // Partial update of 6 checkerboard tiles.
934 layer->invalidateContentRect(IntRect(50, 50, 200, 100)); 934 layer->invalidateContentRect(gfx::Rect(50, 50, 200, 100));
935 { 935 {
936 ScopedFakeTiledLayerImpl layerImpl(1); 936 ScopedFakeTiledLayerImpl layerImpl(1);
937 layerTreeHost->updateLayers(*m_queue.get(), std::numeric_limits<size_t>: :max()); 937 layerTreeHost->updateLayers(*m_queue.get(), std::numeric_limits<size_t>: :max());
938 EXPECT_EQ(6, m_queue->fullUploadSize()); 938 EXPECT_EQ(6, m_queue->fullUploadSize());
939 EXPECT_EQ(0, m_queue->partialUploadSize()); 939 EXPECT_EQ(0, m_queue->partialUploadSize());
940 updateTextures(); 940 updateTextures();
941 EXPECT_EQ(6, layer->fakeLayerUpdater()->updateCount()); 941 EXPECT_EQ(6, layer->fakeLayerUpdater()->updateCount());
942 EXPECT_FALSE(m_queue->hasMoreUpdates()); 942 EXPECT_FALSE(m_queue->hasMoreUpdates());
943 layer->fakeLayerUpdater()->clearUpdateCount(); 943 layer->fakeLayerUpdater()->clearUpdateCount();
944 layerPushPropertiesTo(layer.get(), layerImpl.get()); 944 layerPushPropertiesTo(layer.get(), layerImpl.get());
945 } 945 }
946 layerTreeHost->commitComplete(); 946 layerTreeHost->commitComplete();
947 947
948 // Partial update of 4 tiles. 948 // Partial update of 4 tiles.
949 layer->invalidateContentRect(IntRect(50, 50, 100, 100)); 949 layer->invalidateContentRect(gfx::Rect(50, 50, 100, 100));
950 { 950 {
951 ScopedFakeTiledLayerImpl layerImpl(1); 951 ScopedFakeTiledLayerImpl layerImpl(1);
952 layerTreeHost->updateLayers(*m_queue.get(), std::numeric_limits<size_t>: :max()); 952 layerTreeHost->updateLayers(*m_queue.get(), std::numeric_limits<size_t>: :max());
953 EXPECT_EQ(0, m_queue->fullUploadSize()); 953 EXPECT_EQ(0, m_queue->fullUploadSize());
954 EXPECT_EQ(4, m_queue->partialUploadSize()); 954 EXPECT_EQ(4, m_queue->partialUploadSize());
955 updateTextures(); 955 updateTextures();
956 EXPECT_EQ(4, layer->fakeLayerUpdater()->updateCount()); 956 EXPECT_EQ(4, layer->fakeLayerUpdater()->updateCount());
957 EXPECT_FALSE(m_queue->hasMoreUpdates()); 957 EXPECT_FALSE(m_queue->hasMoreUpdates());
958 layer->fakeLayerUpdater()->clearUpdateCount(); 958 layer->fakeLayerUpdater()->clearUpdateCount();
959 layerPushPropertiesTo(layer.get(), layerImpl.get()); 959 layerPushPropertiesTo(layer.get(), layerImpl.get());
960 } 960 }
961 layerTreeHost->commitComplete(); 961 layerTreeHost->commitComplete();
962 962
963 textureManagerClearAllMemory(layerTreeHost->contentsTextureManager(), m_reso urceProvider.get()); 963 textureManagerClearAllMemory(layerTreeHost->contentsTextureManager(), m_reso urceProvider.get());
964 layerTreeHost->setRootLayer(0); 964 layerTreeHost->setRootLayer(0);
965 } 965 }
966 966
967 TEST_F(TiledLayerTest, tilesPaintedWithoutOcclusion) 967 TEST_F(TiledLayerTest, tilesPaintedWithoutOcclusion)
968 { 968 {
969 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get())); 969 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get()));
970 970
971 // The tile size is 100x100, so this invalidates and then paints two tiles. 971 // The tile size is 100x100, so this invalidates and then paints two tiles.
972 layer->setBounds(IntSize(100, 200)); 972 layer->setBounds(gfx::Size(100, 200));
973 layer->setDrawableContentRect(IntRect(0, 0, 100, 200)); 973 layer->setDrawableContentRect(gfx::Rect(0, 0, 100, 200));
974 layer->setVisibleContentRect(IntRect(0, 0, 100, 200)); 974 layer->setVisibleContentRect(gfx::Rect(0, 0, 100, 200));
975 layer->invalidateContentRect(IntRect(0, 0, 100, 200)); 975 layer->invalidateContentRect(gfx::Rect(0, 0, 100, 200));
976 976
977 layer->setTexturePriorities(m_priorityCalculator); 977 layer->setTexturePriorities(m_priorityCalculator);
978 m_textureManager->prioritizeTextures(); 978 m_textureManager->prioritizeTextures();
979 layer->update(*m_queue.get(), 0, m_stats); 979 layer->update(*m_queue.get(), 0, m_stats);
980 EXPECT_EQ(2, layer->fakeLayerUpdater()->updateCount()); 980 EXPECT_EQ(2, layer->fakeLayerUpdater()->updateCount());
981 } 981 }
982 982
983 TEST_F(TiledLayerTest, tilesPaintedWithOcclusion) 983 TEST_F(TiledLayerTest, tilesPaintedWithOcclusion)
984 { 984 {
985 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get())); 985 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get()));
986 TestOcclusionTracker occluded; 986 TestOcclusionTracker occluded;
987 987
988 // The tile size is 100x100. 988 // The tile size is 100x100.
989 989
990 layer->setBounds(IntSize(600, 600)); 990 layer->setBounds(gfx::Size(600, 600));
991 991
992 occluded.setOcclusion(IntRect(200, 200, 300, 100)); 992 occluded.setOcclusion(cc::IntRect(200, 200, 300, 100));
993 layer->setDrawableContentRect(IntRect(IntPoint(), layer->contentBounds())); 993 layer->setDrawableContentRect(gfx::Rect(gfx::Point(), layer->contentBounds() ));
994 layer->setVisibleContentRect(IntRect(IntPoint(), layer->contentBounds())); 994 layer->setVisibleContentRect(gfx::Rect(gfx::Point(), layer->contentBounds()) );
995 layer->invalidateContentRect(IntRect(0, 0, 600, 600)); 995 layer->invalidateContentRect(gfx::Rect(0, 0, 600, 600));
996 996
997 layer->setTexturePriorities(m_priorityCalculator); 997 layer->setTexturePriorities(m_priorityCalculator);
998 m_textureManager->prioritizeTextures(); 998 m_textureManager->prioritizeTextures();
999 layer->update(*m_queue.get(), &occluded, m_stats); 999 layer->update(*m_queue.get(), &occluded, m_stats);
1000 EXPECT_EQ(36-3, layer->fakeLayerUpdater()->updateCount()); 1000 EXPECT_EQ(36-3, layer->fakeLayerUpdater()->updateCount());
1001 1001
1002 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1); 1002 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1);
1003 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 330000, 1); 1003 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 330000, 1);
1004 EXPECT_EQ(3, occluded.overdrawMetrics().tilesCulledForUpload()); 1004 EXPECT_EQ(3, occluded.overdrawMetrics().tilesCulledForUpload());
1005 1005
1006 layer->fakeLayerUpdater()->clearUpdateCount(); 1006 layer->fakeLayerUpdater()->clearUpdateCount();
1007 layer->setTexturePriorities(m_priorityCalculator); 1007 layer->setTexturePriorities(m_priorityCalculator);
1008 m_textureManager->prioritizeTextures(); 1008 m_textureManager->prioritizeTextures();
1009 1009
1010 occluded.setOcclusion(IntRect(250, 200, 300, 100)); 1010 occluded.setOcclusion(cc::IntRect(250, 200, 300, 100));
1011 layer->invalidateContentRect(IntRect(0, 0, 600, 600)); 1011 layer->invalidateContentRect(gfx::Rect(0, 0, 600, 600));
1012 layer->update(*m_queue.get(), &occluded, m_stats); 1012 layer->update(*m_queue.get(), &occluded, m_stats);
1013 EXPECT_EQ(36-2, layer->fakeLayerUpdater()->updateCount()); 1013 EXPECT_EQ(36-2, layer->fakeLayerUpdater()->updateCount());
1014 1014
1015 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1); 1015 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1);
1016 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 330000 + 340000, 1); 1016 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 330000 + 340000, 1);
1017 EXPECT_EQ(3 + 2, occluded.overdrawMetrics().tilesCulledForUpload()); 1017 EXPECT_EQ(3 + 2, occluded.overdrawMetrics().tilesCulledForUpload());
1018 1018
1019 layer->fakeLayerUpdater()->clearUpdateCount(); 1019 layer->fakeLayerUpdater()->clearUpdateCount();
1020 layer->setTexturePriorities(m_priorityCalculator); 1020 layer->setTexturePriorities(m_priorityCalculator);
1021 m_textureManager->prioritizeTextures(); 1021 m_textureManager->prioritizeTextures();
1022 1022
1023 occluded.setOcclusion(IntRect(250, 250, 300, 100)); 1023 occluded.setOcclusion(cc::IntRect(250, 250, 300, 100));
1024 layer->invalidateContentRect(IntRect(0, 0, 600, 600)); 1024 layer->invalidateContentRect(gfx::Rect(0, 0, 600, 600));
1025 layer->update(*m_queue.get(), &occluded, m_stats); 1025 layer->update(*m_queue.get(), &occluded, m_stats);
1026 EXPECT_EQ(36, layer->fakeLayerUpdater()->updateCount()); 1026 EXPECT_EQ(36, layer->fakeLayerUpdater()->updateCount());
1027 1027
1028 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1); 1028 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1);
1029 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 330000 + 340000 + 360000, 1); 1029 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 330000 + 340000 + 360000, 1);
1030 EXPECT_EQ(3 + 2, occluded.overdrawMetrics().tilesCulledForUpload()); 1030 EXPECT_EQ(3 + 2, occluded.overdrawMetrics().tilesCulledForUpload());
1031 } 1031 }
1032 1032
1033 TEST_F(TiledLayerTest, tilesPaintedWithOcclusionAndVisiblityConstraints) 1033 TEST_F(TiledLayerTest, tilesPaintedWithOcclusionAndVisiblityConstraints)
1034 { 1034 {
1035 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get())); 1035 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get()));
1036 TestOcclusionTracker occluded; 1036 TestOcclusionTracker occluded;
1037 1037
1038 // The tile size is 100x100. 1038 // The tile size is 100x100.
1039 1039
1040 layer->setBounds(IntSize(600, 600)); 1040 layer->setBounds(gfx::Size(600, 600));
1041 1041
1042 // The partially occluded tiles (by the 150 occlusion height) are visible be yond the occlusion, so not culled. 1042 // The partially occluded tiles (by the 150 occlusion height) are visible be yond the occlusion, so not culled.
1043 occluded.setOcclusion(IntRect(200, 200, 300, 150)); 1043 occluded.setOcclusion(cc::IntRect(200, 200, 300, 150));
1044 layer->setDrawableContentRect(IntRect(0, 0, 600, 360)); 1044 layer->setDrawableContentRect(gfx::Rect(0, 0, 600, 360));
1045 layer->setVisibleContentRect(IntRect(0, 0, 600, 360)); 1045 layer->setVisibleContentRect(gfx::Rect(0, 0, 600, 360));
1046 layer->invalidateContentRect(IntRect(0, 0, 600, 600)); 1046 layer->invalidateContentRect(gfx::Rect(0, 0, 600, 600));
1047 1047
1048 layer->setTexturePriorities(m_priorityCalculator); 1048 layer->setTexturePriorities(m_priorityCalculator);
1049 m_textureManager->prioritizeTextures(); 1049 m_textureManager->prioritizeTextures();
1050 layer->update(*m_queue.get(), &occluded, m_stats); 1050 layer->update(*m_queue.get(), &occluded, m_stats);
1051 EXPECT_EQ(24-3, layer->fakeLayerUpdater()->updateCount()); 1051 EXPECT_EQ(24-3, layer->fakeLayerUpdater()->updateCount());
1052 1052
1053 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1); 1053 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1);
1054 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 210000, 1); 1054 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 210000, 1);
1055 EXPECT_EQ(3, occluded.overdrawMetrics().tilesCulledForUpload()); 1055 EXPECT_EQ(3, occluded.overdrawMetrics().tilesCulledForUpload());
1056 1056
1057 layer->fakeLayerUpdater()->clearUpdateCount(); 1057 layer->fakeLayerUpdater()->clearUpdateCount();
1058 1058
1059 // Now the visible region stops at the edge of the occlusion so the partly v isible tiles become fully occluded. 1059 // Now the visible region stops at the edge of the occlusion so the partly v isible tiles become fully occluded.
1060 occluded.setOcclusion(IntRect(200, 200, 300, 150)); 1060 occluded.setOcclusion(cc::IntRect(200, 200, 300, 150));
1061 layer->setDrawableContentRect(IntRect(0, 0, 600, 350)); 1061 layer->setDrawableContentRect(gfx::Rect(0, 0, 600, 350));
1062 layer->setVisibleContentRect(IntRect(0, 0, 600, 350)); 1062 layer->setVisibleContentRect(gfx::Rect(0, 0, 600, 350));
1063 layer->invalidateContentRect(IntRect(0, 0, 600, 600)); 1063 layer->invalidateContentRect(gfx::Rect(0, 0, 600, 600));
1064 layer->setTexturePriorities(m_priorityCalculator); 1064 layer->setTexturePriorities(m_priorityCalculator);
1065 m_textureManager->prioritizeTextures(); 1065 m_textureManager->prioritizeTextures();
1066 layer->update(*m_queue.get(), &occluded, m_stats); 1066 layer->update(*m_queue.get(), &occluded, m_stats);
1067 EXPECT_EQ(24-6, layer->fakeLayerUpdater()->updateCount()); 1067 EXPECT_EQ(24-6, layer->fakeLayerUpdater()->updateCount());
1068 1068
1069 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1); 1069 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1);
1070 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 210000 + 180000, 1); 1070 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 210000 + 180000, 1);
1071 EXPECT_EQ(3 + 6, occluded.overdrawMetrics().tilesCulledForUpload()); 1071 EXPECT_EQ(3 + 6, occluded.overdrawMetrics().tilesCulledForUpload());
1072 1072
1073 layer->fakeLayerUpdater()->clearUpdateCount(); 1073 layer->fakeLayerUpdater()->clearUpdateCount();
1074 1074
1075 // Now the visible region is even smaller than the occlusion, it should have the same result. 1075 // Now the visible region is even smaller than the occlusion, it should have the same result.
1076 occluded.setOcclusion(IntRect(200, 200, 300, 150)); 1076 occluded.setOcclusion(cc::IntRect(200, 200, 300, 150));
1077 layer->setDrawableContentRect(IntRect(0, 0, 600, 340)); 1077 layer->setDrawableContentRect(gfx::Rect(0, 0, 600, 340));
1078 layer->setVisibleContentRect(IntRect(0, 0, 600, 340)); 1078 layer->setVisibleContentRect(gfx::Rect(0, 0, 600, 340));
1079 layer->invalidateContentRect(IntRect(0, 0, 600, 600)); 1079 layer->invalidateContentRect(gfx::Rect(0, 0, 600, 600));
1080 layer->setTexturePriorities(m_priorityCalculator); 1080 layer->setTexturePriorities(m_priorityCalculator);
1081 m_textureManager->prioritizeTextures(); 1081 m_textureManager->prioritizeTextures();
1082 layer->update(*m_queue.get(), &occluded, m_stats); 1082 layer->update(*m_queue.get(), &occluded, m_stats);
1083 EXPECT_EQ(24-6, layer->fakeLayerUpdater()->updateCount()); 1083 EXPECT_EQ(24-6, layer->fakeLayerUpdater()->updateCount());
1084 1084
1085 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1); 1085 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1);
1086 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 210000 + 180000 + 180000, 1); 1086 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 210000 + 180000 + 180000, 1);
1087 EXPECT_EQ(3 + 6 + 6, occluded.overdrawMetrics().tilesCulledForUpload()); 1087 EXPECT_EQ(3 + 6 + 6, occluded.overdrawMetrics().tilesCulledForUpload());
1088 1088
1089 } 1089 }
1090 1090
1091 TEST_F(TiledLayerTest, tilesNotPaintedWithoutInvalidation) 1091 TEST_F(TiledLayerTest, tilesNotPaintedWithoutInvalidation)
1092 { 1092 {
1093 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get())); 1093 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get()));
1094 TestOcclusionTracker occluded; 1094 TestOcclusionTracker occluded;
1095 1095
1096 // The tile size is 100x100. 1096 // The tile size is 100x100.
1097 1097
1098 layer->setBounds(IntSize(600, 600)); 1098 layer->setBounds(gfx::Size(600, 600));
1099 1099
1100 occluded.setOcclusion(IntRect(200, 200, 300, 100)); 1100 occluded.setOcclusion(cc::IntRect(200, 200, 300, 100));
1101 layer->setDrawableContentRect(IntRect(0, 0, 600, 600)); 1101 layer->setDrawableContentRect(gfx::Rect(0, 0, 600, 600));
1102 layer->setVisibleContentRect(IntRect(0, 0, 600, 600)); 1102 layer->setVisibleContentRect(gfx::Rect(0, 0, 600, 600));
1103 layer->invalidateContentRect(IntRect(0, 0, 600, 600)); 1103 layer->invalidateContentRect(gfx::Rect(0, 0, 600, 600));
1104 layer->setTexturePriorities(m_priorityCalculator); 1104 layer->setTexturePriorities(m_priorityCalculator);
1105 m_textureManager->prioritizeTextures(); 1105 m_textureManager->prioritizeTextures();
1106 layer->update(*m_queue.get(), &occluded, m_stats); 1106 layer->update(*m_queue.get(), &occluded, m_stats);
1107 EXPECT_EQ(36-3, layer->fakeLayerUpdater()->updateCount()); 1107 EXPECT_EQ(36-3, layer->fakeLayerUpdater()->updateCount());
1108 { 1108 {
1109 updateTextures(); 1109 updateTextures();
1110 } 1110 }
1111 1111
1112 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1); 1112 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1);
1113 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 330000, 1); 1113 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 330000, 1);
(...skipping 14 matching lines...) Expand all
1128 1128
1129 TEST_F(TiledLayerTest, tilesPaintedWithOcclusionAndTransforms) 1129 TEST_F(TiledLayerTest, tilesPaintedWithOcclusionAndTransforms)
1130 { 1130 {
1131 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get())); 1131 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get()));
1132 TestOcclusionTracker occluded; 1132 TestOcclusionTracker occluded;
1133 1133
1134 // The tile size is 100x100. 1134 // The tile size is 100x100.
1135 1135
1136 // This makes sure the painting works when the occluded region (in screen sp ace) 1136 // This makes sure the painting works when the occluded region (in screen sp ace)
1137 // is transformed differently than the layer. 1137 // is transformed differently than the layer.
1138 layer->setBounds(IntSize(600, 600)); 1138 layer->setBounds(gfx::Size(600, 600));
1139 WebTransformationMatrix screenTransform; 1139 WebTransformationMatrix screenTransform;
1140 screenTransform.scale(0.5); 1140 screenTransform.scale(0.5);
1141 layer->setScreenSpaceTransform(screenTransform); 1141 layer->setScreenSpaceTransform(screenTransform);
1142 layer->setDrawTransform(screenTransform); 1142 layer->setDrawTransform(screenTransform);
1143 1143
1144 occluded.setOcclusion(IntRect(100, 100, 150, 50)); 1144 occluded.setOcclusion(cc::IntRect(100, 100, 150, 50));
1145 layer->setDrawableContentRect(IntRect(IntPoint(), layer->contentBounds())); 1145 layer->setDrawableContentRect(gfx::Rect(gfx::Point(), layer->contentBounds() ));
1146 layer->setVisibleContentRect(IntRect(IntPoint(), layer->contentBounds())); 1146 layer->setVisibleContentRect(gfx::Rect(gfx::Point(), layer->contentBounds()) );
1147 layer->invalidateContentRect(IntRect(0, 0, 600, 600)); 1147 layer->invalidateContentRect(gfx::Rect(0, 0, 600, 600));
1148 layer->setTexturePriorities(m_priorityCalculator); 1148 layer->setTexturePriorities(m_priorityCalculator);
1149 m_textureManager->prioritizeTextures(); 1149 m_textureManager->prioritizeTextures();
1150 layer->update(*m_queue.get(), &occluded, m_stats); 1150 layer->update(*m_queue.get(), &occluded, m_stats);
1151 EXPECT_EQ(36-3, layer->fakeLayerUpdater()->updateCount()); 1151 EXPECT_EQ(36-3, layer->fakeLayerUpdater()->updateCount());
1152 1152
1153 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1); 1153 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1);
1154 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 330000, 1); 1154 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 330000, 1);
1155 EXPECT_EQ(3, occluded.overdrawMetrics().tilesCulledForUpload()); 1155 EXPECT_EQ(3, occluded.overdrawMetrics().tilesCulledForUpload());
1156 } 1156 }
1157 1157
1158 TEST_F(TiledLayerTest, tilesPaintedWithOcclusionAndScaling) 1158 TEST_F(TiledLayerTest, tilesPaintedWithOcclusionAndScaling)
1159 { 1159 {
1160 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get())); 1160 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get()));
1161 TestOcclusionTracker occluded; 1161 TestOcclusionTracker occluded;
1162 1162
1163 // The tile size is 100x100. 1163 // The tile size is 100x100.
1164 1164
1165 // This makes sure the painting works when the content space is scaled to 1165 // This makes sure the painting works when the content space is scaled to
1166 // a different layer space. In this case tiles are scaled to be 200x200 1166 // a different layer space. In this case tiles are scaled to be 200x200
1167 // pixels, which means none should be occluded. 1167 // pixels, which means none should be occluded.
1168 layer->setContentsScale(0.5); 1168 layer->setContentsScale(0.5);
1169 layer->setBounds(IntSize(600, 600)); 1169 layer->setBounds(gfx::Size(600, 600));
1170 WebTransformationMatrix drawTransform; 1170 WebTransformationMatrix drawTransform;
1171 drawTransform.scale(1 / layer->contentsScale()); 1171 drawTransform.scale(1 / layer->contentsScale());
1172 layer->setDrawTransform(drawTransform); 1172 layer->setDrawTransform(drawTransform);
1173 layer->setScreenSpaceTransform(drawTransform); 1173 layer->setScreenSpaceTransform(drawTransform);
1174 1174
1175 occluded.setOcclusion(IntRect(200, 200, 300, 100)); 1175 occluded.setOcclusion(cc::IntRect(200, 200, 300, 100));
1176 layer->setDrawableContentRect(IntRect(IntPoint(), layer->contentBounds())); 1176 layer->setDrawableContentRect(gfx::Rect(gfx::Point(), layer->contentBounds() ));
1177 layer->setVisibleContentRect(IntRect(IntPoint(), layer->contentBounds())); 1177 layer->setVisibleContentRect(gfx::Rect(gfx::Point(), layer->contentBounds()) );
1178 layer->invalidateContentRect(IntRect(0, 0, 600, 600)); 1178 layer->invalidateContentRect(gfx::Rect(0, 0, 600, 600));
1179 layer->setTexturePriorities(m_priorityCalculator); 1179 layer->setTexturePriorities(m_priorityCalculator);
1180 m_textureManager->prioritizeTextures(); 1180 m_textureManager->prioritizeTextures();
1181 layer->update(*m_queue.get(), &occluded, m_stats); 1181 layer->update(*m_queue.get(), &occluded, m_stats);
1182 // The content is half the size of the layer (so the number of tiles is fewe r). 1182 // The content is half the size of the layer (so the number of tiles is fewe r).
1183 // In this case, the content is 300x300, and since the tile size is 100, the 1183 // In this case, the content is 300x300, and since the tile size is 100, the
1184 // number of tiles 3x3. 1184 // number of tiles 3x3.
1185 EXPECT_EQ(9, layer->fakeLayerUpdater()->updateCount()); 1185 EXPECT_EQ(9, layer->fakeLayerUpdater()->updateCount());
1186 1186
1187 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1); 1187 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1);
1188 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 90000, 1 ); 1188 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 90000, 1 );
1189 EXPECT_EQ(0, occluded.overdrawMetrics().tilesCulledForUpload()); 1189 EXPECT_EQ(0, occluded.overdrawMetrics().tilesCulledForUpload());
1190 1190
1191 layer->fakeLayerUpdater()->clearUpdateCount(); 1191 layer->fakeLayerUpdater()->clearUpdateCount();
1192 1192
1193 // This makes sure the painting works when the content space is scaled to 1193 // This makes sure the painting works when the content space is scaled to
1194 // a different layer space. In this case the occluded region catches the 1194 // a different layer space. In this case the occluded region catches the
1195 // blown up tiles. 1195 // blown up tiles.
1196 occluded.setOcclusion(IntRect(200, 200, 300, 200)); 1196 occluded.setOcclusion(cc::IntRect(200, 200, 300, 200));
1197 layer->setDrawableContentRect(IntRect(IntPoint(), layer->contentBounds())); 1197 layer->setDrawableContentRect(gfx::Rect(gfx::Point(), layer->contentBounds() ));
1198 layer->setVisibleContentRect(IntRect(IntPoint(), layer->contentBounds())); 1198 layer->setVisibleContentRect(gfx::Rect(gfx::Point(), layer->contentBounds()) );
1199 layer->invalidateContentRect(IntRect(0, 0, 600, 600)); 1199 layer->invalidateContentRect(gfx::Rect(0, 0, 600, 600));
1200 layer->setTexturePriorities(m_priorityCalculator); 1200 layer->setTexturePriorities(m_priorityCalculator);
1201 m_textureManager->prioritizeTextures(); 1201 m_textureManager->prioritizeTextures();
1202 layer->update(*m_queue.get(), &occluded, m_stats); 1202 layer->update(*m_queue.get(), &occluded, m_stats);
1203 EXPECT_EQ(9-1, layer->fakeLayerUpdater()->updateCount()); 1203 EXPECT_EQ(9-1, layer->fakeLayerUpdater()->updateCount());
1204 1204
1205 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1); 1205 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1);
1206 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 90000 + 80000, 1); 1206 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 90000 + 80000, 1);
1207 EXPECT_EQ(1, occluded.overdrawMetrics().tilesCulledForUpload()); 1207 EXPECT_EQ(1, occluded.overdrawMetrics().tilesCulledForUpload());
1208 1208
1209 layer->fakeLayerUpdater()->clearUpdateCount(); 1209 layer->fakeLayerUpdater()->clearUpdateCount();
1210 1210
1211 // This makes sure content scaling and transforms work together. 1211 // This makes sure content scaling and transforms work together.
1212 WebTransformationMatrix screenTransform; 1212 WebTransformationMatrix screenTransform;
1213 screenTransform.scale(0.5); 1213 screenTransform.scale(0.5);
1214 layer->setScreenSpaceTransform(screenTransform); 1214 layer->setScreenSpaceTransform(screenTransform);
1215 layer->setDrawTransform(screenTransform); 1215 layer->setDrawTransform(screenTransform);
1216 1216
1217 occluded.setOcclusion(IntRect(100, 100, 150, 100)); 1217 occluded.setOcclusion(cc::IntRect(100, 100, 150, 100));
1218 layer->setDrawableContentRect(IntRect(IntPoint(), layer->contentBounds())); 1218 layer->setDrawableContentRect(gfx::Rect(gfx::Point(), layer->contentBounds() ));
1219 layer->setVisibleContentRect(IntRect(IntPoint(), layer->contentBounds())); 1219 layer->setVisibleContentRect(gfx::Rect(gfx::Point(), layer->contentBounds()) );
1220 layer->invalidateContentRect(IntRect(0, 0, 600, 600)); 1220 layer->invalidateContentRect(gfx::Rect(0, 0, 600, 600));
1221 layer->setTexturePriorities(m_priorityCalculator); 1221 layer->setTexturePriorities(m_priorityCalculator);
1222 m_textureManager->prioritizeTextures(); 1222 m_textureManager->prioritizeTextures();
1223 layer->update(*m_queue.get(), &occluded, m_stats); 1223 layer->update(*m_queue.get(), &occluded, m_stats);
1224 EXPECT_EQ(9-1, layer->fakeLayerUpdater()->updateCount()); 1224 EXPECT_EQ(9-1, layer->fakeLayerUpdater()->updateCount());
1225 1225
1226 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1); 1226 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1);
1227 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 90000 + 80000 + 80000, 1); 1227 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 90000 + 80000 + 80000, 1);
1228 EXPECT_EQ(1 + 1, occluded.overdrawMetrics().tilesCulledForUpload()); 1228 EXPECT_EQ(1 + 1, occluded.overdrawMetrics().tilesCulledForUpload());
1229 } 1229 }
1230 1230
1231 TEST_F(TiledLayerTest, visibleContentOpaqueRegion) 1231 TEST_F(TiledLayerTest, visibleContentOpaqueRegion)
1232 { 1232 {
1233 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get())); 1233 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get()));
1234 TestOcclusionTracker occluded; 1234 TestOcclusionTracker occluded;
1235 1235
1236 // The tile size is 100x100, so this invalidates and then paints two tiles i n various ways. 1236 // The tile size is 100x100, so this invalidates and then paints two tiles i n various ways.
1237 1237
1238 IntRect opaquePaintRect; 1238 gfx::Rect opaquePaintRect;
1239 Region opaqueContents; 1239 Region opaqueContents;
1240 1240
1241 IntRect contentBounds = IntRect(0, 0, 100, 200); 1241 gfx::Rect contentBounds = gfx::Rect(0, 0, 100, 200);
1242 IntRect visibleBounds = IntRect(0, 0, 100, 150); 1242 gfx::Rect visibleBounds = gfx::Rect(0, 0, 100, 150);
1243 1243
1244 layer->setBounds(contentBounds.size()); 1244 layer->setBounds(contentBounds.size());
1245 layer->setDrawableContentRect(visibleBounds); 1245 layer->setDrawableContentRect(visibleBounds);
1246 layer->setVisibleContentRect(visibleBounds); 1246 layer->setVisibleContentRect(visibleBounds);
1247 layer->setDrawOpacity(1); 1247 layer->setDrawOpacity(1);
1248 1248
1249 layer->setTexturePriorities(m_priorityCalculator); 1249 layer->setTexturePriorities(m_priorityCalculator);
1250 m_textureManager->prioritizeTextures(); 1250 m_textureManager->prioritizeTextures();
1251 1251
1252 // If the layer doesn't paint opaque content, then the visibleContentOpaqueR egion should be empty. 1252 // If the layer doesn't paint opaque content, then the visibleContentOpaqueR egion should be empty.
1253 layer->fakeLayerUpdater()->setOpaquePaintRect(IntRect()); 1253 layer->fakeLayerUpdater()->setOpaquePaintRect(gfx::Rect());
1254 layer->invalidateContentRect(contentBounds); 1254 layer->invalidateContentRect(contentBounds);
1255 layer->update(*m_queue.get(), &occluded, m_stats); 1255 layer->update(*m_queue.get(), &occluded, m_stats);
1256 opaqueContents = layer->visibleContentOpaqueRegion(); 1256 opaqueContents = layer->visibleContentOpaqueRegion();
1257 EXPECT_TRUE(opaqueContents.isEmpty()); 1257 EXPECT_TRUE(opaqueContents.isEmpty());
1258 1258
1259 EXPECT_NEAR(occluded.overdrawMetrics().pixelsPainted(), 20000, 1); 1259 EXPECT_NEAR(occluded.overdrawMetrics().pixelsPainted(), 20000, 1);
1260 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1); 1260 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1);
1261 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 20000, 1 ); 1261 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 20000, 1 );
1262 EXPECT_EQ(0, occluded.overdrawMetrics().tilesCulledForUpload()); 1262 EXPECT_EQ(0, occluded.overdrawMetrics().tilesCulledForUpload());
1263 1263
1264 // visibleContentOpaqueRegion should match the visible part of what is paint ed opaque. 1264 // visibleContentOpaqueRegion should match the visible part of what is paint ed opaque.
1265 opaquePaintRect = IntRect(10, 10, 90, 190); 1265 opaquePaintRect = gfx::Rect(10, 10, 90, 190);
1266 layer->fakeLayerUpdater()->setOpaquePaintRect(opaquePaintRect); 1266 layer->fakeLayerUpdater()->setOpaquePaintRect(opaquePaintRect);
1267 layer->invalidateContentRect(contentBounds); 1267 layer->invalidateContentRect(contentBounds);
1268 layer->update(*m_queue.get(), &occluded, m_stats); 1268 layer->update(*m_queue.get(), &occluded, m_stats);
1269 updateTextures(); 1269 updateTextures();
1270 opaqueContents = layer->visibleContentOpaqueRegion(); 1270 opaqueContents = layer->visibleContentOpaqueRegion();
1271 EXPECT_RECT_EQ(intersection(opaquePaintRect, visibleBounds), opaqueContents. bounds()); 1271 EXPECT_RECT_EQ(gfx::IntersectRects(opaquePaintRect, visibleBounds), opaqueCo ntents.bounds());
1272 EXPECT_EQ(1u, opaqueContents.rects().size()); 1272 EXPECT_EQ(1u, opaqueContents.rects().size());
1273 1273
1274 EXPECT_NEAR(occluded.overdrawMetrics().pixelsPainted(), 20000 * 2, 1); 1274 EXPECT_NEAR(occluded.overdrawMetrics().pixelsPainted(), 20000 * 2, 1);
1275 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 17100, 1); 1275 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 17100, 1);
1276 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 20000 + 20000 - 17100, 1); 1276 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 20000 + 20000 - 17100, 1);
1277 EXPECT_EQ(0, occluded.overdrawMetrics().tilesCulledForUpload()); 1277 EXPECT_EQ(0, occluded.overdrawMetrics().tilesCulledForUpload());
1278 1278
1279 // If we paint again without invalidating, the same stuff should be opaque. 1279 // If we paint again without invalidating, the same stuff should be opaque.
1280 layer->fakeLayerUpdater()->setOpaquePaintRect(IntRect()); 1280 layer->fakeLayerUpdater()->setOpaquePaintRect(gfx::Rect());
1281 layer->update(*m_queue.get(), &occluded, m_stats); 1281 layer->update(*m_queue.get(), &occluded, m_stats);
1282 updateTextures(); 1282 updateTextures();
1283 opaqueContents = layer->visibleContentOpaqueRegion(); 1283 opaqueContents = layer->visibleContentOpaqueRegion();
1284 EXPECT_RECT_EQ(intersection(opaquePaintRect, visibleBounds), opaqueContents. bounds()); 1284 EXPECT_RECT_EQ(gfx::IntersectRects(opaquePaintRect, visibleBounds), opaqueCo ntents.bounds());
1285 EXPECT_EQ(1u, opaqueContents.rects().size()); 1285 EXPECT_EQ(1u, opaqueContents.rects().size());
1286 1286
1287 EXPECT_NEAR(occluded.overdrawMetrics().pixelsPainted(), 20000 * 2, 1); 1287 EXPECT_NEAR(occluded.overdrawMetrics().pixelsPainted(), 20000 * 2, 1);
1288 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 17100, 1); 1288 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 17100, 1);
1289 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 20000 + 20000 - 17100, 1); 1289 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 20000 + 20000 - 17100, 1);
1290 EXPECT_EQ(0, occluded.overdrawMetrics().tilesCulledForUpload()); 1290 EXPECT_EQ(0, occluded.overdrawMetrics().tilesCulledForUpload());
1291 1291
1292 // If we repaint a non-opaque part of the tile, then it shouldn't lose its o paque-ness. And other tiles should 1292 // If we repaint a non-opaque part of the tile, then it shouldn't lose its o paque-ness. And other tiles should
1293 // not be affected. 1293 // not be affected.
1294 layer->fakeLayerUpdater()->setOpaquePaintRect(IntRect()); 1294 layer->fakeLayerUpdater()->setOpaquePaintRect(gfx::Rect());
1295 layer->invalidateContentRect(IntRect(0, 0, 1, 1)); 1295 layer->invalidateContentRect(gfx::Rect(0, 0, 1, 1));
1296 layer->update(*m_queue.get(), &occluded, m_stats); 1296 layer->update(*m_queue.get(), &occluded, m_stats);
1297 updateTextures(); 1297 updateTextures();
1298 opaqueContents = layer->visibleContentOpaqueRegion(); 1298 opaqueContents = layer->visibleContentOpaqueRegion();
1299 EXPECT_RECT_EQ(intersection(opaquePaintRect, visibleBounds), opaqueContents. bounds()); 1299 EXPECT_RECT_EQ(gfx::IntersectRects(opaquePaintRect, visibleBounds), opaqueCo ntents.bounds());
1300 EXPECT_EQ(1u, opaqueContents.rects().size()); 1300 EXPECT_EQ(1u, opaqueContents.rects().size());
1301 1301
1302 EXPECT_NEAR(occluded.overdrawMetrics().pixelsPainted(), 20000 * 2 + 1, 1); 1302 EXPECT_NEAR(occluded.overdrawMetrics().pixelsPainted(), 20000 * 2 + 1, 1);
1303 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 17100, 1); 1303 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 17100, 1);
1304 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 20000 + 20000 - 17100 + 1, 1); 1304 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 20000 + 20000 - 17100 + 1, 1);
1305 EXPECT_EQ(0, occluded.overdrawMetrics().tilesCulledForUpload()); 1305 EXPECT_EQ(0, occluded.overdrawMetrics().tilesCulledForUpload());
1306 1306
1307 // If we repaint an opaque part of the tile, then it should lose its opaque- ness. But other tiles should still 1307 // If we repaint an opaque part of the tile, then it should lose its opaque- ness. But other tiles should still
1308 // not be affected. 1308 // not be affected.
1309 layer->fakeLayerUpdater()->setOpaquePaintRect(IntRect()); 1309 layer->fakeLayerUpdater()->setOpaquePaintRect(gfx::Rect());
1310 layer->invalidateContentRect(IntRect(10, 10, 1, 1)); 1310 layer->invalidateContentRect(gfx::Rect(10, 10, 1, 1));
1311 layer->update(*m_queue.get(), &occluded, m_stats); 1311 layer->update(*m_queue.get(), &occluded, m_stats);
1312 updateTextures(); 1312 updateTextures();
1313 opaqueContents = layer->visibleContentOpaqueRegion(); 1313 opaqueContents = layer->visibleContentOpaqueRegion();
1314 EXPECT_RECT_EQ(intersection(IntRect(10, 100, 90, 100), visibleBounds), opaqu eContents.bounds()); 1314 EXPECT_RECT_EQ(gfx::IntersectRects(gfx::Rect(10, 100, 90, 100), visibleBound s), opaqueContents.bounds());
1315 EXPECT_EQ(1u, opaqueContents.rects().size()); 1315 EXPECT_EQ(1u, opaqueContents.rects().size());
1316 1316
1317 EXPECT_NEAR(occluded.overdrawMetrics().pixelsPainted(), 20000 * 2 + 1 + 1, 1); 1317 EXPECT_NEAR(occluded.overdrawMetrics().pixelsPainted(), 20000 * 2 + 1 + 1, 1);
1318 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 17100, 1); 1318 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 17100, 1);
1319 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 20000 + 20000 - 17100 + 1 + 1, 1); 1319 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 20000 + 20000 - 17100 + 1 + 1, 1);
1320 EXPECT_EQ(0, occluded.overdrawMetrics().tilesCulledForUpload()); 1320 EXPECT_EQ(0, occluded.overdrawMetrics().tilesCulledForUpload());
1321 } 1321 }
1322 1322
1323 TEST_F(TiledLayerTest, pixelsPaintedMetrics) 1323 TEST_F(TiledLayerTest, pixelsPaintedMetrics)
1324 { 1324 {
1325 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get())); 1325 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get()));
1326 TestOcclusionTracker occluded; 1326 TestOcclusionTracker occluded;
1327 1327
1328 // The tile size is 100x100, so this invalidates and then paints two tiles i n various ways. 1328 // The tile size is 100x100, so this invalidates and then paints two tiles i n various ways.
1329 1329
1330 IntRect opaquePaintRect; 1330 gfx::Rect opaquePaintRect;
1331 Region opaqueContents; 1331 Region opaqueContents;
1332 1332
1333 IntRect contentBounds = IntRect(0, 0, 100, 300); 1333 gfx::Rect contentBounds = gfx::Rect(0, 0, 100, 300);
1334 IntRect visibleBounds = IntRect(0, 0, 100, 300); 1334 gfx::Rect visibleBounds = gfx::Rect(0, 0, 100, 300);
1335 1335
1336 layer->setBounds(contentBounds.size()); 1336 layer->setBounds(contentBounds.size());
1337 layer->setDrawableContentRect(visibleBounds); 1337 layer->setDrawableContentRect(visibleBounds);
1338 layer->setVisibleContentRect(visibleBounds); 1338 layer->setVisibleContentRect(visibleBounds);
1339 layer->setDrawOpacity(1); 1339 layer->setDrawOpacity(1);
1340 1340
1341 layer->setTexturePriorities(m_priorityCalculator); 1341 layer->setTexturePriorities(m_priorityCalculator);
1342 m_textureManager->prioritizeTextures(); 1342 m_textureManager->prioritizeTextures();
1343 1343
1344 // Invalidates and paints the whole layer. 1344 // Invalidates and paints the whole layer.
1345 layer->fakeLayerUpdater()->setOpaquePaintRect(IntRect()); 1345 layer->fakeLayerUpdater()->setOpaquePaintRect(gfx::Rect());
1346 layer->invalidateContentRect(contentBounds); 1346 layer->invalidateContentRect(contentBounds);
1347 layer->update(*m_queue.get(), &occluded, m_stats); 1347 layer->update(*m_queue.get(), &occluded, m_stats);
1348 updateTextures(); 1348 updateTextures();
1349 opaqueContents = layer->visibleContentOpaqueRegion(); 1349 opaqueContents = layer->visibleContentOpaqueRegion();
1350 EXPECT_TRUE(opaqueContents.isEmpty()); 1350 EXPECT_TRUE(opaqueContents.isEmpty());
1351 1351
1352 EXPECT_NEAR(occluded.overdrawMetrics().pixelsPainted(), 30000, 1); 1352 EXPECT_NEAR(occluded.overdrawMetrics().pixelsPainted(), 30000, 1);
1353 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1); 1353 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1);
1354 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 30000, 1 ); 1354 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 30000, 1 );
1355 EXPECT_EQ(0, occluded.overdrawMetrics().tilesCulledForUpload()); 1355 EXPECT_EQ(0, occluded.overdrawMetrics().tilesCulledForUpload());
1356 1356
1357 // Invalidates an area on the top and bottom tile, which will cause us to pa int the tile in the middle, 1357 // Invalidates an area on the top and bottom tile, which will cause us to pa int the tile in the middle,
1358 // even though it is not dirty and will not be uploaded. 1358 // even though it is not dirty and will not be uploaded.
1359 layer->fakeLayerUpdater()->setOpaquePaintRect(IntRect()); 1359 layer->fakeLayerUpdater()->setOpaquePaintRect(gfx::Rect());
1360 layer->invalidateContentRect(IntRect(0, 0, 1, 1)); 1360 layer->invalidateContentRect(gfx::Rect(0, 0, 1, 1));
1361 layer->invalidateContentRect(IntRect(50, 200, 10, 10)); 1361 layer->invalidateContentRect(gfx::Rect(50, 200, 10, 10));
1362 layer->update(*m_queue.get(), &occluded, m_stats); 1362 layer->update(*m_queue.get(), &occluded, m_stats);
1363 updateTextures(); 1363 updateTextures();
1364 opaqueContents = layer->visibleContentOpaqueRegion(); 1364 opaqueContents = layer->visibleContentOpaqueRegion();
1365 EXPECT_TRUE(opaqueContents.isEmpty()); 1365 EXPECT_TRUE(opaqueContents.isEmpty());
1366 1366
1367 // The middle tile was painted even though not invalidated. 1367 // The middle tile was painted even though not invalidated.
1368 EXPECT_NEAR(occluded.overdrawMetrics().pixelsPainted(), 30000 + 60 * 210, 1) ; 1368 EXPECT_NEAR(occluded.overdrawMetrics().pixelsPainted(), 30000 + 60 * 210, 1) ;
1369 // The pixels uploaded will not include the non-invalidated tile in the midd le. 1369 // The pixels uploaded will not include the non-invalidated tile in the midd le.
1370 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1); 1370 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 0, 1);
1371 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 30000 + 1 + 100, 1); 1371 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 30000 + 1 + 100, 1);
1372 EXPECT_EQ(0, occluded.overdrawMetrics().tilesCulledForUpload()); 1372 EXPECT_EQ(0, occluded.overdrawMetrics().tilesCulledForUpload());
1373 } 1373 }
1374 1374
1375 TEST_F(TiledLayerTest, dontAllocateContentsWhenTargetSurfaceCantBeAllocated) 1375 TEST_F(TiledLayerTest, dontAllocateContentsWhenTargetSurfaceCantBeAllocated)
1376 { 1376 {
1377 // Tile size is 100x100. 1377 // Tile size is 100x100.
1378 IntRect rootRect(0, 0, 300, 200); 1378 gfx::Rect rootRect(0, 0, 300, 200);
1379 IntRect childRect(0, 0, 300, 100); 1379 gfx::Rect childRect(0, 0, 300, 100);
1380 IntRect child2Rect(0, 100, 300, 100); 1380 gfx::Rect child2Rect(0, 100, 300, 100);
1381 1381
1382 LayerTreeSettings settings; 1382 LayerTreeSettings settings;
1383 FakeLayerImplTreeHostClient fakeLayerImplTreeHostClient; 1383 FakeLayerImplTreeHostClient fakeLayerImplTreeHostClient;
1384 scoped_ptr<LayerTreeHost> layerTreeHost = LayerTreeHost::create(&fakeLayerIm plTreeHostClient, settings); 1384 scoped_ptr<LayerTreeHost> layerTreeHost = LayerTreeHost::create(&fakeLayerIm plTreeHostClient, settings);
1385 ASSERT_TRUE(layerTreeHost->initializeRendererIfNeeded()); 1385 ASSERT_TRUE(layerTreeHost->initializeRendererIfNeeded());
1386 1386
1387 scoped_refptr<FakeTiledLayer> root = make_scoped_refptr(new FakeTiledLayer(l ayerTreeHost->contentsTextureManager())); 1387 scoped_refptr<FakeTiledLayer> root = make_scoped_refptr(new FakeTiledLayer(l ayerTreeHost->contentsTextureManager()));
1388 scoped_refptr<Layer> surface = Layer::create(); 1388 scoped_refptr<Layer> surface = Layer::create();
1389 scoped_refptr<FakeTiledLayer> child = make_scoped_refptr(new FakeTiledLayer( layerTreeHost->contentsTextureManager())); 1389 scoped_refptr<FakeTiledLayer> child = make_scoped_refptr(new FakeTiledLayer( layerTreeHost->contentsTextureManager()));
1390 scoped_refptr<FakeTiledLayer> child2 = make_scoped_refptr(new FakeTiledLayer (layerTreeHost->contentsTextureManager())); 1390 scoped_refptr<FakeTiledLayer> child2 = make_scoped_refptr(new FakeTiledLayer (layerTreeHost->contentsTextureManager()));
1391 1391
1392 root->setBounds(rootRect.size()); 1392 root->setBounds(rootRect.size());
1393 root->setAnchorPoint(FloatPoint()); 1393 root->setAnchorPoint(gfx::PointF());
1394 root->setDrawableContentRect(rootRect); 1394 root->setDrawableContentRect(rootRect);
1395 root->setVisibleContentRect(rootRect); 1395 root->setVisibleContentRect(rootRect);
1396 root->addChild(surface); 1396 root->addChild(surface);
1397 1397
1398 surface->setForceRenderSurface(true); 1398 surface->setForceRenderSurface(true);
1399 surface->setAnchorPoint(FloatPoint()); 1399 surface->setAnchorPoint(gfx::PointF());
1400 surface->setOpacity(0.5); 1400 surface->setOpacity(0.5);
1401 surface->addChild(child); 1401 surface->addChild(child);
1402 surface->addChild(child2); 1402 surface->addChild(child2);
1403 1403
1404 child->setBounds(childRect.size()); 1404 child->setBounds(childRect.size());
1405 child->setAnchorPoint(FloatPoint()); 1405 child->setAnchorPoint(gfx::PointF());
1406 child->setPosition(childRect.location()); 1406 child->setPosition(childRect.origin());
1407 child->setVisibleContentRect(childRect); 1407 child->setVisibleContentRect(childRect);
1408 child->setDrawableContentRect(rootRect); 1408 child->setDrawableContentRect(rootRect);
1409 1409
1410 child2->setBounds(child2Rect.size()); 1410 child2->setBounds(child2Rect.size());
1411 child2->setAnchorPoint(FloatPoint()); 1411 child2->setAnchorPoint(gfx::PointF());
1412 child2->setPosition(child2Rect.location()); 1412 child2->setPosition(child2Rect.origin());
1413 child2->setVisibleContentRect(child2Rect); 1413 child2->setVisibleContentRect(child2Rect);
1414 child2->setDrawableContentRect(rootRect); 1414 child2->setDrawableContentRect(rootRect);
1415 1415
1416 layerTreeHost->setRootLayer(root); 1416 layerTreeHost->setRootLayer(root);
1417 layerTreeHost->setViewportSize(rootRect.size(), rootRect.size()); 1417 layerTreeHost->setViewportSize(rootRect.size(), rootRect.size());
1418 1418
1419 // With a huge memory limit, all layers should update and push their texture s. 1419 // With a huge memory limit, all layers should update and push their texture s.
1420 root->invalidateContentRect(rootRect); 1420 root->invalidateContentRect(rootRect);
1421 child->invalidateContentRect(childRect); 1421 child->invalidateContentRect(childRect);
1422 child2->invalidateContentRect(child2Rect); 1422 child2->invalidateContentRect(child2Rect);
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1561 1561
1562 private: 1562 private:
1563 TrackingLayerPainter* m_trackingLayerPainter; 1563 TrackingLayerPainter* m_trackingLayerPainter;
1564 scoped_refptr<BitmapCanvasLayerUpdater> m_layerUpdater; 1564 scoped_refptr<BitmapCanvasLayerUpdater> m_layerUpdater;
1565 }; 1565 };
1566 1566
1567 TEST_F(TiledLayerTest, nonIntegerContentsScaleIsNotDistortedDuringPaint) 1567 TEST_F(TiledLayerTest, nonIntegerContentsScaleIsNotDistortedDuringPaint)
1568 { 1568 {
1569 scoped_refptr<UpdateTrackingTiledLayer> layer = make_scoped_refptr(new Updat eTrackingTiledLayer(m_textureManager.get())); 1569 scoped_refptr<UpdateTrackingTiledLayer> layer = make_scoped_refptr(new Updat eTrackingTiledLayer(m_textureManager.get()));
1570 1570
1571 IntRect layerRect(0, 0, 30, 31); 1571 gfx::Rect layerRect(0, 0, 30, 31);
1572 layer->setPosition(layerRect.location()); 1572 layer->setPosition(layerRect.origin());
1573 layer->setBounds(layerRect.size()); 1573 layer->setBounds(layerRect.size());
1574 layer->setContentsScale(1.5); 1574 layer->setContentsScale(1.5);
1575 1575
1576 IntRect contentRect(0, 0, 45, 47); 1576 gfx::Rect contentRect(0, 0, 45, 47);
1577 EXPECT_EQ(contentRect.size(), layer->contentBounds()); 1577 EXPECT_EQ(contentRect.size(), layer->contentBounds());
1578 layer->setVisibleContentRect(contentRect); 1578 layer->setVisibleContentRect(contentRect);
1579 layer->setDrawableContentRect(contentRect); 1579 layer->setDrawableContentRect(contentRect);
1580 1580
1581 layer->setTexturePriorities(m_priorityCalculator); 1581 layer->setTexturePriorities(m_priorityCalculator);
1582 m_textureManager->prioritizeTextures(); 1582 m_textureManager->prioritizeTextures();
1583 1583
1584 // Update the whole tile. 1584 // Update the whole tile.
1585 layer->update(*m_queue.get(), 0, m_stats); 1585 layer->update(*m_queue.get(), 0, m_stats);
1586 layer->trackingLayerPainter()->resetPaintedRect(); 1586 layer->trackingLayerPainter()->resetPaintedRect();
1587 1587
1588 EXPECT_RECT_EQ(IntRect(), layer->trackingLayerPainter()->paintedRect()); 1588 EXPECT_RECT_EQ(gfx::Rect(), layer->trackingLayerPainter()->paintedRect());
1589 updateTextures(); 1589 updateTextures();
1590 1590
1591 // Invalidate the entire layer in content space. When painting, the rect giv en to webkit should match the layer's bounds. 1591 // Invalidate the entire layer in content space. When painting, the rect giv en to webkit should match the layer's bounds.
1592 layer->invalidateContentRect(contentRect); 1592 layer->invalidateContentRect(contentRect);
1593 layer->update(*m_queue.get(), 0, m_stats); 1593 layer->update(*m_queue.get(), 0, m_stats);
1594 1594
1595 EXPECT_RECT_EQ(layerRect, layer->trackingLayerPainter()->paintedRect()); 1595 EXPECT_RECT_EQ(layerRect, layer->trackingLayerPainter()->paintedRect());
1596 } 1596 }
1597 1597
1598 TEST_F(TiledLayerTest, nonIntegerContentsScaleIsNotDistortedDuringInvalidation) 1598 TEST_F(TiledLayerTest, nonIntegerContentsScaleIsNotDistortedDuringInvalidation)
1599 { 1599 {
1600 scoped_refptr<UpdateTrackingTiledLayer> layer = make_scoped_refptr(new Updat eTrackingTiledLayer(m_textureManager.get())); 1600 scoped_refptr<UpdateTrackingTiledLayer> layer = make_scoped_refptr(new Updat eTrackingTiledLayer(m_textureManager.get()));
1601 1601
1602 IntRect layerRect(0, 0, 30, 31); 1602 gfx::Rect layerRect(0, 0, 30, 31);
1603 layer->setPosition(layerRect.location()); 1603 layer->setPosition(layerRect.origin());
1604 layer->setBounds(layerRect.size()); 1604 layer->setBounds(layerRect.size());
1605 layer->setContentsScale(1.3f); 1605 layer->setContentsScale(1.3f);
1606 1606
1607 IntRect contentRect(IntPoint(), layer->contentBounds()); 1607 gfx::Rect contentRect(gfx::Point(), layer->contentBounds());
1608 layer->setVisibleContentRect(contentRect); 1608 layer->setVisibleContentRect(contentRect);
1609 layer->setDrawableContentRect(contentRect); 1609 layer->setDrawableContentRect(contentRect);
1610 1610
1611 layer->setTexturePriorities(m_priorityCalculator); 1611 layer->setTexturePriorities(m_priorityCalculator);
1612 m_textureManager->prioritizeTextures(); 1612 m_textureManager->prioritizeTextures();
1613 1613
1614 // Update the whole tile. 1614 // Update the whole tile.
1615 layer->update(*m_queue.get(), 0, m_stats); 1615 layer->update(*m_queue.get(), 0, m_stats);
1616 layer->trackingLayerPainter()->resetPaintedRect(); 1616 layer->trackingLayerPainter()->resetPaintedRect();
1617 1617
1618 EXPECT_RECT_EQ(IntRect(), layer->trackingLayerPainter()->paintedRect()); 1618 EXPECT_RECT_EQ(gfx::Rect(), layer->trackingLayerPainter()->paintedRect());
1619 updateTextures(); 1619 updateTextures();
1620 1620
1621 // Invalidate the entire layer in layer space. When painting, the rect given to webkit should match the layer's bounds. 1621 // Invalidate the entire layer in layer space. When painting, the rect given to webkit should match the layer's bounds.
1622 layer->setNeedsDisplayRect(layerRect); 1622 layer->setNeedsDisplayRect(layerRect);
1623 layer->update(*m_queue.get(), 0, m_stats); 1623 layer->update(*m_queue.get(), 0, m_stats);
1624 1624
1625 EXPECT_RECT_EQ(layerRect, layer->trackingLayerPainter()->paintedRect()); 1625 EXPECT_RECT_EQ(layerRect, layer->trackingLayerPainter()->paintedRect());
1626 } 1626 }
1627 1627
1628 } // namespace 1628 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698