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 20 matching lines...) Expand all Loading... |
31 * subclasses complete freedom to decide how / what they can batch. | 31 * subclasses complete freedom to decide how / what they can batch. |
32 * | 32 * |
33 * Batches are created when GrContext processes a draw call. Batches of the same
subclass may be | 33 * Batches are created when GrContext processes a draw call. Batches of the same
subclass may be |
34 * merged using combineIfPossible. When two batches merge, one takes on the unio
n of the data | 34 * merged using combineIfPossible. When two batches merge, one takes on the unio
n of the data |
35 * and the other is left empty. The merged batch becomes responsible for drawing
the data from both | 35 * and the other is left empty. The merged batch becomes responsible for drawing
the data from both |
36 * the original batches. | 36 * the original batches. |
37 * | 37 * |
38 * If there are any possible optimizations which might require knowing more abou
t the full state of | 38 * If there are any possible optimizations which might require knowing more abou
t the full state of |
39 * the draw, ie whether or not the GrBatch is allowed to tweak alpha for coverag
e, then this | 39 * the draw, ie whether or not the GrBatch is allowed to tweak alpha for coverag
e, then this |
40 * information will be communicated to the GrBatch prior to geometry generation. | 40 * information will be communicated to the GrBatch prior to geometry generation. |
41 * TODO Batch should own the draw bounds | |
42 */ | 41 */ |
43 | 42 |
44 class GrBatch : public SkRefCnt { | 43 class GrBatch : public SkRefCnt { |
45 public: | 44 public: |
46 SK_DECLARE_INST_COUNT(GrBatch) | 45 SK_DECLARE_INST_COUNT(GrBatch) |
47 GrBatch() : fClassID(kIllegalBatchClassID), fNumberOfDraws(0) { SkDEBUGCODE(
fUsed = false;) } | 46 GrBatch() : fClassID(kIllegalBatchClassID), fNumberOfDraws(0) { SkDEBUGCODE(
fUsed = false;) } |
48 virtual ~GrBatch() {} | 47 virtual ~GrBatch() {} |
49 | 48 |
50 virtual const char* name() const = 0; | 49 virtual const char* name() const = 0; |
51 virtual void getInvariantOutputColor(GrInitInvariantOutput* out) const = 0; | 50 virtual void getInvariantOutputColor(GrInitInvariantOutput* out) const = 0; |
52 virtual void getInvariantOutputCoverage(GrInitInvariantOutput* out) const =
0; | 51 virtual void getInvariantOutputCoverage(GrInitInvariantOutput* out) const =
0; |
53 | 52 |
54 /* | 53 /* |
55 * initBatchTracker is a hook for the some additional overrides / optimizati
on possibilities | 54 * initBatchTracker is a hook for the some additional overrides / optimizati
on possibilities |
56 * from the GrXferProcessor. | 55 * from the GrXferProcessor. |
57 */ | 56 */ |
58 virtual void initBatchTracker(const GrPipelineInfo& init) = 0; | 57 virtual void initBatchTracker(const GrPipelineInfo& init) = 0; |
59 | 58 |
60 bool combineIfPossible(GrBatch* that) { | 59 bool combineIfPossible(GrBatch* that) { |
61 if (this->classID() != that->classID()) { | 60 if (this->classID() != that->classID()) { |
62 return false; | 61 return false; |
63 } | 62 } |
64 | 63 |
65 return onCombineIfPossible(that); | 64 return this->onCombineIfPossible(that); |
66 } | 65 } |
67 | 66 |
68 virtual bool onCombineIfPossible(GrBatch*) = 0; | 67 virtual bool onCombineIfPossible(GrBatch*) = 0; |
69 | 68 |
70 virtual void generateGeometry(GrBatchTarget*, const GrPipeline*) = 0; | 69 virtual void generateGeometry(GrBatchTarget*, const GrPipeline*) = 0; |
71 | 70 |
| 71 const SkRect& bounds() const { return fBounds; } |
| 72 |
72 // TODO this goes away when batches are everywhere | 73 // TODO this goes away when batches are everywhere |
73 void setNumberOfDraws(int numberOfDraws) { fNumberOfDraws = numberOfDraws; } | 74 void setNumberOfDraws(int numberOfDraws) { fNumberOfDraws = numberOfDraws; } |
74 int numberOfDraws() const { return fNumberOfDraws; } | 75 int numberOfDraws() const { return fNumberOfDraws; } |
75 | 76 |
76 void* operator new(size_t size); | 77 void* operator new(size_t size); |
77 void operator delete(void* target); | 78 void operator delete(void* target); |
78 | 79 |
79 void* operator new(size_t size, void* placement) { | 80 void* operator new(size_t size, void* placement) { |
80 return ::operator new(size, placement); | 81 return ::operator new(size, placement); |
81 } | 82 } |
(...skipping 15 matching lines...) Expand all Loading... |
97 SkDEBUGCODE(bool isUsed() const { return fUsed; }) | 98 SkDEBUGCODE(bool isUsed() const { return fUsed; }) |
98 | 99 |
99 protected: | 100 protected: |
100 template <typename PROC_SUBCLASS> void initClassID() { | 101 template <typename PROC_SUBCLASS> void initClassID() { |
101 static uint32_t kClassID = GenClassID(); | 102 static uint32_t kClassID = GenClassID(); |
102 fClassID = kClassID; | 103 fClassID = kClassID; |
103 } | 104 } |
104 | 105 |
105 uint32_t fClassID; | 106 uint32_t fClassID; |
106 | 107 |
| 108 // NOTE, compute some bounds, even if extremely conservative. Do *NOT* setL
argest on the bounds |
| 109 // rect because we outset it for dst copy textures |
| 110 void setBounds(const SkRect& newBounds) { fBounds = newBounds; } |
| 111 |
| 112 void joinBounds(const SkRect& otherBounds) { |
| 113 return fBounds.joinPossiblyEmptyRect(otherBounds); |
| 114 } |
| 115 |
| 116 SkRect fBounds; |
| 117 |
107 private: | 118 private: |
108 static uint32_t GenClassID() { | 119 static uint32_t GenClassID() { |
109 // fCurrProcessorClassID has been initialized to kIllegalProcessorClassI
D. The | 120 // fCurrProcessorClassID has been initialized to kIllegalProcessorClassI
D. The |
110 // atomic inc returns the old value not the incremented value. So we add | 121 // atomic inc returns the old value not the incremented value. So we add |
111 // 1 to the returned value. | 122 // 1 to the returned value. |
112 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(&gCurrBatchClassID)) +
1; | 123 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(&gCurrBatchClassID)) +
1; |
113 if (!id) { | 124 if (!id) { |
114 SkFAIL("This should never wrap as it should only be called once for
each GrBatch " | 125 SkFAIL("This should never wrap as it should only be called once for
each GrBatch " |
115 "subclass."); | 126 "subclass."); |
116 } | 127 } |
117 return id; | 128 return id; |
118 } | 129 } |
119 | 130 |
120 enum { | 131 enum { |
121 kIllegalBatchClassID = 0, | 132 kIllegalBatchClassID = 0, |
122 }; | 133 }; |
123 static int32_t gCurrBatchClassID; | 134 static int32_t gCurrBatchClassID; |
124 | 135 |
125 SkDEBUGCODE(bool fUsed;) | 136 SkDEBUGCODE(bool fUsed;) |
126 | 137 |
127 int fNumberOfDraws; | 138 int fNumberOfDraws; |
128 | 139 |
129 typedef SkRefCnt INHERITED; | 140 typedef SkRefCnt INHERITED; |
130 }; | 141 }; |
131 | 142 |
132 #endif | 143 #endif |
OLD | NEW |