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

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

Issue 1055403010: content: Add GpuMemoryBuffer MemoryDumpProvider implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move register out of ifdef Created 5 years, 7 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 case BGRA_8888: 91 case BGRA_8888:
92 return 1; 92 return 1;
93 case YUV_420: 93 case YUV_420:
94 return 3; 94 return 3;
95 } 95 }
96 NOTREACHED(); 96 NOTREACHED();
97 return 0; 97 return 0;
98 } 98 }
99 99
100 // static 100 // static
101 bool GpuMemoryBufferImpl::StrideInBytes(size_t width, 101 size_t GpuMemoryBufferImpl::SubsamplingFactor(Format format, int plane) {
102 Format format, 102 switch (format) {
103 int plane, 103 case ATC:
104 size_t* stride_in_bytes) { 104 case ATCIA:
105 base::CheckedNumeric<size_t> checked_stride = width; 105 case DXT1:
106 case DXT5:
107 case ETC1:
108 case R_8:
109 case RGBA_8888:
110 case RGBX_8888:
111 case BGRA_8888:
112 return 1;
113 case YUV_420: {
114 static size_t factor[] = {1, 2, 2};
115 DCHECK_LT(static_cast<size_t>(plane), arraysize(factor));
116 return factor[plane];
117 }
118 }
119 NOTREACHED();
120 return 0;
121 }
122
123 // static
124 bool GpuMemoryBufferImpl::RowSizeInBytes(size_t width,
125 Format format,
126 int plane,
127 size_t* size_in_bytes) {
128 base::CheckedNumeric<size_t> checked_size = width;
106 switch (format) { 129 switch (format) {
107 case ATCIA: 130 case ATCIA:
108 case DXT5: 131 case DXT5:
109 DCHECK_EQ(plane, 0); 132 DCHECK_EQ(plane, 0);
110 *stride_in_bytes = width; 133 *size_in_bytes = width;
111 return true; 134 return true;
112 case ATC: 135 case ATC:
113 case DXT1: 136 case DXT1:
114 case ETC1: 137 case ETC1:
115 DCHECK_EQ(plane, 0); 138 DCHECK_EQ(plane, 0);
116 DCHECK_EQ(width % 2, 0u); 139 DCHECK_EQ(width % 2, 0u);
117 *stride_in_bytes = width / 2; 140 *size_in_bytes = width / 2;
118 return true; 141 return true;
119 case R_8: 142 case R_8:
120 checked_stride += 3; 143 checked_size += 3;
121 if (!checked_stride.IsValid()) 144 if (!checked_size.IsValid())
122 return false; 145 return false;
123 *stride_in_bytes = checked_stride.ValueOrDie() & ~0x3; 146 *size_in_bytes = checked_size.ValueOrDie() & ~0x3;
124 return true; 147 return true;
125 case RGBX_8888: 148 case RGBX_8888:
126 case RGBA_8888: 149 case RGBA_8888:
127 case BGRA_8888: 150 case BGRA_8888:
128 checked_stride *= 4; 151 checked_size *= 4;
129 if (!checked_stride.IsValid()) 152 if (!checked_size.IsValid())
130 return false; 153 return false;
131 *stride_in_bytes = checked_stride.ValueOrDie(); 154 *size_in_bytes = checked_size.ValueOrDie();
132 return true; 155 return true;
133 case YUV_420: 156 case YUV_420:
134 DCHECK_EQ(width % 2, 0u); 157 DCHECK_EQ(width % 2, 0u);
135 *stride_in_bytes = width / SubsamplingFactor(format, plane); 158 *size_in_bytes = width / SubsamplingFactor(format, plane);
136 return true; 159 return true;
137 } 160 }
138 NOTREACHED(); 161 NOTREACHED();
139 return false; 162 return false;
140 } 163 }
141 164
142 // static 165 // static
143 size_t GpuMemoryBufferImpl::SubsamplingFactor( 166 bool GpuMemoryBufferImpl::BufferSizeInBytes(const gfx::Size& size,
144 Format format, 167 Format format,
145 int plane) { 168 size_t* size_in_bytes) {
146 switch (format) { 169 base::CheckedNumeric<size_t> checked_size = 0;
147 case ATC: 170 size_t num_planes = NumberOfPlanesForGpuMemoryBufferFormat(format);
148 case ATCIA: 171 for (size_t i = 0; i < num_planes; ++i) {
149 case DXT1: 172 size_t row_size_in_bytes = 0;
150 case DXT5: 173 if (!RowSizeInBytes(size.width(), format, i, &row_size_in_bytes))
151 case ETC1: 174 return false;
152 case R_8: 175 base::CheckedNumeric<size_t> checked_plane_size = row_size_in_bytes;
153 case RGBA_8888: 176 checked_plane_size *= size.height() / SubsamplingFactor(format, i);
154 case RGBX_8888: 177 if (!checked_plane_size.IsValid())
155 case BGRA_8888: 178 return false;
156 return 1; 179 checked_size += checked_plane_size.ValueOrDie();
157 case YUV_420: { 180 if (!checked_size.IsValid())
158 static size_t factor[] = {1, 2, 2}; 181 return false;
159 DCHECK_LT(static_cast<size_t>(plane), arraysize(factor));
160 return factor[plane];
161 }
162 } 182 }
163 NOTREACHED(); 183 *size_in_bytes = checked_size.ValueOrDie();
164 return 0; 184 return true;
165 } 185 }
166 186
167 gfx::GpuMemoryBuffer::Format GpuMemoryBufferImpl::GetFormat() const { 187 gfx::GpuMemoryBuffer::Format GpuMemoryBufferImpl::GetFormat() const {
168 return format_; 188 return format_;
169 } 189 }
170 190
171 bool GpuMemoryBufferImpl::IsMapped() const { 191 bool GpuMemoryBufferImpl::IsMapped() const {
172 return mapped_; 192 return mapped_;
173 } 193 }
174 194
175 ClientBuffer GpuMemoryBufferImpl::AsClientBuffer() { 195 ClientBuffer GpuMemoryBufferImpl::AsClientBuffer() {
176 return reinterpret_cast<ClientBuffer>(this); 196 return reinterpret_cast<ClientBuffer>(this);
177 } 197 }
178 198
179 } // namespace content 199 } // 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.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698