| 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 "cc/prioritized_texture.h" | 7 #include "cc/prioritized_resource.h" |
| 8 | 8 |
| 9 #include "cc/prioritized_texture_manager.h" | 9 #include "cc/prioritized_resource_manager.h" |
| 10 #include "cc/single_thread_proxy.h" // For DebugScopedSetImplThread | 10 #include "cc/single_thread_proxy.h" // For DebugScopedSetImplThread |
| 11 #include "cc/test/fake_graphics_context.h" | 11 #include "cc/test/fake_graphics_context.h" |
| 12 #include "cc/test/tiled_layer_test_common.h" | 12 #include "cc/test/tiled_layer_test_common.h" |
| 13 #include "cc/texture.h" | 13 #include "cc/texture.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 using namespace cc; | 16 using namespace cc; |
| 17 using namespace WebKitTests; | 17 using namespace WebKitTests; |
| 18 | 18 |
| 19 namespace cc { | 19 namespace cc { |
| 20 | 20 |
| 21 class PrioritizedTextureTest : public testing::Test { | 21 class PrioritizedResourceTest : public testing::Test { |
| 22 public: | 22 public: |
| 23 PrioritizedTextureTest() | 23 PrioritizedResourceTest() |
| 24 : m_textureSize(256, 256) | 24 : m_textureSize(256, 256) |
| 25 , m_textureFormat(GL_RGBA) | 25 , m_textureFormat(GL_RGBA) |
| 26 , m_context(WebKit::createFakeGraphicsContext()) | 26 , m_context(WebKit::createFakeGraphicsContext()) |
| 27 { | 27 { |
| 28 DebugScopedSetImplThread implThread; | 28 DebugScopedSetImplThread implThread; |
| 29 m_resourceProvider = ResourceProvider::create(m_context.get()); | 29 m_resourceProvider = ResourceProvider::create(m_context.get()); |
| 30 } | 30 } |
| 31 | 31 |
| 32 virtual ~PrioritizedTextureTest() | 32 virtual ~PrioritizedResourceTest() |
| 33 { | 33 { |
| 34 DebugScopedSetImplThread implThread; | 34 DebugScopedSetImplThread implThread; |
| 35 m_resourceProvider.reset(); | 35 m_resourceProvider.reset(); |
| 36 } | 36 } |
| 37 | 37 |
| 38 size_t texturesMemorySize(size_t textureCount) | 38 size_t texturesMemorySize(size_t textureCount) |
| 39 { | 39 { |
| 40 return Texture::memorySizeBytes(m_textureSize, m_textureFormat) * textur
eCount; | 40 return Texture::memorySizeBytes(m_textureSize, m_textureFormat) * textur
eCount; |
| 41 } | 41 } |
| 42 | 42 |
| 43 scoped_ptr<PrioritizedTextureManager> createManager(size_t maxTextures) | 43 scoped_ptr<PrioritizedResourceManager> createManager(size_t maxTextures) |
| 44 { | 44 { |
| 45 return PrioritizedTextureManager::create(texturesMemorySize(maxTextures)
, 1024, 0); | 45 return PrioritizedResourceManager::create(texturesMemorySize(maxTextures
), 1024, 0); |
| 46 } | 46 } |
| 47 | 47 |
| 48 bool validateTexture(scoped_ptr<PrioritizedTexture>& texture, bool requestLa
te) | 48 bool validateTexture(scoped_ptr<PrioritizedResource>& texture, bool requestL
ate) |
| 49 { | 49 { |
| 50 textureManagerAssertInvariants(texture->textureManager()); | 50 resourceManagerAssertInvariants(texture->resourceManager()); |
| 51 if (requestLate) | 51 if (requestLate) |
| 52 texture->requestLate(); | 52 texture->requestLate(); |
| 53 textureManagerAssertInvariants(texture->textureManager()); | 53 resourceManagerAssertInvariants(texture->resourceManager()); |
| 54 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; | 54 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; |
| 55 bool success = texture->canAcquireBackingTexture(); | 55 bool success = texture->canAcquireBackingTexture(); |
| 56 if (success) | 56 if (success) |
| 57 texture->acquireBackingTexture(resourceProvider()); | 57 texture->acquireBackingTexture(resourceProvider()); |
| 58 return success; | 58 return success; |
| 59 } | 59 } |
| 60 | 60 |
| 61 void prioritizeTexturesAndBackings(PrioritizedTextureManager* textureManager
) | 61 void prioritizeTexturesAndBackings(PrioritizedResourceManager* resourceManag
er) |
| 62 { | 62 { |
| 63 textureManager->prioritizeTextures(); | 63 resourceManager->prioritizeTextures(); |
| 64 textureManagerUpdateBackingsPriorities(textureManager); | 64 resourceManagerUpdateBackingsPriorities(resourceManager); |
| 65 } | 65 } |
| 66 | 66 |
| 67 void textureManagerUpdateBackingsPriorities(PrioritizedTextureManager* textu
reManager) | 67 void resourceManagerUpdateBackingsPriorities(PrioritizedResourceManager* res
ourceManager) |
| 68 { | 68 { |
| 69 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; | 69 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; |
| 70 textureManager->pushTexturePrioritiesToBackings(); | 70 resourceManager->pushTexturePrioritiesToBackings(); |
| 71 } | 71 } |
| 72 | 72 |
| 73 ResourceProvider* resourceProvider() | 73 ResourceProvider* resourceProvider() |
| 74 { | 74 { |
| 75 return m_resourceProvider.get(); | 75 return m_resourceProvider.get(); |
| 76 } | 76 } |
| 77 | 77 |
| 78 void textureManagerAssertInvariants(PrioritizedTextureManager* textureManage
r) | 78 void resourceManagerAssertInvariants(PrioritizedResourceManager* resourceMan
ager) |
| 79 { | 79 { |
| 80 #ifndef NDEBUG | 80 #ifndef NDEBUG |
| 81 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; | 81 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; |
| 82 textureManager->assertInvariants(); | 82 resourceManager->assertInvariants(); |
| 83 #endif | 83 #endif |
| 84 } | 84 } |
| 85 | 85 |
| 86 bool textureBackingIsAbovePriorityCutoff(PrioritizedTexture* texture) | 86 bool textureBackingIsAbovePriorityCutoff(PrioritizedResource* texture) |
| 87 { | 87 { |
| 88 return texture->m_backing->wasAbovePriorityCutoffAtLastPriorityUpdate(); | 88 return texture->m_backing->wasAbovePriorityCutoffAtLastPriorityUpdate(); |
| 89 } | 89 } |
| 90 | 90 |
| 91 protected: | 91 protected: |
| 92 const gfx::Size m_textureSize; | 92 const gfx::Size m_textureSize; |
| 93 const GLenum m_textureFormat; | 93 const GLenum m_textureFormat; |
| 94 scoped_ptr<GraphicsContext> m_context; | 94 scoped_ptr<GraphicsContext> m_context; |
| 95 scoped_ptr<ResourceProvider> m_resourceProvider; | 95 scoped_ptr<ResourceProvider> m_resourceProvider; |
| 96 }; | 96 }; |
| 97 | 97 |
| 98 } | 98 } |
| 99 | 99 |
| 100 namespace { | 100 namespace { |
| 101 | 101 |
| 102 TEST_F(PrioritizedTextureTest, requestTextureExceedingMaxLimit) | 102 TEST_F(PrioritizedResourceTest, requestTextureExceedingMaxLimit) |
| 103 { | 103 { |
| 104 const size_t maxTextures = 8; | 104 const size_t maxTextures = 8; |
| 105 scoped_ptr<PrioritizedTextureManager> textureManager = createManager(maxText
ures); | 105 scoped_ptr<PrioritizedResourceManager> resourceManager = createManager(maxTe
xtures); |
| 106 | 106 |
| 107 // Create textures for double our memory limit. | 107 // Create textures for double our memory limit. |
| 108 scoped_ptr<PrioritizedTexture> textures[maxTextures*2]; | 108 scoped_ptr<PrioritizedResource> textures[maxTextures*2]; |
| 109 | 109 |
| 110 for (size_t i = 0; i < maxTextures*2; ++i) | 110 for (size_t i = 0; i < maxTextures*2; ++i) |
| 111 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); | 111 textures[i] = resourceManager->createTexture(m_textureSize, m_textureFor
mat); |
| 112 | 112 |
| 113 // Set decreasing priorities | 113 // Set decreasing priorities |
| 114 for (size_t i = 0; i < maxTextures*2; ++i) | 114 for (size_t i = 0; i < maxTextures*2; ++i) |
| 115 textures[i]->setRequestPriority(100 + i); | 115 textures[i]->setRequestPriority(100 + i); |
| 116 | 116 |
| 117 // Only lower half should be available. | 117 // Only lower half should be available. |
| 118 prioritizeTexturesAndBackings(textureManager.get()); | 118 prioritizeTexturesAndBackings(resourceManager.get()); |
| 119 EXPECT_TRUE(validateTexture(textures[0], false)); | 119 EXPECT_TRUE(validateTexture(textures[0], false)); |
| 120 EXPECT_TRUE(validateTexture(textures[7], false)); | 120 EXPECT_TRUE(validateTexture(textures[7], false)); |
| 121 EXPECT_FALSE(validateTexture(textures[8], false)); | 121 EXPECT_FALSE(validateTexture(textures[8], false)); |
| 122 EXPECT_FALSE(validateTexture(textures[15], false)); | 122 EXPECT_FALSE(validateTexture(textures[15], false)); |
| 123 | 123 |
| 124 // Set increasing priorities | 124 // Set increasing priorities |
| 125 for (size_t i = 0; i < maxTextures*2; ++i) | 125 for (size_t i = 0; i < maxTextures*2; ++i) |
| 126 textures[i]->setRequestPriority(100 - i); | 126 textures[i]->setRequestPriority(100 - i); |
| 127 | 127 |
| 128 // Only upper half should be available. | 128 // Only upper half should be available. |
| 129 prioritizeTexturesAndBackings(textureManager.get()); | 129 prioritizeTexturesAndBackings(resourceManager.get()); |
| 130 EXPECT_FALSE(validateTexture(textures[0], false)); | 130 EXPECT_FALSE(validateTexture(textures[0], false)); |
| 131 EXPECT_FALSE(validateTexture(textures[7], false)); | 131 EXPECT_FALSE(validateTexture(textures[7], false)); |
| 132 EXPECT_TRUE(validateTexture(textures[8], false)); | 132 EXPECT_TRUE(validateTexture(textures[8], false)); |
| 133 EXPECT_TRUE(validateTexture(textures[15], false)); | 133 EXPECT_TRUE(validateTexture(textures[15], false)); |
| 134 | 134 |
| 135 EXPECT_EQ(texturesMemorySize(maxTextures), textureManager->memoryAboveCutoff
Bytes()); | 135 EXPECT_EQ(texturesMemorySize(maxTextures), resourceManager->memoryAboveCutof
fBytes()); |
| 136 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); | 136 EXPECT_LE(resourceManager->memoryUseBytes(), resourceManager->memoryAboveCut
offBytes()); |
| 137 | 137 |
| 138 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; | 138 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; |
| 139 textureManager->clearAllMemory(resourceProvider()); | 139 resourceManager->clearAllMemory(resourceProvider()); |
| 140 } | 140 } |
| 141 | 141 |
| 142 TEST_F(PrioritizedTextureTest, changeMemoryLimits) | 142 TEST_F(PrioritizedResourceTest, changeMemoryLimits) |
| 143 { | 143 { |
| 144 const size_t maxTextures = 8; | 144 const size_t maxTextures = 8; |
| 145 scoped_ptr<PrioritizedTextureManager> textureManager = createManager(maxText
ures); | 145 scoped_ptr<PrioritizedResourceManager> resourceManager = createManager(maxTe
xtures); |
| 146 scoped_ptr<PrioritizedTexture> textures[maxTextures]; | 146 scoped_ptr<PrioritizedResource> textures[maxTextures]; |
| 147 | 147 |
| 148 for (size_t i = 0; i < maxTextures; ++i) | 148 for (size_t i = 0; i < maxTextures; ++i) |
| 149 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); | 149 textures[i] = resourceManager->createTexture(m_textureSize, m_textureFor
mat); |
| 150 for (size_t i = 0; i < maxTextures; ++i) | 150 for (size_t i = 0; i < maxTextures; ++i) |
| 151 textures[i]->setRequestPriority(100 + i); | 151 textures[i]->setRequestPriority(100 + i); |
| 152 | 152 |
| 153 // Set max limit to 8 textures | 153 // Set max limit to 8 textures |
| 154 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(8)); | 154 resourceManager->setMaxMemoryLimitBytes(texturesMemorySize(8)); |
| 155 prioritizeTexturesAndBackings(textureManager.get()); | 155 prioritizeTexturesAndBackings(resourceManager.get()); |
| 156 for (size_t i = 0; i < maxTextures; ++i) | 156 for (size_t i = 0; i < maxTextures; ++i) |
| 157 validateTexture(textures[i], false); | 157 validateTexture(textures[i], false); |
| 158 { | 158 { |
| 159 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; | 159 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; |
| 160 textureManager->reduceMemory(resourceProvider()); | 160 resourceManager->reduceMemory(resourceProvider()); |
| 161 } | 161 } |
| 162 | 162 |
| 163 EXPECT_EQ(texturesMemorySize(8), textureManager->memoryAboveCutoffBytes()); | 163 EXPECT_EQ(texturesMemorySize(8), resourceManager->memoryAboveCutoffBytes()); |
| 164 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); | 164 EXPECT_LE(resourceManager->memoryUseBytes(), resourceManager->memoryAboveCut
offBytes()); |
| 165 | 165 |
| 166 // Set max limit to 5 textures | 166 // Set max limit to 5 textures |
| 167 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(5)); | 167 resourceManager->setMaxMemoryLimitBytes(texturesMemorySize(5)); |
| 168 prioritizeTexturesAndBackings(textureManager.get()); | 168 prioritizeTexturesAndBackings(resourceManager.get()); |
| 169 for (size_t i = 0; i < maxTextures; ++i) | 169 for (size_t i = 0; i < maxTextures; ++i) |
| 170 EXPECT_EQ(validateTexture(textures[i], false), i < 5); | 170 EXPECT_EQ(validateTexture(textures[i], false), i < 5); |
| 171 { | 171 { |
| 172 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; | 172 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; |
| 173 textureManager->reduceMemory(resourceProvider()); | 173 resourceManager->reduceMemory(resourceProvider()); |
| 174 } | 174 } |
| 175 | 175 |
| 176 EXPECT_EQ(texturesMemorySize(5), textureManager->memoryAboveCutoffBytes()); | 176 EXPECT_EQ(texturesMemorySize(5), resourceManager->memoryAboveCutoffBytes()); |
| 177 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); | 177 EXPECT_LE(resourceManager->memoryUseBytes(), resourceManager->memoryAboveCut
offBytes()); |
| 178 | 178 |
| 179 // Set max limit to 4 textures | 179 // Set max limit to 4 textures |
| 180 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(4)); | 180 resourceManager->setMaxMemoryLimitBytes(texturesMemorySize(4)); |
| 181 prioritizeTexturesAndBackings(textureManager.get()); | 181 prioritizeTexturesAndBackings(resourceManager.get()); |
| 182 for (size_t i = 0; i < maxTextures; ++i) | 182 for (size_t i = 0; i < maxTextures; ++i) |
| 183 EXPECT_EQ(validateTexture(textures[i], false), i < 4); | 183 EXPECT_EQ(validateTexture(textures[i], false), i < 4); |
| 184 { | 184 { |
| 185 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; | 185 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; |
| 186 textureManager->reduceMemory(resourceProvider()); | 186 resourceManager->reduceMemory(resourceProvider()); |
| 187 } | 187 } |
| 188 | 188 |
| 189 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryAboveCutoffBytes()); | 189 EXPECT_EQ(texturesMemorySize(4), resourceManager->memoryAboveCutoffBytes()); |
| 190 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); | 190 EXPECT_LE(resourceManager->memoryUseBytes(), resourceManager->memoryAboveCut
offBytes()); |
| 191 | 191 |
| 192 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; | 192 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; |
| 193 textureManager->clearAllMemory(resourceProvider()); | 193 resourceManager->clearAllMemory(resourceProvider()); |
| 194 } | 194 } |
| 195 | 195 |
| 196 TEST_F(PrioritizedTextureTest, changePriorityCutoff) | 196 TEST_F(PrioritizedResourceTest, changePriorityCutoff) |
| 197 { | 197 { |
| 198 const size_t maxTextures = 8; | 198 const size_t maxTextures = 8; |
| 199 scoped_ptr<PrioritizedTextureManager> textureManager = createManager(maxText
ures); | 199 scoped_ptr<PrioritizedResourceManager> resourceManager = createManager(maxTe
xtures); |
| 200 scoped_ptr<PrioritizedTexture> textures[maxTextures]; | 200 scoped_ptr<PrioritizedResource> textures[maxTextures]; |
| 201 | 201 |
| 202 for (size_t i = 0; i < maxTextures; ++i) | 202 for (size_t i = 0; i < maxTextures; ++i) |
| 203 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); | 203 textures[i] = resourceManager->createTexture(m_textureSize, m_textureFor
mat); |
| 204 for (size_t i = 0; i < maxTextures; ++i) | 204 for (size_t i = 0; i < maxTextures; ++i) |
| 205 textures[i]->setRequestPriority(100 + i); | 205 textures[i]->setRequestPriority(100 + i); |
| 206 | 206 |
| 207 // Set the cutoff to drop two textures. Try to requestLate on all textures,
and | 207 // Set the cutoff to drop two textures. Try to requestLate on all textures,
and |
| 208 // make sure that requestLate doesn't work on a texture with equal priority
to | 208 // make sure that requestLate doesn't work on a texture with equal priority
to |
| 209 // the cutoff. | 209 // the cutoff. |
| 210 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(8)); | 210 resourceManager->setMaxMemoryLimitBytes(texturesMemorySize(8)); |
| 211 textureManager->setExternalPriorityCutoff(106); | 211 resourceManager->setExternalPriorityCutoff(106); |
| 212 prioritizeTexturesAndBackings(textureManager.get()); | 212 prioritizeTexturesAndBackings(resourceManager.get()); |
| 213 for (size_t i = 0; i < maxTextures; ++i) | 213 for (size_t i = 0; i < maxTextures; ++i) |
| 214 EXPECT_EQ(validateTexture(textures[i], true), i < 6); | 214 EXPECT_EQ(validateTexture(textures[i], true), i < 6); |
| 215 { | 215 { |
| 216 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; | 216 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; |
| 217 textureManager->reduceMemory(resourceProvider()); | 217 resourceManager->reduceMemory(resourceProvider()); |
| 218 } | 218 } |
| 219 EXPECT_EQ(texturesMemorySize(6), textureManager->memoryAboveCutoffBytes()); | 219 EXPECT_EQ(texturesMemorySize(6), resourceManager->memoryAboveCutoffBytes()); |
| 220 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); | 220 EXPECT_LE(resourceManager->memoryUseBytes(), resourceManager->memoryAboveCut
offBytes()); |
| 221 | 221 |
| 222 // Set the cutoff to drop two more textures. | 222 // Set the cutoff to drop two more textures. |
| 223 textureManager->setExternalPriorityCutoff(104); | 223 resourceManager->setExternalPriorityCutoff(104); |
| 224 prioritizeTexturesAndBackings(textureManager.get()); | 224 prioritizeTexturesAndBackings(resourceManager.get()); |
| 225 for (size_t i = 0; i < maxTextures; ++i) | 225 for (size_t i = 0; i < maxTextures; ++i) |
| 226 EXPECT_EQ(validateTexture(textures[i], false), i < 4); | 226 EXPECT_EQ(validateTexture(textures[i], false), i < 4); |
| 227 { | 227 { |
| 228 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; | 228 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; |
| 229 textureManager->reduceMemory(resourceProvider()); | 229 resourceManager->reduceMemory(resourceProvider()); |
| 230 } | 230 } |
| 231 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryAboveCutoffBytes()); | 231 EXPECT_EQ(texturesMemorySize(4), resourceManager->memoryAboveCutoffBytes()); |
| 232 | 232 |
| 233 // Do a one-time eviction for one more texture based on priority cutoff | 233 // Do a one-time eviction for one more texture based on priority cutoff |
| 234 PrioritizedTextureManager::BackingList evictedBackings; | 234 PrioritizedResourceManager::BackingList evictedBackings; |
| 235 { | 235 { |
| 236 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; | 236 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; |
| 237 textureManager->reduceMemoryOnImplThread(texturesMemorySize(8), 104, res
ourceProvider()); | 237 resourceManager->reduceMemoryOnImplThread(texturesMemorySize(8), 104, re
sourceProvider()); |
| 238 textureManager->getEvictedBackings(evictedBackings); | 238 resourceManager->getEvictedBackings(evictedBackings); |
| 239 EXPECT_EQ(0, evictedBackings.size()); | 239 EXPECT_EQ(0, evictedBackings.size()); |
| 240 textureManager->reduceMemoryOnImplThread(texturesMemorySize(8), 103, res
ourceProvider()); | 240 resourceManager->reduceMemoryOnImplThread(texturesMemorySize(8), 103, re
sourceProvider()); |
| 241 textureManager->getEvictedBackings(evictedBackings); | 241 resourceManager->getEvictedBackings(evictedBackings); |
| 242 EXPECT_EQ(1, evictedBackings.size()); | 242 EXPECT_EQ(1, evictedBackings.size()); |
| 243 } | 243 } |
| 244 textureManager->unlinkEvictedBackings(evictedBackings); | 244 resourceManager->unlinkEvictedBackings(evictedBackings); |
| 245 EXPECT_EQ(texturesMemorySize(3), textureManager->memoryUseBytes()); | 245 EXPECT_EQ(texturesMemorySize(3), resourceManager->memoryUseBytes()); |
| 246 | 246 |
| 247 // Re-allocate the the texture after the one-time drop. | 247 // Re-allocate the the texture after the one-time drop. |
| 248 prioritizeTexturesAndBackings(textureManager.get()); | 248 prioritizeTexturesAndBackings(resourceManager.get()); |
| 249 for (size_t i = 0; i < maxTextures; ++i) | 249 for (size_t i = 0; i < maxTextures; ++i) |
| 250 EXPECT_EQ(validateTexture(textures[i], false), i < 4); | 250 EXPECT_EQ(validateTexture(textures[i], false), i < 4); |
| 251 { | 251 { |
| 252 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; | 252 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; |
| 253 textureManager->reduceMemory(resourceProvider()); | 253 resourceManager->reduceMemory(resourceProvider()); |
| 254 } | 254 } |
| 255 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryAboveCutoffBytes()); | 255 EXPECT_EQ(texturesMemorySize(4), resourceManager->memoryAboveCutoffBytes()); |
| 256 | 256 |
| 257 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; | 257 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; |
| 258 textureManager->clearAllMemory(resourceProvider()); | 258 resourceManager->clearAllMemory(resourceProvider()); |
| 259 } | 259 } |
| 260 | 260 |
| 261 TEST_F(PrioritizedTextureTest, textureManagerPartialUpdateTextures) | 261 TEST_F(PrioritizedResourceTest, resourceManagerPartialUpdateTextures) |
| 262 { | 262 { |
| 263 const size_t maxTextures = 4; | 263 const size_t maxTextures = 4; |
| 264 const size_t numTextures = 4; | 264 const size_t numTextures = 4; |
| 265 scoped_ptr<PrioritizedTextureManager> textureManager = createManager(maxText
ures); | 265 scoped_ptr<PrioritizedResourceManager> resourceManager = createManager(maxTe
xtures); |
| 266 scoped_ptr<PrioritizedTexture> textures[numTextures]; | 266 scoped_ptr<PrioritizedResource> textures[numTextures]; |
| 267 scoped_ptr<PrioritizedTexture> moreTextures[numTextures]; | 267 scoped_ptr<PrioritizedResource> moreTextures[numTextures]; |
| 268 | 268 |
| 269 for (size_t i = 0; i < numTextures; ++i) { | 269 for (size_t i = 0; i < numTextures; ++i) { |
| 270 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); | 270 textures[i] = resourceManager->createTexture(m_textureSize, m_textureFor
mat); |
| 271 moreTextures[i] = textureManager->createTexture(m_textureSize, m_texture
Format); | 271 moreTextures[i] = resourceManager->createTexture(m_textureSize, m_textur
eFormat); |
| 272 } | 272 } |
| 273 | 273 |
| 274 for (size_t i = 0; i < numTextures; ++i) | 274 for (size_t i = 0; i < numTextures; ++i) |
| 275 textures[i]->setRequestPriority(200 + i); | 275 textures[i]->setRequestPriority(200 + i); |
| 276 prioritizeTexturesAndBackings(textureManager.get()); | 276 prioritizeTexturesAndBackings(resourceManager.get()); |
| 277 | 277 |
| 278 // Allocate textures which are currently high priority. | 278 // Allocate textures which are currently high priority. |
| 279 EXPECT_TRUE(validateTexture(textures[0], false)); | 279 EXPECT_TRUE(validateTexture(textures[0], false)); |
| 280 EXPECT_TRUE(validateTexture(textures[1], false)); | 280 EXPECT_TRUE(validateTexture(textures[1], false)); |
| 281 EXPECT_TRUE(validateTexture(textures[2], false)); | 281 EXPECT_TRUE(validateTexture(textures[2], false)); |
| 282 EXPECT_TRUE(validateTexture(textures[3], false)); | 282 EXPECT_TRUE(validateTexture(textures[3], false)); |
| 283 | 283 |
| 284 EXPECT_TRUE(textures[0]->haveBackingTexture()); | 284 EXPECT_TRUE(textures[0]->haveBackingTexture()); |
| 285 EXPECT_TRUE(textures[1]->haveBackingTexture()); | 285 EXPECT_TRUE(textures[1]->haveBackingTexture()); |
| 286 EXPECT_TRUE(textures[2]->haveBackingTexture()); | 286 EXPECT_TRUE(textures[2]->haveBackingTexture()); |
| 287 EXPECT_TRUE(textures[3]->haveBackingTexture()); | 287 EXPECT_TRUE(textures[3]->haveBackingTexture()); |
| 288 | 288 |
| 289 for (size_t i = 0; i < numTextures; ++i) | 289 for (size_t i = 0; i < numTextures; ++i) |
| 290 moreTextures[i]->setRequestPriority(100 + i); | 290 moreTextures[i]->setRequestPriority(100 + i); |
| 291 prioritizeTexturesAndBackings(textureManager.get()); | 291 prioritizeTexturesAndBackings(resourceManager.get()); |
| 292 | 292 |
| 293 // Textures are now below cutoff. | 293 // Textures are now below cutoff. |
| 294 EXPECT_FALSE(validateTexture(textures[0], false)); | 294 EXPECT_FALSE(validateTexture(textures[0], false)); |
| 295 EXPECT_FALSE(validateTexture(textures[1], false)); | 295 EXPECT_FALSE(validateTexture(textures[1], false)); |
| 296 EXPECT_FALSE(validateTexture(textures[2], false)); | 296 EXPECT_FALSE(validateTexture(textures[2], false)); |
| 297 EXPECT_FALSE(validateTexture(textures[3], false)); | 297 EXPECT_FALSE(validateTexture(textures[3], false)); |
| 298 | 298 |
| 299 // But they are still valid to use. | 299 // But they are still valid to use. |
| 300 EXPECT_TRUE(textures[0]->haveBackingTexture()); | 300 EXPECT_TRUE(textures[0]->haveBackingTexture()); |
| 301 EXPECT_TRUE(textures[1]->haveBackingTexture()); | 301 EXPECT_TRUE(textures[1]->haveBackingTexture()); |
| 302 EXPECT_TRUE(textures[2]->haveBackingTexture()); | 302 EXPECT_TRUE(textures[2]->haveBackingTexture()); |
| 303 EXPECT_TRUE(textures[3]->haveBackingTexture()); | 303 EXPECT_TRUE(textures[3]->haveBackingTexture()); |
| 304 | 304 |
| 305 // Higher priority textures are finally needed. | 305 // Higher priority textures are finally needed. |
| 306 EXPECT_TRUE(validateTexture(moreTextures[0], false)); | 306 EXPECT_TRUE(validateTexture(moreTextures[0], false)); |
| 307 EXPECT_TRUE(validateTexture(moreTextures[1], false)); | 307 EXPECT_TRUE(validateTexture(moreTextures[1], false)); |
| 308 EXPECT_TRUE(validateTexture(moreTextures[2], false)); | 308 EXPECT_TRUE(validateTexture(moreTextures[2], false)); |
| 309 EXPECT_TRUE(validateTexture(moreTextures[3], false)); | 309 EXPECT_TRUE(validateTexture(moreTextures[3], false)); |
| 310 | 310 |
| 311 // Lower priority have been fully evicted. | 311 // Lower priority have been fully evicted. |
| 312 EXPECT_FALSE(textures[0]->haveBackingTexture()); | 312 EXPECT_FALSE(textures[0]->haveBackingTexture()); |
| 313 EXPECT_FALSE(textures[1]->haveBackingTexture()); | 313 EXPECT_FALSE(textures[1]->haveBackingTexture()); |
| 314 EXPECT_FALSE(textures[2]->haveBackingTexture()); | 314 EXPECT_FALSE(textures[2]->haveBackingTexture()); |
| 315 EXPECT_FALSE(textures[3]->haveBackingTexture()); | 315 EXPECT_FALSE(textures[3]->haveBackingTexture()); |
| 316 | 316 |
| 317 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; | 317 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; |
| 318 textureManager->clearAllMemory(resourceProvider()); | 318 resourceManager->clearAllMemory(resourceProvider()); |
| 319 } | 319 } |
| 320 | 320 |
| 321 TEST_F(PrioritizedTextureTest, textureManagerPrioritiesAreEqual) | 321 TEST_F(PrioritizedResourceTest, resourceManagerPrioritiesAreEqual) |
| 322 { | 322 { |
| 323 const size_t maxTextures = 16; | 323 const size_t maxTextures = 16; |
| 324 scoped_ptr<PrioritizedTextureManager> textureManager = createManager(maxText
ures); | 324 scoped_ptr<PrioritizedResourceManager> resourceManager = createManager(maxTe
xtures); |
| 325 scoped_ptr<PrioritizedTexture> textures[maxTextures]; | 325 scoped_ptr<PrioritizedResource> textures[maxTextures]; |
| 326 | 326 |
| 327 for (size_t i = 0; i < maxTextures; ++i) | 327 for (size_t i = 0; i < maxTextures; ++i) |
| 328 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); | 328 textures[i] = resourceManager->createTexture(m_textureSize, m_textureFor
mat); |
| 329 | 329 |
| 330 // All 16 textures have the same priority except 2 higher priority. | 330 // All 16 textures have the same priority except 2 higher priority. |
| 331 for (size_t i = 0; i < maxTextures; ++i) | 331 for (size_t i = 0; i < maxTextures; ++i) |
| 332 textures[i]->setRequestPriority(100); | 332 textures[i]->setRequestPriority(100); |
| 333 textures[0]->setRequestPriority(99); | 333 textures[0]->setRequestPriority(99); |
| 334 textures[1]->setRequestPriority(99); | 334 textures[1]->setRequestPriority(99); |
| 335 | 335 |
| 336 // Set max limit to 8 textures | 336 // Set max limit to 8 textures |
| 337 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(8)); | 337 resourceManager->setMaxMemoryLimitBytes(texturesMemorySize(8)); |
| 338 prioritizeTexturesAndBackings(textureManager.get()); | 338 prioritizeTexturesAndBackings(resourceManager.get()); |
| 339 | 339 |
| 340 // The two high priority textures should be available, others should not. | 340 // The two high priority textures should be available, others should not. |
| 341 for (size_t i = 0; i < 2; ++i) | 341 for (size_t i = 0; i < 2; ++i) |
| 342 EXPECT_TRUE(validateTexture(textures[i], false)); | 342 EXPECT_TRUE(validateTexture(textures[i], false)); |
| 343 for (size_t i = 2; i < maxTextures; ++i) | 343 for (size_t i = 2; i < maxTextures; ++i) |
| 344 EXPECT_FALSE(validateTexture(textures[i], false)); | 344 EXPECT_FALSE(validateTexture(textures[i], false)); |
| 345 EXPECT_EQ(texturesMemorySize(2), textureManager->memoryAboveCutoffBytes()); | 345 EXPECT_EQ(texturesMemorySize(2), resourceManager->memoryAboveCutoffBytes()); |
| 346 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); | 346 EXPECT_LE(resourceManager->memoryUseBytes(), resourceManager->memoryAboveCut
offBytes()); |
| 347 | 347 |
| 348 // Manually reserving textures should only succeed on the higher priority te
xtures, | 348 // Manually reserving textures should only succeed on the higher priority te
xtures, |
| 349 // and on remaining textures up to the memory limit. | 349 // and on remaining textures up to the memory limit. |
| 350 for (size_t i = 0; i < 8; i++) | 350 for (size_t i = 0; i < 8; i++) |
| 351 EXPECT_TRUE(validateTexture(textures[i], true)); | 351 EXPECT_TRUE(validateTexture(textures[i], true)); |
| 352 for (size_t i = 9; i < maxTextures; i++) | 352 for (size_t i = 9; i < maxTextures; i++) |
| 353 EXPECT_FALSE(validateTexture(textures[i], true)); | 353 EXPECT_FALSE(validateTexture(textures[i], true)); |
| 354 EXPECT_EQ(texturesMemorySize(8), textureManager->memoryAboveCutoffBytes()); | 354 EXPECT_EQ(texturesMemorySize(8), resourceManager->memoryAboveCutoffBytes()); |
| 355 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); | 355 EXPECT_LE(resourceManager->memoryUseBytes(), resourceManager->memoryAboveCut
offBytes()); |
| 356 | 356 |
| 357 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; | 357 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; |
| 358 textureManager->clearAllMemory(resourceProvider()); | 358 resourceManager->clearAllMemory(resourceProvider()); |
| 359 } | 359 } |
| 360 | 360 |
| 361 TEST_F(PrioritizedTextureTest, textureManagerDestroyedFirst) | 361 TEST_F(PrioritizedResourceTest, resourceManagerDestroyedFirst) |
| 362 { | 362 { |
| 363 scoped_ptr<PrioritizedTextureManager> textureManager = createManager(1); | 363 scoped_ptr<PrioritizedResourceManager> resourceManager = createManager(1); |
| 364 scoped_ptr<PrioritizedTexture> texture = textureManager->createTexture(m_tex
tureSize, m_textureFormat); | 364 scoped_ptr<PrioritizedResource> texture = resourceManager->createTexture(m_t
extureSize, m_textureFormat); |
| 365 | 365 |
| 366 // Texture is initially invalid, but it will become available. | 366 // Texture is initially invalid, but it will become available. |
| 367 EXPECT_FALSE(texture->haveBackingTexture()); | 367 EXPECT_FALSE(texture->haveBackingTexture()); |
| 368 | 368 |
| 369 texture->setRequestPriority(100); | 369 texture->setRequestPriority(100); |
| 370 prioritizeTexturesAndBackings(textureManager.get()); | 370 prioritizeTexturesAndBackings(resourceManager.get()); |
| 371 | 371 |
| 372 EXPECT_TRUE(validateTexture(texture, false)); | 372 EXPECT_TRUE(validateTexture(texture, false)); |
| 373 EXPECT_TRUE(texture->canAcquireBackingTexture()); | 373 EXPECT_TRUE(texture->canAcquireBackingTexture()); |
| 374 EXPECT_TRUE(texture->haveBackingTexture()); | 374 EXPECT_TRUE(texture->haveBackingTexture()); |
| 375 | 375 |
| 376 { | 376 { |
| 377 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; | 377 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; |
| 378 textureManager->clearAllMemory(resourceProvider()); | 378 resourceManager->clearAllMemory(resourceProvider()); |
| 379 } | 379 } |
| 380 textureManager.reset(); | 380 resourceManager.reset(); |
| 381 | 381 |
| 382 EXPECT_FALSE(texture->canAcquireBackingTexture()); | 382 EXPECT_FALSE(texture->canAcquireBackingTexture()); |
| 383 EXPECT_FALSE(texture->haveBackingTexture()); | 383 EXPECT_FALSE(texture->haveBackingTexture()); |
| 384 } | 384 } |
| 385 | 385 |
| 386 TEST_F(PrioritizedTextureTest, textureMovedToNewManager) | 386 TEST_F(PrioritizedResourceTest, textureMovedToNewManager) |
| 387 { | 387 { |
| 388 scoped_ptr<PrioritizedTextureManager> textureManagerOne = createManager(1); | 388 scoped_ptr<PrioritizedResourceManager> resourceManagerOne = createManager(1)
; |
| 389 scoped_ptr<PrioritizedTextureManager> textureManagerTwo = createManager(1); | 389 scoped_ptr<PrioritizedResourceManager> resourceManagerTwo = createManager(1)
; |
| 390 scoped_ptr<PrioritizedTexture> texture = textureManagerOne->createTexture(m_
textureSize, m_textureFormat); | 390 scoped_ptr<PrioritizedResource> texture = resourceManagerOne->createTexture(
m_textureSize, m_textureFormat); |
| 391 | 391 |
| 392 // Texture is initially invalid, but it will become available. | 392 // Texture is initially invalid, but it will become available. |
| 393 EXPECT_FALSE(texture->haveBackingTexture()); | 393 EXPECT_FALSE(texture->haveBackingTexture()); |
| 394 | 394 |
| 395 texture->setRequestPriority(100); | 395 texture->setRequestPriority(100); |
| 396 prioritizeTexturesAndBackings(textureManagerOne.get()); | 396 prioritizeTexturesAndBackings(resourceManagerOne.get()); |
| 397 | 397 |
| 398 EXPECT_TRUE(validateTexture(texture, false)); | 398 EXPECT_TRUE(validateTexture(texture, false)); |
| 399 EXPECT_TRUE(texture->canAcquireBackingTexture()); | 399 EXPECT_TRUE(texture->canAcquireBackingTexture()); |
| 400 EXPECT_TRUE(texture->haveBackingTexture()); | 400 EXPECT_TRUE(texture->haveBackingTexture()); |
| 401 | 401 |
| 402 texture->setTextureManager(0); | 402 texture->setTextureManager(0); |
| 403 | 403 |
| 404 { | 404 { |
| 405 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; | 405 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; |
| 406 textureManagerOne->clearAllMemory(resourceProvider()); | 406 resourceManagerOne->clearAllMemory(resourceProvider()); |
| 407 } | 407 } |
| 408 textureManagerOne.reset(); | 408 resourceManagerOne.reset(); |
| 409 | 409 |
| 410 EXPECT_FALSE(texture->canAcquireBackingTexture()); | 410 EXPECT_FALSE(texture->canAcquireBackingTexture()); |
| 411 EXPECT_FALSE(texture->haveBackingTexture()); | 411 EXPECT_FALSE(texture->haveBackingTexture()); |
| 412 | 412 |
| 413 texture->setTextureManager(textureManagerTwo.get()); | 413 texture->setTextureManager(resourceManagerTwo.get()); |
| 414 | 414 |
| 415 prioritizeTexturesAndBackings(textureManagerTwo.get()); | 415 prioritizeTexturesAndBackings(resourceManagerTwo.get()); |
| 416 | 416 |
| 417 EXPECT_TRUE(validateTexture(texture, false)); | 417 EXPECT_TRUE(validateTexture(texture, false)); |
| 418 EXPECT_TRUE(texture->canAcquireBackingTexture()); | 418 EXPECT_TRUE(texture->canAcquireBackingTexture()); |
| 419 EXPECT_TRUE(texture->haveBackingTexture()); | 419 EXPECT_TRUE(texture->haveBackingTexture()); |
| 420 | 420 |
| 421 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; | 421 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; |
| 422 textureManagerTwo->clearAllMemory(resourceProvider()); | 422 resourceManagerTwo->clearAllMemory(resourceProvider()); |
| 423 } | 423 } |
| 424 | 424 |
| 425 TEST_F(PrioritizedTextureTest, renderSurfacesReduceMemoryAvailableOutsideRootSur
face) | 425 TEST_F(PrioritizedResourceTest, renderSurfacesReduceMemoryAvailableOutsideRootSu
rface) |
| 426 { | 426 { |
| 427 const size_t maxTextures = 8; | 427 const size_t maxTextures = 8; |
| 428 scoped_ptr<PrioritizedTextureManager> textureManager = createManager(maxText
ures); | 428 scoped_ptr<PrioritizedResourceManager> resourceManager = createManager(maxTe
xtures); |
| 429 | 429 |
| 430 // Half of the memory is taken by surfaces (with high priority place-holder) | 430 // Half of the memory is taken by surfaces (with high priority place-holder) |
| 431 scoped_ptr<PrioritizedTexture> renderSurfacePlaceHolder = textureManager->cr
eateTexture(m_textureSize, m_textureFormat); | 431 scoped_ptr<PrioritizedResource> renderSurfacePlaceHolder = resourceManager->
createTexture(m_textureSize, m_textureFormat); |
| 432 renderSurfacePlaceHolder->setToSelfManagedMemoryPlaceholder(texturesMemorySi
ze(4)); | 432 renderSurfacePlaceHolder->setToSelfManagedMemoryPlaceholder(texturesMemorySi
ze(4)); |
| 433 renderSurfacePlaceHolder->setRequestPriority(PriorityCalculator::renderSurfa
cePriority()); | 433 renderSurfacePlaceHolder->setRequestPriority(PriorityCalculator::renderSurfa
cePriority()); |
| 434 | 434 |
| 435 // Create textures to fill our memory limit. | 435 // Create textures to fill our memory limit. |
| 436 scoped_ptr<PrioritizedTexture> textures[maxTextures]; | 436 scoped_ptr<PrioritizedResource> textures[maxTextures]; |
| 437 | 437 |
| 438 for (size_t i = 0; i < maxTextures; ++i) | 438 for (size_t i = 0; i < maxTextures; ++i) |
| 439 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); | 439 textures[i] = resourceManager->createTexture(m_textureSize, m_textureFor
mat); |
| 440 | 440 |
| 441 // Set decreasing non-visible priorities outside root surface. | 441 // Set decreasing non-visible priorities outside root surface. |
| 442 for (size_t i = 0; i < maxTextures; ++i) | 442 for (size_t i = 0; i < maxTextures; ++i) |
| 443 textures[i]->setRequestPriority(100 + i); | 443 textures[i]->setRequestPriority(100 + i); |
| 444 | 444 |
| 445 // Only lower half should be available. | 445 // Only lower half should be available. |
| 446 prioritizeTexturesAndBackings(textureManager.get()); | 446 prioritizeTexturesAndBackings(resourceManager.get()); |
| 447 EXPECT_TRUE(validateTexture(textures[0], false)); | 447 EXPECT_TRUE(validateTexture(textures[0], false)); |
| 448 EXPECT_TRUE(validateTexture(textures[3], false)); | 448 EXPECT_TRUE(validateTexture(textures[3], false)); |
| 449 EXPECT_FALSE(validateTexture(textures[4], false)); | 449 EXPECT_FALSE(validateTexture(textures[4], false)); |
| 450 EXPECT_FALSE(validateTexture(textures[7], false)); | 450 EXPECT_FALSE(validateTexture(textures[7], false)); |
| 451 | 451 |
| 452 // Set increasing non-visible priorities outside root surface. | 452 // Set increasing non-visible priorities outside root surface. |
| 453 for (size_t i = 0; i < maxTextures; ++i) | 453 for (size_t i = 0; i < maxTextures; ++i) |
| 454 textures[i]->setRequestPriority(100 - i); | 454 textures[i]->setRequestPriority(100 - i); |
| 455 | 455 |
| 456 // Only upper half should be available. | 456 // Only upper half should be available. |
| 457 prioritizeTexturesAndBackings(textureManager.get()); | 457 prioritizeTexturesAndBackings(resourceManager.get()); |
| 458 EXPECT_FALSE(validateTexture(textures[0], false)); | 458 EXPECT_FALSE(validateTexture(textures[0], false)); |
| 459 EXPECT_FALSE(validateTexture(textures[3], false)); | 459 EXPECT_FALSE(validateTexture(textures[3], false)); |
| 460 EXPECT_TRUE(validateTexture(textures[4], false)); | 460 EXPECT_TRUE(validateTexture(textures[4], false)); |
| 461 EXPECT_TRUE(validateTexture(textures[7], false)); | 461 EXPECT_TRUE(validateTexture(textures[7], false)); |
| 462 | 462 |
| 463 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryAboveCutoffBytes()); | 463 EXPECT_EQ(texturesMemorySize(4), resourceManager->memoryAboveCutoffBytes()); |
| 464 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryForSelfManagedTexture
s()); | 464 EXPECT_EQ(texturesMemorySize(4), resourceManager->memoryForSelfManagedTextur
es()); |
| 465 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); | 465 EXPECT_LE(resourceManager->memoryUseBytes(), resourceManager->memoryAboveCut
offBytes()); |
| 466 | 466 |
| 467 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; | 467 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; |
| 468 textureManager->clearAllMemory(resourceProvider()); | 468 resourceManager->clearAllMemory(resourceProvider()); |
| 469 } | 469 } |
| 470 | 470 |
| 471 TEST_F(PrioritizedTextureTest, renderSurfacesReduceMemoryAvailableForRequestLate
) | 471 TEST_F(PrioritizedResourceTest, renderSurfacesReduceMemoryAvailableForRequestLat
e) |
| 472 { | 472 { |
| 473 const size_t maxTextures = 8; | 473 const size_t maxTextures = 8; |
| 474 scoped_ptr<PrioritizedTextureManager> textureManager = createManager(maxText
ures); | 474 scoped_ptr<PrioritizedResourceManager> resourceManager = createManager(maxTe
xtures); |
| 475 | 475 |
| 476 // Half of the memory is taken by surfaces (with high priority place-holder) | 476 // Half of the memory is taken by surfaces (with high priority place-holder) |
| 477 scoped_ptr<PrioritizedTexture> renderSurfacePlaceHolder = textureManager->cr
eateTexture(m_textureSize, m_textureFormat); | 477 scoped_ptr<PrioritizedResource> renderSurfacePlaceHolder = resourceManager->
createTexture(m_textureSize, m_textureFormat); |
| 478 renderSurfacePlaceHolder->setToSelfManagedMemoryPlaceholder(texturesMemorySi
ze(4)); | 478 renderSurfacePlaceHolder->setToSelfManagedMemoryPlaceholder(texturesMemorySi
ze(4)); |
| 479 renderSurfacePlaceHolder->setRequestPriority(PriorityCalculator::renderSurfa
cePriority()); | 479 renderSurfacePlaceHolder->setRequestPriority(PriorityCalculator::renderSurfa
cePriority()); |
| 480 | 480 |
| 481 // Create textures to fill our memory limit. | 481 // Create textures to fill our memory limit. |
| 482 scoped_ptr<PrioritizedTexture> textures[maxTextures]; | 482 scoped_ptr<PrioritizedResource> textures[maxTextures]; |
| 483 | 483 |
| 484 for (size_t i = 0; i < maxTextures; ++i) | 484 for (size_t i = 0; i < maxTextures; ++i) |
| 485 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); | 485 textures[i] = resourceManager->createTexture(m_textureSize, m_textureFor
mat); |
| 486 | 486 |
| 487 // Set equal priorities. | 487 // Set equal priorities. |
| 488 for (size_t i = 0; i < maxTextures; ++i) | 488 for (size_t i = 0; i < maxTextures; ++i) |
| 489 textures[i]->setRequestPriority(100); | 489 textures[i]->setRequestPriority(100); |
| 490 | 490 |
| 491 // The first four to be requested late will be available. | 491 // The first four to be requested late will be available. |
| 492 prioritizeTexturesAndBackings(textureManager.get()); | 492 prioritizeTexturesAndBackings(resourceManager.get()); |
| 493 for (unsigned i = 0; i < maxTextures; ++i) | 493 for (unsigned i = 0; i < maxTextures; ++i) |
| 494 EXPECT_FALSE(validateTexture(textures[i], false)); | 494 EXPECT_FALSE(validateTexture(textures[i], false)); |
| 495 for (unsigned i = 0; i < maxTextures; i += 2) | 495 for (unsigned i = 0; i < maxTextures; i += 2) |
| 496 EXPECT_TRUE(validateTexture(textures[i], true)); | 496 EXPECT_TRUE(validateTexture(textures[i], true)); |
| 497 for (unsigned i = 1; i < maxTextures; i += 2) | 497 for (unsigned i = 1; i < maxTextures; i += 2) |
| 498 EXPECT_FALSE(validateTexture(textures[i], true)); | 498 EXPECT_FALSE(validateTexture(textures[i], true)); |
| 499 | 499 |
| 500 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryAboveCutoffBytes()); | 500 EXPECT_EQ(texturesMemorySize(4), resourceManager->memoryAboveCutoffBytes()); |
| 501 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryForSelfManagedTexture
s()); | 501 EXPECT_EQ(texturesMemorySize(4), resourceManager->memoryForSelfManagedTextur
es()); |
| 502 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); | 502 EXPECT_LE(resourceManager->memoryUseBytes(), resourceManager->memoryAboveCut
offBytes()); |
| 503 | 503 |
| 504 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; | 504 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; |
| 505 textureManager->clearAllMemory(resourceProvider()); | 505 resourceManager->clearAllMemory(resourceProvider()); |
| 506 } | 506 } |
| 507 | 507 |
| 508 TEST_F(PrioritizedTextureTest, whenRenderSurfaceNotAvailableTexturesAlsoNotAvail
able) | 508 TEST_F(PrioritizedResourceTest, whenRenderSurfaceNotAvailableTexturesAlsoNotAvai
lable) |
| 509 { | 509 { |
| 510 const size_t maxTextures = 8; | 510 const size_t maxTextures = 8; |
| 511 scoped_ptr<PrioritizedTextureManager> textureManager = createManager(maxText
ures); | 511 scoped_ptr<PrioritizedResourceManager> resourceManager = createManager(maxTe
xtures); |
| 512 | 512 |
| 513 // Half of the memory is taken by surfaces (with high priority place-holder) | 513 // Half of the memory is taken by surfaces (with high priority place-holder) |
| 514 scoped_ptr<PrioritizedTexture> renderSurfacePlaceHolder = textureManager->cr
eateTexture(m_textureSize, m_textureFormat); | 514 scoped_ptr<PrioritizedResource> renderSurfacePlaceHolder = resourceManager->
createTexture(m_textureSize, m_textureFormat); |
| 515 renderSurfacePlaceHolder->setToSelfManagedMemoryPlaceholder(texturesMemorySi
ze(4)); | 515 renderSurfacePlaceHolder->setToSelfManagedMemoryPlaceholder(texturesMemorySi
ze(4)); |
| 516 renderSurfacePlaceHolder->setRequestPriority(PriorityCalculator::renderSurfa
cePriority()); | 516 renderSurfacePlaceHolder->setRequestPriority(PriorityCalculator::renderSurfa
cePriority()); |
| 517 | 517 |
| 518 // Create textures to fill our memory limit. | 518 // Create textures to fill our memory limit. |
| 519 scoped_ptr<PrioritizedTexture> textures[maxTextures]; | 519 scoped_ptr<PrioritizedResource> textures[maxTextures]; |
| 520 | 520 |
| 521 for (size_t i = 0; i < maxTextures; ++i) | 521 for (size_t i = 0; i < maxTextures; ++i) |
| 522 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); | 522 textures[i] = resourceManager->createTexture(m_textureSize, m_textureFor
mat); |
| 523 | 523 |
| 524 // Set 6 visible textures in the root surface, and 2 in a child surface. | 524 // Set 6 visible textures in the root surface, and 2 in a child surface. |
| 525 for (size_t i = 0; i < 6; ++i) | 525 for (size_t i = 0; i < 6; ++i) |
| 526 textures[i]->setRequestPriority(PriorityCalculator::visiblePriority(true
)); | 526 textures[i]->setRequestPriority(PriorityCalculator::visiblePriority(true
)); |
| 527 for (size_t i = 6; i < 8; ++i) | 527 for (size_t i = 6; i < 8; ++i) |
| 528 textures[i]->setRequestPriority(PriorityCalculator::visiblePriority(fals
e)); | 528 textures[i]->setRequestPriority(PriorityCalculator::visiblePriority(fals
e)); |
| 529 | 529 |
| 530 prioritizeTexturesAndBackings(textureManager.get()); | 530 prioritizeTexturesAndBackings(resourceManager.get()); |
| 531 | 531 |
| 532 // Unable to requestLate textures in the child surface. | 532 // Unable to requestLate textures in the child surface. |
| 533 EXPECT_FALSE(validateTexture(textures[6], true)); | 533 EXPECT_FALSE(validateTexture(textures[6], true)); |
| 534 EXPECT_FALSE(validateTexture(textures[7], true)); | 534 EXPECT_FALSE(validateTexture(textures[7], true)); |
| 535 | 535 |
| 536 // Root surface textures are valid. | 536 // Root surface textures are valid. |
| 537 for (size_t i = 0; i < 6; ++i) | 537 for (size_t i = 0; i < 6; ++i) |
| 538 EXPECT_TRUE(validateTexture(textures[i], false)); | 538 EXPECT_TRUE(validateTexture(textures[i], false)); |
| 539 | 539 |
| 540 EXPECT_EQ(texturesMemorySize(6), textureManager->memoryAboveCutoffBytes()); | 540 EXPECT_EQ(texturesMemorySize(6), resourceManager->memoryAboveCutoffBytes()); |
| 541 EXPECT_EQ(texturesMemorySize(2), textureManager->memoryForSelfManagedTexture
s()); | 541 EXPECT_EQ(texturesMemorySize(2), resourceManager->memoryForSelfManagedTextur
es()); |
| 542 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); | 542 EXPECT_LE(resourceManager->memoryUseBytes(), resourceManager->memoryAboveCut
offBytes()); |
| 543 | 543 |
| 544 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; | 544 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; |
| 545 textureManager->clearAllMemory(resourceProvider()); | 545 resourceManager->clearAllMemory(resourceProvider()); |
| 546 } | 546 } |
| 547 | 547 |
| 548 TEST_F(PrioritizedTextureTest, requestLateBackingsSorting) | 548 TEST_F(PrioritizedResourceTest, requestLateBackingsSorting) |
| 549 { | 549 { |
| 550 const size_t maxTextures = 8; | 550 const size_t maxTextures = 8; |
| 551 scoped_ptr<PrioritizedTextureManager> textureManager = createManager(maxText
ures); | 551 scoped_ptr<PrioritizedResourceManager> resourceManager = createManager(maxTe
xtures); |
| 552 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(maxTextures)); | 552 resourceManager->setMaxMemoryLimitBytes(texturesMemorySize(maxTextures)); |
| 553 | 553 |
| 554 // Create textures to fill our memory limit. | 554 // Create textures to fill our memory limit. |
| 555 scoped_ptr<PrioritizedTexture> textures[maxTextures]; | 555 scoped_ptr<PrioritizedResource> textures[maxTextures]; |
| 556 for (size_t i = 0; i < maxTextures; ++i) | 556 for (size_t i = 0; i < maxTextures; ++i) |
| 557 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); | 557 textures[i] = resourceManager->createTexture(m_textureSize, m_textureFor
mat); |
| 558 | 558 |
| 559 // Set equal priorities, and allocate backings for all textures. | 559 // Set equal priorities, and allocate backings for all textures. |
| 560 for (size_t i = 0; i < maxTextures; ++i) | 560 for (size_t i = 0; i < maxTextures; ++i) |
| 561 textures[i]->setRequestPriority(100); | 561 textures[i]->setRequestPriority(100); |
| 562 prioritizeTexturesAndBackings(textureManager.get()); | 562 prioritizeTexturesAndBackings(resourceManager.get()); |
| 563 for (unsigned i = 0; i < maxTextures; ++i) | 563 for (unsigned i = 0; i < maxTextures; ++i) |
| 564 EXPECT_TRUE(validateTexture(textures[i], false)); | 564 EXPECT_TRUE(validateTexture(textures[i], false)); |
| 565 | 565 |
| 566 // Drop the memory limit and prioritize (none will be above the threshold, | 566 // Drop the memory limit and prioritize (none will be above the threshold, |
| 567 // but they still have backings because reduceMemory hasn't been called). | 567 // but they still have backings because reduceMemory hasn't been called). |
| 568 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(maxTextures / 2)); | 568 resourceManager->setMaxMemoryLimitBytes(texturesMemorySize(maxTextures / 2))
; |
| 569 prioritizeTexturesAndBackings(textureManager.get()); | 569 prioritizeTexturesAndBackings(resourceManager.get()); |
| 570 | 570 |
| 571 // Push half of them back over the limit. | 571 // Push half of them back over the limit. |
| 572 for (size_t i = 0; i < maxTextures; i += 2) | 572 for (size_t i = 0; i < maxTextures; i += 2) |
| 573 EXPECT_TRUE(textures[i]->requestLate()); | 573 EXPECT_TRUE(textures[i]->requestLate()); |
| 574 | 574 |
| 575 // Push the priorities to the backings array and sort the backings array | 575 // Push the priorities to the backings array and sort the backings array |
| 576 textureManagerUpdateBackingsPriorities(textureManager.get()); | 576 resourceManagerUpdateBackingsPriorities(resourceManager.get()); |
| 577 | 577 |
| 578 // Assert that the backings list be sorted with the below-limit backings | 578 // Assert that the backings list be sorted with the below-limit backings |
| 579 // before the above-limit backings. | 579 // before the above-limit backings. |
| 580 textureManagerAssertInvariants(textureManager.get()); | 580 resourceManagerAssertInvariants(resourceManager.get()); |
| 581 | 581 |
| 582 // Make sure that we have backings for all of the textures. | 582 // Make sure that we have backings for all of the textures. |
| 583 for (size_t i = 0; i < maxTextures; ++i) | 583 for (size_t i = 0; i < maxTextures; ++i) |
| 584 EXPECT_TRUE(textures[i]->haveBackingTexture()); | 584 EXPECT_TRUE(textures[i]->haveBackingTexture()); |
| 585 | 585 |
| 586 // Make sure that only the requestLate textures are above the priority cutof
f | 586 // Make sure that only the requestLate textures are above the priority cutof
f |
| 587 for (size_t i = 0; i < maxTextures; i += 2) | 587 for (size_t i = 0; i < maxTextures; i += 2) |
| 588 EXPECT_TRUE(textureBackingIsAbovePriorityCutoff(textures[i].get())); | 588 EXPECT_TRUE(textureBackingIsAbovePriorityCutoff(textures[i].get())); |
| 589 for (size_t i = 1; i < maxTextures; i += 2) | 589 for (size_t i = 1; i < maxTextures; i += 2) |
| 590 EXPECT_FALSE(textureBackingIsAbovePriorityCutoff(textures[i].get())); | 590 EXPECT_FALSE(textureBackingIsAbovePriorityCutoff(textures[i].get())); |
| 591 | 591 |
| 592 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; | 592 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; |
| 593 textureManager->clearAllMemory(resourceProvider()); | 593 resourceManager->clearAllMemory(resourceProvider()); |
| 594 } | 594 } |
| 595 | 595 |
| 596 TEST_F(PrioritizedTextureTest, clearUploadsToEvictedResources) | 596 TEST_F(PrioritizedResourceTest, clearUploadsToEvictedResources) |
| 597 { | 597 { |
| 598 const size_t maxTextures = 4; | 598 const size_t maxTextures = 4; |
| 599 scoped_ptr<PrioritizedTextureManager> textureManager = | 599 scoped_ptr<PrioritizedResourceManager> resourceManager = |
| 600 createManager(maxTextures); | 600 createManager(maxTextures); |
| 601 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(maxTextures)); | 601 resourceManager->setMaxMemoryLimitBytes(texturesMemorySize(maxTextures)); |
| 602 | 602 |
| 603 // Create textures to fill our memory limit. | 603 // Create textures to fill our memory limit. |
| 604 scoped_ptr<PrioritizedTexture> textures[maxTextures]; | 604 scoped_ptr<PrioritizedResource> textures[maxTextures]; |
| 605 | 605 |
| 606 for (size_t i = 0; i < maxTextures; ++i) | 606 for (size_t i = 0; i < maxTextures; ++i) |
| 607 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); | 607 textures[i] = resourceManager->createTexture(m_textureSize, m_textureFor
mat); |
| 608 | 608 |
| 609 // Set equal priorities, and allocate backings for all textures. | 609 // Set equal priorities, and allocate backings for all textures. |
| 610 for (size_t i = 0; i < maxTextures; ++i) | 610 for (size_t i = 0; i < maxTextures; ++i) |
| 611 textures[i]->setRequestPriority(100); | 611 textures[i]->setRequestPriority(100); |
| 612 prioritizeTexturesAndBackings(textureManager.get()); | 612 prioritizeTexturesAndBackings(resourceManager.get()); |
| 613 for (unsigned i = 0; i < maxTextures; ++i) | 613 for (unsigned i = 0; i < maxTextures; ++i) |
| 614 EXPECT_TRUE(validateTexture(textures[i], false)); | 614 EXPECT_TRUE(validateTexture(textures[i], false)); |
| 615 | 615 |
| 616 ResourceUpdateQueue queue; | 616 ResourceUpdateQueue queue; |
| 617 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; | 617 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; |
| 618 for (size_t i = 0; i < maxTextures; ++i) { | 618 for (size_t i = 0; i < maxTextures; ++i) { |
| 619 const ResourceUpdate upload = ResourceUpdate::Create( | 619 const ResourceUpdate upload = ResourceUpdate::Create( |
| 620 textures[i].get(), NULL, gfx::Rect(), gfx::Rect(), gfx::Vector2d()); | 620 textures[i].get(), NULL, gfx::Rect(), gfx::Rect(), gfx::Vector2d()); |
| 621 queue.appendFullUpload(upload); | 621 queue.appendFullUpload(upload); |
| 622 } | 622 } |
| 623 | 623 |
| 624 // Make sure that we have backings for all of the textures. | 624 // Make sure that we have backings for all of the textures. |
| 625 for (size_t i = 0; i < maxTextures; ++i) | 625 for (size_t i = 0; i < maxTextures; ++i) |
| 626 EXPECT_TRUE(textures[i]->haveBackingTexture()); | 626 EXPECT_TRUE(textures[i]->haveBackingTexture()); |
| 627 | 627 |
| 628 queue.clearUploadsToEvictedResources(); | 628 queue.clearUploadsToEvictedResources(); |
| 629 EXPECT_EQ(4, queue.fullUploadSize()); | 629 EXPECT_EQ(4, queue.fullUploadSize()); |
| 630 | 630 |
| 631 textureManager->reduceMemoryOnImplThread( | 631 resourceManager->reduceMemoryOnImplThread( |
| 632 texturesMemorySize(1), PriorityCalculator::allowEverythingCutoff(), reso
urceProvider()); | 632 texturesMemorySize(1), PriorityCalculator::allowEverythingCutoff(), reso
urceProvider()); |
| 633 queue.clearUploadsToEvictedResources(); | 633 queue.clearUploadsToEvictedResources(); |
| 634 EXPECT_EQ(1, queue.fullUploadSize()); | 634 EXPECT_EQ(1, queue.fullUploadSize()); |
| 635 | 635 |
| 636 textureManager->reduceMemoryOnImplThread(0, PriorityCalculator::allowEveryt
hingCutoff(), resourceProvider()); | 636 resourceManager->reduceMemoryOnImplThread(0, PriorityCalculator::allowEvery
thingCutoff(), resourceProvider()); |
| 637 queue.clearUploadsToEvictedResources(); | 637 queue.clearUploadsToEvictedResources(); |
| 638 EXPECT_EQ(0, queue.fullUploadSize()); | 638 EXPECT_EQ(0, queue.fullUploadSize()); |
| 639 | 639 |
| 640 } | 640 } |
| 641 | 641 |
| 642 TEST_F(PrioritizedTextureTest, usageStatistics) | 642 TEST_F(PrioritizedResourceTest, usageStatistics) |
| 643 { | 643 { |
| 644 const size_t maxTextures = 5; | 644 const size_t maxTextures = 5; |
| 645 scoped_ptr<PrioritizedTextureManager> textureManager = createManager(maxText
ures); | 645 scoped_ptr<PrioritizedResourceManager> resourceManager = createManager(maxTe
xtures); |
| 646 scoped_ptr<PrioritizedTexture> textures[maxTextures]; | 646 scoped_ptr<PrioritizedResource> textures[maxTextures]; |
| 647 | 647 |
| 648 for (size_t i = 0; i < maxTextures; ++i) | 648 for (size_t i = 0; i < maxTextures; ++i) |
| 649 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); | 649 textures[i] = resourceManager->createTexture(m_textureSize, m_textureFor
mat); |
| 650 | 650 |
| 651 textures[0]->setRequestPriority(PriorityCalculator::allowVisibleOnlyCutoff()
- 1); | 651 textures[0]->setRequestPriority(PriorityCalculator::allowVisibleOnlyCutoff()
- 1); |
| 652 textures[1]->setRequestPriority(PriorityCalculator::allowVisibleOnlyCutoff()
); | 652 textures[1]->setRequestPriority(PriorityCalculator::allowVisibleOnlyCutoff()
); |
| 653 textures[2]->setRequestPriority(PriorityCalculator::allowVisibleAndNearbyCut
off() - 1); | 653 textures[2]->setRequestPriority(PriorityCalculator::allowVisibleAndNearbyCut
off() - 1); |
| 654 textures[3]->setRequestPriority(PriorityCalculator::allowVisibleAndNearbyCut
off()); | 654 textures[3]->setRequestPriority(PriorityCalculator::allowVisibleAndNearbyCut
off()); |
| 655 textures[4]->setRequestPriority(PriorityCalculator::allowVisibleAndNearbyCut
off() + 1); | 655 textures[4]->setRequestPriority(PriorityCalculator::allowVisibleAndNearbyCut
off() + 1); |
| 656 | 656 |
| 657 // Set max limit to 2 textures. | 657 // Set max limit to 2 textures. |
| 658 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(2)); | 658 resourceManager->setMaxMemoryLimitBytes(texturesMemorySize(2)); |
| 659 prioritizeTexturesAndBackings(textureManager.get()); | 659 prioritizeTexturesAndBackings(resourceManager.get()); |
| 660 | 660 |
| 661 // The first two textures should be available, others should not. | 661 // The first two textures should be available, others should not. |
| 662 for (size_t i = 0; i < 2; ++i) | 662 for (size_t i = 0; i < 2; ++i) |
| 663 EXPECT_TRUE(validateTexture(textures[i], false)); | 663 EXPECT_TRUE(validateTexture(textures[i], false)); |
| 664 for (size_t i = 2; i < maxTextures; ++i) | 664 for (size_t i = 2; i < maxTextures; ++i) |
| 665 EXPECT_FALSE(validateTexture(textures[i], false)); | 665 EXPECT_FALSE(validateTexture(textures[i], false)); |
| 666 | 666 |
| 667 // Validate the statistics. | 667 // Validate the statistics. |
| 668 { | 668 { |
| 669 DebugScopedSetImplThread implThread; | 669 DebugScopedSetImplThread implThread; |
| 670 EXPECT_EQ(texturesMemorySize(2), textureManager->memoryUseBytes()); | 670 EXPECT_EQ(texturesMemorySize(2), resourceManager->memoryUseBytes()); |
| 671 EXPECT_EQ(texturesMemorySize(1), textureManager->memoryVisibleBytes()); | 671 EXPECT_EQ(texturesMemorySize(1), resourceManager->memoryVisibleBytes()); |
| 672 EXPECT_EQ(texturesMemorySize(3), textureManager->memoryVisibleAndNearbyB
ytes()); | 672 EXPECT_EQ(texturesMemorySize(3), resourceManager->memoryVisibleAndNearby
Bytes()); |
| 673 } | 673 } |
| 674 | 674 |
| 675 // Re-prioritize the textures, but do not push the values to backings. | 675 // Re-prioritize the textures, but do not push the values to backings. |
| 676 textures[0]->setRequestPriority(PriorityCalculator::allowVisibleOnlyCutoff()
- 1); | 676 textures[0]->setRequestPriority(PriorityCalculator::allowVisibleOnlyCutoff()
- 1); |
| 677 textures[1]->setRequestPriority(PriorityCalculator::allowVisibleOnlyCutoff()
- 1); | 677 textures[1]->setRequestPriority(PriorityCalculator::allowVisibleOnlyCutoff()
- 1); |
| 678 textures[2]->setRequestPriority(PriorityCalculator::allowVisibleOnlyCutoff()
- 1); | 678 textures[2]->setRequestPriority(PriorityCalculator::allowVisibleOnlyCutoff()
- 1); |
| 679 textures[3]->setRequestPriority(PriorityCalculator::allowVisibleAndNearbyCut
off() - 1); | 679 textures[3]->setRequestPriority(PriorityCalculator::allowVisibleAndNearbyCut
off() - 1); |
| 680 textures[4]->setRequestPriority(PriorityCalculator::allowVisibleAndNearbyCut
off()); | 680 textures[4]->setRequestPriority(PriorityCalculator::allowVisibleAndNearbyCut
off()); |
| 681 textureManager->prioritizeTextures(); | 681 resourceManager->prioritizeTextures(); |
| 682 | 682 |
| 683 // Verify that we still see the old values. | 683 // Verify that we still see the old values. |
| 684 { | 684 { |
| 685 DebugScopedSetImplThread implThread; | 685 DebugScopedSetImplThread implThread; |
| 686 EXPECT_EQ(texturesMemorySize(2), textureManager->memoryUseBytes()); | 686 EXPECT_EQ(texturesMemorySize(2), resourceManager->memoryUseBytes()); |
| 687 EXPECT_EQ(texturesMemorySize(1), textureManager->memoryVisibleBytes()); | 687 EXPECT_EQ(texturesMemorySize(1), resourceManager->memoryVisibleBytes()); |
| 688 EXPECT_EQ(texturesMemorySize(3), textureManager->memoryVisibleAndNearbyB
ytes()); | 688 EXPECT_EQ(texturesMemorySize(3), resourceManager->memoryVisibleAndNearby
Bytes()); |
| 689 } | 689 } |
| 690 | 690 |
| 691 // Push priorities to backings, and verify we see the new values. | 691 // Push priorities to backings, and verify we see the new values. |
| 692 { | 692 { |
| 693 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; | 693 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; |
| 694 textureManager->pushTexturePrioritiesToBackings(); | 694 resourceManager->pushTexturePrioritiesToBackings(); |
| 695 EXPECT_EQ(texturesMemorySize(2), textureManager->memoryUseBytes()); | 695 EXPECT_EQ(texturesMemorySize(2), resourceManager->memoryUseBytes()); |
| 696 EXPECT_EQ(texturesMemorySize(3), textureManager->memoryVisibleBytes()); | 696 EXPECT_EQ(texturesMemorySize(3), resourceManager->memoryVisibleBytes()); |
| 697 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryVisibleAndNearbyB
ytes()); | 697 EXPECT_EQ(texturesMemorySize(4), resourceManager->memoryVisibleAndNearby
Bytes()); |
| 698 } | 698 } |
| 699 | 699 |
| 700 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; | 700 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; |
| 701 textureManager->clearAllMemory(resourceProvider()); | 701 resourceManager->clearAllMemory(resourceProvider()); |
| 702 } | 702 } |
| 703 | 703 |
| 704 | 704 |
| 705 } // anonymous namespace | 705 } // anonymous namespace |
| OLD | NEW |