| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 GrGpu_DEFINED | 8 #ifndef GrGpu_DEFINED |
| 9 #define GrGpu_DEFINED | 9 #define GrGpu_DEFINED |
| 10 | 10 |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 * Takes the current active set of markers and stores them for later use. An
y current marker | 367 * Takes the current active set of markers and stores them for later use. An
y current marker |
| 368 * in the active set is removed from the active set and the targets remove f
unction is called. | 368 * in the active set is removed from the active set and the targets remove f
unction is called. |
| 369 * These functions do not work as a stack so you cannot call save a second t
ime before calling | 369 * These functions do not work as a stack so you cannot call save a second t
ime before calling |
| 370 * restore. Also, it is assumed that when restore is called the current acti
ve set of markers | 370 * restore. Also, it is assumed that when restore is called the current acti
ve set of markers |
| 371 * is empty. When the stored markers are added back into the active set, the
targets add marker | 371 * is empty. When the stored markers are added back into the active set, the
targets add marker |
| 372 * is called. | 372 * is called. |
| 373 */ | 373 */ |
| 374 void saveActiveTraceMarkers(); | 374 void saveActiveTraceMarkers(); |
| 375 void restoreActiveTraceMarkers(); | 375 void restoreActiveTraceMarkers(); |
| 376 | 376 |
| 377 /** | |
| 378 * Query to find out if the vertex or index source is reserved. | |
| 379 */ | |
| 380 bool hasReservedVerticesOrIndices() const { | |
| 381 return GrDrawTarget::kReserved_GeometrySrcType == this->getGeomSrc().fVe
rtexSrc || | |
| 382 GrDrawTarget::kReserved_GeometrySrcType == this->getGeomSrc().fIn
dexSrc; | |
| 383 } | |
| 384 | |
| 385 // Called to determine whether an onCopySurface call would succeed or not. T
his is useful for | 377 // Called to determine whether an onCopySurface call would succeed or not. T
his is useful for |
| 386 // proxy subclasses to test whether the copy would succeed without executing
it yet. Derived | 378 // proxy subclasses to test whether the copy would succeed without executing
it yet. Derived |
| 387 // classes must keep this consistent with their implementation of onCopySurf
ace(). The inputs | 379 // classes must keep this consistent with their implementation of onCopySurf
ace(). The inputs |
| 388 // are the same as onCopySurface(), i.e. srcRect and dstPoint are clipped to
be inside the src | 380 // are the same as onCopySurface(), i.e. srcRect and dstPoint are clipped to
be inside the src |
| 389 // and dst bounds. | 381 // and dst bounds. |
| 390 virtual bool canCopySurface(GrSurface* dst, | 382 virtual bool canCopySurface(GrSurface* dst, |
| 391 GrSurface* src, | 383 GrSurface* src, |
| 392 const SkIRect& srcRect, | 384 const SkIRect& srcRect, |
| 393 const SkIPoint& dstPoint) = 0; | 385 const SkIPoint& dstPoint) = 0; |
| 394 | 386 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 413 | 405 |
| 414 /** | 406 /** |
| 415 * Sets source of index data for the next indexed draw. Data does not have | 407 * Sets source of index data for the next indexed draw. Data does not have |
| 416 * to be in the buffer until drawIndexed. | 408 * to be in the buffer until drawIndexed. |
| 417 * | 409 * |
| 418 * @param buffer index buffer containing indices. Must be unlocked | 410 * @param buffer index buffer containing indices. Must be unlocked |
| 419 * before indexed draw call. | 411 * before indexed draw call. |
| 420 */ | 412 */ |
| 421 void setIndexSourceToBuffer(const GrIndexBuffer* buffer); | 413 void setIndexSourceToBuffer(const GrIndexBuffer* buffer); |
| 422 | 414 |
| 423 /** | |
| 424 * Resets vertex source. Drawing from reset vertices is illegal. Set vertex | |
| 425 * source to reserved, array, or buffer before next draw. May be able to fre
e | |
| 426 * up temporary storage allocated by setVertexSourceToArray or | |
| 427 * reserveVertexSpace. | |
| 428 */ | |
| 429 void resetVertexSource(); | |
| 430 | |
| 431 /** | |
| 432 * Resets index source. Indexed Drawing from reset indices is illegal. Set | |
| 433 * index source to reserved, array, or buffer before next indexed draw. May | |
| 434 * be able to free up temporary storage allocated by setIndexSourceToArray | |
| 435 * or reserveIndexSpace. | |
| 436 */ | |
| 437 void resetIndexSource(); | |
| 438 | |
| 439 /** | |
| 440 * Pushes and resets the vertex/index sources. Any reserved vertex / index | |
| 441 * data is finalized (i.e. cannot be updated after the matching pop but can | |
| 442 * be drawn from). Must be balanced by a pop. | |
| 443 */ | |
| 444 void pushGeometrySource(); | |
| 445 | |
| 446 /** | |
| 447 * Pops the vertex / index sources from the matching push. | |
| 448 */ | |
| 449 void popGeometrySource(); | |
| 450 | |
| 451 protected: | 415 protected: |
| 452 DrawType PrimTypeToDrawType(GrPrimitiveType type) { | 416 DrawType PrimTypeToDrawType(GrPrimitiveType type) { |
| 453 switch (type) { | 417 switch (type) { |
| 454 case kTriangles_GrPrimitiveType: | 418 case kTriangles_GrPrimitiveType: |
| 455 case kTriangleStrip_GrPrimitiveType: | 419 case kTriangleStrip_GrPrimitiveType: |
| 456 case kTriangleFan_GrPrimitiveType: | 420 case kTriangleFan_GrPrimitiveType: |
| 457 return kDrawTriangles_DrawType; | 421 return kDrawTriangles_DrawType; |
| 458 case kPoints_GrPrimitiveType: | 422 case kPoints_GrPrimitiveType: |
| 459 return kDrawPoints_DrawType; | 423 return kDrawPoints_DrawType; |
| 460 case kLines_GrPrimitiveType: | 424 case kLines_GrPrimitiveType: |
| 461 case kLineStrip_GrPrimitiveType: | 425 case kLineStrip_GrPrimitiveType: |
| 462 return kDrawLines_DrawType; | 426 return kDrawLines_DrawType; |
| 463 default: | 427 default: |
| 464 SkFAIL("Unexpected primitive type"); | 428 SkFAIL("Unexpected primitive type"); |
| 465 return kDrawTriangles_DrawType; | 429 return kDrawTriangles_DrawType; |
| 466 } | 430 } |
| 467 } | 431 } |
| 468 | 432 |
| 469 // Functions used to map clip-respecting stencil tests into normal | 433 // Functions used to map clip-respecting stencil tests into normal |
| 470 // stencil funcs supported by GPUs. | 434 // stencil funcs supported by GPUs. |
| 471 static GrStencilFunc ConvertStencilFunc(bool stencilInClip, | 435 static GrStencilFunc ConvertStencilFunc(bool stencilInClip, |
| 472 GrStencilFunc func); | 436 GrStencilFunc func); |
| 473 static void ConvertStencilFuncAndMask(GrStencilFunc func, | 437 static void ConvertStencilFuncAndMask(GrStencilFunc func, |
| 474 bool clipInStencil, | 438 bool clipInStencil, |
| 475 unsigned int clipBit, | 439 unsigned int clipBit, |
| 476 unsigned int userBits, | 440 unsigned int userBits, |
| 477 unsigned int* ref, | 441 unsigned int* ref, |
| 478 unsigned int* mask); | 442 unsigned int* mask); |
| 479 | 443 |
| 480 // subclasses must call this in their destructors to ensure all vertex | 444 struct GeometrySrcState { |
| 481 // and index sources have been released (including those held by | 445 GeometrySrcState() : fVertexBuffer(NULL), fIndexBuffer(NULL), fVertexSiz
e(0) {} |
| 482 // pushGeometrySource()) | 446 const GrVertexBuffer* fVertexBuffer; |
| 483 void releaseGeometry(); | 447 const GrIndexBuffer* fIndexBuffer; |
| 448 size_t fVertexSize; |
| 449 }; |
| 484 | 450 |
| 485 // accessors for derived classes | 451 // accessors for derived classes |
| 486 const GrDrawTarget::GeometrySrcState& getGeomSrc() const { return fGeoSrcSta
teStack.back(); } | 452 const GeometrySrcState& getGeomSrc() const { return fGeoSrcState; } |
| 487 | 453 |
| 488 // it is preferable to call this rather than getGeomSrc()->fVertexSize becau
se of the assert. | 454 // it is preferable to call this rather than getGeomSrc()->fVertexSize becau
se of the assert. |
| 489 size_t getVertexSize() const { | 455 size_t getVertexSize() const { |
| 490 // the vertex layout is only valid if a vertex source has been specified
. | 456 // the vertex layout is only valid if a vertex source has been specified
. |
| 491 SkASSERT(this->getGeomSrc().fVertexSrc != GrDrawTarget::kNone_GeometrySr
cType); | 457 SkASSERT(this->getGeomSrc().fVertexBuffer); |
| 492 return this->getGeomSrc().fVertexSize; | 458 return this->getGeomSrc().fVertexSize; |
| 493 } | 459 } |
| 494 | 460 |
| 495 const GrTraceMarkerSet& getActiveTraceMarkers() { return fActiveTraceMarkers
; } | 461 const GrTraceMarkerSet& getActiveTraceMarkers() { return fActiveTraceMarkers
; } |
| 496 | 462 |
| 497 GrContext::GPUStats fGPUStats; | 463 GrContext::GPUStats fGPUStats; |
| 498 | 464 |
| 499 struct GeometryPoolState { | |
| 500 const GrVertexBuffer* fPoolVertexBuffer; | |
| 501 int fPoolStartVertex; | |
| 502 | |
| 503 const GrIndexBuffer* fPoolIndexBuffer; | |
| 504 int fPoolStartIndex; | |
| 505 }; | |
| 506 const GeometryPoolState& getGeomPoolState() { | |
| 507 return fGeomPoolStateStack.back(); | |
| 508 } | |
| 509 | |
| 510 // Helpers for setting up geometry state | |
| 511 void finalizeReservedVertices(); | |
| 512 void finalizeReservedIndices(); | |
| 513 | |
| 514 SkAutoTDelete<GrPathRendering> fPathRendering; | 465 SkAutoTDelete<GrPathRendering> fPathRendering; |
| 515 | 466 |
| 516 // Subclass must initialize this in its constructor. | 467 // Subclass must initialize this in its constructor. |
| 517 SkAutoTUnref<const GrDrawTargetCaps> fCaps; | 468 SkAutoTUnref<const GrDrawTargetCaps> fCaps; |
| 518 | 469 |
| 519 private: | 470 private: |
| 520 // GrDrawTarget overrides | |
| 521 virtual bool onReserveVertexSpace(size_t vertexSize, int vertexCount, void**
vertices); | |
| 522 virtual bool onReserveIndexSpace(int indexCount, void** indices); | |
| 523 virtual void releaseReservedVertexSpace(); | |
| 524 virtual void releaseReservedIndexSpace(); | |
| 525 virtual void geometrySourceWillPush(); | |
| 526 virtual void geometrySourceWillPop(const GrDrawTarget::GeometrySrcState& res
toredState); | |
| 527 | |
| 528 // called when the 3D context state is unknown. Subclass should emit any | 471 // called when the 3D context state is unknown. Subclass should emit any |
| 529 // assumed 3D context state and dirty any state cache. | 472 // assumed 3D context state and dirty any state cache. |
| 530 virtual void onResetContext(uint32_t resetBits) = 0; | 473 virtual void onResetContext(uint32_t resetBits) = 0; |
| 531 | 474 |
| 532 // overridden by backend-specific derived class to create objects. | 475 // overridden by backend-specific derived class to create objects. |
| 533 virtual GrTexture* onCreateTexture(const GrSurfaceDesc& desc, | 476 virtual GrTexture* onCreateTexture(const GrSurfaceDesc& desc, |
| 534 const void* srcData, | 477 const void* srcData, |
| 535 size_t rowBytes) = 0; | 478 size_t rowBytes) = 0; |
| 536 virtual GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, | 479 virtual GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, |
| 537 const void* srcData) = 0; | 480 const void* srcData) = 0; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 int count, | 550 int count, |
| 608 const float transforms[], | 551 const float transforms[], |
| 609 GrDrawTarget::PathTransformType, | 552 GrDrawTarget::PathTransformType, |
| 610 const GrClipMaskManager::ScissorState&, | 553 const GrClipMaskManager::ScissorState&, |
| 611 const GrStencilSettings&, | 554 const GrStencilSettings&, |
| 612 const GrDeviceCoordTexture*); | 555 const GrDeviceCoordTexture*); |
| 613 | 556 |
| 614 virtual void didAddGpuTraceMarker() = 0; | 557 virtual void didAddGpuTraceMarker() = 0; |
| 615 virtual void didRemoveGpuTraceMarker() = 0; | 558 virtual void didRemoveGpuTraceMarker() = 0; |
| 616 | 559 |
| 617 | |
| 618 // readies the pools to provide vertex/index data. | |
| 619 void prepareVertexPool(); | |
| 620 void prepareIndexPool(); | |
| 621 | |
| 622 void resetContext() { | 560 void resetContext() { |
| 623 this->onResetContext(fResetBits); | 561 this->onResetContext(fResetBits); |
| 624 fResetBits = 0; | 562 fResetBits = 0; |
| 625 ++fResetTimestamp; | 563 ++fResetTimestamp; |
| 626 } | 564 } |
| 627 | 565 |
| 628 void handleDirtyContext() { | 566 void handleDirtyContext() { |
| 629 if (fResetBits) { | 567 if (fResetBits) { |
| 630 this->resetContext(); | 568 this->resetContext(); |
| 631 } | 569 } |
| 632 } | 570 } |
| 633 | 571 |
| 634 // called when setting a new vert/idx source to unref prev vb/ib | 572 GeometrySrcState fGeoSrcS
tate; |
| 635 void releasePreviousVertexSource(); | |
| 636 void releasePreviousIndexSource(); | |
| 637 | |
| 638 enum { | |
| 639 kPreallocGeoSrcStateStackCnt = 4, | |
| 640 }; | |
| 641 SkSTArray<kPreallocGeoSrcStateStackCnt, GrDrawTarget::GeometrySrcState, true
> fGeoSrcStateStack; | |
| 642 | |
| 643 enum { | |
| 644 kPreallocGeomPoolStateStackCnt = 4, | |
| 645 }; | |
| 646 SkSTArray<kPreallocGeomPoolStateStackCnt, GeometryPoolState, true> fGeomPoo
lStateStack; | |
| 647 ResetTimestamp fResetTi
mestamp; | 573 ResetTimestamp fResetTi
mestamp; |
| 648 uint32_t fResetBi
ts; | 574 uint32_t fResetBi
ts; |
| 649 GrVertexBufferAllocPool* fVertexP
ool; | |
| 650 GrIndexBufferAllocPool* fIndexPo
ol; | |
| 651 // counts number of uses of vertex/index pool in the geometry stack | |
| 652 int fVertexP
oolUseCnt; | |
| 653 int fIndexPo
olUseCnt; | |
| 654 // these are mutable so they can be created on-demand | 575 // these are mutable so they can be created on-demand |
| 655 mutable GrIndexBuffer* fQuadInd
exBuffer; | 576 mutable GrIndexBuffer* fQuadInd
exBuffer; |
| 656 GrDrawState fDefaultDraw
State; | 577 GrDrawState fDefault
DrawState; |
| 657 GrDrawState* fDrawSta
te; | 578 GrDrawState* fDrawSta
te; |
| 658 // To keep track that we always have at least as many debug marker adds as r
emoves | 579 // To keep track that we always have at least as many debug marker adds as r
emoves |
| 659 int fGpuTrac
eMarkerCount; | 580 int fGpuTrac
eMarkerCount; |
| 660 GrTraceMarkerSet fActiveT
raceMarkers; | 581 GrTraceMarkerSet fActiveT
raceMarkers; |
| 661 GrTraceMarkerSet fStoredT
raceMarkers; | 582 GrTraceMarkerSet fStoredT
raceMarkers; |
| 662 // The context owns us, not vice-versa, so this ptr is not ref'ed by Gpu. | 583 // The context owns us, not vice-versa, so this ptr is not ref'ed by Gpu. |
| 663 GrContext* fContext
; | 584 GrContext* fContext
; |
| 664 | 585 |
| 665 // TODO fix this | 586 // TODO fix this |
| 666 friend class GrInOrderDrawBuffer; | 587 friend class GrInOrderDrawBuffer; |
| 667 | 588 |
| 668 typedef SkRefCnt INHERITED; | 589 typedef SkRefCnt INHERITED; |
| 669 }; | 590 }; |
| 670 | 591 |
| 671 #endif | 592 #endif |
| OLD | NEW |