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 |
11 #include "GrClipData.h" | 11 #include "GrClipData.h" |
12 #include "GrDrawState.h" | 12 #include "GrDrawState.h" |
13 #include "GrIndexBuffer.h" | 13 #include "GrIndexBuffer.h" |
14 | 14 |
15 #include "SkClipStack.h" | 15 #include "SkClipStack.h" |
16 #include "SkMatrix.h" | 16 #include "SkMatrix.h" |
17 #include "SkPath.h" | 17 #include "SkPath.h" |
18 #include "SkTArray.h" | 18 #include "SkTArray.h" |
19 #include "SkTLazy.h" | 19 #include "SkTLazy.h" |
20 #include "SkTypes.h" | 20 #include "SkTypes.h" |
21 #include "SkXfermode.h" | 21 #include "SkXfermode.h" |
22 | 22 |
23 class GrClipData; | 23 class GrClipData; |
24 class GrDrawTargetCaps; | 24 class GrDrawTargetCaps; |
25 // class GrDrawTarget; | |
bsalomon
2014/03/17 17:50:38
?
egdaniel
2014/03/17 19:49:12
Woops. Left over from some old test iteration. Rem
| |
25 class GrPath; | 26 class GrPath; |
26 class GrVertexBuffer; | 27 class GrVertexBuffer; |
27 class SkStrokeRec; | 28 class SkStrokeRec; |
28 | 29 |
30 class GpuTraceMarker { | |
31 public: | |
32 GpuTraceMarker(const char* marker, int idCounter) : fMarker(marker), fID(idC ounter) {} | |
33 | |
34 bool operator<(const GpuTraceMarker& rhs) const { | |
35 return this->fMarker < rhs.fMarker || (this->fMarker == rhs.fMarker && t his->fID < rhs.fID); | |
36 } | |
37 | |
38 bool operator==(const GpuTraceMarker& rhs) const { | |
39 return (this->fID == rhs.fID && this->fMarker == rhs.fMarker); | |
40 } | |
41 | |
42 const char* fMarker; | |
43 int fID; | |
44 }; | |
45 | |
29 class GrDrawTarget : public SkRefCnt { | 46 class GrDrawTarget : public SkRefCnt { |
30 protected: | 47 protected: |
31 class DrawInfo; | 48 class DrawInfo; |
32 | 49 |
33 public: | 50 public: |
34 SK_DECLARE_INST_COUNT(GrDrawTarget) | 51 SK_DECLARE_INST_COUNT(GrDrawTarget) |
35 | 52 |
36 /////////////////////////////////////////////////////////////////////////// | 53 /////////////////////////////////////////////////////////////////////////// |
37 | 54 |
38 // The context may not be fully constructed and should not be used during Gr DrawTarget | 55 // The context may not be fully constructed and should not be used during Gr DrawTarget |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
416 * clip and all other draw state (blend mode, stages, etc). Clears the | 433 * clip and all other draw state (blend mode, stages, etc). Clears the |
417 * whole thing if rect is NULL, otherwise just the rect. If canIgnoreRect | 434 * whole thing if rect is NULL, otherwise just the rect. If canIgnoreRect |
418 * is set then the entire render target can be optionally cleared. | 435 * is set then the entire render target can be optionally cleared. |
419 */ | 436 */ |
420 virtual void clear(const SkIRect* rect, | 437 virtual void clear(const SkIRect* rect, |
421 GrColor color, | 438 GrColor color, |
422 bool canIgnoreRect, | 439 bool canIgnoreRect, |
423 GrRenderTarget* renderTarget = NULL) = 0; | 440 GrRenderTarget* renderTarget = NULL) = 0; |
424 | 441 |
425 /** | 442 /** |
426 * instantGpuTraceEvent places a single "sign post" type marker into command stream. The | 443 * Called at start and end of gpu trace marking |
427 * argument marker will be the name of the annotation that is added. | 444 * GR_CREATE_GPU_TRACE_MARKER(marker_str, target) will automatically call th ese at the start |
445 * and end of a code block respectively | |
428 */ | 446 */ |
429 void instantGpuTraceEvent(const char* marker); | 447 void addGpuTraceMarker(GpuTraceMarker* marker); |
430 /** | 448 void removeGpuTraceMarker(GpuTraceMarker* marker); |
431 * The following two functions are used for marking groups of commands. Use pushGpuTraceEvent | 449 |
432 * to set the beginning of a command set, and popGpuTraceEvent is be called at end of the | 450 bool gpuTracingEnabled() const; |
bsalomon
2014/03/17 17:50:38
I wonder if we really need enable/disable control
egdaniel
2014/03/17 19:49:12
This function is for controlling whether or not it
bsalomon
2014/03/19 13:28:44
sgtm
| |
433 * command set. The argument marker is the name for the annotation that is a dded. The push and | 451 |
434 * pops can be used hierarchically, but every push must have a match pop. | 452 SkTDArray<GpuTraceMarker>* getActiveTraceMarkers() { return &fActiveTraceMar kers; } |
bsalomon
2014/03/17 17:50:38
const &?
egdaniel
2014/03/17 19:49:12
in gl/GrGpuGl.cpp I call getActiveTraceMarkers(),
| |
435 */ | 453 |
436 void pushGpuTraceEvent(const char* marker); | 454 static SkString getTraceString(SkTDArray<GpuTraceMarker>* markerArray, |
bsalomon
2014/03/17 17:50:38
Def. const & for markerArray. Also static function
egdaniel
2014/03/17 19:49:12
markerArray ends up getting sorted in the function
bsalomon
2014/03/19 13:28:44
Ok that makes sense. It'd be nice to hide this som
egdaniel
2014/03/19 14:27:03
So the function has already been moved to protecte
bsalomon
2014/03/19 14:43:43
It just seems to me like sorting-and-stringifying
egdaniel
2014/03/19 15:16:30
Okay so here is my proposal (GpuTM is our trace ma
bsalomon
2014/03/19 15:27:01
How about getActiveMarkersTraceString()?
egdaniel
2014/03/19 15:33:53
So internally I have a single array that stores th
bsalomon
2014/03/19 15:50:39
Got it. Do you think you get a lot of value out of
| |
437 void popGpuTraceEvent(); | 455 int startIdx, int numMarkers); |
438 | 456 |
439 /** | 457 /** |
440 * Copies a pixel rectangle from one surface to another. This call may final ize | 458 * Copies a pixel rectangle from one surface to another. This call may final ize |
441 * reserved vertex/index data (as though a draw call was made). The src pixe ls | 459 * reserved vertex/index data (as though a draw call was made). The src pixe ls |
442 * copied are specified by srcRect. They are copied to a rect of the same | 460 * copied are specified by srcRect. They are copied to a rect of the same |
443 * size in dst with top left at dstPoint. If the src rect is clipped by the | 461 * size in dst with top left at dstPoint. If the src rect is clipped by the |
444 * src bounds then pixel values in the dst rect corresponding to area clipp ed | 462 * src bounds then pixel values in the dst rect corresponding to area clipp ed |
445 * by the src rect are not overwritten. This method can fail and return fals e | 463 * by the src rect are not overwritten. This method can fail and return fals e |
446 * depending on the type of surface, configs, etc, and the backend-specific | 464 * depending on the type of surface, configs, etc, and the backend-specific |
447 * limitations. If rect is clipped out entirely by the src or dst bounds the n | 465 * limitations. If rect is clipped out entirely by the src or dst bounds the n |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
861 // drawNonIndexed from reserved vertex space. | 879 // drawNonIndexed from reserved vertex space. |
862 virtual void onDrawRect(const SkRect& rect, | 880 virtual void onDrawRect(const SkRect& rect, |
863 const SkMatrix* matrix, | 881 const SkMatrix* matrix, |
864 const SkRect* localRect, | 882 const SkRect* localRect, |
865 const SkMatrix* localMatrix); | 883 const SkMatrix* localMatrix); |
866 | 884 |
867 virtual void onStencilPath(const GrPath*, SkPath::FillType) = 0; | 885 virtual void onStencilPath(const GrPath*, SkPath::FillType) = 0; |
868 virtual void onDrawPath(const GrPath*, SkPath::FillType, | 886 virtual void onDrawPath(const GrPath*, SkPath::FillType, |
869 const GrDeviceCoordTexture* dstCopy) = 0; | 887 const GrDeviceCoordTexture* dstCopy) = 0; |
870 | 888 |
871 virtual void onInstantGpuTraceEvent(const char* marker) = 0; | 889 virtual void onAddGpuTraceMarker() = 0; |
bsalomon
2014/03/17 17:50:38
It's unclear from the header why we have all three
egdaniel
2014/03/17 19:49:12
So the basic structure here is: addGpuTraceMarker
bsalomon
2014/03/19 13:28:44
Ok so addTraceMarkerActiveSet is just a helper/imp
| |
872 virtual void onPushGpuTraceEvent(const char* marker) = 0; | 890 virtual void onRemoveGpuTraceMarker() = 0; |
873 virtual void onPopGpuTraceEvent() = 0; | |
874 | 891 |
875 // helpers for reserving vertex and index space. | 892 // helpers for reserving vertex and index space. |
876 bool reserveVertexSpace(size_t vertexSize, | 893 bool reserveVertexSpace(size_t vertexSize, |
877 int vertexCount, | 894 int vertexCount, |
878 void** vertices); | 895 void** vertices); |
879 bool reserveIndexSpace(int indexCount, void** indices); | 896 bool reserveIndexSpace(int indexCount, void** indices); |
880 | 897 |
881 // called by drawIndexed and drawNonIndexed. Use a negative indexCount to | 898 // called by drawIndexed and drawNonIndexed. Use a negative indexCount to |
882 // indicate non-indexed drawing. | 899 // indicate non-indexed drawing. |
883 bool checkDraw(GrPrimitiveType type, int startVertex, | 900 bool checkDraw(GrPrimitiveType type, int startVertex, |
884 int startIndex, int vertexCount, | 901 int startIndex, int vertexCount, |
885 int indexCount) const; | 902 int indexCount) const; |
886 // called when setting a new vert/idx source to unref prev vb/ib | 903 // called when setting a new vert/idx source to unref prev vb/ib |
887 void releasePreviousVertexSource(); | 904 void releasePreviousVertexSource(); |
888 void releasePreviousIndexSource(); | 905 void releasePreviousIndexSource(); |
889 | 906 |
890 // Makes a copy of the dst if it is necessary for the draw. Returns false if a copy is required | 907 // Makes a copy of the dst if it is necessary for the draw. Returns false if a copy is required |
891 // but couldn't be made. Otherwise, returns true. | 908 // but couldn't be made. Otherwise, returns true. |
892 bool setupDstReadIfNecessary(DrawInfo* info) { | 909 bool setupDstReadIfNecessary(DrawInfo* info) { |
893 return this->setupDstReadIfNecessary(&info->fDstCopy, info->getDevBounds ()); | 910 return this->setupDstReadIfNecessary(&info->fDstCopy, info->getDevBounds ()); |
894 } | 911 } |
895 bool setupDstReadIfNecessary(GrDeviceCoordTexture* dstCopy, const SkRect* dr awBounds); | 912 bool setupDstReadIfNecessary(GrDeviceCoordTexture* dstCopy, const SkRect* dr awBounds); |
896 | 913 |
897 // Check to see if this set of draw commands has been sent out | 914 // Check to see if this set of draw commands has been sent out |
898 virtual bool isIssued(uint32_t drawID) { return true; } | 915 virtual bool isIssued(uint32_t drawID) { return true; } |
899 | 916 |
917 // Add new marker to our current active set | |
918 void addTraceMarkerActiveSet(GpuTraceMarker* marker); | |
919 | |
920 // Remove marker from our current active set | |
921 void removeTraceMarkerActiveSet(GpuTraceMarker* marker); | |
922 | |
900 enum { | 923 enum { |
901 kPreallocGeoSrcStateStackCnt = 4, | 924 kPreallocGeoSrcStateStackCnt = 4, |
902 }; | 925 }; |
903 SkSTArray<kPreallocGeoSrcStateStackCnt, GeometrySrcState, true> fGeoSrcState Stack; | 926 SkSTArray<kPreallocGeoSrcStateStackCnt, GeometrySrcState, true> fGeoSrcState Stack; |
904 const GrClipData* fClip; | 927 const GrClipData* fClip; |
905 GrDrawState* fDrawState; | 928 GrDrawState* fDrawState; |
906 GrDrawState fDefaultDraw State; | 929 GrDrawState fDefaultDraw State; |
907 // The context owns us, not vice-versa, so this ptr is not ref'ed by DrawTar get. | 930 // The context owns us, not vice-versa, so this ptr is not ref'ed by DrawTar get. |
908 GrContext* fContext; | 931 GrContext* fContext; |
909 // To keep track that we always have at least as many debug marker pushes as pops | 932 // To keep track that we always have at least as many debug marker adds as r emoves |
910 int fPushGpuTrac eCount; | 933 int fGpuTraceMar kerCount; |
934 SkTDArray<GpuTraceMarker> fActiveTraceMarkers; | |
911 | 935 |
912 typedef SkRefCnt INHERITED; | 936 typedef SkRefCnt INHERITED; |
913 }; | 937 }; |
914 | 938 |
939 /** | |
940 * Marker generation class used for adding and removing markers around code bloc ks | |
941 */ | |
942 class TraceMarkerGenerator : public ::SkNoncopyable { | |
943 public: | |
944 TraceMarkerGenerator(const char* marker_str, int* marker_counter, GrDrawTarg et* target) | |
945 : fTarget(target), fTraceMarker(marker_str, *marker_counter) { | |
946 if (fTarget->gpuTracingEnabled()) { | |
947 sk_atomic_inc(marker_counter); | |
948 fTarget->addGpuTraceMarker(&fTraceMarker); | |
949 } | |
950 } | |
951 ~TraceMarkerGenerator() { | |
952 if (fTarget->gpuTracingEnabled()) { | |
953 fTarget->removeGpuTraceMarker(&fTraceMarker); | |
954 } | |
955 } | |
956 private: | |
957 GrDrawTarget* fTarget; | |
958 GpuTraceMarker fTraceMarker; | |
959 }; | |
960 | |
961 ////////// macros to place around the internal draw calls ////////////////// | |
962 // marker is of type const char* and target is of type GrDrawTarget* | |
963 | |
964 #define GR_CREATE_GPU_TRACE_MARKER(marker_str, target) \ | |
965 static const char* static_str = marker_str; \ | |
966 static int marker_counter = 0; \ | |
967 TraceMarkerGenerator SK_MACRO_APPEND_LINE(TMG)(static_str, \ | |
968 &marker_counter, \ | |
969 target); \ | |
970 | |
971 //////////////////////////////////////////////////////////////////////////// | |
972 | |
973 | |
915 #endif | 974 #endif |
OLD | NEW |