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

Side by Side Diff: content/common/gpu/client/gpu_memory_buffer_impl.cc

Issue 1269503007: Unify graphics buffer format & usage enums for GpuMemoryBuffer & SurfaceFactoryOzone (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add header to BUILD.gn Created 5 years, 4 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "content/common/gpu/client/gpu_memory_buffer_impl.h" 5 #include "content/common/gpu/client/gpu_memory_buffer_impl.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/numerics/safe_math.h" 8 #include "base/numerics/safe_math.h"
9 #include "content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h" 9 #include "content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h"
10 #include "ui/gl/gl_bindings.h" 10 #include "ui/gl/gl_bindings.h"
11 11
12 #if defined(OS_MACOSX) 12 #if defined(OS_MACOSX)
13 #include "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h" 13 #include "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h"
14 #endif 14 #endif
15 15
16 #if defined(OS_ANDROID) 16 #if defined(OS_ANDROID)
17 #include "content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.h" 17 #include "content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.h"
18 #endif 18 #endif
19 19
20 #if defined(USE_OZONE) 20 #if defined(USE_OZONE)
21 #include "content/common/gpu/client/gpu_memory_buffer_impl_ozone_native_pixmap.h " 21 #include "content/common/gpu/client/gpu_memory_buffer_impl_ozone_native_pixmap.h "
22 #endif 22 #endif
23 23
24 namespace content { 24 namespace content {
25 25
26 GpuMemoryBufferImpl::GpuMemoryBufferImpl(gfx::GpuMemoryBufferId id, 26 GpuMemoryBufferImpl::GpuMemoryBufferImpl(gfx::GpuMemoryBufferId id,
27 const gfx::Size& size, 27 const gfx::Size& size,
28 Format format, 28 gfx::BufferFormat format,
29 const DestructionCallback& callback) 29 const DestructionCallback& callback)
30 : id_(id), 30 : id_(id),
31 size_(size), 31 size_(size),
32 format_(format), 32 format_(format),
33 callback_(callback), 33 callback_(callback),
34 mapped_(false), 34 mapped_(false),
35 destruction_sync_point_(0) { 35 destruction_sync_point_(0) {}
36 }
37 36
38 GpuMemoryBufferImpl::~GpuMemoryBufferImpl() { 37 GpuMemoryBufferImpl::~GpuMemoryBufferImpl() {
39 DCHECK(!mapped_); 38 DCHECK(!mapped_);
40 callback_.Run(destruction_sync_point_); 39 callback_.Run(destruction_sync_point_);
41 } 40 }
42 41
43 // static 42 // static
44 scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImpl::CreateFromHandle( 43 scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImpl::CreateFromHandle(
45 const gfx::GpuMemoryBufferHandle& handle, 44 const gfx::GpuMemoryBufferHandle& handle,
46 const gfx::Size& size, 45 const gfx::Size& size,
47 Format format, 46 gfx::BufferFormat format,
48 Usage usage, 47 gfx::BufferUsage usage,
49 const DestructionCallback& callback) { 48 const DestructionCallback& callback) {
50 switch (handle.type) { 49 switch (handle.type) {
51 case gfx::SHARED_MEMORY_BUFFER: 50 case gfx::SHARED_MEMORY_BUFFER:
52 return GpuMemoryBufferImplSharedMemory::CreateFromHandle( 51 return GpuMemoryBufferImplSharedMemory::CreateFromHandle(
53 handle, size, format, callback); 52 handle, size, format, callback);
54 #if defined(OS_MACOSX) 53 #if defined(OS_MACOSX)
55 case gfx::IO_SURFACE_BUFFER: 54 case gfx::IO_SURFACE_BUFFER:
56 return GpuMemoryBufferImplIOSurface::CreateFromHandle( 55 return GpuMemoryBufferImplIOSurface::CreateFromHandle(
57 handle, size, format, usage, callback); 56 handle, size, format, usage, callback);
58 #endif 57 #endif
(...skipping 14 matching lines...) Expand all
73 } 72 }
74 73
75 // static 74 // static
76 GpuMemoryBufferImpl* GpuMemoryBufferImpl::FromClientBuffer( 75 GpuMemoryBufferImpl* GpuMemoryBufferImpl::FromClientBuffer(
77 ClientBuffer buffer) { 76 ClientBuffer buffer) {
78 return reinterpret_cast<GpuMemoryBufferImpl*>(buffer); 77 return reinterpret_cast<GpuMemoryBufferImpl*>(buffer);
79 } 78 }
80 79
81 // static 80 // static
82 size_t GpuMemoryBufferImpl::NumberOfPlanesForGpuMemoryBufferFormat( 81 size_t GpuMemoryBufferImpl::NumberOfPlanesForGpuMemoryBufferFormat(
83 Format format) { 82 gfx::BufferFormat format) {
84 switch (format) { 83 switch (format) {
85 case ATC: 84 case gfx::BufferFormat::ATC:
86 case ATCIA: 85 case gfx::BufferFormat::ATCIA:
87 case DXT1: 86 case gfx::BufferFormat::DXT1:
88 case DXT5: 87 case gfx::BufferFormat::DXT5:
89 case ETC1: 88 case gfx::BufferFormat::ETC1:
90 case R_8: 89 case gfx::BufferFormat::R_8:
91 case RGBA_4444: 90 case gfx::BufferFormat::RGBA_4444:
92 case RGBA_8888: 91 case gfx::BufferFormat::RGBA_8888:
93 case RGBX_8888: 92 case gfx::BufferFormat::RGBX_8888:
94 case BGRA_8888: 93 case gfx::BufferFormat::BGRA_8888:
95 return 1; 94 return 1;
96 case YUV_420: 95 case gfx::BufferFormat::YUV_420:
97 return 3; 96 return 3;
98 } 97 }
99 NOTREACHED(); 98 NOTREACHED();
100 return 0; 99 return 0;
101 } 100 }
102 101
103 // static 102 // static
104 size_t GpuMemoryBufferImpl::SubsamplingFactor(Format format, int plane) { 103 size_t GpuMemoryBufferImpl::SubsamplingFactor(gfx::BufferFormat format,
104 int plane) {
105 switch (format) { 105 switch (format) {
106 case ATC: 106 case gfx::BufferFormat::ATC:
107 case ATCIA: 107 case gfx::BufferFormat::ATCIA:
108 case DXT1: 108 case gfx::BufferFormat::DXT1:
109 case DXT5: 109 case gfx::BufferFormat::DXT5:
110 case ETC1: 110 case gfx::BufferFormat::ETC1:
111 case R_8: 111 case gfx::BufferFormat::R_8:
112 case RGBA_4444: 112 case gfx::BufferFormat::RGBA_4444:
113 case RGBA_8888: 113 case gfx::BufferFormat::RGBA_8888:
114 case RGBX_8888: 114 case gfx::BufferFormat::RGBX_8888:
115 case BGRA_8888: 115 case gfx::BufferFormat::BGRA_8888:
116 return 1; 116 return 1;
117 case YUV_420: { 117 case gfx::BufferFormat::YUV_420: {
118 static size_t factor[] = {1, 2, 2}; 118 static size_t factor[] = {1, 2, 2};
119 DCHECK_LT(static_cast<size_t>(plane), arraysize(factor)); 119 DCHECK_LT(static_cast<size_t>(plane), arraysize(factor));
120 return factor[plane]; 120 return factor[plane];
121 } 121 }
122 } 122 }
123 NOTREACHED(); 123 NOTREACHED();
124 return 0; 124 return 0;
125 } 125 }
126 126
127 // static 127 // static
128 bool GpuMemoryBufferImpl::RowSizeInBytes(size_t width, 128 bool GpuMemoryBufferImpl::RowSizeInBytes(size_t width,
129 Format format, 129 gfx::BufferFormat format,
130 int plane, 130 int plane,
131 size_t* size_in_bytes) { 131 size_t* size_in_bytes) {
132 base::CheckedNumeric<size_t> checked_size = width; 132 base::CheckedNumeric<size_t> checked_size = width;
133 switch (format) { 133 switch (format) {
134 case ATCIA: 134 case gfx::BufferFormat::ATCIA:
135 case DXT5: 135 case gfx::BufferFormat::DXT5:
136 DCHECK_EQ(plane, 0); 136 DCHECK_EQ(plane, 0);
137 *size_in_bytes = width; 137 *size_in_bytes = width;
138 return true; 138 return true;
139 case ATC: 139 case gfx::BufferFormat::ATC:
140 case DXT1: 140 case gfx::BufferFormat::DXT1:
141 case ETC1: 141 case gfx::BufferFormat::ETC1:
142 DCHECK_EQ(plane, 0); 142 DCHECK_EQ(plane, 0);
143 DCHECK_EQ(width % 2, 0u); 143 DCHECK_EQ(width % 2, 0u);
144 *size_in_bytes = width / 2; 144 *size_in_bytes = width / 2;
145 return true; 145 return true;
146 case R_8: 146 case gfx::BufferFormat::R_8:
147 checked_size += 3; 147 checked_size += 3;
148 if (!checked_size.IsValid()) 148 if (!checked_size.IsValid())
149 return false; 149 return false;
150 *size_in_bytes = checked_size.ValueOrDie() & ~0x3; 150 *size_in_bytes = checked_size.ValueOrDie() & ~0x3;
151 return true; 151 return true;
152 case RGBA_4444: 152 case gfx::BufferFormat::RGBA_4444:
153 checked_size *= 2; 153 checked_size *= 2;
154 if (!checked_size.IsValid()) 154 if (!checked_size.IsValid())
155 return false; 155 return false;
156 *size_in_bytes = checked_size.ValueOrDie(); 156 *size_in_bytes = checked_size.ValueOrDie();
157 case RGBX_8888: 157 case gfx::BufferFormat::RGBX_8888:
158 case RGBA_8888: 158 case gfx::BufferFormat::RGBA_8888:
159 case BGRA_8888: 159 case gfx::BufferFormat::BGRA_8888:
160 checked_size *= 4; 160 checked_size *= 4;
161 if (!checked_size.IsValid()) 161 if (!checked_size.IsValid())
162 return false; 162 return false;
163 *size_in_bytes = checked_size.ValueOrDie(); 163 *size_in_bytes = checked_size.ValueOrDie();
164 return true; 164 return true;
165 case YUV_420: 165 case gfx::BufferFormat::YUV_420:
166 DCHECK_EQ(width % 2, 0u); 166 DCHECK_EQ(width % 2, 0u);
167 *size_in_bytes = width / SubsamplingFactor(format, plane); 167 *size_in_bytes = width / SubsamplingFactor(format, plane);
168 return true; 168 return true;
169 } 169 }
170 NOTREACHED(); 170 NOTREACHED();
171 return false; 171 return false;
172 } 172 }
173 173
174 // static 174 // static
175 bool GpuMemoryBufferImpl::BufferSizeInBytes(const gfx::Size& size, 175 bool GpuMemoryBufferImpl::BufferSizeInBytes(const gfx::Size& size,
176 Format format, 176 gfx::BufferFormat format,
177 size_t* size_in_bytes) { 177 size_t* size_in_bytes) {
178 base::CheckedNumeric<size_t> checked_size = 0; 178 base::CheckedNumeric<size_t> checked_size = 0;
179 size_t num_planes = NumberOfPlanesForGpuMemoryBufferFormat(format); 179 size_t num_planes = NumberOfPlanesForGpuMemoryBufferFormat(format);
180 for (size_t i = 0; i < num_planes; ++i) { 180 for (size_t i = 0; i < num_planes; ++i) {
181 size_t row_size_in_bytes = 0; 181 size_t row_size_in_bytes = 0;
182 if (!RowSizeInBytes(size.width(), format, i, &row_size_in_bytes)) 182 if (!RowSizeInBytes(size.width(), format, i, &row_size_in_bytes))
183 return false; 183 return false;
184 base::CheckedNumeric<size_t> checked_plane_size = row_size_in_bytes; 184 base::CheckedNumeric<size_t> checked_plane_size = row_size_in_bytes;
185 checked_plane_size *= size.height() / SubsamplingFactor(format, i); 185 checked_plane_size *= size.height() / SubsamplingFactor(format, i);
186 if (!checked_plane_size.IsValid()) 186 if (!checked_plane_size.IsValid())
187 return false; 187 return false;
188 checked_size += checked_plane_size.ValueOrDie(); 188 checked_size += checked_plane_size.ValueOrDie();
189 if (!checked_size.IsValid()) 189 if (!checked_size.IsValid())
190 return false; 190 return false;
191 } 191 }
192 *size_in_bytes = checked_size.ValueOrDie(); 192 *size_in_bytes = checked_size.ValueOrDie();
193 return true; 193 return true;
194 } 194 }
195 195
196 gfx::GpuMemoryBuffer::Format GpuMemoryBufferImpl::GetFormat() const { 196 gfx::BufferFormat GpuMemoryBufferImpl::GetFormat() const {
197 return format_; 197 return format_;
198 } 198 }
199 199
200 bool GpuMemoryBufferImpl::IsMapped() const { 200 bool GpuMemoryBufferImpl::IsMapped() const {
201 return mapped_; 201 return mapped_;
202 } 202 }
203 203
204 gfx::GpuMemoryBufferId GpuMemoryBufferImpl::GetId() const { 204 gfx::GpuMemoryBufferId GpuMemoryBufferImpl::GetId() const {
205 return id_; 205 return id_;
206 } 206 }
207 207
208 ClientBuffer GpuMemoryBufferImpl::AsClientBuffer() { 208 ClientBuffer GpuMemoryBufferImpl::AsClientBuffer() {
209 return reinterpret_cast<ClientBuffer>(this); 209 return reinterpret_cast<ClientBuffer>(this);
210 } 210 }
211 211
212 } // namespace content 212 } // namespace content
OLDNEW
« no previous file with comments | « content/common/gpu/client/gpu_memory_buffer_impl.h ('k') | content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698