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

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: Fix build warning again 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"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 } 71 }
72 } 72 }
73 73
74 // static 74 // static
75 GpuMemoryBufferImpl* GpuMemoryBufferImpl::FromClientBuffer( 75 GpuMemoryBufferImpl* GpuMemoryBufferImpl::FromClientBuffer(
76 ClientBuffer buffer) { 76 ClientBuffer buffer) {
77 return reinterpret_cast<GpuMemoryBufferImpl*>(buffer); 77 return reinterpret_cast<GpuMemoryBufferImpl*>(buffer);
78 } 78 }
79 79
80 // 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
103 size_t GpuMemoryBufferImpl::SubsamplingFactor(gfx::BufferFormat format, 81 size_t GpuMemoryBufferImpl::SubsamplingFactor(gfx::BufferFormat format,
104 int plane) { 82 int plane) {
105 switch (format) { 83 switch (format) {
106 case gfx::BufferFormat::ATC: 84 case gfx::BufferFormat::ATC:
107 case gfx::BufferFormat::ATCIA: 85 case gfx::BufferFormat::ATCIA:
108 case gfx::BufferFormat::DXT1: 86 case gfx::BufferFormat::DXT1:
109 case gfx::BufferFormat::DXT5: 87 case gfx::BufferFormat::DXT5:
110 case gfx::BufferFormat::ETC1: 88 case gfx::BufferFormat::ETC1:
111 case gfx::BufferFormat::R_8: 89 case gfx::BufferFormat::R_8:
112 case gfx::BufferFormat::RGBA_4444: 90 case gfx::BufferFormat::RGBA_4444:
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 } 147 }
170 NOTREACHED(); 148 NOTREACHED();
171 return false; 149 return false;
172 } 150 }
173 151
174 // static 152 // static
175 bool GpuMemoryBufferImpl::BufferSizeInBytes(const gfx::Size& size, 153 bool GpuMemoryBufferImpl::BufferSizeInBytes(const gfx::Size& size,
176 gfx::BufferFormat format, 154 gfx::BufferFormat format,
177 size_t* size_in_bytes) { 155 size_t* size_in_bytes) {
178 base::CheckedNumeric<size_t> checked_size = 0; 156 base::CheckedNumeric<size_t> checked_size = 0;
179 size_t num_planes = NumberOfPlanesForGpuMemoryBufferFormat(format); 157 size_t num_planes = gfx::GpuMemoryBuffer::NumberOfPlanes(format);
180 for (size_t i = 0; i < num_planes; ++i) { 158 for (size_t i = 0; i < num_planes; ++i) {
181 size_t row_size_in_bytes = 0; 159 size_t row_size_in_bytes = 0;
182 if (!RowSizeInBytes(size.width(), format, i, &row_size_in_bytes)) 160 if (!RowSizeInBytes(size.width(), format, i, &row_size_in_bytes))
183 return false; 161 return false;
184 base::CheckedNumeric<size_t> checked_plane_size = row_size_in_bytes; 162 base::CheckedNumeric<size_t> checked_plane_size = row_size_in_bytes;
185 checked_plane_size *= size.height() / SubsamplingFactor(format, i); 163 checked_plane_size *= size.height() / SubsamplingFactor(format, i);
186 if (!checked_plane_size.IsValid()) 164 if (!checked_plane_size.IsValid())
187 return false; 165 return false;
188 checked_size += checked_plane_size.ValueOrDie(); 166 checked_size += checked_plane_size.ValueOrDie();
189 if (!checked_size.IsValid()) 167 if (!checked_size.IsValid())
(...skipping 13 matching lines...) Expand all
203 181
204 gfx::GpuMemoryBufferId GpuMemoryBufferImpl::GetId() const { 182 gfx::GpuMemoryBufferId GpuMemoryBufferImpl::GetId() const {
205 return id_; 183 return id_;
206 } 184 }
207 185
208 ClientBuffer GpuMemoryBufferImpl::AsClientBuffer() { 186 ClientBuffer GpuMemoryBufferImpl::AsClientBuffer() {
209 return reinterpret_cast<ClientBuffer>(this); 187 return reinterpret_cast<ClientBuffer>(this);
210 } 188 }
211 189
212 } // namespace content 190 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698