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 13 matching lines...) Expand all Loading... |
24 #include "SkTypes.h" | 24 #include "SkTypes.h" |
25 #include "SkXfermode.h" | 25 #include "SkXfermode.h" |
26 | 26 |
27 class GrClipData; | 27 class GrClipData; |
28 class GrDrawTargetCaps; | 28 class GrDrawTargetCaps; |
29 class GrPath; | 29 class GrPath; |
30 class GrPathRange; | 30 class GrPathRange; |
31 class GrVertexBuffer; | 31 class GrVertexBuffer; |
32 | 32 |
33 class GrDrawTarget : public SkRefCnt { | 33 class GrDrawTarget : public SkRefCnt { |
34 protected: | |
35 class DrawInfo; | |
36 | |
37 public: | 34 public: |
38 SK_DECLARE_INST_COUNT(GrDrawTarget) | 35 SK_DECLARE_INST_COUNT(GrDrawTarget) |
39 | 36 |
40 | 37 |
41 typedef GrPathRendering::PathTransformType PathTransformType ; | 38 typedef GrPathRendering::PathTransformType PathTransformType ; |
42 | 39 |
43 /////////////////////////////////////////////////////////////////////////// | 40 /////////////////////////////////////////////////////////////////////////// |
44 | 41 |
45 // The context may not be fully constructed and should not be used during Gr
DrawTarget | 42 // The context may not be fully constructed and should not be used during Gr
DrawTarget |
46 // construction. | 43 // construction. |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 */ | 472 */ |
476 virtual void initCopySurfaceDstDesc(const GrSurface* src, GrTextureDesc* des
c); | 473 virtual void initCopySurfaceDstDesc(const GrSurface* src, GrTextureDesc* des
c); |
477 | 474 |
478 | 475 |
479 /** | 476 /** |
480 * Release any resources that are cached but not currently in use. This | 477 * Release any resources that are cached but not currently in use. This |
481 * is intended to give an application some recourse when resources are low. | 478 * is intended to give an application some recourse when resources are low. |
482 */ | 479 */ |
483 virtual void purgeResources() {}; | 480 virtual void purgeResources() {}; |
484 | 481 |
| 482 class DrawInfo; |
| 483 |
485 /** | 484 /** |
486 * For subclass internal use to invoke a call to onDraw(). See DrawInfo belo
w. | 485 * For subclass internal use to invoke a call to onDraw(). See DrawInfo belo
w. |
487 */ | 486 */ |
488 void executeDraw(const DrawInfo& info) { this->onDraw(info); } | 487 void executeDraw(const DrawInfo& info) { this->onDraw(info); } |
489 | 488 |
490 /** | 489 /** |
491 * For subclass internal use to invoke a call to onDrawPath(). | 490 * For subclass internal use to invoke a call to onDrawPath(). |
492 */ | 491 */ |
493 void executeDrawPath(const GrPath* path, SkPath::FillType fill, | 492 void executeDrawPath(const GrPath* path, SkPath::FillType fill, |
494 const GrDeviceCoordTexture* dstCopy) { | 493 const GrDeviceCoordTexture* dstCopy) { |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 bool isIssued() { return fDrawTarget && fDrawTarget->isIssued(fDrawID);
} | 685 bool isIssued() { return fDrawTarget && fDrawTarget->isIssued(fDrawID);
} |
687 | 686 |
688 private: | 687 private: |
689 GrDrawTarget* fDrawTarget; | 688 GrDrawTarget* fDrawTarget; |
690 uint32_t fDrawID; // this may wrap, but we're doing direct compa
rison | 689 uint32_t fDrawID; // this may wrap, but we're doing direct compa
rison |
691 // so that should be okay | 690 // so that should be okay |
692 }; | 691 }; |
693 | 692 |
694 virtual DrawToken getCurrentDrawToken() { return DrawToken(this, 0); } | 693 virtual DrawToken getCurrentDrawToken() { return DrawToken(this, 0); } |
695 | 694 |
| 695 /** |
| 696 * Used to communicate draws to subclass's onDraw function. |
| 697 * TODO move to its own .h file |
| 698 */ |
| 699 class DrawInfo { |
| 700 public: |
| 701 DrawInfo(const DrawInfo& di) { (*this) = di; } |
| 702 DrawInfo& operator =(const DrawInfo& di); |
| 703 |
| 704 GrPrimitiveType primitiveType() const { return fPrimitiveType; } |
| 705 int startVertex() const { return fStartVertex; } |
| 706 int startIndex() const { return fStartIndex; } |
| 707 int vertexCount() const { return fVertexCount; } |
| 708 int indexCount() const { return fIndexCount; } |
| 709 int verticesPerInstance() const { return fVerticesPerInstance; } |
| 710 int indicesPerInstance() const { return fIndicesPerInstance; } |
| 711 int instanceCount() const { return fInstanceCount; } |
| 712 |
| 713 bool isIndexed() const { return fIndexCount > 0; } |
| 714 #ifdef SK_DEBUG |
| 715 bool isInstanced() const; // this version is longer because of asserts |
| 716 #else |
| 717 bool isInstanced() const { return fInstanceCount > 0; } |
| 718 #endif |
| 719 |
| 720 // adds or remove instances |
| 721 void adjustInstanceCount(int instanceOffset); |
| 722 // shifts the start vertex |
| 723 void adjustStartVertex(int vertexOffset); |
| 724 // shifts the start index |
| 725 void adjustStartIndex(int indexOffset); |
| 726 |
| 727 void setDevBounds(const SkRect& bounds) { |
| 728 fDevBoundsStorage = bounds; |
| 729 fDevBounds = &fDevBoundsStorage; |
| 730 } |
| 731 const SkRect* getDevBounds() const { return fDevBounds; } |
| 732 |
| 733 // NULL if no copy of the dst is needed for the draw. |
| 734 const GrDeviceCoordTexture* getDstCopy() const { |
| 735 if (fDstCopy.texture()) { |
| 736 return &fDstCopy; |
| 737 } else { |
| 738 return NULL; |
| 739 } |
| 740 } |
| 741 |
| 742 // The state of the scissor is controlled by the clip manager, no one el
se should set |
| 743 // Scissor state |
| 744 struct ScissorState { |
| 745 ScissorState() : fEnabled(false) {} |
| 746 bool fEnabled; |
| 747 SkIRect fRect; |
| 748 }; |
| 749 |
| 750 /** |
| 751 * These methods are called by the clip manager's setupClipping function |
| 752 * which (called as part of GrGpu's implementation of onDraw and |
| 753 * onStencilPath member functions.) The GrGpu subclass should flush the |
| 754 * stencil state to the 3D API in its implementation of flushGraphicsSta
te. |
| 755 */ |
| 756 void enableScissor(const SkIRect& rect) { |
| 757 fScissorState.fEnabled = true; |
| 758 fScissorState.fRect = rect; |
| 759 } |
| 760 void disableScissor() { fScissorState.fEnabled = false; } |
| 761 |
| 762 const ScissorState& getScissor() const { return fScissorState; } |
| 763 |
| 764 private: |
| 765 DrawInfo() { fDevBounds = NULL; } |
| 766 |
| 767 friend class GrDrawTarget; |
| 768 // TODO make this its own class with setters and getters |
| 769 friend class GrGpu; |
| 770 |
| 771 GrPrimitiveType fPrimitiveType; |
| 772 |
| 773 int fStartVertex; |
| 774 int fStartIndex; |
| 775 int fVertexCount; |
| 776 int fIndexCount; |
| 777 |
| 778 int fInstanceCount; |
| 779 int fVerticesPerInstance; |
| 780 int fIndicesPerInstance; |
| 781 |
| 782 SkRect fDevBoundsStorage; |
| 783 SkRect* fDevBounds; |
| 784 |
| 785 GrDeviceCoordTexture fDstCopy; |
| 786 |
| 787 ScissorState fScissorState; |
| 788 }; |
| 789 |
696 protected: | 790 protected: |
697 // Extend access to GrDrawState::convertToPEndeingExec to subclasses. | 791 // Extend access to GrDrawState::convertToPEndeingExec to subclasses. |
698 void convertDrawStateToPendingExec(GrDrawState* ds) { | 792 void convertDrawStateToPendingExec(GrDrawState* ds) { |
699 ds->convertToPendingExec(); | 793 ds->convertToPendingExec(); |
700 } | 794 } |
701 | 795 |
702 enum GeometrySrcType { | 796 enum GeometrySrcType { |
703 kNone_GeometrySrcType, //<! src has not been specified | 797 kNone_GeometrySrcType, //<! src has not been specified |
704 kReserved_GeometrySrcType, //<! src was set using reserve*Space | 798 kReserved_GeometrySrcType, //<! src was set using reserve*Space |
705 kArray_GeometrySrcType, //<! src was set using set*SourceToArray | 799 kArray_GeometrySrcType, //<! src was set using set*SourceToArray |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
780 // the vertex layout is only valid if a vertex source has been specified
. | 874 // the vertex layout is only valid if a vertex source has been specified
. |
781 SkASSERT(this->getGeomSrc().fVertexSrc != kNone_GeometrySrcType); | 875 SkASSERT(this->getGeomSrc().fVertexSrc != kNone_GeometrySrcType); |
782 return this->getGeomSrc().fVertexSize; | 876 return this->getGeomSrc().fVertexSize; |
783 } | 877 } |
784 | 878 |
785 // Subclass must initialize this in its constructor. | 879 // Subclass must initialize this in its constructor. |
786 SkAutoTUnref<const GrDrawTargetCaps> fCaps; | 880 SkAutoTUnref<const GrDrawTargetCaps> fCaps; |
787 | 881 |
788 const GrTraceMarkerSet& getActiveTraceMarkers() { return fActiveTraceMarkers
; } | 882 const GrTraceMarkerSet& getActiveTraceMarkers() { return fActiveTraceMarkers
; } |
789 | 883 |
790 /** | |
791 * Used to communicate draws to subclass's onDraw function. | |
792 */ | |
793 class DrawInfo { | |
794 public: | |
795 DrawInfo(const DrawInfo& di) { (*this) = di; } | |
796 DrawInfo& operator =(const DrawInfo& di); | |
797 | |
798 GrPrimitiveType primitiveType() const { return fPrimitiveType; } | |
799 int startVertex() const { return fStartVertex; } | |
800 int startIndex() const { return fStartIndex; } | |
801 int vertexCount() const { return fVertexCount; } | |
802 int indexCount() const { return fIndexCount; } | |
803 int verticesPerInstance() const { return fVerticesPerInstance; } | |
804 int indicesPerInstance() const { return fIndicesPerInstance; } | |
805 int instanceCount() const { return fInstanceCount; } | |
806 | |
807 bool isIndexed() const { return fIndexCount > 0; } | |
808 #ifdef SK_DEBUG | |
809 bool isInstanced() const; // this version is longer because of asserts | |
810 #else | |
811 bool isInstanced() const { return fInstanceCount > 0; } | |
812 #endif | |
813 | |
814 // adds or remove instances | |
815 void adjustInstanceCount(int instanceOffset); | |
816 // shifts the start vertex | |
817 void adjustStartVertex(int vertexOffset); | |
818 // shifts the start index | |
819 void adjustStartIndex(int indexOffset); | |
820 | |
821 void setDevBounds(const SkRect& bounds) { | |
822 fDevBoundsStorage = bounds; | |
823 fDevBounds = &fDevBoundsStorage; | |
824 } | |
825 const SkRect* getDevBounds() const { return fDevBounds; } | |
826 | |
827 // NULL if no copy of the dst is needed for the draw. | |
828 const GrDeviceCoordTexture* getDstCopy() const { | |
829 if (fDstCopy.texture()) { | |
830 return &fDstCopy; | |
831 } else { | |
832 return NULL; | |
833 } | |
834 } | |
835 | |
836 private: | |
837 DrawInfo() { fDevBounds = NULL; } | |
838 | |
839 friend class GrDrawTarget; | |
840 | |
841 GrPrimitiveType fPrimitiveType; | |
842 | |
843 int fStartVertex; | |
844 int fStartIndex; | |
845 int fVertexCount; | |
846 int fIndexCount; | |
847 | |
848 int fInstanceCount; | |
849 int fVerticesPerInstance; | |
850 int fIndicesPerInstance; | |
851 | |
852 SkRect fDevBoundsStorage; | |
853 SkRect* fDevBounds; | |
854 | |
855 GrDeviceCoordTexture fDstCopy; | |
856 }; | |
857 | |
858 // Makes a copy of the dst if it is necessary for the draw. Returns false if
a copy is required | 884 // Makes a copy of the dst if it is necessary for the draw. Returns false if
a copy is required |
859 // but couldn't be made. Otherwise, returns true. This method needs to be p
rotected because it | 885 // but couldn't be made. Otherwise, returns true. This method needs to be p
rotected because it |
860 // needs to be accessed by GLPrograms to setup a correct drawstate | 886 // needs to be accessed by GLPrograms to setup a correct drawstate |
861 bool setupDstReadIfNecessary(DrawInfo* info) { | 887 bool setupDstReadIfNecessary(DrawInfo* info) { |
862 return this->setupDstReadIfNecessary(&info->fDstCopy, info->getDevBounds
()); | 888 return this->setupDstReadIfNecessary(&info->fDstCopy, info->getDevBounds
()); |
863 } | 889 } |
864 bool setupDstReadIfNecessary(GrDeviceCoordTexture* dstCopy, const SkRect* dr
awBounds); | 890 bool setupDstReadIfNecessary(GrDeviceCoordTexture* dstCopy, const SkRect* dr
awBounds); |
865 | 891 |
866 private: | 892 private: |
867 // A subclass can optionally overload this function to be notified before | 893 // A subclass can optionally overload this function to be notified before |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
935 GrContext* fContext; | 961 GrContext* fContext; |
936 // To keep track that we always have at least as many debug marker adds as r
emoves | 962 // To keep track that we always have at least as many debug marker adds as r
emoves |
937 int fGpuTraceMar
kerCount; | 963 int fGpuTraceMar
kerCount; |
938 GrTraceMarkerSet fActiveTrace
Markers; | 964 GrTraceMarkerSet fActiveTrace
Markers; |
939 GrTraceMarkerSet fStoredTrace
Markers; | 965 GrTraceMarkerSet fStoredTrace
Markers; |
940 | 966 |
941 typedef SkRefCnt INHERITED; | 967 typedef SkRefCnt INHERITED; |
942 }; | 968 }; |
943 | 969 |
944 #endif | 970 #endif |
OLD | NEW |