| 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 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 { | 36 { |
| 37 DebugScopedSetImplThread implThread; | 37 DebugScopedSetImplThread implThread; |
| 38 m_resourceProvider.clear(); | 38 m_resourceProvider.clear(); |
| 39 } | 39 } |
| 40 | 40 |
| 41 size_t texturesMemorySize(size_t textureCount) | 41 size_t texturesMemorySize(size_t textureCount) |
| 42 { | 42 { |
| 43 return CCTexture::memorySizeBytes(m_textureSize, m_textureFormat) * text
ureCount; | 43 return CCTexture::memorySizeBytes(m_textureSize, m_textureFormat) * text
ureCount; |
| 44 } | 44 } |
| 45 | 45 |
| 46 PassOwnPtr<CCPrioritizedTextureManager> createManager(size_t maxTextures) | 46 scoped_ptr<CCPrioritizedTextureManager> createManager(size_t maxTextures) |
| 47 { | 47 { |
| 48 return CCPrioritizedTextureManager::create(texturesMemorySize(maxTexture
s), 1024, 0); | 48 return CCPrioritizedTextureManager::create(texturesMemorySize(maxTexture
s), 1024, 0); |
| 49 } | 49 } |
| 50 | 50 |
| 51 bool validateTexture(OwnPtr<CCPrioritizedTexture>& texture, bool requestLate
) | 51 bool validateTexture(scoped_ptr<CCPrioritizedTexture>& texture, bool request
Late) |
| 52 { | 52 { |
| 53 textureManagerAssertInvariants(texture->textureManager()); | 53 textureManagerAssertInvariants(texture->textureManager()); |
| 54 if (requestLate) | 54 if (requestLate) |
| 55 texture->requestLate(); | 55 texture->requestLate(); |
| 56 textureManagerAssertInvariants(texture->textureManager()); | 56 textureManagerAssertInvariants(texture->textureManager()); |
| 57 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; | 57 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; |
| 58 bool success = texture->canAcquireBackingTexture(); | 58 bool success = texture->canAcquireBackingTexture(); |
| 59 if (success) | 59 if (success) |
| 60 texture->acquireBackingTexture(resourceProvider()); | 60 texture->acquireBackingTexture(resourceProvider()); |
| 61 return success; | 61 return success; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 OwnPtr<CCResourceProvider> m_resourceProvider; | 99 OwnPtr<CCResourceProvider> m_resourceProvider; |
| 100 }; | 100 }; |
| 101 | 101 |
| 102 } | 102 } |
| 103 | 103 |
| 104 namespace { | 104 namespace { |
| 105 | 105 |
| 106 TEST_F(CCPrioritizedTextureTest, requestTextureExceedingMaxLimit) | 106 TEST_F(CCPrioritizedTextureTest, requestTextureExceedingMaxLimit) |
| 107 { | 107 { |
| 108 const size_t maxTextures = 8; | 108 const size_t maxTextures = 8; |
| 109 OwnPtr<CCPrioritizedTextureManager> textureManager = createManager(maxTextur
es); | 109 scoped_ptr<CCPrioritizedTextureManager> textureManager = createManager(maxTe
xtures); |
| 110 | 110 |
| 111 // Create textures for double our memory limit. | 111 // Create textures for double our memory limit. |
| 112 OwnPtr<CCPrioritizedTexture> textures[maxTextures*2]; | 112 scoped_ptr<CCPrioritizedTexture> textures[maxTextures*2]; |
| 113 | 113 |
| 114 for (size_t i = 0; i < maxTextures*2; ++i) | 114 for (size_t i = 0; i < maxTextures*2; ++i) |
| 115 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); | 115 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); |
| 116 | 116 |
| 117 // Set decreasing priorities | 117 // Set decreasing priorities |
| 118 for (size_t i = 0; i < maxTextures*2; ++i) | 118 for (size_t i = 0; i < maxTextures*2; ++i) |
| 119 textures[i]->setRequestPriority(100 + i); | 119 textures[i]->setRequestPriority(100 + i); |
| 120 | 120 |
| 121 // Only lower half should be available. | 121 // Only lower half should be available. |
| 122 prioritizeTexturesAndBackings(textureManager.get()); | 122 prioritizeTexturesAndBackings(textureManager.get()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 139 EXPECT_EQ(texturesMemorySize(maxTextures), textureManager->memoryAboveCutoff
Bytes()); | 139 EXPECT_EQ(texturesMemorySize(maxTextures), textureManager->memoryAboveCutoff
Bytes()); |
| 140 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); | 140 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); |
| 141 | 141 |
| 142 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; | 142 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; |
| 143 textureManager->clearAllMemory(resourceProvider()); | 143 textureManager->clearAllMemory(resourceProvider()); |
| 144 } | 144 } |
| 145 | 145 |
| 146 TEST_F(CCPrioritizedTextureTest, changeMemoryLimits) | 146 TEST_F(CCPrioritizedTextureTest, changeMemoryLimits) |
| 147 { | 147 { |
| 148 const size_t maxTextures = 8; | 148 const size_t maxTextures = 8; |
| 149 OwnPtr<CCPrioritizedTextureManager> textureManager = createManager(maxTextur
es); | 149 scoped_ptr<CCPrioritizedTextureManager> textureManager = createManager(maxTe
xtures); |
| 150 OwnPtr<CCPrioritizedTexture> textures[maxTextures]; | 150 scoped_ptr<CCPrioritizedTexture> textures[maxTextures]; |
| 151 | 151 |
| 152 for (size_t i = 0; i < maxTextures; ++i) | 152 for (size_t i = 0; i < maxTextures; ++i) |
| 153 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); | 153 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); |
| 154 for (size_t i = 0; i < maxTextures; ++i) | 154 for (size_t i = 0; i < maxTextures; ++i) |
| 155 textures[i]->setRequestPriority(100 + i); | 155 textures[i]->setRequestPriority(100 + i); |
| 156 | 156 |
| 157 // Set max limit to 8 textures | 157 // Set max limit to 8 textures |
| 158 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(8)); | 158 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(8)); |
| 159 prioritizeTexturesAndBackings(textureManager.get()); | 159 prioritizeTexturesAndBackings(textureManager.get()); |
| 160 for (size_t i = 0; i < maxTextures; ++i) | 160 for (size_t i = 0; i < maxTextures; ++i) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); | 194 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); |
| 195 | 195 |
| 196 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; | 196 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; |
| 197 textureManager->clearAllMemory(resourceProvider()); | 197 textureManager->clearAllMemory(resourceProvider()); |
| 198 } | 198 } |
| 199 | 199 |
| 200 TEST_F(CCPrioritizedTextureTest, textureManagerPartialUpdateTextures) | 200 TEST_F(CCPrioritizedTextureTest, textureManagerPartialUpdateTextures) |
| 201 { | 201 { |
| 202 const size_t maxTextures = 4; | 202 const size_t maxTextures = 4; |
| 203 const size_t numTextures = 4; | 203 const size_t numTextures = 4; |
| 204 OwnPtr<CCPrioritizedTextureManager> textureManager = createManager(maxTextur
es); | 204 scoped_ptr<CCPrioritizedTextureManager> textureManager = createManager(maxTe
xtures); |
| 205 OwnPtr<CCPrioritizedTexture> textures[numTextures]; | 205 scoped_ptr<CCPrioritizedTexture> textures[numTextures]; |
| 206 OwnPtr<CCPrioritizedTexture> moreTextures[numTextures]; | 206 scoped_ptr<CCPrioritizedTexture> moreTextures[numTextures]; |
| 207 | 207 |
| 208 for (size_t i = 0; i < numTextures; ++i) { | 208 for (size_t i = 0; i < numTextures; ++i) { |
| 209 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); | 209 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); |
| 210 moreTextures[i] = textureManager->createTexture(m_textureSize, m_texture
Format); | 210 moreTextures[i] = textureManager->createTexture(m_textureSize, m_texture
Format); |
| 211 } | 211 } |
| 212 | 212 |
| 213 for (size_t i = 0; i < numTextures; ++i) | 213 for (size_t i = 0; i < numTextures; ++i) |
| 214 textures[i]->setRequestPriority(200 + i); | 214 textures[i]->setRequestPriority(200 + i); |
| 215 prioritizeTexturesAndBackings(textureManager.get()); | 215 prioritizeTexturesAndBackings(textureManager.get()); |
| 216 | 216 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 EXPECT_FALSE(textures[2]->haveBackingTexture()); | 253 EXPECT_FALSE(textures[2]->haveBackingTexture()); |
| 254 EXPECT_FALSE(textures[3]->haveBackingTexture()); | 254 EXPECT_FALSE(textures[3]->haveBackingTexture()); |
| 255 | 255 |
| 256 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; | 256 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; |
| 257 textureManager->clearAllMemory(resourceProvider()); | 257 textureManager->clearAllMemory(resourceProvider()); |
| 258 } | 258 } |
| 259 | 259 |
| 260 TEST_F(CCPrioritizedTextureTest, textureManagerPrioritiesAreEqual) | 260 TEST_F(CCPrioritizedTextureTest, textureManagerPrioritiesAreEqual) |
| 261 { | 261 { |
| 262 const size_t maxTextures = 16; | 262 const size_t maxTextures = 16; |
| 263 OwnPtr<CCPrioritizedTextureManager> textureManager = createManager(maxTextur
es); | 263 scoped_ptr<CCPrioritizedTextureManager> textureManager = createManager(maxTe
xtures); |
| 264 OwnPtr<CCPrioritizedTexture> textures[maxTextures]; | 264 scoped_ptr<CCPrioritizedTexture> textures[maxTextures]; |
| 265 | 265 |
| 266 for (size_t i = 0; i < maxTextures; ++i) | 266 for (size_t i = 0; i < maxTextures; ++i) |
| 267 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); | 267 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); |
| 268 | 268 |
| 269 // All 16 textures have the same priority except 2 higher priority. | 269 // All 16 textures have the same priority except 2 higher priority. |
| 270 for (size_t i = 0; i < maxTextures; ++i) | 270 for (size_t i = 0; i < maxTextures; ++i) |
| 271 textures[i]->setRequestPriority(100); | 271 textures[i]->setRequestPriority(100); |
| 272 textures[0]->setRequestPriority(99); | 272 textures[0]->setRequestPriority(99); |
| 273 textures[1]->setRequestPriority(99); | 273 textures[1]->setRequestPriority(99); |
| 274 | 274 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 292 EXPECT_FALSE(validateTexture(textures[i], true)); | 292 EXPECT_FALSE(validateTexture(textures[i], true)); |
| 293 EXPECT_EQ(texturesMemorySize(8), textureManager->memoryAboveCutoffBytes()); | 293 EXPECT_EQ(texturesMemorySize(8), textureManager->memoryAboveCutoffBytes()); |
| 294 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); | 294 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); |
| 295 | 295 |
| 296 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; | 296 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; |
| 297 textureManager->clearAllMemory(resourceProvider()); | 297 textureManager->clearAllMemory(resourceProvider()); |
| 298 } | 298 } |
| 299 | 299 |
| 300 TEST_F(CCPrioritizedTextureTest, textureManagerDestroyedFirst) | 300 TEST_F(CCPrioritizedTextureTest, textureManagerDestroyedFirst) |
| 301 { | 301 { |
| 302 OwnPtr<CCPrioritizedTextureManager> textureManager = createManager(1); | 302 scoped_ptr<CCPrioritizedTextureManager> textureManager = createManager(1); |
| 303 OwnPtr<CCPrioritizedTexture> texture = textureManager->createTexture(m_textu
reSize, m_textureFormat); | 303 scoped_ptr<CCPrioritizedTexture> texture = textureManager->createTexture(m_t
extureSize, m_textureFormat); |
| 304 | 304 |
| 305 // Texture is initially invalid, but it will become available. | 305 // Texture is initially invalid, but it will become available. |
| 306 EXPECT_FALSE(texture->haveBackingTexture()); | 306 EXPECT_FALSE(texture->haveBackingTexture()); |
| 307 | 307 |
| 308 texture->setRequestPriority(100); | 308 texture->setRequestPriority(100); |
| 309 prioritizeTexturesAndBackings(textureManager.get()); | 309 prioritizeTexturesAndBackings(textureManager.get()); |
| 310 | 310 |
| 311 EXPECT_TRUE(validateTexture(texture, false)); | 311 EXPECT_TRUE(validateTexture(texture, false)); |
| 312 EXPECT_TRUE(texture->canAcquireBackingTexture()); | 312 EXPECT_TRUE(texture->canAcquireBackingTexture()); |
| 313 EXPECT_TRUE(texture->haveBackingTexture()); | 313 EXPECT_TRUE(texture->haveBackingTexture()); |
| 314 | 314 |
| 315 { | 315 { |
| 316 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; | 316 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; |
| 317 textureManager->clearAllMemory(resourceProvider()); | 317 textureManager->clearAllMemory(resourceProvider()); |
| 318 } | 318 } |
| 319 textureManager.clear(); | 319 textureManager.reset(); |
| 320 | 320 |
| 321 EXPECT_FALSE(texture->canAcquireBackingTexture()); | 321 EXPECT_FALSE(texture->canAcquireBackingTexture()); |
| 322 EXPECT_FALSE(texture->haveBackingTexture()); | 322 EXPECT_FALSE(texture->haveBackingTexture()); |
| 323 } | 323 } |
| 324 | 324 |
| 325 TEST_F(CCPrioritizedTextureTest, textureMovedToNewManager) | 325 TEST_F(CCPrioritizedTextureTest, textureMovedToNewManager) |
| 326 { | 326 { |
| 327 OwnPtr<CCPrioritizedTextureManager> textureManagerOne = createManager(1); | 327 scoped_ptr<CCPrioritizedTextureManager> textureManagerOne = createManager(1)
; |
| 328 OwnPtr<CCPrioritizedTextureManager> textureManagerTwo = createManager(1); | 328 scoped_ptr<CCPrioritizedTextureManager> textureManagerTwo = createManager(1)
; |
| 329 OwnPtr<CCPrioritizedTexture> texture = textureManagerOne->createTexture(m_te
xtureSize, m_textureFormat); | 329 scoped_ptr<CCPrioritizedTexture> texture = textureManagerOne->createTexture(
m_textureSize, m_textureFormat); |
| 330 | 330 |
| 331 // Texture is initially invalid, but it will become available. | 331 // Texture is initially invalid, but it will become available. |
| 332 EXPECT_FALSE(texture->haveBackingTexture()); | 332 EXPECT_FALSE(texture->haveBackingTexture()); |
| 333 | 333 |
| 334 texture->setRequestPriority(100); | 334 texture->setRequestPriority(100); |
| 335 prioritizeTexturesAndBackings(textureManagerOne.get()); | 335 prioritizeTexturesAndBackings(textureManagerOne.get()); |
| 336 | 336 |
| 337 EXPECT_TRUE(validateTexture(texture, false)); | 337 EXPECT_TRUE(validateTexture(texture, false)); |
| 338 EXPECT_TRUE(texture->canAcquireBackingTexture()); | 338 EXPECT_TRUE(texture->canAcquireBackingTexture()); |
| 339 EXPECT_TRUE(texture->haveBackingTexture()); | 339 EXPECT_TRUE(texture->haveBackingTexture()); |
| 340 | 340 |
| 341 texture->setTextureManager(0); | 341 texture->setTextureManager(0); |
| 342 | 342 |
| 343 { | 343 { |
| 344 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; | 344 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; |
| 345 textureManagerOne->clearAllMemory(resourceProvider()); | 345 textureManagerOne->clearAllMemory(resourceProvider()); |
| 346 } | 346 } |
| 347 textureManagerOne.clear(); | 347 textureManagerOne.reset(); |
| 348 | 348 |
| 349 EXPECT_FALSE(texture->canAcquireBackingTexture()); | 349 EXPECT_FALSE(texture->canAcquireBackingTexture()); |
| 350 EXPECT_FALSE(texture->haveBackingTexture()); | 350 EXPECT_FALSE(texture->haveBackingTexture()); |
| 351 | 351 |
| 352 texture->setTextureManager(textureManagerTwo.get()); | 352 texture->setTextureManager(textureManagerTwo.get()); |
| 353 | 353 |
| 354 prioritizeTexturesAndBackings(textureManagerTwo.get()); | 354 prioritizeTexturesAndBackings(textureManagerTwo.get()); |
| 355 | 355 |
| 356 EXPECT_TRUE(validateTexture(texture, false)); | 356 EXPECT_TRUE(validateTexture(texture, false)); |
| 357 EXPECT_TRUE(texture->canAcquireBackingTexture()); | 357 EXPECT_TRUE(texture->canAcquireBackingTexture()); |
| 358 EXPECT_TRUE(texture->haveBackingTexture()); | 358 EXPECT_TRUE(texture->haveBackingTexture()); |
| 359 | 359 |
| 360 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; | 360 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; |
| 361 textureManagerTwo->clearAllMemory(resourceProvider()); | 361 textureManagerTwo->clearAllMemory(resourceProvider()); |
| 362 } | 362 } |
| 363 | 363 |
| 364 TEST_F(CCPrioritizedTextureTest, renderSurfacesReduceMemoryAvailableOutsideRootS
urface) | 364 TEST_F(CCPrioritizedTextureTest, renderSurfacesReduceMemoryAvailableOutsideRootS
urface) |
| 365 { | 365 { |
| 366 const size_t maxTextures = 8; | 366 const size_t maxTextures = 8; |
| 367 OwnPtr<CCPrioritizedTextureManager> textureManager = createManager(maxTextur
es); | 367 scoped_ptr<CCPrioritizedTextureManager> textureManager = createManager(maxTe
xtures); |
| 368 | 368 |
| 369 // Half of the memory is taken by surfaces (with high priority place-holder) | 369 // Half of the memory is taken by surfaces (with high priority place-holder) |
| 370 OwnPtr<CCPrioritizedTexture> renderSurfacePlaceHolder = textureManager->crea
teTexture(m_textureSize, m_textureFormat); | 370 scoped_ptr<CCPrioritizedTexture> renderSurfacePlaceHolder = textureManager->
createTexture(m_textureSize, m_textureFormat); |
| 371 renderSurfacePlaceHolder->setToSelfManagedMemoryPlaceholder(texturesMemorySi
ze(4)); | 371 renderSurfacePlaceHolder->setToSelfManagedMemoryPlaceholder(texturesMemorySi
ze(4)); |
| 372 renderSurfacePlaceHolder->setRequestPriority(CCPriorityCalculator::renderSur
facePriority()); | 372 renderSurfacePlaceHolder->setRequestPriority(CCPriorityCalculator::renderSur
facePriority()); |
| 373 | 373 |
| 374 // Create textures to fill our memory limit. | 374 // Create textures to fill our memory limit. |
| 375 OwnPtr<CCPrioritizedTexture> textures[maxTextures]; | 375 scoped_ptr<CCPrioritizedTexture> textures[maxTextures]; |
| 376 | 376 |
| 377 for (size_t i = 0; i < maxTextures; ++i) | 377 for (size_t i = 0; i < maxTextures; ++i) |
| 378 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); | 378 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); |
| 379 | 379 |
| 380 // Set decreasing non-visible priorities outside root surface. | 380 // Set decreasing non-visible priorities outside root surface. |
| 381 for (size_t i = 0; i < maxTextures; ++i) | 381 for (size_t i = 0; i < maxTextures; ++i) |
| 382 textures[i]->setRequestPriority(100 + i); | 382 textures[i]->setRequestPriority(100 + i); |
| 383 | 383 |
| 384 // Only lower half should be available. | 384 // Only lower half should be available. |
| 385 prioritizeTexturesAndBackings(textureManager.get()); | 385 prioritizeTexturesAndBackings(textureManager.get()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 403 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryForSelfManagedTexture
s()); | 403 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryForSelfManagedTexture
s()); |
| 404 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); | 404 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); |
| 405 | 405 |
| 406 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; | 406 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; |
| 407 textureManager->clearAllMemory(resourceProvider()); | 407 textureManager->clearAllMemory(resourceProvider()); |
| 408 } | 408 } |
| 409 | 409 |
| 410 TEST_F(CCPrioritizedTextureTest, renderSurfacesReduceMemoryAvailableForRequestLa
te) | 410 TEST_F(CCPrioritizedTextureTest, renderSurfacesReduceMemoryAvailableForRequestLa
te) |
| 411 { | 411 { |
| 412 const size_t maxTextures = 8; | 412 const size_t maxTextures = 8; |
| 413 OwnPtr<CCPrioritizedTextureManager> textureManager = createManager(maxTextur
es); | 413 scoped_ptr<CCPrioritizedTextureManager> textureManager = createManager(maxTe
xtures); |
| 414 | 414 |
| 415 // Half of the memory is taken by surfaces (with high priority place-holder) | 415 // Half of the memory is taken by surfaces (with high priority place-holder) |
| 416 OwnPtr<CCPrioritizedTexture> renderSurfacePlaceHolder = textureManager->crea
teTexture(m_textureSize, m_textureFormat); | 416 scoped_ptr<CCPrioritizedTexture> renderSurfacePlaceHolder = textureManager->
createTexture(m_textureSize, m_textureFormat); |
| 417 renderSurfacePlaceHolder->setToSelfManagedMemoryPlaceholder(texturesMemorySi
ze(4)); | 417 renderSurfacePlaceHolder->setToSelfManagedMemoryPlaceholder(texturesMemorySi
ze(4)); |
| 418 renderSurfacePlaceHolder->setRequestPriority(CCPriorityCalculator::renderSur
facePriority()); | 418 renderSurfacePlaceHolder->setRequestPriority(CCPriorityCalculator::renderSur
facePriority()); |
| 419 | 419 |
| 420 // Create textures to fill our memory limit. | 420 // Create textures to fill our memory limit. |
| 421 OwnPtr<CCPrioritizedTexture> textures[maxTextures]; | 421 scoped_ptr<CCPrioritizedTexture> textures[maxTextures]; |
| 422 | 422 |
| 423 for (size_t i = 0; i < maxTextures; ++i) | 423 for (size_t i = 0; i < maxTextures; ++i) |
| 424 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); | 424 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); |
| 425 | 425 |
| 426 // Set equal priorities. | 426 // Set equal priorities. |
| 427 for (size_t i = 0; i < maxTextures; ++i) | 427 for (size_t i = 0; i < maxTextures; ++i) |
| 428 textures[i]->setRequestPriority(100); | 428 textures[i]->setRequestPriority(100); |
| 429 | 429 |
| 430 // The first four to be requested late will be available. | 430 // The first four to be requested late will be available. |
| 431 prioritizeTexturesAndBackings(textureManager.get()); | 431 prioritizeTexturesAndBackings(textureManager.get()); |
| 432 for (unsigned i = 0; i < maxTextures; ++i) | 432 for (unsigned i = 0; i < maxTextures; ++i) |
| 433 EXPECT_FALSE(validateTexture(textures[i], false)); | 433 EXPECT_FALSE(validateTexture(textures[i], false)); |
| 434 for (unsigned i = 0; i < maxTextures; i += 2) | 434 for (unsigned i = 0; i < maxTextures; i += 2) |
| 435 EXPECT_TRUE(validateTexture(textures[i], true)); | 435 EXPECT_TRUE(validateTexture(textures[i], true)); |
| 436 for (unsigned i = 1; i < maxTextures; i += 2) | 436 for (unsigned i = 1; i < maxTextures; i += 2) |
| 437 EXPECT_FALSE(validateTexture(textures[i], true)); | 437 EXPECT_FALSE(validateTexture(textures[i], true)); |
| 438 | 438 |
| 439 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryAboveCutoffBytes()); | 439 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryAboveCutoffBytes()); |
| 440 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryForSelfManagedTexture
s()); | 440 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryForSelfManagedTexture
s()); |
| 441 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); | 441 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); |
| 442 | 442 |
| 443 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; | 443 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; |
| 444 textureManager->clearAllMemory(resourceProvider()); | 444 textureManager->clearAllMemory(resourceProvider()); |
| 445 } | 445 } |
| 446 | 446 |
| 447 TEST_F(CCPrioritizedTextureTest, whenRenderSurfaceNotAvailableTexturesAlsoNotAva
ilable) | 447 TEST_F(CCPrioritizedTextureTest, whenRenderSurfaceNotAvailableTexturesAlsoNotAva
ilable) |
| 448 { | 448 { |
| 449 const size_t maxTextures = 8; | 449 const size_t maxTextures = 8; |
| 450 OwnPtr<CCPrioritizedTextureManager> textureManager = createManager(maxTextur
es); | 450 scoped_ptr<CCPrioritizedTextureManager> textureManager = createManager(maxTe
xtures); |
| 451 | 451 |
| 452 // Half of the memory is taken by surfaces (with high priority place-holder) | 452 // Half of the memory is taken by surfaces (with high priority place-holder) |
| 453 OwnPtr<CCPrioritizedTexture> renderSurfacePlaceHolder = textureManager->crea
teTexture(m_textureSize, m_textureFormat); | 453 scoped_ptr<CCPrioritizedTexture> renderSurfacePlaceHolder = textureManager->
createTexture(m_textureSize, m_textureFormat); |
| 454 renderSurfacePlaceHolder->setToSelfManagedMemoryPlaceholder(texturesMemorySi
ze(4)); | 454 renderSurfacePlaceHolder->setToSelfManagedMemoryPlaceholder(texturesMemorySi
ze(4)); |
| 455 renderSurfacePlaceHolder->setRequestPriority(CCPriorityCalculator::renderSur
facePriority()); | 455 renderSurfacePlaceHolder->setRequestPriority(CCPriorityCalculator::renderSur
facePriority()); |
| 456 | 456 |
| 457 // Create textures to fill our memory limit. | 457 // Create textures to fill our memory limit. |
| 458 OwnPtr<CCPrioritizedTexture> textures[maxTextures]; | 458 scoped_ptr<CCPrioritizedTexture> textures[maxTextures]; |
| 459 | 459 |
| 460 for (size_t i = 0; i < maxTextures; ++i) | 460 for (size_t i = 0; i < maxTextures; ++i) |
| 461 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); | 461 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); |
| 462 | 462 |
| 463 // Set 6 visible textures in the root surface, and 2 in a child surface. | 463 // Set 6 visible textures in the root surface, and 2 in a child surface. |
| 464 for (size_t i = 0; i < 6; ++i) | 464 for (size_t i = 0; i < 6; ++i) |
| 465 textures[i]->setRequestPriority(CCPriorityCalculator::visiblePriority(tr
ue)); | 465 textures[i]->setRequestPriority(CCPriorityCalculator::visiblePriority(tr
ue)); |
| 466 for (size_t i = 6; i < 8; ++i) | 466 for (size_t i = 6; i < 8; ++i) |
| 467 textures[i]->setRequestPriority(CCPriorityCalculator::visiblePriority(fa
lse)); | 467 textures[i]->setRequestPriority(CCPriorityCalculator::visiblePriority(fa
lse)); |
| 468 | 468 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 480 EXPECT_EQ(texturesMemorySize(2), textureManager->memoryForSelfManagedTexture
s()); | 480 EXPECT_EQ(texturesMemorySize(2), textureManager->memoryForSelfManagedTexture
s()); |
| 481 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); | 481 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); |
| 482 | 482 |
| 483 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; | 483 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; |
| 484 textureManager->clearAllMemory(resourceProvider()); | 484 textureManager->clearAllMemory(resourceProvider()); |
| 485 } | 485 } |
| 486 | 486 |
| 487 TEST_F(CCPrioritizedTextureTest, requestLateBackingsSorting) | 487 TEST_F(CCPrioritizedTextureTest, requestLateBackingsSorting) |
| 488 { | 488 { |
| 489 const size_t maxTextures = 8; | 489 const size_t maxTextures = 8; |
| 490 OwnPtr<CCPrioritizedTextureManager> textureManager = createManager(maxTextur
es); | 490 scoped_ptr<CCPrioritizedTextureManager> textureManager = createManager(maxTe
xtures); |
| 491 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(maxTextures)); | 491 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(maxTextures)); |
| 492 | 492 |
| 493 // Create textures to fill our memory limit. | 493 // Create textures to fill our memory limit. |
| 494 OwnPtr<CCPrioritizedTexture> textures[maxTextures]; | 494 scoped_ptr<CCPrioritizedTexture> textures[maxTextures]; |
| 495 for (size_t i = 0; i < maxTextures; ++i) | 495 for (size_t i = 0; i < maxTextures; ++i) |
| 496 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); | 496 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); |
| 497 | 497 |
| 498 // Set equal priorities, and allocate backings for all textures. | 498 // Set equal priorities, and allocate backings for all textures. |
| 499 for (size_t i = 0; i < maxTextures; ++i) | 499 for (size_t i = 0; i < maxTextures; ++i) |
| 500 textures[i]->setRequestPriority(100); | 500 textures[i]->setRequestPriority(100); |
| 501 prioritizeTexturesAndBackings(textureManager.get()); | 501 prioritizeTexturesAndBackings(textureManager.get()); |
| 502 for (unsigned i = 0; i < maxTextures; ++i) | 502 for (unsigned i = 0; i < maxTextures; ++i) |
| 503 EXPECT_TRUE(validateTexture(textures[i], false)); | 503 EXPECT_TRUE(validateTexture(textures[i], false)); |
| 504 | 504 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 527 EXPECT_TRUE(textureBackingIsAbovePriorityCutoff(textures[i].get())); | 527 EXPECT_TRUE(textureBackingIsAbovePriorityCutoff(textures[i].get())); |
| 528 for (size_t i = 1; i < maxTextures; i += 2) | 528 for (size_t i = 1; i < maxTextures; i += 2) |
| 529 EXPECT_FALSE(textureBackingIsAbovePriorityCutoff(textures[i].get())); | 529 EXPECT_FALSE(textureBackingIsAbovePriorityCutoff(textures[i].get())); |
| 530 | 530 |
| 531 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; | 531 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; |
| 532 textureManager->clearAllMemory(resourceProvider()); | 532 textureManager->clearAllMemory(resourceProvider()); |
| 533 } | 533 } |
| 534 | 534 |
| 535 | 535 |
| 536 } // namespace | 536 } // namespace |
| OLD | NEW |