diff options
author | apatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-08 18:31:08 +0000 |
---|---|---|
committer | apatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-08 18:31:08 +0000 |
commit | 20407e957e31a0faf159403d47dc5d1d6c903f9e (patch) | |
tree | 350962b37d2cb6d9e0fdae78a24efb2bd3c72723 /gpu/command_buffer/client/mapped_memory.cc | |
parent | 9283f2789927383ece6aedbd948a645164c35c53 (diff) | |
download | chromium_src-20407e957e31a0faf159403d47dc5d1d6c903f9e.zip chromium_src-20407e957e31a0faf159403d47dc5d1d6c903f9e.tar.gz chromium_src-20407e957e31a0faf159403d47dc5d1d6c903f9e.tar.bz2 |
Removed dependencies on base from GPU common and client code.
The main change was to make scoped_ptr and the basic types the same for both NaCl and trusted plugins and to implement new logging code for GPU common and client code. Service code and unit tests can still use the logging code in base.
I am really not happy with the new logging code but I thought I'd let you take a look at it to see what you think. The biggest thing I don't like is it uses assert(false) to throw an exception in a platform independent way, which brings up a modal dialog. Not ideal in the middle of a unit test run. I don't know if that will make the bots hang. Hopefully they'll time out or something.
TEST=try
BUG=none
Review URL: http://codereview.chromium.org/2936009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58857 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu/command_buffer/client/mapped_memory.cc')
-rw-r--r-- | gpu/command_buffer/client/mapped_memory.cc | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/gpu/command_buffer/client/mapped_memory.cc b/gpu/command_buffer/client/mapped_memory.cc index 7aafe0a..d2c4886 100644 --- a/gpu/command_buffer/client/mapped_memory.cc +++ b/gpu/command_buffer/client/mapped_memory.cc @@ -2,10 +2,18 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "gpu/command_buffer/client/mapped_memory.h" -#include "gpu/command_buffer/client/cmd_buffer_helper.h" +#include <algorithm> +#include <functional> + +#include "../client/mapped_memory.h" +#include "../client/cmd_buffer_helper.h" namespace gpu { +namespace { +void DeleteMemoryChunk(MemoryChunk* chunk) { + delete chunk; +} +} MemoryChunk::MemoryChunk( int32 shm_id, gpu::Buffer shm, CommandBufferHelper* helper) @@ -14,17 +22,24 @@ MemoryChunk::MemoryChunk( allocator_(shm.size, helper, shm.ptr) { } +MappedMemoryManager::~MappedMemoryManager() { + std::for_each(chunks_.begin(), + chunks_.end(), + std::pointer_to_unary_function<MemoryChunk*, void>( + DeleteMemoryChunk)); +} + void* MappedMemoryManager::Alloc( unsigned int size, int32* shm_id, unsigned int* shm_offset) { - DCHECK(shm_id); - DCHECK(shm_offset); + GPU_DCHECK(shm_id); + GPU_DCHECK(shm_offset); // See if any of the chucks can satisfy this request. for (size_t ii = 0; ii < chunks_.size(); ++ii) { - MemoryChunk* chunk = chunks_[ii].get(); + MemoryChunk* chunk = chunks_[ii]; chunk->FreeUnused(); if (chunk->GetLargestFreeSizeWithoutWaiting() >= size) { void* mem = chunk->Alloc(size); - DCHECK(mem); + GPU_DCHECK(mem); *shm_id = chunk->shm_id(); *shm_offset = chunk->GetOffset(mem); return mem; @@ -38,10 +53,10 @@ void* MappedMemoryManager::Alloc( return NULL; } gpu::Buffer shm = cmd_buf->GetTransferBuffer(id); - MemoryChunk::Ref mc(new MemoryChunk(id, shm, helper_)); + MemoryChunk* mc = new MemoryChunk(id, shm, helper_); chunks_.push_back(mc); void* mem = mc->Alloc(size); - DCHECK(mem); + GPU_DCHECK(mem); *shm_id = mc->shm_id(); *shm_offset = mc->GetOffset(mem); return mem; @@ -49,24 +64,24 @@ void* MappedMemoryManager::Alloc( void MappedMemoryManager::Free(void* pointer) { for (size_t ii = 0; ii < chunks_.size(); ++ii) { - MemoryChunk* chunk = chunks_[ii].get(); + MemoryChunk* chunk = chunks_[ii]; if (chunk->IsInChunk(pointer)) { chunk->Free(pointer); return; } } - NOTREACHED(); + GPU_NOTREACHED(); } void MappedMemoryManager::FreePendingToken(void* pointer, int32 token) { for (size_t ii = 0; ii < chunks_.size(); ++ii) { - MemoryChunk* chunk = chunks_[ii].get(); + MemoryChunk* chunk = chunks_[ii]; if (chunk->IsInChunk(pointer)) { chunk->FreePendingToken(pointer, token); return; } } - NOTREACHED(); + GPU_NOTREACHED(); } } // namespace gpu |