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.h" | 5 #include "content/common/gpu/client/gpu_memory_buffer_impl.h" |
6 | 6 |
7 #include "ui/gl/gl_bindings.h" | 7 #include "ui/gl/gl_bindings.h" |
8 | 8 |
9 namespace content { | 9 namespace content { |
10 | 10 |
11 GpuMemoryBufferImpl::GpuMemoryBufferImpl( | 11 GpuMemoryBufferImpl::GpuMemoryBufferImpl( |
12 scoped_ptr<base::SharedMemory> shared_memory, | 12 gfx::Size size, unsigned internalformat) |
13 size_t width, | 13 : size_(size), |
14 size_t height, | |
15 unsigned internalformat) | |
16 : shared_memory_(shared_memory.Pass()), | |
17 size_(gfx::Size(width, height)), | |
18 internalformat_(internalformat), | 14 internalformat_(internalformat), |
19 mapped_(false) { | 15 mapped_(false) { |
20 DCHECK(!shared_memory_->memory()); | |
21 DCHECK(IsFormatValid(internalformat)); | 16 DCHECK(IsFormatValid(internalformat)); |
22 } | 17 } |
23 | 18 |
24 GpuMemoryBufferImpl::~GpuMemoryBufferImpl() { | 19 GpuMemoryBufferImpl::~GpuMemoryBufferImpl() { |
25 } | 20 } |
26 | 21 |
27 void GpuMemoryBufferImpl::Map(AccessMode mode, void** vaddr) { | |
28 DCHECK(!mapped_); | |
29 *vaddr = NULL; | |
30 if (!shared_memory_->Map(size_.GetArea() * BytesPerPixel(internalformat_))) | |
31 return; | |
32 *vaddr = shared_memory_->memory(); | |
33 mapped_ = true; | |
34 } | |
35 | |
36 void GpuMemoryBufferImpl::Unmap() { | |
37 DCHECK(mapped_); | |
38 shared_memory_->Unmap(); | |
39 mapped_ = false; | |
40 } | |
41 | |
42 bool GpuMemoryBufferImpl::IsMapped() const { | |
43 return mapped_; | |
44 } | |
45 | |
46 uint32 GpuMemoryBufferImpl::GetStride() const { | |
47 return size_.width() * BytesPerPixel(internalformat_); | |
48 } | |
49 | |
50 gfx::GpuMemoryBufferHandle GpuMemoryBufferImpl::GetHandle() const { | |
51 gfx::GpuMemoryBufferHandle handle; | |
52 handle.type = gfx::SHARED_MEMORY_BUFFER; | |
53 handle.handle = shared_memory_->handle(); | |
54 return handle; | |
55 } | |
56 | |
57 // static | 22 // static |
58 bool GpuMemoryBufferImpl::IsFormatValid(unsigned internalformat) { | 23 bool GpuMemoryBufferImpl::IsFormatValid(unsigned internalformat) { |
59 switch (internalformat) { | 24 switch (internalformat) { |
60 case GL_BGRA8_EXT: | 25 case GL_BGRA8_EXT: |
61 case GL_RGBA8_OES: | 26 case GL_RGBA8_OES: |
62 return true; | 27 return true; |
63 default: | 28 default: |
64 return false; | 29 return false; |
65 } | 30 } |
66 } | 31 } |
67 | 32 |
68 // static | 33 // static |
69 size_t GpuMemoryBufferImpl::BytesPerPixel(unsigned internalformat) { | 34 size_t GpuMemoryBufferImpl::BytesPerPixel(unsigned internalformat) { |
70 switch (internalformat) { | 35 switch (internalformat) { |
71 case GL_BGRA8_EXT: | 36 case GL_BGRA8_EXT: |
72 case GL_RGBA8_OES: | 37 case GL_RGBA8_OES: |
73 return 4; | 38 return 4; |
74 default: | 39 default: |
75 NOTREACHED(); | 40 NOTREACHED(); |
76 return 0; | 41 return 0; |
77 } | 42 } |
78 } | 43 } |
79 | 44 |
| 45 bool GpuMemoryBufferImpl::IsMapped() const { |
| 46 return mapped_; |
| 47 } |
| 48 |
| 49 uint32 GpuMemoryBufferImpl::GetStride() const { |
| 50 return size_.width() * BytesPerPixel(internalformat_); |
| 51 } |
| 52 |
80 } // namespace content | 53 } // namespace content |
OLD | NEW |