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

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

Issue 1291643002: Revert of Move NumberOfPlanesForGpuMemoryBufferFormat to gfx (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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/gfx/buffer_format_util.h"
11 #include "ui/gl/gl_bindings.h" 10 #include "ui/gl/gl_bindings.h"
12 11
13 #if defined(OS_MACOSX) 12 #if defined(OS_MACOSX)
14 #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"
15 #endif 14 #endif
16 15
17 #if defined(OS_ANDROID) 16 #if defined(OS_ANDROID)
18 #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"
19 #endif 18 #endif
20 19
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 } 71 }
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
81 size_t GpuMemoryBufferImpl::NumberOfPlanesForGpuMemoryBufferFormat(
82 gfx::BufferFormat format) {
83 switch (format) {
84 case gfx::BufferFormat::ATC:
85 case gfx::BufferFormat::ATCIA:
86 case gfx::BufferFormat::DXT1:
87 case gfx::BufferFormat::DXT5:
88 case gfx::BufferFormat::ETC1:
89 case gfx::BufferFormat::R_8:
90 case gfx::BufferFormat::RGBA_4444:
91 case gfx::BufferFormat::RGBA_8888:
92 case gfx::BufferFormat::RGBX_8888:
93 case gfx::BufferFormat::BGRA_8888:
94 return 1;
95 case gfx::BufferFormat::YUV_420:
96 return 3;
97 }
98 NOTREACHED();
99 return 0;
100 }
101
102 // static
82 size_t GpuMemoryBufferImpl::SubsamplingFactor(gfx::BufferFormat format, 103 size_t GpuMemoryBufferImpl::SubsamplingFactor(gfx::BufferFormat format,
83 int plane) { 104 int plane) {
84 switch (format) { 105 switch (format) {
85 case gfx::BufferFormat::ATC: 106 case gfx::BufferFormat::ATC:
86 case gfx::BufferFormat::ATCIA: 107 case gfx::BufferFormat::ATCIA:
87 case gfx::BufferFormat::DXT1: 108 case gfx::BufferFormat::DXT1:
88 case gfx::BufferFormat::DXT5: 109 case gfx::BufferFormat::DXT5:
89 case gfx::BufferFormat::ETC1: 110 case gfx::BufferFormat::ETC1:
90 case gfx::BufferFormat::R_8: 111 case gfx::BufferFormat::R_8:
91 case gfx::BufferFormat::RGBA_4444: 112 case gfx::BufferFormat::RGBA_4444:
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 } 169 }
149 NOTREACHED(); 170 NOTREACHED();
150 return false; 171 return false;
151 } 172 }
152 173
153 // static 174 // static
154 bool GpuMemoryBufferImpl::BufferSizeInBytes(const gfx::Size& size, 175 bool GpuMemoryBufferImpl::BufferSizeInBytes(const gfx::Size& size,
155 gfx::BufferFormat format, 176 gfx::BufferFormat format,
156 size_t* size_in_bytes) { 177 size_t* size_in_bytes) {
157 base::CheckedNumeric<size_t> checked_size = 0; 178 base::CheckedNumeric<size_t> checked_size = 0;
158 size_t num_planes = gfx::NumberOfPlanesForBufferFormat(format); 179 size_t num_planes = NumberOfPlanesForGpuMemoryBufferFormat(format);
159 for (size_t i = 0; i < num_planes; ++i) { 180 for (size_t i = 0; i < num_planes; ++i) {
160 size_t row_size_in_bytes = 0; 181 size_t row_size_in_bytes = 0;
161 if (!RowSizeInBytes(size.width(), format, i, &row_size_in_bytes)) 182 if (!RowSizeInBytes(size.width(), format, i, &row_size_in_bytes))
162 return false; 183 return false;
163 base::CheckedNumeric<size_t> checked_plane_size = row_size_in_bytes; 184 base::CheckedNumeric<size_t> checked_plane_size = row_size_in_bytes;
164 checked_plane_size *= size.height() / SubsamplingFactor(format, i); 185 checked_plane_size *= size.height() / SubsamplingFactor(format, i);
165 if (!checked_plane_size.IsValid()) 186 if (!checked_plane_size.IsValid())
166 return false; 187 return false;
167 checked_size += checked_plane_size.ValueOrDie(); 188 checked_size += checked_plane_size.ValueOrDie();
168 if (!checked_size.IsValid()) 189 if (!checked_size.IsValid())
(...skipping 13 matching lines...) Expand all
182 203
183 gfx::GpuMemoryBufferId GpuMemoryBufferImpl::GetId() const { 204 gfx::GpuMemoryBufferId GpuMemoryBufferImpl::GetId() const {
184 return id_; 205 return id_;
185 } 206 }
186 207
187 ClientBuffer GpuMemoryBufferImpl::AsClientBuffer() { 208 ClientBuffer GpuMemoryBufferImpl::AsClientBuffer() {
188 return reinterpret_cast<ClientBuffer>(this); 209 return reinterpret_cast<ClientBuffer>(this);
189 } 210 }
190 211
191 } // 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_shared_memory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698