| 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/ptr_util.h" |
| 10 #include "base/memory/shared_memory.h" | 11 #include "base/memory/shared_memory.h" |
| 11 #include "base/numerics/safe_conversions.h" | 12 #include "base/numerics/safe_conversions.h" |
| 12 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 13 #include "ui/gfx/buffer_format_util.h" | 14 #include "ui/gfx/buffer_format_util.h" |
| 14 | 15 |
| 15 namespace mus { | 16 namespace mus { |
| 16 | 17 |
| 17 MojoGpuMemoryBufferImpl::MojoGpuMemoryBufferImpl( | 18 MojoGpuMemoryBufferImpl::MojoGpuMemoryBufferImpl( |
| 18 const gfx::Size& size, | 19 const gfx::Size& size, |
| 19 gfx::BufferFormat format, | 20 gfx::BufferFormat format, |
| 20 scoped_ptr<base::SharedMemory> shared_memory) | 21 std::unique_ptr<base::SharedMemory> shared_memory) |
| 21 : GpuMemoryBufferImpl(gfx::GenericSharedMemoryId(0), size, format), | 22 : GpuMemoryBufferImpl(gfx::GenericSharedMemoryId(0), size, format), |
| 22 shared_memory_(std::move(shared_memory)) {} | 23 shared_memory_(std::move(shared_memory)) {} |
| 23 | 24 |
| 24 // TODO(rjkroege): Support running a destructor callback as necessary. | 25 // TODO(rjkroege): Support running a destructor callback as necessary. |
| 25 MojoGpuMemoryBufferImpl::~MojoGpuMemoryBufferImpl() {} | 26 MojoGpuMemoryBufferImpl::~MojoGpuMemoryBufferImpl() {} |
| 26 | 27 |
| 27 scoped_ptr<gfx::GpuMemoryBuffer> MojoGpuMemoryBufferImpl::Create( | 28 std::unique_ptr<gfx::GpuMemoryBuffer> MojoGpuMemoryBufferImpl::Create( |
| 28 const gfx::Size& size, | 29 const gfx::Size& size, |
| 29 gfx::BufferFormat format, | 30 gfx::BufferFormat format, |
| 30 gfx::BufferUsage usage) { | 31 gfx::BufferUsage usage) { |
| 31 size_t bytes = gfx::BufferSizeForBufferFormat(size, format); | 32 size_t bytes = gfx::BufferSizeForBufferFormat(size, format); |
| 32 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory); | 33 std::unique_ptr<base::SharedMemory> shared_memory(new base::SharedMemory); |
| 33 | 34 |
| 34 if (!shared_memory->CreateAnonymous(bytes)) | 35 if (!shared_memory->CreateAnonymous(bytes)) |
| 35 return nullptr; | 36 return nullptr; |
| 36 | 37 |
| 37 return make_scoped_ptr<gfx::GpuMemoryBuffer>( | 38 return base::WrapUnique<gfx::GpuMemoryBuffer>( |
| 38 new MojoGpuMemoryBufferImpl(size, format, std::move(shared_memory))); | 39 new MojoGpuMemoryBufferImpl(size, format, std::move(shared_memory))); |
| 39 } | 40 } |
| 40 | 41 |
| 41 MojoGpuMemoryBufferImpl* MojoGpuMemoryBufferImpl::FromClientBuffer( | 42 MojoGpuMemoryBufferImpl* MojoGpuMemoryBufferImpl::FromClientBuffer( |
| 42 ClientBuffer buffer) { | 43 ClientBuffer buffer) { |
| 43 return reinterpret_cast<MojoGpuMemoryBufferImpl*>(buffer); | 44 return reinterpret_cast<MojoGpuMemoryBufferImpl*>(buffer); |
| 44 } | 45 } |
| 45 | 46 |
| 46 const unsigned char* MojoGpuMemoryBufferImpl::GetMemory() const { | 47 const unsigned char* MojoGpuMemoryBufferImpl::GetMemory() const { |
| 47 return static_cast<const unsigned char*>(shared_memory_->memory()); | 48 return static_cast<const unsigned char*>(shared_memory_->memory()); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 gfx::RowSizeForBufferFormat(size_.width(), format_, 0)); | 84 gfx::RowSizeForBufferFormat(size_.width(), format_, 0)); |
| 84 | 85 |
| 85 return handle; | 86 return handle; |
| 86 } | 87 } |
| 87 | 88 |
| 88 gfx::GpuMemoryBufferType MojoGpuMemoryBufferImpl::GetBufferType() const { | 89 gfx::GpuMemoryBufferType MojoGpuMemoryBufferImpl::GetBufferType() const { |
| 89 return gfx::SHARED_MEMORY_BUFFER; | 90 return gfx::SHARED_MEMORY_BUFFER; |
| 90 } | 91 } |
| 91 | 92 |
| 92 } // namespace mus | 93 } // namespace mus |
| OLD | NEW |