diff options
author | Simon Hausmann <simon.hausmann@nokia.com> | 2012-08-21 10:57:44 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2012-08-21 10:57:44 +0200 |
commit | 5ef7c8a6a70875d4430752d146bdcb069605d71d (patch) | |
tree | f6256640b6c46d7da221435803cae65326817ba2 /Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp | |
parent | decad929f578d8db641febc8740649ca6c574638 (diff) | |
download | qtwebkit-5ef7c8a6a70875d4430752d146bdcb069605d71d.tar.gz |
Imported WebKit commit 356d83016b090995d08ad568f2d2c243aa55e831 (http://svn.webkit.org/repository/webkit/trunk@126147)
New snapshot including various build fixes for newer Qt 5
Diffstat (limited to 'Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp')
-rw-r--r-- | Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp | 185 |
1 files changed, 95 insertions, 90 deletions
diff --git a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp b/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp index bab7168c4..689b817af 100644 --- a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp +++ b/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp @@ -29,14 +29,14 @@ #include "BitmapCanvasLayerTextureUpdater.h" #include "CCAnimationTestCommon.h" #include "CCLayerTreeTestCommon.h" +#include "CCOverdrawMetrics.h" +#include "CCRenderingStats.h" +#include "CCSingleThreadProxy.h" // For DebugScopedSetImplThread +#include "CCTextureUpdateController.h" #include "CCTiledLayerTestCommon.h" #include "FakeCCGraphicsContext.h" #include "FakeCCLayerTreeHostClient.h" #include "LayerPainterChromium.h" -#include "cc/CCOverdrawMetrics.h" -#include "cc/CCRenderingStats.h" -#include "cc/CCSingleThreadProxy.h" // For DebugScopedSetImplThread -#include "cc/CCTextureUpdateController.h" #include <gtest/gtest.h> #include <public/WebCompositor.h> #include <public/WebTransformationMatrix.h> @@ -497,6 +497,72 @@ TEST_F(TiledLayerChromiumTest, pushTilesLayerMarkedDirtyDuringPaintOnPreviousLay EXPECT_TRUE(layer2Impl->hasTileAt(0, 1)); } +TEST_F(TiledLayerChromiumTest, paintSmallAnimatedLayersImmediately) +{ + // Create a CCLayerTreeHost that has the right viewportsize, + // so the layer is considered small enough. + WebKit::WebCompositor::initialize(0); + FakeCCLayerTreeHostClient fakeCCLayerTreeHostClient; + OwnPtr<CCLayerTreeHost> ccLayerTreeHost = CCLayerTreeHost::create(&fakeCCLayerTreeHostClient, CCLayerTreeSettings()); + + bool runOutOfMemory[2] = {false, true}; + for (int i = 0; i < 2; i++) { + // Create a layer with 4x4 tiles. + int layerWidth = 4 * FakeTiledLayerChromium::tileSize().width(); + int layerHeight = 4 * FakeTiledLayerChromium::tileSize().height(); + int memoryForLayer = layerWidth * layerHeight * 4; + IntSize viewportSize = IntSize(layerWidth, layerHeight); + ccLayerTreeHost->setViewportSize(viewportSize, viewportSize); + + // Use 8x4 tiles to run out of memory. + if (runOutOfMemory[i]) + layerWidth *= 2; + + OwnPtr<CCPrioritizedTextureManager> textureManager = CCPrioritizedTextureManager::create(memoryForLayer, 1024, CCRenderer::ContentPool); + DebugScopedSetImplThread implThread; + + RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(textureManager.get())); + OwnPtr<FakeCCTiledLayerImpl> layerImpl(adoptPtr(new FakeCCTiledLayerImpl(1))); + + // Full size layer with half being visible. + IntSize contentBounds(layerWidth, layerHeight); + IntRect contentRect(IntPoint::zero(), contentBounds); + IntRect visibleRect(IntPoint::zero(), IntSize(layerWidth / 2, layerHeight)); + + // Pretend the layer is animating. + layer->setDrawTransformIsAnimating(true); + layer->setBounds(contentBounds); + layer->setVisibleContentRect(visibleRect); + layer->invalidateContentRect(contentRect); + layer->setLayerTreeHost(ccLayerTreeHost.get()); + + // The layer should paint it's entire contents on the first paint + // if it is close to the viewport size and has the available memory. + layer->setTexturePriorities(m_priorityCalculator); + textureManager->prioritizeTextures(); + layer->updateContentRect(m_queue, visibleRect, 0, m_stats); + updateTextures(); + layer->pushPropertiesTo(layerImpl.get()); + + // We should have all the tiles for the small animated layer. + // We should still have the visible tiles when we didn't + // have enough memory for all the tiles. + if (!runOutOfMemory[i]) { + for (int i = 0; i < 4; ++i) { + for (int j = 0; j < 4; ++j) + EXPECT_TRUE(layerImpl->hasTileAt(i, j)); + } + } else { + for (int i = 0; i < 8; ++i) { + for (int j = 0; j < 4; ++j) + EXPECT_EQ(layerImpl->hasTileAt(i, j), i < 4); + } + } + } + ccLayerTreeHost.clear(); + WebKit::WebCompositor::shutdown(); +} + TEST_F(TiledLayerChromiumTest, idlePaintOutOfMemory) { // The tile size is 100x100. Setup 3x3 tiles with one 1x1 visible tile in the center. @@ -581,108 +647,47 @@ TEST_F(TiledLayerChromiumTest, idlePaintNonVisibleLayers) IntSize contentBounds(100, 100); IntRect contentRect(IntPoint::zero(), contentBounds); - OwnPtr<CCPrioritizedTextureManager> textureManager = CCPrioritizedTextureManager::create(20000, 1024, CCRenderer::ContentPool); + OwnPtr<CCPrioritizedTextureManager> textureManager = CCPrioritizedTextureManager::create(4*1024*1024, 1024, CCRenderer::ContentPool); RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(textureManager.get())); DebugScopedSetImplThread implThread; OwnPtr<FakeCCTiledLayerImpl> layerImpl(adoptPtr(new FakeCCTiledLayerImpl(1))); - - // Invalidate the layer but make none of it visible, so nothing paints. - IntRect visibleRect; - layer->setBounds(contentBounds); - layer->setVisibleContentRect(visibleRect); - layer->invalidateContentRect(contentRect); - - for (int i = 0; i < 2; i++) { - // Paint / idle-paint. - layer->setTexturePriorities(m_priorityCalculator); - textureManager->prioritizeTextures(); - layer->updateContentRect(m_queue, visibleRect, 0, m_stats); - - // Non-visible layers don't need idle paint. - EXPECT_FALSE(layer->needsIdlePaint(visibleRect)); - - layer->pushPropertiesTo(layerImpl.get()); - - // We should not have any tiles pushed since the layer is not visible. - EXPECT_FALSE(layerImpl->hasTileAt(0, 0)); - } -} -static void testHaveOuterTiles(FakeCCTiledLayerImpl* layerImpl, int width, int height, int have) -{ - for (int i = 0; i < width; ++i) { - for (int j = 0; j < height; ++j) { - bool hasTile = i < have || j < have || i >= width - have || j >= height - have; - EXPECT_EQ(hasTile, layerImpl->hasTileAt(i, j)); - } - } -} + // Alternate between not visible and visible. + IntRect v(0, 0, 100, 100); + IntRect nv(0, 0, 0, 0); + IntRect visibleRect[10] = {nv, nv, v, v, nv, nv, v, v, nv, nv}; + bool invalidate[10] = {true, true, true, true, true, true, true, true, false, false }; -TEST_F(TiledLayerChromiumTest, idlePaintNonVisibleAnimatingLayers) -{ - OwnPtr<CCPrioritizedTextureManager> textureManager = CCPrioritizedTextureManager::create(8000*8000*8, 1024, CCRenderer::ContentPool); - DebugScopedSetImplThread implThread; + // We should not have any tiles except for when the layer was visible + // or after the layer was visible and we didn't invalidate. + bool haveTile[10] = { false, false, true, true, false, false, true, true, true, true }; - int tileWidth = FakeTiledLayerChromium::tileSize().width(); - int tileHeight = FakeTiledLayerChromium::tileSize().height(); - int width[] = { 1, 2, 3, 4, 9, 10, 0 }; - int height[] = { 1, 2, 3, 4, 9, 10, 0 }; + for (int i = 0; i < 10; i++) { + layer->setVisibleContentRect(visibleRect[i]); - for (int j = 0; height[j]; ++j) { - for (int i = 0; width[i]; ++i) { - RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(textureManager.get())); - OwnPtr<FakeCCTiledLayerImpl> layerImpl(adoptPtr(new FakeCCTiledLayerImpl(1))); - - // Pretend the layer is animating. - layer->setDrawTransformIsAnimating(true); - - IntSize contentBounds(width[i] * tileWidth, height[j] * tileHeight); - IntRect contentRect(IntPoint::zero(), contentBounds); - IntRect visibleRect; - - layer->setBounds(contentBounds); - layer->setVisibleContentRect(visibleRect); + // Skip invalidation once to insure the tile stays in memory while not visible. + if (invalidate[i]) layer->invalidateContentRect(contentRect); - layer->setTexturePriorities(m_priorityCalculator); - textureManager->prioritizeTextures(); - - // If idlePaintRect gives back a non-empty result then we should paint it. Otherwise, - // we shoud paint nothing. - bool shouldPrepaint = !layer->idlePaintRect(visibleRect).isEmpty(); - - // Normally we don't allow non-visible layers to pre-paint, but if they are animating then we should. - EXPECT_EQ(shouldPrepaint, layer->needsIdlePaint(visibleRect)); - - // If the layer is to be prepainted at all, then after four updates we should have the outer row/columns painted. - for (int k = 0; k < 4; ++k) { - layer->setTexturePriorities(m_priorityCalculator); - textureManager->prioritizeTextures(); - - layer->updateContentRect(m_queue, visibleRect, 0, m_stats); - updateTextures(); - layer->pushPropertiesTo(layerImpl.get()); - } - - testHaveOuterTiles(layerImpl.get(), width[i], height[j], shouldPrepaint ? 1 : 0); + // Paint / idle-paint. + textureManager->clearPriorities(); + layer->setTexturePriorities(m_priorityCalculator); + textureManager->prioritizeTextures(); + layer->updateContentRect(m_queue, visibleRect[i], 0, m_stats); - // We don't currently idle paint past the outermost tiles. - EXPECT_FALSE(layer->needsIdlePaint(visibleRect)); - for (int k = 0; k < 4; ++k) { - layer->setTexturePriorities(m_priorityCalculator); - textureManager->prioritizeTextures(); + updateTextures(); - layer->updateContentRect(m_queue, visibleRect, 0, m_stats); - updateTextures(); - layer->pushPropertiesTo(layerImpl.get()); - } + // We should never signal idle paint, as we painted the entire layer + // or the layer was not visible. + EXPECT_FALSE(layer->needsIdlePaint(visibleRect[i])); - testHaveOuterTiles(layerImpl.get(), width[i], height[j], shouldPrepaint ? 1 : 0); - } + layer->pushPropertiesTo(layerImpl.get()); + EXPECT_EQ(layerImpl->hasTileAt(0, 0), haveTile[i]); } } + TEST_F(TiledLayerChromiumTest, invalidateFromPrepare) { OwnPtr<CCPrioritizedTextureManager> textureManager = CCPrioritizedTextureManager::create(4*1024*1024, 1024, CCRenderer::ContentPool); |