| 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 "services/ui/public/cpp/mojo_gpu_memory_buffer.h" | 5 #include "services/ui/public/cpp/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/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 size_t shared_memory_size; | 36 size_t shared_memory_size; |
| 37 bool readonly; | 37 bool readonly; |
| 38 MojoResult result = mojo::UnwrapSharedMemoryHandle( | 38 MojoResult result = mojo::UnwrapSharedMemoryHandle( |
| 39 std::move(handle), &platform_handle, &shared_memory_size, &readonly); | 39 std::move(handle), &platform_handle, &shared_memory_size, &readonly); |
| 40 if (result != MOJO_RESULT_OK) | 40 if (result != MOJO_RESULT_OK) |
| 41 return nullptr; | 41 return nullptr; |
| 42 DCHECK_EQ(shared_memory_size, bytes); | 42 DCHECK_EQ(shared_memory_size, bytes); |
| 43 | 43 |
| 44 auto shared_memory = | 44 auto shared_memory = |
| 45 base::MakeUnique<base::SharedMemory>(platform_handle, readonly); | 45 base::MakeUnique<base::SharedMemory>(platform_handle, readonly); |
| 46 const int stride = base::checked_cast<int>( | 46 const uint32_t stride = base::checked_cast<uint32_t>( |
| 47 gfx::RowSizeForBufferFormat(size.width(), format, 0)); | 47 gfx::RowSizeForBufferFormat(size.width(), format, 0)); |
| 48 return base::WrapUnique(new MojoGpuMemoryBufferImpl( | 48 return base::WrapUnique(new MojoGpuMemoryBufferImpl( |
| 49 size, format, std::move(shared_memory), 0, stride)); | 49 size, format, std::move(shared_memory), 0, stride)); |
| 50 } | 50 } |
| 51 | 51 |
| 52 // static | 52 // static |
| 53 std::unique_ptr<gfx::GpuMemoryBuffer> MojoGpuMemoryBufferImpl::CreateFromHandle( | 53 std::unique_ptr<gfx::GpuMemoryBuffer> MojoGpuMemoryBufferImpl::CreateFromHandle( |
| 54 const gfx::GpuMemoryBufferHandle& handle, | 54 const gfx::GpuMemoryBufferHandle& handle, |
| 55 const gfx::Size& size, | 55 const gfx::Size& size, |
| 56 gfx::BufferFormat format, | 56 gfx::BufferFormat format, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 return reinterpret_cast<uint8_t*>(shared_memory_->memory()) + offset_ + | 91 return reinterpret_cast<uint8_t*>(shared_memory_->memory()) + offset_ + |
| 92 gfx::BufferOffsetForBufferFormat(size_, format_, plane); | 92 gfx::BufferOffsetForBufferFormat(size_, format_, plane); |
| 93 } | 93 } |
| 94 | 94 |
| 95 void MojoGpuMemoryBufferImpl::Unmap() { | 95 void MojoGpuMemoryBufferImpl::Unmap() { |
| 96 DCHECK(mapped_); | 96 DCHECK(mapped_); |
| 97 shared_memory_->Unmap(); | 97 shared_memory_->Unmap(); |
| 98 mapped_ = false; | 98 mapped_ = false; |
| 99 } | 99 } |
| 100 | 100 |
| 101 int MojoGpuMemoryBufferImpl::stride(size_t plane) const { | 101 uint32_t MojoGpuMemoryBufferImpl::stride(size_t plane) const { |
| 102 DCHECK_LT(plane, gfx::NumberOfPlanesForBufferFormat(format_)); | 102 DCHECK_LT(plane, gfx::NumberOfPlanesForBufferFormat(format_)); |
| 103 return base::checked_cast<int>(gfx::RowSizeForBufferFormat( | 103 return base::checked_cast<uint32_t>(gfx::RowSizeForBufferFormat( |
| 104 size_.width(), format_, static_cast<int>(plane))); | 104 size_.width(), format_, static_cast<int>(plane))); |
| 105 } | 105 } |
| 106 | 106 |
| 107 gfx::GpuMemoryBufferHandle MojoGpuMemoryBufferImpl::GetHandle() const { | 107 gfx::GpuMemoryBufferHandle MojoGpuMemoryBufferImpl::GetHandle() const { |
| 108 gfx::GpuMemoryBufferHandle handle; | 108 gfx::GpuMemoryBufferHandle handle; |
| 109 handle.type = gfx::SHARED_MEMORY_BUFFER; | 109 handle.type = gfx::SHARED_MEMORY_BUFFER; |
| 110 handle.handle = shared_memory_->handle(); | 110 handle.handle = shared_memory_->handle(); |
| 111 handle.offset = offset_; | 111 handle.offset = offset_; |
| 112 handle.stride = stride_; | 112 handle.stride = stride_; |
| 113 | 113 |
| 114 return handle; | 114 return handle; |
| 115 } | 115 } |
| 116 | 116 |
| 117 gfx::GpuMemoryBufferType MojoGpuMemoryBufferImpl::GetBufferType() const { | 117 gfx::GpuMemoryBufferType MojoGpuMemoryBufferImpl::GetBufferType() const { |
| 118 return gfx::SHARED_MEMORY_BUFFER; | 118 return gfx::SHARED_MEMORY_BUFFER; |
| 119 } | 119 } |
| 120 | 120 |
| 121 MojoGpuMemoryBufferImpl::MojoGpuMemoryBufferImpl( | 121 MojoGpuMemoryBufferImpl::MojoGpuMemoryBufferImpl( |
| 122 const gfx::Size& size, | 122 const gfx::Size& size, |
| 123 gfx::BufferFormat format, | 123 gfx::BufferFormat format, |
| 124 std::unique_ptr<base::SharedMemory> shared_memory, | 124 std::unique_ptr<base::SharedMemory> shared_memory, |
| 125 uint32_t offset, | 125 uint32_t offset, |
| 126 int32_t stride) | 126 uint32_t stride) |
| 127 : GpuMemoryBufferImpl(gfx::GenericSharedMemoryId(0), size, format), | 127 : GpuMemoryBufferImpl(gfx::GenericSharedMemoryId(0), size, format), |
| 128 shared_memory_(std::move(shared_memory)), | 128 shared_memory_(std::move(shared_memory)), |
| 129 offset_(offset), | 129 offset_(offset), |
| 130 stride_(stride) {} | 130 stride_(stride) {} |
| 131 | 131 |
| 132 } // namespace ui | 132 } // namespace ui |
| OLD | NEW |