| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrDrawTarget_DEFINED | 8 #ifndef GrDrawTarget_DEFINED |
| 9 #define GrDrawTarget_DEFINED | 9 #define GrDrawTarget_DEFINED |
| 10 | 10 |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 | 218 |
| 219 private: | 219 private: |
| 220 GrDrawTarget* fDrawTarget; | 220 GrDrawTarget* fDrawTarget; |
| 221 uint32_t fDrawID; // this may wrap, but we're doing direct compa
rison | 221 uint32_t fDrawID; // this may wrap, but we're doing direct compa
rison |
| 222 // so that should be okay | 222 // so that should be okay |
| 223 }; | 223 }; |
| 224 | 224 |
| 225 virtual DrawToken getCurrentDrawToken() { return DrawToken(this, 0); } | 225 virtual DrawToken getCurrentDrawToken() { return DrawToken(this, 0); } |
| 226 | 226 |
| 227 /** | 227 /** |
| 228 * Used to communicate draw index vertex offsets and counts toto GPUs / subc
lasses | 228 * Used to communicate draws to GPUs / subclasses |
| 229 */ | 229 */ |
| 230 class DrawInfo { | 230 class DrawInfo { |
| 231 public: | 231 public: |
| 232 DrawInfo() {} | 232 DrawInfo() { fDevBounds = NULL; } |
| 233 DrawInfo(const DrawInfo& di) { (*this) = di; } | 233 DrawInfo(const DrawInfo& di) { (*this) = di; } |
| 234 DrawInfo& operator =(const DrawInfo& di); | 234 DrawInfo& operator =(const DrawInfo& di); |
| 235 | 235 |
| 236 void init(GrPrimitiveType primType, const GrVertexBuffer* vertexBuffer,
int startVertex, | |
| 237 int vertexCount) { | |
| 238 SkASSERT(vertexBuffer); | |
| 239 SkASSERT(vertexCount); | |
| 240 SkASSERT(startVertex >= 0); | |
| 241 fPrimitiveType = primType; | |
| 242 fVertexBuffer.reset(SkRef(vertexBuffer)); | |
| 243 fIndexBuffer.reset(NULL); | |
| 244 fStartVertex = startVertex; | |
| 245 fStartIndex = 0; | |
| 246 fVertexCount = vertexCount; | |
| 247 fIndexCount = 0; | |
| 248 fInstanceCount = 0; | |
| 249 fVerticesPerInstance = 0; | |
| 250 fIndicesPerInstance = 0; | |
| 251 } | |
| 252 | |
| 253 void initIndexed(GrPrimitiveType primType, | |
| 254 const GrVertexBuffer* vertexBuffer, | |
| 255 const GrIndexBuffer* indexBuffer, | |
| 256 int startVertex, | |
| 257 int startIndex, | |
| 258 int vertexCount, | |
| 259 int indexCount) { | |
| 260 SkASSERT(indexBuffer); | |
| 261 SkASSERT(vertexBuffer); | |
| 262 SkASSERT(indexCount); | |
| 263 SkASSERT(vertexCount); | |
| 264 SkASSERT(startIndex >= 0); | |
| 265 SkASSERT(startVertex >= 0); | |
| 266 fPrimitiveType = primType; | |
| 267 fVertexBuffer.reset(SkRef(vertexBuffer)); | |
| 268 fIndexBuffer.reset(SkRef(indexBuffer)); | |
| 269 fStartVertex = startVertex; | |
| 270 fStartIndex = startIndex; | |
| 271 fVertexCount = vertexCount; | |
| 272 fIndexCount = indexCount; | |
| 273 fInstanceCount = 0; | |
| 274 fVerticesPerInstance = 0; | |
| 275 fIndicesPerInstance = 0; | |
| 276 } | |
| 277 | |
| 278 void initInstanced(GrPrimitiveType primType, | |
| 279 const GrVertexBuffer* vertexBuffer, | |
| 280 const GrIndexBuffer* indexBuffer, | |
| 281 int startVertex, | |
| 282 int verticesPerInstance, | |
| 283 int indicesPerInstance, | |
| 284 int instanceCount) { | |
| 285 SkASSERT(vertexBuffer); | |
| 286 SkASSERT(indexBuffer); | |
| 287 SkASSERT(instanceCount); | |
| 288 SkASSERT(verticesPerInstance); | |
| 289 SkASSERT(indicesPerInstance); | |
| 290 SkASSERT(startVertex >= 0); | |
| 291 fPrimitiveType = primType; | |
| 292 fVertexBuffer.reset(SkRef(vertexBuffer)); | |
| 293 fIndexBuffer.reset(SkRef(indexBuffer)); | |
| 294 fStartVertex = startVertex; | |
| 295 fStartIndex = 0; | |
| 296 fVerticesPerInstance = verticesPerInstance; | |
| 297 fIndicesPerInstance = indicesPerInstance; | |
| 298 fInstanceCount = instanceCount; | |
| 299 fVertexCount = instanceCount * fVerticesPerInstance; | |
| 300 fIndexCount = instanceCount * fIndicesPerInstance; | |
| 301 } | |
| 302 | |
| 303 /** Variation of the above that may be used when the total number of ins
tances may exceed | |
| 304 the number of instances supported by the index buffer. To be used wi
th | |
| 305 nextInstances() to draw in max-sized batches.*/ | |
| 306 void initInstanced(GrPrimitiveType primType, | |
| 307 const GrVertexBuffer* vertexBuffer, | |
| 308 const GrIndexBuffer* indexBuffer, | |
| 309 int startVertex, | |
| 310 int verticesPerInstance, | |
| 311 int indicesPerInstance, | |
| 312 int* instancesRemaining, | |
| 313 int maxInstancesPerDraw) { | |
| 314 int instanceCount = SkTMin(*instancesRemaining, maxInstancesPerDraw)
; | |
| 315 *instancesRemaining -= instanceCount; | |
| 316 this->initInstanced(primType, vertexBuffer, indexBuffer, startVertex
, | |
| 317 verticesPerInstance, indicesPerInstance, instanc
eCount); | |
| 318 } | |
| 319 | |
| 320 GrPrimitiveType primitiveType() const { return fPrimitiveType; } | 236 GrPrimitiveType primitiveType() const { return fPrimitiveType; } |
| 321 int startVertex() const { return fStartVertex; } | 237 int startVertex() const { return fStartVertex; } |
| 322 int startIndex() const { return fStartIndex; } | 238 int startIndex() const { return fStartIndex; } |
| 323 int vertexCount() const { return fVertexCount; } | 239 int vertexCount() const { return fVertexCount; } |
| 324 int indexCount() const { return fIndexCount; } | 240 int indexCount() const { return fIndexCount; } |
| 325 | |
| 326 /** These return 0 if initInstanced was not used to initialize the DrawI
nfo. */ | |
| 327 int verticesPerInstance() const { return fVerticesPerInstance; } | 241 int verticesPerInstance() const { return fVerticesPerInstance; } |
| 328 int indicesPerInstance() const { return fIndicesPerInstance; } | 242 int indicesPerInstance() const { return fIndicesPerInstance; } |
| 329 int instanceCount() const { return fInstanceCount; } | 243 int instanceCount() const { return fInstanceCount; } |
| 330 | 244 |
| 245 void setPrimitiveType(GrPrimitiveType type) { fPrimitiveType = type; } |
| 246 void setStartVertex(int startVertex) { fStartVertex = startVertex; } |
| 247 void setStartIndex(int startIndex) { fStartIndex = startIndex; } |
| 248 void setVertexCount(int vertexCount) { fVertexCount = vertexCount; } |
| 249 void setIndexCount(int indexCount) { fIndexCount = indexCount; } |
| 250 void setVerticesPerInstance(int verticesPerI) { fVerticesPerInstance = v
erticesPerI; } |
| 251 void setIndicesPerInstance(int indicesPerI) { fIndicesPerInstance = indi
cesPerI; } |
| 252 void setInstanceCount(int instanceCount) { fInstanceCount = instanceCoun
t; } |
| 253 |
| 331 bool isIndexed() const { return fIndexCount > 0; } | 254 bool isIndexed() const { return fIndexCount > 0; } |
| 255 #ifdef SK_DEBUG |
| 256 bool isInstanced() const; // this version is longer because of asserts |
| 257 #else |
| 332 bool isInstanced() const { return fInstanceCount > 0; } | 258 bool isInstanced() const { return fInstanceCount > 0; } |
| 259 #endif |
| 333 | 260 |
| 334 /** Called after using this draw info to draw the next set of instances. | 261 // adds or remove instances |
| 335 The vertex offset is advanced while the index buffer is reused at th
e same | 262 void adjustInstanceCount(int instanceOffset); |
| 336 position. instancesRemaining is number of instances that remain, max
Instances is | 263 // shifts the start vertex |
| 337 the most number of instances that can be used with the index buffer.
If there | 264 void adjustStartVertex(int vertexOffset) { |
| 338 are no instances remaining, the DrawInfo is unmodified and false is
returned.*/ | 265 fStartVertex += vertexOffset; |
| 339 bool nextInstances(int* instancesRemaining, int maxInstances) { | 266 SkASSERT(fStartVertex >= 0); |
| 340 SkASSERT(this->isInstanced()); | |
| 341 if (!*instancesRemaining) { | |
| 342 return false; | |
| 343 } | |
| 344 fStartVertex += fVertexCount; | |
| 345 fInstanceCount = SkTMin(*instancesRemaining, maxInstances); | |
| 346 fVertexCount = fInstanceCount * fVerticesPerInstance; | |
| 347 fIndexCount = fInstanceCount * fIndicesPerInstance; | |
| 348 *instancesRemaining -= fInstanceCount; | |
| 349 return true; | |
| 350 } | 267 } |
| 351 | 268 // shifts the start index |
| 269 void adjustStartIndex(int indexOffset) { |
| 270 SkASSERT(this->isIndexed()); |
| 271 fStartIndex += indexOffset; |
| 272 SkASSERT(fStartIndex >= 0); |
| 273 } |
| 274 void setDevBounds(const SkRect& bounds) { |
| 275 fDevBoundsStorage = bounds; |
| 276 fDevBounds = &fDevBoundsStorage; |
| 277 } |
| 352 const GrVertexBuffer* vertexBuffer() const { return fVertexBuffer.get();
} | 278 const GrVertexBuffer* vertexBuffer() const { return fVertexBuffer.get();
} |
| 353 const GrIndexBuffer* indexBuffer() const { return fIndexBuffer.get(); } | 279 const GrIndexBuffer* indexBuffer() const { return fIndexBuffer.get(); } |
| 280 void setVertexBuffer(const GrVertexBuffer* vb) { |
| 281 fVertexBuffer.reset(vb); |
| 282 } |
| 283 void setIndexBuffer(const GrIndexBuffer* ib) { |
| 284 fIndexBuffer.reset(ib); |
| 285 } |
| 286 const SkRect* getDevBounds() const { return fDevBounds; } |
| 354 | 287 |
| 355 private: | 288 private: |
| 356 friend class GrDrawTarget; | 289 friend class GrDrawTarget; |
| 357 | 290 |
| 358 GrPrimitiveType fPrimitiveType; | 291 GrPrimitiveType fPrimitiveType; |
| 359 | 292 |
| 360 int fStartVertex; | 293 int fStartVertex; |
| 361 int fStartIndex; | 294 int fStartIndex; |
| 362 int fVertexCount; | 295 int fVertexCount; |
| 363 int fIndexCount; | 296 int fIndexCount; |
| 364 | 297 |
| 365 int fInstanceCount; | 298 int fInstanceCount; |
| 366 int fVerticesPerInstance; | 299 int fVerticesPerInstance; |
| 367 int fIndicesPerInstance; | 300 int fIndicesPerInstance; |
| 368 | 301 |
| 302 SkRect fDevBoundsStorage; |
| 303 SkRect* fDevBounds; |
| 304 |
| 369 GrPendingIOResource<const GrVertexBuffer, kRead_GrIOType> fVertexBuffer; | 305 GrPendingIOResource<const GrVertexBuffer, kRead_GrIOType> fVertexBuffer; |
| 370 GrPendingIOResource<const GrIndexBuffer, kRead_GrIOType> fIndexBuffer; | 306 GrPendingIOResource<const GrIndexBuffer, kRead_GrIOType> fIndexBuffer; |
| 371 }; | 307 }; |
| 372 | 308 |
| 373 bool programUnitTest(int maxStages); | 309 bool programUnitTest(int maxStages); |
| 374 | 310 |
| 375 protected: | 311 protected: |
| 376 friend class GrTargetCommands; // for PipelineInfo | 312 friend class GrTargetCommands; // for PipelineInfo |
| 377 | 313 |
| 378 GrContext* getContext() { return fContext; } | 314 GrContext* getContext() { return fContext; } |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 virtual bool setupClip(GrPipelineBuilder*, | 477 virtual bool setupClip(GrPipelineBuilder*, |
| 542 GrPipelineBuilder::AutoRestoreFragmentProcessors*, | 478 GrPipelineBuilder::AutoRestoreFragmentProcessors*, |
| 543 GrPipelineBuilder::AutoRestoreStencil*, | 479 GrPipelineBuilder::AutoRestoreStencil*, |
| 544 GrScissorState* scissorState, | 480 GrScissorState* scissorState, |
| 545 const SkRect* devBounds) override; | 481 const SkRect* devBounds) override; |
| 546 | 482 |
| 547 typedef GrDrawTarget INHERITED; | 483 typedef GrDrawTarget INHERITED; |
| 548 }; | 484 }; |
| 549 | 485 |
| 550 #endif | 486 #endif |
| OLD | NEW |