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

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: Discard blocks by simply marking them as padding. 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 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 manager_->set_chunk_size_multiple(kChunkSize); 317 manager_->set_chunk_size_multiple(kChunkSize);
318 318
319 // Allocate one chunk worth of memory. 319 // Allocate one chunk worth of memory.
320 int32 id1 = -1; 320 int32 id1 = -1;
321 unsigned int offset1 = 0xFFFFFFFFU; 321 unsigned int offset1 = 0xFFFFFFFFU;
322 void* mem1 = manager_->Alloc(kChunkSize, &id1, &offset1); 322 void* mem1 = manager_->Alloc(kChunkSize, &id1, &offset1);
323 ASSERT_TRUE(mem1); 323 ASSERT_TRUE(mem1);
324 EXPECT_NE(-1, id1); 324 EXPECT_NE(-1, id1);
325 EXPECT_EQ(0u, offset1); 325 EXPECT_EQ(0u, offset1);
326 326
327 EXPECT_EQ(kChunkSize, manager_->allocated_memory());
328
329 manager_->Free(mem1);
330
327 // Allocate half a chunk worth of memory again. 331 // Allocate half a chunk worth of memory again.
328 // The same chunk will be used. 332 // The same chunk will be used.
329 int32 id2 = -1; 333 int32 id2 = -1;
330 unsigned int offset2 = 0xFFFFFFFFU; 334 unsigned int offset2 = 0xFFFFFFFFU;
331 void* mem2 = manager_->Alloc(kChunkSize, &id2, &offset2); 335 void* mem2 = manager_->Alloc(kChunkSize, &id2, &offset2);
332 ASSERT_TRUE(mem2); 336 ASSERT_TRUE(mem2);
333 EXPECT_NE(-1, id2); 337 EXPECT_NE(-1, id2);
334 EXPECT_EQ(0u, offset2); 338 EXPECT_EQ(0u, offset2);
335 339
336 // Expect two chunks to be allocated, exceeding the limit, 340 // Expect two chunks to be allocated, exceeding the limit,
337 // since all memory is in use. 341 // since all memory is in use.
338 EXPECT_EQ(2 * kChunkSize, manager_->allocated_memory()); 342 EXPECT_EQ(kChunkSize, manager_->allocated_memory());
339 343
340 manager_->Free(mem1);
341 manager_->Free(mem2); 344 manager_->Free(mem2);
342 } 345 }
343 346
344 TEST_F(MappedMemoryManagerTest, MemoryLimitWithReuse) { 347 TEST_F(MappedMemoryManagerTest, MemoryLimitWithReuse) {
345 const unsigned int kSize = 1024; 348 const unsigned int kSize = 1024;
346 // Reset the manager with a memory limit. 349 // Reset the manager with a memory limit.
347 manager_.reset(new MappedMemoryManager( 350 manager_.reset(new MappedMemoryManager(
348 helper_.get(), base::Bind(&EmptyPoll), kSize)); 351 helper_.get(), base::Bind(&EmptyPoll), kSize));
349 const unsigned int kChunkSize = 2 * 1024; 352 const unsigned int kChunkSize = 2 * 1024;
350 manager_->set_chunk_size_multiple(kChunkSize); 353 manager_->set_chunk_size_multiple(kChunkSize);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 } 409 }
407 410
408 TEST_F(MappedMemoryManagerTest, Poll) { 411 TEST_F(MappedMemoryManagerTest, Poll) {
409 std::list<void*> unmanaged_memory_list; 412 std::list<void*> unmanaged_memory_list;
410 413
411 const unsigned int kSize = 1024; 414 const unsigned int kSize = 1024;
412 // Reset the manager with a memory limit. 415 // Reset the manager with a memory limit.
413 manager_.reset(new MappedMemoryManager( 416 manager_.reset(new MappedMemoryManager(
414 helper_.get(), 417 helper_.get(),
415 base::Bind(&Poll, this, &unmanaged_memory_list), 418 base::Bind(&Poll, this, &unmanaged_memory_list),
416 kSize)); 419 kSize*2));
417 420
418 // Allocate kSize bytes. Don't add the address to 421 // Allocate kSize bytes. Don't add the address to
419 // the unmanaged memory list, so that it won't be free:ed just yet. 422 // the unmanaged memory list, so that it won't be free:ed just yet.
420 int32 id1; 423 int32 id1;
421 unsigned int offset1; 424 unsigned int offset1;
422 void* mem1 = manager_->Alloc(kSize, &id1, &offset1); 425 void* mem1 = manager_->Alloc(kSize, &id1, &offset1);
423 EXPECT_EQ(manager_->bytes_in_use(), kSize); 426 EXPECT_EQ(manager_->bytes_in_use(), kSize);
424 427
425 // Allocate kSize more bytes, and make sure we grew. 428 // Allocate kSize more bytes, and make sure we grew.
426 int32 id2; 429 int32 id2;
(...skipping 12 matching lines...) Expand all
439 unsigned int offset3; 442 unsigned int offset3;
440 void* mem3 = manager_->Alloc(kSize, &id3, &offset3); 443 void* mem3 = manager_->Alloc(kSize, &id3, &offset3);
441 EXPECT_EQ(manager_->bytes_in_use(), kSize * 2); 444 EXPECT_EQ(manager_->bytes_in_use(), kSize * 2);
442 445
443 manager_->Free(mem2); 446 manager_->Free(mem2);
444 manager_->Free(mem3); 447 manager_->Free(mem3);
445 EXPECT_EQ(manager_->bytes_in_use(), static_cast<size_t>(0)); 448 EXPECT_EQ(manager_->bytes_in_use(), static_cast<size_t>(0));
446 } 449 }
447 450
448 } // namespace gpu 451 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698