Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(543)

Side by Side Diff: src/gpu/GrBatch.h

Issue 1276913002: Add Batch logging (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/gpu/GrBatch.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 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 GrBatch_DEFINED 8 #ifndef GrBatch_DEFINED
9 #define GrBatch_DEFINED 9 #define GrBatch_DEFINED
10 10
(...skipping 18 matching lines...) Expand all
29 * 29 *
30 * Batches are created when GrContext processes a draw call. Batches of the same subclass may be 30 * Batches are created when GrContext processes a draw call. Batches of the same subclass may be
31 * merged using combineIfPossible. When two batches merge, one takes on the unio n of the data 31 * merged using combineIfPossible. When two batches merge, one takes on the unio n of the data
32 * and the other is left empty. The merged batch becomes responsible for drawing the data from both 32 * and the other is left empty. The merged batch becomes responsible for drawing the data from both
33 * the original batches. 33 * the original batches.
34 * 34 *
35 * If there are any possible optimizations which might require knowing more abou t the full state of 35 * If there are any possible optimizations which might require knowing more abou t the full state of
36 * the draw, ie whether or not the GrBatch is allowed to tweak alpha for coverag e, then this 36 * the draw, ie whether or not the GrBatch is allowed to tweak alpha for coverag e, then this
37 * information will be communicated to the GrBatch prior to geometry generation. 37 * information will be communicated to the GrBatch prior to geometry generation.
38 */ 38 */
39 #define GR_BATCH_SPEW 0
40 #if GR_BATCH_SPEW
41 #define GrBATCH_INFO(...) SkDebugf(__VA_ARGS__)
42 #define GrBATCH_SPEW(code) code
43 #else
44 #define GrBATCH_SPEW(code)
45 #define GrBATCH_INFO(...)
46 #endif
39 47
40 class GrBatch : public GrNonAtomicRef { 48 class GrBatch : public GrNonAtomicRef {
41 public: 49 public:
42 GrBatch() : fClassID(kIllegalBatchClassID), fNumberOfDraws(0) { SkDEBUGCODE( fUsed = false;) } 50 GrBatch()
51 : fClassID(kIllegalBatchID)
52 , fNumberOfDraws(0)
53 #if GR_BATCH_SPEW
54 , fUniqueID(GenID(&gCurrBatchUniqueID))
55 #endif
56 { SkDEBUGCODE(fUsed = false;) }
43 virtual ~GrBatch() {} 57 virtual ~GrBatch() {}
44 58
45 virtual const char* name() const = 0; 59 virtual const char* name() const = 0;
46 virtual void getInvariantOutputColor(GrInitInvariantOutput* out) const = 0; 60 virtual void getInvariantOutputColor(GrInitInvariantOutput* out) const = 0;
47 virtual void getInvariantOutputCoverage(GrInitInvariantOutput* out) const = 0; 61 virtual void getInvariantOutputCoverage(GrInitInvariantOutput* out) const = 0;
48 62
49 /* 63 /*
50 * initBatchTracker is a hook for the some additional overrides / optimizati on possibilities 64 * initBatchTracker is a hook for the some additional overrides / optimizati on possibilities
51 * from the GrXferProcessor. 65 * from the GrXferProcessor.
52 */ 66 */
(...skipping 26 matching lines...) Expand all
79 void operator delete(void* target, void* placement) { 93 void operator delete(void* target, void* placement) {
80 ::operator delete(target, placement); 94 ::operator delete(target, placement);
81 } 95 }
82 96
83 /** 97 /**
84 * Helper for down-casting to a GrBatch subclass 98 * Helper for down-casting to a GrBatch subclass
85 */ 99 */
86 template <typename T> const T& cast() const { return *static_cast<const T*>( this); } 100 template <typename T> const T& cast() const { return *static_cast<const T*>( this); }
87 template <typename T> T* cast() { return static_cast<T*>(this); } 101 template <typename T> T* cast() { return static_cast<T*>(this); }
88 102
89 uint32_t classID() const { SkASSERT(kIllegalBatchClassID != fClassID); retur n fClassID; } 103 uint32_t classID() const { SkASSERT(kIllegalBatchID != fClassID); return fCl assID; }
90 104
91 // TODO no GrPrimitiveProcessors yet read fragment position 105 // TODO no GrPrimitiveProcessors yet read fragment position
92 bool willReadFragmentPosition() const { return false; } 106 bool willReadFragmentPosition() const { return false; }
93 107
94 SkDEBUGCODE(bool isUsed() const { return fUsed; }) 108 SkDEBUGCODE(bool isUsed() const { return fUsed; })
95 109
96 const GrPipeline* pipeline() const { return fPipeline; } 110 const GrPipeline* pipeline() const { return fPipeline; }
97 void setPipeline(const GrPipeline* pipeline) { fPipeline.reset(SkRef(pipelin e)); } 111 void setPipeline(const GrPipeline* pipeline) { fPipeline.reset(SkRef(pipelin e)); }
98 112
113 #if GR_BATCH_SPEW
114 uint32_t uniqueID() const { return fUniqueID; }
115 #endif
116
99 protected: 117 protected:
100 template <typename PROC_SUBCLASS> void initClassID() { 118 template <typename PROC_SUBCLASS> void initClassID() {
101 static uint32_t kClassID = GenClassID(); 119 static uint32_t kClassID = GenID(&gCurrBatchClassID);
102 fClassID = kClassID; 120 fClassID = kClassID;
103 } 121 }
104 122
105 // NOTE, compute some bounds, even if extremely conservative. Do *NOT* setL argest on the bounds 123 // NOTE, compute some bounds, even if extremely conservative. Do *NOT* setL argest on the bounds
106 // rect because we outset it for dst copy textures 124 // rect because we outset it for dst copy textures
107 void setBounds(const SkRect& newBounds) { fBounds = newBounds; } 125 void setBounds(const SkRect& newBounds) { fBounds = newBounds; }
108 126
109 void joinBounds(const SkRect& otherBounds) { 127 void joinBounds(const SkRect& otherBounds) {
110 return fBounds.joinPossiblyEmptyRect(otherBounds); 128 return fBounds.joinPossiblyEmptyRect(otherBounds);
111 } 129 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 using InstancedHelper::issueDraw; 163 using InstancedHelper::issueDraw;
146 164
147 private: 165 private:
148 typedef InstancedHelper INHERITED; 166 typedef InstancedHelper INHERITED;
149 }; 167 };
150 168
151 uint32_t fClassID; 169 uint32_t fClassID;
152 SkRect fBounds; 170 SkRect fBounds;
153 171
154 private: 172 private:
155 static uint32_t GenClassID() { 173 static uint32_t GenID(int32_t* idCounter) {
156 // fCurrProcessorClassID has been initialized to kIllegalProcessorClassI D. The 174 // fCurrProcessorClassID has been initialized to kIllegalProcessorClassI D. The
157 // atomic inc returns the old value not the incremented value. So we add 175 // atomic inc returns the old value not the incremented value. So we add
158 // 1 to the returned value. 176 // 1 to the returned value.
159 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(&gCurrBatchClassID)) + 1; 177 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(idCounter)) + 1;
160 if (!id) { 178 if (!id) {
161 SkFAIL("This should never wrap as it should only be called once for each GrBatch " 179 SkFAIL("This should never wrap as it should only be called once for each GrBatch "
162 "subclass."); 180 "subclass.");
163 } 181 }
164 return id; 182 return id;
165 } 183 }
166 184
167 enum { 185 enum {
168 kIllegalBatchClassID = 0, 186 kIllegalBatchID = 0,
169 }; 187 };
170 SkAutoTUnref<const GrPipeline> fPipeline; 188 SkAutoTUnref<const GrPipeline> fPipeline;
171 static int32_t gCurrBatchClassID; 189 static int32_t gCurrBatchClassID;
172 int fNumberOfDraws; 190 int fNumberOfDraws;
173 SkDEBUGCODE(bool fUsed;) 191 SkDEBUGCODE(bool fUsed;)
192 #if GR_BATCH_SPEW
193 static int32_t gCurrBatchUniqueID;
194 uint32_t fUniqueID;
195 #endif
174 196
175 typedef SkRefCnt INHERITED; 197 typedef SkRefCnt INHERITED;
176 }; 198 };
177 199
178 #endif 200 #endif
OLDNEW
« no previous file with comments | « no previous file | src/gpu/GrBatch.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698