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

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

Issue 1281043006: Move NumberOfPlanesForGpuMemoryBufferFormat to gfx (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase 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"
10 #include "ui/gl/gl_bindings.h" 11 #include "ui/gl/gl_bindings.h"
11 12
12 #if defined(OS_MACOSX) 13 #if defined(OS_MACOSX)
13 #include "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h" 14 #include "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h"
14 #endif 15 #endif
15 16
16 #if defined(OS_ANDROID) 17 #if defined(OS_ANDROID)
17 #include "content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.h" 18 #include "content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.h"
18 #endif 19 #endif
19 20
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 } 72 }
72 } 73 }
73 74
74 // static 75 // static
75 GpuMemoryBufferImpl* GpuMemoryBufferImpl::FromClientBuffer( 76 GpuMemoryBufferImpl* GpuMemoryBufferImpl::FromClientBuffer(
76 ClientBuffer buffer) { 77 ClientBuffer buffer) {
77 return reinterpret_cast<GpuMemoryBufferImpl*>(buffer); 78 return reinterpret_cast<GpuMemoryBufferImpl*>(buffer);
78 } 79 }
79 80
80 // static 81 // 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
103 size_t GpuMemoryBufferImpl::SubsamplingFactor(gfx::BufferFormat format, 82 size_t GpuMemoryBufferImpl::SubsamplingFactor(gfx::BufferFormat format,
104 int plane) { 83 int plane) {
105 switch (format) { 84 switch (format) {
106 case gfx::BufferFormat::ATC: 85 case gfx::BufferFormat::ATC:
107 case gfx::BufferFormat::ATCIA: 86 case gfx::BufferFormat::ATCIA:
108 case gfx::BufferFormat::DXT1: 87 case gfx::BufferFormat::DXT1:
109 case gfx::BufferFormat::DXT5: 88 case gfx::BufferFormat::DXT5:
110 case gfx::BufferFormat::ETC1: 89 case gfx::BufferFormat::ETC1:
111 case gfx::BufferFormat::R_8: 90 case gfx::BufferFormat::R_8:
112 case gfx::BufferFormat::RGBA_4444: 91 case gfx::BufferFormat::RGBA_4444:
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 } 148 }
170 NOTREACHED(); 149 NOTREACHED();
171 return false; 150 return false;
172 } 151 }
173 152
174 // static 153 // static
175 bool GpuMemoryBufferImpl::BufferSizeInBytes(const gfx::Size& size, 154 bool GpuMemoryBufferImpl::BufferSizeInBytes(const gfx::Size& size,
176 gfx::BufferFormat format, 155 gfx::BufferFormat format,
177 size_t* size_in_bytes) { 156 size_t* size_in_bytes) {
178 base::CheckedNumeric<size_t> checked_size = 0; 157 base::CheckedNumeric<size_t> checked_size = 0;
179 size_t num_planes = NumberOfPlanesForGpuMemoryBufferFormat(format); 158 size_t num_planes = gfx::NumberOfPlanesForBufferFormat(format);
180 for (size_t i = 0; i < num_planes; ++i) { 159 for (size_t i = 0; i < num_planes; ++i) {
181 size_t row_size_in_bytes = 0; 160 size_t row_size_in_bytes = 0;
182 if (!RowSizeInBytes(size.width(), format, i, &row_size_in_bytes)) 161 if (!RowSizeInBytes(size.width(), format, i, &row_size_in_bytes))
183 return false; 162 return false;
184 base::CheckedNumeric<size_t> checked_plane_size = row_size_in_bytes; 163 base::CheckedNumeric<size_t> checked_plane_size = row_size_in_bytes;
185 checked_plane_size *= size.height() / SubsamplingFactor(format, i); 164 checked_plane_size *= size.height() / SubsamplingFactor(format, i);
186 if (!checked_plane_size.IsValid()) 165 if (!checked_plane_size.IsValid())
187 return false; 166 return false;
188 checked_size += checked_plane_size.ValueOrDie(); 167 checked_size += checked_plane_size.ValueOrDie();
189 if (!checked_size.IsValid()) 168 if (!checked_size.IsValid())
(...skipping 13 matching lines...) Expand all
203 182
204 gfx::GpuMemoryBufferId GpuMemoryBufferImpl::GetId() const { 183 gfx::GpuMemoryBufferId GpuMemoryBufferImpl::GetId() const {
205 return id_; 184 return id_;
206 } 185 }
207 186
208 ClientBuffer GpuMemoryBufferImpl::AsClientBuffer() { 187 ClientBuffer GpuMemoryBufferImpl::AsClientBuffer() {
209 return reinterpret_cast<ClientBuffer>(this); 188 return reinterpret_cast<ClientBuffer>(this);
210 } 189 }
211 190
212 } // namespace content 191 } // 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