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