| 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 "cc/test/fake_graphics_context.h" | 12 #include "cc/test/fake_graphics_context.h" |
| 13 #include "cc/test/tiled_layer_test_common.h" | 13 #include "cc/test/tiled_layer_test_common.h" |
| 14 #include "cc/test/web_compositor_initializer.h" | 14 #include "cc/test/web_compositor_initializer.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 16 |
| 17 using namespace cc; | 17 using namespace cc; |
| 18 using namespace WebKitTests; | 18 using namespace WebKitTests; |
| 19 | 19 |
| 20 namespace cc { | 20 namespace cc { |
| 21 | 21 |
| 22 class CCPrioritizedTextureTest : public testing::Test { | 22 class PrioritizedTextureTest : public testing::Test { |
| 23 public: | 23 public: |
| 24 CCPrioritizedTextureTest() | 24 PrioritizedTextureTest() |
| 25 : m_textureSize(256, 256) | 25 : m_textureSize(256, 256) |
| 26 , m_textureFormat(GraphicsContext3D::RGBA) | 26 , m_textureFormat(GraphicsContext3D::RGBA) |
| 27 , m_compositorInitializer(0) | 27 , m_compositorInitializer(0) |
| 28 , m_context(WebKit::createFakeCCGraphicsContext()) | 28 , m_context(WebKit::createFakeGraphicsContext()) |
| 29 { | 29 { |
| 30 DebugScopedSetImplThread implThread; | 30 DebugScopedSetImplThread implThread; |
| 31 m_resourceProvider = CCResourceProvider::create(m_context.get()); | 31 m_resourceProvider = ResourceProvider::create(m_context.get()); |
| 32 } | 32 } |
| 33 | 33 |
| 34 virtual ~CCPrioritizedTextureTest() | 34 virtual ~PrioritizedTextureTest() |
| 35 { | 35 { |
| 36 DebugScopedSetImplThread implThread; | 36 DebugScopedSetImplThread implThread; |
| 37 m_resourceProvider.reset(); | 37 m_resourceProvider.reset(); |
| 38 } | 38 } |
| 39 | 39 |
| 40 size_t texturesMemorySize(size_t textureCount) | 40 size_t texturesMemorySize(size_t textureCount) |
| 41 { | 41 { |
| 42 return CCTexture::memorySizeBytes(m_textureSize, m_textureFormat) * text
ureCount; | 42 return Texture::memorySizeBytes(m_textureSize, m_textureFormat) * textur
eCount; |
| 43 } | 43 } |
| 44 | 44 |
| 45 scoped_ptr<CCPrioritizedTextureManager> createManager(size_t maxTextures) | 45 scoped_ptr<PrioritizedTextureManager> createManager(size_t maxTextures) |
| 46 { | 46 { |
| 47 return CCPrioritizedTextureManager::create(texturesMemorySize(maxTexture
s), 1024, 0); | 47 return PrioritizedTextureManager::create(texturesMemorySize(maxTextures)
, 1024, 0); |
| 48 } | 48 } |
| 49 | 49 |
| 50 bool validateTexture(scoped_ptr<CCPrioritizedTexture>& texture, bool request
Late) | 50 bool validateTexture(scoped_ptr<PrioritizedTexture>& texture, bool requestLa
te) |
| 51 { | 51 { |
| 52 textureManagerAssertInvariants(texture->textureManager()); | 52 textureManagerAssertInvariants(texture->textureManager()); |
| 53 if (requestLate) | 53 if (requestLate) |
| 54 texture->requestLate(); | 54 texture->requestLate(); |
| 55 textureManagerAssertInvariants(texture->textureManager()); | 55 textureManagerAssertInvariants(texture->textureManager()); |
| 56 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; | 56 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; |
| 57 bool success = texture->canAcquireBackingTexture(); | 57 bool success = texture->canAcquireBackingTexture(); |
| 58 if (success) | 58 if (success) |
| 59 texture->acquireBackingTexture(resourceProvider()); | 59 texture->acquireBackingTexture(resourceProvider()); |
| 60 return success; | 60 return success; |
| 61 } | 61 } |
| 62 | 62 |
| 63 void prioritizeTexturesAndBackings(CCPrioritizedTextureManager* textureManag
er) | 63 void prioritizeTexturesAndBackings(PrioritizedTextureManager* textureManager
) |
| 64 { | 64 { |
| 65 textureManager->prioritizeTextures(); | 65 textureManager->prioritizeTextures(); |
| 66 textureManagerUpdateBackingsPriorities(textureManager); | 66 textureManagerUpdateBackingsPriorities(textureManager); |
| 67 } | 67 } |
| 68 | 68 |
| 69 void textureManagerUpdateBackingsPriorities(CCPrioritizedTextureManager* tex
tureManager) | 69 void textureManagerUpdateBackingsPriorities(PrioritizedTextureManager* textu
reManager) |
| 70 { | 70 { |
| 71 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; | 71 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; |
| 72 textureManager->pushTexturePrioritiesToBackings(); | 72 textureManager->pushTexturePrioritiesToBackings(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 CCResourceProvider* resourceProvider() | 75 ResourceProvider* resourceProvider() |
| 76 { | 76 { |
| 77 return m_resourceProvider.get(); | 77 return m_resourceProvider.get(); |
| 78 } | 78 } |
| 79 | 79 |
| 80 void textureManagerAssertInvariants(CCPrioritizedTextureManager* textureMana
ger) | 80 void textureManagerAssertInvariants(PrioritizedTextureManager* textureManage
r) |
| 81 { | 81 { |
| 82 #if !ASSERT_DISABLED | 82 #if !ASSERT_DISABLED |
| 83 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; | 83 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; |
| 84 textureManager->assertInvariants(); | 84 textureManager->assertInvariants(); |
| 85 #endif | 85 #endif |
| 86 } | 86 } |
| 87 | 87 |
| 88 bool textureBackingIsAbovePriorityCutoff(CCPrioritizedTexture* texture) | 88 bool textureBackingIsAbovePriorityCutoff(PrioritizedTexture* texture) |
| 89 { | 89 { |
| 90 return texture->m_backing->wasAbovePriorityCutoffAtLastPriorityUpdate(); | 90 return texture->m_backing->wasAbovePriorityCutoffAtLastPriorityUpdate(); |
| 91 } | 91 } |
| 92 | 92 |
| 93 protected: | 93 protected: |
| 94 const IntSize m_textureSize; | 94 const IntSize m_textureSize; |
| 95 const GC3Denum m_textureFormat; | 95 const GC3Denum m_textureFormat; |
| 96 WebCompositorInitializer m_compositorInitializer; | 96 WebCompositorInitializer m_compositorInitializer; |
| 97 scoped_ptr<CCGraphicsContext> m_context; | 97 scoped_ptr<GraphicsContext> m_context; |
| 98 scoped_ptr<CCResourceProvider> m_resourceProvider; | 98 scoped_ptr<ResourceProvider> m_resourceProvider; |
| 99 }; | 99 }; |
| 100 | 100 |
| 101 } | 101 } |
| 102 | 102 |
| 103 namespace { | 103 namespace { |
| 104 | 104 |
| 105 TEST_F(CCPrioritizedTextureTest, requestTextureExceedingMaxLimit) | 105 TEST_F(PrioritizedTextureTest, requestTextureExceedingMaxLimit) |
| 106 { | 106 { |
| 107 const size_t maxTextures = 8; | 107 const size_t maxTextures = 8; |
| 108 scoped_ptr<CCPrioritizedTextureManager> textureManager = createManager(maxTe
xtures); | 108 scoped_ptr<PrioritizedTextureManager> textureManager = createManager(maxText
ures); |
| 109 | 109 |
| 110 // Create textures for double our memory limit. | 110 // Create textures for double our memory limit. |
| 111 scoped_ptr<CCPrioritizedTexture> textures[maxTextures*2]; | 111 scoped_ptr<PrioritizedTexture> textures[maxTextures*2]; |
| 112 | 112 |
| 113 for (size_t i = 0; i < maxTextures*2; ++i) | 113 for (size_t i = 0; i < maxTextures*2; ++i) |
| 114 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); | 114 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); |
| 115 | 115 |
| 116 // Set decreasing priorities | 116 // Set decreasing priorities |
| 117 for (size_t i = 0; i < maxTextures*2; ++i) | 117 for (size_t i = 0; i < maxTextures*2; ++i) |
| 118 textures[i]->setRequestPriority(100 + i); | 118 textures[i]->setRequestPriority(100 + i); |
| 119 | 119 |
| 120 // Only lower half should be available. | 120 // Only lower half should be available. |
| 121 prioritizeTexturesAndBackings(textureManager.get()); | 121 prioritizeTexturesAndBackings(textureManager.get()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 135 EXPECT_TRUE(validateTexture(textures[8], false)); | 135 EXPECT_TRUE(validateTexture(textures[8], false)); |
| 136 EXPECT_TRUE(validateTexture(textures[15], false)); | 136 EXPECT_TRUE(validateTexture(textures[15], false)); |
| 137 | 137 |
| 138 EXPECT_EQ(texturesMemorySize(maxTextures), textureManager->memoryAboveCutoff
Bytes()); | 138 EXPECT_EQ(texturesMemorySize(maxTextures), textureManager->memoryAboveCutoff
Bytes()); |
| 139 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); | 139 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); |
| 140 | 140 |
| 141 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; | 141 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; |
| 142 textureManager->clearAllMemory(resourceProvider()); | 142 textureManager->clearAllMemory(resourceProvider()); |
| 143 } | 143 } |
| 144 | 144 |
| 145 TEST_F(CCPrioritizedTextureTest, changeMemoryLimits) | 145 TEST_F(PrioritizedTextureTest, changeMemoryLimits) |
| 146 { | 146 { |
| 147 const size_t maxTextures = 8; | 147 const size_t maxTextures = 8; |
| 148 scoped_ptr<CCPrioritizedTextureManager> textureManager = createManager(maxTe
xtures); | 148 scoped_ptr<PrioritizedTextureManager> textureManager = createManager(maxText
ures); |
| 149 scoped_ptr<CCPrioritizedTexture> textures[maxTextures]; | 149 scoped_ptr<PrioritizedTexture> textures[maxTextures]; |
| 150 | 150 |
| 151 for (size_t i = 0; i < maxTextures; ++i) | 151 for (size_t i = 0; i < maxTextures; ++i) |
| 152 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); | 152 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); |
| 153 for (size_t i = 0; i < maxTextures; ++i) | 153 for (size_t i = 0; i < maxTextures; ++i) |
| 154 textures[i]->setRequestPriority(100 + i); | 154 textures[i]->setRequestPriority(100 + i); |
| 155 | 155 |
| 156 // Set max limit to 8 textures | 156 // Set max limit to 8 textures |
| 157 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(8)); | 157 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(8)); |
| 158 prioritizeTexturesAndBackings(textureManager.get()); | 158 prioritizeTexturesAndBackings(textureManager.get()); |
| 159 for (size_t i = 0; i < maxTextures; ++i) | 159 for (size_t i = 0; i < maxTextures; ++i) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 189 textureManager->reduceMemory(resourceProvider()); | 189 textureManager->reduceMemory(resourceProvider()); |
| 190 } | 190 } |
| 191 | 191 |
| 192 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryAboveCutoffBytes()); | 192 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryAboveCutoffBytes()); |
| 193 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); | 193 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); |
| 194 | 194 |
| 195 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; | 195 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; |
| 196 textureManager->clearAllMemory(resourceProvider()); | 196 textureManager->clearAllMemory(resourceProvider()); |
| 197 } | 197 } |
| 198 | 198 |
| 199 TEST_F(CCPrioritizedTextureTest, textureManagerPartialUpdateTextures) | 199 TEST_F(PrioritizedTextureTest, textureManagerPartialUpdateTextures) |
| 200 { | 200 { |
| 201 const size_t maxTextures = 4; | 201 const size_t maxTextures = 4; |
| 202 const size_t numTextures = 4; | 202 const size_t numTextures = 4; |
| 203 scoped_ptr<CCPrioritizedTextureManager> textureManager = createManager(maxTe
xtures); | 203 scoped_ptr<PrioritizedTextureManager> textureManager = createManager(maxText
ures); |
| 204 scoped_ptr<CCPrioritizedTexture> textures[numTextures]; | 204 scoped_ptr<PrioritizedTexture> textures[numTextures]; |
| 205 scoped_ptr<CCPrioritizedTexture> moreTextures[numTextures]; | 205 scoped_ptr<PrioritizedTexture> moreTextures[numTextures]; |
| 206 | 206 |
| 207 for (size_t i = 0; i < numTextures; ++i) { | 207 for (size_t i = 0; i < numTextures; ++i) { |
| 208 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); | 208 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); |
| 209 moreTextures[i] = textureManager->createTexture(m_textureSize, m_texture
Format); | 209 moreTextures[i] = textureManager->createTexture(m_textureSize, m_texture
Format); |
| 210 } | 210 } |
| 211 | 211 |
| 212 for (size_t i = 0; i < numTextures; ++i) | 212 for (size_t i = 0; i < numTextures; ++i) |
| 213 textures[i]->setRequestPriority(200 + i); | 213 textures[i]->setRequestPriority(200 + i); |
| 214 prioritizeTexturesAndBackings(textureManager.get()); | 214 prioritizeTexturesAndBackings(textureManager.get()); |
| 215 | 215 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 // Lower priority have been fully evicted. | 249 // Lower priority have been fully evicted. |
| 250 EXPECT_FALSE(textures[0]->haveBackingTexture()); | 250 EXPECT_FALSE(textures[0]->haveBackingTexture()); |
| 251 EXPECT_FALSE(textures[1]->haveBackingTexture()); | 251 EXPECT_FALSE(textures[1]->haveBackingTexture()); |
| 252 EXPECT_FALSE(textures[2]->haveBackingTexture()); | 252 EXPECT_FALSE(textures[2]->haveBackingTexture()); |
| 253 EXPECT_FALSE(textures[3]->haveBackingTexture()); | 253 EXPECT_FALSE(textures[3]->haveBackingTexture()); |
| 254 | 254 |
| 255 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; | 255 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; |
| 256 textureManager->clearAllMemory(resourceProvider()); | 256 textureManager->clearAllMemory(resourceProvider()); |
| 257 } | 257 } |
| 258 | 258 |
| 259 TEST_F(CCPrioritizedTextureTest, textureManagerPrioritiesAreEqual) | 259 TEST_F(PrioritizedTextureTest, textureManagerPrioritiesAreEqual) |
| 260 { | 260 { |
| 261 const size_t maxTextures = 16; | 261 const size_t maxTextures = 16; |
| 262 scoped_ptr<CCPrioritizedTextureManager> textureManager = createManager(maxTe
xtures); | 262 scoped_ptr<PrioritizedTextureManager> textureManager = createManager(maxText
ures); |
| 263 scoped_ptr<CCPrioritizedTexture> textures[maxTextures]; | 263 scoped_ptr<PrioritizedTexture> textures[maxTextures]; |
| 264 | 264 |
| 265 for (size_t i = 0; i < maxTextures; ++i) | 265 for (size_t i = 0; i < maxTextures; ++i) |
| 266 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); | 266 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); |
| 267 | 267 |
| 268 // All 16 textures have the same priority except 2 higher priority. | 268 // All 16 textures have the same priority except 2 higher priority. |
| 269 for (size_t i = 0; i < maxTextures; ++i) | 269 for (size_t i = 0; i < maxTextures; ++i) |
| 270 textures[i]->setRequestPriority(100); | 270 textures[i]->setRequestPriority(100); |
| 271 textures[0]->setRequestPriority(99); | 271 textures[0]->setRequestPriority(99); |
| 272 textures[1]->setRequestPriority(99); | 272 textures[1]->setRequestPriority(99); |
| 273 | 273 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 289 EXPECT_TRUE(validateTexture(textures[i], true)); | 289 EXPECT_TRUE(validateTexture(textures[i], true)); |
| 290 for (size_t i = 9; i < maxTextures; i++) | 290 for (size_t i = 9; i < maxTextures; i++) |
| 291 EXPECT_FALSE(validateTexture(textures[i], true)); | 291 EXPECT_FALSE(validateTexture(textures[i], true)); |
| 292 EXPECT_EQ(texturesMemorySize(8), textureManager->memoryAboveCutoffBytes()); | 292 EXPECT_EQ(texturesMemorySize(8), textureManager->memoryAboveCutoffBytes()); |
| 293 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); | 293 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); |
| 294 | 294 |
| 295 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; | 295 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; |
| 296 textureManager->clearAllMemory(resourceProvider()); | 296 textureManager->clearAllMemory(resourceProvider()); |
| 297 } | 297 } |
| 298 | 298 |
| 299 TEST_F(CCPrioritizedTextureTest, textureManagerDestroyedFirst) | 299 TEST_F(PrioritizedTextureTest, textureManagerDestroyedFirst) |
| 300 { | 300 { |
| 301 scoped_ptr<CCPrioritizedTextureManager> textureManager = createManager(1); | 301 scoped_ptr<PrioritizedTextureManager> textureManager = createManager(1); |
| 302 scoped_ptr<CCPrioritizedTexture> texture = textureManager->createTexture(m_t
extureSize, m_textureFormat); | 302 scoped_ptr<PrioritizedTexture> texture = textureManager->createTexture(m_tex
tureSize, m_textureFormat); |
| 303 | 303 |
| 304 // Texture is initially invalid, but it will become available. | 304 // Texture is initially invalid, but it will become available. |
| 305 EXPECT_FALSE(texture->haveBackingTexture()); | 305 EXPECT_FALSE(texture->haveBackingTexture()); |
| 306 | 306 |
| 307 texture->setRequestPriority(100); | 307 texture->setRequestPriority(100); |
| 308 prioritizeTexturesAndBackings(textureManager.get()); | 308 prioritizeTexturesAndBackings(textureManager.get()); |
| 309 | 309 |
| 310 EXPECT_TRUE(validateTexture(texture, false)); | 310 EXPECT_TRUE(validateTexture(texture, false)); |
| 311 EXPECT_TRUE(texture->canAcquireBackingTexture()); | 311 EXPECT_TRUE(texture->canAcquireBackingTexture()); |
| 312 EXPECT_TRUE(texture->haveBackingTexture()); | 312 EXPECT_TRUE(texture->haveBackingTexture()); |
| 313 | 313 |
| 314 { | 314 { |
| 315 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; | 315 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; |
| 316 textureManager->clearAllMemory(resourceProvider()); | 316 textureManager->clearAllMemory(resourceProvider()); |
| 317 } | 317 } |
| 318 textureManager.reset(); | 318 textureManager.reset(); |
| 319 | 319 |
| 320 EXPECT_FALSE(texture->canAcquireBackingTexture()); | 320 EXPECT_FALSE(texture->canAcquireBackingTexture()); |
| 321 EXPECT_FALSE(texture->haveBackingTexture()); | 321 EXPECT_FALSE(texture->haveBackingTexture()); |
| 322 } | 322 } |
| 323 | 323 |
| 324 TEST_F(CCPrioritizedTextureTest, textureMovedToNewManager) | 324 TEST_F(PrioritizedTextureTest, textureMovedToNewManager) |
| 325 { | 325 { |
| 326 scoped_ptr<CCPrioritizedTextureManager> textureManagerOne = createManager(1)
; | 326 scoped_ptr<PrioritizedTextureManager> textureManagerOne = createManager(1); |
| 327 scoped_ptr<CCPrioritizedTextureManager> textureManagerTwo = createManager(1)
; | 327 scoped_ptr<PrioritizedTextureManager> textureManagerTwo = createManager(1); |
| 328 scoped_ptr<CCPrioritizedTexture> texture = textureManagerOne->createTexture(
m_textureSize, m_textureFormat); | 328 scoped_ptr<PrioritizedTexture> texture = textureManagerOne->createTexture(m_
textureSize, m_textureFormat); |
| 329 | 329 |
| 330 // Texture is initially invalid, but it will become available. | 330 // Texture is initially invalid, but it will become available. |
| 331 EXPECT_FALSE(texture->haveBackingTexture()); | 331 EXPECT_FALSE(texture->haveBackingTexture()); |
| 332 | 332 |
| 333 texture->setRequestPriority(100); | 333 texture->setRequestPriority(100); |
| 334 prioritizeTexturesAndBackings(textureManagerOne.get()); | 334 prioritizeTexturesAndBackings(textureManagerOne.get()); |
| 335 | 335 |
| 336 EXPECT_TRUE(validateTexture(texture, false)); | 336 EXPECT_TRUE(validateTexture(texture, false)); |
| 337 EXPECT_TRUE(texture->canAcquireBackingTexture()); | 337 EXPECT_TRUE(texture->canAcquireBackingTexture()); |
| 338 EXPECT_TRUE(texture->haveBackingTexture()); | 338 EXPECT_TRUE(texture->haveBackingTexture()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 353 prioritizeTexturesAndBackings(textureManagerTwo.get()); | 353 prioritizeTexturesAndBackings(textureManagerTwo.get()); |
| 354 | 354 |
| 355 EXPECT_TRUE(validateTexture(texture, false)); | 355 EXPECT_TRUE(validateTexture(texture, false)); |
| 356 EXPECT_TRUE(texture->canAcquireBackingTexture()); | 356 EXPECT_TRUE(texture->canAcquireBackingTexture()); |
| 357 EXPECT_TRUE(texture->haveBackingTexture()); | 357 EXPECT_TRUE(texture->haveBackingTexture()); |
| 358 | 358 |
| 359 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; | 359 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; |
| 360 textureManagerTwo->clearAllMemory(resourceProvider()); | 360 textureManagerTwo->clearAllMemory(resourceProvider()); |
| 361 } | 361 } |
| 362 | 362 |
| 363 TEST_F(CCPrioritizedTextureTest, renderSurfacesReduceMemoryAvailableOutsideRootS
urface) | 363 TEST_F(PrioritizedTextureTest, renderSurfacesReduceMemoryAvailableOutsideRootSur
face) |
| 364 { | 364 { |
| 365 const size_t maxTextures = 8; | 365 const size_t maxTextures = 8; |
| 366 scoped_ptr<CCPrioritizedTextureManager> textureManager = createManager(maxTe
xtures); | 366 scoped_ptr<PrioritizedTextureManager> textureManager = createManager(maxText
ures); |
| 367 | 367 |
| 368 // Half of the memory is taken by surfaces (with high priority place-holder) | 368 // Half of the memory is taken by surfaces (with high priority place-holder) |
| 369 scoped_ptr<CCPrioritizedTexture> renderSurfacePlaceHolder = textureManager->
createTexture(m_textureSize, m_textureFormat); | 369 scoped_ptr<PrioritizedTexture> renderSurfacePlaceHolder = textureManager->cr
eateTexture(m_textureSize, m_textureFormat); |
| 370 renderSurfacePlaceHolder->setToSelfManagedMemoryPlaceholder(texturesMemorySi
ze(4)); | 370 renderSurfacePlaceHolder->setToSelfManagedMemoryPlaceholder(texturesMemorySi
ze(4)); |
| 371 renderSurfacePlaceHolder->setRequestPriority(CCPriorityCalculator::renderSur
facePriority()); | 371 renderSurfacePlaceHolder->setRequestPriority(PriorityCalculator::renderSurfa
cePriority()); |
| 372 | 372 |
| 373 // Create textures to fill our memory limit. | 373 // Create textures to fill our memory limit. |
| 374 scoped_ptr<CCPrioritizedTexture> textures[maxTextures]; | 374 scoped_ptr<PrioritizedTexture> textures[maxTextures]; |
| 375 | 375 |
| 376 for (size_t i = 0; i < maxTextures; ++i) | 376 for (size_t i = 0; i < maxTextures; ++i) |
| 377 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); | 377 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); |
| 378 | 378 |
| 379 // Set decreasing non-visible priorities outside root surface. | 379 // Set decreasing non-visible priorities outside root surface. |
| 380 for (size_t i = 0; i < maxTextures; ++i) | 380 for (size_t i = 0; i < maxTextures; ++i) |
| 381 textures[i]->setRequestPriority(100 + i); | 381 textures[i]->setRequestPriority(100 + i); |
| 382 | 382 |
| 383 // Only lower half should be available. | 383 // Only lower half should be available. |
| 384 prioritizeTexturesAndBackings(textureManager.get()); | 384 prioritizeTexturesAndBackings(textureManager.get()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 399 EXPECT_TRUE(validateTexture(textures[7], false)); | 399 EXPECT_TRUE(validateTexture(textures[7], false)); |
| 400 | 400 |
| 401 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryAboveCutoffBytes()); | 401 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryAboveCutoffBytes()); |
| 402 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryForSelfManagedTexture
s()); | 402 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryForSelfManagedTexture
s()); |
| 403 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); | 403 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); |
| 404 | 404 |
| 405 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; | 405 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; |
| 406 textureManager->clearAllMemory(resourceProvider()); | 406 textureManager->clearAllMemory(resourceProvider()); |
| 407 } | 407 } |
| 408 | 408 |
| 409 TEST_F(CCPrioritizedTextureTest, renderSurfacesReduceMemoryAvailableForRequestLa
te) | 409 TEST_F(PrioritizedTextureTest, renderSurfacesReduceMemoryAvailableForRequestLate
) |
| 410 { | 410 { |
| 411 const size_t maxTextures = 8; | 411 const size_t maxTextures = 8; |
| 412 scoped_ptr<CCPrioritizedTextureManager> textureManager = createManager(maxTe
xtures); | 412 scoped_ptr<PrioritizedTextureManager> textureManager = createManager(maxText
ures); |
| 413 | 413 |
| 414 // Half of the memory is taken by surfaces (with high priority place-holder) | 414 // Half of the memory is taken by surfaces (with high priority place-holder) |
| 415 scoped_ptr<CCPrioritizedTexture> renderSurfacePlaceHolder = textureManager->
createTexture(m_textureSize, m_textureFormat); | 415 scoped_ptr<PrioritizedTexture> renderSurfacePlaceHolder = textureManager->cr
eateTexture(m_textureSize, m_textureFormat); |
| 416 renderSurfacePlaceHolder->setToSelfManagedMemoryPlaceholder(texturesMemorySi
ze(4)); | 416 renderSurfacePlaceHolder->setToSelfManagedMemoryPlaceholder(texturesMemorySi
ze(4)); |
| 417 renderSurfacePlaceHolder->setRequestPriority(CCPriorityCalculator::renderSur
facePriority()); | 417 renderSurfacePlaceHolder->setRequestPriority(PriorityCalculator::renderSurfa
cePriority()); |
| 418 | 418 |
| 419 // Create textures to fill our memory limit. | 419 // Create textures to fill our memory limit. |
| 420 scoped_ptr<CCPrioritizedTexture> textures[maxTextures]; | 420 scoped_ptr<PrioritizedTexture> textures[maxTextures]; |
| 421 | 421 |
| 422 for (size_t i = 0; i < maxTextures; ++i) | 422 for (size_t i = 0; i < maxTextures; ++i) |
| 423 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); | 423 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); |
| 424 | 424 |
| 425 // Set equal priorities. | 425 // Set equal priorities. |
| 426 for (size_t i = 0; i < maxTextures; ++i) | 426 for (size_t i = 0; i < maxTextures; ++i) |
| 427 textures[i]->setRequestPriority(100); | 427 textures[i]->setRequestPriority(100); |
| 428 | 428 |
| 429 // The first four to be requested late will be available. | 429 // The first four to be requested late will be available. |
| 430 prioritizeTexturesAndBackings(textureManager.get()); | 430 prioritizeTexturesAndBackings(textureManager.get()); |
| 431 for (unsigned i = 0; i < maxTextures; ++i) | 431 for (unsigned i = 0; i < maxTextures; ++i) |
| 432 EXPECT_FALSE(validateTexture(textures[i], false)); | 432 EXPECT_FALSE(validateTexture(textures[i], false)); |
| 433 for (unsigned i = 0; i < maxTextures; i += 2) | 433 for (unsigned i = 0; i < maxTextures; i += 2) |
| 434 EXPECT_TRUE(validateTexture(textures[i], true)); | 434 EXPECT_TRUE(validateTexture(textures[i], true)); |
| 435 for (unsigned i = 1; i < maxTextures; i += 2) | 435 for (unsigned i = 1; i < maxTextures; i += 2) |
| 436 EXPECT_FALSE(validateTexture(textures[i], true)); | 436 EXPECT_FALSE(validateTexture(textures[i], true)); |
| 437 | 437 |
| 438 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryAboveCutoffBytes()); | 438 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryAboveCutoffBytes()); |
| 439 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryForSelfManagedTexture
s()); | 439 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryForSelfManagedTexture
s()); |
| 440 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); | 440 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); |
| 441 | 441 |
| 442 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; | 442 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; |
| 443 textureManager->clearAllMemory(resourceProvider()); | 443 textureManager->clearAllMemory(resourceProvider()); |
| 444 } | 444 } |
| 445 | 445 |
| 446 TEST_F(CCPrioritizedTextureTest, whenRenderSurfaceNotAvailableTexturesAlsoNotAva
ilable) | 446 TEST_F(PrioritizedTextureTest, whenRenderSurfaceNotAvailableTexturesAlsoNotAvail
able) |
| 447 { | 447 { |
| 448 const size_t maxTextures = 8; | 448 const size_t maxTextures = 8; |
| 449 scoped_ptr<CCPrioritizedTextureManager> textureManager = createManager(maxTe
xtures); | 449 scoped_ptr<PrioritizedTextureManager> textureManager = createManager(maxText
ures); |
| 450 | 450 |
| 451 // Half of the memory is taken by surfaces (with high priority place-holder) | 451 // Half of the memory is taken by surfaces (with high priority place-holder) |
| 452 scoped_ptr<CCPrioritizedTexture> renderSurfacePlaceHolder = textureManager->
createTexture(m_textureSize, m_textureFormat); | 452 scoped_ptr<PrioritizedTexture> renderSurfacePlaceHolder = textureManager->cr
eateTexture(m_textureSize, m_textureFormat); |
| 453 renderSurfacePlaceHolder->setToSelfManagedMemoryPlaceholder(texturesMemorySi
ze(4)); | 453 renderSurfacePlaceHolder->setToSelfManagedMemoryPlaceholder(texturesMemorySi
ze(4)); |
| 454 renderSurfacePlaceHolder->setRequestPriority(CCPriorityCalculator::renderSur
facePriority()); | 454 renderSurfacePlaceHolder->setRequestPriority(PriorityCalculator::renderSurfa
cePriority()); |
| 455 | 455 |
| 456 // Create textures to fill our memory limit. | 456 // Create textures to fill our memory limit. |
| 457 scoped_ptr<CCPrioritizedTexture> textures[maxTextures]; | 457 scoped_ptr<PrioritizedTexture> textures[maxTextures]; |
| 458 | 458 |
| 459 for (size_t i = 0; i < maxTextures; ++i) | 459 for (size_t i = 0; i < maxTextures; ++i) |
| 460 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); | 460 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); |
| 461 | 461 |
| 462 // Set 6 visible textures in the root surface, and 2 in a child surface. | 462 // Set 6 visible textures in the root surface, and 2 in a child surface. |
| 463 for (size_t i = 0; i < 6; ++i) | 463 for (size_t i = 0; i < 6; ++i) |
| 464 textures[i]->setRequestPriority(CCPriorityCalculator::visiblePriority(tr
ue)); | 464 textures[i]->setRequestPriority(PriorityCalculator::visiblePriority(true
)); |
| 465 for (size_t i = 6; i < 8; ++i) | 465 for (size_t i = 6; i < 8; ++i) |
| 466 textures[i]->setRequestPriority(CCPriorityCalculator::visiblePriority(fa
lse)); | 466 textures[i]->setRequestPriority(PriorityCalculator::visiblePriority(fals
e)); |
| 467 | 467 |
| 468 prioritizeTexturesAndBackings(textureManager.get()); | 468 prioritizeTexturesAndBackings(textureManager.get()); |
| 469 | 469 |
| 470 // Unable to requestLate textures in the child surface. | 470 // Unable to requestLate textures in the child surface. |
| 471 EXPECT_FALSE(validateTexture(textures[6], true)); | 471 EXPECT_FALSE(validateTexture(textures[6], true)); |
| 472 EXPECT_FALSE(validateTexture(textures[7], true)); | 472 EXPECT_FALSE(validateTexture(textures[7], true)); |
| 473 | 473 |
| 474 // Root surface textures are valid. | 474 // Root surface textures are valid. |
| 475 for (size_t i = 0; i < 6; ++i) | 475 for (size_t i = 0; i < 6; ++i) |
| 476 EXPECT_TRUE(validateTexture(textures[i], false)); | 476 EXPECT_TRUE(validateTexture(textures[i], false)); |
| 477 | 477 |
| 478 EXPECT_EQ(texturesMemorySize(6), textureManager->memoryAboveCutoffBytes()); | 478 EXPECT_EQ(texturesMemorySize(6), textureManager->memoryAboveCutoffBytes()); |
| 479 EXPECT_EQ(texturesMemorySize(2), textureManager->memoryForSelfManagedTexture
s()); | 479 EXPECT_EQ(texturesMemorySize(2), textureManager->memoryForSelfManagedTexture
s()); |
| 480 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); | 480 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); |
| 481 | 481 |
| 482 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; | 482 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; |
| 483 textureManager->clearAllMemory(resourceProvider()); | 483 textureManager->clearAllMemory(resourceProvider()); |
| 484 } | 484 } |
| 485 | 485 |
| 486 TEST_F(CCPrioritizedTextureTest, requestLateBackingsSorting) | 486 TEST_F(PrioritizedTextureTest, requestLateBackingsSorting) |
| 487 { | 487 { |
| 488 const size_t maxTextures = 8; | 488 const size_t maxTextures = 8; |
| 489 scoped_ptr<CCPrioritizedTextureManager> textureManager = createManager(maxTe
xtures); | 489 scoped_ptr<PrioritizedTextureManager> textureManager = createManager(maxText
ures); |
| 490 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(maxTextures)); | 490 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(maxTextures)); |
| 491 | 491 |
| 492 // Create textures to fill our memory limit. | 492 // Create textures to fill our memory limit. |
| 493 scoped_ptr<CCPrioritizedTexture> textures[maxTextures]; | 493 scoped_ptr<PrioritizedTexture> textures[maxTextures]; |
| 494 for (size_t i = 0; i < maxTextures; ++i) | 494 for (size_t i = 0; i < maxTextures; ++i) |
| 495 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); | 495 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); |
| 496 | 496 |
| 497 // Set equal priorities, and allocate backings for all textures. | 497 // Set equal priorities, and allocate backings for all textures. |
| 498 for (size_t i = 0; i < maxTextures; ++i) | 498 for (size_t i = 0; i < maxTextures; ++i) |
| 499 textures[i]->setRequestPriority(100); | 499 textures[i]->setRequestPriority(100); |
| 500 prioritizeTexturesAndBackings(textureManager.get()); | 500 prioritizeTexturesAndBackings(textureManager.get()); |
| 501 for (unsigned i = 0; i < maxTextures; ++i) | 501 for (unsigned i = 0; i < maxTextures; ++i) |
| 502 EXPECT_TRUE(validateTexture(textures[i], false)); | 502 EXPECT_TRUE(validateTexture(textures[i], false)); |
| 503 | 503 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 524 // Make sure that only the requestLate textures are above the priority cutof
f | 524 // Make sure that only the requestLate textures are above the priority cutof
f |
| 525 for (size_t i = 0; i < maxTextures; i += 2) | 525 for (size_t i = 0; i < maxTextures; i += 2) |
| 526 EXPECT_TRUE(textureBackingIsAbovePriorityCutoff(textures[i].get())); | 526 EXPECT_TRUE(textureBackingIsAbovePriorityCutoff(textures[i].get())); |
| 527 for (size_t i = 1; i < maxTextures; i += 2) | 527 for (size_t i = 1; i < maxTextures; i += 2) |
| 528 EXPECT_FALSE(textureBackingIsAbovePriorityCutoff(textures[i].get())); | 528 EXPECT_FALSE(textureBackingIsAbovePriorityCutoff(textures[i].get())); |
| 529 | 529 |
| 530 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; | 530 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; |
| 531 textureManager->clearAllMemory(resourceProvider()); | 531 textureManager->clearAllMemory(resourceProvider()); |
| 532 } | 532 } |
| 533 | 533 |
| 534 TEST_F(CCPrioritizedTextureTest, clearUploadsToEvictedResources) | 534 TEST_F(PrioritizedTextureTest, clearUploadsToEvictedResources) |
| 535 { | 535 { |
| 536 const size_t maxTextures = 4; | 536 const size_t maxTextures = 4; |
| 537 scoped_ptr<CCPrioritizedTextureManager> textureManager = | 537 scoped_ptr<PrioritizedTextureManager> textureManager = |
| 538 createManager(maxTextures); | 538 createManager(maxTextures); |
| 539 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(maxTextures)); | 539 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(maxTextures)); |
| 540 | 540 |
| 541 // Create textures to fill our memory limit. | 541 // Create textures to fill our memory limit. |
| 542 scoped_ptr<CCPrioritizedTexture> textures[maxTextures]; | 542 scoped_ptr<PrioritizedTexture> textures[maxTextures]; |
| 543 | 543 |
| 544 for (size_t i = 0; i < maxTextures; ++i) | 544 for (size_t i = 0; i < maxTextures; ++i) |
| 545 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); | 545 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); |
| 546 | 546 |
| 547 // Set equal priorities, and allocate backings for all textures. | 547 // Set equal priorities, and allocate backings for all textures. |
| 548 for (size_t i = 0; i < maxTextures; ++i) | 548 for (size_t i = 0; i < maxTextures; ++i) |
| 549 textures[i]->setRequestPriority(100); | 549 textures[i]->setRequestPriority(100); |
| 550 prioritizeTexturesAndBackings(textureManager.get()); | 550 prioritizeTexturesAndBackings(textureManager.get()); |
| 551 for (unsigned i = 0; i < maxTextures; ++i) | 551 for (unsigned i = 0; i < maxTextures; ++i) |
| 552 EXPECT_TRUE(validateTexture(textures[i], false)); | 552 EXPECT_TRUE(validateTexture(textures[i], false)); |
| 553 | 553 |
| 554 CCTextureUpdateQueue queue; | 554 TextureUpdateQueue queue; |
| 555 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; | 555 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; |
| 556 for (size_t i = 0; i < maxTextures; ++i) { | 556 for (size_t i = 0; i < maxTextures; ++i) { |
| 557 const TextureUploader::Parameters upload = { textures[i].get() }; | 557 const TextureUploader::Parameters upload = { textures[i].get() }; |
| 558 queue.appendFullUpload(upload); | 558 queue.appendFullUpload(upload); |
| 559 } | 559 } |
| 560 | 560 |
| 561 // Make sure that we have backings for all of the textures. | 561 // Make sure that we have backings for all of the textures. |
| 562 for (size_t i = 0; i < maxTextures; ++i) | 562 for (size_t i = 0; i < maxTextures; ++i) |
| 563 EXPECT_TRUE(textures[i]->haveBackingTexture()); | 563 EXPECT_TRUE(textures[i]->haveBackingTexture()); |
| 564 | 564 |
| 565 queue.clearUploadsToEvictedResources(); | 565 queue.clearUploadsToEvictedResources(); |
| 566 EXPECT_EQ(4, queue.fullUploadSize()); | 566 EXPECT_EQ(4, queue.fullUploadSize()); |
| 567 | 567 |
| 568 textureManager->reduceMemoryOnImplThread( | 568 textureManager->reduceMemoryOnImplThread( |
| 569 texturesMemorySize(1), resourceProvider()); | 569 texturesMemorySize(1), resourceProvider()); |
| 570 queue.clearUploadsToEvictedResources(); | 570 queue.clearUploadsToEvictedResources(); |
| 571 EXPECT_EQ(1, queue.fullUploadSize()); | 571 EXPECT_EQ(1, queue.fullUploadSize()); |
| 572 | 572 |
| 573 textureManager->reduceMemoryOnImplThread(0, resourceProvider()); | 573 textureManager->reduceMemoryOnImplThread(0, resourceProvider()); |
| 574 queue.clearUploadsToEvictedResources(); | 574 queue.clearUploadsToEvictedResources(); |
| 575 EXPECT_EQ(0, queue.fullUploadSize()); | 575 EXPECT_EQ(0, queue.fullUploadSize()); |
| 576 | 576 |
| 577 } | 577 } |
| 578 | 578 |
| 579 } // namespace | 579 } // namespace |
| OLD | NEW |