| 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 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 * information will be communicated to the GrBatch prior to geometry generation. | 39 * information will be communicated to the GrBatch prior to geometry generation. |
| 40 */ | 40 */ |
| 41 | 41 |
| 42 struct GrBatchOpt { | 42 struct GrBatchOpt { |
| 43 bool fCanTweakAlphaForCoverage; | 43 bool fCanTweakAlphaForCoverage; |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 class GrBatch : public SkRefCnt { | 46 class GrBatch : public SkRefCnt { |
| 47 public: | 47 public: |
| 48 SK_DECLARE_INST_COUNT(GrBatch) | 48 SK_DECLARE_INST_COUNT(GrBatch) |
| 49 GrBatch() { SkDEBUGCODE(fUsed = false;) } | 49 GrBatch() : fBatchesGenerated(0) { SkDEBUGCODE(fUsed = false;) } |
| 50 virtual ~GrBatch() {} | 50 virtual ~GrBatch() {} |
| 51 | 51 |
| 52 virtual const char* name() const = 0; | 52 virtual const char* name() const = 0; |
| 53 virtual void getInvariantOutputColor(GrInitInvariantOutput* out) const = 0; | 53 virtual void getInvariantOutputColor(GrInitInvariantOutput* out) const = 0; |
| 54 virtual void getInvariantOutputCoverage(GrInitInvariantOutput* out) const =
0; | 54 virtual void getInvariantOutputCoverage(GrInitInvariantOutput* out) const =
0; |
| 55 | 55 |
| 56 /* | 56 /* |
| 57 * initBatchOpt is used to communicate possible optimizations to the GrBatch
. initBatchTracker | 57 * initBatchOpt is used to communicate possible optimizations to the GrBatch
. initBatchTracker |
| 58 * is a hook for the some additional overrides from the GrXferProcessor. Th
is is a bit | 58 * is a hook for the some additional overrides from the GrXferProcessor. Th
is is a bit |
| 59 * confusing but has to be like this until GrBatch is everywhere. | 59 * confusing but has to be like this until GrBatch is everywhere. |
| 60 * | 60 * |
| 61 * TODO combine to a single init call when GrBatch is everywhere. | 61 * TODO combine to a single init call when GrBatch is everywhere. |
| 62 */ | 62 */ |
| 63 virtual void initBatchOpt(const GrBatchOpt&) = 0; | 63 virtual void initBatchOpt(const GrBatchOpt&) = 0; |
| 64 virtual void initBatchTracker(const GrPipelineInfo& init) = 0; | 64 virtual void initBatchTracker(const GrPipelineInfo& init) = 0; |
| 65 | 65 |
| 66 bool combineIfPossible(GrBatch* that) { | 66 bool combineIfPossible(GrBatch* that) { |
| 67 if (this->classID() != that->classID()) { | 67 if (this->classID() != that->classID()) { |
| 68 return false; | 68 return false; |
| 69 } | 69 } |
| 70 | 70 |
| 71 return onCombineIfPossible(that); | 71 return onCombineIfPossible(that); |
| 72 } | 72 } |
| 73 | 73 |
| 74 virtual bool onCombineIfPossible(GrBatch*) = 0; | 74 virtual bool onCombineIfPossible(GrBatch*) = 0; |
| 75 | 75 |
| 76 virtual void generateGeometry(GrBatchTarget*, const GrPipeline*) = 0; | 76 virtual void generateGeometry(GrBatchTarget*, const GrPipeline*) = 0; |
| 77 | 77 |
| 78 // TODO this goes away when batches are everywhere |
| 79 int batchesGenerated() const { return fBatchesGenerated; } |
| 80 |
| 78 void* operator new(size_t size); | 81 void* operator new(size_t size); |
| 79 void operator delete(void* target); | 82 void operator delete(void* target); |
| 80 | 83 |
| 81 void* operator new(size_t size, void* placement) { | 84 void* operator new(size_t size, void* placement) { |
| 82 return ::operator new(size, placement); | 85 return ::operator new(size, placement); |
| 83 } | 86 } |
| 84 void operator delete(void* target, void* placement) { | 87 void operator delete(void* target, void* placement) { |
| 85 ::operator delete(target, placement); | 88 ::operator delete(target, placement); |
| 86 } | 89 } |
| 87 | 90 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 98 | 101 |
| 99 SkDEBUGCODE(bool isUsed() const { return fUsed; }) | 102 SkDEBUGCODE(bool isUsed() const { return fUsed; }) |
| 100 | 103 |
| 101 protected: | 104 protected: |
| 102 template <typename PROC_SUBCLASS> void initClassID() { | 105 template <typename PROC_SUBCLASS> void initClassID() { |
| 103 static uint32_t kClassID = GenClassID(); | 106 static uint32_t kClassID = GenClassID(); |
| 104 fClassID = kClassID; | 107 fClassID = kClassID; |
| 105 } | 108 } |
| 106 | 109 |
| 107 uint32_t fClassID; | 110 uint32_t fClassID; |
| 111 int fBatchesGenerated; |
| 108 | 112 |
| 109 private: | 113 private: |
| 110 static uint32_t GenClassID() { | 114 static uint32_t GenClassID() { |
| 111 // fCurrProcessorClassID has been initialized to kIllegalProcessorClassI
D. The | 115 // fCurrProcessorClassID has been initialized to kIllegalProcessorClassI
D. The |
| 112 // atomic inc returns the old value not the incremented value. So we add | 116 // atomic inc returns the old value not the incremented value. So we add |
| 113 // 1 to the returned value. | 117 // 1 to the returned value. |
| 114 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(&gCurrBatchClassID)) +
1; | 118 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(&gCurrBatchClassID)) +
1; |
| 115 if (!id) { | 119 if (!id) { |
| 116 SkFAIL("This should never wrap as it should only be called once for
each GrBatch " | 120 SkFAIL("This should never wrap as it should only be called once for
each GrBatch " |
| 117 "subclass."); | 121 "subclass."); |
| 118 } | 122 } |
| 119 return id; | 123 return id; |
| 120 } | 124 } |
| 121 | 125 |
| 122 enum { | 126 enum { |
| 123 kIllegalBatchClassID = 0, | 127 kIllegalBatchClassID = 0, |
| 124 }; | 128 }; |
| 125 static int32_t gCurrBatchClassID; | 129 static int32_t gCurrBatchClassID; |
| 126 | 130 |
| 127 SkDEBUGCODE(bool fUsed;) | 131 SkDEBUGCODE(bool fUsed;) |
| 128 | 132 |
| 129 typedef SkRefCnt INHERITED; | 133 typedef SkRefCnt INHERITED; |
| 130 }; | 134 }; |
| 131 | 135 |
| 132 #endif | 136 #endif |
| OLD | NEW |