| 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 | 16 |
| 16 class GrCaps; | 17 class GrCaps; |
| 18 class GrBatchFlushState; |
| 17 | 19 |
| 18 /** | 20 /** |
| 19 * GrBatch is the base class for all Ganesh deferred geometry generators. To fa
cilitate | 21 * GrBatch is the base class for all Ganesh deferred geometry generators. To fa
cilitate |
| 20 * reorderable batching, Ganesh does not generate geometry inline with draw call
s. Instead, it | 22 * reorderable batching, Ganesh does not generate geometry inline with draw call
s. Instead, it |
| 21 * captures the arguments to the draw and then generates the geometry on demand.
This gives GrBatch | 23 * captures the arguments to the draw and then generates the geometry on demand.
This gives GrBatch |
| 22 * subclasses complete freedom to decide how / what they can batch. | 24 * subclasses complete freedom to decide how / what they can batch. |
| 23 * | 25 * |
| 24 * Batches are created when GrContext processes a draw call. Batches of the same
subclass may be | 26 * Batches are created when GrContext processes a draw call. Batches of the same
subclass may be |
| 25 * merged using combineIfPossible. When two batches merge, one takes on the unio
n of the data | 27 * merged using combineIfPossible. When two batches merge, one takes on the unio
n of the data |
| 26 * and the other is left empty. The merged batch becomes responsible for drawing
the data from both | 28 * and the other is left empty. The merged batch becomes responsible for drawing
the data from both |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 template <typename T> const T& cast() const { return *static_cast<const T*>(
this); } | 74 template <typename T> const T& cast() const { return *static_cast<const T*>(
this); } |
| 73 template <typename T> T* cast() { return static_cast<T*>(this); } | 75 template <typename T> T* cast() { return static_cast<T*>(this); } |
| 74 | 76 |
| 75 uint32_t classID() const { SkASSERT(kIllegalBatchID != fClassID); return fCl
assID; } | 77 uint32_t classID() const { SkASSERT(kIllegalBatchID != fClassID); return fCl
assID; } |
| 76 | 78 |
| 77 #if GR_BATCH_SPEW | 79 #if GR_BATCH_SPEW |
| 78 uint32_t uniqueID() const { return fUniqueID; } | 80 uint32_t uniqueID() const { return fUniqueID; } |
| 79 #endif | 81 #endif |
| 80 SkDEBUGCODE(bool isUsed() const { return fUsed; }) | 82 SkDEBUGCODE(bool isUsed() const { return fUsed; }) |
| 81 | 83 |
| 84 /** Called prior to drawing. The batch should perform any resource creation
necessary to |
| 85 to quickly issue its draw when draw is called. */ |
| 86 void prepare(GrBatchFlushState* state) { this->onPrepare(state); } |
| 87 |
| 88 /** Issues the batches commands to GrGpu. */ |
| 89 void draw(GrBatchFlushState* state) { this->onDraw(state); } |
| 90 |
| 91 /** Used to block batching across render target changes. Remove this once we
store |
| 92 GrBatches for different RTs in different targets. */ |
| 93 virtual uint32_t renderTargetUniqueID() const = 0; |
| 94 |
| 95 /** Used for spewing information about batches when debugging. */ |
| 96 virtual SkString dumpInfo() const = 0; |
| 97 |
| 82 protected: | 98 protected: |
| 83 template <typename PROC_SUBCLASS> void initClassID() { | 99 template <typename PROC_SUBCLASS> void initClassID() { |
| 84 static uint32_t kClassID = GenID(&gCurrBatchClassID); | 100 static uint32_t kClassID = GenID(&gCurrBatchClassID); |
| 85 fClassID = kClassID; | 101 fClassID = kClassID; |
| 86 } | 102 } |
| 87 | 103 |
| 88 // NOTE, compute some bounds, even if extremely conservative. Do *NOT* setL
argest on the bounds | 104 // NOTE, compute some bounds, even if extremely conservative. Do *NOT* setL
argest on the bounds |
| 89 // rect because we outset it for dst copy textures | 105 // rect because we outset it for dst copy textures |
| 90 void setBounds(const SkRect& newBounds) { fBounds = newBounds; } | 106 void setBounds(const SkRect& newBounds) { fBounds = newBounds; } |
| 91 | 107 |
| 92 void joinBounds(const SkRect& otherBounds) { | 108 void joinBounds(const SkRect& otherBounds) { |
| 93 return fBounds.joinPossiblyEmptyRect(otherBounds); | 109 return fBounds.joinPossiblyEmptyRect(otherBounds); |
| 94 } | 110 } |
| 95 | 111 |
| 96 SkRect fBounds; | 112 SkRect fBounds; |
| 97 | 113 |
| 98 private: | 114 private: |
| 99 virtual bool onCombineIfPossible(GrBatch*, const GrCaps& caps) = 0; | 115 virtual bool onCombineIfPossible(GrBatch*, const GrCaps& caps) = 0; |
| 100 | 116 |
| 117 virtual void onPrepare(GrBatchFlushState*) = 0; |
| 118 virtual void onDraw(GrBatchFlushState*) = 0; |
| 119 |
| 101 static uint32_t GenID(int32_t* idCounter) { | 120 static uint32_t GenID(int32_t* idCounter) { |
| 102 // fCurrProcessorClassID has been initialized to kIllegalProcessorClassI
D. The | 121 // fCurrProcessorClassID has been initialized to kIllegalProcessorClassI
D. The |
| 103 // atomic inc returns the old value not the incremented value. So we add | 122 // atomic inc returns the old value not the incremented value. So we add |
| 104 // 1 to the returned value. | 123 // 1 to the returned value. |
| 105 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(idCounter)) + 1; | 124 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(idCounter)) + 1; |
| 106 if (!id) { | 125 if (!id) { |
| 107 SkFAIL("This should never wrap as it should only be called once for
each GrBatch " | 126 SkFAIL("This should never wrap as it should only be called once for
each GrBatch " |
| 108 "subclass."); | 127 "subclass."); |
| 109 } | 128 } |
| 110 return id; | 129 return id; |
| 111 } | 130 } |
| 112 | 131 |
| 113 enum { | 132 enum { |
| 114 kIllegalBatchID = 0, | 133 kIllegalBatchID = 0, |
| 115 }; | 134 }; |
| 116 | 135 |
| 117 uint32_t fClassID; | 136 uint32_t fClassID; |
| 118 SkDEBUGCODE(bool fUsed;) | 137 SkDEBUGCODE(bool fUsed;) |
| 119 #if GR_BATCH_SPEW | 138 #if GR_BATCH_SPEW |
| 120 uint32_t fUniqueID; | 139 uint32_t fUniqueID; |
| 121 static int32_t gCurrBatchUniqueID; | 140 static int32_t gCurrBatchUniqueID; |
| 122 #endif | 141 #endif |
| 123 static int32_t gCurrBatchClassID; | 142 static int32_t gCurrBatchClassID; |
| 124 typedef GrNonAtomicRef INHERITED; | 143 typedef GrNonAtomicRef INHERITED; |
| 125 }; | 144 }; |
| 126 | 145 |
| 127 #endif | 146 #endif |
| OLD | NEW |