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

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

Issue 1412223009: Reland: GpuMemoryBuffer interface change: Map(**) to Map() and memory(plane); stride(plane) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Win X64 compile fix Created 5 years, 2 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 "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/shared_memory.h" 8 #include "base/memory/shared_memory.h"
9 #include "base/numerics/safe_conversions.h" 9 #include "base/numerics/safe_conversions.h"
10 #include "ui/gfx/buffer_format_util.h" 10 #include "ui/gfx/buffer_format_util.h"
(...skipping 25 matching lines...) Expand all
36 36
37 MojoGpuMemoryBufferImpl* MojoGpuMemoryBufferImpl::FromClientBuffer( 37 MojoGpuMemoryBufferImpl* MojoGpuMemoryBufferImpl::FromClientBuffer(
38 ClientBuffer buffer) { 38 ClientBuffer buffer) {
39 return reinterpret_cast<MojoGpuMemoryBufferImpl*>(buffer); 39 return reinterpret_cast<MojoGpuMemoryBufferImpl*>(buffer);
40 } 40 }
41 41
42 const unsigned char* MojoGpuMemoryBufferImpl::GetMemory() const { 42 const unsigned char* MojoGpuMemoryBufferImpl::GetMemory() const {
43 return static_cast<const unsigned char*>(shared_memory_->memory()); 43 return static_cast<const unsigned char*>(shared_memory_->memory());
44 } 44 }
45 45
46 bool MojoGpuMemoryBufferImpl::Map(void** data) { 46 bool MojoGpuMemoryBufferImpl::Map() {
47 DCHECK(!mapped_); 47 DCHECK(!mapped_);
48 if (!shared_memory_->Map(gfx::BufferSizeForBufferFormat(size_, format_))) 48 if (!shared_memory_->Map(gfx::BufferSizeForBufferFormat(size_, format_)))
49 return false; 49 return false;
50 mapped_ = true; 50 mapped_ = true;
51 size_t offset = 0;
52 int num_planes =
53 static_cast<int>(gfx::NumberOfPlanesForBufferFormat(format_));
54 for (int i = 0; i < num_planes; ++i) {
55 data[i] = reinterpret_cast<uint8*>(shared_memory_->memory()) + offset;
56 offset +=
57 gfx::RowSizeForBufferFormat(size_.width(), format_, i) *
58 (size_.height() / gfx::SubsamplingFactorForBufferFormat(format_, i));
59 }
60 return true; 51 return true;
61 } 52 }
62 53
54 void* MojoGpuMemoryBufferImpl::memory(size_t plane) {
55 DCHECK(mapped_);
56 DCHECK_LT(plane, gfx::NumberOfPlanesForBufferFormat(format_));
57 return reinterpret_cast<uint8*>(shared_memory_->memory()) +
58 gfx::BufferOffsetForBufferFormat(size_, format_, plane);
59 }
60
63 void MojoGpuMemoryBufferImpl::Unmap() { 61 void MojoGpuMemoryBufferImpl::Unmap() {
64 DCHECK(mapped_); 62 DCHECK(mapped_);
65 shared_memory_->Unmap(); 63 shared_memory_->Unmap();
66 mapped_ = false; 64 mapped_ = false;
67 } 65 }
68 66
69 gfx::Size MojoGpuMemoryBufferImpl::GetSize() const { 67 gfx::Size MojoGpuMemoryBufferImpl::GetSize() const {
70 return size_; 68 return size_;
71 } 69 }
72 70
73 gfx::BufferFormat MojoGpuMemoryBufferImpl::GetFormat() const { 71 gfx::BufferFormat MojoGpuMemoryBufferImpl::GetFormat() const {
74 return format_; 72 return format_;
75 } 73 }
76 74
77 void MojoGpuMemoryBufferImpl::GetStride(int* stride) const { 75 int MojoGpuMemoryBufferImpl::stride(size_t plane) const {
78 int num_planes = 76 DCHECK_LT(plane, gfx::NumberOfPlanesForBufferFormat(format_));
79 static_cast<int>(gfx::NumberOfPlanesForBufferFormat(format_)); 77 return base::checked_cast<int>(gfx::RowSizeForBufferFormat(
80 for (int i = 0; i < num_planes; ++i) 78 size_.width(), format_, static_cast<int>(plane)));
81 stride[i] = base::checked_cast<int>(
82 gfx::RowSizeForBufferFormat(size_.width(), format_, i));
83 } 79 }
84 80
85 gfx::GpuMemoryBufferId MojoGpuMemoryBufferImpl::GetId() const { 81 gfx::GpuMemoryBufferId MojoGpuMemoryBufferImpl::GetId() const {
86 return gfx::GpuMemoryBufferId(0); 82 return gfx::GpuMemoryBufferId(0);
87 } 83 }
88 84
89 gfx::GpuMemoryBufferHandle MojoGpuMemoryBufferImpl::GetHandle() const { 85 gfx::GpuMemoryBufferHandle MojoGpuMemoryBufferImpl::GetHandle() const {
90 gfx::GpuMemoryBufferHandle handle; 86 gfx::GpuMemoryBufferHandle handle;
91 handle.type = gfx::SHARED_MEMORY_BUFFER; 87 handle.type = gfx::SHARED_MEMORY_BUFFER;
92 handle.handle = shared_memory_->handle(); 88 handle.handle = shared_memory_->handle();
93 return handle; 89 return handle;
94 } 90 }
95 91
96 ClientBuffer MojoGpuMemoryBufferImpl::AsClientBuffer() { 92 ClientBuffer MojoGpuMemoryBufferImpl::AsClientBuffer() {
97 return reinterpret_cast<ClientBuffer>(this); 93 return reinterpret_cast<ClientBuffer>(this);
98 } 94 }
99 95
100 } // namespace mus 96 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/gles2/mojo_gpu_memory_buffer.h ('k') | content/browser/compositor/buffer_queue_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698