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 | 8 |
9 namespace content { | 9 namespace content { |
10 | 10 |
11 GpuMemoryBufferImplShm::GpuMemoryBufferImplShm(gfx::Size size, | 11 GpuMemoryBufferImplShm::GpuMemoryBufferImplShm(gfx::Size size, |
12 unsigned internalformat) | 12 unsigned internalformat) |
13 : GpuMemoryBufferImpl(size, internalformat) {} | 13 : GpuMemoryBufferImpl(size, |
| 14 internalformat, |
| 15 gfx::GpuMemoryBuffer::READ_WRITE) { |
| 16 } |
14 | 17 |
15 GpuMemoryBufferImplShm::~GpuMemoryBufferImplShm() {} | 18 GpuMemoryBufferImplShm::~GpuMemoryBufferImplShm() {} |
16 | 19 |
17 bool GpuMemoryBufferImplShm::Initialize(gfx::GpuMemoryBufferHandle handle) { | 20 bool GpuMemoryBufferImplShm::Initialize(gfx::GpuMemoryBufferHandle handle) { |
18 if (!base::SharedMemory::IsHandleValid(handle.handle)) | 21 if (!base::SharedMemory::IsHandleValid(handle.handle)) |
19 return false; | 22 return false; |
20 shared_memory_.reset(new base::SharedMemory(handle.handle, false)); | 23 shared_memory_.reset(new base::SharedMemory(handle.handle, false)); |
21 DCHECK(!shared_memory_->memory()); | 24 DCHECK(!shared_memory_->memory()); |
22 return true; | 25 return true; |
23 } | 26 } |
24 | 27 |
25 bool GpuMemoryBufferImplShm::InitializeFromSharedMemory( | 28 bool GpuMemoryBufferImplShm::InitializeFromSharedMemory( |
26 scoped_ptr<base::SharedMemory> shared_memory) { | 29 scoped_ptr<base::SharedMemory> shared_memory) { |
27 shared_memory_ = shared_memory.Pass(); | 30 shared_memory_ = shared_memory.Pass(); |
28 DCHECK(!shared_memory_->memory()); | 31 DCHECK(!shared_memory_->memory()); |
29 return true; | 32 return true; |
30 } | 33 } |
31 | 34 |
32 void* GpuMemoryBufferImplShm::Map(AccessMode mode) { | 35 void* GpuMemoryBufferImplShm::Map() { |
33 DCHECK(!mapped_); | 36 DCHECK(!mapped_); |
34 if (!shared_memory_->Map(size_.GetArea() * BytesPerPixel(internalformat_))) | 37 if (!shared_memory_->Map(size_.GetArea() * BytesPerPixel(internalformat_))) |
35 return NULL; | 38 return NULL; |
36 mapped_ = true; | 39 mapped_ = true; |
37 return shared_memory_->memory(); | 40 return shared_memory_->memory(); |
38 } | 41 } |
39 | 42 |
40 void GpuMemoryBufferImplShm::Unmap() { | 43 void GpuMemoryBufferImplShm::Unmap() { |
41 DCHECK(mapped_); | 44 DCHECK(mapped_); |
42 shared_memory_->Unmap(); | 45 shared_memory_->Unmap(); |
43 mapped_ = false; | 46 mapped_ = false; |
44 } | 47 } |
45 | 48 |
46 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplShm::GetHandle() const { | 49 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplShm::GetHandle() const { |
47 gfx::GpuMemoryBufferHandle handle; | 50 gfx::GpuMemoryBufferHandle handle; |
48 handle.type = gfx::SHARED_MEMORY_BUFFER; | 51 handle.type = gfx::SHARED_MEMORY_BUFFER; |
49 handle.handle = shared_memory_->handle(); | 52 handle.handle = shared_memory_->handle(); |
50 return handle; | 53 return handle; |
51 } | 54 } |
52 | 55 |
53 } // namespace content | 56 } // namespace content |
OLD | NEW |