| 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/mus/gles2/mojo_gpu_memory_buffer.h" | 5 #include "components/mus/gles2/mojo_gpu_memory_buffer.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/shared_memory.h" | 10 #include "base/memory/shared_memory.h" |
| 11 #include "base/numerics/safe_conversions.h" | 11 #include "base/numerics/safe_conversions.h" |
| 12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 13 #include "ui/gfx/buffer_format_util.h" | 13 #include "ui/gfx/buffer_format_util.h" |
| 14 | 14 |
| 15 namespace mus { | 15 namespace mus { |
| 16 | 16 |
| 17 MojoGpuMemoryBufferImpl::MojoGpuMemoryBufferImpl( | 17 MojoGpuMemoryBufferImpl::MojoGpuMemoryBufferImpl( |
| 18 const gfx::Size& size, | 18 const gfx::Size& size, |
| 19 gfx::BufferFormat format, | 19 gfx::BufferFormat format, |
| 20 scoped_ptr<base::SharedMemory> shared_memory) | 20 scoped_ptr<base::SharedMemory> shared_memory) |
| 21 : size_(size), | 21 : GpuMemoryBufferImpl(gfx::GenericSharedMemoryId(0), size, format), |
| 22 format_(format), | 22 shared_memory_(std::move(shared_memory)) {} |
| 23 shared_memory_(std::move(shared_memory)), | |
| 24 mapped_(false) {} | |
| 25 | 23 |
| 24 // TODO(rjkroege): Support running a destructor callback as necessary. |
| 26 MojoGpuMemoryBufferImpl::~MojoGpuMemoryBufferImpl() {} | 25 MojoGpuMemoryBufferImpl::~MojoGpuMemoryBufferImpl() {} |
| 27 | 26 |
| 28 scoped_ptr<gfx::GpuMemoryBuffer> MojoGpuMemoryBufferImpl::Create( | 27 scoped_ptr<gfx::GpuMemoryBuffer> MojoGpuMemoryBufferImpl::Create( |
| 29 const gfx::Size& size, | 28 const gfx::Size& size, |
| 30 gfx::BufferFormat format, | 29 gfx::BufferFormat format, |
| 31 gfx::BufferUsage usage) { | 30 gfx::BufferUsage usage) { |
| 32 size_t bytes = gfx::BufferSizeForBufferFormat(size, format); | 31 size_t bytes = gfx::BufferSizeForBufferFormat(size, format); |
| 33 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory); | 32 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory); |
| 34 | 33 |
| 35 #if defined(OS_MACOSX) | 34 #if defined(OS_MACOSX) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 return reinterpret_cast<uint8_t*>(shared_memory_->memory()) + | 68 return reinterpret_cast<uint8_t*>(shared_memory_->memory()) + |
| 70 gfx::BufferOffsetForBufferFormat(size_, format_, plane); | 69 gfx::BufferOffsetForBufferFormat(size_, format_, plane); |
| 71 } | 70 } |
| 72 | 71 |
| 73 void MojoGpuMemoryBufferImpl::Unmap() { | 72 void MojoGpuMemoryBufferImpl::Unmap() { |
| 74 DCHECK(mapped_); | 73 DCHECK(mapped_); |
| 75 shared_memory_->Unmap(); | 74 shared_memory_->Unmap(); |
| 76 mapped_ = false; | 75 mapped_ = false; |
| 77 } | 76 } |
| 78 | 77 |
| 79 gfx::Size MojoGpuMemoryBufferImpl::GetSize() const { | |
| 80 return size_; | |
| 81 } | |
| 82 | |
| 83 gfx::BufferFormat MojoGpuMemoryBufferImpl::GetFormat() const { | |
| 84 return format_; | |
| 85 } | |
| 86 | |
| 87 int MojoGpuMemoryBufferImpl::stride(size_t plane) const { | 78 int MojoGpuMemoryBufferImpl::stride(size_t plane) const { |
| 88 DCHECK_LT(plane, gfx::NumberOfPlanesForBufferFormat(format_)); | 79 DCHECK_LT(plane, gfx::NumberOfPlanesForBufferFormat(format_)); |
| 89 return base::checked_cast<int>(gfx::RowSizeForBufferFormat( | 80 return base::checked_cast<int>(gfx::RowSizeForBufferFormat( |
| 90 size_.width(), format_, static_cast<int>(plane))); | 81 size_.width(), format_, static_cast<int>(plane))); |
| 91 } | 82 } |
| 92 | 83 |
| 93 gfx::GpuMemoryBufferId MojoGpuMemoryBufferImpl::GetId() const { | |
| 94 return gfx::GpuMemoryBufferId(0); | |
| 95 } | |
| 96 | |
| 97 gfx::GpuMemoryBufferHandle MojoGpuMemoryBufferImpl::GetHandle() const { | 84 gfx::GpuMemoryBufferHandle MojoGpuMemoryBufferImpl::GetHandle() const { |
| 98 gfx::GpuMemoryBufferHandle handle; | 85 gfx::GpuMemoryBufferHandle handle; |
| 99 handle.type = gfx::SHARED_MEMORY_BUFFER; | 86 handle.type = gfx::SHARED_MEMORY_BUFFER; |
| 100 handle.handle = shared_memory_->handle(); | 87 handle.handle = shared_memory_->handle(); |
| 101 handle.offset = 0; | 88 handle.offset = 0; |
| 102 handle.stride = static_cast<int32_t>( | 89 handle.stride = static_cast<int32_t>( |
| 103 gfx::RowSizeForBufferFormat(size_.width(), format_, 0)); | 90 gfx::RowSizeForBufferFormat(size_.width(), format_, 0)); |
| 91 |
| 104 return handle; | 92 return handle; |
| 105 } | 93 } |
| 106 | 94 |
| 107 ClientBuffer MojoGpuMemoryBufferImpl::AsClientBuffer() { | 95 gfx::GpuMemoryBufferType MojoGpuMemoryBufferImpl::GetBufferType() const { |
| 108 return reinterpret_cast<ClientBuffer>(this); | 96 return gfx::SHARED_MEMORY_BUFFER; |
| 109 } | 97 } |
| 110 | 98 |
| 111 } // namespace mus | 99 } // namespace mus |
| OLD | NEW |