OLD | NEW |
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 |
11 #include <new> | 11 #include <new> |
12 #include "GrNonAtomicRef.h" | 12 #include "GrNonAtomicRef.h" |
13 | 13 |
14 #include "SkRect.h" | 14 #include "SkRect.h" |
15 #include "SkString.h" | 15 #include "SkString.h" |
16 | 16 |
| 17 #include "draws/GrDraw.h" |
| 18 |
| 19 #include "../private/SkTemplates.h" |
| 20 |
17 class GrCaps; | 21 class GrCaps; |
18 class GrBatchFlushState; | 22 class GrBatchFlushState; |
19 | 23 |
20 /** | 24 /** |
21 * GrBatch is the base class for all Ganesh deferred geometry generators. To fa
cilitate | 25 * GrBatch is the base class for all Ganesh deferred geometry generators. To fa
cilitate |
22 * reorderable batching, Ganesh does not generate geometry inline with draw call
s. Instead, it | 26 * reorderable batching, Ganesh does not generate geometry inline with draw call
s. Instead, it |
23 * captures the arguments to the draw and then generates the geometry on demand.
This gives GrBatch | 27 * captures the arguments to the draw and then generates the geometry on demand.
This gives GrBatch |
24 * subclasses complete freedom to decide how / what they can batch. | 28 * subclasses complete freedom to decide how / what they can batch. |
25 * | 29 * |
26 * 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 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 /** Issues the batches commands to GrGpu. */ | 106 /** Issues the batches commands to GrGpu. */ |
103 void draw(GrBatchFlushState* state) { this->onDraw(state); } | 107 void draw(GrBatchFlushState* state) { this->onDraw(state); } |
104 | 108 |
105 /** Used to block batching across render target changes. Remove this once we
store | 109 /** Used to block batching across render target changes. Remove this once we
store |
106 GrBatches for different RTs in different targets. */ | 110 GrBatches for different RTs in different targets. */ |
107 virtual uint32_t renderTargetUniqueID() const = 0; | 111 virtual uint32_t renderTargetUniqueID() const = 0; |
108 | 112 |
109 /** Used for spewing information about batches when debugging. */ | 113 /** Used for spewing information about batches when debugging. */ |
110 virtual SkString dumpInfo() const = 0; | 114 virtual SkString dumpInfo() const = 0; |
111 | 115 |
| 116 template <typename T, typename... Args> void initSnapStorage(Args&&... args)
{ |
| 117 SkASSERT(!fSnap && sizeof(T) < fSnapStorage.size()); |
| 118 fSnap = new (SkTCast<T*>(fSnapStorage.get())) T(skstd::forward<Args>(arg
s)...); |
| 119 } |
| 120 const GrDrawSnap* getDrawSnap() const { return fSnap; } |
| 121 |
112 protected: | 122 protected: |
113 // 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 |
114 // rect because we outset it for dst copy textures | 124 // rect because we outset it for dst copy textures |
115 void setBounds(const SkRect& newBounds) { fBounds = newBounds; } | 125 void setBounds(const SkRect& newBounds) { fBounds = newBounds; } |
116 | 126 |
117 void joinBounds(const SkRect& otherBounds) { | 127 void joinBounds(const SkRect& otherBounds) { |
118 return fBounds.joinPossiblyEmptyRect(otherBounds); | 128 return fBounds.joinPossiblyEmptyRect(otherBounds); |
119 } | 129 } |
120 | 130 |
121 static uint32_t GenBatchClassID() { return GenID(&gCurrBatchClassID); } | 131 static uint32_t GenBatchClassID() { return GenID(&gCurrBatchClassID); } |
(...skipping 16 matching lines...) Expand all Loading... |
138 } | 148 } |
139 return id; | 149 return id; |
140 } | 150 } |
141 | 151 |
142 enum { | 152 enum { |
143 kIllegalBatchID = 0, | 153 kIllegalBatchID = 0, |
144 }; | 154 }; |
145 | 155 |
146 SkDEBUGCODE(bool fUsed;) | 156 SkDEBUGCODE(bool fUsed;) |
147 const uint32_t fClassID; | 157 const uint32_t fClassID; |
| 158 GrDrawSnap* fSnap; |
| 159 SkAlignedSStorage<128> fSnapStorage; // 128 bytes should be mor
e than enough |
148 #if GR_BATCH_SPEW | 160 #if GR_BATCH_SPEW |
149 static uint32_t GenBatchID() { return GenID(&gCurrBatchUniqueID); } | 161 static uint32_t GenBatchID() { return GenID(&gCurrBatchUniqueID); } |
150 const uint32_t fUniqueID; | 162 const uint32_t fUniqueID; |
151 static int32_t gCurrBatchUniqueID; | 163 static int32_t gCurrBatchUniqueID; |
152 #endif | 164 #endif |
| 165 |
153 static int32_t gCurrBatchClassID; | 166 static int32_t gCurrBatchClassID; |
154 typedef GrNonAtomicRef INHERITED; | 167 typedef GrNonAtomicRef INHERITED; |
155 }; | 168 }; |
156 | 169 |
157 #endif | 170 #endif |
OLD | NEW |