Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: components/mus/gles2/mojo_gpu_memory_buffer.cc

Issue 1857243005: Scan-out capable buffers (aka ui::NativePixmap) for Mus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: build fix for windows Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 (!shared_memory->CreateAnonymous(bytes)) 34 if (!shared_memory->CreateAnonymous(bytes))
(...skipping 26 matching lines...) Expand all
62 return reinterpret_cast<uint8_t*>(shared_memory_->memory()) + 61 return reinterpret_cast<uint8_t*>(shared_memory_->memory()) +
63 gfx::BufferOffsetForBufferFormat(size_, format_, plane); 62 gfx::BufferOffsetForBufferFormat(size_, format_, plane);
64 } 63 }
65 64
66 void MojoGpuMemoryBufferImpl::Unmap() { 65 void MojoGpuMemoryBufferImpl::Unmap() {
67 DCHECK(mapped_); 66 DCHECK(mapped_);
68 shared_memory_->Unmap(); 67 shared_memory_->Unmap();
69 mapped_ = false; 68 mapped_ = false;
70 } 69 }
71 70
72 gfx::Size MojoGpuMemoryBufferImpl::GetSize() const {
73 return size_;
74 }
75
76 gfx::BufferFormat MojoGpuMemoryBufferImpl::GetFormat() const {
77 return format_;
78 }
79
80 int MojoGpuMemoryBufferImpl::stride(size_t plane) const { 71 int MojoGpuMemoryBufferImpl::stride(size_t plane) const {
81 DCHECK_LT(plane, gfx::NumberOfPlanesForBufferFormat(format_)); 72 DCHECK_LT(plane, gfx::NumberOfPlanesForBufferFormat(format_));
82 return base::checked_cast<int>(gfx::RowSizeForBufferFormat( 73 return base::checked_cast<int>(gfx::RowSizeForBufferFormat(
83 size_.width(), format_, static_cast<int>(plane))); 74 size_.width(), format_, static_cast<int>(plane)));
84 } 75 }
85 76
86 gfx::GpuMemoryBufferId MojoGpuMemoryBufferImpl::GetId() const {
87 return gfx::GpuMemoryBufferId(0);
88 }
89
90 gfx::GpuMemoryBufferHandle MojoGpuMemoryBufferImpl::GetHandle() const { 77 gfx::GpuMemoryBufferHandle MojoGpuMemoryBufferImpl::GetHandle() const {
91 gfx::GpuMemoryBufferHandle handle; 78 gfx::GpuMemoryBufferHandle handle;
92 handle.type = gfx::SHARED_MEMORY_BUFFER; 79 handle.type = gfx::SHARED_MEMORY_BUFFER;
93 handle.handle = shared_memory_->handle(); 80 handle.handle = shared_memory_->handle();
94 handle.offset = 0; 81 handle.offset = 0;
95 handle.stride = static_cast<int32_t>( 82 handle.stride = static_cast<int32_t>(
96 gfx::RowSizeForBufferFormat(size_.width(), format_, 0)); 83 gfx::RowSizeForBufferFormat(size_.width(), format_, 0));
84
97 return handle; 85 return handle;
98 } 86 }
99 87
100 ClientBuffer MojoGpuMemoryBufferImpl::AsClientBuffer() { 88 gfx::GpuMemoryBufferType MojoGpuMemoryBufferImpl::GetBufferType() const {
101 return reinterpret_cast<ClientBuffer>(this); 89 return gfx::SHARED_MEMORY_BUFFER;
102 } 90 }
103 91
104 } // namespace mus 92 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/gles2/mojo_gpu_memory_buffer.h ('k') | components/mus/gles2/ozone_gpu_memory_buffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698