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_command_buffer_stub.h" | 5 #include "content/common/gpu/gpu_command_buffer_stub.h" |
6 #include "content/common/gpu/gpu_memory_allocation.h" | 6 #include "content/common/gpu/gpu_memory_allocation.h" |
7 #include "content/common/gpu/gpu_memory_manager.h" | 7 #include "content/common/gpu/gpu_memory_manager.h" |
8 | 8 |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 // Older should never be more important than newer: | 166 // Older should never be more important than newer: |
167 EXPECT_FALSE(is_more_important(&stub_true1, &stub_true2)); | 167 EXPECT_FALSE(is_more_important(&stub_true1, &stub_true2)); |
168 EXPECT_FALSE(is_more_important(&stub_true1, &stub_true3)); | 168 EXPECT_FALSE(is_more_important(&stub_true1, &stub_true3)); |
169 EXPECT_FALSE(is_more_important(&stub_true2, &stub_true3)); | 169 EXPECT_FALSE(is_more_important(&stub_true2, &stub_true3)); |
170 EXPECT_FALSE(is_more_important(&stub_false1, &stub_false2)); | 170 EXPECT_FALSE(is_more_important(&stub_false1, &stub_false2)); |
171 EXPECT_FALSE(is_more_important(&stub_false1, &stub_false3)); | 171 EXPECT_FALSE(is_more_important(&stub_false1, &stub_false3)); |
172 EXPECT_FALSE(is_more_important(&stub_false2, &stub_false3)); | 172 EXPECT_FALSE(is_more_important(&stub_false2, &stub_false3)); |
173 } | 173 } |
174 | 174 |
175 // Test GpuMemoryManager::Manage basic functionality. | 175 // Test GpuMemoryManager::Manage basic functionality. |
176 // Expect memory allocation to set has_frontbuffer, has_backbuffer according | 176 // Expect memory allocation to set suggest_have_frontbuffer/backbuffer according |
177 // to visibility and last used time for stubs with surface. | 177 // to visibility and last used time for stubs with surface. |
178 // Expect memory allocation to be shared according to share groups for stubs | 178 // Expect memory allocation to be shared according to share groups for stubs |
179 // without a surface. | 179 // without a surface. |
180 TEST_F(GpuMemoryManagerTest, TestManageBasicFunctionality) { | 180 TEST_F(GpuMemoryManagerTest, TestManageBasicFunctionality) { |
181 // Test stubs with surface. | 181 // Test stubs with surface. |
182 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), true, older_), | 182 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), true, older_), |
183 stub2(GenerateUniqueSurfaceId(), false, older_); | 183 stub2(GenerateUniqueSurfaceId(), false, older_); |
184 client_.stubs_.push_back(&stub1); | 184 client_.stubs_.push_back(&stub1); |
185 client_.stubs_.push_back(&stub2); | 185 client_.stubs_.push_back(&stub2); |
186 | 186 |
187 Manage(); | 187 Manage(); |
188 EXPECT_EQ(stub1.allocation_.has_frontbuffer, true); | 188 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, true); |
189 EXPECT_EQ(stub1.allocation_.has_backbuffer, true); | 189 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, true); |
190 EXPECT_EQ(stub2.allocation_.has_frontbuffer, true); | 190 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, true); |
191 EXPECT_EQ(stub2.allocation_.has_backbuffer, false); | 191 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, false); |
192 | 192 |
193 // Test stubs without surface, with share group of 1 stub. | 193 // Test stubs without surface, with share group of 1 stub. |
194 FakeCommandBufferStubWithoutSurface stub3, stub4; | 194 FakeCommandBufferStubWithoutSurface stub3, stub4; |
195 stub3.share_group_.push_back(&stub1); | 195 stub3.share_group_.push_back(&stub1); |
196 stub4.share_group_.push_back(&stub2); | 196 stub4.share_group_.push_back(&stub2); |
197 client_.stubs_.push_back(&stub3); | 197 client_.stubs_.push_back(&stub3); |
198 client_.stubs_.push_back(&stub4); | 198 client_.stubs_.push_back(&stub4); |
199 | 199 |
200 Manage(); | 200 Manage(); |
201 EXPECT_EQ(stub1.allocation_, stub3.allocation_); | 201 EXPECT_EQ(stub1.allocation_, stub3.allocation_); |
202 EXPECT_EQ(stub2.allocation_, stub4.allocation_); | 202 EXPECT_EQ(stub2.allocation_, stub4.allocation_); |
203 | 203 |
204 // Test stub without surface, with share group of multiple stubs. | 204 // Test stub without surface, with share group of multiple stubs. |
205 FakeCommandBufferStubWithoutSurface stub5; | 205 FakeCommandBufferStubWithoutSurface stub5; |
206 stub5.share_group_.push_back(&stub1); | 206 stub5.share_group_.push_back(&stub1); |
207 stub5.share_group_.push_back(&stub2); | 207 stub5.share_group_.push_back(&stub2); |
208 client_.stubs_.push_back(&stub5); | 208 client_.stubs_.push_back(&stub5); |
209 | 209 |
210 Manage(); | 210 Manage(); |
211 EXPECT_EQ(stub1.allocation_, stub5.allocation_); | 211 EXPECT_EQ(stub1.allocation_, stub5.allocation_); |
212 } | 212 } |
213 | 213 |
214 // Test GpuMemoryManager::Manage functionality: changing visibility. | 214 // Test GpuMemoryManager::Manage functionality: changing visibility. |
215 // Expect memory allocation to set has_frontbuffer, has_backbuffer according | 215 // Expect memory allocation to set suggest_have_frontbuffer/backbuffer according |
216 // to visibility and last used time for stubs with surface. | 216 // to visibility and last used time for stubs with surface. |
217 // Expect memory allocation to be shared according to share groups for stubs | 217 // Expect memory allocation to be shared according to share groups for stubs |
218 // without a surface. | 218 // without a surface. |
219 TEST_F(GpuMemoryManagerTest, TestManageChangingVisibility) { | 219 TEST_F(GpuMemoryManagerTest, TestManageChangingVisibility) { |
220 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), true, older_), | 220 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), true, older_), |
221 stub2(GenerateUniqueSurfaceId(), false, older_); | 221 stub2(GenerateUniqueSurfaceId(), false, older_); |
222 client_.stubs_.push_back(&stub1); | 222 client_.stubs_.push_back(&stub1); |
223 client_.stubs_.push_back(&stub2); | 223 client_.stubs_.push_back(&stub2); |
224 | 224 |
225 FakeCommandBufferStubWithoutSurface stub3, stub4; | 225 FakeCommandBufferStubWithoutSurface stub3, stub4; |
226 stub3.share_group_.push_back(&stub1); | 226 stub3.share_group_.push_back(&stub1); |
227 stub4.share_group_.push_back(&stub2); | 227 stub4.share_group_.push_back(&stub2); |
228 client_.stubs_.push_back(&stub3); | 228 client_.stubs_.push_back(&stub3); |
229 client_.stubs_.push_back(&stub4); | 229 client_.stubs_.push_back(&stub4); |
230 | 230 |
231 FakeCommandBufferStubWithoutSurface stub5; | 231 FakeCommandBufferStubWithoutSurface stub5; |
232 stub5.share_group_.push_back(&stub1); | 232 stub5.share_group_.push_back(&stub1); |
233 stub5.share_group_.push_back(&stub2); | 233 stub5.share_group_.push_back(&stub2); |
234 client_.stubs_.push_back(&stub5); | 234 client_.stubs_.push_back(&stub5); |
235 | 235 |
236 Manage(); | 236 Manage(); |
237 EXPECT_EQ(stub1.allocation_.has_frontbuffer, true); | 237 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, true); |
238 EXPECT_EQ(stub1.allocation_.has_backbuffer, true); | 238 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, true); |
239 EXPECT_EQ(stub2.allocation_.has_frontbuffer, true); | 239 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, true); |
240 EXPECT_EQ(stub2.allocation_.has_backbuffer, false); | 240 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, false); |
241 EXPECT_EQ(stub1.allocation_, stub3.allocation_); | 241 EXPECT_EQ(stub1.allocation_, stub3.allocation_); |
242 EXPECT_EQ(stub2.allocation_, stub4.allocation_); | 242 EXPECT_EQ(stub2.allocation_, stub4.allocation_); |
243 EXPECT_EQ(stub1.allocation_, stub5.allocation_); | 243 EXPECT_EQ(stub1.allocation_, stub5.allocation_); |
244 | 244 |
245 stub1.surface_state_.visible = false; | 245 stub1.surface_state_.visible = false; |
246 stub2.surface_state_.visible = true; | 246 stub2.surface_state_.visible = true; |
247 | 247 |
248 Manage(); | 248 Manage(); |
249 EXPECT_EQ(stub1.allocation_.has_frontbuffer, true); | 249 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, true); |
250 EXPECT_EQ(stub1.allocation_.has_backbuffer, false); | 250 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, false); |
251 EXPECT_EQ(stub2.allocation_.has_frontbuffer, true); | 251 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, true); |
252 EXPECT_EQ(stub2.allocation_.has_backbuffer, true); | 252 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, true); |
253 EXPECT_EQ(stub1.allocation_, stub3.allocation_); | 253 EXPECT_EQ(stub1.allocation_, stub3.allocation_); |
254 EXPECT_EQ(stub2.allocation_, stub4.allocation_); | 254 EXPECT_EQ(stub2.allocation_, stub4.allocation_); |
255 EXPECT_EQ(stub2.allocation_, stub5.allocation_); | 255 EXPECT_EQ(stub2.allocation_, stub5.allocation_); |
256 } | 256 } |
257 | 257 |
258 // Test GpuMemoryManager::Manage functionality: Test more than threshold number | 258 // Test GpuMemoryManager::Manage functionality: Test more than threshold number |
259 // of visible stubs. | 259 // of visible stubs. |
260 // Expect all allocations to continue to have frontbuffer. | 260 // Expect all allocations to continue to have frontbuffer. |
261 TEST_F(GpuMemoryManagerTest, TestManageManyVisibleStubs) { | 261 TEST_F(GpuMemoryManagerTest, TestManageManyVisibleStubs) { |
262 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), true, older_), | 262 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), true, older_), |
(...skipping 10 matching lines...) Expand all Loading... |
273 stub6.share_group_.push_back(&stub2); | 273 stub6.share_group_.push_back(&stub2); |
274 client_.stubs_.push_back(&stub5); | 274 client_.stubs_.push_back(&stub5); |
275 client_.stubs_.push_back(&stub6); | 275 client_.stubs_.push_back(&stub6); |
276 | 276 |
277 FakeCommandBufferStubWithoutSurface stub7; | 277 FakeCommandBufferStubWithoutSurface stub7; |
278 stub7.share_group_.push_back(&stub1); | 278 stub7.share_group_.push_back(&stub1); |
279 stub7.share_group_.push_back(&stub2); | 279 stub7.share_group_.push_back(&stub2); |
280 client_.stubs_.push_back(&stub7); | 280 client_.stubs_.push_back(&stub7); |
281 | 281 |
282 Manage(); | 282 Manage(); |
283 EXPECT_EQ(stub1.allocation_.has_frontbuffer, true); | 283 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, true); |
284 EXPECT_EQ(stub1.allocation_.has_backbuffer, true); | 284 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, true); |
285 EXPECT_EQ(stub2.allocation_.has_frontbuffer, true); | 285 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, true); |
286 EXPECT_EQ(stub2.allocation_.has_backbuffer, true); | 286 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, true); |
287 EXPECT_EQ(stub3.allocation_.has_frontbuffer, true); | 287 EXPECT_EQ(stub3.allocation_.suggest_have_frontbuffer, true); |
288 EXPECT_EQ(stub3.allocation_.has_backbuffer, true); | 288 EXPECT_EQ(stub3.allocation_.suggest_have_backbuffer, true); |
289 EXPECT_EQ(stub4.allocation_.has_frontbuffer, true); | 289 EXPECT_EQ(stub4.allocation_.suggest_have_frontbuffer, true); |
290 EXPECT_EQ(stub4.allocation_.has_backbuffer, true); | 290 EXPECT_EQ(stub4.allocation_.suggest_have_backbuffer, true); |
291 EXPECT_EQ(stub5.allocation_, stub1.allocation_); | 291 EXPECT_EQ(stub5.allocation_, stub1.allocation_); |
292 EXPECT_EQ(stub6.allocation_, stub2.allocation_); | 292 EXPECT_EQ(stub6.allocation_, stub2.allocation_); |
293 EXPECT_EQ(stub7.allocation_, stub1.allocation_); | 293 EXPECT_EQ(stub7.allocation_, stub1.allocation_); |
294 } | 294 } |
295 | 295 |
296 // Test GpuMemoryManager::Manage functionality: Test more than threshold number | 296 // Test GpuMemoryManager::Manage functionality: Test more than threshold number |
297 // of not visible stubs. | 297 // of not visible stubs. |
298 // Expect the stubs surpassing the threshold to not have a backbuffer. | 298 // Expect the stubs surpassing the threshold to not have a backbuffer. |
299 TEST_F(GpuMemoryManagerTest, TestManageManyNotVisibleStubs) { | 299 TEST_F(GpuMemoryManagerTest, TestManageManyNotVisibleStubs) { |
300 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), false, newer_), | 300 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), false, newer_), |
(...skipping 10 matching lines...) Expand all Loading... |
311 stub6.share_group_.push_back(&stub4); | 311 stub6.share_group_.push_back(&stub4); |
312 client_.stubs_.push_back(&stub5); | 312 client_.stubs_.push_back(&stub5); |
313 client_.stubs_.push_back(&stub6); | 313 client_.stubs_.push_back(&stub6); |
314 | 314 |
315 FakeCommandBufferStubWithoutSurface stub7; | 315 FakeCommandBufferStubWithoutSurface stub7; |
316 stub7.share_group_.push_back(&stub1); | 316 stub7.share_group_.push_back(&stub1); |
317 stub7.share_group_.push_back(&stub4); | 317 stub7.share_group_.push_back(&stub4); |
318 client_.stubs_.push_back(&stub7); | 318 client_.stubs_.push_back(&stub7); |
319 | 319 |
320 Manage(); | 320 Manage(); |
321 EXPECT_EQ(stub1.allocation_.has_frontbuffer, true); | 321 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, true); |
322 EXPECT_EQ(stub1.allocation_.has_backbuffer, false); | 322 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, false); |
323 EXPECT_EQ(stub2.allocation_.has_frontbuffer, true); | 323 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, true); |
324 EXPECT_EQ(stub2.allocation_.has_backbuffer, false); | 324 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, false); |
325 EXPECT_EQ(stub3.allocation_.has_frontbuffer, true); | 325 EXPECT_EQ(stub3.allocation_.suggest_have_frontbuffer, true); |
326 EXPECT_EQ(stub3.allocation_.has_backbuffer, false); | 326 EXPECT_EQ(stub3.allocation_.suggest_have_backbuffer, false); |
327 EXPECT_EQ(stub4.allocation_.has_frontbuffer, false); | 327 EXPECT_EQ(stub4.allocation_.suggest_have_frontbuffer, false); |
328 EXPECT_EQ(stub4.allocation_.has_backbuffer, false); | 328 EXPECT_EQ(stub4.allocation_.suggest_have_backbuffer, false); |
329 EXPECT_EQ(stub5.allocation_, stub1.allocation_); | 329 EXPECT_EQ(stub5.allocation_, stub1.allocation_); |
330 EXPECT_EQ(stub6.allocation_, stub4.allocation_); | 330 EXPECT_EQ(stub6.allocation_, stub4.allocation_); |
331 EXPECT_EQ(stub7.allocation_, stub1.allocation_); | 331 EXPECT_EQ(stub7.allocation_, stub1.allocation_); |
332 } | 332 } |
333 | 333 |
334 // Test GpuMemoryManager::Manage functionality: Test changing the last used | 334 // Test GpuMemoryManager::Manage functionality: Test changing the last used |
335 // time of stubs when doing so causes change in which stubs surpass threshold. | 335 // time of stubs when doing so causes change in which stubs surpass threshold. |
336 // Expect frontbuffer to be dropped for the older stub. | 336 // Expect frontbuffer to be dropped for the older stub. |
337 TEST_F(GpuMemoryManagerTest, TestManageChangingLastUsedTime) { | 337 TEST_F(GpuMemoryManagerTest, TestManageChangingLastUsedTime) { |
338 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), false, newer_), | 338 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), false, newer_), |
(...skipping 10 matching lines...) Expand all Loading... |
349 stub6.share_group_.push_back(&stub4); | 349 stub6.share_group_.push_back(&stub4); |
350 client_.stubs_.push_back(&stub5); | 350 client_.stubs_.push_back(&stub5); |
351 client_.stubs_.push_back(&stub6); | 351 client_.stubs_.push_back(&stub6); |
352 | 352 |
353 FakeCommandBufferStubWithoutSurface stub7; | 353 FakeCommandBufferStubWithoutSurface stub7; |
354 stub7.share_group_.push_back(&stub3); | 354 stub7.share_group_.push_back(&stub3); |
355 stub7.share_group_.push_back(&stub4); | 355 stub7.share_group_.push_back(&stub4); |
356 client_.stubs_.push_back(&stub7); | 356 client_.stubs_.push_back(&stub7); |
357 | 357 |
358 Manage(); | 358 Manage(); |
359 EXPECT_EQ(stub3.allocation_.has_frontbuffer, true); | 359 EXPECT_EQ(stub3.allocation_.suggest_have_frontbuffer, true); |
360 EXPECT_EQ(stub3.allocation_.has_backbuffer, false); | 360 EXPECT_EQ(stub3.allocation_.suggest_have_backbuffer, false); |
361 EXPECT_EQ(stub4.allocation_.has_frontbuffer, false); | 361 EXPECT_EQ(stub4.allocation_.suggest_have_frontbuffer, false); |
362 EXPECT_EQ(stub4.allocation_.has_backbuffer, false); | 362 EXPECT_EQ(stub4.allocation_.suggest_have_backbuffer, false); |
363 EXPECT_EQ(stub5.allocation_, stub3.allocation_); | 363 EXPECT_EQ(stub5.allocation_, stub3.allocation_); |
364 EXPECT_EQ(stub6.allocation_, stub4.allocation_); | 364 EXPECT_EQ(stub6.allocation_, stub4.allocation_); |
365 EXPECT_EQ(stub7.allocation_, stub3.allocation_); | 365 EXPECT_EQ(stub7.allocation_, stub3.allocation_); |
366 | 366 |
367 stub3.surface_state_.last_used_time = older_; | 367 stub3.surface_state_.last_used_time = older_; |
368 stub4.surface_state_.last_used_time = newer_; | 368 stub4.surface_state_.last_used_time = newer_; |
369 | 369 |
370 Manage(); | 370 Manage(); |
371 EXPECT_EQ(stub3.allocation_.has_frontbuffer, false); | 371 EXPECT_EQ(stub3.allocation_.suggest_have_frontbuffer, false); |
372 EXPECT_EQ(stub3.allocation_.has_backbuffer, false); | 372 EXPECT_EQ(stub3.allocation_.suggest_have_backbuffer, false); |
373 EXPECT_EQ(stub4.allocation_.has_frontbuffer, true); | 373 EXPECT_EQ(stub4.allocation_.suggest_have_frontbuffer, true); |
374 EXPECT_EQ(stub4.allocation_.has_backbuffer, false); | 374 EXPECT_EQ(stub4.allocation_.suggest_have_backbuffer, false); |
375 EXPECT_EQ(stub5.allocation_, stub3.allocation_); | 375 EXPECT_EQ(stub5.allocation_, stub3.allocation_); |
376 EXPECT_EQ(stub6.allocation_, stub4.allocation_); | 376 EXPECT_EQ(stub6.allocation_, stub4.allocation_); |
377 EXPECT_EQ(stub7.allocation_, stub4.allocation_); | 377 EXPECT_EQ(stub7.allocation_, stub4.allocation_); |
378 } | 378 } |
379 | 379 |
380 // Test GpuMemoryManager::Manage functionality: Test changing importance of | 380 // Test GpuMemoryManager::Manage functionality: Test changing importance of |
381 // enough stubs so that every stub in share group crosses threshold. | 381 // enough stubs so that every stub in share group crosses threshold. |
382 // Expect memory allocation of the stubs without surface to share memory | 382 // Expect memory allocation of the stubs without surface to share memory |
383 // allocation with the most visible stub in share group. | 383 // allocation with the most visible stub in share group. |
384 TEST_F(GpuMemoryManagerTest, TestManageChangingImportanceShareGroup) { | 384 TEST_F(GpuMemoryManagerTest, TestManageChangingImportanceShareGroup) { |
(...skipping 10 matching lines...) Expand all Loading... |
395 | 395 |
396 FakeCommandBufferStubWithoutSurface stub3, stub4; | 396 FakeCommandBufferStubWithoutSurface stub3, stub4; |
397 stub3.share_group_.push_back(&stub1); | 397 stub3.share_group_.push_back(&stub1); |
398 stub3.share_group_.push_back(&stub2); | 398 stub3.share_group_.push_back(&stub2); |
399 stub4.share_group_.push_back(&stub1); | 399 stub4.share_group_.push_back(&stub1); |
400 stub4.share_group_.push_back(&stub2); | 400 stub4.share_group_.push_back(&stub2); |
401 client_.stubs_.push_back(&stub3); | 401 client_.stubs_.push_back(&stub3); |
402 client_.stubs_.push_back(&stub4); | 402 client_.stubs_.push_back(&stub4); |
403 | 403 |
404 Manage(); | 404 Manage(); |
405 EXPECT_EQ(stub1.allocation_.has_frontbuffer, true); | 405 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, true); |
406 EXPECT_EQ(stub1.allocation_.has_backbuffer, true); | 406 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, true); |
407 EXPECT_EQ(stub2.allocation_.has_frontbuffer, true); | 407 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, true); |
408 EXPECT_EQ(stub2.allocation_.has_backbuffer, true); | 408 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, true); |
409 EXPECT_EQ(stub3.allocation_, stub1.allocation_); | 409 EXPECT_EQ(stub3.allocation_, stub1.allocation_); |
410 EXPECT_EQ(stub3.allocation_, stub2.allocation_); | 410 EXPECT_EQ(stub3.allocation_, stub2.allocation_); |
411 EXPECT_EQ(stub4.allocation_, stub1.allocation_); | 411 EXPECT_EQ(stub4.allocation_, stub1.allocation_); |
412 EXPECT_EQ(stub4.allocation_, stub2.allocation_); | 412 EXPECT_EQ(stub4.allocation_, stub2.allocation_); |
413 | 413 |
414 stub1.surface_state_.visible = false; | 414 stub1.surface_state_.visible = false; |
415 | 415 |
416 Manage(); | 416 Manage(); |
417 EXPECT_EQ(stub1.allocation_.has_frontbuffer, true); | 417 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, true); |
418 EXPECT_EQ(stub1.allocation_.has_backbuffer, false); | 418 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, false); |
419 EXPECT_EQ(stub2.allocation_.has_frontbuffer, true); | 419 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, true); |
420 EXPECT_EQ(stub2.allocation_.has_backbuffer, true); | 420 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, true); |
421 EXPECT_NE(stub3.allocation_, stub1.allocation_); | 421 EXPECT_NE(stub3.allocation_, stub1.allocation_); |
422 EXPECT_EQ(stub3.allocation_, stub2.allocation_); | 422 EXPECT_EQ(stub3.allocation_, stub2.allocation_); |
423 EXPECT_NE(stub4.allocation_, stub1.allocation_); | 423 EXPECT_NE(stub4.allocation_, stub1.allocation_); |
424 EXPECT_EQ(stub4.allocation_, stub2.allocation_); | 424 EXPECT_EQ(stub4.allocation_, stub2.allocation_); |
425 | 425 |
426 stub2.surface_state_.visible = false; | 426 stub2.surface_state_.visible = false; |
427 | 427 |
428 Manage(); | 428 Manage(); |
429 EXPECT_EQ(stub1.allocation_.has_frontbuffer, true); | 429 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, true); |
430 EXPECT_EQ(stub1.allocation_.has_backbuffer, false); | 430 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, false); |
431 EXPECT_EQ(stub2.allocation_.has_frontbuffer, true); | 431 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, true); |
432 EXPECT_EQ(stub2.allocation_.has_backbuffer, false); | 432 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, false); |
433 EXPECT_EQ(stub3.allocation_, stub1.allocation_); | 433 EXPECT_EQ(stub3.allocation_, stub1.allocation_); |
434 EXPECT_EQ(stub3.allocation_, stub2.allocation_); | 434 EXPECT_EQ(stub3.allocation_, stub2.allocation_); |
435 EXPECT_EQ(stub4.allocation_, stub1.allocation_); | 435 EXPECT_EQ(stub4.allocation_, stub1.allocation_); |
436 EXPECT_EQ(stub4.allocation_, stub2.allocation_); | 436 EXPECT_EQ(stub4.allocation_, stub2.allocation_); |
437 | 437 |
438 stub1.surface_state_.last_used_time = older_; | 438 stub1.surface_state_.last_used_time = older_; |
439 | 439 |
440 Manage(); | 440 Manage(); |
441 EXPECT_EQ(stub1.allocation_.has_frontbuffer, false); | 441 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, false); |
442 EXPECT_EQ(stub1.allocation_.has_backbuffer, false); | 442 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, false); |
443 EXPECT_EQ(stub2.allocation_.has_frontbuffer, true); | 443 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, true); |
444 EXPECT_EQ(stub2.allocation_.has_backbuffer, false); | 444 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, false); |
445 EXPECT_NE(stub3.allocation_, stub1.allocation_); | 445 EXPECT_NE(stub3.allocation_, stub1.allocation_); |
446 EXPECT_EQ(stub3.allocation_, stub2.allocation_); | 446 EXPECT_EQ(stub3.allocation_, stub2.allocation_); |
447 EXPECT_NE(stub4.allocation_, stub1.allocation_); | 447 EXPECT_NE(stub4.allocation_, stub1.allocation_); |
448 EXPECT_EQ(stub4.allocation_, stub2.allocation_); | 448 EXPECT_EQ(stub4.allocation_, stub2.allocation_); |
449 | 449 |
450 stub2.surface_state_.last_used_time = older_; | 450 stub2.surface_state_.last_used_time = older_; |
451 | 451 |
452 Manage(); | 452 Manage(); |
453 EXPECT_EQ(stub1.allocation_.has_frontbuffer, false); | 453 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, false); |
454 EXPECT_EQ(stub1.allocation_.has_backbuffer, false); | 454 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, false); |
455 EXPECT_EQ(stub2.allocation_.has_frontbuffer, false); | 455 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, false); |
456 EXPECT_EQ(stub2.allocation_.has_backbuffer, false); | 456 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, false); |
457 EXPECT_EQ(stub3.allocation_, stub1.allocation_); | 457 EXPECT_EQ(stub3.allocation_, stub1.allocation_); |
458 EXPECT_EQ(stub3.allocation_, stub2.allocation_); | 458 EXPECT_EQ(stub3.allocation_, stub2.allocation_); |
459 EXPECT_EQ(stub4.allocation_, stub1.allocation_); | 459 EXPECT_EQ(stub4.allocation_, stub1.allocation_); |
460 EXPECT_EQ(stub4.allocation_, stub2.allocation_); | 460 EXPECT_EQ(stub4.allocation_, stub2.allocation_); |
461 } | 461 } |
| 462 |
| 463 // Test GpuMemoryAllocation comparison operators: Iterate over all possible |
| 464 // combinations of gpu_resource_size_in_bytes, suggest_have_backbuffer, and |
| 465 // suggest_have_frontbuffer, and make sure allocations with equal values test |
| 466 // equal and non equal values test not equal. |
| 467 TEST_F(GpuMemoryManagerTest, GpuMemoryAllocationCompareTests) { |
| 468 int gpu_resource_size_in_bytes_values[] = { 0, 1, 12345678 }; |
| 469 bool suggest_have_backbuffer_values[] = { false, true }; |
| 470 bool suggest_have_frontbuffer_values[] = { false, true }; |
| 471 |
| 472 for(int* sz = &gpu_resource_size_in_bytes_values[0]; |
| 473 sz != &gpu_resource_size_in_bytes_values[3]; ++sz) { |
| 474 for(bool* shbb = &suggest_have_backbuffer_values[0]; |
| 475 shbb != &suggest_have_backbuffer_values[2]; ++shbb) { |
| 476 for(bool* shfb = &suggest_have_frontbuffer_values[0]; |
| 477 shfb != &suggest_have_frontbuffer_values[2]; ++shfb) { |
| 478 GpuMemoryAllocation allocation(*sz, *shbb, *shfb); |
| 479 EXPECT_EQ(allocation, GpuMemoryAllocation(*sz, *shbb, *shfb)); |
| 480 EXPECT_NE(allocation, GpuMemoryAllocation(*sz+1, *shbb, *shfb)); |
| 481 EXPECT_NE(allocation, GpuMemoryAllocation(*sz, !*shbb, *shfb)); |
| 482 EXPECT_NE(allocation, GpuMemoryAllocation(*sz, *shbb, !*shfb)); |
| 483 } |
| 484 } |
| 485 } |
| 486 } |
OLD | NEW |