diff options
author | jamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-25 00:09:14 +0000 |
---|---|---|
committer | jamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-25 00:09:14 +0000 |
commit | 94f206c1c75eb8cc4df2225a1c5c9c7b6fc96679 (patch) | |
tree | 530f51d5c75459999e4adf2a6895884ce1c15ce0 /cc/CCPrioritizedTextureTest.cpp | |
parent | 56235947f2b023fc63cfad692c56df4e92199848 (diff) | |
download | chromium_src-94f206c1c75eb8cc4df2225a1c5c9c7b6fc96679.zip chromium_src-94f206c1c75eb8cc4df2225a1c5c9c7b6fc96679.tar.gz chromium_src-94f206c1c75eb8cc4df2225a1c5c9c7b6fc96679.tar.bz2 |
Here are gyp targets and stubs for compiling libcc and the webkit_compositor bindings in chromium. Everything is guarded behind the off-by-default use_libcc_for_compositor gyp variable. I haven't included the actual code here, but there are scripts to sync. I plan to land + manually sync the code into place until we're ready to flip the gyp switch.
Snapshot from r126652
BUG=
Review URL: https://chromiumcodereview.appspot.com/10828381
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@153354 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/CCPrioritizedTextureTest.cpp')
-rw-r--r-- | cc/CCPrioritizedTextureTest.cpp | 456 |
1 files changed, 456 insertions, 0 deletions
diff --git a/cc/CCPrioritizedTextureTest.cpp b/cc/CCPrioritizedTextureTest.cpp new file mode 100644 index 0000000..0594d6b --- /dev/null +++ b/cc/CCPrioritizedTextureTest.cpp @@ -0,0 +1,456 @@ +// Copyright 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "config.h" + +#include "CCPrioritizedTexture.h" + +#include "CCPrioritizedTextureManager.h" +#include "CCSingleThreadProxy.h" // For DebugScopedSetImplThread +#include "CCTexture.h" +#include "CCTiledLayerTestCommon.h" +#include "FakeCCGraphicsContext.h" +#include <gtest/gtest.h> + +using namespace WebCore; +using namespace WebKitTests; +using namespace WTF; + +namespace { + +class CCPrioritizedTextureTest : public testing::Test { +public: + CCPrioritizedTextureTest() + : m_textureSize(256, 256) + , m_textureFormat(GraphicsContext3D::RGBA) + , m_context(WebKit::createFakeCCGraphicsContext()) + { + DebugScopedSetImplThread implThread; + m_resourceProvider = CCResourceProvider::create(m_context.get()); + } + + virtual ~CCPrioritizedTextureTest() + { + DebugScopedSetImplThread implThread; + m_resourceProvider.clear(); + } + + size_t texturesMemorySize(size_t textureCount) + { + return CCTexture::memorySizeBytes(m_textureSize, m_textureFormat) * textureCount; + } + + PassOwnPtr<CCPrioritizedTextureManager> createManager(size_t maxTextures) + { + return CCPrioritizedTextureManager::create(texturesMemorySize(maxTextures), 1024, 0); + } + + bool validateTexture(OwnPtr<CCPrioritizedTexture>& texture, bool requestLate) + { + DebugScopedSetImplThread implThread; +#if !ASSERT_DISABLED + texture->textureManager()->assertInvariants(); +#endif + if (requestLate) + texture->requestLate(); + bool success = texture->canAcquireBackingTexture(); + if (success) + texture->acquireBackingTexture(resourceProvider()); + return success; + } + + CCResourceProvider* resourceProvider() + { + return m_resourceProvider.get(); + } + +protected: + const IntSize m_textureSize; + const GC3Denum m_textureFormat; + OwnPtr<CCGraphicsContext> m_context; + OwnPtr<CCResourceProvider> m_resourceProvider; +}; + +TEST_F(CCPrioritizedTextureTest, requestTextureExceedingMaxLimit) +{ + const size_t maxTextures = 8; + OwnPtr<CCPrioritizedTextureManager> textureManager = createManager(maxTextures); + + // Create textures for double our memory limit. + OwnPtr<CCPrioritizedTexture> textures[maxTextures*2]; + + for (size_t i = 0; i < maxTextures*2; ++i) + textures[i] = textureManager->createTexture(m_textureSize, m_textureFormat); + + // Set decreasing priorities + for (size_t i = 0; i < maxTextures*2; ++i) + textures[i]->setRequestPriority(100 + i); + + // Only lower half should be available. + textureManager->prioritizeTextures(); + EXPECT_TRUE(validateTexture(textures[0], false)); + EXPECT_TRUE(validateTexture(textures[7], false)); + EXPECT_FALSE(validateTexture(textures[8], false)); + EXPECT_FALSE(validateTexture(textures[15], false)); + + // Set increasing priorities + for (size_t i = 0; i < maxTextures*2; ++i) + textures[i]->setRequestPriority(100 - i); + + // Only upper half should be available. + textureManager->prioritizeTextures(); + EXPECT_FALSE(validateTexture(textures[0], false)); + EXPECT_FALSE(validateTexture(textures[7], false)); + EXPECT_TRUE(validateTexture(textures[8], false)); + EXPECT_TRUE(validateTexture(textures[15], false)); + + EXPECT_EQ(texturesMemorySize(maxTextures), textureManager->memoryAboveCutoffBytes()); + EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutoffBytes()); + + DebugScopedSetImplThread implThread; + textureManager->clearAllMemory(resourceProvider()); +} + +TEST_F(CCPrioritizedTextureTest, changeMemoryLimits) +{ + const size_t maxTextures = 8; + OwnPtr<CCPrioritizedTextureManager> textureManager = createManager(maxTextures); + OwnPtr<CCPrioritizedTexture> textures[maxTextures]; + + for (size_t i = 0; i < maxTextures; ++i) + textures[i] = textureManager->createTexture(m_textureSize, m_textureFormat); + for (size_t i = 0; i < maxTextures; ++i) + textures[i]->setRequestPriority(100 + i); + + // Set max limit to 8 textures + textureManager->setMaxMemoryLimitBytes(texturesMemorySize(8)); + textureManager->prioritizeTextures(); + for (size_t i = 0; i < maxTextures; ++i) + validateTexture(textures[i], false); + { + DebugScopedSetImplThread implThread; + textureManager->reduceMemory(resourceProvider()); + } + + EXPECT_EQ(texturesMemorySize(8), textureManager->memoryAboveCutoffBytes()); + EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutoffBytes()); + + // Set max limit to 5 textures + textureManager->setMaxMemoryLimitBytes(texturesMemorySize(5)); + textureManager->prioritizeTextures(); + for (size_t i = 0; i < maxTextures; ++i) + EXPECT_EQ(validateTexture(textures[i], false), i < 5); + { + DebugScopedSetImplThread implThread; + textureManager->reduceMemory(resourceProvider()); + } + + EXPECT_EQ(texturesMemorySize(5), textureManager->memoryAboveCutoffBytes()); + EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutoffBytes()); + + // Set max limit to 4 textures + textureManager->setMaxMemoryLimitBytes(texturesMemorySize(4)); + textureManager->prioritizeTextures(); + for (size_t i = 0; i < maxTextures; ++i) + EXPECT_EQ(validateTexture(textures[i], false), i < 4); + { + DebugScopedSetImplThread implThread; + textureManager->reduceMemory(resourceProvider()); + } + + EXPECT_EQ(texturesMemorySize(4), textureManager->memoryAboveCutoffBytes()); + EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutoffBytes()); + + DebugScopedSetImplThread implThread; + textureManager->clearAllMemory(resourceProvider()); +} + +TEST_F(CCPrioritizedTextureTest, textureManagerPartialUpdateTextures) +{ + const size_t maxTextures = 4; + const size_t numTextures = 4; + OwnPtr<CCPrioritizedTextureManager> textureManager = createManager(maxTextures); + OwnPtr<CCPrioritizedTexture> textures[numTextures]; + OwnPtr<CCPrioritizedTexture> moreTextures[numTextures]; + + for (size_t i = 0; i < numTextures; ++i) { + textures[i] = textureManager->createTexture(m_textureSize, m_textureFormat); + moreTextures[i] = textureManager->createTexture(m_textureSize, m_textureFormat); + } + + for (size_t i = 0; i < numTextures; ++i) + textures[i]->setRequestPriority(200 + i); + textureManager->prioritizeTextures(); + + // Allocate textures which are currently high priority. + EXPECT_TRUE(validateTexture(textures[0], false)); + EXPECT_TRUE(validateTexture(textures[1], false)); + EXPECT_TRUE(validateTexture(textures[2], false)); + EXPECT_TRUE(validateTexture(textures[3], false)); + + EXPECT_TRUE(textures[0]->haveBackingTexture()); + EXPECT_TRUE(textures[1]->haveBackingTexture()); + EXPECT_TRUE(textures[2]->haveBackingTexture()); + EXPECT_TRUE(textures[3]->haveBackingTexture()); + + for (size_t i = 0; i < numTextures; ++i) + moreTextures[i]->setRequestPriority(100 + i); + textureManager->prioritizeTextures(); + + // Textures are now below cutoff. + EXPECT_FALSE(validateTexture(textures[0], false)); + EXPECT_FALSE(validateTexture(textures[1], false)); + EXPECT_FALSE(validateTexture(textures[2], false)); + EXPECT_FALSE(validateTexture(textures[3], false)); + + // But they are still valid to use. + EXPECT_TRUE(textures[0]->haveBackingTexture()); + EXPECT_TRUE(textures[1]->haveBackingTexture()); + EXPECT_TRUE(textures[2]->haveBackingTexture()); + EXPECT_TRUE(textures[3]->haveBackingTexture()); + + // Higher priority textures are finally needed. + EXPECT_TRUE(validateTexture(moreTextures[0], false)); + EXPECT_TRUE(validateTexture(moreTextures[1], false)); + EXPECT_TRUE(validateTexture(moreTextures[2], false)); + EXPECT_TRUE(validateTexture(moreTextures[3], false)); + + // Lower priority have been fully evicted. + EXPECT_FALSE(textures[0]->haveBackingTexture()); + EXPECT_FALSE(textures[1]->haveBackingTexture()); + EXPECT_FALSE(textures[2]->haveBackingTexture()); + EXPECT_FALSE(textures[3]->haveBackingTexture()); + + DebugScopedSetImplThread implThread; + textureManager->clearAllMemory(resourceProvider()); +} + +TEST_F(CCPrioritizedTextureTest, textureManagerPrioritiesAreEqual) +{ + const size_t maxTextures = 16; + OwnPtr<CCPrioritizedTextureManager> textureManager = createManager(maxTextures); + OwnPtr<CCPrioritizedTexture> textures[maxTextures]; + + for (size_t i = 0; i < maxTextures; ++i) + textures[i] = textureManager->createTexture(m_textureSize, m_textureFormat); + + // All 16 textures have the same priority except 2 higher priority. + for (size_t i = 0; i < maxTextures; ++i) + textures[i]->setRequestPriority(100); + textures[0]->setRequestPriority(99); + textures[1]->setRequestPriority(99); + + // Set max limit to 8 textures + textureManager->setMaxMemoryLimitBytes(texturesMemorySize(8)); + textureManager->prioritizeTextures(); + + // The two high priority textures should be available, others should not. + for (size_t i = 0; i < 2; ++i) + EXPECT_TRUE(validateTexture(textures[i], false)); + for (size_t i = 2; i < maxTextures; ++i) + EXPECT_FALSE(validateTexture(textures[i], false)); + EXPECT_EQ(texturesMemorySize(2), textureManager->memoryAboveCutoffBytes()); + EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutoffBytes()); + + // Manually reserving textures should only succeed on the higher priority textures, + // and on remaining textures up to the memory limit. + for (size_t i = 0; i < 8; i++) + EXPECT_TRUE(validateTexture(textures[i], true)); + for (size_t i = 9; i < maxTextures; i++) + EXPECT_FALSE(validateTexture(textures[i], true)); + EXPECT_EQ(texturesMemorySize(8), textureManager->memoryAboveCutoffBytes()); + EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutoffBytes()); + + DebugScopedSetImplThread implThread; + textureManager->clearAllMemory(resourceProvider()); +} + +TEST_F(CCPrioritizedTextureTest, textureManagerDestroyedFirst) +{ + OwnPtr<CCPrioritizedTextureManager> textureManager = createManager(1); + OwnPtr<CCPrioritizedTexture> texture = textureManager->createTexture(m_textureSize, m_textureFormat); + + // Texture is initially invalid, but it will become available. + EXPECT_FALSE(texture->haveBackingTexture()); + + texture->setRequestPriority(100); + textureManager->prioritizeTextures(); + + EXPECT_TRUE(validateTexture(texture, false)); + EXPECT_TRUE(texture->canAcquireBackingTexture()); + EXPECT_TRUE(texture->haveBackingTexture()); + + { + DebugScopedSetImplThread implThread; + textureManager->clearAllMemory(resourceProvider()); + } + textureManager.clear(); + + EXPECT_FALSE(texture->canAcquireBackingTexture()); + EXPECT_FALSE(texture->haveBackingTexture()); +} + +TEST_F(CCPrioritizedTextureTest, textureMovedToNewManager) +{ + OwnPtr<CCPrioritizedTextureManager> textureManagerOne = createManager(1); + OwnPtr<CCPrioritizedTextureManager> textureManagerTwo = createManager(1); + OwnPtr<CCPrioritizedTexture> texture = textureManagerOne->createTexture(m_textureSize, m_textureFormat); + + // Texture is initially invalid, but it will become available. + EXPECT_FALSE(texture->haveBackingTexture()); + + texture->setRequestPriority(100); + textureManagerOne->prioritizeTextures(); + + EXPECT_TRUE(validateTexture(texture, false)); + EXPECT_TRUE(texture->canAcquireBackingTexture()); + EXPECT_TRUE(texture->haveBackingTexture()); + + texture->setTextureManager(0); + + { + DebugScopedSetImplThread implThread; + textureManagerOne->clearAllMemory(resourceProvider()); + } + textureManagerOne.clear(); + + EXPECT_FALSE(texture->canAcquireBackingTexture()); + EXPECT_FALSE(texture->haveBackingTexture()); + + texture->setTextureManager(textureManagerTwo.get()); + + textureManagerTwo->prioritizeTextures(); + + EXPECT_TRUE(validateTexture(texture, false)); + EXPECT_TRUE(texture->canAcquireBackingTexture()); + EXPECT_TRUE(texture->haveBackingTexture()); + + DebugScopedSetImplThread implThread; + textureManagerTwo->clearAllMemory(resourceProvider()); +} + +TEST_F(CCPrioritizedTextureTest, renderSurfacesReduceMemoryAvailableOutsideRootSurface) +{ + const size_t maxTextures = 8; + OwnPtr<CCPrioritizedTextureManager> textureManager = createManager(maxTextures); + + // Half of the memory is taken by surfaces (with high priority place-holder) + OwnPtr<CCPrioritizedTexture> renderSurfacePlaceHolder = textureManager->createTexture(m_textureSize, m_textureFormat); + renderSurfacePlaceHolder->setToSelfManagedMemoryPlaceholder(texturesMemorySize(4)); + renderSurfacePlaceHolder->setRequestPriority(CCPriorityCalculator::renderSurfacePriority()); + + // Create textures to fill our memory limit. + OwnPtr<CCPrioritizedTexture> textures[maxTextures]; + + for (size_t i = 0; i < maxTextures; ++i) + textures[i] = textureManager->createTexture(m_textureSize, m_textureFormat); + + // Set decreasing non-visible priorities outside root surface. + for (size_t i = 0; i < maxTextures; ++i) + textures[i]->setRequestPriority(100 + i); + + // Only lower half should be available. + textureManager->prioritizeTextures(); + EXPECT_TRUE(validateTexture(textures[0], false)); + EXPECT_TRUE(validateTexture(textures[3], false)); + EXPECT_FALSE(validateTexture(textures[4], false)); + EXPECT_FALSE(validateTexture(textures[7], false)); + + // Set increasing non-visible priorities outside root surface. + for (size_t i = 0; i < maxTextures; ++i) + textures[i]->setRequestPriority(100 - i); + + // Only upper half should be available. + textureManager->prioritizeTextures(); + EXPECT_FALSE(validateTexture(textures[0], false)); + EXPECT_FALSE(validateTexture(textures[3], false)); + EXPECT_TRUE(validateTexture(textures[4], false)); + EXPECT_TRUE(validateTexture(textures[7], false)); + + EXPECT_EQ(texturesMemorySize(4), textureManager->memoryAboveCutoffBytes()); + EXPECT_EQ(texturesMemorySize(4), textureManager->memoryForSelfManagedTextures()); + EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutoffBytes()); + + DebugScopedSetImplThread implThread; + textureManager->clearAllMemory(resourceProvider()); +} + +TEST_F(CCPrioritizedTextureTest, renderSurfacesReduceMemoryAvailableForRequestLate) +{ + const size_t maxTextures = 8; + OwnPtr<CCPrioritizedTextureManager> textureManager = createManager(maxTextures); + + // Half of the memory is taken by surfaces (with high priority place-holder) + OwnPtr<CCPrioritizedTexture> renderSurfacePlaceHolder = textureManager->createTexture(m_textureSize, m_textureFormat); + renderSurfacePlaceHolder->setToSelfManagedMemoryPlaceholder(texturesMemorySize(4)); + renderSurfacePlaceHolder->setRequestPriority(CCPriorityCalculator::renderSurfacePriority()); + + // Create textures to fill our memory limit. + OwnPtr<CCPrioritizedTexture> textures[maxTextures]; + + for (size_t i = 0; i < maxTextures; ++i) + textures[i] = textureManager->createTexture(m_textureSize, m_textureFormat); + + // Set equal priorities. + for (size_t i = 0; i < maxTextures; ++i) + textures[i]->setRequestPriority(100); + + // The first four to be requested late will be available. + textureManager->prioritizeTextures(); + for (unsigned i = 0; i < maxTextures; ++i) + EXPECT_FALSE(validateTexture(textures[i], false)); + for (unsigned i = 0; i < maxTextures; i += 2) + EXPECT_TRUE(validateTexture(textures[i], true)); + for (unsigned i = 1; i < maxTextures; i += 2) + EXPECT_FALSE(validateTexture(textures[i], true)); + + EXPECT_EQ(texturesMemorySize(4), textureManager->memoryAboveCutoffBytes()); + EXPECT_EQ(texturesMemorySize(4), textureManager->memoryForSelfManagedTextures()); + EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutoffBytes()); + + DebugScopedSetImplThread implThread; + textureManager->clearAllMemory(resourceProvider()); +} + +TEST_F(CCPrioritizedTextureTest, whenRenderSurfaceNotAvailableTexturesAlsoNotAvailable) +{ + const size_t maxTextures = 8; + OwnPtr<CCPrioritizedTextureManager> textureManager = createManager(maxTextures); + + // Half of the memory is taken by surfaces (with high priority place-holder) + OwnPtr<CCPrioritizedTexture> renderSurfacePlaceHolder = textureManager->createTexture(m_textureSize, m_textureFormat); + renderSurfacePlaceHolder->setToSelfManagedMemoryPlaceholder(texturesMemorySize(4)); + renderSurfacePlaceHolder->setRequestPriority(CCPriorityCalculator::renderSurfacePriority()); + + // Create textures to fill our memory limit. + OwnPtr<CCPrioritizedTexture> textures[maxTextures]; + + for (size_t i = 0; i < maxTextures; ++i) + textures[i] = textureManager->createTexture(m_textureSize, m_textureFormat); + + // Set 6 visible textures in the root surface, and 2 in a child surface. + for (size_t i = 0; i < 6; ++i) + textures[i]->setRequestPriority(CCPriorityCalculator::visiblePriority(true)); + for (size_t i = 6; i < 8; ++i) + textures[i]->setRequestPriority(CCPriorityCalculator::visiblePriority(false)); + + textureManager->prioritizeTextures(); + + // Unable to requestLate textures in the child surface. + EXPECT_FALSE(validateTexture(textures[6], true)); + EXPECT_FALSE(validateTexture(textures[7], true)); + + // Root surface textures are valid. + for (size_t i = 0; i < 6; ++i) + EXPECT_TRUE(validateTexture(textures[i], false)); + + EXPECT_EQ(texturesMemorySize(6), textureManager->memoryAboveCutoffBytes()); + EXPECT_EQ(texturesMemorySize(2), textureManager->memoryForSelfManagedTextures()); + EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutoffBytes()); + + DebugScopedSetImplThread implThread; + textureManager->clearAllMemory(resourceProvider()); +} + +} // namespace |