| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "CCPrioritizedTexture.h" | 7 #include "CCPrioritizedTexture.h" |
| 8 | 8 |
| 9 #include "CCPrioritizedTextureManager.h" | 9 #include "CCPrioritizedTextureManager.h" |
| 10 #include "CCSingleThreadProxy.h" // For DebugScopedSetImplThread | 10 #include "CCSingleThreadProxy.h" // For DebugScopedSetImplThread |
| 11 #include "CCTexture.h" | 11 #include "CCTexture.h" |
| 12 #include "CCTiledLayerTestCommon.h" | 12 #include "CCTiledLayerTestCommon.h" |
| 13 #include "FakeCCGraphicsContext.h" | 13 #include "FakeCCGraphicsContext.h" |
| 14 #include "WebCompositorInitializer.h" |
| 14 #include <gtest/gtest.h> | 15 #include <gtest/gtest.h> |
| 15 #include <public/WebCompositor.h> | |
| 16 | 16 |
| 17 using namespace WebCore; | 17 using namespace WebCore; |
| 18 using namespace WebKitTests; | 18 using namespace WebKitTests; |
| 19 using namespace WTF; | 19 using namespace WTF; |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 class CCPrioritizedTextureTest : public testing::Test { | 23 class CCPrioritizedTextureTest : public testing::Test { |
| 24 public: | 24 public: |
| 25 CCPrioritizedTextureTest() | 25 CCPrioritizedTextureTest() |
| 26 : m_textureSize(256, 256) | 26 : m_textureSize(256, 256) |
| 27 , m_textureFormat(GraphicsContext3D::RGBA) | 27 , m_textureFormat(GraphicsContext3D::RGBA) |
| 28 , m_compositorInitializer(0) |
| 28 , m_context(WebKit::createFakeCCGraphicsContext()) | 29 , m_context(WebKit::createFakeCCGraphicsContext()) |
| 29 { | 30 { |
| 30 WebKit::WebCompositor::initialize(0); | |
| 31 DebugScopedSetImplThread implThread; | 31 DebugScopedSetImplThread implThread; |
| 32 m_resourceProvider = CCResourceProvider::create(m_context.get()); | 32 m_resourceProvider = CCResourceProvider::create(m_context.get()); |
| 33 } | 33 } |
| 34 | 34 |
| 35 virtual ~CCPrioritizedTextureTest() | 35 virtual ~CCPrioritizedTextureTest() |
| 36 { | 36 { |
| 37 { | 37 DebugScopedSetImplThread implThread; |
| 38 DebugScopedSetImplThread implThread; | 38 m_resourceProvider.clear(); |
| 39 m_resourceProvider.clear(); | |
| 40 } | |
| 41 WebKit::WebCompositor::shutdown(); | |
| 42 } | 39 } |
| 43 | 40 |
| 44 size_t texturesMemorySize(size_t textureCount) | 41 size_t texturesMemorySize(size_t textureCount) |
| 45 { | 42 { |
| 46 return CCTexture::memorySizeBytes(m_textureSize, m_textureFormat) * text
ureCount; | 43 return CCTexture::memorySizeBytes(m_textureSize, m_textureFormat) * text
ureCount; |
| 47 } | 44 } |
| 48 | 45 |
| 49 PassOwnPtr<CCPrioritizedTextureManager> createManager(size_t maxTextures) | 46 PassOwnPtr<CCPrioritizedTextureManager> createManager(size_t maxTextures) |
| 50 { | 47 { |
| 51 return CCPrioritizedTextureManager::create(texturesMemorySize(maxTexture
s), 1024, 0); | 48 return CCPrioritizedTextureManager::create(texturesMemorySize(maxTexture
s), 1024, 0); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 66 } | 63 } |
| 67 | 64 |
| 68 CCResourceProvider* resourceProvider() | 65 CCResourceProvider* resourceProvider() |
| 69 { | 66 { |
| 70 return m_resourceProvider.get(); | 67 return m_resourceProvider.get(); |
| 71 } | 68 } |
| 72 | 69 |
| 73 protected: | 70 protected: |
| 74 const IntSize m_textureSize; | 71 const IntSize m_textureSize; |
| 75 const GC3Denum m_textureFormat; | 72 const GC3Denum m_textureFormat; |
| 73 WebCompositorInitializer m_compositorInitializer; |
| 76 OwnPtr<CCGraphicsContext> m_context; | 74 OwnPtr<CCGraphicsContext> m_context; |
| 77 OwnPtr<CCResourceProvider> m_resourceProvider; | 75 OwnPtr<CCResourceProvider> m_resourceProvider; |
| 78 }; | 76 }; |
| 79 | 77 |
| 80 TEST_F(CCPrioritizedTextureTest, requestTextureExceedingMaxLimit) | 78 TEST_F(CCPrioritizedTextureTest, requestTextureExceedingMaxLimit) |
| 81 { | 79 { |
| 82 const size_t maxTextures = 8; | 80 const size_t maxTextures = 8; |
| 83 OwnPtr<CCPrioritizedTextureManager> textureManager = createManager(maxTextur
es); | 81 OwnPtr<CCPrioritizedTextureManager> textureManager = createManager(maxTextur
es); |
| 84 | 82 |
| 85 // Create textures for double our memory limit. | 83 // Create textures for double our memory limit. |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 | 450 |
| 453 EXPECT_EQ(texturesMemorySize(6), textureManager->memoryAboveCutoffBytes()); | 451 EXPECT_EQ(texturesMemorySize(6), textureManager->memoryAboveCutoffBytes()); |
| 454 EXPECT_EQ(texturesMemorySize(2), textureManager->memoryForSelfManagedTexture
s()); | 452 EXPECT_EQ(texturesMemorySize(2), textureManager->memoryForSelfManagedTexture
s()); |
| 455 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); | 453 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); |
| 456 | 454 |
| 457 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; | 455 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; |
| 458 textureManager->clearAllMemory(resourceProvider()); | 456 textureManager->clearAllMemory(resourceProvider()); |
| 459 } | 457 } |
| 460 | 458 |
| 461 } // namespace | 459 } // namespace |
| OLD | NEW |