Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/resources/prioritized_resource.h" | 5 #include "cc/resources/prioritized_resource.h" |
| 6 | 6 |
| 7 #include "cc/resources/prioritized_resource_manager.h" | 7 #include "cc/resources/prioritized_resource_manager.h" |
| 8 #include "cc/resources/resource.h" | 8 #include "cc/resources/resource.h" |
| 9 #include "cc/test/fake_output_surface.h" | 9 #include "cc/test/fake_output_surface.h" |
| 10 #include "cc/test/fake_proxy.h" | 10 #include "cc/test/fake_proxy.h" |
| 11 #include "cc/test/tiled_layer_test_common.h" | 11 #include "cc/test/tiled_layer_test_common.h" |
| 12 #include "cc/trees/single_thread_proxy.h" // For DebugScopedSetImplThread | 12 #include "cc/trees/single_thread_proxy.h" // For DebugScopedSetImplThread |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 14 |
| 15 namespace cc { | 15 namespace cc { |
| 16 | 16 |
| 17 class PrioritizedResourceTest : public testing::Test { | 17 class PrioritizedResourceTest : public testing::Test { |
| 18 public: | 18 public: |
| 19 PrioritizedResourceTest() | 19 PrioritizedResourceTest() |
| 20 : proxy_(scoped_ptr<Thread>(NULL)), | 20 : proxy_(scoped_ptr<Thread>(NULL)), |
| 21 texture_size_(256, 256), | 21 texture_size_(256, 256), |
| 22 texture_format_(GL_RGBA), | 22 texture_format_(GL_RGBA), |
| 23 output_surface_(CreateFakeOutputSurface()) { | 23 output_surface_(CreateFakeOutputSurface()) { |
| 24 DebugScopedSetImplThread impl_thread(&proxy_); | 24 DebugScopedSetImplThread impl_thread(&proxy_); |
| 25 resource_provider_ = cc::ResourceProvider::Create(output_surface_.get()) ; | 25 resource_provider_ = cc::ResourceProvider::Create(output_surface_.get()); |
| 26 } | 26 } |
| 27 | 27 |
| 28 virtual ~PrioritizedResourceTest() { | 28 virtual ~PrioritizedResourceTest() { |
| 29 DebugScopedSetImplThread impl_thread(&proxy_); | 29 DebugScopedSetImplThread impl_thread(&proxy_); |
| 30 resource_provider_.reset(); | 30 resource_provider_.reset(); |
| 31 } | 31 } |
| 32 | 32 |
| 33 size_t TexturesMemorySize(size_t texture_count) { | 33 size_t TexturesMemorySize(size_t texture_count) { |
| 34 return Resource::MemorySizeBytes(texture_size_, texture_format_) * | 34 return Resource::MemorySizeBytes(texture_size_, texture_format_) * |
| 35 texture_count; | 35 texture_count; |
| 36 } | 36 } |
| 37 | 37 |
| 38 scoped_ptr<PrioritizedResourceManager> CreateManager(size_t max_textures) { | 38 scoped_ptr<PrioritizedResourceManager> CreateManager(size_t max_textures) { |
| 39 scoped_ptr<PrioritizedResourceManager> manager = | 39 scoped_ptr<PrioritizedResourceManager> manager = |
| 40 PrioritizedResourceManager::Create(&proxy_); | 40 PrioritizedResourceManager::Create(&proxy_); |
| 41 manager->SetMaxMemoryLimitBytes(TexturesMemorySize(max_textures)); | 41 manager->SetMaxMemoryLimitBytes(TexturesMemorySize(max_textures)); |
| 42 return manager.Pass(); | 42 return manager.Pass(); |
| 43 } | 43 } |
| 44 | 44 |
| 45 bool ValidateTexture(scoped_ptr<PrioritizedResource>& texture, | 45 bool ValidateTexture(scoped_ptr<PrioritizedResource>& texture, |
| 46 bool request_late) { | 46 bool request_late) { |
| 47 ResourceManagerAssertInvariants(texture->resource_manager()); | 47 ResourceManagerAssertInvariants(texture->resource_manager()); |
| 48 if (request_late) | 48 if (request_late) |
| 49 texture->RequestLate(); | 49 texture->RequestLate(); |
| 50 ResourceManagerAssertInvariants(texture->resource_manager()); | 50 ResourceManagerAssertInvariants(texture->resource_manager()); |
| 51 DebugScopedSetImplThreadAndMainThreadBlocked | 51 DebugScopedSetImplThreadAndMainThreadBlocked |
| 52 impl_thread_and_main_thread_blocked(&proxy_); | 52 impl_thread_and_main_thread_blocked(&proxy_); |
| 53 bool success = texture->can_acquire_backing_texture(); | 53 bool success = texture->can_acquire_backing_texture(); |
| 54 if (success) | 54 if (success) |
| 55 texture->AcquireBackingTexture(ResourceProvider()); | 55 texture->AcquireBackingTexture(ResourceProvider()); |
| 56 return success; | 56 return success; |
| 57 } | 57 } |
| 58 | 58 |
| 59 void PrioritizeTexturesAndBackings( | 59 void PrioritizeTexturesAndBackings( |
| 60 PrioritizedResourceManager* resource_manager) { | 60 PrioritizedResourceManager* resource_manager) { |
| 61 resource_manager->PrioritizeTextures(); | 61 resource_manager->PrioritizeTextures(); |
| 62 ResourceManagerUpdateBackingsPriorities(resource_manager); | 62 ResourceManagerUpdateBackingsPriorities(resource_manager); |
| 63 } | 63 } |
| 64 | 64 |
| 65 void ResourceManagerUpdateBackingsPriorities( | 65 void ResourceManagerUpdateBackingsPriorities( |
| 66 PrioritizedResourceManager* resource_manager) { | 66 PrioritizedResourceManager* resource_manager) { |
| 67 DebugScopedSetImplThreadAndMainThreadBlocked | 67 DebugScopedSetImplThreadAndMainThreadBlocked |
| 68 impl_thread_and_main_thread_blocked(&proxy_); | 68 impl_thread_and_main_thread_blocked(&proxy_); |
| 69 resource_manager->PushTexturePrioritiesToBackings(); | 69 resource_manager->PushTexturePrioritiesToBackings(); |
| 70 } | 70 } |
| 71 | 71 |
| 72 cc::ResourceProvider* ResourceProvider() { return resource_provider_.get(); } | 72 cc::ResourceProvider* ResourceProvider() { return resource_provider_.get(); } |
| 73 | 73 |
| 74 void ResourceManagerAssertInvariants( | 74 void ResourceManagerAssertInvariants( |
| 75 PrioritizedResourceManager* resource_manager) { | 75 PrioritizedResourceManager* resource_manager) { |
| 76 #ifndef NDEBUG | 76 #ifndef NDEBUG |
| 77 DebugScopedSetImplThreadAndMainThreadBlocked | 77 DebugScopedSetImplThreadAndMainThreadBlocked |
| 78 impl_thread_and_main_thread_blocked(&proxy_); | 78 impl_thread_and_main_thread_blocked(&proxy_); |
| 79 resource_manager->AssertInvariants(); | 79 resource_manager->AssertInvariants(); |
| 80 #endif | 80 #endif |
| 81 } | 81 } |
| 82 | 82 |
| 83 bool TextureBackingIsAbovePriorityCutoff(PrioritizedResource* texture) { | 83 bool TextureBackingIsAbovePriorityCutoff(PrioritizedResource* texture) { |
| 84 return texture->backing()-> | 84 return texture->backing() |
| 85 was_above_priority_cutoff_at_last_priority_update(); | 85 ->was_above_priority_cutoff_at_last_priority_update(); |
|
danakj
2013/03/25 17:23:31
ಠ_ಠ
| |
| 86 } | 86 } |
| 87 | 87 |
| 88 size_t EvictedBackingCount(PrioritizedResourceManager* resource_manager) { | 88 size_t EvictedBackingCount(PrioritizedResourceManager* resource_manager) { |
| 89 return resource_manager->evicted_backings_.size(); | 89 return resource_manager->evicted_backings_.size(); |
| 90 } | 90 } |
| 91 | 91 |
| 92 protected: | 92 protected: |
| 93 FakeProxy proxy_; | 93 FakeProxy proxy_; |
| 94 const gfx::Size texture_size_; | 94 const gfx::Size texture_size_; |
| 95 const GLenum texture_format_; | 95 const GLenum texture_format_; |
| 96 scoped_ptr<OutputSurface> output_surface_; | 96 scoped_ptr<OutputSurface> output_surface_; |
| 97 scoped_ptr<cc::ResourceProvider> resource_provider_; | 97 scoped_ptr<cc::ResourceProvider> resource_provider_; |
| 98 }; | 98 }; |
| 99 | 99 |
| 100 namespace { | 100 namespace { |
| 101 | 101 |
| 102 TEST_F(PrioritizedResourceTest, RequestTextureExceedingMaxLimit) { | 102 TEST_F(PrioritizedResourceTest, RequestTextureExceedingMaxLimit) { |
| 103 const size_t max_textures = 8; | 103 const size_t max_textures = 8; |
|
danakj
2013/03/25 17:23:31
no const, or kMaxTextures
| |
| 104 scoped_ptr<PrioritizedResourceManager> resource_manager = | 104 scoped_ptr<PrioritizedResourceManager> resource_manager = |
| 105 CreateManager(max_textures); | 105 CreateManager(max_textures); |
| 106 | 106 |
| 107 // Create textures for double our memory limit. | 107 // Create textures for double our memory limit. |
| 108 scoped_ptr<PrioritizedResource> textures[max_textures * 2]; | 108 scoped_ptr<PrioritizedResource> textures[max_textures * 2]; |
| 109 | 109 |
| 110 for (size_t i = 0; i < max_textures * 2; ++i) | 110 for (size_t i = 0; i < max_textures * 2; ++i) |
| 111 textures[i] = | 111 textures[i] = |
| 112 resource_manager->CreateTexture(texture_size_, texture_format_); | 112 resource_manager->CreateTexture(texture_size_, texture_format_); |
| 113 | 113 |
| 114 // Set decreasing priorities | 114 // Set decreasing priorities |
| 115 for (size_t i = 0; i < max_textures * 2; ++i) | 115 for (size_t i = 0; i < max_textures * 2; ++i) |
| 116 textures[i]->set_request_priority(100 + i); | 116 textures[i]->set_request_priority(100 + i); |
| 117 | 117 |
| 118 // Only lower half should be available. | 118 // Only lower half should be available. |
| 119 PrioritizeTexturesAndBackings(resource_manager.get()); | 119 PrioritizeTexturesAndBackings(resource_manager.get()); |
| 120 EXPECT_TRUE(ValidateTexture(textures[0], false)); | 120 EXPECT_TRUE(ValidateTexture(textures[0], false)); |
| 121 EXPECT_TRUE(ValidateTexture(textures[7], false)); | 121 EXPECT_TRUE(ValidateTexture(textures[7], false)); |
| 122 EXPECT_FALSE(ValidateTexture(textures[8], false)); | 122 EXPECT_FALSE(ValidateTexture(textures[8], false)); |
| 123 EXPECT_FALSE(ValidateTexture(textures[15], false)); | 123 EXPECT_FALSE(ValidateTexture(textures[15], false)); |
| 124 | 124 |
| 125 // Set increasing priorities | 125 // Set increasing priorities |
| 126 for (size_t i = 0; i < max_textures * 2; ++i) | 126 for (size_t i = 0; i < max_textures * 2; ++i) |
| 127 textures[i]->set_request_priority(100 - i); | 127 textures[i]->set_request_priority(100 - i); |
| 128 | 128 |
| 129 // Only upper half should be available. | 129 // Only upper half should be available. |
| 130 PrioritizeTexturesAndBackings(resource_manager.get()); | 130 PrioritizeTexturesAndBackings(resource_manager.get()); |
| 131 EXPECT_FALSE(ValidateTexture(textures[0], false)); | 131 EXPECT_FALSE(ValidateTexture(textures[0], false)); |
| 132 EXPECT_FALSE(ValidateTexture(textures[7], false)); | 132 EXPECT_FALSE(ValidateTexture(textures[7], false)); |
| 133 EXPECT_TRUE(ValidateTexture(textures[8], false)); | 133 EXPECT_TRUE(ValidateTexture(textures[8], false)); |
| 134 EXPECT_TRUE(ValidateTexture(textures[15], false)); | 134 EXPECT_TRUE(ValidateTexture(textures[15], false)); |
| 135 | 135 |
| 136 EXPECT_EQ(TexturesMemorySize(max_textures), | 136 EXPECT_EQ(TexturesMemorySize(max_textures), |
| 137 resource_manager->MemoryAboveCutoffBytes()); | 137 resource_manager->MemoryAboveCutoffBytes()); |
| 138 EXPECT_LE(resource_manager->MemoryUseBytes(), | 138 EXPECT_LE(resource_manager->MemoryUseBytes(), |
| 139 resource_manager->MemoryAboveCutoffBytes()); | 139 resource_manager->MemoryAboveCutoffBytes()); |
| 140 | 140 |
| 141 DebugScopedSetImplThreadAndMainThreadBlocked | |
| 142 impl_thread_and_main_thread_blocked(&proxy_); | |
| 143 resource_manager->ClearAllMemory(ResourceProvider()); | |
| 144 } | |
| 145 | |
| 146 TEST_F(PrioritizedResourceTest, ChangeMemoryLimits) { | |
| 147 const size_t max_textures = 8; | |
|
danakj
2013/03/25 17:23:31
const
| |
| 148 scoped_ptr<PrioritizedResourceManager> resource_manager = | |
| 149 CreateManager(max_textures); | |
| 150 scoped_ptr<PrioritizedResource> textures[max_textures]; | |
| 151 | |
| 152 for (size_t i = 0; i < max_textures; ++i) | |
|
danakj
2013/03/25 17:23:31
{}
| |
| 153 textures[i] = | |
| 154 resource_manager->CreateTexture(texture_size_, texture_format_); | |
| 155 for (size_t i = 0; i < max_textures; ++i) | |
| 156 textures[i]->set_request_priority(100 + i); | |
| 157 | |
| 158 // Set max limit to 8 textures | |
| 159 resource_manager->SetMaxMemoryLimitBytes(TexturesMemorySize(8)); | |
| 160 PrioritizeTexturesAndBackings(resource_manager.get()); | |
| 161 for (size_t i = 0; i < max_textures; ++i) | |
| 162 ValidateTexture(textures[i], false); | |
| 163 { | |
| 164 DebugScopedSetImplThreadAndMainThreadBlocked | |
| 165 impl_thread_and_main_thread_blocked(&proxy_); | |
| 166 resource_manager->ReduceMemory(ResourceProvider()); | |
| 167 } | |
| 168 | |
| 169 EXPECT_EQ(TexturesMemorySize(8), resource_manager->MemoryAboveCutoffBytes()); | |
| 170 EXPECT_LE(resource_manager->MemoryUseBytes(), | |
| 171 resource_manager->MemoryAboveCutoffBytes()); | |
| 172 | |
| 173 // Set max limit to 5 textures | |
| 174 resource_manager->SetMaxMemoryLimitBytes(TexturesMemorySize(5)); | |
| 175 PrioritizeTexturesAndBackings(resource_manager.get()); | |
| 176 for (size_t i = 0; i < max_textures; ++i) | |
| 177 EXPECT_EQ(ValidateTexture(textures[i], false), i < 5); | |
| 178 { | |
| 179 DebugScopedSetImplThreadAndMainThreadBlocked | |
| 180 impl_thread_and_main_thread_blocked(&proxy_); | |
| 181 resource_manager->ReduceMemory(ResourceProvider()); | |
| 182 } | |
| 183 | |
| 184 EXPECT_EQ(TexturesMemorySize(5), resource_manager->MemoryAboveCutoffBytes()); | |
| 185 EXPECT_LE(resource_manager->MemoryUseBytes(), | |
| 186 resource_manager->MemoryAboveCutoffBytes()); | |
| 187 | |
| 188 // Set max limit to 4 textures | |
| 189 resource_manager->SetMaxMemoryLimitBytes(TexturesMemorySize(4)); | |
| 190 PrioritizeTexturesAndBackings(resource_manager.get()); | |
| 191 for (size_t i = 0; i < max_textures; ++i) | |
| 192 EXPECT_EQ(ValidateTexture(textures[i], false), i < 4); | |
| 193 { | |
| 194 DebugScopedSetImplThreadAndMainThreadBlocked | |
| 195 impl_thread_and_main_thread_blocked(&proxy_); | |
| 196 resource_manager->ReduceMemory(ResourceProvider()); | |
| 197 } | |
| 198 | |
| 199 EXPECT_EQ(TexturesMemorySize(4), resource_manager->MemoryAboveCutoffBytes()); | |
| 200 EXPECT_LE(resource_manager->MemoryUseBytes(), | |
| 201 resource_manager->MemoryAboveCutoffBytes()); | |
| 202 | |
| 203 DebugScopedSetImplThreadAndMainThreadBlocked | |
| 204 impl_thread_and_main_thread_blocked(&proxy_); | |
| 205 resource_manager->ClearAllMemory(ResourceProvider()); | |
| 206 } | |
| 207 | |
| 208 TEST_F(PrioritizedResourceTest, ChangePriorityCutoff) { | |
| 209 const size_t max_textures = 8; | |
|
danakj
2013/03/25 17:23:31
const
| |
| 210 scoped_ptr<PrioritizedResourceManager> resource_manager = | |
| 211 CreateManager(max_textures); | |
| 212 scoped_ptr<PrioritizedResource> textures[max_textures]; | |
| 213 | |
| 214 for (size_t i = 0; i < max_textures; ++i) | |
|
danakj
2013/03/25 17:23:31
{}
| |
| 215 textures[i] = | |
| 216 resource_manager->CreateTexture(texture_size_, texture_format_); | |
| 217 for (size_t i = 0; i < max_textures; ++i) | |
| 218 textures[i]->set_request_priority(100 + i); | |
| 219 | |
| 220 // Set the cutoff to drop two textures. Try to request_late on all textures, | |
| 221 // and make sure that request_late doesn't work on a texture with equal | |
| 222 // priority to the cutoff. | |
| 223 resource_manager->SetMaxMemoryLimitBytes(TexturesMemorySize(8)); | |
| 224 resource_manager->SetExternalPriorityCutoff(106); | |
| 225 PrioritizeTexturesAndBackings(resource_manager.get()); | |
| 226 for (size_t i = 0; i < max_textures; ++i) | |
| 227 EXPECT_EQ(ValidateTexture(textures[i], true), i < 6); | |
| 228 { | |
| 229 DebugScopedSetImplThreadAndMainThreadBlocked | |
| 230 impl_thread_and_main_thread_blocked(&proxy_); | |
| 231 resource_manager->ReduceMemory(ResourceProvider()); | |
| 232 } | |
| 233 EXPECT_EQ(TexturesMemorySize(6), resource_manager->MemoryAboveCutoffBytes()); | |
| 234 EXPECT_LE(resource_manager->MemoryUseBytes(), | |
| 235 resource_manager->MemoryAboveCutoffBytes()); | |
| 236 | |
| 237 // Set the cutoff to drop two more textures. | |
| 238 resource_manager->SetExternalPriorityCutoff(104); | |
| 239 PrioritizeTexturesAndBackings(resource_manager.get()); | |
| 240 for (size_t i = 0; i < max_textures; ++i) | |
| 241 EXPECT_EQ(ValidateTexture(textures[i], false), i < 4); | |
| 242 { | |
| 243 DebugScopedSetImplThreadAndMainThreadBlocked | |
| 244 impl_thread_and_main_thread_blocked(&proxy_); | |
| 245 resource_manager->ReduceMemory(ResourceProvider()); | |
| 246 } | |
| 247 EXPECT_EQ(TexturesMemorySize(4), resource_manager->MemoryAboveCutoffBytes()); | |
| 248 | |
| 249 // Do a one-time eviction for one more texture based on priority cutoff | |
| 250 PrioritizedResourceManager::BackingList evicted_backings; | |
| 251 resource_manager->UnlinkAndClearEvictedBackings(); | |
| 252 { | |
| 253 DebugScopedSetImplThreadAndMainThreadBlocked | |
| 254 impl_thread_and_main_thread_blocked(&proxy_); | |
| 255 resource_manager->ReduceMemoryOnImplThread( | |
| 256 TexturesMemorySize(8), 104, ResourceProvider()); | |
| 257 EXPECT_EQ(0, EvictedBackingCount(resource_manager.get())); | |
| 258 resource_manager->ReduceMemoryOnImplThread( | |
| 259 TexturesMemorySize(8), 103, ResourceProvider()); | |
| 260 EXPECT_EQ(1, EvictedBackingCount(resource_manager.get())); | |
| 261 } | |
| 262 resource_manager->UnlinkAndClearEvictedBackings(); | |
| 263 EXPECT_EQ(TexturesMemorySize(3), resource_manager->MemoryUseBytes()); | |
| 264 | |
| 265 // Re-allocate the the texture after the one-time drop. | |
| 266 PrioritizeTexturesAndBackings(resource_manager.get()); | |
| 267 for (size_t i = 0; i < max_textures; ++i) | |
| 268 EXPECT_EQ(ValidateTexture(textures[i], false), i < 4); | |
| 269 { | |
| 270 DebugScopedSetImplThreadAndMainThreadBlocked | |
| 271 impl_thread_and_main_thread_blocked(&proxy_); | |
| 272 resource_manager->ReduceMemory(ResourceProvider()); | |
| 273 } | |
| 274 EXPECT_EQ(TexturesMemorySize(4), resource_manager->MemoryAboveCutoffBytes()); | |
| 275 | |
| 276 DebugScopedSetImplThreadAndMainThreadBlocked | |
| 277 impl_thread_and_main_thread_blocked(&proxy_); | |
| 278 resource_manager->ClearAllMemory(ResourceProvider()); | |
| 279 } | |
| 280 | |
| 281 TEST_F(PrioritizedResourceTest, ResourceManagerPartialUpdateTextures) { | |
| 282 const size_t max_textures = 4; | |
|
danakj
2013/03/25 17:23:31
const
| |
| 283 const size_t num_textures = 4; | |
| 284 scoped_ptr<PrioritizedResourceManager> resource_manager = | |
| 285 CreateManager(max_textures); | |
| 286 scoped_ptr<PrioritizedResource> textures[num_textures]; | |
| 287 scoped_ptr<PrioritizedResource> more_textures[num_textures]; | |
| 288 | |
| 289 for (size_t i = 0; i < num_textures; ++i) { | |
| 290 textures[i] = | |
| 291 resource_manager->CreateTexture(texture_size_, texture_format_); | |
| 292 more_textures[i] = | |
| 293 resource_manager->CreateTexture(texture_size_, texture_format_); | |
| 294 } | |
| 295 | |
| 296 for (size_t i = 0; i < num_textures; ++i) | |
| 297 textures[i]->set_request_priority(200 + i); | |
| 298 PrioritizeTexturesAndBackings(resource_manager.get()); | |
| 299 | |
| 300 // Allocate textures which are currently high priority. | |
| 301 EXPECT_TRUE(ValidateTexture(textures[0], false)); | |
| 302 EXPECT_TRUE(ValidateTexture(textures[1], false)); | |
| 303 EXPECT_TRUE(ValidateTexture(textures[2], false)); | |
| 304 EXPECT_TRUE(ValidateTexture(textures[3], false)); | |
| 305 | |
| 306 EXPECT_TRUE(textures[0]->have_backing_texture()); | |
| 307 EXPECT_TRUE(textures[1]->have_backing_texture()); | |
| 308 EXPECT_TRUE(textures[2]->have_backing_texture()); | |
| 309 EXPECT_TRUE(textures[3]->have_backing_texture()); | |
| 310 | |
| 311 for (size_t i = 0; i < num_textures; ++i) | |
| 312 more_textures[i]->set_request_priority(100 + i); | |
| 313 PrioritizeTexturesAndBackings(resource_manager.get()); | |
| 314 | |
| 315 // Textures are now below cutoff. | |
| 316 EXPECT_FALSE(ValidateTexture(textures[0], false)); | |
| 317 EXPECT_FALSE(ValidateTexture(textures[1], false)); | |
| 318 EXPECT_FALSE(ValidateTexture(textures[2], false)); | |
| 319 EXPECT_FALSE(ValidateTexture(textures[3], false)); | |
| 320 | |
| 321 // But they are still valid to use. | |
| 322 EXPECT_TRUE(textures[0]->have_backing_texture()); | |
| 323 EXPECT_TRUE(textures[1]->have_backing_texture()); | |
| 324 EXPECT_TRUE(textures[2]->have_backing_texture()); | |
| 325 EXPECT_TRUE(textures[3]->have_backing_texture()); | |
| 326 | |
| 327 // Higher priority textures are finally needed. | |
| 328 EXPECT_TRUE(ValidateTexture(more_textures[0], false)); | |
| 329 EXPECT_TRUE(ValidateTexture(more_textures[1], false)); | |
| 330 EXPECT_TRUE(ValidateTexture(more_textures[2], false)); | |
| 331 EXPECT_TRUE(ValidateTexture(more_textures[3], false)); | |
| 332 | |
| 333 // Lower priority have been fully evicted. | |
| 334 EXPECT_FALSE(textures[0]->have_backing_texture()); | |
| 335 EXPECT_FALSE(textures[1]->have_backing_texture()); | |
| 336 EXPECT_FALSE(textures[2]->have_backing_texture()); | |
| 337 EXPECT_FALSE(textures[3]->have_backing_texture()); | |
| 338 | |
| 339 DebugScopedSetImplThreadAndMainThreadBlocked | |
| 340 impl_thread_and_main_thread_blocked(&proxy_); | |
| 341 resource_manager->ClearAllMemory(ResourceProvider()); | |
| 342 } | |
| 343 | |
| 344 TEST_F(PrioritizedResourceTest, ResourceManagerPrioritiesAreEqual) { | |
| 345 const size_t max_textures = 16; | |
|
danakj
2013/03/25 17:23:31
const
| |
| 346 scoped_ptr<PrioritizedResourceManager> resource_manager = | |
| 347 CreateManager(max_textures); | |
| 348 scoped_ptr<PrioritizedResource> textures[max_textures]; | |
| 349 | |
| 350 for (size_t i = 0; i < max_textures; ++i) | |
|
danakj
2013/03/25 17:23:31
{}
| |
| 351 textures[i] = | |
| 352 resource_manager->CreateTexture(texture_size_, texture_format_); | |
| 353 | |
| 354 // All 16 textures have the same priority except 2 higher priority. | |
| 355 for (size_t i = 0; i < max_textures; ++i) | |
| 356 textures[i]->set_request_priority(100); | |
| 357 textures[0]->set_request_priority(99); | |
| 358 textures[1]->set_request_priority(99); | |
| 359 | |
| 360 // Set max limit to 8 textures | |
| 361 resource_manager->SetMaxMemoryLimitBytes(TexturesMemorySize(8)); | |
| 362 PrioritizeTexturesAndBackings(resource_manager.get()); | |
| 363 | |
| 364 // The two high priority textures should be available, others should not. | |
| 365 for (size_t i = 0; i < 2; ++i) | |
| 366 EXPECT_TRUE(ValidateTexture(textures[i], false)); | |
| 367 for (size_t i = 2; i < max_textures; ++i) | |
| 368 EXPECT_FALSE(ValidateTexture(textures[i], false)); | |
| 369 EXPECT_EQ(TexturesMemorySize(2), resource_manager->MemoryAboveCutoffBytes()); | |
| 370 EXPECT_LE(resource_manager->MemoryUseBytes(), | |
| 371 resource_manager->MemoryAboveCutoffBytes()); | |
| 372 | |
| 373 // Manually reserving textures should only succeed on the higher priority | |
| 374 // textures, and on remaining textures up to the memory limit. | |
| 375 for (size_t i = 0; i < 8; i++) | |
| 376 EXPECT_TRUE(ValidateTexture(textures[i], true)); | |
| 377 for (size_t i = 9; i < max_textures; i++) | |
| 378 EXPECT_FALSE(ValidateTexture(textures[i], true)); | |
| 379 EXPECT_EQ(TexturesMemorySize(8), resource_manager->MemoryAboveCutoffBytes()); | |
| 380 EXPECT_LE(resource_manager->MemoryUseBytes(), | |
| 381 resource_manager->MemoryAboveCutoffBytes()); | |
| 382 | |
| 383 DebugScopedSetImplThreadAndMainThreadBlocked | |
| 384 impl_thread_and_main_thread_blocked(&proxy_); | |
| 385 resource_manager->ClearAllMemory(ResourceProvider()); | |
| 386 } | |
| 387 | |
| 388 TEST_F(PrioritizedResourceTest, ResourceManagerDestroyedFirst) { | |
| 389 scoped_ptr<PrioritizedResourceManager> resource_manager = CreateManager(1); | |
| 390 scoped_ptr<PrioritizedResource> texture = | |
| 391 resource_manager->CreateTexture(texture_size_, texture_format_); | |
| 392 | |
| 393 // Texture is initially invalid, but it will become available. | |
| 394 EXPECT_FALSE(texture->have_backing_texture()); | |
| 395 | |
| 396 texture->set_request_priority(100); | |
| 397 PrioritizeTexturesAndBackings(resource_manager.get()); | |
| 398 | |
| 399 EXPECT_TRUE(ValidateTexture(texture, false)); | |
| 400 EXPECT_TRUE(texture->can_acquire_backing_texture()); | |
| 401 EXPECT_TRUE(texture->have_backing_texture()); | |
| 402 { | |
| 141 DebugScopedSetImplThreadAndMainThreadBlocked | 403 DebugScopedSetImplThreadAndMainThreadBlocked |
| 142 impl_thread_and_main_thread_blocked(&proxy_); | 404 impl_thread_and_main_thread_blocked(&proxy_); |
| 143 resource_manager->ClearAllMemory(ResourceProvider()); | 405 resource_manager->ClearAllMemory(ResourceProvider()); |
| 144 } | 406 } |
| 145 | 407 resource_manager.reset(); |
| 146 TEST_F(PrioritizedResourceTest, ChangeMemoryLimits) { | 408 |
| 147 const size_t max_textures = 8; | 409 EXPECT_FALSE(texture->can_acquire_backing_texture()); |
| 148 scoped_ptr<PrioritizedResourceManager> resource_manager = | 410 EXPECT_FALSE(texture->have_backing_texture()); |
| 149 CreateManager(max_textures); | |
| 150 scoped_ptr<PrioritizedResource> textures[max_textures]; | |
| 151 | |
| 152 for (size_t i = 0; i < max_textures; ++i) | |
| 153 textures[i] = | |
| 154 resource_manager->CreateTexture(texture_size_, texture_format_); | |
| 155 for (size_t i = 0; i < max_textures; ++i) | |
| 156 textures[i]->set_request_priority(100 + i); | |
| 157 | |
| 158 // Set max limit to 8 textures | |
| 159 resource_manager->SetMaxMemoryLimitBytes(TexturesMemorySize(8)); | |
| 160 PrioritizeTexturesAndBackings(resource_manager.get()); | |
| 161 for (size_t i = 0; i < max_textures; ++i) | |
| 162 ValidateTexture(textures[i], false); { | |
| 163 DebugScopedSetImplThreadAndMainThreadBlocked | |
| 164 impl_thread_and_main_thread_blocked(&proxy_); | |
| 165 resource_manager->ReduceMemory(ResourceProvider()); | |
| 166 } | |
| 167 | |
| 168 EXPECT_EQ(TexturesMemorySize(8), | |
| 169 resource_manager->MemoryAboveCutoffBytes()); | |
| 170 EXPECT_LE(resource_manager->MemoryUseBytes(), | |
| 171 resource_manager->MemoryAboveCutoffBytes()); | |
| 172 | |
| 173 // Set max limit to 5 textures | |
| 174 resource_manager->SetMaxMemoryLimitBytes(TexturesMemorySize(5)); | |
| 175 PrioritizeTexturesAndBackings(resource_manager.get()); | |
| 176 for (size_t i = 0; i < max_textures; ++i) | |
| 177 EXPECT_EQ(ValidateTexture(textures[i], false), i < 5); { | |
| 178 DebugScopedSetImplThreadAndMainThreadBlocked | |
| 179 impl_thread_and_main_thread_blocked(&proxy_); | |
| 180 resource_manager->ReduceMemory(ResourceProvider()); | |
| 181 } | |
| 182 | |
| 183 EXPECT_EQ(TexturesMemorySize(5), | |
| 184 resource_manager->MemoryAboveCutoffBytes()); | |
| 185 EXPECT_LE(resource_manager->MemoryUseBytes(), | |
| 186 resource_manager->MemoryAboveCutoffBytes()); | |
| 187 | |
| 188 // Set max limit to 4 textures | |
| 189 resource_manager->SetMaxMemoryLimitBytes(TexturesMemorySize(4)); | |
| 190 PrioritizeTexturesAndBackings(resource_manager.get()); | |
| 191 for (size_t i = 0; i < max_textures; ++i) | |
| 192 EXPECT_EQ(ValidateTexture(textures[i], false), i < 4); { | |
| 193 DebugScopedSetImplThreadAndMainThreadBlocked | |
| 194 impl_thread_and_main_thread_blocked(&proxy_); | |
| 195 resource_manager->ReduceMemory(ResourceProvider()); | |
| 196 } | |
| 197 | |
| 198 EXPECT_EQ(TexturesMemorySize(4), | |
| 199 resource_manager->MemoryAboveCutoffBytes()); | |
| 200 EXPECT_LE(resource_manager->MemoryUseBytes(), | |
| 201 resource_manager->MemoryAboveCutoffBytes()); | |
| 202 | |
| 203 DebugScopedSetImplThreadAndMainThreadBlocked | |
| 204 impl_thread_and_main_thread_blocked(&proxy_); | |
| 205 resource_manager->ClearAllMemory(ResourceProvider()); | |
| 206 } | |
| 207 | |
| 208 TEST_F(PrioritizedResourceTest, ChangePriorityCutoff) { | |
| 209 const size_t max_textures = 8; | |
| 210 scoped_ptr<PrioritizedResourceManager> resource_manager = | |
| 211 CreateManager(max_textures); | |
| 212 scoped_ptr<PrioritizedResource> textures[max_textures]; | |
| 213 | |
| 214 for (size_t i = 0; i < max_textures; ++i) | |
| 215 textures[i] = | |
| 216 resource_manager->CreateTexture(texture_size_, texture_format_); | |
| 217 for (size_t i = 0; i < max_textures; ++i) | |
| 218 textures[i]->set_request_priority(100 + i); | |
| 219 | |
| 220 // Set the cutoff to drop two textures. Try to request_late on all textures, | |
| 221 // and make sure that request_late doesn't work on a texture with equal | |
| 222 // priority to the cutoff. | |
| 223 resource_manager->SetMaxMemoryLimitBytes(TexturesMemorySize(8)); | |
| 224 resource_manager->SetExternalPriorityCutoff(106); | |
| 225 PrioritizeTexturesAndBackings(resource_manager.get()); | |
| 226 for (size_t i = 0; i < max_textures; ++i) | |
| 227 EXPECT_EQ(ValidateTexture(textures[i], true), i < 6); { | |
| 228 DebugScopedSetImplThreadAndMainThreadBlocked | |
| 229 impl_thread_and_main_thread_blocked(&proxy_); | |
| 230 resource_manager->ReduceMemory(ResourceProvider()); | |
| 231 } | |
| 232 EXPECT_EQ(TexturesMemorySize(6), | |
| 233 resource_manager->MemoryAboveCutoffBytes()); | |
| 234 EXPECT_LE(resource_manager->MemoryUseBytes(), | |
| 235 resource_manager->MemoryAboveCutoffBytes()); | |
| 236 | |
| 237 // Set the cutoff to drop two more textures. | |
| 238 resource_manager->SetExternalPriorityCutoff(104); | |
| 239 PrioritizeTexturesAndBackings(resource_manager.get()); | |
| 240 for (size_t i = 0; i < max_textures; ++i) | |
| 241 EXPECT_EQ(ValidateTexture(textures[i], false), i < 4); { | |
| 242 DebugScopedSetImplThreadAndMainThreadBlocked | |
| 243 impl_thread_and_main_thread_blocked(&proxy_); | |
| 244 resource_manager->ReduceMemory(ResourceProvider()); | |
| 245 } | |
| 246 EXPECT_EQ(TexturesMemorySize(4), | |
| 247 resource_manager->MemoryAboveCutoffBytes()); | |
| 248 | |
| 249 // Do a one-time eviction for one more texture based on priority cutoff | |
| 250 PrioritizedResourceManager::BackingList evicted_backings; | |
| 251 resource_manager->UnlinkAndClearEvictedBackings(); { | |
| 252 DebugScopedSetImplThreadAndMainThreadBlocked | |
| 253 impl_thread_and_main_thread_blocked(&proxy_); | |
| 254 resource_manager->ReduceMemoryOnImplThread( | |
| 255 TexturesMemorySize(8), 104, ResourceProvider()); | |
| 256 EXPECT_EQ(0, EvictedBackingCount(resource_manager.get())); | |
| 257 resource_manager->ReduceMemoryOnImplThread( | |
| 258 TexturesMemorySize(8), 103, ResourceProvider()); | |
| 259 EXPECT_EQ(1, EvictedBackingCount(resource_manager.get())); | |
| 260 } | |
| 261 resource_manager->UnlinkAndClearEvictedBackings(); | |
| 262 EXPECT_EQ(TexturesMemorySize(3), resource_manager->MemoryUseBytes()); | |
| 263 | |
| 264 // Re-allocate the the texture after the one-time drop. | |
| 265 PrioritizeTexturesAndBackings(resource_manager.get()); | |
| 266 for (size_t i = 0; i < max_textures; ++i) | |
| 267 EXPECT_EQ(ValidateTexture(textures[i], false), i < 4); { | |
| 268 DebugScopedSetImplThreadAndMainThreadBlocked | |
| 269 impl_thread_and_main_thread_blocked(&proxy_); | |
| 270 resource_manager->ReduceMemory(ResourceProvider()); | |
| 271 } | |
| 272 EXPECT_EQ(TexturesMemorySize(4), | |
| 273 resource_manager->MemoryAboveCutoffBytes()); | |
| 274 | |
| 275 DebugScopedSetImplThreadAndMainThreadBlocked | |
| 276 impl_thread_and_main_thread_blocked(&proxy_); | |
| 277 resource_manager->ClearAllMemory(ResourceProvider()); | |
| 278 } | |
| 279 | |
| 280 TEST_F(PrioritizedResourceTest, ResourceManagerPartialUpdateTextures) { | |
| 281 const size_t max_textures = 4; | |
| 282 const size_t num_textures = 4; | |
| 283 scoped_ptr<PrioritizedResourceManager> resource_manager = | |
| 284 CreateManager(max_textures); | |
| 285 scoped_ptr<PrioritizedResource> textures[num_textures]; | |
| 286 scoped_ptr<PrioritizedResource> more_textures[num_textures]; | |
| 287 | |
| 288 for (size_t i = 0; i < num_textures; ++i) { | |
| 289 textures[i] = | |
| 290 resource_manager->CreateTexture(texture_size_, texture_format_); | |
| 291 more_textures[i] = | |
| 292 resource_manager->CreateTexture(texture_size_, texture_format_); | |
| 293 } | |
| 294 | |
| 295 for (size_t i = 0; i < num_textures; ++i) | |
| 296 textures[i]->set_request_priority(200 + i); | |
| 297 PrioritizeTexturesAndBackings(resource_manager.get()); | |
| 298 | |
| 299 // Allocate textures which are currently high priority. | |
| 300 EXPECT_TRUE(ValidateTexture(textures[0], false)); | |
| 301 EXPECT_TRUE(ValidateTexture(textures[1], false)); | |
| 302 EXPECT_TRUE(ValidateTexture(textures[2], false)); | |
| 303 EXPECT_TRUE(ValidateTexture(textures[3], false)); | |
| 304 | |
| 305 EXPECT_TRUE(textures[0]->have_backing_texture()); | |
| 306 EXPECT_TRUE(textures[1]->have_backing_texture()); | |
| 307 EXPECT_TRUE(textures[2]->have_backing_texture()); | |
| 308 EXPECT_TRUE(textures[3]->have_backing_texture()); | |
| 309 | |
| 310 for (size_t i = 0; i < num_textures; ++i) | |
| 311 more_textures[i]->set_request_priority(100 + i); | |
| 312 PrioritizeTexturesAndBackings(resource_manager.get()); | |
| 313 | |
| 314 // Textures are now below cutoff. | |
| 315 EXPECT_FALSE(ValidateTexture(textures[0], false)); | |
| 316 EXPECT_FALSE(ValidateTexture(textures[1], false)); | |
| 317 EXPECT_FALSE(ValidateTexture(textures[2], false)); | |
| 318 EXPECT_FALSE(ValidateTexture(textures[3], false)); | |
| 319 | |
| 320 // But they are still valid to use. | |
| 321 EXPECT_TRUE(textures[0]->have_backing_texture()); | |
| 322 EXPECT_TRUE(textures[1]->have_backing_texture()); | |
| 323 EXPECT_TRUE(textures[2]->have_backing_texture()); | |
| 324 EXPECT_TRUE(textures[3]->have_backing_texture()); | |
| 325 | |
| 326 // Higher priority textures are finally needed. | |
| 327 EXPECT_TRUE(ValidateTexture(more_textures[0], false)); | |
| 328 EXPECT_TRUE(ValidateTexture(more_textures[1], false)); | |
| 329 EXPECT_TRUE(ValidateTexture(more_textures[2], false)); | |
| 330 EXPECT_TRUE(ValidateTexture(more_textures[3], false)); | |
| 331 | |
| 332 // Lower priority have been fully evicted. | |
| 333 EXPECT_FALSE(textures[0]->have_backing_texture()); | |
| 334 EXPECT_FALSE(textures[1]->have_backing_texture()); | |
| 335 EXPECT_FALSE(textures[2]->have_backing_texture()); | |
| 336 EXPECT_FALSE(textures[3]->have_backing_texture()); | |
| 337 | |
| 338 DebugScopedSetImplThreadAndMainThreadBlocked | |
| 339 impl_thread_and_main_thread_blocked(&proxy_); | |
| 340 resource_manager->ClearAllMemory(ResourceProvider()); | |
| 341 } | |
| 342 | |
| 343 TEST_F(PrioritizedResourceTest, ResourceManagerPrioritiesAreEqual) { | |
| 344 const size_t max_textures = 16; | |
| 345 scoped_ptr<PrioritizedResourceManager> resource_manager = | |
| 346 CreateManager(max_textures); | |
| 347 scoped_ptr<PrioritizedResource> textures[max_textures]; | |
| 348 | |
| 349 for (size_t i = 0; i < max_textures; ++i) | |
| 350 textures[i] = | |
| 351 resource_manager->CreateTexture(texture_size_, texture_format_); | |
| 352 | |
| 353 // All 16 textures have the same priority except 2 higher priority. | |
| 354 for (size_t i = 0; i < max_textures; ++i) | |
| 355 textures[i]->set_request_priority(100); | |
| 356 textures[0]->set_request_priority(99); | |
| 357 textures[1]->set_request_priority(99); | |
| 358 | |
| 359 // Set max limit to 8 textures | |
| 360 resource_manager->SetMaxMemoryLimitBytes(TexturesMemorySize(8)); | |
| 361 PrioritizeTexturesAndBackings(resource_manager.get()); | |
| 362 | |
| 363 // The two high priority textures should be available, others should not. | |
| 364 for (size_t i = 0; i < 2; ++i) | |
| 365 EXPECT_TRUE(ValidateTexture(textures[i], false)); | |
| 366 for (size_t i = 2; i < max_textures; ++i) | |
| 367 EXPECT_FALSE(ValidateTexture(textures[i], false)); | |
| 368 EXPECT_EQ(TexturesMemorySize(2), | |
| 369 resource_manager->MemoryAboveCutoffBytes()); | |
| 370 EXPECT_LE(resource_manager->MemoryUseBytes(), | |
| 371 resource_manager->MemoryAboveCutoffBytes()); | |
| 372 | |
| 373 // Manually reserving textures should only succeed on the higher priority | |
| 374 // textures, and on remaining textures up to the memory limit. | |
| 375 for (size_t i = 0; i < 8; i++) | |
| 376 EXPECT_TRUE(ValidateTexture(textures[i], true)); | |
| 377 for (size_t i = 9; i < max_textures; i++) | |
| 378 EXPECT_FALSE(ValidateTexture(textures[i], true)); | |
| 379 EXPECT_EQ(TexturesMemorySize(8), | |
| 380 resource_manager->MemoryAboveCutoffBytes()); | |
| 381 EXPECT_LE(resource_manager->MemoryUseBytes(), | |
| 382 resource_manager->MemoryAboveCutoffBytes()); | |
| 383 | |
| 384 DebugScopedSetImplThreadAndMainThreadBlocked | |
| 385 impl_thread_and_main_thread_blocked(&proxy_); | |
| 386 resource_manager->ClearAllMemory(ResourceProvider()); | |
| 387 } | |
| 388 | |
| 389 TEST_F(PrioritizedResourceTest, ResourceManagerDestroyedFirst) { | |
| 390 scoped_ptr<PrioritizedResourceManager> resource_manager = CreateManager(1); | |
| 391 scoped_ptr<PrioritizedResource> texture = | |
| 392 resource_manager->CreateTexture(texture_size_, texture_format_); | |
| 393 | |
| 394 // Texture is initially invalid, but it will become available. | |
| 395 EXPECT_FALSE(texture->have_backing_texture()); | |
| 396 | |
| 397 texture->set_request_priority(100); | |
| 398 PrioritizeTexturesAndBackings(resource_manager.get()); | |
| 399 | |
| 400 EXPECT_TRUE(ValidateTexture(texture, false)); | |
| 401 EXPECT_TRUE(texture->can_acquire_backing_texture()); | |
| 402 EXPECT_TRUE(texture->have_backing_texture()); { | |
| 403 DebugScopedSetImplThreadAndMainThreadBlocked | |
| 404 impl_thread_and_main_thread_blocked(&proxy_); | |
| 405 resource_manager->ClearAllMemory(ResourceProvider()); | |
| 406 } | |
| 407 resource_manager.reset(); | |
| 408 | |
| 409 EXPECT_FALSE(texture->can_acquire_backing_texture()); | |
| 410 EXPECT_FALSE(texture->have_backing_texture()); | |
| 411 } | 411 } |
| 412 | 412 |
| 413 TEST_F(PrioritizedResourceTest, TextureMovedToNewManager) { | 413 TEST_F(PrioritizedResourceTest, TextureMovedToNewManager) { |
| 414 scoped_ptr<PrioritizedResourceManager> resource_manager_one = | 414 scoped_ptr<PrioritizedResourceManager> resource_manager_one = |
| 415 CreateManager(1); | 415 CreateManager(1); |
| 416 scoped_ptr<PrioritizedResourceManager> resource_manager_two = | 416 scoped_ptr<PrioritizedResourceManager> resource_manager_two = |
| 417 CreateManager(1); | 417 CreateManager(1); |
| 418 scoped_ptr<PrioritizedResource> texture = | 418 scoped_ptr<PrioritizedResource> texture = |
| 419 resource_manager_one->CreateTexture(texture_size_, texture_format_); | 419 resource_manager_one->CreateTexture(texture_size_, texture_format_); |
| 420 | 420 |
| 421 // Texture is initially invalid, but it will become available. | 421 // Texture is initially invalid, but it will become available. |
| 422 EXPECT_FALSE(texture->have_backing_texture()); | 422 EXPECT_FALSE(texture->have_backing_texture()); |
| 423 | 423 |
| 424 texture->set_request_priority(100); | 424 texture->set_request_priority(100); |
| 425 PrioritizeTexturesAndBackings(resource_manager_one.get()); | 425 PrioritizeTexturesAndBackings(resource_manager_one.get()); |
| 426 | 426 |
| 427 EXPECT_TRUE(ValidateTexture(texture, false)); | 427 EXPECT_TRUE(ValidateTexture(texture, false)); |
| 428 EXPECT_TRUE(texture->can_acquire_backing_texture()); | 428 EXPECT_TRUE(texture->can_acquire_backing_texture()); |
| 429 EXPECT_TRUE(texture->have_backing_texture()); | 429 EXPECT_TRUE(texture->have_backing_texture()); |
| 430 | 430 |
| 431 texture->SetTextureManager(0); { | 431 texture->SetTextureManager(0); |
|
danakj
2013/03/25 17:23:31
NULL
| |
| 432 DebugScopedSetImplThreadAndMainThreadBlocked | 432 { |
| 433 impl_thread_and_main_thread_blocked(&proxy_); | 433 DebugScopedSetImplThreadAndMainThreadBlocked |
| 434 resource_manager_one->ClearAllMemory(ResourceProvider()); | 434 impl_thread_and_main_thread_blocked(&proxy_); |
| 435 } | 435 resource_manager_one->ClearAllMemory(ResourceProvider()); |
| 436 resource_manager_one.reset(); | 436 } |
| 437 | 437 resource_manager_one.reset(); |
| 438 EXPECT_FALSE(texture->can_acquire_backing_texture()); | 438 |
| 439 EXPECT_FALSE(texture->have_backing_texture()); | 439 EXPECT_FALSE(texture->can_acquire_backing_texture()); |
| 440 | 440 EXPECT_FALSE(texture->have_backing_texture()); |
| 441 texture->SetTextureManager(resource_manager_two.get()); | 441 |
| 442 | 442 texture->SetTextureManager(resource_manager_two.get()); |
| 443 PrioritizeTexturesAndBackings(resource_manager_two.get()); | 443 |
| 444 | 444 PrioritizeTexturesAndBackings(resource_manager_two.get()); |
| 445 EXPECT_TRUE(ValidateTexture(texture, false)); | 445 |
| 446 EXPECT_TRUE(texture->can_acquire_backing_texture()); | 446 EXPECT_TRUE(ValidateTexture(texture, false)); |
| 447 EXPECT_TRUE(texture->have_backing_texture()); | 447 EXPECT_TRUE(texture->can_acquire_backing_texture()); |
| 448 | 448 EXPECT_TRUE(texture->have_backing_texture()); |
| 449 DebugScopedSetImplThreadAndMainThreadBlocked | 449 |
| 450 impl_thread_and_main_thread_blocked(&proxy_); | 450 DebugScopedSetImplThreadAndMainThreadBlocked |
| 451 resource_manager_two->ClearAllMemory(ResourceProvider()); | 451 impl_thread_and_main_thread_blocked(&proxy_); |
| 452 resource_manager_two->ClearAllMemory(ResourceProvider()); | |
| 452 } | 453 } |
| 453 | 454 |
| 454 TEST_F(PrioritizedResourceTest, | 455 TEST_F(PrioritizedResourceTest, |
| 455 RenderSurfacesReduceMemoryAvailableOutsideRootSurface) { | 456 RenderSurfacesReduceMemoryAvailableOutsideRootSurface) { |
| 456 const size_t max_textures = 8; | 457 const size_t max_textures = 8; |
|
danakj
2013/03/25 17:23:31
const
| |
| 457 scoped_ptr<PrioritizedResourceManager> resource_manager = | 458 scoped_ptr<PrioritizedResourceManager> resource_manager = |
| 458 CreateManager(max_textures); | 459 CreateManager(max_textures); |
| 459 | 460 |
| 460 // Half of the memory is taken by surfaces (with high priority place-holder) | 461 // Half of the memory is taken by surfaces (with high priority place-holder) |
| 461 scoped_ptr<PrioritizedResource> render_surface_place_holder = | 462 scoped_ptr<PrioritizedResource> render_surface_place_holder = |
| 462 resource_manager->CreateTexture(texture_size_, texture_format_); | 463 resource_manager->CreateTexture(texture_size_, texture_format_); |
| 463 render_surface_place_holder->SetToSelfManagedMemoryPlaceholder( | 464 render_surface_place_holder->SetToSelfManagedMemoryPlaceholder( |
| 464 TexturesMemorySize(4)); | 465 TexturesMemorySize(4)); |
| 465 render_surface_place_holder->set_request_priority( | 466 render_surface_place_holder->set_request_priority( |
| 466 PriorityCalculator::RenderSurfacePriority()); | 467 PriorityCalculator::RenderSurfacePriority()); |
| 467 | 468 |
| 468 // Create textures to fill our memory limit. | 469 // Create textures to fill our memory limit. |
| 469 scoped_ptr<PrioritizedResource> textures[max_textures]; | 470 scoped_ptr<PrioritizedResource> textures[max_textures]; |
| 470 | 471 |
| 471 for (size_t i = 0; i < max_textures; ++i) | 472 for (size_t i = 0; i < max_textures; ++i) |
|
danakj
2013/03/25 17:23:31
{}
| |
| 472 textures[i] = | 473 textures[i] = |
| 473 resource_manager->CreateTexture(texture_size_, texture_format_); | 474 resource_manager->CreateTexture(texture_size_, texture_format_); |
| 474 | 475 |
| 475 // Set decreasing non-visible priorities outside root surface. | 476 // Set decreasing non-visible priorities outside root surface. |
| 476 for (size_t i = 0; i < max_textures; ++i) | 477 for (size_t i = 0; i < max_textures; ++i) |
| 477 textures[i]->set_request_priority(100 + i); | 478 textures[i]->set_request_priority(100 + i); |
| 478 | 479 |
| 479 // Only lower half should be available. | 480 // Only lower half should be available. |
| 480 PrioritizeTexturesAndBackings(resource_manager.get()); | 481 PrioritizeTexturesAndBackings(resource_manager.get()); |
| 481 EXPECT_TRUE(ValidateTexture(textures[0], false)); | 482 EXPECT_TRUE(ValidateTexture(textures[0], false)); |
| 482 EXPECT_TRUE(ValidateTexture(textures[3], false)); | 483 EXPECT_TRUE(ValidateTexture(textures[3], false)); |
| 483 EXPECT_FALSE(ValidateTexture(textures[4], false)); | 484 EXPECT_FALSE(ValidateTexture(textures[4], false)); |
| 484 EXPECT_FALSE(ValidateTexture(textures[7], false)); | 485 EXPECT_FALSE(ValidateTexture(textures[7], false)); |
| 485 | 486 |
| 486 // Set increasing non-visible priorities outside root surface. | 487 // Set increasing non-visible priorities outside root surface. |
| 487 for (size_t i = 0; i < max_textures; ++i) | 488 for (size_t i = 0; i < max_textures; ++i) |
| 488 textures[i]->set_request_priority(100 - i); | 489 textures[i]->set_request_priority(100 - i); |
| 489 | 490 |
| 490 // Only upper half should be available. | 491 // Only upper half should be available. |
| 491 PrioritizeTexturesAndBackings(resource_manager.get()); | 492 PrioritizeTexturesAndBackings(resource_manager.get()); |
| 492 EXPECT_FALSE(ValidateTexture(textures[0], false)); | 493 EXPECT_FALSE(ValidateTexture(textures[0], false)); |
| 493 EXPECT_FALSE(ValidateTexture(textures[3], false)); | 494 EXPECT_FALSE(ValidateTexture(textures[3], false)); |
| 494 EXPECT_TRUE(ValidateTexture(textures[4], false)); | 495 EXPECT_TRUE(ValidateTexture(textures[4], false)); |
| 495 EXPECT_TRUE(ValidateTexture(textures[7], false)); | 496 EXPECT_TRUE(ValidateTexture(textures[7], false)); |
| 496 | 497 |
| 497 EXPECT_EQ(TexturesMemorySize(4), | 498 EXPECT_EQ(TexturesMemorySize(4), resource_manager->MemoryAboveCutoffBytes()); |
| 498 resource_manager->MemoryAboveCutoffBytes()); | 499 EXPECT_EQ(TexturesMemorySize(4), |
| 499 EXPECT_EQ(TexturesMemorySize(4), | 500 resource_manager->MemoryForSelfManagedTextures()); |
| 500 resource_manager->MemoryForSelfManagedTextures()); | 501 EXPECT_LE(resource_manager->MemoryUseBytes(), |
| 501 EXPECT_LE(resource_manager->MemoryUseBytes(), | 502 resource_manager->MemoryAboveCutoffBytes()); |
| 502 resource_manager->MemoryAboveCutoffBytes()); | 503 |
| 503 | 504 DebugScopedSetImplThreadAndMainThreadBlocked |
| 504 DebugScopedSetImplThreadAndMainThreadBlocked | 505 impl_thread_and_main_thread_blocked(&proxy_); |
| 505 impl_thread_and_main_thread_blocked(&proxy_); | 506 resource_manager->ClearAllMemory(ResourceProvider()); |
| 506 resource_manager->ClearAllMemory(ResourceProvider()); | |
| 507 } | 507 } |
| 508 | 508 |
| 509 TEST_F(PrioritizedResourceTest, | 509 TEST_F(PrioritizedResourceTest, |
| 510 RenderSurfacesReduceMemoryAvailableForRequestLate) { | 510 RenderSurfacesReduceMemoryAvailableForRequestLate) { |
| 511 const size_t max_textures = 8; | 511 const size_t max_textures = 8; |
|
danakj
2013/03/25 17:23:31
const
| |
| 512 scoped_ptr<PrioritizedResourceManager> resource_manager = | 512 scoped_ptr<PrioritizedResourceManager> resource_manager = |
| 513 CreateManager(max_textures); | 513 CreateManager(max_textures); |
| 514 | 514 |
| 515 // Half of the memory is taken by surfaces (with high priority place-holder) | 515 // Half of the memory is taken by surfaces (with high priority place-holder) |
| 516 scoped_ptr<PrioritizedResource> render_surface_place_holder = | 516 scoped_ptr<PrioritizedResource> render_surface_place_holder = |
| 517 resource_manager->CreateTexture(texture_size_, texture_format_); | 517 resource_manager->CreateTexture(texture_size_, texture_format_); |
| 518 render_surface_place_holder->SetToSelfManagedMemoryPlaceholder( | 518 render_surface_place_holder->SetToSelfManagedMemoryPlaceholder( |
| 519 TexturesMemorySize(4)); | 519 TexturesMemorySize(4)); |
| 520 render_surface_place_holder->set_request_priority( | 520 render_surface_place_holder->set_request_priority( |
| 521 PriorityCalculator::RenderSurfacePriority()); | 521 PriorityCalculator::RenderSurfacePriority()); |
| 522 | 522 |
| 523 // Create textures to fill our memory limit. | 523 // Create textures to fill our memory limit. |
| 524 scoped_ptr<PrioritizedResource> textures[max_textures]; | 524 scoped_ptr<PrioritizedResource> textures[max_textures]; |
| 525 | 525 |
| 526 for (size_t i = 0; i < max_textures; ++i) | 526 for (size_t i = 0; i < max_textures; ++i) |
|
danakj
2013/03/25 17:23:31
{}
| |
| 527 textures[i] = | 527 textures[i] = |
| 528 resource_manager->CreateTexture(texture_size_, texture_format_); | 528 resource_manager->CreateTexture(texture_size_, texture_format_); |
| 529 | 529 |
| 530 // Set equal priorities. | 530 // Set equal priorities. |
| 531 for (size_t i = 0; i < max_textures; ++i) | 531 for (size_t i = 0; i < max_textures; ++i) |
| 532 textures[i]->set_request_priority(100); | 532 textures[i]->set_request_priority(100); |
| 533 | 533 |
| 534 // The first four to be requested late will be available. | 534 // The first four to be requested late will be available. |
| 535 PrioritizeTexturesAndBackings(resource_manager.get()); | 535 PrioritizeTexturesAndBackings(resource_manager.get()); |
| 536 for (unsigned i = 0; i < max_textures; ++i) | 536 for (unsigned i = 0; i < max_textures; ++i) |
| 537 EXPECT_FALSE(ValidateTexture(textures[i], false)); | 537 EXPECT_FALSE(ValidateTexture(textures[i], false)); |
| 538 for (unsigned i = 0; i < max_textures; i += 2) | 538 for (unsigned i = 0; i < max_textures; i += 2) |
| 539 EXPECT_TRUE(ValidateTexture(textures[i], true)); | 539 EXPECT_TRUE(ValidateTexture(textures[i], true)); |
| 540 for (unsigned i = 1; i < max_textures; i += 2) | 540 for (unsigned i = 1; i < max_textures; i += 2) |
| 541 EXPECT_FALSE(ValidateTexture(textures[i], true)); | 541 EXPECT_FALSE(ValidateTexture(textures[i], true)); |
| 542 | 542 |
| 543 EXPECT_EQ(TexturesMemorySize(4), | 543 EXPECT_EQ(TexturesMemorySize(4), resource_manager->MemoryAboveCutoffBytes()); |
| 544 resource_manager->MemoryAboveCutoffBytes()); | 544 EXPECT_EQ(TexturesMemorySize(4), |
| 545 EXPECT_EQ(TexturesMemorySize(4), | 545 resource_manager->MemoryForSelfManagedTextures()); |
| 546 resource_manager->MemoryForSelfManagedTextures()); | 546 EXPECT_LE(resource_manager->MemoryUseBytes(), |
| 547 EXPECT_LE(resource_manager->MemoryUseBytes(), | 547 resource_manager->MemoryAboveCutoffBytes()); |
| 548 resource_manager->MemoryAboveCutoffBytes()); | 548 |
| 549 | 549 DebugScopedSetImplThreadAndMainThreadBlocked |
| 550 DebugScopedSetImplThreadAndMainThreadBlocked | 550 impl_thread_and_main_thread_blocked(&proxy_); |
| 551 impl_thread_and_main_thread_blocked(&proxy_); | 551 resource_manager->ClearAllMemory(ResourceProvider()); |
| 552 resource_manager->ClearAllMemory(ResourceProvider()); | |
| 553 } | 552 } |
| 554 | 553 |
| 555 TEST_F(PrioritizedResourceTest, | 554 TEST_F(PrioritizedResourceTest, |
| 556 WhenRenderSurfaceNotAvailableTexturesAlsoNotAvailable) { | 555 WhenRenderSurfaceNotAvailableTexturesAlsoNotAvailable) { |
| 557 const size_t max_textures = 8; | 556 const size_t max_textures = 8; |
|
danakj
2013/03/25 17:23:31
const
| |
| 558 scoped_ptr<PrioritizedResourceManager> resource_manager = | 557 scoped_ptr<PrioritizedResourceManager> resource_manager = |
| 559 CreateManager(max_textures); | 558 CreateManager(max_textures); |
| 560 | 559 |
| 561 // Half of the memory is taken by surfaces (with high priority place-holder) | 560 // Half of the memory is taken by surfaces (with high priority place-holder) |
| 562 scoped_ptr<PrioritizedResource> render_surface_place_holder = | 561 scoped_ptr<PrioritizedResource> render_surface_place_holder = |
| 563 resource_manager->CreateTexture(texture_size_, texture_format_); | 562 resource_manager->CreateTexture(texture_size_, texture_format_); |
| 564 render_surface_place_holder->SetToSelfManagedMemoryPlaceholder( | 563 render_surface_place_holder->SetToSelfManagedMemoryPlaceholder( |
| 565 TexturesMemorySize(4)); | 564 TexturesMemorySize(4)); |
| 566 render_surface_place_holder->set_request_priority( | 565 render_surface_place_holder->set_request_priority( |
| 567 PriorityCalculator::RenderSurfacePriority()); | 566 PriorityCalculator::RenderSurfacePriority()); |
| 568 | 567 |
| 569 // Create textures to fill our memory limit. | 568 // Create textures to fill our memory limit. |
| 570 scoped_ptr<PrioritizedResource> textures[max_textures]; | 569 scoped_ptr<PrioritizedResource> textures[max_textures]; |
| 571 | 570 |
| 572 for (size_t i = 0; i < max_textures; ++i) | 571 for (size_t i = 0; i < max_textures; ++i) |
|
danakj
2013/03/25 17:23:31
{}
| |
| 573 textures[i] = | 572 textures[i] = |
| 574 resource_manager->CreateTexture(texture_size_, texture_format_); | 573 resource_manager->CreateTexture(texture_size_, texture_format_); |
| 575 | 574 |
| 576 // Set 6 visible textures in the root surface, and 2 in a child surface. | 575 // Set 6 visible textures in the root surface, and 2 in a child surface. |
| 577 for (size_t i = 0; i < 6; ++i) | 576 for (size_t i = 0; i < 6; ++i) |
|
danakj
2013/03/25 17:23:31
{}
| |
| 578 textures[i]-> | 577 textures[i] |
| 579 set_request_priority(PriorityCalculator::VisiblePriority(true)); | 578 ->set_request_priority(PriorityCalculator::VisiblePriority(true)); |
|
danakj
2013/03/25 17:23:31
-> on prev line
| |
| 580 for (size_t i = 6; i < 8; ++i) | 579 for (size_t i = 6; i < 8; ++i) |
|
danakj
2013/03/25 17:23:31
{}
| |
| 581 textures[i]-> | 580 textures[i] |
| 582 set_request_priority(PriorityCalculator::VisiblePriority(false)); | 581 ->set_request_priority(PriorityCalculator::VisiblePriority(false)); |
|
danakj
2013/03/25 17:23:31
-> moves up
| |
| 583 | 582 |
| 584 PrioritizeTexturesAndBackings(resource_manager.get()); | 583 PrioritizeTexturesAndBackings(resource_manager.get()); |
| 585 | 584 |
| 586 // Unable to request_late textures in the child surface. | 585 // Unable to request_late textures in the child surface. |
| 587 EXPECT_FALSE(ValidateTexture(textures[6], true)); | 586 EXPECT_FALSE(ValidateTexture(textures[6], true)); |
| 588 EXPECT_FALSE(ValidateTexture(textures[7], true)); | 587 EXPECT_FALSE(ValidateTexture(textures[7], true)); |
| 589 | 588 |
| 590 // Root surface textures are valid. | 589 // Root surface textures are valid. |
| 591 for (size_t i = 0; i < 6; ++i) | 590 for (size_t i = 0; i < 6; ++i) |
| 592 EXPECT_TRUE(ValidateTexture(textures[i], false)); | 591 EXPECT_TRUE(ValidateTexture(textures[i], false)); |
| 593 | 592 |
| 594 EXPECT_EQ(TexturesMemorySize(6), | 593 EXPECT_EQ(TexturesMemorySize(6), resource_manager->MemoryAboveCutoffBytes()); |
| 595 resource_manager->MemoryAboveCutoffBytes()); | 594 EXPECT_EQ(TexturesMemorySize(2), |
| 596 EXPECT_EQ(TexturesMemorySize(2), | 595 resource_manager->MemoryForSelfManagedTextures()); |
| 597 resource_manager->MemoryForSelfManagedTextures()); | 596 EXPECT_LE(resource_manager->MemoryUseBytes(), |
| 598 EXPECT_LE(resource_manager->MemoryUseBytes(), | 597 resource_manager->MemoryAboveCutoffBytes()); |
| 599 resource_manager->MemoryAboveCutoffBytes()); | 598 |
| 600 | 599 DebugScopedSetImplThreadAndMainThreadBlocked |
| 601 DebugScopedSetImplThreadAndMainThreadBlocked | 600 impl_thread_and_main_thread_blocked(&proxy_); |
| 602 impl_thread_and_main_thread_blocked(&proxy_); | 601 resource_manager->ClearAllMemory(ResourceProvider()); |
| 603 resource_manager->ClearAllMemory(ResourceProvider()); | |
| 604 } | 602 } |
| 605 | 603 |
| 606 TEST_F(PrioritizedResourceTest, RequestLateBackingsSorting) { | 604 TEST_F(PrioritizedResourceTest, RequestLateBackingsSorting) { |
| 607 const size_t max_textures = 8; | 605 const size_t max_textures = 8; |
|
danakj
2013/03/25 17:23:31
const
| |
| 608 scoped_ptr<PrioritizedResourceManager> resource_manager = | 606 scoped_ptr<PrioritizedResourceManager> resource_manager = |
| 609 CreateManager(max_textures); | 607 CreateManager(max_textures); |
| 610 resource_manager->SetMaxMemoryLimitBytes(TexturesMemorySize(max_textures)); | 608 resource_manager->SetMaxMemoryLimitBytes(TexturesMemorySize(max_textures)); |
| 611 | 609 |
| 612 // Create textures to fill our memory limit. | 610 // Create textures to fill our memory limit. |
| 613 scoped_ptr<PrioritizedResource> textures[max_textures]; | 611 scoped_ptr<PrioritizedResource> textures[max_textures]; |
| 614 for (size_t i = 0; i < max_textures; ++i) | 612 for (size_t i = 0; i < max_textures; ++i) |
|
danakj
2013/03/25 17:23:31
{}
| |
| 615 textures[i] = | 613 textures[i] = |
| 616 resource_manager->CreateTexture(texture_size_, texture_format_); | 614 resource_manager->CreateTexture(texture_size_, texture_format_); |
| 617 | 615 |
| 618 // Set equal priorities, and allocate backings for all textures. | 616 // Set equal priorities, and allocate backings for all textures. |
| 619 for (size_t i = 0; i < max_textures; ++i) | 617 for (size_t i = 0; i < max_textures; ++i) |
| 620 textures[i]->set_request_priority(100); | 618 textures[i]->set_request_priority(100); |
| 621 PrioritizeTexturesAndBackings(resource_manager.get()); | 619 PrioritizeTexturesAndBackings(resource_manager.get()); |
| 622 for (unsigned i = 0; i < max_textures; ++i) | 620 for (unsigned i = 0; i < max_textures; ++i) |
| 623 EXPECT_TRUE(ValidateTexture(textures[i], false)); | 621 EXPECT_TRUE(ValidateTexture(textures[i], false)); |
| 624 | 622 |
| 625 // Drop the memory limit and prioritize (none will be above the threshold, | 623 // Drop the memory limit and prioritize (none will be above the threshold, |
| 626 // but they still have backings because ReduceMemory hasn't been called). | 624 // but they still have backings because ReduceMemory hasn't been called). |
| 627 resource_manager->SetMaxMemoryLimitBytes( | 625 resource_manager->SetMaxMemoryLimitBytes( |
| 628 TexturesMemorySize(max_textures / 2)); | 626 TexturesMemorySize(max_textures / 2)); |
| 629 PrioritizeTexturesAndBackings(resource_manager.get()); | 627 PrioritizeTexturesAndBackings(resource_manager.get()); |
| 630 | 628 |
| 631 // Push half of them back over the limit. | 629 // Push half of them back over the limit. |
| 632 for (size_t i = 0; i < max_textures; i += 2) | 630 for (size_t i = 0; i < max_textures; i += 2) |
| 633 EXPECT_TRUE(textures[i]->RequestLate()); | 631 EXPECT_TRUE(textures[i]->RequestLate()); |
| 634 | 632 |
| 635 // Push the priorities to the backings array and sort the backings array | 633 // Push the priorities to the backings array and sort the backings array |
| 636 ResourceManagerUpdateBackingsPriorities(resource_manager.get()); | 634 ResourceManagerUpdateBackingsPriorities(resource_manager.get()); |
| 637 | 635 |
| 638 // Assert that the backings list be sorted with the below-limit backings | 636 // Assert that the backings list be sorted with the below-limit backings |
| 639 // before the above-limit backings. | 637 // before the above-limit backings. |
| 640 ResourceManagerAssertInvariants(resource_manager.get()); | 638 ResourceManagerAssertInvariants(resource_manager.get()); |
| 641 | 639 |
| 642 // Make sure that we have backings for all of the textures. | 640 // Make sure that we have backings for all of the textures. |
| 643 for (size_t i = 0; i < max_textures; ++i) | 641 for (size_t i = 0; i < max_textures; ++i) |
| 644 EXPECT_TRUE(textures[i]->have_backing_texture()); | 642 EXPECT_TRUE(textures[i]->have_backing_texture()); |
| 645 | 643 |
| 646 // Make sure that only the request_late textures are above the priority | 644 // Make sure that only the request_late textures are above the priority |
| 647 // cutoff | 645 // cutoff |
| 648 for (size_t i = 0; i < max_textures; i += 2) | 646 for (size_t i = 0; i < max_textures; i += 2) |
| 649 EXPECT_TRUE(TextureBackingIsAbovePriorityCutoff(textures[i].get())); | 647 EXPECT_TRUE(TextureBackingIsAbovePriorityCutoff(textures[i].get())); |
| 650 for (size_t i = 1; i < max_textures; i += 2) | 648 for (size_t i = 1; i < max_textures; i += 2) |
| 651 EXPECT_FALSE(TextureBackingIsAbovePriorityCutoff(textures[i].get())); | 649 EXPECT_FALSE(TextureBackingIsAbovePriorityCutoff(textures[i].get())); |
| 652 | 650 |
| 653 DebugScopedSetImplThreadAndMainThreadBlocked | 651 DebugScopedSetImplThreadAndMainThreadBlocked |
| 654 impl_thread_and_main_thread_blocked(&proxy_); | 652 impl_thread_and_main_thread_blocked(&proxy_); |
| 655 resource_manager->ClearAllMemory(ResourceProvider()); | 653 resource_manager->ClearAllMemory(ResourceProvider()); |
| 656 } | 654 } |
| 657 | 655 |
| 658 TEST_F(PrioritizedResourceTest, ClearUploadsToEvictedResources) { | 656 TEST_F(PrioritizedResourceTest, ClearUploadsToEvictedResources) { |
| 659 const size_t max_textures = 4; | 657 const size_t max_textures = 4; |
|
danakj
2013/03/25 17:23:31
const
| |
| 660 scoped_ptr<PrioritizedResourceManager> resource_manager = | 658 scoped_ptr<PrioritizedResourceManager> resource_manager = |
| 661 CreateManager(max_textures); | 659 CreateManager(max_textures); |
| 662 resource_manager->SetMaxMemoryLimitBytes(TexturesMemorySize(max_textures)); | 660 resource_manager->SetMaxMemoryLimitBytes(TexturesMemorySize(max_textures)); |
| 663 | 661 |
| 664 // Create textures to fill our memory limit. | 662 // Create textures to fill our memory limit. |
| 665 scoped_ptr<PrioritizedResource> textures[max_textures]; | 663 scoped_ptr<PrioritizedResource> textures[max_textures]; |
| 666 | 664 |
| 667 for (size_t i = 0; i < max_textures; ++i) | 665 for (size_t i = 0; i < max_textures; ++i) |
|
danakj
2013/03/25 17:23:31
{}
| |
| 668 textures[i] = | 666 textures[i] = |
| 669 resource_manager->CreateTexture(texture_size_, texture_format_); | 667 resource_manager->CreateTexture(texture_size_, texture_format_); |
| 670 | 668 |
| 671 // Set equal priorities, and allocate backings for all textures. | 669 // Set equal priorities, and allocate backings for all textures. |
| 672 for (size_t i = 0; i < max_textures; ++i) | 670 for (size_t i = 0; i < max_textures; ++i) |
| 673 textures[i]->set_request_priority(100); | 671 textures[i]->set_request_priority(100); |
| 674 PrioritizeTexturesAndBackings(resource_manager.get()); | 672 PrioritizeTexturesAndBackings(resource_manager.get()); |
| 675 for (unsigned i = 0; i < max_textures; ++i) | 673 for (unsigned i = 0; i < max_textures; ++i) |
| 676 EXPECT_TRUE(ValidateTexture(textures[i], false)); | 674 EXPECT_TRUE(ValidateTexture(textures[i], false)); |
| 677 | 675 |
| 678 ResourceUpdateQueue queue; | 676 ResourceUpdateQueue queue; |
| 679 DebugScopedSetImplThreadAndMainThreadBlocked | 677 DebugScopedSetImplThreadAndMainThreadBlocked |
| 680 impl_thread_and_main_thread_blocked(&proxy_); | 678 impl_thread_and_main_thread_blocked(&proxy_); |
| 681 for (size_t i = 0; i < max_textures; ++i) { | 679 for (size_t i = 0; i < max_textures; ++i) { |
| 682 const ResourceUpdate upload = ResourceUpdate::Create( | 680 const ResourceUpdate upload = ResourceUpdate::Create( |
| 683 textures[i].get(), NULL, gfx::Rect(), gfx::Rect(), gfx::Vector2d()); | 681 textures[i].get(), NULL, gfx::Rect(), gfx::Rect(), gfx::Vector2d()); |
| 684 queue.AppendFullUpload(upload); | 682 queue.AppendFullUpload(upload); |
| 685 } | 683 } |
| 686 | 684 |
| 687 // Make sure that we have backings for all of the textures. | 685 // Make sure that we have backings for all of the textures. |
| 688 for (size_t i = 0; i < max_textures; ++i) | 686 for (size_t i = 0; i < max_textures; ++i) |
| 689 EXPECT_TRUE(textures[i]->have_backing_texture()); | 687 EXPECT_TRUE(textures[i]->have_backing_texture()); |
| 690 | 688 |
| 691 queue.ClearUploadsToEvictedResources(); | 689 queue.ClearUploadsToEvictedResources(); |
| 692 EXPECT_EQ(4, queue.FullUploadSize()); | 690 EXPECT_EQ(4, queue.FullUploadSize()); |
| 693 | 691 |
| 694 resource_manager->ReduceMemoryOnImplThread( | 692 resource_manager->ReduceMemoryOnImplThread( |
| 695 TexturesMemorySize(1), | 693 TexturesMemorySize(1), |
| 696 PriorityCalculator::AllowEverythingCutoff(), | 694 PriorityCalculator::AllowEverythingCutoff(), |
| 697 ResourceProvider()); | 695 ResourceProvider()); |
| 698 queue.ClearUploadsToEvictedResources(); | 696 queue.ClearUploadsToEvictedResources(); |
| 699 EXPECT_EQ(1, queue.FullUploadSize()); | 697 EXPECT_EQ(1, queue.FullUploadSize()); |
| 700 | 698 |
| 701 resource_manager->ReduceMemoryOnImplThread( | 699 resource_manager->ReduceMemoryOnImplThread( |
| 702 0, PriorityCalculator::AllowEverythingCutoff(), ResourceProvider()); | 700 0, PriorityCalculator::AllowEverythingCutoff(), ResourceProvider()); |
| 703 queue.ClearUploadsToEvictedResources(); | 701 queue.ClearUploadsToEvictedResources(); |
| 704 EXPECT_EQ(0, queue.FullUploadSize()); | 702 EXPECT_EQ(0, queue.FullUploadSize()); |
| 705 } | 703 } |
| 706 | 704 |
| 707 TEST_F(PrioritizedResourceTest, UsageStatistics) { | 705 TEST_F(PrioritizedResourceTest, UsageStatistics) { |
| 708 const size_t max_textures = 5; | 706 const size_t max_textures = 5; |
|
danakj
2013/03/25 17:23:31
const
| |
| 709 scoped_ptr<PrioritizedResourceManager> resource_manager = | 707 scoped_ptr<PrioritizedResourceManager> resource_manager = |
| 710 CreateManager(max_textures); | 708 CreateManager(max_textures); |
| 711 scoped_ptr<PrioritizedResource> textures[max_textures]; | 709 scoped_ptr<PrioritizedResource> textures[max_textures]; |
| 712 | 710 |
| 713 for (size_t i = 0; i < max_textures; ++i) | 711 for (size_t i = 0; i < max_textures; ++i) |
|
danakj
2013/03/25 17:23:31
{}
| |
| 714 textures[i] = | 712 textures[i] = |
| 715 resource_manager->CreateTexture(texture_size_, texture_format_); | 713 resource_manager->CreateTexture(texture_size_, texture_format_); |
| 716 | 714 |
| 717 textures[0]->set_request_priority( | 715 textures[0] |
| 718 PriorityCalculator::AllowVisibleOnlyCutoff() - 1); | 716 ->set_request_priority(PriorityCalculator::AllowVisibleOnlyCutoff() - 1); |
|
danakj
2013/03/25 17:23:31
move ->'s
| |
| 719 textures[1]-> | 717 textures[1] |
| 720 set_request_priority(PriorityCalculator::AllowVisibleOnlyCutoff()); | 718 ->set_request_priority(PriorityCalculator::AllowVisibleOnlyCutoff()); |
| 721 textures[2]->set_request_priority( | 719 textures[2]->set_request_priority( |
| 722 PriorityCalculator::AllowVisibleAndNearbyCutoff() - 1); | 720 PriorityCalculator::AllowVisibleAndNearbyCutoff() - 1); |
| 723 textures[3]->set_request_priority( | 721 textures[3] |
| 724 PriorityCalculator::AllowVisibleAndNearbyCutoff()); | 722 ->set_request_priority(PriorityCalculator::AllowVisibleAndNearbyCutoff()); |
| 725 textures[4]->set_request_priority( | 723 textures[4]->set_request_priority( |
| 726 PriorityCalculator::AllowVisibleAndNearbyCutoff() + 1); | 724 PriorityCalculator::AllowVisibleAndNearbyCutoff() + 1); |
| 727 | 725 |
| 728 // Set max limit to 2 textures. | 726 // Set max limit to 2 textures. |
| 729 resource_manager->SetMaxMemoryLimitBytes(TexturesMemorySize(2)); | 727 resource_manager->SetMaxMemoryLimitBytes(TexturesMemorySize(2)); |
| 730 PrioritizeTexturesAndBackings(resource_manager.get()); | 728 PrioritizeTexturesAndBackings(resource_manager.get()); |
| 731 | 729 |
| 732 // The first two textures should be available, others should not. | 730 // The first two textures should be available, others should not. |
| 733 for (size_t i = 0; i < 2; ++i) | 731 for (size_t i = 0; i < 2; ++i) |
| 734 EXPECT_TRUE(ValidateTexture(textures[i], false)); | 732 EXPECT_TRUE(ValidateTexture(textures[i], false)); |
| 735 for (size_t i = 2; i < max_textures; ++i) | 733 for (size_t i = 2; i < max_textures; ++i) |
| 736 EXPECT_FALSE(ValidateTexture(textures[i], false)); | 734 EXPECT_FALSE(ValidateTexture(textures[i], false)); |
| 737 | 735 |
| 738 // Validate the statistics. | 736 // Validate the statistics. |
| 739 { | 737 { |
| 740 DebugScopedSetImplThread impl_thread(&proxy_); | 738 DebugScopedSetImplThread impl_thread(&proxy_); |
| 741 EXPECT_EQ(TexturesMemorySize(2), resource_manager->MemoryUseBytes()); | 739 EXPECT_EQ(TexturesMemorySize(2), resource_manager->MemoryUseBytes()); |
| 742 EXPECT_EQ(TexturesMemorySize(1), | 740 EXPECT_EQ(TexturesMemorySize(1), resource_manager->MemoryVisibleBytes()); |
| 743 resource_manager->MemoryVisibleBytes()); | 741 EXPECT_EQ(TexturesMemorySize(3), |
| 744 EXPECT_EQ(TexturesMemorySize(3), | 742 resource_manager->MemoryVisibleAndNearbyBytes()); |
| 745 resource_manager->MemoryVisibleAndNearbyBytes()); | 743 } |
| 746 } | 744 |
| 747 | 745 // Re-prioritize the textures, but do not push the values to backings. |
| 748 // Re-prioritize the textures, but do not push the values to backings. | 746 textures[0] |
| 749 textures[0]->set_request_priority( | 747 ->set_request_priority(PriorityCalculator::AllowVisibleOnlyCutoff() - 1); |
|
danakj
2013/03/25 17:23:31
->
| |
| 750 PriorityCalculator::AllowVisibleOnlyCutoff() - 1); | 748 textures[1] |
| 751 textures[1]->set_request_priority( | 749 ->set_request_priority(PriorityCalculator::AllowVisibleOnlyCutoff() - 1); |
| 752 PriorityCalculator::AllowVisibleOnlyCutoff() - 1); | 750 textures[2] |
| 753 textures[2]->set_request_priority( | 751 ->set_request_priority(PriorityCalculator::AllowVisibleOnlyCutoff() - 1); |
| 754 PriorityCalculator::AllowVisibleOnlyCutoff() - 1); | 752 textures[3]->set_request_priority( |
| 755 textures[3]->set_request_priority( | 753 PriorityCalculator::AllowVisibleAndNearbyCutoff() - 1); |
| 756 PriorityCalculator::AllowVisibleAndNearbyCutoff() - 1); | 754 textures[4] |
| 757 textures[4]->set_request_priority( | 755 ->set_request_priority(PriorityCalculator::AllowVisibleAndNearbyCutoff()); |
| 758 PriorityCalculator::AllowVisibleAndNearbyCutoff()); | 756 resource_manager->PrioritizeTextures(); |
| 759 resource_manager->PrioritizeTextures(); | 757 |
| 760 | 758 // Verify that we still see the old values. |
| 761 // Verify that we still see the old values. | 759 { |
| 762 { | 760 DebugScopedSetImplThread impl_thread(&proxy_); |
| 763 DebugScopedSetImplThread impl_thread (& proxy_); | 761 EXPECT_EQ(TexturesMemorySize(2), resource_manager->MemoryUseBytes()); |
| 764 EXPECT_EQ(TexturesMemorySize(2), resource_manager->MemoryUseBytes()); | 762 EXPECT_EQ(TexturesMemorySize(1), resource_manager->MemoryVisibleBytes()); |
| 765 EXPECT_EQ(TexturesMemorySize(1), | 763 EXPECT_EQ(TexturesMemorySize(3), |
| 766 resource_manager->MemoryVisibleBytes()); | 764 resource_manager->MemoryVisibleAndNearbyBytes()); |
| 767 EXPECT_EQ(TexturesMemorySize(3), | 765 } |
| 768 resource_manager->MemoryVisibleAndNearbyBytes()); | 766 |
| 769 } | 767 // Push priorities to backings, and verify we see the new values. |
| 770 | 768 { |
| 771 // Push priorities to backings, and verify we see the new values. | 769 DebugScopedSetImplThreadAndMainThreadBlocked |
| 772 { | 770 impl_thread_and_main_thread_blocked(&proxy_); |
| 773 DebugScopedSetImplThreadAndMainThreadBlocked | 771 resource_manager->PushTexturePrioritiesToBackings(); |
| 774 impl_thread_and_main_thread_blocked (& proxy_); | 772 EXPECT_EQ(TexturesMemorySize(2), resource_manager->MemoryUseBytes()); |
| 775 resource_manager->PushTexturePrioritiesToBackings(); | 773 EXPECT_EQ(TexturesMemorySize(3), resource_manager->MemoryVisibleBytes()); |
| 776 EXPECT_EQ(TexturesMemorySize(2), resource_manager->MemoryUseBytes()); | 774 EXPECT_EQ(TexturesMemorySize(4), |
| 777 EXPECT_EQ(TexturesMemorySize(3), | 775 resource_manager->MemoryVisibleAndNearbyBytes()); |
| 778 resource_manager->MemoryVisibleBytes()); | 776 } |
| 779 EXPECT_EQ(TexturesMemorySize(4), | 777 |
| 780 resource_manager->MemoryVisibleAndNearbyBytes()); | 778 DebugScopedSetImplThreadAndMainThreadBlocked |
| 781 } | 779 impl_thread_and_main_thread_blocked(&proxy_); |
| 782 | 780 resource_manager->ClearAllMemory(ResourceProvider()); |
| 783 DebugScopedSetImplThreadAndMainThreadBlocked | |
| 784 impl_thread_and_main_thread_blocked (& proxy_); | |
| 785 resource_manager->ClearAllMemory(ResourceProvider()); | |
| 786 } | 781 } |
| 787 | 782 |
| 788 } // namespace | 783 } // namespace |
| 789 } // namespace cc | 784 } // namespace cc |
| OLD | NEW |