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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 * out: a hint about the number of indices that can be | 194 * out: a hint about the number of indices that can be |
195 * allocated cheaply. Negative means no hint. | 195 * allocated cheaply. Negative means no hint. |
196 * Ignored if NULL. | 196 * Ignored if NULL. |
197 * | 197 * |
198 * @return true if target should be flushed based on the input values. | 198 * @return true if target should be flushed based on the input values. |
199 */ | 199 */ |
200 virtual bool geometryHints(int* vertexCount, | 200 virtual bool geometryHints(int* vertexCount, |
201 int* indexCount) const; | 201 int* indexCount) const; |
202 | 202 |
203 /** | 203 /** |
204 * Sets source of vertex data for the next draw. Array must contain | |
205 * the vertex data when this is called. | |
206 * | |
207 * @param vertexArray cpu array containing vertex data. | |
208 * @param vertexCount the number of vertices in the array. Vertex size is | |
209 * queried from the current GrDrawState. | |
210 */ | |
211 void setVertexSourceToArray(const void* vertexArray, int vertexCount); | |
212 | |
213 /** | |
214 * Sets source of index data for the next indexed draw. Array must contain | |
215 * the indices when this is called. | |
216 * | |
217 * @param indexArray cpu array containing index data. | |
218 * @param indexCount the number of indices in the array. | |
219 */ | |
220 void setIndexSourceToArray(const void* indexArray, int indexCount); | |
221 | |
222 /** | |
223 * Sets source of vertex data for the next draw. Data does not have to be | 204 * Sets source of vertex data for the next draw. Data does not have to be |
224 * in the buffer until drawIndexed, drawNonIndexed, or drawIndexedInstances. | 205 * in the buffer until drawIndexed, drawNonIndexed, or drawIndexedInstances. |
225 * | 206 * |
226 * @param buffer vertex buffer containing vertex data. Must be | 207 * @param buffer vertex buffer containing vertex data. Must be |
227 * unlocked before draw call. Vertex size is queried | 208 * unlocked before draw call. Vertex size is queried |
228 * from current GrDrawState. | 209 * from current GrDrawState. |
229 */ | 210 */ |
230 void setVertexSourceToBuffer(const GrVertexBuffer* buffer); | 211 void setVertexSourceToBuffer(const GrVertexBuffer* buffer); |
231 | 212 |
232 /** | 213 /** |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 | 674 |
694 protected: | 675 protected: |
695 // Extend access to GrDrawState::convertToPEndeingExec to subclasses. | 676 // Extend access to GrDrawState::convertToPEndeingExec to subclasses. |
696 void convertDrawStateToPendingExec(GrDrawState* ds) { | 677 void convertDrawStateToPendingExec(GrDrawState* ds) { |
697 ds->convertToPendingExec(); | 678 ds->convertToPendingExec(); |
698 } | 679 } |
699 | 680 |
700 enum GeometrySrcType { | 681 enum GeometrySrcType { |
701 kNone_GeometrySrcType, //<! src has not been specified | 682 kNone_GeometrySrcType, //<! src has not been specified |
702 kReserved_GeometrySrcType, //<! src was set using reserve*Space | 683 kReserved_GeometrySrcType, //<! src was set using reserve*Space |
703 kArray_GeometrySrcType, //<! src was set using set*SourceToArray | |
704 kBuffer_GeometrySrcType //<! src was set using set*SourceToBuffer | 684 kBuffer_GeometrySrcType //<! src was set using set*SourceToBuffer |
705 }; | 685 }; |
706 | 686 |
707 struct GeometrySrcState { | 687 struct GeometrySrcState { |
708 GeometrySrcType fVertexSrc; | 688 GeometrySrcType fVertexSrc; |
709 union { | 689 union { |
710 // valid if src type is buffer | 690 // valid if src type is buffer |
711 const GrVertexBuffer* fVertexBuffer; | 691 const GrVertexBuffer* fVertexBuffer; |
712 // valid if src type is reserved or array | 692 // valid if src type is reserved or array |
713 int fVertexCount; | 693 int fVertexCount; |
714 }; | 694 }; |
715 | 695 |
716 GeometrySrcType fIndexSrc; | 696 GeometrySrcType fIndexSrc; |
717 union { | 697 union { |
718 // valid if src type is buffer | 698 // valid if src type is buffer |
719 const GrIndexBuffer* fIndexBuffer; | 699 const GrIndexBuffer* fIndexBuffer; |
720 // valid if src type is reserved or array | 700 // valid if src type is reserved or array |
721 int fIndexCount; | 701 int fIndexCount; |
722 }; | 702 }; |
723 | 703 |
724 size_t fVertexSize; | 704 size_t fVertexSize; |
725 }; | 705 }; |
726 | 706 |
727 int indexCountInCurrentSource() const { | 707 int indexCountInCurrentSource() const { |
728 const GeometrySrcState& src = this->getGeomSrc(); | 708 const GeometrySrcState& src = this->getGeomSrc(); |
729 switch (src.fIndexSrc) { | 709 switch (src.fIndexSrc) { |
730 case kNone_GeometrySrcType: | 710 case kNone_GeometrySrcType: |
731 return 0; | 711 return 0; |
732 case kReserved_GeometrySrcType: | 712 case kReserved_GeometrySrcType: |
733 case kArray_GeometrySrcType: | |
734 return src.fIndexCount; | 713 return src.fIndexCount; |
735 case kBuffer_GeometrySrcType: | 714 case kBuffer_GeometrySrcType: |
736 return static_cast<int>(src.fIndexBuffer->gpuMemorySize() / size
of(uint16_t)); | 715 return static_cast<int>(src.fIndexBuffer->gpuMemorySize() / size
of(uint16_t)); |
737 default: | 716 default: |
738 SkFAIL("Unexpected Index Source."); | 717 SkFAIL("Unexpected Index Source."); |
739 return 0; | 718 return 0; |
740 } | 719 } |
741 } | 720 } |
742 | 721 |
743 // This method is called by copySurface The srcRect is guaranteed to be ent
irely within the | 722 // This method is called by copySurface The srcRect is guaranteed to be ent
irely within the |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
865 // A subclass can optionally overload this function to be notified before | 844 // A subclass can optionally overload this function to be notified before |
866 // vertex and index space is reserved. | 845 // vertex and index space is reserved. |
867 virtual void willReserveVertexAndIndexSpace(int vertexCount, int indexCount)
{} | 846 virtual void willReserveVertexAndIndexSpace(int vertexCount, int indexCount)
{} |
868 | 847 |
869 // implemented by subclass to allocate space for reserved geom | 848 // implemented by subclass to allocate space for reserved geom |
870 virtual bool onReserveVertexSpace(size_t vertexSize, int vertexCount, void**
vertices) = 0; | 849 virtual bool onReserveVertexSpace(size_t vertexSize, int vertexCount, void**
vertices) = 0; |
871 virtual bool onReserveIndexSpace(int indexCount, void** indices) = 0; | 850 virtual bool onReserveIndexSpace(int indexCount, void** indices) = 0; |
872 // implemented by subclass to handle release of reserved geom space | 851 // implemented by subclass to handle release of reserved geom space |
873 virtual void releaseReservedVertexSpace() = 0; | 852 virtual void releaseReservedVertexSpace() = 0; |
874 virtual void releaseReservedIndexSpace() = 0; | 853 virtual void releaseReservedIndexSpace() = 0; |
875 // subclass must consume array contents when set | |
876 virtual void onSetVertexSourceToArray(const void* vertexArray, int vertexCou
nt) = 0; | |
877 virtual void onSetIndexSourceToArray(const void* indexArray, int indexCount)
= 0; | |
878 // subclass is notified that geom source will be set away from an array | |
879 virtual void releaseVertexArray() = 0; | |
880 virtual void releaseIndexArray() = 0; | |
881 // subclass overrides to be notified just before geo src state is pushed/pop
ped. | 854 // subclass overrides to be notified just before geo src state is pushed/pop
ped. |
882 virtual void geometrySourceWillPush() = 0; | 855 virtual void geometrySourceWillPush() = 0; |
883 virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) =
0; | 856 virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) =
0; |
884 // subclass called to perform drawing | 857 // subclass called to perform drawing |
885 virtual void onDraw(const DrawInfo&) = 0; | 858 virtual void onDraw(const DrawInfo&) = 0; |
886 // Implementation of drawRect. The geometry src and vertex attribs will alre
ady | 859 // Implementation of drawRect. The geometry src and vertex attribs will alre
ady |
887 // be saved before this is called and restored afterwards. A subclass may ov
erride | 860 // be saved before this is called and restored afterwards. A subclass may ov
erride |
888 // this to perform more optimal rect rendering. Its draws should be funneled
through | 861 // this to perform more optimal rect rendering. Its draws should be funneled
through |
889 // one of the public GrDrawTarget draw methods (e.g. drawNonIndexed, | 862 // one of the public GrDrawTarget draw methods (e.g. drawNonIndexed, |
890 // drawIndexedInstances, ...). The base class draws a two triangle fan using | 863 // drawIndexedInstances, ...). The base class draws a two triangle fan using |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
976 protected: | 949 protected: |
977 GrClipMaskManager fClipMaskManager; | 950 GrClipMaskManager fClipMaskManager; |
978 | 951 |
979 private: | 952 private: |
980 GrClipMaskManager* getClipMaskManager() { return &fClipMaskManager; } | 953 GrClipMaskManager* getClipMaskManager() { return &fClipMaskManager; } |
981 | 954 |
982 typedef GrDrawTarget INHERITED; | 955 typedef GrDrawTarget INHERITED; |
983 }; | 956 }; |
984 | 957 |
985 #endif | 958 #endif |
OLD | NEW |