OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2010 Google Inc. | 3 * Copyright 2010 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 | 10 |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 *indexCount = -1; | 225 *indexCount = -1; |
226 } | 226 } |
227 return false; | 227 return false; |
228 } | 228 } |
229 | 229 |
230 void GrDrawTarget::releasePreviousVertexSource() { | 230 void GrDrawTarget::releasePreviousVertexSource() { |
231 GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); | 231 GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
232 switch (geoSrc.fVertexSrc) { | 232 switch (geoSrc.fVertexSrc) { |
233 case kNone_GeometrySrcType: | 233 case kNone_GeometrySrcType: |
234 break; | 234 break; |
235 case kArray_GeometrySrcType: | |
236 this->releaseVertexArray(); | |
237 break; | |
238 case kReserved_GeometrySrcType: | 235 case kReserved_GeometrySrcType: |
239 this->releaseReservedVertexSpace(); | 236 this->releaseReservedVertexSpace(); |
240 break; | 237 break; |
241 case kBuffer_GeometrySrcType: | 238 case kBuffer_GeometrySrcType: |
242 geoSrc.fVertexBuffer->unref(); | 239 geoSrc.fVertexBuffer->unref(); |
243 #ifdef SK_DEBUG | 240 #ifdef SK_DEBUG |
244 geoSrc.fVertexBuffer = (GrVertexBuffer*)DEBUG_INVAL_BUFFER; | 241 geoSrc.fVertexBuffer = (GrVertexBuffer*)DEBUG_INVAL_BUFFER; |
245 #endif | 242 #endif |
246 break; | 243 break; |
247 default: | 244 default: |
248 SkFAIL("Unknown Vertex Source Type."); | 245 SkFAIL("Unknown Vertex Source Type."); |
249 break; | 246 break; |
250 } | 247 } |
251 } | 248 } |
252 | 249 |
253 void GrDrawTarget::releasePreviousIndexSource() { | 250 void GrDrawTarget::releasePreviousIndexSource() { |
254 GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); | 251 GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
255 switch (geoSrc.fIndexSrc) { | 252 switch (geoSrc.fIndexSrc) { |
256 case kNone_GeometrySrcType: // these two don't require | 253 case kNone_GeometrySrcType: // these two don't require |
257 break; | 254 break; |
258 case kArray_GeometrySrcType: | |
259 this->releaseIndexArray(); | |
260 break; | |
261 case kReserved_GeometrySrcType: | 255 case kReserved_GeometrySrcType: |
262 this->releaseReservedIndexSpace(); | 256 this->releaseReservedIndexSpace(); |
263 break; | 257 break; |
264 case kBuffer_GeometrySrcType: | 258 case kBuffer_GeometrySrcType: |
265 geoSrc.fIndexBuffer->unref(); | 259 geoSrc.fIndexBuffer->unref(); |
266 #ifdef SK_DEBUG | 260 #ifdef SK_DEBUG |
267 geoSrc.fIndexBuffer = (GrIndexBuffer*)DEBUG_INVAL_BUFFER; | 261 geoSrc.fIndexBuffer = (GrIndexBuffer*)DEBUG_INVAL_BUFFER; |
268 #endif | 262 #endif |
269 break; | 263 break; |
270 default: | 264 default: |
271 SkFAIL("Unknown Index Source Type."); | 265 SkFAIL("Unknown Index Source Type."); |
272 break; | 266 break; |
273 } | 267 } |
274 } | 268 } |
275 | 269 |
276 void GrDrawTarget::setVertexSourceToArray(const void* vertexArray, | |
277 int vertexCount) { | |
278 this->releasePreviousVertexSource(); | |
279 GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); | |
280 geoSrc.fVertexSrc = kArray_GeometrySrcType; | |
281 geoSrc.fVertexSize = this->drawState()->getVertexStride(); | |
282 geoSrc.fVertexCount = vertexCount; | |
283 this->onSetVertexSourceToArray(vertexArray, vertexCount); | |
284 } | |
285 | |
286 void GrDrawTarget::setIndexSourceToArray(const void* indexArray, | |
287 int indexCount) { | |
288 this->releasePreviousIndexSource(); | |
289 GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); | |
290 geoSrc.fIndexSrc = kArray_GeometrySrcType; | |
291 geoSrc.fIndexCount = indexCount; | |
292 this->onSetIndexSourceToArray(indexArray, indexCount); | |
293 } | |
294 | |
295 void GrDrawTarget::setVertexSourceToBuffer(const GrVertexBuffer* buffer) { | 270 void GrDrawTarget::setVertexSourceToBuffer(const GrVertexBuffer* buffer) { |
296 this->releasePreviousVertexSource(); | 271 this->releasePreviousVertexSource(); |
297 GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); | 272 GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
298 geoSrc.fVertexSrc = kBuffer_GeometrySrcType; | 273 geoSrc.fVertexSrc = kBuffer_GeometrySrcType; |
299 geoSrc.fVertexBuffer = buffer; | 274 geoSrc.fVertexBuffer = buffer; |
300 buffer->ref(); | 275 buffer->ref(); |
301 geoSrc.fVertexSize = this->drawState()->getVertexStride(); | 276 geoSrc.fVertexSize = this->drawState()->getVertexStride(); |
302 } | 277 } |
303 | 278 |
304 void GrDrawTarget::setIndexSourceToBuffer(const GrIndexBuffer* buffer) { | 279 void GrDrawTarget::setIndexSourceToBuffer(const GrIndexBuffer* buffer) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 int indexCount) const { | 326 int indexCount) const { |
352 const GrDrawState& drawState = this->getDrawState(); | 327 const GrDrawState& drawState = this->getDrawState(); |
353 #ifdef SK_DEBUG | 328 #ifdef SK_DEBUG |
354 const GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); | 329 const GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
355 int maxVertex = startVertex + vertexCount; | 330 int maxVertex = startVertex + vertexCount; |
356 int maxValidVertex; | 331 int maxValidVertex; |
357 switch (geoSrc.fVertexSrc) { | 332 switch (geoSrc.fVertexSrc) { |
358 case kNone_GeometrySrcType: | 333 case kNone_GeometrySrcType: |
359 SkFAIL("Attempting to draw without vertex src."); | 334 SkFAIL("Attempting to draw without vertex src."); |
360 case kReserved_GeometrySrcType: // fallthrough | 335 case kReserved_GeometrySrcType: // fallthrough |
361 case kArray_GeometrySrcType: | |
362 maxValidVertex = geoSrc.fVertexCount; | 336 maxValidVertex = geoSrc.fVertexCount; |
363 break; | 337 break; |
364 case kBuffer_GeometrySrcType: | 338 case kBuffer_GeometrySrcType: |
365 maxValidVertex = static_cast<int>(geoSrc.fVertexBuffer->gpuMemorySiz
e() / geoSrc.fVertexSize); | 339 maxValidVertex = static_cast<int>(geoSrc.fVertexBuffer->gpuMemorySiz
e() / geoSrc.fVertexSize); |
366 break; | 340 break; |
367 } | 341 } |
368 if (maxVertex > maxValidVertex) { | 342 if (maxVertex > maxValidVertex) { |
369 SkFAIL("Drawing outside valid vertex range."); | 343 SkFAIL("Drawing outside valid vertex range."); |
370 } | 344 } |
371 if (indexCount > 0) { | 345 if (indexCount > 0) { |
372 int maxIndex = startIndex + indexCount; | 346 int maxIndex = startIndex + indexCount; |
373 int maxValidIndex; | 347 int maxValidIndex; |
374 switch (geoSrc.fIndexSrc) { | 348 switch (geoSrc.fIndexSrc) { |
375 case kNone_GeometrySrcType: | 349 case kNone_GeometrySrcType: |
376 SkFAIL("Attempting to draw indexed geom without index src."); | 350 SkFAIL("Attempting to draw indexed geom without index src."); |
377 case kReserved_GeometrySrcType: // fallthrough | 351 case kReserved_GeometrySrcType: // fallthrough |
378 case kArray_GeometrySrcType: | |
379 maxValidIndex = geoSrc.fIndexCount; | 352 maxValidIndex = geoSrc.fIndexCount; |
380 break; | 353 break; |
381 case kBuffer_GeometrySrcType: | 354 case kBuffer_GeometrySrcType: |
382 maxValidIndex = static_cast<int>(geoSrc.fIndexBuffer->gpuMemoryS
ize() / sizeof(uint16_t)); | 355 maxValidIndex = static_cast<int>(geoSrc.fIndexBuffer->gpuMemoryS
ize() / sizeof(uint16_t)); |
383 break; | 356 break; |
384 } | 357 } |
385 if (maxIndex > maxValidIndex) { | 358 if (maxIndex > maxValidIndex) { |
386 SkFAIL("Index reads outside valid index range."); | 359 SkFAIL("Index reads outside valid index range."); |
387 } | 360 } |
388 } | 361 } |
(...skipping 754 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1143 | 1116 |
1144 uint32_t GrDrawTargetCaps::CreateUniqueID() { | 1117 uint32_t GrDrawTargetCaps::CreateUniqueID() { |
1145 static int32_t gUniqueID = SK_InvalidUniqueID; | 1118 static int32_t gUniqueID = SK_InvalidUniqueID; |
1146 uint32_t id; | 1119 uint32_t id; |
1147 do { | 1120 do { |
1148 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); | 1121 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); |
1149 } while (id == SK_InvalidUniqueID); | 1122 } while (id == SK_InvalidUniqueID); |
1150 return id; | 1123 return id; |
1151 } | 1124 } |
1152 | 1125 |
OLD | NEW |