OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "gpu/command_buffer/service/buffer_manager.h" | 5 #include "gpu/command_buffer/service/buffer_manager.h" |
| 6 |
| 7 #include <stdint.h> |
| 8 |
6 #include <limits> | 9 #include <limits> |
| 10 |
7 #include "base/logging.h" | 11 #include "base/logging.h" |
8 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
9 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
10 #include "base/trace_event/memory_dump_manager.h" | 14 #include "base/trace_event/memory_dump_manager.h" |
11 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
12 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 16 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
13 #include "gpu/command_buffer/service/context_state.h" | 17 #include "gpu/command_buffer/service/context_state.h" |
14 #include "gpu/command_buffer/service/error_state.h" | 18 #include "gpu/command_buffer/service/error_state.h" |
15 #include "gpu/command_buffer/service/feature_info.h" | 19 #include "gpu/command_buffer/service/feature_info.h" |
16 #include "gpu/command_buffer/service/memory_tracking.h" | 20 #include "gpu/command_buffer/service/memory_tracking.h" |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 void Buffer::SetInfo( | 140 void Buffer::SetInfo( |
137 GLsizeiptr size, GLenum usage, bool shadow, const GLvoid* data, | 141 GLsizeiptr size, GLenum usage, bool shadow, const GLvoid* data, |
138 bool is_client_side_array) { | 142 bool is_client_side_array) { |
139 usage_ = usage; | 143 usage_ = usage; |
140 is_client_side_array_ = is_client_side_array; | 144 is_client_side_array_ = is_client_side_array; |
141 ClearCache(); | 145 ClearCache(); |
142 if (size != size_ || shadow != shadowed_) { | 146 if (size != size_ || shadow != shadowed_) { |
143 shadowed_ = shadow; | 147 shadowed_ = shadow; |
144 size_ = size; | 148 size_ = size; |
145 if (shadowed_) { | 149 if (shadowed_) { |
146 shadow_.reset(new int8[size]); | 150 shadow_.reset(new int8_t[size]); |
147 } else { | 151 } else { |
148 shadow_.reset(); | 152 shadow_.reset(); |
149 } | 153 } |
150 } | 154 } |
151 if (shadowed_) { | 155 if (shadowed_) { |
152 if (data) { | 156 if (data) { |
153 memcpy(shadow_.get(), data, size); | 157 memcpy(shadow_.get(), data, size); |
154 } else { | 158 } else { |
155 memset(shadow_.get(), 0, size); | 159 memset(shadow_.get(), 0, size); |
156 } | 160 } |
157 } | 161 } |
158 mapped_range_.reset(nullptr); | 162 mapped_range_.reset(nullptr); |
159 } | 163 } |
160 | 164 |
161 bool Buffer::CheckRange( | 165 bool Buffer::CheckRange( |
162 GLintptr offset, GLsizeiptr size) const { | 166 GLintptr offset, GLsizeiptr size) const { |
163 int32 end = 0; | 167 int32_t end = 0; |
164 return offset >= 0 && size >= 0 && | 168 return offset >= 0 && size >= 0 && |
165 offset <= std::numeric_limits<int32>::max() && | 169 offset <= std::numeric_limits<int32_t>::max() && |
166 size <= std::numeric_limits<int32>::max() && | 170 size <= std::numeric_limits<int32_t>::max() && |
167 SafeAddInt32(offset, size, &end) && end <= size_; | 171 SafeAddInt32(offset, size, &end) && end <= size_; |
168 } | 172 } |
169 | 173 |
170 bool Buffer::SetRange( | 174 bool Buffer::SetRange( |
171 GLintptr offset, GLsizeiptr size, const GLvoid * data) { | 175 GLintptr offset, GLsizeiptr size, const GLvoid * data) { |
172 if (!CheckRange(offset, size)) { | 176 if (!CheckRange(offset, size)) { |
173 return false; | 177 return false; |
174 } | 178 } |
175 if (shadowed_) { | 179 if (shadowed_) { |
176 memcpy(shadow_.get() + offset, data, size); | 180 memcpy(shadow_.get() + offset, data, size); |
(...skipping 13 matching lines...) Expand all Loading... |
190 return shadow_.get() + offset; | 194 return shadow_.get() + offset; |
191 } | 195 } |
192 | 196 |
193 void Buffer::ClearCache() { | 197 void Buffer::ClearCache() { |
194 range_set_.clear(); | 198 range_set_.clear(); |
195 } | 199 } |
196 | 200 |
197 template <typename T> | 201 template <typename T> |
198 GLuint GetMaxValue(const void* data, GLuint offset, GLsizei count) { | 202 GLuint GetMaxValue(const void* data, GLuint offset, GLsizei count) { |
199 GLuint max_value = 0; | 203 GLuint max_value = 0; |
200 const T* element = reinterpret_cast<const T*>( | 204 const T* element = |
201 static_cast<const int8*>(data) + offset); | 205 reinterpret_cast<const T*>(static_cast<const int8_t*>(data) + offset); |
202 const T* end = element + count; | 206 const T* end = element + count; |
203 for (; element < end; ++element) { | 207 for (; element < end; ++element) { |
204 if (*element > max_value) { | 208 if (*element > max_value) { |
205 max_value = *element; | 209 max_value = *element; |
206 } | 210 } |
207 } | 211 } |
208 return max_value; | 212 return max_value; |
209 } | 213 } |
210 | 214 |
211 bool Buffer::GetMaxValueForRange( | 215 bool Buffer::GetMaxValueForRange( |
212 GLuint offset, GLsizei count, GLenum type, GLuint* max_value) { | 216 GLuint offset, GLsizei count, GLenum type, GLuint* max_value) { |
213 Range range(offset, count, type); | 217 Range range(offset, count, type); |
214 RangeToMaxValueMap::iterator it = range_set_.find(range); | 218 RangeToMaxValueMap::iterator it = range_set_.find(range); |
215 if (it != range_set_.end()) { | 219 if (it != range_set_.end()) { |
216 *max_value = it->second; | 220 *max_value = it->second; |
217 return true; | 221 return true; |
218 } | 222 } |
219 | 223 |
220 uint32 size; | 224 uint32_t size; |
221 if (!SafeMultiplyUint32( | 225 if (!SafeMultiplyUint32( |
222 count, GLES2Util::GetGLTypeSizeForTexturesAndBuffers(type), &size)) { | 226 count, GLES2Util::GetGLTypeSizeForTexturesAndBuffers(type), &size)) { |
223 return false; | 227 return false; |
224 } | 228 } |
225 | 229 |
226 if (!SafeAddUint32(offset, size, &size)) { | 230 if (!SafeAddUint32(offset, size, &size)) { |
227 return false; | 231 return false; |
228 } | 232 } |
229 | 233 |
230 if (size > static_cast<uint32>(size_)) { | 234 if (size > static_cast<uint32_t>(size_)) { |
231 return false; | 235 return false; |
232 } | 236 } |
233 | 237 |
234 if (!shadowed_) { | 238 if (!shadowed_) { |
235 return false; | 239 return false; |
236 } | 240 } |
237 | 241 |
238 // Scan the range for the max value and store | 242 // Scan the range for the max value and store |
239 GLuint max_v = 0; | 243 GLuint max_v = 0; |
240 switch (type) { | 244 switch (type) { |
241 case GL_UNSIGNED_BYTE: | 245 case GL_UNSIGNED_BYTE: |
242 max_v = GetMaxValue<uint8>(shadow_.get(), offset, count); | 246 max_v = GetMaxValue<uint8_t>(shadow_.get(), offset, count); |
243 break; | 247 break; |
244 case GL_UNSIGNED_SHORT: | 248 case GL_UNSIGNED_SHORT: |
245 // Check we are not accessing an odd byte for a 2 byte value. | 249 // Check we are not accessing an odd byte for a 2 byte value. |
246 if ((offset & 1) != 0) { | 250 if ((offset & 1) != 0) { |
247 return false; | 251 return false; |
248 } | 252 } |
249 max_v = GetMaxValue<uint16>(shadow_.get(), offset, count); | 253 max_v = GetMaxValue<uint16_t>(shadow_.get(), offset, count); |
250 break; | 254 break; |
251 case GL_UNSIGNED_INT: | 255 case GL_UNSIGNED_INT: |
252 // Check we are not accessing a non aligned address for a 4 byte value. | 256 // Check we are not accessing a non aligned address for a 4 byte value. |
253 if ((offset & 3) != 0) { | 257 if ((offset & 3) != 0) { |
254 return false; | 258 return false; |
255 } | 259 } |
256 max_v = GetMaxValue<uint32>(shadow_.get(), offset, count); | 260 max_v = GetMaxValue<uint32_t>(shadow_.get(), offset, count); |
257 break; | 261 break; |
258 default: | 262 default: |
259 NOTREACHED(); // should never get here by validation. | 263 NOTREACHED(); // should never get here by validation. |
260 break; | 264 break; |
261 } | 265 } |
262 range_set_.insert(std::make_pair(range, max_v)); | 266 range_set_.insert(std::make_pair(range, max_v)); |
263 *max_value = max_v; | 267 *max_value = max_v; |
264 return true; | 268 return true; |
265 } | 269 } |
266 | 270 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 | 344 |
341 | 345 |
342 void BufferManager::DoBufferData( | 346 void BufferManager::DoBufferData( |
343 ErrorState* error_state, | 347 ErrorState* error_state, |
344 Buffer* buffer, | 348 Buffer* buffer, |
345 GLenum target, | 349 GLenum target, |
346 GLsizeiptr size, | 350 GLsizeiptr size, |
347 GLenum usage, | 351 GLenum usage, |
348 const GLvoid* data) { | 352 const GLvoid* data) { |
349 // Clear the buffer to 0 if no initial data was passed in. | 353 // Clear the buffer to 0 if no initial data was passed in. |
350 scoped_ptr<int8[]> zero; | 354 scoped_ptr<int8_t[]> zero; |
351 if (!data) { | 355 if (!data) { |
352 zero.reset(new int8[size]); | 356 zero.reset(new int8_t[size]); |
353 memset(zero.get(), 0, size); | 357 memset(zero.get(), 0, size); |
354 data = zero.get(); | 358 data = zero.get(); |
355 } | 359 } |
356 | 360 |
357 ERRORSTATE_COPY_REAL_GL_ERRORS_TO_WRAPPER(error_state, "glBufferData"); | 361 ERRORSTATE_COPY_REAL_GL_ERRORS_TO_WRAPPER(error_state, "glBufferData"); |
358 if (IsUsageClientSideArray(usage)) { | 362 if (IsUsageClientSideArray(usage)) { |
359 GLsizei empty_size = UseNonZeroSizeForClientSideArrayBuffer() ? 1 : 0; | 363 GLsizei empty_size = UseNonZeroSizeForClientSideArrayBuffer() ? 1 : 0; |
360 glBufferData(target, empty_size, NULL, usage); | 364 glBufferData(target, empty_size, NULL, usage); |
361 } else { | 365 } else { |
362 glBufferData(target, size, data, usage); | 366 glBufferData(target, size, data, usage); |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 auto guid = gfx::GetGLBufferGUIDForTracing( | 554 auto guid = gfx::GetGLBufferGUIDForTracing( |
551 memory_tracker_->ShareGroupTracingGUID(), client_buffer_id); | 555 memory_tracker_->ShareGroupTracingGUID(), client_buffer_id); |
552 pmd->CreateSharedGlobalAllocatorDump(guid); | 556 pmd->CreateSharedGlobalAllocatorDump(guid); |
553 pmd->AddOwnershipEdge(dump->guid(), guid); | 557 pmd->AddOwnershipEdge(dump->guid(), guid); |
554 } | 558 } |
555 return true; | 559 return true; |
556 } | 560 } |
557 | 561 |
558 } // namespace gles2 | 562 } // namespace gles2 |
559 } // namespace gpu | 563 } // namespace gpu |
OLD | NEW |