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_texture.h" |
8 | 8 |
9 #include "cc/prioritized_texture_manager.h" | 9 #include "cc/prioritized_texture_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/fake_proxy.h" | |
13 #include "cc/test/tiled_layer_test_common.h" | 12 #include "cc/test/tiled_layer_test_common.h" |
14 #include "cc/texture.h" | 13 #include "cc/texture.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
16 | 15 |
17 using namespace cc; | 16 using namespace cc; |
18 using namespace WebKitTests; | 17 using namespace WebKitTests; |
19 | 18 |
20 namespace cc { | 19 namespace cc { |
21 | 20 |
22 class PrioritizedTextureTest : public testing::Test { | 21 class PrioritizedTextureTest : public testing::Test { |
23 public: | 22 public: |
24 PrioritizedTextureTest() | 23 PrioritizedTextureTest() |
25 : m_proxy(scoped_ptr<Thread>(NULL)) | 24 : m_textureSize(256, 256) |
26 , m_textureSize(256, 256) | |
27 , m_textureFormat(GL_RGBA) | 25 , m_textureFormat(GL_RGBA) |
28 , m_context(WebKit::createFakeGraphicsContext()) | 26 , m_context(WebKit::createFakeGraphicsContext()) |
29 { | 27 { |
30 DebugScopedSetImplThread implThread(&m_proxy); | 28 DebugScopedSetImplThread implThread; |
31 m_resourceProvider = ResourceProvider::create(m_context.get()); | 29 m_resourceProvider = ResourceProvider::create(m_context.get()); |
32 } | 30 } |
33 | 31 |
34 virtual ~PrioritizedTextureTest() | 32 virtual ~PrioritizedTextureTest() |
35 { | 33 { |
36 DebugScopedSetImplThread implThread(&m_proxy); | 34 DebugScopedSetImplThread implThread; |
37 m_resourceProvider.reset(); | 35 m_resourceProvider.reset(); |
38 } | 36 } |
39 | 37 |
40 size_t texturesMemorySize(size_t textureCount) | 38 size_t texturesMemorySize(size_t textureCount) |
41 { | 39 { |
42 return Texture::memorySizeBytes(m_textureSize, m_textureFormat) * textur
eCount; | 40 return Texture::memorySizeBytes(m_textureSize, m_textureFormat) * textur
eCount; |
43 } | 41 } |
44 | 42 |
45 scoped_ptr<PrioritizedTextureManager> createManager(size_t maxTextures) | 43 scoped_ptr<PrioritizedTextureManager> createManager(size_t maxTextures) |
46 { | 44 { |
47 return PrioritizedTextureManager::create(texturesMemorySize(maxTextures)
, 1024, 0, &m_proxy); | 45 return PrioritizedTextureManager::create(texturesMemorySize(maxTextures)
, 1024, 0); |
48 } | 46 } |
49 | 47 |
50 bool validateTexture(scoped_ptr<PrioritizedTexture>& texture, bool requestLa
te) | 48 bool validateTexture(scoped_ptr<PrioritizedTexture>& texture, bool requestLa
te) |
51 { | 49 { |
52 textureManagerAssertInvariants(texture->textureManager()); | 50 textureManagerAssertInvariants(texture->textureManager()); |
53 if (requestLate) | 51 if (requestLate) |
54 texture->requestLate(); | 52 texture->requestLate(); |
55 textureManagerAssertInvariants(texture->textureManager()); | 53 textureManagerAssertInvariants(texture->textureManager()); |
56 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked(&m_proxy); | 54 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; |
57 bool success = texture->canAcquireBackingTexture(); | 55 bool success = texture->canAcquireBackingTexture(); |
58 if (success) | 56 if (success) |
59 texture->acquireBackingTexture(resourceProvider()); | 57 texture->acquireBackingTexture(resourceProvider()); |
60 return success; | 58 return success; |
61 } | 59 } |
62 | 60 |
63 void prioritizeTexturesAndBackings(PrioritizedTextureManager* textureManager
) | 61 void prioritizeTexturesAndBackings(PrioritizedTextureManager* textureManager
) |
64 { | 62 { |
65 textureManager->prioritizeTextures(); | 63 textureManager->prioritizeTextures(); |
66 textureManagerUpdateBackingsPriorities(textureManager); | 64 textureManagerUpdateBackingsPriorities(textureManager); |
67 } | 65 } |
68 | 66 |
69 void textureManagerUpdateBackingsPriorities(PrioritizedTextureManager* textu
reManager) | 67 void textureManagerUpdateBackingsPriorities(PrioritizedTextureManager* textu
reManager) |
70 { | 68 { |
71 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked(&m_proxy); | 69 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; |
72 textureManager->pushTexturePrioritiesToBackings(); | 70 textureManager->pushTexturePrioritiesToBackings(); |
73 } | 71 } |
74 | 72 |
75 ResourceProvider* resourceProvider() | 73 ResourceProvider* resourceProvider() |
76 { | 74 { |
77 return m_resourceProvider.get(); | 75 return m_resourceProvider.get(); |
78 } | 76 } |
79 | 77 |
80 void textureManagerAssertInvariants(PrioritizedTextureManager* textureManage
r) | 78 void textureManagerAssertInvariants(PrioritizedTextureManager* textureManage
r) |
81 { | 79 { |
82 #ifndef NDEBUG | 80 #ifndef NDEBUG |
83 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked(&m_proxy); | 81 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; |
84 textureManager->assertInvariants(); | 82 textureManager->assertInvariants(); |
85 #endif | 83 #endif |
86 } | 84 } |
87 | 85 |
88 bool textureBackingIsAbovePriorityCutoff(PrioritizedTexture* texture) | 86 bool textureBackingIsAbovePriorityCutoff(PrioritizedTexture* texture) |
89 { | 87 { |
90 return texture->m_backing->wasAbovePriorityCutoffAtLastPriorityUpdate(); | 88 return texture->m_backing->wasAbovePriorityCutoffAtLastPriorityUpdate(); |
91 } | 89 } |
92 | 90 |
93 protected: | 91 protected: |
94 FakeProxy m_proxy; | |
95 const gfx::Size m_textureSize; | 92 const gfx::Size m_textureSize; |
96 const GLenum m_textureFormat; | 93 const GLenum m_textureFormat; |
97 scoped_ptr<GraphicsContext> m_context; | 94 scoped_ptr<GraphicsContext> m_context; |
98 scoped_ptr<ResourceProvider> m_resourceProvider; | 95 scoped_ptr<ResourceProvider> m_resourceProvider; |
99 }; | 96 }; |
100 | 97 |
101 } | 98 } |
102 | 99 |
103 namespace { | 100 namespace { |
104 | 101 |
(...skipping 26 matching lines...) Expand all Loading... |
131 // Only upper half should be available. | 128 // Only upper half should be available. |
132 prioritizeTexturesAndBackings(textureManager.get()); | 129 prioritizeTexturesAndBackings(textureManager.get()); |
133 EXPECT_FALSE(validateTexture(textures[0], false)); | 130 EXPECT_FALSE(validateTexture(textures[0], false)); |
134 EXPECT_FALSE(validateTexture(textures[7], false)); | 131 EXPECT_FALSE(validateTexture(textures[7], false)); |
135 EXPECT_TRUE(validateTexture(textures[8], false)); | 132 EXPECT_TRUE(validateTexture(textures[8], false)); |
136 EXPECT_TRUE(validateTexture(textures[15], false)); | 133 EXPECT_TRUE(validateTexture(textures[15], false)); |
137 | 134 |
138 EXPECT_EQ(texturesMemorySize(maxTextures), textureManager->memoryAboveCutoff
Bytes()); | 135 EXPECT_EQ(texturesMemorySize(maxTextures), textureManager->memoryAboveCutoff
Bytes()); |
139 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); | 136 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); |
140 | 137 |
141 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(
&m_proxy); | 138 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; |
142 textureManager->clearAllMemory(resourceProvider()); | 139 textureManager->clearAllMemory(resourceProvider()); |
143 } | 140 } |
144 | 141 |
145 TEST_F(PrioritizedTextureTest, changeMemoryLimits) | 142 TEST_F(PrioritizedTextureTest, changeMemoryLimits) |
146 { | 143 { |
147 const size_t maxTextures = 8; | 144 const size_t maxTextures = 8; |
148 scoped_ptr<PrioritizedTextureManager> textureManager = createManager(maxText
ures); | 145 scoped_ptr<PrioritizedTextureManager> textureManager = createManager(maxText
ures); |
149 scoped_ptr<PrioritizedTexture> textures[maxTextures]; | 146 scoped_ptr<PrioritizedTexture> textures[maxTextures]; |
150 | 147 |
151 for (size_t i = 0; i < maxTextures; ++i) | 148 for (size_t i = 0; i < maxTextures; ++i) |
152 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); | 149 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); |
153 for (size_t i = 0; i < maxTextures; ++i) | 150 for (size_t i = 0; i < maxTextures; ++i) |
154 textures[i]->setRequestPriority(100 + i); | 151 textures[i]->setRequestPriority(100 + i); |
155 | 152 |
156 // Set max limit to 8 textures | 153 // Set max limit to 8 textures |
157 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(8)); | 154 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(8)); |
158 prioritizeTexturesAndBackings(textureManager.get()); | 155 prioritizeTexturesAndBackings(textureManager.get()); |
159 for (size_t i = 0; i < maxTextures; ++i) | 156 for (size_t i = 0; i < maxTextures; ++i) |
160 validateTexture(textures[i], false); | 157 validateTexture(textures[i], false); |
161 { | 158 { |
162 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked(&m_proxy); | 159 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; |
163 textureManager->reduceMemory(resourceProvider()); | 160 textureManager->reduceMemory(resourceProvider()); |
164 } | 161 } |
165 | 162 |
166 EXPECT_EQ(texturesMemorySize(8), textureManager->memoryAboveCutoffBytes()); | 163 EXPECT_EQ(texturesMemorySize(8), textureManager->memoryAboveCutoffBytes()); |
167 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); | 164 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); |
168 | 165 |
169 // Set max limit to 5 textures | 166 // Set max limit to 5 textures |
170 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(5)); | 167 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(5)); |
171 prioritizeTexturesAndBackings(textureManager.get()); | 168 prioritizeTexturesAndBackings(textureManager.get()); |
172 for (size_t i = 0; i < maxTextures; ++i) | 169 for (size_t i = 0; i < maxTextures; ++i) |
173 EXPECT_EQ(validateTexture(textures[i], false), i < 5); | 170 EXPECT_EQ(validateTexture(textures[i], false), i < 5); |
174 { | 171 { |
175 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked(&m_proxy); | 172 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; |
176 textureManager->reduceMemory(resourceProvider()); | 173 textureManager->reduceMemory(resourceProvider()); |
177 } | 174 } |
178 | 175 |
179 EXPECT_EQ(texturesMemorySize(5), textureManager->memoryAboveCutoffBytes()); | 176 EXPECT_EQ(texturesMemorySize(5), textureManager->memoryAboveCutoffBytes()); |
180 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); | 177 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); |
181 | 178 |
182 // Set max limit to 4 textures | 179 // Set max limit to 4 textures |
183 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(4)); | 180 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(4)); |
184 prioritizeTexturesAndBackings(textureManager.get()); | 181 prioritizeTexturesAndBackings(textureManager.get()); |
185 for (size_t i = 0; i < maxTextures; ++i) | 182 for (size_t i = 0; i < maxTextures; ++i) |
186 EXPECT_EQ(validateTexture(textures[i], false), i < 4); | 183 EXPECT_EQ(validateTexture(textures[i], false), i < 4); |
187 { | 184 { |
188 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked(&m_proxy); | 185 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; |
189 textureManager->reduceMemory(resourceProvider()); | 186 textureManager->reduceMemory(resourceProvider()); |
190 } | 187 } |
191 | 188 |
192 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryAboveCutoffBytes()); | 189 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryAboveCutoffBytes()); |
193 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); | 190 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); |
194 | 191 |
195 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(
&m_proxy); | 192 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; |
196 textureManager->clearAllMemory(resourceProvider()); | 193 textureManager->clearAllMemory(resourceProvider()); |
197 } | 194 } |
198 | 195 |
199 TEST_F(PrioritizedTextureTest, changePriorityCutoff) | 196 TEST_F(PrioritizedTextureTest, changePriorityCutoff) |
200 { | 197 { |
201 const size_t maxTextures = 8; | 198 const size_t maxTextures = 8; |
202 scoped_ptr<PrioritizedTextureManager> textureManager = createManager(maxText
ures); | 199 scoped_ptr<PrioritizedTextureManager> textureManager = createManager(maxText
ures); |
203 scoped_ptr<PrioritizedTexture> textures[maxTextures]; | 200 scoped_ptr<PrioritizedTexture> textures[maxTextures]; |
204 | 201 |
205 for (size_t i = 0; i < maxTextures; ++i) | 202 for (size_t i = 0; i < maxTextures; ++i) |
206 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); | 203 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); |
207 for (size_t i = 0; i < maxTextures; ++i) | 204 for (size_t i = 0; i < maxTextures; ++i) |
208 textures[i]->setRequestPriority(100 + i); | 205 textures[i]->setRequestPriority(100 + i); |
209 | 206 |
210 // 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 |
211 // 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 |
212 // the cutoff. | 209 // the cutoff. |
213 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(8)); | 210 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(8)); |
214 textureManager->setExternalPriorityCutoff(106); | 211 textureManager->setExternalPriorityCutoff(106); |
215 prioritizeTexturesAndBackings(textureManager.get()); | 212 prioritizeTexturesAndBackings(textureManager.get()); |
216 for (size_t i = 0; i < maxTextures; ++i) | 213 for (size_t i = 0; i < maxTextures; ++i) |
217 EXPECT_EQ(validateTexture(textures[i], true), i < 6); | 214 EXPECT_EQ(validateTexture(textures[i], true), i < 6); |
218 { | 215 { |
219 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked(&m_proxy); | 216 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; |
220 textureManager->reduceMemory(resourceProvider()); | 217 textureManager->reduceMemory(resourceProvider()); |
221 } | 218 } |
222 EXPECT_EQ(texturesMemorySize(6), textureManager->memoryAboveCutoffBytes()); | 219 EXPECT_EQ(texturesMemorySize(6), textureManager->memoryAboveCutoffBytes()); |
223 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); | 220 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); |
224 | 221 |
225 // Set the cutoff to drop two more textures. | 222 // Set the cutoff to drop two more textures. |
226 textureManager->setExternalPriorityCutoff(104); | 223 textureManager->setExternalPriorityCutoff(104); |
227 prioritizeTexturesAndBackings(textureManager.get()); | 224 prioritizeTexturesAndBackings(textureManager.get()); |
228 for (size_t i = 0; i < maxTextures; ++i) | 225 for (size_t i = 0; i < maxTextures; ++i) |
229 EXPECT_EQ(validateTexture(textures[i], false), i < 4); | 226 EXPECT_EQ(validateTexture(textures[i], false), i < 4); |
230 { | 227 { |
231 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked(&m_proxy); | 228 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; |
232 textureManager->reduceMemory(resourceProvider()); | 229 textureManager->reduceMemory(resourceProvider()); |
233 } | 230 } |
234 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryAboveCutoffBytes()); | 231 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryAboveCutoffBytes()); |
235 | 232 |
236 // 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 |
237 PrioritizedTextureManager::BackingList evictedBackings; | 234 PrioritizedTextureManager::BackingList evictedBackings; |
238 { | 235 { |
239 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked(&m_proxy); | 236 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; |
240 textureManager->reduceMemoryOnImplThread(texturesMemorySize(8), 104, res
ourceProvider()); | 237 textureManager->reduceMemoryOnImplThread(texturesMemorySize(8), 104, res
ourceProvider()); |
241 textureManager->getEvictedBackings(evictedBackings); | 238 textureManager->getEvictedBackings(evictedBackings); |
242 EXPECT_EQ(0, evictedBackings.size()); | 239 EXPECT_EQ(0, evictedBackings.size()); |
243 textureManager->reduceMemoryOnImplThread(texturesMemorySize(8), 103, res
ourceProvider()); | 240 textureManager->reduceMemoryOnImplThread(texturesMemorySize(8), 103, res
ourceProvider()); |
244 textureManager->getEvictedBackings(evictedBackings); | 241 textureManager->getEvictedBackings(evictedBackings); |
245 EXPECT_EQ(1, evictedBackings.size()); | 242 EXPECT_EQ(1, evictedBackings.size()); |
246 } | 243 } |
247 textureManager->unlinkEvictedBackings(evictedBackings); | 244 textureManager->unlinkEvictedBackings(evictedBackings); |
248 EXPECT_EQ(texturesMemorySize(3), textureManager->memoryUseBytes()); | 245 EXPECT_EQ(texturesMemorySize(3), textureManager->memoryUseBytes()); |
249 | 246 |
250 // Re-allocate the the texture after the one-time drop. | 247 // Re-allocate the the texture after the one-time drop. |
251 prioritizeTexturesAndBackings(textureManager.get()); | 248 prioritizeTexturesAndBackings(textureManager.get()); |
252 for (size_t i = 0; i < maxTextures; ++i) | 249 for (size_t i = 0; i < maxTextures; ++i) |
253 EXPECT_EQ(validateTexture(textures[i], false), i < 4); | 250 EXPECT_EQ(validateTexture(textures[i], false), i < 4); |
254 { | 251 { |
255 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked(&m_proxy); | 252 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; |
256 textureManager->reduceMemory(resourceProvider()); | 253 textureManager->reduceMemory(resourceProvider()); |
257 } | 254 } |
258 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryAboveCutoffBytes()); | 255 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryAboveCutoffBytes()); |
259 | 256 |
260 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(
&m_proxy); | 257 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; |
261 textureManager->clearAllMemory(resourceProvider()); | 258 textureManager->clearAllMemory(resourceProvider()); |
262 } | 259 } |
263 | 260 |
264 TEST_F(PrioritizedTextureTest, textureManagerPartialUpdateTextures) | 261 TEST_F(PrioritizedTextureTest, textureManagerPartialUpdateTextures) |
265 { | 262 { |
266 const size_t maxTextures = 4; | 263 const size_t maxTextures = 4; |
267 const size_t numTextures = 4; | 264 const size_t numTextures = 4; |
268 scoped_ptr<PrioritizedTextureManager> textureManager = createManager(maxText
ures); | 265 scoped_ptr<PrioritizedTextureManager> textureManager = createManager(maxText
ures); |
269 scoped_ptr<PrioritizedTexture> textures[numTextures]; | 266 scoped_ptr<PrioritizedTexture> textures[numTextures]; |
270 scoped_ptr<PrioritizedTexture> moreTextures[numTextures]; | 267 scoped_ptr<PrioritizedTexture> moreTextures[numTextures]; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 EXPECT_TRUE(validateTexture(moreTextures[1], false)); | 307 EXPECT_TRUE(validateTexture(moreTextures[1], false)); |
311 EXPECT_TRUE(validateTexture(moreTextures[2], false)); | 308 EXPECT_TRUE(validateTexture(moreTextures[2], false)); |
312 EXPECT_TRUE(validateTexture(moreTextures[3], false)); | 309 EXPECT_TRUE(validateTexture(moreTextures[3], false)); |
313 | 310 |
314 // Lower priority have been fully evicted. | 311 // Lower priority have been fully evicted. |
315 EXPECT_FALSE(textures[0]->haveBackingTexture()); | 312 EXPECT_FALSE(textures[0]->haveBackingTexture()); |
316 EXPECT_FALSE(textures[1]->haveBackingTexture()); | 313 EXPECT_FALSE(textures[1]->haveBackingTexture()); |
317 EXPECT_FALSE(textures[2]->haveBackingTexture()); | 314 EXPECT_FALSE(textures[2]->haveBackingTexture()); |
318 EXPECT_FALSE(textures[3]->haveBackingTexture()); | 315 EXPECT_FALSE(textures[3]->haveBackingTexture()); |
319 | 316 |
320 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(
&m_proxy); | 317 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; |
321 textureManager->clearAllMemory(resourceProvider()); | 318 textureManager->clearAllMemory(resourceProvider()); |
322 } | 319 } |
323 | 320 |
324 TEST_F(PrioritizedTextureTest, textureManagerPrioritiesAreEqual) | 321 TEST_F(PrioritizedTextureTest, textureManagerPrioritiesAreEqual) |
325 { | 322 { |
326 const size_t maxTextures = 16; | 323 const size_t maxTextures = 16; |
327 scoped_ptr<PrioritizedTextureManager> textureManager = createManager(maxText
ures); | 324 scoped_ptr<PrioritizedTextureManager> textureManager = createManager(maxText
ures); |
328 scoped_ptr<PrioritizedTexture> textures[maxTextures]; | 325 scoped_ptr<PrioritizedTexture> textures[maxTextures]; |
329 | 326 |
330 for (size_t i = 0; i < maxTextures; ++i) | 327 for (size_t i = 0; i < maxTextures; ++i) |
(...skipping 19 matching lines...) Expand all Loading... |
350 | 347 |
351 // 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, |
352 // and on remaining textures up to the memory limit. | 349 // and on remaining textures up to the memory limit. |
353 for (size_t i = 0; i < 8; i++) | 350 for (size_t i = 0; i < 8; i++) |
354 EXPECT_TRUE(validateTexture(textures[i], true)); | 351 EXPECT_TRUE(validateTexture(textures[i], true)); |
355 for (size_t i = 9; i < maxTextures; i++) | 352 for (size_t i = 9; i < maxTextures; i++) |
356 EXPECT_FALSE(validateTexture(textures[i], true)); | 353 EXPECT_FALSE(validateTexture(textures[i], true)); |
357 EXPECT_EQ(texturesMemorySize(8), textureManager->memoryAboveCutoffBytes()); | 354 EXPECT_EQ(texturesMemorySize(8), textureManager->memoryAboveCutoffBytes()); |
358 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); | 355 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); |
359 | 356 |
360 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(
&m_proxy); | 357 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; |
361 textureManager->clearAllMemory(resourceProvider()); | 358 textureManager->clearAllMemory(resourceProvider()); |
362 } | 359 } |
363 | 360 |
364 TEST_F(PrioritizedTextureTest, textureManagerDestroyedFirst) | 361 TEST_F(PrioritizedTextureTest, textureManagerDestroyedFirst) |
365 { | 362 { |
366 scoped_ptr<PrioritizedTextureManager> textureManager = createManager(1); | 363 scoped_ptr<PrioritizedTextureManager> textureManager = createManager(1); |
367 scoped_ptr<PrioritizedTexture> texture = textureManager->createTexture(m_tex
tureSize, m_textureFormat); | 364 scoped_ptr<PrioritizedTexture> texture = textureManager->createTexture(m_tex
tureSize, m_textureFormat); |
368 | 365 |
369 // Texture is initially invalid, but it will become available. | 366 // Texture is initially invalid, but it will become available. |
370 EXPECT_FALSE(texture->haveBackingTexture()); | 367 EXPECT_FALSE(texture->haveBackingTexture()); |
371 | 368 |
372 texture->setRequestPriority(100); | 369 texture->setRequestPriority(100); |
373 prioritizeTexturesAndBackings(textureManager.get()); | 370 prioritizeTexturesAndBackings(textureManager.get()); |
374 | 371 |
375 EXPECT_TRUE(validateTexture(texture, false)); | 372 EXPECT_TRUE(validateTexture(texture, false)); |
376 EXPECT_TRUE(texture->canAcquireBackingTexture()); | 373 EXPECT_TRUE(texture->canAcquireBackingTexture()); |
377 EXPECT_TRUE(texture->haveBackingTexture()); | 374 EXPECT_TRUE(texture->haveBackingTexture()); |
378 | 375 |
379 { | 376 { |
380 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked(&m_proxy); | 377 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; |
381 textureManager->clearAllMemory(resourceProvider()); | 378 textureManager->clearAllMemory(resourceProvider()); |
382 } | 379 } |
383 textureManager.reset(); | 380 textureManager.reset(); |
384 | 381 |
385 EXPECT_FALSE(texture->canAcquireBackingTexture()); | 382 EXPECT_FALSE(texture->canAcquireBackingTexture()); |
386 EXPECT_FALSE(texture->haveBackingTexture()); | 383 EXPECT_FALSE(texture->haveBackingTexture()); |
387 } | 384 } |
388 | 385 |
389 TEST_F(PrioritizedTextureTest, textureMovedToNewManager) | 386 TEST_F(PrioritizedTextureTest, textureMovedToNewManager) |
390 { | 387 { |
391 scoped_ptr<PrioritizedTextureManager> textureManagerOne = createManager(1); | 388 scoped_ptr<PrioritizedTextureManager> textureManagerOne = createManager(1); |
392 scoped_ptr<PrioritizedTextureManager> textureManagerTwo = createManager(1); | 389 scoped_ptr<PrioritizedTextureManager> textureManagerTwo = createManager(1); |
393 scoped_ptr<PrioritizedTexture> texture = textureManagerOne->createTexture(m_
textureSize, m_textureFormat); | 390 scoped_ptr<PrioritizedTexture> texture = textureManagerOne->createTexture(m_
textureSize, m_textureFormat); |
394 | 391 |
395 // Texture is initially invalid, but it will become available. | 392 // Texture is initially invalid, but it will become available. |
396 EXPECT_FALSE(texture->haveBackingTexture()); | 393 EXPECT_FALSE(texture->haveBackingTexture()); |
397 | 394 |
398 texture->setRequestPriority(100); | 395 texture->setRequestPriority(100); |
399 prioritizeTexturesAndBackings(textureManagerOne.get()); | 396 prioritizeTexturesAndBackings(textureManagerOne.get()); |
400 | 397 |
401 EXPECT_TRUE(validateTexture(texture, false)); | 398 EXPECT_TRUE(validateTexture(texture, false)); |
402 EXPECT_TRUE(texture->canAcquireBackingTexture()); | 399 EXPECT_TRUE(texture->canAcquireBackingTexture()); |
403 EXPECT_TRUE(texture->haveBackingTexture()); | 400 EXPECT_TRUE(texture->haveBackingTexture()); |
404 | 401 |
405 texture->setTextureManager(0); | 402 texture->setTextureManager(0); |
406 | 403 |
407 { | 404 { |
408 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked(&m_proxy); | 405 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; |
409 textureManagerOne->clearAllMemory(resourceProvider()); | 406 textureManagerOne->clearAllMemory(resourceProvider()); |
410 } | 407 } |
411 textureManagerOne.reset(); | 408 textureManagerOne.reset(); |
412 | 409 |
413 EXPECT_FALSE(texture->canAcquireBackingTexture()); | 410 EXPECT_FALSE(texture->canAcquireBackingTexture()); |
414 EXPECT_FALSE(texture->haveBackingTexture()); | 411 EXPECT_FALSE(texture->haveBackingTexture()); |
415 | 412 |
416 texture->setTextureManager(textureManagerTwo.get()); | 413 texture->setTextureManager(textureManagerTwo.get()); |
417 | 414 |
418 prioritizeTexturesAndBackings(textureManagerTwo.get()); | 415 prioritizeTexturesAndBackings(textureManagerTwo.get()); |
419 | 416 |
420 EXPECT_TRUE(validateTexture(texture, false)); | 417 EXPECT_TRUE(validateTexture(texture, false)); |
421 EXPECT_TRUE(texture->canAcquireBackingTexture()); | 418 EXPECT_TRUE(texture->canAcquireBackingTexture()); |
422 EXPECT_TRUE(texture->haveBackingTexture()); | 419 EXPECT_TRUE(texture->haveBackingTexture()); |
423 | 420 |
424 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(
&m_proxy); | 421 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; |
425 textureManagerTwo->clearAllMemory(resourceProvider()); | 422 textureManagerTwo->clearAllMemory(resourceProvider()); |
426 } | 423 } |
427 | 424 |
428 TEST_F(PrioritizedTextureTest, renderSurfacesReduceMemoryAvailableOutsideRootSur
face) | 425 TEST_F(PrioritizedTextureTest, renderSurfacesReduceMemoryAvailableOutsideRootSur
face) |
429 { | 426 { |
430 const size_t maxTextures = 8; | 427 const size_t maxTextures = 8; |
431 scoped_ptr<PrioritizedTextureManager> textureManager = createManager(maxText
ures); | 428 scoped_ptr<PrioritizedTextureManager> textureManager = createManager(maxText
ures); |
432 | 429 |
433 // 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) |
434 scoped_ptr<PrioritizedTexture> renderSurfacePlaceHolder = textureManager->cr
eateTexture(m_textureSize, m_textureFormat); | 431 scoped_ptr<PrioritizedTexture> renderSurfacePlaceHolder = textureManager->cr
eateTexture(m_textureSize, m_textureFormat); |
(...skipping 25 matching lines...) Expand all Loading... |
460 prioritizeTexturesAndBackings(textureManager.get()); | 457 prioritizeTexturesAndBackings(textureManager.get()); |
461 EXPECT_FALSE(validateTexture(textures[0], false)); | 458 EXPECT_FALSE(validateTexture(textures[0], false)); |
462 EXPECT_FALSE(validateTexture(textures[3], false)); | 459 EXPECT_FALSE(validateTexture(textures[3], false)); |
463 EXPECT_TRUE(validateTexture(textures[4], false)); | 460 EXPECT_TRUE(validateTexture(textures[4], false)); |
464 EXPECT_TRUE(validateTexture(textures[7], false)); | 461 EXPECT_TRUE(validateTexture(textures[7], false)); |
465 | 462 |
466 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryAboveCutoffBytes()); | 463 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryAboveCutoffBytes()); |
467 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryForSelfManagedTexture
s()); | 464 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryForSelfManagedTexture
s()); |
468 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); | 465 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); |
469 | 466 |
470 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(
&m_proxy); | 467 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; |
471 textureManager->clearAllMemory(resourceProvider()); | 468 textureManager->clearAllMemory(resourceProvider()); |
472 } | 469 } |
473 | 470 |
474 TEST_F(PrioritizedTextureTest, renderSurfacesReduceMemoryAvailableForRequestLate
) | 471 TEST_F(PrioritizedTextureTest, renderSurfacesReduceMemoryAvailableForRequestLate
) |
475 { | 472 { |
476 const size_t maxTextures = 8; | 473 const size_t maxTextures = 8; |
477 scoped_ptr<PrioritizedTextureManager> textureManager = createManager(maxText
ures); | 474 scoped_ptr<PrioritizedTextureManager> textureManager = createManager(maxText
ures); |
478 | 475 |
479 // 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) |
480 scoped_ptr<PrioritizedTexture> renderSurfacePlaceHolder = textureManager->cr
eateTexture(m_textureSize, m_textureFormat); | 477 scoped_ptr<PrioritizedTexture> renderSurfacePlaceHolder = textureManager->cr
eateTexture(m_textureSize, m_textureFormat); |
(...skipping 16 matching lines...) Expand all Loading... |
497 EXPECT_FALSE(validateTexture(textures[i], false)); | 494 EXPECT_FALSE(validateTexture(textures[i], false)); |
498 for (unsigned i = 0; i < maxTextures; i += 2) | 495 for (unsigned i = 0; i < maxTextures; i += 2) |
499 EXPECT_TRUE(validateTexture(textures[i], true)); | 496 EXPECT_TRUE(validateTexture(textures[i], true)); |
500 for (unsigned i = 1; i < maxTextures; i += 2) | 497 for (unsigned i = 1; i < maxTextures; i += 2) |
501 EXPECT_FALSE(validateTexture(textures[i], true)); | 498 EXPECT_FALSE(validateTexture(textures[i], true)); |
502 | 499 |
503 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryAboveCutoffBytes()); | 500 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryAboveCutoffBytes()); |
504 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryForSelfManagedTexture
s()); | 501 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryForSelfManagedTexture
s()); |
505 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); | 502 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); |
506 | 503 |
507 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(
&m_proxy); | 504 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; |
508 textureManager->clearAllMemory(resourceProvider()); | 505 textureManager->clearAllMemory(resourceProvider()); |
509 } | 506 } |
510 | 507 |
511 TEST_F(PrioritizedTextureTest, whenRenderSurfaceNotAvailableTexturesAlsoNotAvail
able) | 508 TEST_F(PrioritizedTextureTest, whenRenderSurfaceNotAvailableTexturesAlsoNotAvail
able) |
512 { | 509 { |
513 const size_t maxTextures = 8; | 510 const size_t maxTextures = 8; |
514 scoped_ptr<PrioritizedTextureManager> textureManager = createManager(maxText
ures); | 511 scoped_ptr<PrioritizedTextureManager> textureManager = createManager(maxText
ures); |
515 | 512 |
516 // 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) |
517 scoped_ptr<PrioritizedTexture> renderSurfacePlaceHolder = textureManager->cr
eateTexture(m_textureSize, m_textureFormat); | 514 scoped_ptr<PrioritizedTexture> renderSurfacePlaceHolder = textureManager->cr
eateTexture(m_textureSize, m_textureFormat); |
(...skipping 19 matching lines...) Expand all Loading... |
537 EXPECT_FALSE(validateTexture(textures[7], true)); | 534 EXPECT_FALSE(validateTexture(textures[7], true)); |
538 | 535 |
539 // Root surface textures are valid. | 536 // Root surface textures are valid. |
540 for (size_t i = 0; i < 6; ++i) | 537 for (size_t i = 0; i < 6; ++i) |
541 EXPECT_TRUE(validateTexture(textures[i], false)); | 538 EXPECT_TRUE(validateTexture(textures[i], false)); |
542 | 539 |
543 EXPECT_EQ(texturesMemorySize(6), textureManager->memoryAboveCutoffBytes()); | 540 EXPECT_EQ(texturesMemorySize(6), textureManager->memoryAboveCutoffBytes()); |
544 EXPECT_EQ(texturesMemorySize(2), textureManager->memoryForSelfManagedTexture
s()); | 541 EXPECT_EQ(texturesMemorySize(2), textureManager->memoryForSelfManagedTexture
s()); |
545 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); | 542 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); |
546 | 543 |
547 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(
&m_proxy); | 544 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; |
548 textureManager->clearAllMemory(resourceProvider()); | 545 textureManager->clearAllMemory(resourceProvider()); |
549 } | 546 } |
550 | 547 |
551 TEST_F(PrioritizedTextureTest, requestLateBackingsSorting) | 548 TEST_F(PrioritizedTextureTest, requestLateBackingsSorting) |
552 { | 549 { |
553 const size_t maxTextures = 8; | 550 const size_t maxTextures = 8; |
554 scoped_ptr<PrioritizedTextureManager> textureManager = createManager(maxText
ures); | 551 scoped_ptr<PrioritizedTextureManager> textureManager = createManager(maxText
ures); |
555 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(maxTextures)); | 552 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(maxTextures)); |
556 | 553 |
557 // Create textures to fill our memory limit. | 554 // Create textures to fill our memory limit. |
(...skipping 27 matching lines...) Expand all Loading... |
585 // Make sure that we have backings for all of the textures. | 582 // Make sure that we have backings for all of the textures. |
586 for (size_t i = 0; i < maxTextures; ++i) | 583 for (size_t i = 0; i < maxTextures; ++i) |
587 EXPECT_TRUE(textures[i]->haveBackingTexture()); | 584 EXPECT_TRUE(textures[i]->haveBackingTexture()); |
588 | 585 |
589 // 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 |
590 for (size_t i = 0; i < maxTextures; i += 2) | 587 for (size_t i = 0; i < maxTextures; i += 2) |
591 EXPECT_TRUE(textureBackingIsAbovePriorityCutoff(textures[i].get())); | 588 EXPECT_TRUE(textureBackingIsAbovePriorityCutoff(textures[i].get())); |
592 for (size_t i = 1; i < maxTextures; i += 2) | 589 for (size_t i = 1; i < maxTextures; i += 2) |
593 EXPECT_FALSE(textureBackingIsAbovePriorityCutoff(textures[i].get())); | 590 EXPECT_FALSE(textureBackingIsAbovePriorityCutoff(textures[i].get())); |
594 | 591 |
595 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(
&m_proxy); | 592 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; |
596 textureManager->clearAllMemory(resourceProvider()); | 593 textureManager->clearAllMemory(resourceProvider()); |
597 } | 594 } |
598 | 595 |
599 TEST_F(PrioritizedTextureTest, clearUploadsToEvictedResources) | 596 TEST_F(PrioritizedTextureTest, clearUploadsToEvictedResources) |
600 { | 597 { |
601 const size_t maxTextures = 4; | 598 const size_t maxTextures = 4; |
602 scoped_ptr<PrioritizedTextureManager> textureManager = | 599 scoped_ptr<PrioritizedTextureManager> textureManager = |
603 createManager(maxTextures); | 600 createManager(maxTextures); |
604 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(maxTextures)); | 601 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(maxTextures)); |
605 | 602 |
606 // Create textures to fill our memory limit. | 603 // Create textures to fill our memory limit. |
607 scoped_ptr<PrioritizedTexture> textures[maxTextures]; | 604 scoped_ptr<PrioritizedTexture> textures[maxTextures]; |
608 | 605 |
609 for (size_t i = 0; i < maxTextures; ++i) | 606 for (size_t i = 0; i < maxTextures; ++i) |
610 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); | 607 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); |
611 | 608 |
612 // Set equal priorities, and allocate backings for all textures. | 609 // Set equal priorities, and allocate backings for all textures. |
613 for (size_t i = 0; i < maxTextures; ++i) | 610 for (size_t i = 0; i < maxTextures; ++i) |
614 textures[i]->setRequestPriority(100); | 611 textures[i]->setRequestPriority(100); |
615 prioritizeTexturesAndBackings(textureManager.get()); | 612 prioritizeTexturesAndBackings(textureManager.get()); |
616 for (unsigned i = 0; i < maxTextures; ++i) | 613 for (unsigned i = 0; i < maxTextures; ++i) |
617 EXPECT_TRUE(validateTexture(textures[i], false)); | 614 EXPECT_TRUE(validateTexture(textures[i], false)); |
618 | 615 |
619 ResourceUpdateQueue queue; | 616 ResourceUpdateQueue queue; |
620 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(
&m_proxy); | 617 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; |
621 for (size_t i = 0; i < maxTextures; ++i) { | 618 for (size_t i = 0; i < maxTextures; ++i) { |
622 const ResourceUpdate upload = ResourceUpdate::Create( | 619 const ResourceUpdate upload = ResourceUpdate::Create( |
623 textures[i].get(), NULL, gfx::Rect(), gfx::Rect(), gfx::Vector2d()); | 620 textures[i].get(), NULL, gfx::Rect(), gfx::Rect(), gfx::Vector2d()); |
624 queue.appendFullUpload(upload); | 621 queue.appendFullUpload(upload); |
625 } | 622 } |
626 | 623 |
627 // Make sure that we have backings for all of the textures. | 624 // Make sure that we have backings for all of the textures. |
628 for (size_t i = 0; i < maxTextures; ++i) | 625 for (size_t i = 0; i < maxTextures; ++i) |
629 EXPECT_TRUE(textures[i]->haveBackingTexture()); | 626 EXPECT_TRUE(textures[i]->haveBackingTexture()); |
630 | 627 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 prioritizeTexturesAndBackings(textureManager.get()); | 659 prioritizeTexturesAndBackings(textureManager.get()); |
663 | 660 |
664 // The first two textures should be available, others should not. | 661 // The first two textures should be available, others should not. |
665 for (size_t i = 0; i < 2; ++i) | 662 for (size_t i = 0; i < 2; ++i) |
666 EXPECT_TRUE(validateTexture(textures[i], false)); | 663 EXPECT_TRUE(validateTexture(textures[i], false)); |
667 for (size_t i = 2; i < maxTextures; ++i) | 664 for (size_t i = 2; i < maxTextures; ++i) |
668 EXPECT_FALSE(validateTexture(textures[i], false)); | 665 EXPECT_FALSE(validateTexture(textures[i], false)); |
669 | 666 |
670 // Validate the statistics. | 667 // Validate the statistics. |
671 { | 668 { |
672 DebugScopedSetImplThread implThread(&m_proxy); | 669 DebugScopedSetImplThread implThread; |
673 EXPECT_EQ(texturesMemorySize(2), textureManager->memoryUseBytes()); | 670 EXPECT_EQ(texturesMemorySize(2), textureManager->memoryUseBytes()); |
674 EXPECT_EQ(texturesMemorySize(1), textureManager->memoryVisibleBytes()); | 671 EXPECT_EQ(texturesMemorySize(1), textureManager->memoryVisibleBytes()); |
675 EXPECT_EQ(texturesMemorySize(3), textureManager->memoryVisibleAndNearbyB
ytes()); | 672 EXPECT_EQ(texturesMemorySize(3), textureManager->memoryVisibleAndNearbyB
ytes()); |
676 } | 673 } |
677 | 674 |
678 // 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. |
679 textures[0]->setRequestPriority(PriorityCalculator::allowVisibleOnlyCutoff()
- 1); | 676 textures[0]->setRequestPriority(PriorityCalculator::allowVisibleOnlyCutoff()
- 1); |
680 textures[1]->setRequestPriority(PriorityCalculator::allowVisibleOnlyCutoff()
- 1); | 677 textures[1]->setRequestPriority(PriorityCalculator::allowVisibleOnlyCutoff()
- 1); |
681 textures[2]->setRequestPriority(PriorityCalculator::allowVisibleOnlyCutoff()
- 1); | 678 textures[2]->setRequestPriority(PriorityCalculator::allowVisibleOnlyCutoff()
- 1); |
682 textures[3]->setRequestPriority(PriorityCalculator::allowVisibleAndNearbyCut
off() - 1); | 679 textures[3]->setRequestPriority(PriorityCalculator::allowVisibleAndNearbyCut
off() - 1); |
683 textures[4]->setRequestPriority(PriorityCalculator::allowVisibleAndNearbyCut
off()); | 680 textures[4]->setRequestPriority(PriorityCalculator::allowVisibleAndNearbyCut
off()); |
684 textureManager->prioritizeTextures(); | 681 textureManager->prioritizeTextures(); |
685 | 682 |
686 // Verify that we still see the old values. | 683 // Verify that we still see the old values. |
687 { | 684 { |
688 DebugScopedSetImplThread implThread(&m_proxy); | 685 DebugScopedSetImplThread implThread; |
689 EXPECT_EQ(texturesMemorySize(2), textureManager->memoryUseBytes()); | 686 EXPECT_EQ(texturesMemorySize(2), textureManager->memoryUseBytes()); |
690 EXPECT_EQ(texturesMemorySize(1), textureManager->memoryVisibleBytes()); | 687 EXPECT_EQ(texturesMemorySize(1), textureManager->memoryVisibleBytes()); |
691 EXPECT_EQ(texturesMemorySize(3), textureManager->memoryVisibleAndNearbyB
ytes()); | 688 EXPECT_EQ(texturesMemorySize(3), textureManager->memoryVisibleAndNearbyB
ytes()); |
692 } | 689 } |
693 | 690 |
694 // Push priorities to backings, and verify we see the new values. | 691 // Push priorities to backings, and verify we see the new values. |
695 { | 692 { |
696 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked(&m_proxy); | 693 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; |
697 textureManager->pushTexturePrioritiesToBackings(); | 694 textureManager->pushTexturePrioritiesToBackings(); |
698 EXPECT_EQ(texturesMemorySize(2), textureManager->memoryUseBytes()); | 695 EXPECT_EQ(texturesMemorySize(2), textureManager->memoryUseBytes()); |
699 EXPECT_EQ(texturesMemorySize(3), textureManager->memoryVisibleBytes()); | 696 EXPECT_EQ(texturesMemorySize(3), textureManager->memoryVisibleBytes()); |
700 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryVisibleAndNearbyB
ytes()); | 697 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryVisibleAndNearbyB
ytes()); |
701 } | 698 } |
702 | 699 |
703 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(
&m_proxy); | 700 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; |
704 textureManager->clearAllMemory(resourceProvider()); | 701 textureManager->clearAllMemory(resourceProvider()); |
705 } | 702 } |
706 | 703 |
707 | 704 |
708 } // namespace | 705 } // namespace |
OLD | NEW |