| 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 "../private/SkAtomics.h" | 11 #include "../private/SkAtomics.h" |
| 12 #include "GrNonAtomicRef.h" | 12 #include "GrNonAtomicRef.h" |
| 13 #include "SkMatrix.h" |
| 13 #include "SkRect.h" | 14 #include "SkRect.h" |
| 14 #include "SkString.h" | 15 #include "SkString.h" |
| 15 | 16 |
| 16 #include <new> | 17 #include <new> |
| 17 | 18 |
| 18 class GrCaps; | 19 class GrCaps; |
| 19 class GrGpuCommandBuffer; | 20 class GrGpuCommandBuffer; |
| 20 class GrBatchFlushState; | 21 class GrBatchFlushState; |
| 21 class GrRenderTarget; | 22 class GrRenderTarget; |
| 22 | 23 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 virtual const char* name() const = 0; | 64 virtual const char* name() const = 0; |
| 64 | 65 |
| 65 bool combineIfPossible(GrBatch* that, const GrCaps& caps) { | 66 bool combineIfPossible(GrBatch* that, const GrCaps& caps) { |
| 66 if (this->classID() != that->classID()) { | 67 if (this->classID() != that->classID()) { |
| 67 return false; | 68 return false; |
| 68 } | 69 } |
| 69 | 70 |
| 70 return this->onCombineIfPossible(that, caps); | 71 return this->onCombineIfPossible(that, caps); |
| 71 } | 72 } |
| 72 | 73 |
| 73 const SkRect& bounds() const { return fBounds; } | 74 const SkRect& bounds() const { |
| 75 SkASSERT(kUninitialized_BoundsFlag != fBoundsFlags); |
| 76 return fBounds; |
| 77 } |
| 78 |
| 79 bool hasAABloat() const { |
| 80 SkASSERT(fBoundsFlags != kUninitialized_BoundsFlag); |
| 81 return SkToBool(fBoundsFlags & kAABloat_BoundsFlag); |
| 82 } |
| 83 |
| 84 bool hasZeroArea() const { |
| 85 SkASSERT(fBoundsFlags != kUninitialized_BoundsFlag); |
| 86 return SkToBool(fBoundsFlags & kZeroArea_BoundsFlag); |
| 87 } |
| 74 | 88 |
| 75 void* operator new(size_t size); | 89 void* operator new(size_t size); |
| 76 void operator delete(void* target); | 90 void operator delete(void* target); |
| 77 | 91 |
| 78 void* operator new(size_t size, void* placement) { | 92 void* operator new(size_t size, void* placement) { |
| 79 return ::operator new(size, placement); | 93 return ::operator new(size, placement); |
| 80 } | 94 } |
| 81 void operator delete(void* target, void* placement) { | 95 void operator delete(void* target, void* placement) { |
| 82 ::operator delete(target, placement); | 96 ::operator delete(target, placement); |
| 83 } | 97 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 SkString string; | 136 SkString string; |
| 123 string.appendf("BatchBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", | 137 string.appendf("BatchBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", |
| 124 fBounds.fLeft, fBounds.fTop, fBounds.fRight, fBounds.fBot
tom); | 138 fBounds.fLeft, fBounds.fTop, fBounds.fRight, fBounds.fBot
tom); |
| 125 return string; | 139 return string; |
| 126 } | 140 } |
| 127 | 141 |
| 128 /** Can remove this when multi-draw-buffer lands */ | 142 /** Can remove this when multi-draw-buffer lands */ |
| 129 virtual GrRenderTarget* renderTarget() const = 0; | 143 virtual GrRenderTarget* renderTarget() const = 0; |
| 130 | 144 |
| 131 protected: | 145 protected: |
| 132 // NOTE, compute some bounds, even if extremely conservative. Do *NOT* setL
argest on the bounds | 146 /** |
| 133 // rect because we outset it for dst copy textures | 147 * Indicates that the batch will produce geometry that extends beyond its bo
unds for the |
| 134 void setBounds(const SkRect& newBounds) { fBounds = newBounds; } | 148 * purpose of ensuring that the fragment shader runs on partially covered pi
xels for |
| 149 * non-MSAA antialiasing. |
| 150 */ |
| 151 enum class HasAABloat { |
| 152 kYes, |
| 153 kNo |
| 154 }; |
| 155 /** |
| 156 * Indicates that the geometry represented by the batch has zero area (i.e.
it is hairline |
| 157 * or points). |
| 158 */ |
| 159 enum class IsZeroArea { |
| 160 kYes, |
| 161 kNo |
| 162 }; |
| 163 void setBounds(const SkRect& newBounds, HasAABloat aabloat, IsZeroArea zeroA
rea) { |
| 164 fBounds = newBounds; |
| 165 this->setBoundsFlags(aabloat, zeroArea); |
| 166 } |
| 167 void setTransformedBounds(const SkRect& srcBounds, const SkMatrix& m, |
| 168 HasAABloat aabloat, IsZeroArea zeroArea) { |
| 169 m.mapRect(&fBounds, srcBounds); |
| 170 this->setBoundsFlags(aabloat, zeroArea); |
| 171 } |
| 135 | 172 |
| 136 void joinBounds(const SkRect& otherBounds) { | 173 void joinBounds(const GrBatch& that) { |
| 137 return fBounds.joinPossiblyEmptyRect(otherBounds); | 174 if (that.hasAABloat()) { |
| 175 fBoundsFlags |= kAABloat_BoundsFlag; |
| 176 } |
| 177 if (that.hasZeroArea()) { |
| 178 fBoundsFlags |= kZeroArea_BoundsFlag; |
| 179 } |
| 180 return fBounds.joinPossiblyEmptyRect(that.fBounds); |
| 181 } |
| 182 |
| 183 void replaceBounds(const GrBatch& that) { |
| 184 fBounds = that.fBounds; |
| 185 fBoundsFlags = that.fBoundsFlags; |
| 138 } | 186 } |
| 139 | 187 |
| 140 static uint32_t GenBatchClassID() { return GenID(&gCurrBatchClassID); } | 188 static uint32_t GenBatchClassID() { return GenID(&gCurrBatchClassID); } |
| 141 | 189 |
| 142 SkRect fBounds; | |
| 143 | |
| 144 private: | 190 private: |
| 145 virtual bool onCombineIfPossible(GrBatch*, const GrCaps& caps) = 0; | 191 virtual bool onCombineIfPossible(GrBatch*, const GrCaps& caps) = 0; |
| 146 | 192 |
| 147 virtual void onPrepare(GrBatchFlushState*) = 0; | 193 virtual void onPrepare(GrBatchFlushState*) = 0; |
| 148 virtual void onDraw(GrBatchFlushState*) = 0; | 194 virtual void onDraw(GrBatchFlushState*) = 0; |
| 149 | 195 |
| 150 static uint32_t GenID(int32_t* idCounter) { | 196 static uint32_t GenID(int32_t* idCounter) { |
| 151 // The atomic inc returns the old value not the incremented value. So we
add | 197 // The atomic inc returns the old value not the incremented value. So we
add |
| 152 // 1 to the returned value. | 198 // 1 to the returned value. |
| 153 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(idCounter)) + 1; | 199 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(idCounter)) + 1; |
| 154 if (!id) { | 200 if (!id) { |
| 155 SkFAIL("This should never wrap as it should only be called once for
each GrBatch " | 201 SkFAIL("This should never wrap as it should only be called once for
each GrBatch " |
| 156 "subclass."); | 202 "subclass."); |
| 157 } | 203 } |
| 158 return id; | 204 return id; |
| 159 } | 205 } |
| 160 | 206 |
| 207 void setBoundsFlags(HasAABloat aabloat, IsZeroArea zeroArea) { |
| 208 fBoundsFlags = 0; |
| 209 fBoundsFlags |= (HasAABloat::kYes == aabloat) ? kAABloat_BoundsFlag : 0; |
| 210 fBoundsFlags |= (IsZeroArea ::kYes == zeroArea) ? kZeroArea_BoundsFlag :
0; |
| 211 } |
| 212 |
| 161 enum { | 213 enum { |
| 162 kIllegalBatchID = 0, | 214 kIllegalBatchID = 0, |
| 163 }; | 215 }; |
| 164 | 216 |
| 217 enum BoundsFlags { |
| 218 kAABloat_BoundsFlag = 0x1, |
| 219 kZeroArea_BoundsFlag = 0x2, |
| 220 SkDEBUGCODE(kUninitialized_BoundsFlag = 0x4) |
| 221 }; |
| 222 |
| 165 SkDEBUGCODE(bool fUsed;) | 223 SkDEBUGCODE(bool fUsed;) |
| 166 const uint32_t fClassID; | 224 const uint16_t fClassID; |
| 225 uint16_t fBoundsFlags; |
| 226 |
| 167 static uint32_t GenBatchID() { return GenID(&gCurrBatchUniqueID); } | 227 static uint32_t GenBatchID() { return GenID(&gCurrBatchUniqueID); } |
| 168 mutable uint32_t fUniqueID; | 228 mutable uint32_t fUniqueID; |
| 229 SkRect fBounds; |
| 230 |
| 169 static int32_t gCurrBatchUniqueID; | 231 static int32_t gCurrBatchUniqueID; |
| 170 static int32_t gCurrBatchClassID; | 232 static int32_t gCurrBatchClassID; |
| 171 }; | 233 }; |
| 172 | 234 |
| 173 #endif | 235 #endif |
| OLD | NEW |