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

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

Issue 1352813003: add a ClassID function to GrBatch (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: tweaks Created 5 years, 3 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
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 23 matching lines...) Expand all
34 */ 34 */
35 #define GR_BATCH_SPEW 0 35 #define GR_BATCH_SPEW 0
36 #if GR_BATCH_SPEW 36 #if GR_BATCH_SPEW
37 #define GrBATCH_INFO(...) SkDebugf(__VA_ARGS__) 37 #define GrBATCH_INFO(...) SkDebugf(__VA_ARGS__)
38 #define GrBATCH_SPEW(code) code 38 #define GrBATCH_SPEW(code) code
39 #else 39 #else
40 #define GrBATCH_SPEW(code) 40 #define GrBATCH_SPEW(code)
41 #define GrBATCH_INFO(...) 41 #define GrBATCH_INFO(...)
42 #endif 42 #endif
43 43
44 // A helper macro to generate a class static id
robertphillips 2015/09/17 14:56:06 DEFINE_BATCH_CLASS_ID ?
45 #define BATCH_CLASS_ID \
46 static uint32_t ClassID() { \
47 static uint32_t kClassID = GenID(&gCurrBatchClassID); \
48 return kClassID; \
49 }
50
44 class GrBatch : public GrNonAtomicRef { 51 class GrBatch : public GrNonAtomicRef {
45 public: 52 public:
46 GrBatch(); 53 GrBatch();
47 ~GrBatch() override; 54 ~GrBatch() override;
48 55
49 virtual const char* name() const = 0; 56 virtual const char* name() const = 0;
50 57
51 bool combineIfPossible(GrBatch* that, const GrCaps& caps) { 58 bool combineIfPossible(GrBatch* that, const GrCaps& caps) {
52 if (this->classID() != that->classID()) { 59 if (this->classID() != that->classID()) {
53 return false; 60 return false;
54 } 61 }
55 62
56 return this->onCombineIfPossible(that, caps); 63 return this->onCombineIfPossible(that, caps);
57 } 64 }
58 65
59 const SkRect& bounds() const { return fBounds; } 66 const SkRect& bounds() const { return fBounds; }
60 67
61 void* operator new(size_t size); 68 void* operator new(size_t size);
62 void operator delete(void* target); 69 void operator delete(void* target);
63 70
64 void* operator new(size_t size, void* placement) { 71 void* operator new(size_t size, void* placement) {
65 return ::operator new(size, placement); 72 return ::operator new(size, placement);
66 } 73 }
67 void operator delete(void* target, void* placement) { 74 void operator delete(void* target, void* placement) {
68 ::operator delete(target, placement); 75 ::operator delete(target, placement);
69 } 76 }
70 77
71 /** 78 /**
72 * Helper for down-casting to a GrBatch subclass 79 * Helper for safely down-casting to a GrBatch subclass
73 */ 80 */
74 template <typename T> const T& cast() const { return *static_cast<const T*>( this); } 81 template <typename T> const T& cast() const {
75 template <typename T> T* cast() { return static_cast<T*>(this); } 82 SkASSERT(T::ClassID() == this->classID());
83 return *static_cast<const T*>(this);
84 }
85
86 template <typename T> T* cast() {
87 SkASSERT(T::ClassID() == this->classID());
88 return static_cast<T*>(this);
89 }
76 90
77 uint32_t classID() const { SkASSERT(kIllegalBatchID != fClassID); return fCl assID; } 91 uint32_t classID() const { SkASSERT(kIllegalBatchID != fClassID); return fCl assID; }
78 92
79 #if GR_BATCH_SPEW 93 #if GR_BATCH_SPEW
80 uint32_t uniqueID() const { return fUniqueID; } 94 uint32_t uniqueID() const { return fUniqueID; }
81 #endif 95 #endif
82 SkDEBUGCODE(bool isUsed() const { return fUsed; }) 96 SkDEBUGCODE(bool isUsed() const { return fUsed; })
83 97
84 /** Called prior to drawing. The batch should perform any resource creation necessary to 98 /** Called prior to drawing. The batch should perform any resource creation necessary to
85 to quickly issue its draw when draw is called. */ 99 to quickly issue its draw when draw is called. */
86 void prepare(GrBatchFlushState* state) { this->onPrepare(state); } 100 void prepare(GrBatchFlushState* state) { this->onPrepare(state); }
87 101
88 /** Issues the batches commands to GrGpu. */ 102 /** Issues the batches commands to GrGpu. */
89 void draw(GrBatchFlushState* state) { this->onDraw(state); } 103 void draw(GrBatchFlushState* state) { this->onDraw(state); }
90 104
91 /** Used to block batching across render target changes. Remove this once we store 105 /** Used to block batching across render target changes. Remove this once we store
92 GrBatches for different RTs in different targets. */ 106 GrBatches for different RTs in different targets. */
93 virtual uint32_t renderTargetUniqueID() const = 0; 107 virtual uint32_t renderTargetUniqueID() const = 0;
94 108
95 /** Used for spewing information about batches when debugging. */ 109 /** Used for spewing information about batches when debugging. */
96 virtual SkString dumpInfo() const = 0; 110 virtual SkString dumpInfo() const = 0;
97 111
98 protected: 112 protected:
robertphillips 2015/09/17 14:56:06 // (via BATCH_CLASS_ID macro) ? We can't do this
99 template <typename PROC_SUBCLASS> void initClassID() { 113 // Caller must have already defined BATCH_SUBCLASS::ClassID()
100 static uint32_t kClassID = GenID(&gCurrBatchClassID); 114 template <class BATCH_SUBCLASS> void initClassID() {
101 fClassID = kClassID; 115 SkASSERT(kIllegalBatchID == fClassID);
116 fClassID = BATCH_SUBCLASS::ClassID();
102 } 117 }
103 118
104 // NOTE, compute some bounds, even if extremely conservative. Do *NOT* setL argest on the bounds 119 // NOTE, compute some bounds, even if extremely conservative. Do *NOT* setL argest on the bounds
105 // rect because we outset it for dst copy textures 120 // rect because we outset it for dst copy textures
106 void setBounds(const SkRect& newBounds) { fBounds = newBounds; } 121 void setBounds(const SkRect& newBounds) { fBounds = newBounds; }
107 122
108 void joinBounds(const SkRect& otherBounds) { 123 void joinBounds(const SkRect& otherBounds) {
109 return fBounds.joinPossiblyEmptyRect(otherBounds); 124 return fBounds.joinPossiblyEmptyRect(otherBounds);
110 } 125 }
111 126
112 SkRect fBounds;
113
114 private:
115 virtual bool onCombineIfPossible(GrBatch*, const GrCaps& caps) = 0;
116
117 virtual void onPrepare(GrBatchFlushState*) = 0;
118 virtual void onDraw(GrBatchFlushState*) = 0;
119
120 static uint32_t GenID(int32_t* idCounter) { 127 static uint32_t GenID(int32_t* idCounter) {
robertphillips 2015/09/17 14:56:06 fCurrProcessorClassID -> idCounter ?
121 // fCurrProcessorClassID has been initialized to kIllegalProcessorClassI D. The 128 // fCurrProcessorClassID has been initialized to kIllegalProcessorClassI D. The
122 // atomic inc returns the old value not the incremented value. So we add 129 // atomic inc returns the old value not the incremented value. So we add
123 // 1 to the returned value. 130 // 1 to the returned value.
124 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(idCounter)) + 1; 131 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(idCounter)) + 1;
125 if (!id) { 132 if (!id) {
126 SkFAIL("This should never wrap as it should only be called once for each GrBatch " 133 SkFAIL("This should never wrap as it should only be called once for each GrBatch "
127 "subclass."); 134 "subclass.");
128 } 135 }
129 return id; 136 return id;
130 } 137 }
131 138
139 SkRect fBounds;
140 uint32_t fClassID;
robertphillips 2015/09/17 14:56:06 = kIllegalBatchID; ?
141 static int32_t gCurrBatchClassID;
142
143 private:
144 virtual bool onCombineIfPossible(GrBatch*, const GrCaps& caps) = 0;
145
146 virtual void onPrepare(GrBatchFlushState*) = 0;
147 virtual void onDraw(GrBatchFlushState*) = 0;
148
132 enum { 149 enum {
133 kIllegalBatchID = 0, 150 kIllegalBatchID = 0,
134 }; 151 };
135 152
136 uint32_t fClassID;
137 SkDEBUGCODE(bool fUsed;) 153 SkDEBUGCODE(bool fUsed;)
138 #if GR_BATCH_SPEW 154 #if GR_BATCH_SPEW
139 uint32_t fUniqueID; 155 uint32_t fUniqueID;
140 static int32_t gCurrBatchUniqueID; 156 static int32_t gCurrBatchUniqueID;
141 #endif 157 #endif
142 static int32_t gCurrBatchClassID;
143 typedef GrNonAtomicRef INHERITED; 158 typedef GrNonAtomicRef INHERITED;
144 }; 159 };
145 160
146 #endif 161 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698