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

Side by Side Diff: gpu/command_buffer/client/mapped_memory_unittest.cc

Issue 1168853002: Use mapped memory for uploading large textures. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Bad upload, reupload Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "gpu/command_buffer/client/mapped_memory.h" 5 #include "gpu/command_buffer/client/mapped_memory.h"
6 6
7 #include <list> 7 #include <list>
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 // It will reuse the space from the second allocation just freed. 387 // It will reuse the space from the second allocation just freed.
388 EXPECT_EQ(kSize, offset3); 388 EXPECT_EQ(kSize, offset3);
389 389
390 // Expect one chunk to be allocated 390 // Expect one chunk to be allocated
391 EXPECT_EQ(1 * kChunkSize, manager_->allocated_memory()); 391 EXPECT_EQ(1 * kChunkSize, manager_->allocated_memory());
392 392
393 manager_->Free(mem1); 393 manager_->Free(mem1);
394 manager_->Free(mem3); 394 manager_->Free(mem3);
395 } 395 }
396 396
397 TEST_F(MappedMemoryManagerTest, MaxAllocationTest) {
398 const unsigned int kSize = 1024;
399 // Reset the manager with a memory limit.
400 manager_.reset(new MappedMemoryManager(
401 helper_.get(), base::Bind(&EmptyPoll), kSize));
402
403 const size_t kLimit = 512;
404 manager_->set_chunk_size_multiple(kLimit);
405
406 // Allocate twice the limit worth of memory (currently unbounded).
407 int32 id1 = -1;
408 unsigned int offset1 = 0xFFFFFFFFU;
409 void* mem1 = manager_->Alloc(kLimit, &id1, &offset1);
410 ASSERT_TRUE(mem1);
411 EXPECT_NE(-1, id1);
412 EXPECT_EQ(0u, offset1);
413
414 int32 id2 = -1;
415 unsigned int offset2 = 0xFFFFFFFFU;
416 void* mem2 = manager_->Alloc(kLimit, &id2, &offset2);
417 ASSERT_TRUE(mem2);
418 EXPECT_NE(-1, id2);
419 EXPECT_EQ(0u, offset2);
420
421 manager_->set_max_allocated_bytes(kLimit);
422
423 // A new allocation should now fail.
424 int32 id3 = -1;
425 unsigned int offset3 = 0xFFFFFFFFU;
426 void* mem3 = manager_->Alloc(kLimit, &id3, &offset3);
427 ASSERT_FALSE(mem3);
428 EXPECT_EQ(-1, id3);
429 EXPECT_EQ(0xFFFFFFFFU, offset3);
430
431 manager_->Free(mem2);
432
433 // New allocation is over the limit but should reuse allocated space
434 int32 id4 = -1;
435 unsigned int offset4 = 0xFFFFFFFFU;
436 void* mem4 = manager_->Alloc(kLimit, &id4, &offset4);
437 ASSERT_TRUE(mem4);
438 EXPECT_EQ(id2, id4);
439 EXPECT_EQ(offset2, offset4);
440
441 manager_->Free(mem1);
442 manager_->Free(mem4);
443 }
444
397 namespace { 445 namespace {
398 void Poll(MappedMemoryManagerTest *test, std::list<void*>* list) { 446 void Poll(MappedMemoryManagerTest *test, std::list<void*>* list) {
399 std::list<void*>::iterator it = list->begin(); 447 std::list<void*>::iterator it = list->begin();
400 while (it != list->end()) { 448 while (it != list->end()) {
401 void* address = *it; 449 void* address = *it;
402 test->manager()->Free(address); 450 test->manager()->Free(address);
403 it = list->erase(it); 451 it = list->erase(it);
404 } 452 }
405 } 453 }
406 } 454 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 unsigned int offset3; 487 unsigned int offset3;
440 void* mem3 = manager_->Alloc(kSize, &id3, &offset3); 488 void* mem3 = manager_->Alloc(kSize, &id3, &offset3);
441 EXPECT_EQ(manager_->bytes_in_use(), kSize * 2); 489 EXPECT_EQ(manager_->bytes_in_use(), kSize * 2);
442 490
443 manager_->Free(mem2); 491 manager_->Free(mem2);
444 manager_->Free(mem3); 492 manager_->Free(mem3);
445 EXPECT_EQ(manager_->bytes_in_use(), static_cast<size_t>(0)); 493 EXPECT_EQ(manager_->bytes_in_use(), static_cast<size_t>(0));
446 } 494 }
447 495
448 } // namespace gpu 496 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698