| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "gpu/ipc/client/gpu_memory_buffer_impl_shared_memory.h" | 5 #include "gpu/ipc/client/gpu_memory_buffer_impl_shared_memory.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 } // namespace | 22 } // namespace |
| 23 | 23 |
| 24 GpuMemoryBufferImplSharedMemory::GpuMemoryBufferImplSharedMemory( | 24 GpuMemoryBufferImplSharedMemory::GpuMemoryBufferImplSharedMemory( |
| 25 gfx::GpuMemoryBufferId id, | 25 gfx::GpuMemoryBufferId id, |
| 26 const gfx::Size& size, | 26 const gfx::Size& size, |
| 27 gfx::BufferFormat format, | 27 gfx::BufferFormat format, |
| 28 const DestructionCallback& callback, | 28 const DestructionCallback& callback, |
| 29 std::unique_ptr<base::SharedMemory> shared_memory, | 29 std::unique_ptr<base::SharedMemory> shared_memory, |
| 30 size_t offset, | 30 size_t offset, |
| 31 int stride) | 31 uint32_t stride) |
| 32 : GpuMemoryBufferImpl(id, size, format, callback), | 32 : GpuMemoryBufferImpl(id, size, format, callback), |
| 33 shared_memory_(std::move(shared_memory)), | 33 shared_memory_(std::move(shared_memory)), |
| 34 offset_(offset), | 34 offset_(offset), |
| 35 stride_(stride) { | 35 stride_(stride) { |
| 36 DCHECK(IsSizeValidForFormat(size, format)); | 36 DCHECK(IsSizeValidForFormat(size, format)); |
| 37 } | 37 } |
| 38 | 38 |
| 39 GpuMemoryBufferImplSharedMemory::~GpuMemoryBufferImplSharedMemory() {} | 39 GpuMemoryBufferImplSharedMemory::~GpuMemoryBufferImplSharedMemory() {} |
| 40 | 40 |
| 41 // static | 41 // static |
| (...skipping 27 matching lines...) Expand all Loading... |
| 69 return gfx::GpuMemoryBufferHandle(); | 69 return gfx::GpuMemoryBufferHandle(); |
| 70 | 70 |
| 71 base::SharedMemory shared_memory; | 71 base::SharedMemory shared_memory; |
| 72 if (!shared_memory.CreateAnonymous(buffer_size)) | 72 if (!shared_memory.CreateAnonymous(buffer_size)) |
| 73 return gfx::GpuMemoryBufferHandle(); | 73 return gfx::GpuMemoryBufferHandle(); |
| 74 | 74 |
| 75 gfx::GpuMemoryBufferHandle handle; | 75 gfx::GpuMemoryBufferHandle handle; |
| 76 handle.type = gfx::SHARED_MEMORY_BUFFER; | 76 handle.type = gfx::SHARED_MEMORY_BUFFER; |
| 77 handle.id = id; | 77 handle.id = id; |
| 78 handle.offset = 0; | 78 handle.offset = 0; |
| 79 handle.stride = static_cast<int32_t>( | 79 handle.stride = static_cast<uint32_t>( |
| 80 gfx::RowSizeForBufferFormat(size.width(), format, 0)); | 80 gfx::RowSizeForBufferFormat(size.width(), format, 0)); |
| 81 shared_memory.GiveToProcess(child_process, &handle.handle); | 81 shared_memory.GiveToProcess(child_process, &handle.handle); |
| 82 return handle; | 82 return handle; |
| 83 } | 83 } |
| 84 | 84 |
| 85 // static | 85 // static |
| 86 std::unique_ptr<GpuMemoryBufferImplSharedMemory> | 86 std::unique_ptr<GpuMemoryBufferImplSharedMemory> |
| 87 GpuMemoryBufferImplSharedMemory::CreateFromHandle( | 87 GpuMemoryBufferImplSharedMemory::CreateFromHandle( |
| 88 const gfx::GpuMemoryBufferHandle& handle, | 88 const gfx::GpuMemoryBufferHandle& handle, |
| 89 const gfx::Size& size, | 89 const gfx::Size& size, |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 const gfx::Size& size, | 163 const gfx::Size& size, |
| 164 gfx::BufferFormat format, | 164 gfx::BufferFormat format, |
| 165 gfx::BufferUsage usage, | 165 gfx::BufferUsage usage, |
| 166 gfx::GpuMemoryBufferHandle* handle) { | 166 gfx::GpuMemoryBufferHandle* handle) { |
| 167 base::SharedMemory shared_memory; | 167 base::SharedMemory shared_memory; |
| 168 bool rv = shared_memory.CreateAnonymous( | 168 bool rv = shared_memory.CreateAnonymous( |
| 169 gfx::BufferSizeForBufferFormat(size, format)); | 169 gfx::BufferSizeForBufferFormat(size, format)); |
| 170 DCHECK(rv); | 170 DCHECK(rv); |
| 171 handle->type = gfx::SHARED_MEMORY_BUFFER; | 171 handle->type = gfx::SHARED_MEMORY_BUFFER; |
| 172 handle->offset = 0; | 172 handle->offset = 0; |
| 173 handle->stride = static_cast<int32_t>( | 173 handle->stride = static_cast<uint32_t>( |
| 174 gfx::RowSizeForBufferFormat(size.width(), format, 0)); | 174 gfx::RowSizeForBufferFormat(size.width(), format, 0)); |
| 175 handle->handle = base::SharedMemory::DuplicateHandle(shared_memory.handle()); | 175 handle->handle = base::SharedMemory::DuplicateHandle(shared_memory.handle()); |
| 176 return base::Bind(&Noop); | 176 return base::Bind(&Noop); |
| 177 } | 177 } |
| 178 | 178 |
| 179 bool GpuMemoryBufferImplSharedMemory::Map() { | 179 bool GpuMemoryBufferImplSharedMemory::Map() { |
| 180 DCHECK(!mapped_); | 180 DCHECK(!mapped_); |
| 181 | 181 |
| 182 // Map the buffer first time Map() is called then keep it mapped for the | 182 // Map the buffer first time Map() is called then keep it mapped for the |
| 183 // lifetime of the buffer. This avoids mapping the buffer unless necessary. | 183 // lifetime of the buffer. This avoids mapping the buffer unless necessary. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 200 DCHECK_LT(plane, gfx::NumberOfPlanesForBufferFormat(format_)); | 200 DCHECK_LT(plane, gfx::NumberOfPlanesForBufferFormat(format_)); |
| 201 return reinterpret_cast<uint8_t*>(shared_memory_->memory()) + offset_ + | 201 return reinterpret_cast<uint8_t*>(shared_memory_->memory()) + offset_ + |
| 202 gfx::BufferOffsetForBufferFormat(size_, format_, plane); | 202 gfx::BufferOffsetForBufferFormat(size_, format_, plane); |
| 203 } | 203 } |
| 204 | 204 |
| 205 void GpuMemoryBufferImplSharedMemory::Unmap() { | 205 void GpuMemoryBufferImplSharedMemory::Unmap() { |
| 206 DCHECK(mapped_); | 206 DCHECK(mapped_); |
| 207 mapped_ = false; | 207 mapped_ = false; |
| 208 } | 208 } |
| 209 | 209 |
| 210 int GpuMemoryBufferImplSharedMemory::stride(size_t plane) const { | 210 uint32_t GpuMemoryBufferImplSharedMemory::stride(size_t plane) const { |
| 211 DCHECK_LT(plane, gfx::NumberOfPlanesForBufferFormat(format_)); | 211 DCHECK_LT(plane, gfx::NumberOfPlanesForBufferFormat(format_)); |
| 212 return gfx::RowSizeForBufferFormat(size_.width(), format_, plane); | 212 return gfx::RowSizeForBufferFormat(size_.width(), format_, plane); |
| 213 } | 213 } |
| 214 | 214 |
| 215 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplSharedMemory::GetHandle() const { | 215 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplSharedMemory::GetHandle() const { |
| 216 gfx::GpuMemoryBufferHandle handle; | 216 gfx::GpuMemoryBufferHandle handle; |
| 217 handle.type = gfx::SHARED_MEMORY_BUFFER; | 217 handle.type = gfx::SHARED_MEMORY_BUFFER; |
| 218 handle.id = id_; | 218 handle.id = id_; |
| 219 handle.offset = offset_; | 219 handle.offset = offset_; |
| 220 handle.stride = stride_; | 220 handle.stride = stride_; |
| 221 handle.handle = shared_memory_->handle(); | 221 handle.handle = shared_memory_->handle(); |
| 222 return handle; | 222 return handle; |
| 223 } | 223 } |
| 224 | 224 |
| 225 } // namespace gpu | 225 } // namespace gpu |
| OLD | NEW |