| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/client/gpu_memory_buffer_impl_shm.h" | 5 #include "content/common/gpu/client/gpu_memory_buffer_impl_shm.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "ui/gl/gl_bindings.h" |
| 8 | 9 |
| 9 namespace content { | 10 namespace content { |
| 10 | 11 |
| 11 GpuMemoryBufferImplShm::GpuMemoryBufferImplShm(gfx::Size size, | 12 GpuMemoryBufferImplShm::GpuMemoryBufferImplShm(gfx::Size size, |
| 12 unsigned internalformat) | 13 unsigned internalformat) |
| 13 : GpuMemoryBufferImpl(size, internalformat) {} | 14 : GpuMemoryBufferImpl(size, internalformat) {} |
| 14 | 15 |
| 15 GpuMemoryBufferImplShm::~GpuMemoryBufferImplShm() {} | 16 GpuMemoryBufferImplShm::~GpuMemoryBufferImplShm() {} |
| 16 | 17 |
| 18 // static |
| 19 bool GpuMemoryBufferImplShm::IsUsageSupported(unsigned usage) { |
| 20 switch (usage) { |
| 21 case GL_IMAGE_MAP_CHROMIUM: |
| 22 return true; |
| 23 default: |
| 24 return false; |
| 25 } |
| 26 } |
| 27 |
| 17 bool GpuMemoryBufferImplShm::Initialize(gfx::GpuMemoryBufferHandle handle) { | 28 bool GpuMemoryBufferImplShm::Initialize(gfx::GpuMemoryBufferHandle handle) { |
| 18 if (!base::SharedMemory::IsHandleValid(handle.handle)) | 29 if (!base::SharedMemory::IsHandleValid(handle.handle)) |
| 19 return false; | 30 return false; |
| 20 shared_memory_.reset(new base::SharedMemory(handle.handle, false)); | 31 shared_memory_.reset(new base::SharedMemory(handle.handle, false)); |
| 21 DCHECK(!shared_memory_->memory()); | 32 DCHECK(!shared_memory_->memory()); |
| 22 return true; | 33 return true; |
| 23 } | 34 } |
| 24 | 35 |
| 25 bool GpuMemoryBufferImplShm::InitializeFromSharedMemory( | 36 bool GpuMemoryBufferImplShm::InitializeFromSharedMemory( |
| 26 scoped_ptr<base::SharedMemory> shared_memory) { | 37 scoped_ptr<base::SharedMemory> shared_memory) { |
| 27 shared_memory_ = shared_memory.Pass(); | 38 shared_memory_ = shared_memory.Pass(); |
| 28 DCHECK(!shared_memory_->memory()); | 39 DCHECK(!shared_memory_->memory()); |
| 29 return true; | 40 return true; |
| 30 } | 41 } |
| 31 | 42 |
| 32 void* GpuMemoryBufferImplShm::Map(AccessMode mode) { | 43 void* GpuMemoryBufferImplShm::Map() { |
| 33 DCHECK(!mapped_); | 44 DCHECK(!mapped_); |
| 34 if (!shared_memory_->Map(size_.GetArea() * BytesPerPixel(internalformat_))) | 45 if (!shared_memory_->Map(size_.GetArea() * BytesPerPixel(internalformat_))) |
| 35 return NULL; | 46 return NULL; |
| 36 mapped_ = true; | 47 mapped_ = true; |
| 37 return shared_memory_->memory(); | 48 return shared_memory_->memory(); |
| 38 } | 49 } |
| 39 | 50 |
| 40 void GpuMemoryBufferImplShm::Unmap() { | 51 void GpuMemoryBufferImplShm::Unmap() { |
| 41 DCHECK(mapped_); | 52 DCHECK(mapped_); |
| 42 shared_memory_->Unmap(); | 53 shared_memory_->Unmap(); |
| 43 mapped_ = false; | 54 mapped_ = false; |
| 44 } | 55 } |
| 45 | 56 |
| 46 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplShm::GetHandle() const { | 57 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplShm::GetHandle() const { |
| 47 gfx::GpuMemoryBufferHandle handle; | 58 gfx::GpuMemoryBufferHandle handle; |
| 48 handle.type = gfx::SHARED_MEMORY_BUFFER; | 59 handle.type = gfx::SHARED_MEMORY_BUFFER; |
| 49 handle.handle = shared_memory_->handle(); | 60 handle.handle = shared_memory_->handle(); |
| 50 return handle; | 61 return handle; |
| 51 } | 62 } |
| 52 | 63 |
| 53 } // namespace content | 64 } // namespace content |
| OLD | NEW |