OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/view_manager/gles2/mojo_gpu_memory_buffer.h" | 5 #include "components/view_manager/gles2/mojo_gpu_memory_buffer.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/shared_memory.h" | 8 #include "base/memory/shared_memory.h" |
9 #include "base/numerics/safe_conversions.h" | 9 #include "base/numerics/safe_conversions.h" |
10 #include "ui/gfx/buffer_format_util.h" | 10 #include "ui/gfx/buffer_format_util.h" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 return nullptr; | 106 return nullptr; |
107 return make_scoped_ptr<gfx::GpuMemoryBuffer>( | 107 return make_scoped_ptr<gfx::GpuMemoryBuffer>( |
108 new MojoGpuMemoryBufferImpl(size, format, shared_memory.Pass())); | 108 new MojoGpuMemoryBufferImpl(size, format, shared_memory.Pass())); |
109 } | 109 } |
110 | 110 |
111 MojoGpuMemoryBufferImpl* MojoGpuMemoryBufferImpl::FromClientBuffer( | 111 MojoGpuMemoryBufferImpl* MojoGpuMemoryBufferImpl::FromClientBuffer( |
112 ClientBuffer buffer) { | 112 ClientBuffer buffer) { |
113 return reinterpret_cast<MojoGpuMemoryBufferImpl*>(buffer); | 113 return reinterpret_cast<MojoGpuMemoryBufferImpl*>(buffer); |
114 } | 114 } |
115 | 115 |
| 116 const unsigned char* MojoGpuMemoryBufferImpl::GetMemory() const { |
| 117 return static_cast<const unsigned char*>(shared_memory_->memory()); |
| 118 } |
| 119 |
116 bool MojoGpuMemoryBufferImpl::Map(void** data) { | 120 bool MojoGpuMemoryBufferImpl::Map(void** data) { |
117 DCHECK(!mapped_); | 121 DCHECK(!mapped_); |
118 if (!shared_memory_->Map(BufferSizeInBytes(size_, format_))) | 122 if (!shared_memory_->Map(BufferSizeInBytes(size_, format_))) |
119 return false; | 123 return false; |
120 mapped_ = true; | 124 mapped_ = true; |
121 size_t offset = 0; | 125 size_t offset = 0; |
122 int num_planes = static_cast<int>( | 126 int num_planes = static_cast<int>( |
123 gfx::NumberOfPlanesForBufferFormat(format_)); | 127 gfx::NumberOfPlanesForBufferFormat(format_)); |
124 for (int i = 0; i < num_planes; ++i) { | 128 for (int i = 0; i < num_planes; ++i) { |
125 data[i] = reinterpret_cast<uint8*>(shared_memory_->memory()) + offset; | 129 data[i] = reinterpret_cast<uint8*>(shared_memory_->memory()) + offset; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 handle.type = gfx::SHARED_MEMORY_BUFFER; | 164 handle.type = gfx::SHARED_MEMORY_BUFFER; |
161 handle.handle = shared_memory_->handle(); | 165 handle.handle = shared_memory_->handle(); |
162 return handle; | 166 return handle; |
163 } | 167 } |
164 | 168 |
165 ClientBuffer MojoGpuMemoryBufferImpl::AsClientBuffer() { | 169 ClientBuffer MojoGpuMemoryBufferImpl::AsClientBuffer() { |
166 return reinterpret_cast<ClientBuffer>(this); | 170 return reinterpret_cast<ClientBuffer>(this); |
167 } | 171 } |
168 | 172 |
169 } // namespace gles2 | 173 } // namespace gles2 |
OLD | NEW |