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

Side by Side Diff: cc/tiled_layer_unittest.cc

Issue 11193010: cc: Add predictive pre-painting. (Closed) Base URL: http://git.chromium.org/chromium/src.git@PTM_TiledLayerChromium_fixes
Patch Set: Rebase + fix test Created 8 years, 2 months 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
« cc/tiled_layer.cc ('K') | « cc/tiled_layer.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "CCOverdrawMetrics.h" 9 #include "CCOverdrawMetrics.h"
10 #include "CCRenderingStats.h" 10 #include "CCRenderingStats.h"
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 282
283 // We should have one tile on the impl side. 283 // We should have one tile on the impl side.
284 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(2, 2)); 284 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(2, 2));
285 285
286 // For the next four updates, we should detect we still need idle painting. 286 // For the next four updates, we should detect we still need idle painting.
287 for (int i = 0; i < 4; i++) { 287 for (int i = 0; i < 4; i++) {
288 needsUpdate = updateAndPush(layer.get(), layerImpl.get()); 288 needsUpdate = updateAndPush(layer.get(), layerImpl.get());
289 EXPECT_TRUE(needsUpdate); 289 EXPECT_TRUE(needsUpdate);
290 } 290 }
291 291
292 // We should have one tile surrounding the visible tile on all sides, but no other tiles.
293 IntRect idlePaintTiles(1, 1, 3, 3);
294 for (int i = 0; i < 5; i++) {
295 for (int j = 0; j < 5; j++)
296 EXPECT_EQ(layerImpl->hasResourceIdForTileAt(i, j), idlePaintTiles.co ntains(i, j));
297 }
298
299 // We should always finish painting eventually. 292 // We should always finish painting eventually.
300 for (int i = 0; i < 20; i++) 293 for (int i = 0; i < 20; i++)
301 needsUpdate = updateAndPush(layer.get(), layerImpl.get()); 294 needsUpdate = updateAndPush(layer.get(), layerImpl.get());
295
296 // We should have pre-painted all of the surrounding tiles.
297 for (int i = 0; i < 5; i++) {
298 for (int j = 0; j < 5; j++)
299 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(i, j));
300 }
301
302 EXPECT_FALSE(needsUpdate); 302 EXPECT_FALSE(needsUpdate);
303 } 303 }
304 304
305 TEST_F(TiledLayerChromiumTest, predictivePainting)
306 {
307 scoped_refptr<FakeTiledLayerChromium> layer = make_scoped_refptr(new FakeTil edLayerChromium(m_textureManager.get()));
308 ScopedFakeCCTiledLayerImpl layerImpl(1);
309
310 // Prepainting should occur in the scroll direction first, and the
311 // visible rect should be extruded only along the dominant axis.
312 IntSize directions[6] = { IntSize(-10, 0),
313 IntSize(10, 0),
314 IntSize(0, -10),
315 IntSize(0, 10),
316 IntSize(10, 20),
317 IntSize(-20, 10) };
318 // We should push all tiles that touch the extruded visible rect.
319 IntRect pushedVisibleTiles[6] = { IntRect(2, 2, 2, 1),
320 IntRect(1, 2, 2, 1),
321 IntRect(2, 2, 1, 2),
322 IntRect(2, 1, 1, 2),
323 IntRect(2, 1, 1, 2),
324 IntRect(2, 2, 2, 1) };
325 // The first pre-paint should also paint first in the scroll
326 // direction so we should find one additional tile in the scroll direction.
327 IntRect pushedPrepaintTiles[6] = { IntRect(2, 2, 3, 1),
328 IntRect(0, 2, 3, 1),
329 IntRect(2, 2, 1, 3),
330 IntRect(2, 0, 1, 3),
331 IntRect(2, 0, 1, 3),
332 IntRect(2, 2, 3, 1) };
333 for(int k = 0; k < 6; k++) {
334 // The tile size is 100x100. Setup 5x5 tiles with one visible tile
335 // in the center.
336 IntSize contentBounds = IntSize(500, 500);
337 IntRect contentRect = IntRect(0, 0, 500, 500);
338 IntRect visibleRect = IntRect(200, 200, 100, 100);
339 IntRect previousVisibleRect = IntRect(visibleRect.location() + direction s[k], visibleRect.size());
340 IntRect nextVisibleRect = IntRect(visibleRect.location() - directions[k] , visibleRect.size());
341
342 // Setup. Use the previousVisibleRect to setup the prediction for next f rame.
343 layer->setBounds(contentBounds);
344 layer->setVisibleContentRect(previousVisibleRect);
345 layer->invalidateContentRect(contentRect);
346 bool needsUpdate = updateAndPush(layer.get(), layerImpl.get());
347
348 // Invalidate and move the visibleRect in the scroll direction.
349 // Check that the correct tiles have been painted in the visible pass.
350 layer->invalidateContentRect(contentRect);
351 layer->setVisibleContentRect(visibleRect);
352 needsUpdate = updateAndPush(layer.get(), layerImpl.get());
353 for (int i = 0; i < 5; i++) {
354 for (int j = 0; j < 5; j++)
355 EXPECT_EQ(layerImpl->hasResourceIdForTileAt(i, j), pushedVisible Tiles[k].contains(i, j));
356 }
357
358 // Move the transform in the same direction without invalidating.
359 // Check that non-visible pre-painting occured in the correct direction.
360 // Ignore diagonal scrolls here (k > 3) as these have new visible conten t now.
361 if (k <= 3) {
362 layer->setVisibleContentRect(nextVisibleRect);
363 needsUpdate = updateAndPush(layer.get(), layerImpl.get());
364 for (int i = 0; i < 5; i++) {
365 for (int j = 0; j < 5; j++)
366 EXPECT_EQ(layerImpl->hasResourceIdForTileAt(i, j), pushedPre paintTiles[k].contains(i, j));
367 }
368 }
369
370 // We should always finish painting eventually.
371 for (int i = 0; i < 20; i++)
372 needsUpdate = updateAndPush(layer.get(), layerImpl.get());
373 EXPECT_FALSE(needsUpdate);
374 }
375 }
376
305 TEST_F(TiledLayerChromiumTest, pushTilesAfterIdlePaintFailed) 377 TEST_F(TiledLayerChromiumTest, pushTilesAfterIdlePaintFailed)
306 { 378 {
307 // 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. 379 // 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.
308 m_textureManager->setMaxMemoryLimitBytes(2 * 1024 * 1024); 380 m_textureManager->setMaxMemoryLimitBytes(2 * 1024 * 1024);
309 scoped_refptr<FakeTiledLayerChromium> layer1 = make_scoped_refptr(new FakeTi ledLayerChromium(m_textureManager.get())); 381 scoped_refptr<FakeTiledLayerChromium> layer1 = make_scoped_refptr(new FakeTi ledLayerChromium(m_textureManager.get()));
310 ScopedFakeCCTiledLayerImpl layerImpl1(1); 382 ScopedFakeCCTiledLayerImpl layerImpl1(1);
311 scoped_refptr<FakeTiledLayerChromium> layer2 = make_scoped_refptr(new FakeTi ledLayerChromium(m_textureManager.get())); 383 scoped_refptr<FakeTiledLayerChromium> layer2 = make_scoped_refptr(new FakeTi ledLayerChromium(m_textureManager.get()));
312 ScopedFakeCCTiledLayerImpl layerImpl2(2); 384 ScopedFakeCCTiledLayerImpl layerImpl2(2);
313 385
314 // For this test we have two layers. layer1 exhausts most texture memory, le aving room for 2 more tiles from 386 // For this test we have two layers. layer1 exhausts most texture memory, le aving room for 2 more tiles from
(...skipping 1234 matching lines...) Expand 10 before | Expand all | Expand 10 after
1549 updateTextures(); 1621 updateTextures();
1550 1622
1551 // Invalidate the entire layer in layer space. When painting, the rect given to webkit should match the layer's bounds. 1623 // Invalidate the entire layer in layer space. When painting, the rect given to webkit should match the layer's bounds.
1552 layer->setNeedsDisplayRect(layerRect); 1624 layer->setNeedsDisplayRect(layerRect);
1553 layer->update(*m_queue.get(), 0, m_stats); 1625 layer->update(*m_queue.get(), 0, m_stats);
1554 1626
1555 EXPECT_RECT_EQ(layerRect, layer->trackingLayerPainter()->paintedRect()); 1627 EXPECT_RECT_EQ(layerRect, layer->trackingLayerPainter()->paintedRect());
1556 } 1628 }
1557 1629
1558 } // namespace 1630 } // namespace
OLDNEW
« cc/tiled_layer.cc ('K') | « cc/tiled_layer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698