Chromium Code Reviews| Index: content/common/gpu/client/gpu_memory_buffer_impl_shm.cc |
| diff --git a/content/common/gpu/client/gpu_memory_buffer_impl_shm.cc b/content/common/gpu/client/gpu_memory_buffer_impl_shm.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7af4452be1aafb62965f1b6a04fb98ac6bcc6983 |
| --- /dev/null |
| +++ b/content/common/gpu/client/gpu_memory_buffer_impl_shm.cc |
| @@ -0,0 +1,56 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/common/gpu/client/gpu_memory_buffer_impl_shm.h" |
| + |
| +#include "base/logging.h" |
| + |
| +namespace content { |
| + |
| +GpuMemoryBufferImplShm::GpuMemoryBufferImplShm( |
| + gfx::Size size, unsigned internalformat) |
| + : GpuMemoryBufferImpl(size, internalformat) { |
| +} |
| + |
| +GpuMemoryBufferImplShm::~GpuMemoryBufferImplShm() { |
| +} |
| + |
| +bool GpuMemoryBufferImplShm::Initialize(gfx::GpuMemoryBufferHandle handle) { |
| + if (!base::SharedMemory::IsHandleValid(handle.handle)) |
| + return false; |
| + shared_memory_.reset(new base::SharedMemory(handle.handle, false)); |
| + DCHECK(!shared_memory_->memory()); |
| + return true; |
| +} |
| + |
| +bool GpuMemoryBufferImplShm::InitializeFromSharedMemory( |
| + scoped_ptr<base::SharedMemory> shared_memory) { |
| + shared_memory_ = shared_memory.Pass(); |
| + DCHECK(!shared_memory_->memory()); |
| + return true; |
| +} |
| + |
| +void GpuMemoryBufferImplShm::Map(AccessMode mode, void** vaddr) { |
|
Ken Russell (switch to Gerrit)
2013/12/03 22:36:13
How often are Map/Unmap expected to be called?
I
reveman
2013/12/04 02:00:31
Less frequently than the buffer is used for drawin
|
| + DCHECK(!mapped_); |
| + *vaddr = NULL; |
| + if (!shared_memory_->Map(size_.GetArea() * BytesPerPixel(internalformat_))) |
| + return; |
| + *vaddr = shared_memory_->memory(); |
| + mapped_ = true; |
| +} |
| + |
| +void GpuMemoryBufferImplShm::Unmap() { |
| + DCHECK(mapped_); |
| + shared_memory_->Unmap(); |
| + mapped_ = false; |
| +} |
| + |
| +gfx::GpuMemoryBufferHandle GpuMemoryBufferImplShm::GetHandle() const { |
| + gfx::GpuMemoryBufferHandle handle; |
| + handle.type = gfx::SHARED_MEMORY_BUFFER; |
| + handle.handle = shared_memory_->handle(); |
| + return handle; |
| +} |
| + |
| +} // namespace content |