OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "content/common/gpu/gpu_memory_manager.h" | 5 #include "content/common/gpu/gpu_memory_manager.h" |
6 | 6 |
7 #include "content/common/gpu/gpu_memory_manager_client.h" | 7 #include "content/common/gpu/gpu_memory_manager_client.h" |
8 #include "content/common/gpu/gpu_memory_tracking.h" | 8 #include "content/common/gpu/gpu_memory_tracking.h" |
9 #include "gpu/command_buffer/common/gpu_memory_allocation.h" | 9 #include "gpu/command_buffer/common/gpu_memory_allocation.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 client_state_.reset( | 99 client_state_.reset( |
100 memmgr_->CreateClientState(this, surface_id != 0, visible)); | 100 memmgr_->CreateClientState(this, surface_id != 0, visible)); |
101 } | 101 } |
102 | 102 |
103 ~FakeClient() override { | 103 ~FakeClient() override { |
104 client_state_.reset(); | 104 client_state_.reset(); |
105 tracking_group_.reset(); | 105 tracking_group_.reset(); |
106 memory_tracker_ = NULL; | 106 memory_tracker_ = NULL; |
107 } | 107 } |
108 | 108 |
| 109 void SetMemoryAllocation(const MemoryAllocation& alloc) override { |
| 110 allocation_ = alloc; |
| 111 ClientAssignmentCollector::AddClientStat(this, alloc); |
| 112 } |
| 113 |
109 void SuggestHaveFrontBuffer(bool suggest_have_frontbuffer) override { | 114 void SuggestHaveFrontBuffer(bool suggest_have_frontbuffer) override { |
110 suggest_have_frontbuffer_ = suggest_have_frontbuffer; | 115 suggest_have_frontbuffer_ = suggest_have_frontbuffer; |
111 } | 116 } |
112 | 117 |
113 bool GetTotalGpuMemory(uint64* bytes) override { | 118 bool GetTotalGpuMemory(uint64* bytes) override { |
114 if (total_gpu_memory_) { | 119 if (total_gpu_memory_) { |
115 *bytes = total_gpu_memory_; | 120 *bytes = total_gpu_memory_; |
116 return true; | 121 return true; |
117 } | 122 } |
118 return false; | 123 return false; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 } | 184 } |
180 | 185 |
181 void Manage() { | 186 void Manage() { |
182 ClientAssignmentCollector::ClearAllStats(); | 187 ClientAssignmentCollector::ClearAllStats(); |
183 memmgr_.Manage(); | 188 memmgr_.Manage(); |
184 } | 189 } |
185 | 190 |
186 GpuMemoryManager memmgr_; | 191 GpuMemoryManager memmgr_; |
187 }; | 192 }; |
188 | 193 |
| 194 // Test GpuMemoryManager::Manage basic functionality. |
| 195 // Expect memory allocation to set suggest_have_frontbuffer/backbuffer |
| 196 // according to visibility and last used time for stubs with surface. |
| 197 // Expect memory allocation to be shared according to share groups for stubs |
| 198 // without a surface. |
| 199 TEST_F(GpuMemoryManagerTest, TestManageBasicFunctionality) { |
| 200 // Test stubs with surface. |
| 201 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true), |
| 202 stub2(&memmgr_, GenerateUniqueSurfaceId(), false); |
| 203 |
| 204 Manage(); |
| 205 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub1.allocation_)); |
| 206 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_)); |
| 207 |
| 208 // Test stubs without surface, with share group of 1 stub. |
| 209 FakeClient stub3(&memmgr_, &stub1), stub4(&memmgr_, &stub2); |
| 210 |
| 211 Manage(); |
| 212 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub1.allocation_)); |
| 213 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_)); |
| 214 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub3.allocation_)); |
| 215 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub4.allocation_)); |
| 216 |
| 217 // Test stub without surface, with share group of multiple stubs. |
| 218 FakeClient stub5(&memmgr_ , &stub2); |
| 219 |
| 220 Manage(); |
| 221 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub4.allocation_)); |
| 222 } |
| 223 |
| 224 // Test GpuMemoryManager::Manage functionality: changing visibility. |
| 225 // Expect memory allocation to set suggest_have_frontbuffer/backbuffer |
| 226 // according to visibility and last used time for stubs with surface. |
| 227 // Expect memory allocation to be shared according to share groups for stubs |
| 228 // without a surface. |
| 229 TEST_F(GpuMemoryManagerTest, TestManageChangingVisibility) { |
| 230 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true), |
| 231 stub2(&memmgr_, GenerateUniqueSurfaceId(), false); |
| 232 |
| 233 FakeClient stub3(&memmgr_, &stub1), stub4(&memmgr_, &stub2); |
| 234 FakeClient stub5(&memmgr_ , &stub2); |
| 235 |
| 236 Manage(); |
| 237 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub1.allocation_)); |
| 238 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_)); |
| 239 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub3.allocation_)); |
| 240 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub4.allocation_)); |
| 241 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub5.allocation_)); |
| 242 |
| 243 stub1.SetVisible(false); |
| 244 stub2.SetVisible(true); |
| 245 |
| 246 Manage(); |
| 247 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub1.allocation_)); |
| 248 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub2.allocation_)); |
| 249 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub3.allocation_)); |
| 250 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub4.allocation_)); |
| 251 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub5.allocation_)); |
| 252 } |
| 253 |
| 254 // Test GpuMemoryManager::Manage functionality: Test more than threshold number |
| 255 // of visible stubs. |
| 256 // Expect all allocations to continue to have frontbuffer. |
| 257 TEST_F(GpuMemoryManagerTest, TestManageManyVisibleStubs) { |
| 258 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true), |
| 259 stub2(&memmgr_, GenerateUniqueSurfaceId(), true), |
| 260 stub3(&memmgr_, GenerateUniqueSurfaceId(), true), |
| 261 stub4(&memmgr_, GenerateUniqueSurfaceId(), true); |
| 262 |
| 263 FakeClient stub5(&memmgr_ , &stub1), stub6(&memmgr_ , &stub2); |
| 264 FakeClient stub7(&memmgr_ , &stub2); |
| 265 |
| 266 Manage(); |
| 267 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub1.allocation_)); |
| 268 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub2.allocation_)); |
| 269 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub3.allocation_)); |
| 270 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub4.allocation_)); |
| 271 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub5.allocation_)); |
| 272 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub6.allocation_)); |
| 273 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub7.allocation_)); |
| 274 } |
| 275 |
| 276 // Test GpuMemoryManager::Manage functionality: Test more than threshold number |
| 277 // of not visible stubs. |
| 278 // Expect the stubs surpassing the threshold to not have a backbuffer. |
| 279 TEST_F(GpuMemoryManagerTest, TestManageManyNotVisibleStubs) { |
| 280 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true), |
| 281 stub2(&memmgr_, GenerateUniqueSurfaceId(), true), |
| 282 stub3(&memmgr_, GenerateUniqueSurfaceId(), true), |
| 283 stub4(&memmgr_, GenerateUniqueSurfaceId(), true); |
| 284 stub4.SetVisible(false); |
| 285 stub3.SetVisible(false); |
| 286 stub2.SetVisible(false); |
| 287 stub1.SetVisible(false); |
| 288 |
| 289 FakeClient stub5(&memmgr_ , &stub1), stub6(&memmgr_ , &stub4); |
| 290 FakeClient stub7(&memmgr_ , &stub1); |
| 291 |
| 292 Manage(); |
| 293 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub1.allocation_)); |
| 294 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_)); |
| 295 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub3.allocation_)); |
| 296 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub4.allocation_)); |
| 297 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub5.allocation_)); |
| 298 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub6.allocation_)); |
| 299 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub7.allocation_)); |
| 300 } |
| 301 |
| 302 // Test GpuMemoryManager::Manage functionality: Test changing the last used |
| 303 // time of stubs when doing so causes change in which stubs surpass threshold. |
| 304 // Expect frontbuffer to be dropped for the older stub. |
| 305 TEST_F(GpuMemoryManagerTest, TestManageChangingLastUsedTime) { |
| 306 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true), |
| 307 stub2(&memmgr_, GenerateUniqueSurfaceId(), true), |
| 308 stub3(&memmgr_, GenerateUniqueSurfaceId(), true), |
| 309 stub4(&memmgr_, GenerateUniqueSurfaceId(), true); |
| 310 |
| 311 FakeClient stub5(&memmgr_ , &stub3), stub6(&memmgr_ , &stub4); |
| 312 FakeClient stub7(&memmgr_ , &stub3); |
| 313 |
| 314 // Make stub4 be the least-recently-used client |
| 315 stub4.SetVisible(false); |
| 316 stub3.SetVisible(false); |
| 317 stub2.SetVisible(false); |
| 318 stub1.SetVisible(false); |
| 319 |
| 320 Manage(); |
| 321 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub1.allocation_)); |
| 322 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_)); |
| 323 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub3.allocation_)); |
| 324 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub4.allocation_)); |
| 325 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub5.allocation_)); |
| 326 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub6.allocation_)); |
| 327 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub7.allocation_)); |
| 328 |
| 329 // Make stub3 become the least-recently-used client. |
| 330 stub2.SetVisible(true); |
| 331 stub2.SetVisible(false); |
| 332 stub4.SetVisible(true); |
| 333 stub4.SetVisible(false); |
| 334 |
| 335 Manage(); |
| 336 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub1.allocation_)); |
| 337 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_)); |
| 338 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub3.allocation_)); |
| 339 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub4.allocation_)); |
| 340 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub5.allocation_)); |
| 341 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub6.allocation_)); |
| 342 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub7.allocation_)); |
| 343 } |
| 344 |
| 345 // Test GpuMemoryManager::Manage functionality: Test changing importance of |
| 346 // enough stubs so that every stub in share group crosses threshold. |
| 347 // Expect memory allocation of the stubs without surface to share memory |
| 348 // allocation with the most visible stub in share group. |
| 349 TEST_F(GpuMemoryManagerTest, TestManageChangingImportanceShareGroup) { |
| 350 FakeClient stub_ignore_a(&memmgr_, GenerateUniqueSurfaceId(), true), |
| 351 stub_ignore_b(&memmgr_, GenerateUniqueSurfaceId(), false), |
| 352 stub_ignore_c(&memmgr_, GenerateUniqueSurfaceId(), false); |
| 353 FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), false), |
| 354 stub2(&memmgr_, GenerateUniqueSurfaceId(), false); |
| 355 |
| 356 FakeClient stub3(&memmgr_, &stub2), stub4(&memmgr_, &stub2); |
| 357 |
| 358 // stub1 and stub2 keep their non-hibernated state because they're |
| 359 // either visible or the 2 most recently used clients (through the |
| 360 // first three checks). |
| 361 stub1.SetVisible(true); |
| 362 stub2.SetVisible(true); |
| 363 Manage(); |
| 364 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub1.allocation_)); |
| 365 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub2.allocation_)); |
| 366 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub3.allocation_)); |
| 367 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub4.allocation_)); |
| 368 |
| 369 stub1.SetVisible(false); |
| 370 Manage(); |
| 371 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub1.allocation_)); |
| 372 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub2.allocation_)); |
| 373 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub3.allocation_)); |
| 374 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub4.allocation_)); |
| 375 |
| 376 stub2.SetVisible(false); |
| 377 Manage(); |
| 378 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub1.allocation_)); |
| 379 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_)); |
| 380 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub3.allocation_)); |
| 381 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub4.allocation_)); |
| 382 |
| 383 // stub_ignore_b will cause stub1 to become hibernated (because |
| 384 // stub_ignore_a, stub_ignore_b, and stub2 are all non-hibernated and more |
| 385 // important). |
| 386 stub_ignore_b.SetVisible(true); |
| 387 stub_ignore_b.SetVisible(false); |
| 388 Manage(); |
| 389 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub1.allocation_)); |
| 390 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_)); |
| 391 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub3.allocation_)); |
| 392 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub4.allocation_)); |
| 393 |
| 394 // stub_ignore_c will cause stub2 to become hibernated (because |
| 395 // stub_ignore_a, stub_ignore_b, and stub_ignore_c are all non-hibernated |
| 396 // and more important). |
| 397 stub_ignore_c.SetVisible(true); |
| 398 stub_ignore_c.SetVisible(false); |
| 399 Manage(); |
| 400 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub1.allocation_)); |
| 401 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub2.allocation_)); |
| 402 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub3.allocation_)); |
| 403 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub4.allocation_)); |
| 404 } |
| 405 |
189 } // namespace content | 406 } // namespace content |
OLD | NEW |