| 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> |
| 8 |
| 7 #include "base/logging.h" | 9 #include "base/logging.h" |
| 8 #include "base/memory/shared_memory.h" | 10 #include "base/memory/shared_memory.h" |
| 9 #include "base/numerics/safe_conversions.h" | 11 #include "base/numerics/safe_conversions.h" |
| 12 #include "build/build_config.h" |
| 10 #include "ui/gfx/buffer_format_util.h" | 13 #include "ui/gfx/buffer_format_util.h" |
| 11 | 14 |
| 12 namespace mus { | 15 namespace mus { |
| 13 | 16 |
| 14 MojoGpuMemoryBufferImpl::MojoGpuMemoryBufferImpl( | 17 MojoGpuMemoryBufferImpl::MojoGpuMemoryBufferImpl( |
| 15 const gfx::Size& size, | 18 const gfx::Size& size, |
| 16 gfx::BufferFormat format, | 19 gfx::BufferFormat format, |
| 17 scoped_ptr<base::SharedMemory> shared_memory) | 20 scoped_ptr<base::SharedMemory> shared_memory) |
| 18 : size_(size), | 21 : size_(size), |
| 19 format_(format), | 22 format_(format), |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 DCHECK(!mapped_); | 59 DCHECK(!mapped_); |
| 57 if (!shared_memory_->Map(gfx::BufferSizeForBufferFormat(size_, format_))) | 60 if (!shared_memory_->Map(gfx::BufferSizeForBufferFormat(size_, format_))) |
| 58 return false; | 61 return false; |
| 59 mapped_ = true; | 62 mapped_ = true; |
| 60 return true; | 63 return true; |
| 61 } | 64 } |
| 62 | 65 |
| 63 void* MojoGpuMemoryBufferImpl::memory(size_t plane) { | 66 void* MojoGpuMemoryBufferImpl::memory(size_t plane) { |
| 64 DCHECK(mapped_); | 67 DCHECK(mapped_); |
| 65 DCHECK_LT(plane, gfx::NumberOfPlanesForBufferFormat(format_)); | 68 DCHECK_LT(plane, gfx::NumberOfPlanesForBufferFormat(format_)); |
| 66 return reinterpret_cast<uint8*>(shared_memory_->memory()) + | 69 return reinterpret_cast<uint8_t*>(shared_memory_->memory()) + |
| 67 gfx::BufferOffsetForBufferFormat(size_, format_, plane); | 70 gfx::BufferOffsetForBufferFormat(size_, format_, plane); |
| 68 } | 71 } |
| 69 | 72 |
| 70 void MojoGpuMemoryBufferImpl::Unmap() { | 73 void MojoGpuMemoryBufferImpl::Unmap() { |
| 71 DCHECK(mapped_); | 74 DCHECK(mapped_); |
| 72 shared_memory_->Unmap(); | 75 shared_memory_->Unmap(); |
| 73 mapped_ = false; | 76 mapped_ = false; |
| 74 } | 77 } |
| 75 | 78 |
| 76 gfx::Size MojoGpuMemoryBufferImpl::GetSize() const { | 79 gfx::Size MojoGpuMemoryBufferImpl::GetSize() const { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 99 handle.stride = static_cast<int32_t>( | 102 handle.stride = static_cast<int32_t>( |
| 100 gfx::RowSizeForBufferFormat(size_.width(), format_, 0)); | 103 gfx::RowSizeForBufferFormat(size_.width(), format_, 0)); |
| 101 return handle; | 104 return handle; |
| 102 } | 105 } |
| 103 | 106 |
| 104 ClientBuffer MojoGpuMemoryBufferImpl::AsClientBuffer() { | 107 ClientBuffer MojoGpuMemoryBufferImpl::AsClientBuffer() { |
| 105 return reinterpret_cast<ClientBuffer>(this); | 108 return reinterpret_cast<ClientBuffer>(this); |
| 106 } | 109 } |
| 107 | 110 |
| 108 } // namespace mus | 111 } // namespace mus |
| OLD | NEW |