OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "config.h" | |
6 | |
7 #include "CCPrioritizedTexture.h" | |
8 | |
9 #include "CCPrioritizedTextureManager.h" | |
10 #include "CCSingleThreadProxy.h" // For DebugScopedSetImplThread | |
11 #include "CCTexture.h" | |
12 #include "CCTiledLayerTestCommon.h" | |
13 #include "FakeCCGraphicsContext.h" | |
14 #include "WebCompositorInitializer.h" | |
15 #include "testing/gtest/include/gtest/gtest.h" | |
16 | |
17 using namespace cc; | |
18 using namespace WebKitTests; | |
19 using namespace WTF; | |
20 | |
21 namespace cc { | |
22 | |
23 class CCPrioritizedTextureTest : public testing::Test { | |
24 public: | |
25 CCPrioritizedTextureTest() | |
26 : m_textureSize(256, 256) | |
27 , m_textureFormat(GraphicsContext3D::RGBA) | |
28 , m_compositorInitializer(0) | |
29 , m_context(WebKit::createFakeCCGraphicsContext()) | |
30 { | |
31 DebugScopedSetImplThread implThread; | |
32 m_resourceProvider = CCResourceProvider::create(m_context.get()); | |
33 } | |
34 | |
35 virtual ~CCPrioritizedTextureTest() | |
36 { | |
37 DebugScopedSetImplThread implThread; | |
38 m_resourceProvider.clear(); | |
39 } | |
40 | |
41 size_t texturesMemorySize(size_t textureCount) | |
42 { | |
43 return CCTexture::memorySizeBytes(m_textureSize, m_textureFormat) * text
ureCount; | |
44 } | |
45 | |
46 scoped_ptr<CCPrioritizedTextureManager> createManager(size_t maxTextures) | |
47 { | |
48 return CCPrioritizedTextureManager::create(texturesMemorySize(maxTexture
s), 1024, 0); | |
49 } | |
50 | |
51 bool validateTexture(scoped_ptr<CCPrioritizedTexture>& texture, bool request
Late) | |
52 { | |
53 textureManagerAssertInvariants(texture->textureManager()); | |
54 if (requestLate) | |
55 texture->requestLate(); | |
56 textureManagerAssertInvariants(texture->textureManager()); | |
57 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; | |
58 bool success = texture->canAcquireBackingTexture(); | |
59 if (success) | |
60 texture->acquireBackingTexture(resourceProvider()); | |
61 return success; | |
62 } | |
63 | |
64 void prioritizeTexturesAndBackings(CCPrioritizedTextureManager* textureManag
er) | |
65 { | |
66 textureManager->prioritizeTextures(); | |
67 textureManagerUpdateBackingsPriorities(textureManager); | |
68 } | |
69 | |
70 void textureManagerUpdateBackingsPriorities(CCPrioritizedTextureManager* tex
tureManager) | |
71 { | |
72 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; | |
73 textureManager->updateBackingsPriorities(); | |
74 } | |
75 | |
76 CCResourceProvider* resourceProvider() | |
77 { | |
78 return m_resourceProvider.get(); | |
79 } | |
80 | |
81 void textureManagerAssertInvariants(CCPrioritizedTextureManager* textureMana
ger) | |
82 { | |
83 #if !ASSERT_DISABLED | |
84 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; | |
85 textureManager->assertInvariants(); | |
86 #endif | |
87 } | |
88 | |
89 bool textureBackingIsAbovePriorityCutoff(CCPrioritizedTexture* texture) | |
90 { | |
91 return texture->m_backing->wasAbovePriorityCutoffAtLastPriorityUpdate(); | |
92 } | |
93 | |
94 protected: | |
95 const IntSize m_textureSize; | |
96 const GC3Denum m_textureFormat; | |
97 WebCompositorInitializer m_compositorInitializer; | |
98 scoped_ptr<CCGraphicsContext> m_context; | |
99 OwnPtr<CCResourceProvider> m_resourceProvider; | |
100 }; | |
101 | |
102 } | |
103 | |
104 namespace { | |
105 | |
106 TEST_F(CCPrioritizedTextureTest, requestTextureExceedingMaxLimit) | |
107 { | |
108 const size_t maxTextures = 8; | |
109 scoped_ptr<CCPrioritizedTextureManager> textureManager = createManager(maxTe
xtures); | |
110 | |
111 // Create textures for double our memory limit. | |
112 scoped_ptr<CCPrioritizedTexture> textures[maxTextures*2]; | |
113 | |
114 for (size_t i = 0; i < maxTextures*2; ++i) | |
115 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); | |
116 | |
117 // Set decreasing priorities | |
118 for (size_t i = 0; i < maxTextures*2; ++i) | |
119 textures[i]->setRequestPriority(100 + i); | |
120 | |
121 // Only lower half should be available. | |
122 prioritizeTexturesAndBackings(textureManager.get()); | |
123 EXPECT_TRUE(validateTexture(textures[0], false)); | |
124 EXPECT_TRUE(validateTexture(textures[7], false)); | |
125 EXPECT_FALSE(validateTexture(textures[8], false)); | |
126 EXPECT_FALSE(validateTexture(textures[15], false)); | |
127 | |
128 // Set increasing priorities | |
129 for (size_t i = 0; i < maxTextures*2; ++i) | |
130 textures[i]->setRequestPriority(100 - i); | |
131 | |
132 // Only upper half should be available. | |
133 prioritizeTexturesAndBackings(textureManager.get()); | |
134 EXPECT_FALSE(validateTexture(textures[0], false)); | |
135 EXPECT_FALSE(validateTexture(textures[7], false)); | |
136 EXPECT_TRUE(validateTexture(textures[8], false)); | |
137 EXPECT_TRUE(validateTexture(textures[15], false)); | |
138 | |
139 EXPECT_EQ(texturesMemorySize(maxTextures), textureManager->memoryAboveCutoff
Bytes()); | |
140 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); | |
141 | |
142 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; | |
143 textureManager->clearAllMemory(resourceProvider()); | |
144 } | |
145 | |
146 TEST_F(CCPrioritizedTextureTest, changeMemoryLimits) | |
147 { | |
148 const size_t maxTextures = 8; | |
149 scoped_ptr<CCPrioritizedTextureManager> textureManager = createManager(maxTe
xtures); | |
150 scoped_ptr<CCPrioritizedTexture> textures[maxTextures]; | |
151 | |
152 for (size_t i = 0; i < maxTextures; ++i) | |
153 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); | |
154 for (size_t i = 0; i < maxTextures; ++i) | |
155 textures[i]->setRequestPriority(100 + i); | |
156 | |
157 // Set max limit to 8 textures | |
158 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(8)); | |
159 prioritizeTexturesAndBackings(textureManager.get()); | |
160 for (size_t i = 0; i < maxTextures; ++i) | |
161 validateTexture(textures[i], false); | |
162 { | |
163 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; | |
164 textureManager->reduceMemory(resourceProvider()); | |
165 } | |
166 | |
167 EXPECT_EQ(texturesMemorySize(8), textureManager->memoryAboveCutoffBytes()); | |
168 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); | |
169 | |
170 // Set max limit to 5 textures | |
171 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(5)); | |
172 prioritizeTexturesAndBackings(textureManager.get()); | |
173 for (size_t i = 0; i < maxTextures; ++i) | |
174 EXPECT_EQ(validateTexture(textures[i], false), i < 5); | |
175 { | |
176 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; | |
177 textureManager->reduceMemory(resourceProvider()); | |
178 } | |
179 | |
180 EXPECT_EQ(texturesMemorySize(5), textureManager->memoryAboveCutoffBytes()); | |
181 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); | |
182 | |
183 // Set max limit to 4 textures | |
184 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(4)); | |
185 prioritizeTexturesAndBackings(textureManager.get()); | |
186 for (size_t i = 0; i < maxTextures; ++i) | |
187 EXPECT_EQ(validateTexture(textures[i], false), i < 4); | |
188 { | |
189 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; | |
190 textureManager->reduceMemory(resourceProvider()); | |
191 } | |
192 | |
193 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryAboveCutoffBytes()); | |
194 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); | |
195 | |
196 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; | |
197 textureManager->clearAllMemory(resourceProvider()); | |
198 } | |
199 | |
200 TEST_F(CCPrioritizedTextureTest, textureManagerPartialUpdateTextures) | |
201 { | |
202 const size_t maxTextures = 4; | |
203 const size_t numTextures = 4; | |
204 scoped_ptr<CCPrioritizedTextureManager> textureManager = createManager(maxTe
xtures); | |
205 scoped_ptr<CCPrioritizedTexture> textures[numTextures]; | |
206 scoped_ptr<CCPrioritizedTexture> moreTextures[numTextures]; | |
207 | |
208 for (size_t i = 0; i < numTextures; ++i) { | |
209 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); | |
210 moreTextures[i] = textureManager->createTexture(m_textureSize, m_texture
Format); | |
211 } | |
212 | |
213 for (size_t i = 0; i < numTextures; ++i) | |
214 textures[i]->setRequestPriority(200 + i); | |
215 prioritizeTexturesAndBackings(textureManager.get()); | |
216 | |
217 // Allocate textures which are currently high priority. | |
218 EXPECT_TRUE(validateTexture(textures[0], false)); | |
219 EXPECT_TRUE(validateTexture(textures[1], false)); | |
220 EXPECT_TRUE(validateTexture(textures[2], false)); | |
221 EXPECT_TRUE(validateTexture(textures[3], false)); | |
222 | |
223 EXPECT_TRUE(textures[0]->haveBackingTexture()); | |
224 EXPECT_TRUE(textures[1]->haveBackingTexture()); | |
225 EXPECT_TRUE(textures[2]->haveBackingTexture()); | |
226 EXPECT_TRUE(textures[3]->haveBackingTexture()); | |
227 | |
228 for (size_t i = 0; i < numTextures; ++i) | |
229 moreTextures[i]->setRequestPriority(100 + i); | |
230 prioritizeTexturesAndBackings(textureManager.get()); | |
231 | |
232 // Textures are now below cutoff. | |
233 EXPECT_FALSE(validateTexture(textures[0], false)); | |
234 EXPECT_FALSE(validateTexture(textures[1], false)); | |
235 EXPECT_FALSE(validateTexture(textures[2], false)); | |
236 EXPECT_FALSE(validateTexture(textures[3], false)); | |
237 | |
238 // But they are still valid to use. | |
239 EXPECT_TRUE(textures[0]->haveBackingTexture()); | |
240 EXPECT_TRUE(textures[1]->haveBackingTexture()); | |
241 EXPECT_TRUE(textures[2]->haveBackingTexture()); | |
242 EXPECT_TRUE(textures[3]->haveBackingTexture()); | |
243 | |
244 // Higher priority textures are finally needed. | |
245 EXPECT_TRUE(validateTexture(moreTextures[0], false)); | |
246 EXPECT_TRUE(validateTexture(moreTextures[1], false)); | |
247 EXPECT_TRUE(validateTexture(moreTextures[2], false)); | |
248 EXPECT_TRUE(validateTexture(moreTextures[3], false)); | |
249 | |
250 // Lower priority have been fully evicted. | |
251 EXPECT_FALSE(textures[0]->haveBackingTexture()); | |
252 EXPECT_FALSE(textures[1]->haveBackingTexture()); | |
253 EXPECT_FALSE(textures[2]->haveBackingTexture()); | |
254 EXPECT_FALSE(textures[3]->haveBackingTexture()); | |
255 | |
256 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; | |
257 textureManager->clearAllMemory(resourceProvider()); | |
258 } | |
259 | |
260 TEST_F(CCPrioritizedTextureTest, textureManagerPrioritiesAreEqual) | |
261 { | |
262 const size_t maxTextures = 16; | |
263 scoped_ptr<CCPrioritizedTextureManager> textureManager = createManager(maxTe
xtures); | |
264 scoped_ptr<CCPrioritizedTexture> textures[maxTextures]; | |
265 | |
266 for (size_t i = 0; i < maxTextures; ++i) | |
267 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); | |
268 | |
269 // All 16 textures have the same priority except 2 higher priority. | |
270 for (size_t i = 0; i < maxTextures; ++i) | |
271 textures[i]->setRequestPriority(100); | |
272 textures[0]->setRequestPriority(99); | |
273 textures[1]->setRequestPriority(99); | |
274 | |
275 // Set max limit to 8 textures | |
276 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(8)); | |
277 prioritizeTexturesAndBackings(textureManager.get()); | |
278 | |
279 // The two high priority textures should be available, others should not. | |
280 for (size_t i = 0; i < 2; ++i) | |
281 EXPECT_TRUE(validateTexture(textures[i], false)); | |
282 for (size_t i = 2; i < maxTextures; ++i) | |
283 EXPECT_FALSE(validateTexture(textures[i], false)); | |
284 EXPECT_EQ(texturesMemorySize(2), textureManager->memoryAboveCutoffBytes()); | |
285 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); | |
286 | |
287 // Manually reserving textures should only succeed on the higher priority te
xtures, | |
288 // and on remaining textures up to the memory limit. | |
289 for (size_t i = 0; i < 8; i++) | |
290 EXPECT_TRUE(validateTexture(textures[i], true)); | |
291 for (size_t i = 9; i < maxTextures; i++) | |
292 EXPECT_FALSE(validateTexture(textures[i], true)); | |
293 EXPECT_EQ(texturesMemorySize(8), textureManager->memoryAboveCutoffBytes()); | |
294 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); | |
295 | |
296 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; | |
297 textureManager->clearAllMemory(resourceProvider()); | |
298 } | |
299 | |
300 TEST_F(CCPrioritizedTextureTest, textureManagerDestroyedFirst) | |
301 { | |
302 scoped_ptr<CCPrioritizedTextureManager> textureManager = createManager(1); | |
303 scoped_ptr<CCPrioritizedTexture> texture = textureManager->createTexture(m_t
extureSize, m_textureFormat); | |
304 | |
305 // Texture is initially invalid, but it will become available. | |
306 EXPECT_FALSE(texture->haveBackingTexture()); | |
307 | |
308 texture->setRequestPriority(100); | |
309 prioritizeTexturesAndBackings(textureManager.get()); | |
310 | |
311 EXPECT_TRUE(validateTexture(texture, false)); | |
312 EXPECT_TRUE(texture->canAcquireBackingTexture()); | |
313 EXPECT_TRUE(texture->haveBackingTexture()); | |
314 | |
315 { | |
316 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; | |
317 textureManager->clearAllMemory(resourceProvider()); | |
318 } | |
319 textureManager.reset(); | |
320 | |
321 EXPECT_FALSE(texture->canAcquireBackingTexture()); | |
322 EXPECT_FALSE(texture->haveBackingTexture()); | |
323 } | |
324 | |
325 TEST_F(CCPrioritizedTextureTest, textureMovedToNewManager) | |
326 { | |
327 scoped_ptr<CCPrioritizedTextureManager> textureManagerOne = createManager(1)
; | |
328 scoped_ptr<CCPrioritizedTextureManager> textureManagerTwo = createManager(1)
; | |
329 scoped_ptr<CCPrioritizedTexture> texture = textureManagerOne->createTexture(
m_textureSize, m_textureFormat); | |
330 | |
331 // Texture is initially invalid, but it will become available. | |
332 EXPECT_FALSE(texture->haveBackingTexture()); | |
333 | |
334 texture->setRequestPriority(100); | |
335 prioritizeTexturesAndBackings(textureManagerOne.get()); | |
336 | |
337 EXPECT_TRUE(validateTexture(texture, false)); | |
338 EXPECT_TRUE(texture->canAcquireBackingTexture()); | |
339 EXPECT_TRUE(texture->haveBackingTexture()); | |
340 | |
341 texture->setTextureManager(0); | |
342 | |
343 { | |
344 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; | |
345 textureManagerOne->clearAllMemory(resourceProvider()); | |
346 } | |
347 textureManagerOne.reset(); | |
348 | |
349 EXPECT_FALSE(texture->canAcquireBackingTexture()); | |
350 EXPECT_FALSE(texture->haveBackingTexture()); | |
351 | |
352 texture->setTextureManager(textureManagerTwo.get()); | |
353 | |
354 prioritizeTexturesAndBackings(textureManagerTwo.get()); | |
355 | |
356 EXPECT_TRUE(validateTexture(texture, false)); | |
357 EXPECT_TRUE(texture->canAcquireBackingTexture()); | |
358 EXPECT_TRUE(texture->haveBackingTexture()); | |
359 | |
360 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; | |
361 textureManagerTwo->clearAllMemory(resourceProvider()); | |
362 } | |
363 | |
364 TEST_F(CCPrioritizedTextureTest, renderSurfacesReduceMemoryAvailableOutsideRootS
urface) | |
365 { | |
366 const size_t maxTextures = 8; | |
367 scoped_ptr<CCPrioritizedTextureManager> textureManager = createManager(maxTe
xtures); | |
368 | |
369 // Half of the memory is taken by surfaces (with high priority place-holder) | |
370 scoped_ptr<CCPrioritizedTexture> renderSurfacePlaceHolder = textureManager->
createTexture(m_textureSize, m_textureFormat); | |
371 renderSurfacePlaceHolder->setToSelfManagedMemoryPlaceholder(texturesMemorySi
ze(4)); | |
372 renderSurfacePlaceHolder->setRequestPriority(CCPriorityCalculator::renderSur
facePriority()); | |
373 | |
374 // Create textures to fill our memory limit. | |
375 scoped_ptr<CCPrioritizedTexture> textures[maxTextures]; | |
376 | |
377 for (size_t i = 0; i < maxTextures; ++i) | |
378 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); | |
379 | |
380 // Set decreasing non-visible priorities outside root surface. | |
381 for (size_t i = 0; i < maxTextures; ++i) | |
382 textures[i]->setRequestPriority(100 + i); | |
383 | |
384 // Only lower half should be available. | |
385 prioritizeTexturesAndBackings(textureManager.get()); | |
386 EXPECT_TRUE(validateTexture(textures[0], false)); | |
387 EXPECT_TRUE(validateTexture(textures[3], false)); | |
388 EXPECT_FALSE(validateTexture(textures[4], false)); | |
389 EXPECT_FALSE(validateTexture(textures[7], false)); | |
390 | |
391 // Set increasing non-visible priorities outside root surface. | |
392 for (size_t i = 0; i < maxTextures; ++i) | |
393 textures[i]->setRequestPriority(100 - i); | |
394 | |
395 // Only upper half should be available. | |
396 prioritizeTexturesAndBackings(textureManager.get()); | |
397 EXPECT_FALSE(validateTexture(textures[0], false)); | |
398 EXPECT_FALSE(validateTexture(textures[3], false)); | |
399 EXPECT_TRUE(validateTexture(textures[4], false)); | |
400 EXPECT_TRUE(validateTexture(textures[7], false)); | |
401 | |
402 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryAboveCutoffBytes()); | |
403 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryForSelfManagedTexture
s()); | |
404 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); | |
405 | |
406 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; | |
407 textureManager->clearAllMemory(resourceProvider()); | |
408 } | |
409 | |
410 TEST_F(CCPrioritizedTextureTest, renderSurfacesReduceMemoryAvailableForRequestLa
te) | |
411 { | |
412 const size_t maxTextures = 8; | |
413 scoped_ptr<CCPrioritizedTextureManager> textureManager = createManager(maxTe
xtures); | |
414 | |
415 // Half of the memory is taken by surfaces (with high priority place-holder) | |
416 scoped_ptr<CCPrioritizedTexture> renderSurfacePlaceHolder = textureManager->
createTexture(m_textureSize, m_textureFormat); | |
417 renderSurfacePlaceHolder->setToSelfManagedMemoryPlaceholder(texturesMemorySi
ze(4)); | |
418 renderSurfacePlaceHolder->setRequestPriority(CCPriorityCalculator::renderSur
facePriority()); | |
419 | |
420 // Create textures to fill our memory limit. | |
421 scoped_ptr<CCPrioritizedTexture> textures[maxTextures]; | |
422 | |
423 for (size_t i = 0; i < maxTextures; ++i) | |
424 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); | |
425 | |
426 // Set equal priorities. | |
427 for (size_t i = 0; i < maxTextures; ++i) | |
428 textures[i]->setRequestPriority(100); | |
429 | |
430 // The first four to be requested late will be available. | |
431 prioritizeTexturesAndBackings(textureManager.get()); | |
432 for (unsigned i = 0; i < maxTextures; ++i) | |
433 EXPECT_FALSE(validateTexture(textures[i], false)); | |
434 for (unsigned i = 0; i < maxTextures; i += 2) | |
435 EXPECT_TRUE(validateTexture(textures[i], true)); | |
436 for (unsigned i = 1; i < maxTextures; i += 2) | |
437 EXPECT_FALSE(validateTexture(textures[i], true)); | |
438 | |
439 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryAboveCutoffBytes()); | |
440 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryForSelfManagedTexture
s()); | |
441 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); | |
442 | |
443 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; | |
444 textureManager->clearAllMemory(resourceProvider()); | |
445 } | |
446 | |
447 TEST_F(CCPrioritizedTextureTest, whenRenderSurfaceNotAvailableTexturesAlsoNotAva
ilable) | |
448 { | |
449 const size_t maxTextures = 8; | |
450 scoped_ptr<CCPrioritizedTextureManager> textureManager = createManager(maxTe
xtures); | |
451 | |
452 // Half of the memory is taken by surfaces (with high priority place-holder) | |
453 scoped_ptr<CCPrioritizedTexture> renderSurfacePlaceHolder = textureManager->
createTexture(m_textureSize, m_textureFormat); | |
454 renderSurfacePlaceHolder->setToSelfManagedMemoryPlaceholder(texturesMemorySi
ze(4)); | |
455 renderSurfacePlaceHolder->setRequestPriority(CCPriorityCalculator::renderSur
facePriority()); | |
456 | |
457 // Create textures to fill our memory limit. | |
458 scoped_ptr<CCPrioritizedTexture> textures[maxTextures]; | |
459 | |
460 for (size_t i = 0; i < maxTextures; ++i) | |
461 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); | |
462 | |
463 // Set 6 visible textures in the root surface, and 2 in a child surface. | |
464 for (size_t i = 0; i < 6; ++i) | |
465 textures[i]->setRequestPriority(CCPriorityCalculator::visiblePriority(tr
ue)); | |
466 for (size_t i = 6; i < 8; ++i) | |
467 textures[i]->setRequestPriority(CCPriorityCalculator::visiblePriority(fa
lse)); | |
468 | |
469 prioritizeTexturesAndBackings(textureManager.get()); | |
470 | |
471 // Unable to requestLate textures in the child surface. | |
472 EXPECT_FALSE(validateTexture(textures[6], true)); | |
473 EXPECT_FALSE(validateTexture(textures[7], true)); | |
474 | |
475 // Root surface textures are valid. | |
476 for (size_t i = 0; i < 6; ++i) | |
477 EXPECT_TRUE(validateTexture(textures[i], false)); | |
478 | |
479 EXPECT_EQ(texturesMemorySize(6), textureManager->memoryAboveCutoffBytes()); | |
480 EXPECT_EQ(texturesMemorySize(2), textureManager->memoryForSelfManagedTexture
s()); | |
481 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof
fBytes()); | |
482 | |
483 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; | |
484 textureManager->clearAllMemory(resourceProvider()); | |
485 } | |
486 | |
487 TEST_F(CCPrioritizedTextureTest, requestLateBackingsSorting) | |
488 { | |
489 const size_t maxTextures = 8; | |
490 scoped_ptr<CCPrioritizedTextureManager> textureManager = createManager(maxTe
xtures); | |
491 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(maxTextures)); | |
492 | |
493 // Create textures to fill our memory limit. | |
494 scoped_ptr<CCPrioritizedTexture> textures[maxTextures]; | |
495 for (size_t i = 0; i < maxTextures; ++i) | |
496 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm
at); | |
497 | |
498 // Set equal priorities, and allocate backings for all textures. | |
499 for (size_t i = 0; i < maxTextures; ++i) | |
500 textures[i]->setRequestPriority(100); | |
501 prioritizeTexturesAndBackings(textureManager.get()); | |
502 for (unsigned i = 0; i < maxTextures; ++i) | |
503 EXPECT_TRUE(validateTexture(textures[i], false)); | |
504 | |
505 // Drop the memory limit and prioritize (none will be above the threshold, | |
506 // but they still have backings because reduceMemory hasn't been called). | |
507 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(maxTextures / 2)); | |
508 prioritizeTexturesAndBackings(textureManager.get()); | |
509 | |
510 // Push half of them back over the limit. | |
511 for (size_t i = 0; i < maxTextures; i += 2) | |
512 EXPECT_TRUE(textures[i]->requestLate()); | |
513 | |
514 // Push the priorities to the backings array and sort the backings array | |
515 textureManagerUpdateBackingsPriorities(textureManager.get()); | |
516 | |
517 // Assert that the backings list be sorted with the below-limit backings | |
518 // before the above-limit backings. | |
519 textureManagerAssertInvariants(textureManager.get()); | |
520 | |
521 // Make sure that we have backings for all of the textures. | |
522 for (size_t i = 0; i < maxTextures; ++i) | |
523 EXPECT_TRUE(textures[i]->haveBackingTexture()); | |
524 | |
525 // Make sure that only the requestLate textures are above the priority cutof
f | |
526 for (size_t i = 0; i < maxTextures; i += 2) | |
527 EXPECT_TRUE(textureBackingIsAbovePriorityCutoff(textures[i].get())); | |
528 for (size_t i = 1; i < maxTextures; i += 2) | |
529 EXPECT_FALSE(textureBackingIsAbovePriorityCutoff(textures[i].get())); | |
530 | |
531 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; | |
532 textureManager->clearAllMemory(resourceProvider()); | |
533 } | |
534 | |
535 | |
536 } // namespace | |
OLD | NEW |