Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(394)

Side by Side Diff: cc/CCPrioritizedTextureTest.cpp

Issue 10919320: Integrate r128344 and r128253 from WebKit (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/CCPrioritizedTextureManager.cpp ('k') | cc/CCSingleThreadProxy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 6
7 #include "CCPrioritizedTexture.h" 7 #include "CCPrioritizedTexture.h"
8 8
9 #include "CCPrioritizedTextureManager.h" 9 #include "CCPrioritizedTextureManager.h"
10 #include "CCSingleThreadProxy.h" // For DebugScopedSetImplThread 10 #include "CCSingleThreadProxy.h" // For DebugScopedSetImplThread
11 #include "CCTexture.h" 11 #include "CCTexture.h"
12 #include "CCTiledLayerTestCommon.h" 12 #include "CCTiledLayerTestCommon.h"
13 #include "FakeCCGraphicsContext.h" 13 #include "FakeCCGraphicsContext.h"
14 #include "WebCompositorInitializer.h" 14 #include "WebCompositorInitializer.h"
15 #include <gtest/gtest.h> 15 #include <gtest/gtest.h>
16 16
17 using namespace cc; 17 using namespace cc;
18 using namespace WebKitTests; 18 using namespace WebKitTests;
19 using namespace WTF; 19 using namespace WTF;
20 20
21 namespace { 21 namespace WebCore {
jamesr 2012/09/17 18:11:08 is this change deliberate? normally tests are in a
ccameron 2012/09/17 18:15:59 Yes -- I made the test base class a friend of the
jamesr 2012/09/17 18:24:08 It seems to not be quite working: FAILED: clang++
ccameron 2012/09/17 18:30:30 Ack, you're right!
22 22
23 class CCPrioritizedTextureTest : public testing::Test { 23 class CCPrioritizedTextureTest : public testing::Test {
24 public: 24 public:
25 CCPrioritizedTextureTest() 25 CCPrioritizedTextureTest()
26 : m_textureSize(256, 256) 26 : m_textureSize(256, 256)
27 , m_textureFormat(GraphicsContext3D::RGBA) 27 , m_textureFormat(GraphicsContext3D::RGBA)
28 , m_compositorInitializer(0) 28 , m_compositorInitializer(0)
29 , m_context(WebKit::createFakeCCGraphicsContext()) 29 , m_context(WebKit::createFakeCCGraphicsContext())
30 { 30 {
31 DebugScopedSetImplThread implThread; 31 DebugScopedSetImplThread implThread;
(...skipping 11 matching lines...) Expand all
43 return CCTexture::memorySizeBytes(m_textureSize, m_textureFormat) * text ureCount; 43 return CCTexture::memorySizeBytes(m_textureSize, m_textureFormat) * text ureCount;
44 } 44 }
45 45
46 PassOwnPtr<CCPrioritizedTextureManager> createManager(size_t maxTextures) 46 PassOwnPtr<CCPrioritizedTextureManager> createManager(size_t maxTextures)
47 { 47 {
48 return CCPrioritizedTextureManager::create(texturesMemorySize(maxTexture s), 1024, 0); 48 return CCPrioritizedTextureManager::create(texturesMemorySize(maxTexture s), 1024, 0);
49 } 49 }
50 50
51 bool validateTexture(OwnPtr<CCPrioritizedTexture>& texture, bool requestLate ) 51 bool validateTexture(OwnPtr<CCPrioritizedTexture>& texture, bool requestLate )
52 { 52 {
53 #if !ASSERT_DISABLED 53 textureManagerAssertInvariants(texture->textureManager());
54 texture->textureManager()->assertInvariants();
55 #endif
56 if (requestLate) 54 if (requestLate)
57 texture->requestLate(); 55 texture->requestLate();
56 textureManagerAssertInvariants(texture->textureManager());
58 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc ked; 57 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc ked;
59 bool success = texture->canAcquireBackingTexture(); 58 bool success = texture->canAcquireBackingTexture();
60 if (success) 59 if (success)
61 texture->acquireBackingTexture(resourceProvider()); 60 texture->acquireBackingTexture(resourceProvider());
62 return success; 61 return success;
63 } 62 }
64 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
65 CCResourceProvider* resourceProvider() 76 CCResourceProvider* resourceProvider()
66 { 77 {
67 return m_resourceProvider.get(); 78 return m_resourceProvider.get();
68 } 79 }
69 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
70 protected: 94 protected:
71 const IntSize m_textureSize; 95 const IntSize m_textureSize;
72 const GC3Denum m_textureFormat; 96 const GC3Denum m_textureFormat;
73 WebCompositorInitializer m_compositorInitializer; 97 WebCompositorInitializer m_compositorInitializer;
74 OwnPtr<CCGraphicsContext> m_context; 98 OwnPtr<CCGraphicsContext> m_context;
75 OwnPtr<CCResourceProvider> m_resourceProvider; 99 OwnPtr<CCResourceProvider> m_resourceProvider;
76 }; 100 };
77 101
102 }
103
104 namespace {
105
78 TEST_F(CCPrioritizedTextureTest, requestTextureExceedingMaxLimit) 106 TEST_F(CCPrioritizedTextureTest, requestTextureExceedingMaxLimit)
79 { 107 {
80 const size_t maxTextures = 8; 108 const size_t maxTextures = 8;
81 OwnPtr<CCPrioritizedTextureManager> textureManager = createManager(maxTextur es); 109 OwnPtr<CCPrioritizedTextureManager> textureManager = createManager(maxTextur es);
82 110
83 // Create textures for double our memory limit. 111 // Create textures for double our memory limit.
84 OwnPtr<CCPrioritizedTexture> textures[maxTextures*2]; 112 OwnPtr<CCPrioritizedTexture> textures[maxTextures*2];
85 113
86 for (size_t i = 0; i < maxTextures*2; ++i) 114 for (size_t i = 0; i < maxTextures*2; ++i)
87 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm at); 115 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm at);
88 116
89 // Set decreasing priorities 117 // Set decreasing priorities
90 for (size_t i = 0; i < maxTextures*2; ++i) 118 for (size_t i = 0; i < maxTextures*2; ++i)
91 textures[i]->setRequestPriority(100 + i); 119 textures[i]->setRequestPriority(100 + i);
92 120
93 // Only lower half should be available. 121 // Only lower half should be available.
94 textureManager->prioritizeTextures(); 122 prioritizeTexturesAndBackings(textureManager.get());
95 EXPECT_TRUE(validateTexture(textures[0], false)); 123 EXPECT_TRUE(validateTexture(textures[0], false));
96 EXPECT_TRUE(validateTexture(textures[7], false)); 124 EXPECT_TRUE(validateTexture(textures[7], false));
97 EXPECT_FALSE(validateTexture(textures[8], false)); 125 EXPECT_FALSE(validateTexture(textures[8], false));
98 EXPECT_FALSE(validateTexture(textures[15], false)); 126 EXPECT_FALSE(validateTexture(textures[15], false));
99 127
100 // Set increasing priorities 128 // Set increasing priorities
101 for (size_t i = 0; i < maxTextures*2; ++i) 129 for (size_t i = 0; i < maxTextures*2; ++i)
102 textures[i]->setRequestPriority(100 - i); 130 textures[i]->setRequestPriority(100 - i);
103 131
104 // Only upper half should be available. 132 // Only upper half should be available.
105 textureManager->prioritizeTextures(); 133 prioritizeTexturesAndBackings(textureManager.get());
106 EXPECT_FALSE(validateTexture(textures[0], false)); 134 EXPECT_FALSE(validateTexture(textures[0], false));
107 EXPECT_FALSE(validateTexture(textures[7], false)); 135 EXPECT_FALSE(validateTexture(textures[7], false));
108 EXPECT_TRUE(validateTexture(textures[8], false)); 136 EXPECT_TRUE(validateTexture(textures[8], false));
109 EXPECT_TRUE(validateTexture(textures[15], false)); 137 EXPECT_TRUE(validateTexture(textures[15], false));
110 138
111 EXPECT_EQ(texturesMemorySize(maxTextures), textureManager->memoryAboveCutoff Bytes()); 139 EXPECT_EQ(texturesMemorySize(maxTextures), textureManager->memoryAboveCutoff Bytes());
112 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof fBytes()); 140 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof fBytes());
113 141
114 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; 142 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
115 textureManager->clearAllMemory(resourceProvider()); 143 textureManager->clearAllMemory(resourceProvider());
116 } 144 }
117 145
118 TEST_F(CCPrioritizedTextureTest, changeMemoryLimits) 146 TEST_F(CCPrioritizedTextureTest, changeMemoryLimits)
119 { 147 {
120 const size_t maxTextures = 8; 148 const size_t maxTextures = 8;
121 OwnPtr<CCPrioritizedTextureManager> textureManager = createManager(maxTextur es); 149 OwnPtr<CCPrioritizedTextureManager> textureManager = createManager(maxTextur es);
122 OwnPtr<CCPrioritizedTexture> textures[maxTextures]; 150 OwnPtr<CCPrioritizedTexture> textures[maxTextures];
123 151
124 for (size_t i = 0; i < maxTextures; ++i) 152 for (size_t i = 0; i < maxTextures; ++i)
125 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm at); 153 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm at);
126 for (size_t i = 0; i < maxTextures; ++i) 154 for (size_t i = 0; i < maxTextures; ++i)
127 textures[i]->setRequestPriority(100 + i); 155 textures[i]->setRequestPriority(100 + i);
128 156
129 // Set max limit to 8 textures 157 // Set max limit to 8 textures
130 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(8)); 158 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(8));
131 textureManager->prioritizeTextures(); 159 prioritizeTexturesAndBackings(textureManager.get());
132 for (size_t i = 0; i < maxTextures; ++i) 160 for (size_t i = 0; i < maxTextures; ++i)
133 validateTexture(textures[i], false); 161 validateTexture(textures[i], false);
134 { 162 {
135 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc ked; 163 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc ked;
136 textureManager->reduceMemory(resourceProvider()); 164 textureManager->reduceMemory(resourceProvider());
137 } 165 }
138 166
139 EXPECT_EQ(texturesMemorySize(8), textureManager->memoryAboveCutoffBytes()); 167 EXPECT_EQ(texturesMemorySize(8), textureManager->memoryAboveCutoffBytes());
140 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof fBytes()); 168 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof fBytes());
141 169
142 // Set max limit to 5 textures 170 // Set max limit to 5 textures
143 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(5)); 171 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(5));
144 textureManager->prioritizeTextures(); 172 prioritizeTexturesAndBackings(textureManager.get());
145 for (size_t i = 0; i < maxTextures; ++i) 173 for (size_t i = 0; i < maxTextures; ++i)
146 EXPECT_EQ(validateTexture(textures[i], false), i < 5); 174 EXPECT_EQ(validateTexture(textures[i], false), i < 5);
147 { 175 {
148 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc ked; 176 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc ked;
149 textureManager->reduceMemory(resourceProvider()); 177 textureManager->reduceMemory(resourceProvider());
150 } 178 }
151 179
152 EXPECT_EQ(texturesMemorySize(5), textureManager->memoryAboveCutoffBytes()); 180 EXPECT_EQ(texturesMemorySize(5), textureManager->memoryAboveCutoffBytes());
153 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof fBytes()); 181 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof fBytes());
154 182
155 // Set max limit to 4 textures 183 // Set max limit to 4 textures
156 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(4)); 184 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(4));
157 textureManager->prioritizeTextures(); 185 prioritizeTexturesAndBackings(textureManager.get());
158 for (size_t i = 0; i < maxTextures; ++i) 186 for (size_t i = 0; i < maxTextures; ++i)
159 EXPECT_EQ(validateTexture(textures[i], false), i < 4); 187 EXPECT_EQ(validateTexture(textures[i], false), i < 4);
160 { 188 {
161 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc ked; 189 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc ked;
162 textureManager->reduceMemory(resourceProvider()); 190 textureManager->reduceMemory(resourceProvider());
163 } 191 }
164 192
165 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryAboveCutoffBytes()); 193 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryAboveCutoffBytes());
166 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof fBytes()); 194 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof fBytes());
167 195
168 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; 196 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
169 textureManager->clearAllMemory(resourceProvider()); 197 textureManager->clearAllMemory(resourceProvider());
170 } 198 }
171 199
172 TEST_F(CCPrioritizedTextureTest, textureManagerPartialUpdateTextures) 200 TEST_F(CCPrioritizedTextureTest, textureManagerPartialUpdateTextures)
173 { 201 {
174 const size_t maxTextures = 4; 202 const size_t maxTextures = 4;
175 const size_t numTextures = 4; 203 const size_t numTextures = 4;
176 OwnPtr<CCPrioritizedTextureManager> textureManager = createManager(maxTextur es); 204 OwnPtr<CCPrioritizedTextureManager> textureManager = createManager(maxTextur es);
177 OwnPtr<CCPrioritizedTexture> textures[numTextures]; 205 OwnPtr<CCPrioritizedTexture> textures[numTextures];
178 OwnPtr<CCPrioritizedTexture> moreTextures[numTextures]; 206 OwnPtr<CCPrioritizedTexture> moreTextures[numTextures];
179 207
180 for (size_t i = 0; i < numTextures; ++i) { 208 for (size_t i = 0; i < numTextures; ++i) {
181 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm at); 209 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm at);
182 moreTextures[i] = textureManager->createTexture(m_textureSize, m_texture Format); 210 moreTextures[i] = textureManager->createTexture(m_textureSize, m_texture Format);
183 } 211 }
184 212
185 for (size_t i = 0; i < numTextures; ++i) 213 for (size_t i = 0; i < numTextures; ++i)
186 textures[i]->setRequestPriority(200 + i); 214 textures[i]->setRequestPriority(200 + i);
187 textureManager->prioritizeTextures(); 215 prioritizeTexturesAndBackings(textureManager.get());
188 216
189 // Allocate textures which are currently high priority. 217 // Allocate textures which are currently high priority.
190 EXPECT_TRUE(validateTexture(textures[0], false)); 218 EXPECT_TRUE(validateTexture(textures[0], false));
191 EXPECT_TRUE(validateTexture(textures[1], false)); 219 EXPECT_TRUE(validateTexture(textures[1], false));
192 EXPECT_TRUE(validateTexture(textures[2], false)); 220 EXPECT_TRUE(validateTexture(textures[2], false));
193 EXPECT_TRUE(validateTexture(textures[3], false)); 221 EXPECT_TRUE(validateTexture(textures[3], false));
194 222
195 EXPECT_TRUE(textures[0]->haveBackingTexture()); 223 EXPECT_TRUE(textures[0]->haveBackingTexture());
196 EXPECT_TRUE(textures[1]->haveBackingTexture()); 224 EXPECT_TRUE(textures[1]->haveBackingTexture());
197 EXPECT_TRUE(textures[2]->haveBackingTexture()); 225 EXPECT_TRUE(textures[2]->haveBackingTexture());
198 EXPECT_TRUE(textures[3]->haveBackingTexture()); 226 EXPECT_TRUE(textures[3]->haveBackingTexture());
199 227
200 for (size_t i = 0; i < numTextures; ++i) 228 for (size_t i = 0; i < numTextures; ++i)
201 moreTextures[i]->setRequestPriority(100 + i); 229 moreTextures[i]->setRequestPriority(100 + i);
202 textureManager->prioritizeTextures(); 230 prioritizeTexturesAndBackings(textureManager.get());
203 231
204 // Textures are now below cutoff. 232 // Textures are now below cutoff.
205 EXPECT_FALSE(validateTexture(textures[0], false)); 233 EXPECT_FALSE(validateTexture(textures[0], false));
206 EXPECT_FALSE(validateTexture(textures[1], false)); 234 EXPECT_FALSE(validateTexture(textures[1], false));
207 EXPECT_FALSE(validateTexture(textures[2], false)); 235 EXPECT_FALSE(validateTexture(textures[2], false));
208 EXPECT_FALSE(validateTexture(textures[3], false)); 236 EXPECT_FALSE(validateTexture(textures[3], false));
209 237
210 // But they are still valid to use. 238 // But they are still valid to use.
211 EXPECT_TRUE(textures[0]->haveBackingTexture()); 239 EXPECT_TRUE(textures[0]->haveBackingTexture());
212 EXPECT_TRUE(textures[1]->haveBackingTexture()); 240 EXPECT_TRUE(textures[1]->haveBackingTexture());
(...skipping 26 matching lines...) Expand all
239 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm at); 267 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm at);
240 268
241 // All 16 textures have the same priority except 2 higher priority. 269 // All 16 textures have the same priority except 2 higher priority.
242 for (size_t i = 0; i < maxTextures; ++i) 270 for (size_t i = 0; i < maxTextures; ++i)
243 textures[i]->setRequestPriority(100); 271 textures[i]->setRequestPriority(100);
244 textures[0]->setRequestPriority(99); 272 textures[0]->setRequestPriority(99);
245 textures[1]->setRequestPriority(99); 273 textures[1]->setRequestPriority(99);
246 274
247 // Set max limit to 8 textures 275 // Set max limit to 8 textures
248 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(8)); 276 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(8));
249 textureManager->prioritizeTextures(); 277 prioritizeTexturesAndBackings(textureManager.get());
250 278
251 // The two high priority textures should be available, others should not. 279 // The two high priority textures should be available, others should not.
252 for (size_t i = 0; i < 2; ++i) 280 for (size_t i = 0; i < 2; ++i)
253 EXPECT_TRUE(validateTexture(textures[i], false)); 281 EXPECT_TRUE(validateTexture(textures[i], false));
254 for (size_t i = 2; i < maxTextures; ++i) 282 for (size_t i = 2; i < maxTextures; ++i)
255 EXPECT_FALSE(validateTexture(textures[i], false)); 283 EXPECT_FALSE(validateTexture(textures[i], false));
256 EXPECT_EQ(texturesMemorySize(2), textureManager->memoryAboveCutoffBytes()); 284 EXPECT_EQ(texturesMemorySize(2), textureManager->memoryAboveCutoffBytes());
257 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof fBytes()); 285 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof fBytes());
258 286
259 // Manually reserving textures should only succeed on the higher priority te xtures, 287 // Manually reserving textures should only succeed on the higher priority te xtures,
(...skipping 11 matching lines...) Expand all
271 299
272 TEST_F(CCPrioritizedTextureTest, textureManagerDestroyedFirst) 300 TEST_F(CCPrioritizedTextureTest, textureManagerDestroyedFirst)
273 { 301 {
274 OwnPtr<CCPrioritizedTextureManager> textureManager = createManager(1); 302 OwnPtr<CCPrioritizedTextureManager> textureManager = createManager(1);
275 OwnPtr<CCPrioritizedTexture> texture = textureManager->createTexture(m_textu reSize, m_textureFormat); 303 OwnPtr<CCPrioritizedTexture> texture = textureManager->createTexture(m_textu reSize, m_textureFormat);
276 304
277 // Texture is initially invalid, but it will become available. 305 // Texture is initially invalid, but it will become available.
278 EXPECT_FALSE(texture->haveBackingTexture()); 306 EXPECT_FALSE(texture->haveBackingTexture());
279 307
280 texture->setRequestPriority(100); 308 texture->setRequestPriority(100);
281 textureManager->prioritizeTextures(); 309 prioritizeTexturesAndBackings(textureManager.get());
282 310
283 EXPECT_TRUE(validateTexture(texture, false)); 311 EXPECT_TRUE(validateTexture(texture, false));
284 EXPECT_TRUE(texture->canAcquireBackingTexture()); 312 EXPECT_TRUE(texture->canAcquireBackingTexture());
285 EXPECT_TRUE(texture->haveBackingTexture()); 313 EXPECT_TRUE(texture->haveBackingTexture());
286 314
287 { 315 {
288 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc ked; 316 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc ked;
289 textureManager->clearAllMemory(resourceProvider()); 317 textureManager->clearAllMemory(resourceProvider());
290 } 318 }
291 textureManager.clear(); 319 textureManager.clear();
292 320
293 EXPECT_FALSE(texture->canAcquireBackingTexture()); 321 EXPECT_FALSE(texture->canAcquireBackingTexture());
294 EXPECT_FALSE(texture->haveBackingTexture()); 322 EXPECT_FALSE(texture->haveBackingTexture());
295 } 323 }
296 324
297 TEST_F(CCPrioritizedTextureTest, textureMovedToNewManager) 325 TEST_F(CCPrioritizedTextureTest, textureMovedToNewManager)
298 { 326 {
299 OwnPtr<CCPrioritizedTextureManager> textureManagerOne = createManager(1); 327 OwnPtr<CCPrioritizedTextureManager> textureManagerOne = createManager(1);
300 OwnPtr<CCPrioritizedTextureManager> textureManagerTwo = createManager(1); 328 OwnPtr<CCPrioritizedTextureManager> textureManagerTwo = createManager(1);
301 OwnPtr<CCPrioritizedTexture> texture = textureManagerOne->createTexture(m_te xtureSize, m_textureFormat); 329 OwnPtr<CCPrioritizedTexture> texture = textureManagerOne->createTexture(m_te xtureSize, m_textureFormat);
302 330
303 // Texture is initially invalid, but it will become available. 331 // Texture is initially invalid, but it will become available.
304 EXPECT_FALSE(texture->haveBackingTexture()); 332 EXPECT_FALSE(texture->haveBackingTexture());
305 333
306 texture->setRequestPriority(100); 334 texture->setRequestPriority(100);
307 textureManagerOne->prioritizeTextures(); 335 prioritizeTexturesAndBackings(textureManagerOne.get());
308 336
309 EXPECT_TRUE(validateTexture(texture, false)); 337 EXPECT_TRUE(validateTexture(texture, false));
310 EXPECT_TRUE(texture->canAcquireBackingTexture()); 338 EXPECT_TRUE(texture->canAcquireBackingTexture());
311 EXPECT_TRUE(texture->haveBackingTexture()); 339 EXPECT_TRUE(texture->haveBackingTexture());
312 340
313 texture->setTextureManager(0); 341 texture->setTextureManager(0);
314 342
315 { 343 {
316 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc ked; 344 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc ked;
317 textureManagerOne->clearAllMemory(resourceProvider()); 345 textureManagerOne->clearAllMemory(resourceProvider());
318 } 346 }
319 textureManagerOne.clear(); 347 textureManagerOne.clear();
320 348
321 EXPECT_FALSE(texture->canAcquireBackingTexture()); 349 EXPECT_FALSE(texture->canAcquireBackingTexture());
322 EXPECT_FALSE(texture->haveBackingTexture()); 350 EXPECT_FALSE(texture->haveBackingTexture());
323 351
324 texture->setTextureManager(textureManagerTwo.get()); 352 texture->setTextureManager(textureManagerTwo.get());
325 353
326 textureManagerTwo->prioritizeTextures(); 354 prioritizeTexturesAndBackings(textureManagerTwo.get());
327 355
328 EXPECT_TRUE(validateTexture(texture, false)); 356 EXPECT_TRUE(validateTexture(texture, false));
329 EXPECT_TRUE(texture->canAcquireBackingTexture()); 357 EXPECT_TRUE(texture->canAcquireBackingTexture());
330 EXPECT_TRUE(texture->haveBackingTexture()); 358 EXPECT_TRUE(texture->haveBackingTexture());
331 359
332 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; 360 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
333 textureManagerTwo->clearAllMemory(resourceProvider()); 361 textureManagerTwo->clearAllMemory(resourceProvider());
334 } 362 }
335 363
336 TEST_F(CCPrioritizedTextureTest, renderSurfacesReduceMemoryAvailableOutsideRootS urface) 364 TEST_F(CCPrioritizedTextureTest, renderSurfacesReduceMemoryAvailableOutsideRootS urface)
(...skipping 10 matching lines...) Expand all
347 OwnPtr<CCPrioritizedTexture> textures[maxTextures]; 375 OwnPtr<CCPrioritizedTexture> textures[maxTextures];
348 376
349 for (size_t i = 0; i < maxTextures; ++i) 377 for (size_t i = 0; i < maxTextures; ++i)
350 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm at); 378 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm at);
351 379
352 // Set decreasing non-visible priorities outside root surface. 380 // Set decreasing non-visible priorities outside root surface.
353 for (size_t i = 0; i < maxTextures; ++i) 381 for (size_t i = 0; i < maxTextures; ++i)
354 textures[i]->setRequestPriority(100 + i); 382 textures[i]->setRequestPriority(100 + i);
355 383
356 // Only lower half should be available. 384 // Only lower half should be available.
357 textureManager->prioritizeTextures(); 385 prioritizeTexturesAndBackings(textureManager.get());
358 EXPECT_TRUE(validateTexture(textures[0], false)); 386 EXPECT_TRUE(validateTexture(textures[0], false));
359 EXPECT_TRUE(validateTexture(textures[3], false)); 387 EXPECT_TRUE(validateTexture(textures[3], false));
360 EXPECT_FALSE(validateTexture(textures[4], false)); 388 EXPECT_FALSE(validateTexture(textures[4], false));
361 EXPECT_FALSE(validateTexture(textures[7], false)); 389 EXPECT_FALSE(validateTexture(textures[7], false));
362 390
363 // Set increasing non-visible priorities outside root surface. 391 // Set increasing non-visible priorities outside root surface.
364 for (size_t i = 0; i < maxTextures; ++i) 392 for (size_t i = 0; i < maxTextures; ++i)
365 textures[i]->setRequestPriority(100 - i); 393 textures[i]->setRequestPriority(100 - i);
366 394
367 // Only upper half should be available. 395 // Only upper half should be available.
368 textureManager->prioritizeTextures(); 396 prioritizeTexturesAndBackings(textureManager.get());
369 EXPECT_FALSE(validateTexture(textures[0], false)); 397 EXPECT_FALSE(validateTexture(textures[0], false));
370 EXPECT_FALSE(validateTexture(textures[3], false)); 398 EXPECT_FALSE(validateTexture(textures[3], false));
371 EXPECT_TRUE(validateTexture(textures[4], false)); 399 EXPECT_TRUE(validateTexture(textures[4], false));
372 EXPECT_TRUE(validateTexture(textures[7], false)); 400 EXPECT_TRUE(validateTexture(textures[7], false));
373 401
374 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryAboveCutoffBytes()); 402 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryAboveCutoffBytes());
375 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryForSelfManagedTexture s()); 403 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryForSelfManagedTexture s());
376 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof fBytes()); 404 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof fBytes());
377 405
378 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; 406 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
(...skipping 14 matching lines...) Expand all
393 OwnPtr<CCPrioritizedTexture> textures[maxTextures]; 421 OwnPtr<CCPrioritizedTexture> textures[maxTextures];
394 422
395 for (size_t i = 0; i < maxTextures; ++i) 423 for (size_t i = 0; i < maxTextures; ++i)
396 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm at); 424 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm at);
397 425
398 // Set equal priorities. 426 // Set equal priorities.
399 for (size_t i = 0; i < maxTextures; ++i) 427 for (size_t i = 0; i < maxTextures; ++i)
400 textures[i]->setRequestPriority(100); 428 textures[i]->setRequestPriority(100);
401 429
402 // The first four to be requested late will be available. 430 // The first four to be requested late will be available.
403 textureManager->prioritizeTextures(); 431 prioritizeTexturesAndBackings(textureManager.get());
404 for (unsigned i = 0; i < maxTextures; ++i) 432 for (unsigned i = 0; i < maxTextures; ++i)
405 EXPECT_FALSE(validateTexture(textures[i], false)); 433 EXPECT_FALSE(validateTexture(textures[i], false));
406 for (unsigned i = 0; i < maxTextures; i += 2) 434 for (unsigned i = 0; i < maxTextures; i += 2)
407 EXPECT_TRUE(validateTexture(textures[i], true)); 435 EXPECT_TRUE(validateTexture(textures[i], true));
408 for (unsigned i = 1; i < maxTextures; i += 2) 436 for (unsigned i = 1; i < maxTextures; i += 2)
409 EXPECT_FALSE(validateTexture(textures[i], true)); 437 EXPECT_FALSE(validateTexture(textures[i], true));
410 438
411 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryAboveCutoffBytes()); 439 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryAboveCutoffBytes());
412 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryForSelfManagedTexture s()); 440 EXPECT_EQ(texturesMemorySize(4), textureManager->memoryForSelfManagedTexture s());
413 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof fBytes()); 441 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof fBytes());
(...skipping 17 matching lines...) Expand all
431 459
432 for (size_t i = 0; i < maxTextures; ++i) 460 for (size_t i = 0; i < maxTextures; ++i)
433 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm at); 461 textures[i] = textureManager->createTexture(m_textureSize, m_textureForm at);
434 462
435 // Set 6 visible textures in the root surface, and 2 in a child surface. 463 // Set 6 visible textures in the root surface, and 2 in a child surface.
436 for (size_t i = 0; i < 6; ++i) 464 for (size_t i = 0; i < 6; ++i)
437 textures[i]->setRequestPriority(CCPriorityCalculator::visiblePriority(tr ue)); 465 textures[i]->setRequestPriority(CCPriorityCalculator::visiblePriority(tr ue));
438 for (size_t i = 6; i < 8; ++i) 466 for (size_t i = 6; i < 8; ++i)
439 textures[i]->setRequestPriority(CCPriorityCalculator::visiblePriority(fa lse)); 467 textures[i]->setRequestPriority(CCPriorityCalculator::visiblePriority(fa lse));
440 468
441 textureManager->prioritizeTextures(); 469 prioritizeTexturesAndBackings(textureManager.get());
442 470
443 // Unable to requestLate textures in the child surface. 471 // Unable to requestLate textures in the child surface.
444 EXPECT_FALSE(validateTexture(textures[6], true)); 472 EXPECT_FALSE(validateTexture(textures[6], true));
445 EXPECT_FALSE(validateTexture(textures[7], true)); 473 EXPECT_FALSE(validateTexture(textures[7], true));
446 474
447 // Root surface textures are valid. 475 // Root surface textures are valid.
448 for (size_t i = 0; i < 6; ++i) 476 for (size_t i = 0; i < 6; ++i)
449 EXPECT_TRUE(validateTexture(textures[i], false)); 477 EXPECT_TRUE(validateTexture(textures[i], false));
450 478
451 EXPECT_EQ(texturesMemorySize(6), textureManager->memoryAboveCutoffBytes()); 479 EXPECT_EQ(texturesMemorySize(6), textureManager->memoryAboveCutoffBytes());
452 EXPECT_EQ(texturesMemorySize(2), textureManager->memoryForSelfManagedTexture s()); 480 EXPECT_EQ(texturesMemorySize(2), textureManager->memoryForSelfManagedTexture s());
453 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof fBytes()); 481 EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutof fBytes());
454 482
455 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; 483 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked;
456 textureManager->clearAllMemory(resourceProvider()); 484 textureManager->clearAllMemory(resourceProvider());
457 } 485 }
458 486
487 TEST_F(CCPrioritizedTextureTest, requestLateBackingsSorting)
488 {
489 const size_t maxTextures = 8;
490 OwnPtr<CCPrioritizedTextureManager> textureManager = createManager(maxTextur es);
491 textureManager->setMaxMemoryLimitBytes(texturesMemorySize(maxTextures));
492
493 // Create textures to fill our memory limit.
494 OwnPtr<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
459 } // namespace 536 } // namespace
OLDNEW
« no previous file with comments | « cc/CCPrioritizedTextureManager.cpp ('k') | cc/CCSingleThreadProxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698