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

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: Add constants. 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
« no previous file with comments | « 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 "cc/bitmap_canvas_layer_texture_updater.h" 9 #include "cc/bitmap_canvas_layer_texture_updater.h"
10 #include "cc/layer_painter.h" 10 #include "cc/layer_painter.h"
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
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());
287 EXPECT_TRUE(needsUpdate); 287 EXPECT_TRUE(needsUpdate);
288 } 288 }
289 289
290 // We should have one tile surrounding the visible tile on all sides, but no other tiles.
291 IntRect idlePaintTiles(1, 1, 3, 3);
292 for (int i = 0; i < 5; i++) {
293 for (int j = 0; j < 5; j++)
294 EXPECT_EQ(layerImpl->hasResourceIdForTileAt(i, j), idlePaintTiles.co ntains(i, j));
295 }
296
297 // We should always finish painting eventually. 290 // We should always finish painting eventually.
298 for (int i = 0; i < 20; i++) 291 for (int i = 0; i < 20; i++)
299 needsUpdate = updateAndPush(layer.get(), layerImpl.get()); 292 needsUpdate = updateAndPush(layer.get(), layerImpl.get());
293
294 // We should have pre-painted all of the surrounding tiles.
295 for (int i = 0; i < 5; i++) {
296 for (int j = 0; j < 5; j++)
297 EXPECT_TRUE(layerImpl->hasResourceIdForTileAt(i, j));
298 }
299
300 EXPECT_FALSE(needsUpdate); 300 EXPECT_FALSE(needsUpdate);
301 } 301 }
302 302
303 TEST_F(TiledLayerTest, predictivePainting)
304 {
305 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer( m_textureManager.get()));
306 ScopedFakeTiledLayerImpl layerImpl(1);
307
308 // Prepainting should occur in the scroll direction first, and the
309 // visible rect should be extruded only along the dominant axis.
310 IntSize directions[6] = { IntSize(-10, 0),
311 IntSize(10, 0),
312 IntSize(0, -10),
313 IntSize(0, 10),
314 IntSize(10, 20),
315 IntSize(-20, 10) };
316 // We should push all tiles that touch the extruded visible rect.
317 IntRect pushedVisibleTiles[6] = { IntRect(2, 2, 2, 1),
318 IntRect(1, 2, 2, 1),
319 IntRect(2, 2, 1, 2),
320 IntRect(2, 1, 1, 2),
321 IntRect(2, 1, 1, 2),
322 IntRect(2, 2, 2, 1) };
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.
325 IntRect pushedPrepaintTiles[6] = { IntRect(2, 2, 3, 1),
326 IntRect(0, 2, 3, 1),
327 IntRect(2, 2, 1, 3),
328 IntRect(2, 0, 1, 3),
329 IntRect(2, 0, 1, 3),
330 IntRect(2, 2, 3, 1) };
331 for(int k = 0; k < 6; k++) {
332 // The tile size is 100x100. Setup 5x5 tiles with one visible tile
333 // in the center.
334 IntSize contentBounds = IntSize(500, 500);
335 IntRect contentRect = IntRect(0, 0, 500, 500);
336 IntRect visibleRect = IntRect(200, 200, 100, 100);
337 IntRect previousVisibleRect = IntRect(visibleRect.location() + direction s[k], visibleRect.size());
338 IntRect nextVisibleRect = IntRect(visibleRect.location() - directions[k] , visibleRect.size());
339
340 // Setup. Use the previousVisibleRect to setup the prediction for next f rame.
341 layer->setBounds(contentBounds);
342 layer->setVisibleContentRect(previousVisibleRect);
343 layer->invalidateContentRect(contentRect);
344 bool needsUpdate = updateAndPush(layer.get(), layerImpl.get());
345
346 // Invalidate and move the visibleRect in the scroll direction.
347 // Check that the correct tiles have been painted in the visible pass.
348 layer->invalidateContentRect(contentRect);
349 layer->setVisibleContentRect(visibleRect);
350 needsUpdate = updateAndPush(layer.get(), layerImpl.get());
351 for (int i = 0; i < 5; i++) {
352 for (int j = 0; j < 5; j++)
353 EXPECT_EQ(layerImpl->hasResourceIdForTileAt(i, j), pushedVisible Tiles[k].contains(i, j));
354 }
355
356 // Move the transform in the same direction without invalidating.
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.
359 if (k <= 3) {
360 layer->setVisibleContentRect(nextVisibleRect);
361 needsUpdate = updateAndPush(layer.get(), layerImpl.get());
362 for (int i = 0; i < 5; i++) {
363 for (int j = 0; j < 5; j++)
364 EXPECT_EQ(layerImpl->hasResourceIdForTileAt(i, j), pushedPre paintTiles[k].contains(i, j));
365 }
366 }
367
368 // We should always finish painting eventually.
369 for (int i = 0; i < 20; i++)
370 needsUpdate = updateAndPush(layer.get(), layerImpl.get());
371 EXPECT_FALSE(needsUpdate);
372 }
373 }
374
303 TEST_F(TiledLayerTest, pushTilesAfterIdlePaintFailed) 375 TEST_F(TiledLayerTest, pushTilesAfterIdlePaintFailed)
304 { 376 {
305 // 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.
306 m_textureManager->setMaxMemoryLimitBytes(2 * 1024 * 1024); 378 m_textureManager->setMaxMemoryLimitBytes(2 * 1024 * 1024);
307 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()));
308 ScopedFakeTiledLayerImpl layerImpl1(1); 380 ScopedFakeTiledLayerImpl layerImpl1(1);
309 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()));
310 ScopedFakeTiledLayerImpl layerImpl2(2); 382 ScopedFakeTiledLayerImpl layerImpl2(2);
311 383
312 // 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
(...skipping 1234 matching lines...) Expand 10 before | Expand all | Expand 10 after
1547 updateTextures(); 1619 updateTextures();
1548 1620
1549 // 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.
1550 layer->setNeedsDisplayRect(layerRect); 1622 layer->setNeedsDisplayRect(layerRect);
1551 layer->update(*m_queue.get(), 0, m_stats); 1623 layer->update(*m_queue.get(), 0, m_stats);
1552 1624
1553 EXPECT_RECT_EQ(layerRect, layer->trackingLayerPainter()->paintedRect()); 1625 EXPECT_RECT_EQ(layerRect, layer->trackingLayerPainter()->paintedRect());
1554 } 1626 }
1555 1627
1556 } // namespace 1628 } // namespace
OLDNEW
« no previous file with comments | « cc/tiled_layer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698