diff options
author | 2014-10-13 12:53:46 -0700 | |
---|---|---|
committer | 2014-10-13 12:53:46 -0700 | |
commit | ccb2e384a036f29d989d3c1468f879324e81a678 (patch) | |
tree | 27e38ca2ad78e3a0f741a1cc6c23899eb22b822c /include | |
parent | cad5d3e264535c919b80e1e2a85407307961f221 (diff) |
Create helper functions to use in computeInvariantOutput calls
BUG=skia:
Review URL: https://codereview.chromium.org/643743003
Diffstat (limited to 'include')
-rw-r--r-- | include/gpu/GrProcessor.h | 73 |
1 files changed, 68 insertions, 5 deletions
diff --git a/include/gpu/GrProcessor.h b/include/gpu/GrProcessor.h index a5c834168b..6b1d1e370c 100644 --- a/include/gpu/GrProcessor.h +++ b/include/gpu/GrProcessor.h @@ -38,12 +38,58 @@ public: virtual ~GrProcessor(); struct InvariantOutput{ - GrColor fColor; - uint32_t fValidFlags; - bool fIsSingleComponent; - InvariantOutput() : fColor(0), fValidFlags(0), fIsSingleComponent(false) {} + void mulByUnknownOpaqueColor() { + if (this->isOpaque()) { + fValidFlags = kA_GrColorComponentFlag; + fIsSingleComponent = false; + } else { + // Since the current state is not opaque we no longer care if the color being + // multiplied is opaque. + this->mulByUnknownColor(); + } + } + + void mulByUnknownColor() { + if (this->hasZeroAlpha()) { + this->setToTransparentBlack(); + } else { + this->setToUnknown(); + } + } + + void mulByUnknownAlpha() { + if (this->hasZeroAlpha()) { + this->setToTransparentBlack(); + } else { + // We don't need to change fIsSingleComponent in this case + fValidFlags = 0; + } + } + + void invalidateComponents(uint8_t invalidateFlags) { + fValidFlags &= ~invalidateFlags; + fIsSingleComponent = false; + } + + void setToTransparentBlack() { + fValidFlags = kRGBA_GrColorComponentFlags; + fColor = 0; + fIsSingleComponent = true; + } + + void setToOther(uint8_t validFlags, GrColor color) { + fValidFlags = validFlags; + fColor = color; + fIsSingleComponent = false; + } + + void setToUnknown() { + fValidFlags = 0; + fIsSingleComponent = false; + } + bool isOpaque() const { return ((fValidFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUnpackA(fColor)); } @@ -52,6 +98,9 @@ public: return (fValidFlags == kRGBA_GrColorComponentFlags && 0xFFFFFFFF == fColor); } + GrColor color() const { return fColor; } + uint8_t validFlags() const { return fValidFlags; } + /** * If isSingleComponent is true, then the flag values for r, g, b, and a must all be the * same. If the flags are all set then all color components must be equal. @@ -59,12 +108,26 @@ public: SkDEBUGCODE(void validate() const;) private: - SkDEBUGCODE(bool colorComponentsAllEqual() const;) + bool hasZeroAlpha() const { + return ((fValidFlags & kA_GrColorComponentFlag) && 0 == GrColorUnpackA(fColor)); + } + SkDEBUGCODE(bool colorComponentsAllEqual() const;) /** * If alpha is valid, check that any valid R,G,B values are <= A */ SkDEBUGCODE(bool validPreMulColor() const;) + + // Friended class that have "controller" code which loop over stages calling + // computeInvarianteOutput(). These controllers may need to manually adjust the internal + // members of InvariantOutput + friend class GrDrawState; + friend class GrOptDrawState; + friend class GrPaint; + + GrColor fColor; + uint32_t fValidFlags; + bool fIsSingleComponent; }; /** |