Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2014 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 #ifndef GrInvariantOutput_DEFINED | |
| 9 #define GrInvariantOutput_DEFINED | |
| 10 | |
| 11 #include "GrColor.h" | |
| 12 | |
| 13 class GrInvariantOutput{ | |
|
bsalomon
2014/11/04 19:57:05
missing space
| |
| 14 public: | |
| 15 GrInvariantOutput() : fColor(0), fValidFlags(0), fIsSingleComponent(false), | |
| 16 fNonMulStageFound(false), fWillUseInputColor(true) {} | |
| 17 | |
| 18 enum ReadInput { | |
| 19 kWill_ReadInput, | |
| 20 kWillNot_ReadInput, | |
| 21 }; | |
| 22 | |
| 23 void mulByUnknownOpaqueColor() { | |
| 24 if (this->isOpaque()) { | |
| 25 fValidFlags = kA_GrColorComponentFlag; | |
| 26 fIsSingleComponent = false; | |
| 27 } else { | |
| 28 // Since the current state is not opaque we no longer care if the co lor being | |
| 29 // multiplied is opaque. | |
| 30 this->mulByUnknownColor(); | |
| 31 } | |
| 32 } | |
| 33 | |
| 34 void mulByUnknownColor() { | |
| 35 if (this->hasZeroAlpha()) { | |
| 36 this->internalSetToTransparentBlack(); | |
| 37 } else { | |
| 38 this->internalSetToUnknown(); | |
| 39 } | |
| 40 } | |
| 41 | |
| 42 void mulByUnknownAlpha() { | |
| 43 if (this->hasZeroAlpha()) { | |
| 44 this->internalSetToTransparentBlack(); | |
| 45 } else { | |
| 46 // We don't need to change fIsSingleComponent in this case | |
| 47 fValidFlags = 0; | |
| 48 } | |
| 49 } | |
| 50 | |
| 51 void mulByKnownAlpha(uint8_t alpha) { | |
| 52 if (this->hasZeroAlpha() || 0 == alpha) { | |
| 53 this->internalSetToTransparentBlack(); | |
| 54 } else { | |
| 55 if (alpha != 255) { | |
| 56 // Multiply color by alpha | |
| 57 fColor = GrColorPackRGBA(SkMulDiv255Round(GrColorUnpackR(fColor) , alpha), | |
| 58 SkMulDiv255Round(GrColorUnpackG(fColor) , alpha), | |
| 59 SkMulDiv255Round(GrColorUnpackB(fColor) , alpha), | |
| 60 SkMulDiv255Round(GrColorUnpackA(fColor) , alpha)); | |
| 61 } | |
| 62 } | |
| 63 } | |
| 64 | |
| 65 void invalidateComponents(uint8_t invalidateFlags, ReadInput readsInput) { | |
| 66 fValidFlags &= ~invalidateFlags; | |
| 67 fIsSingleComponent = false; | |
| 68 if (kWillNot_ReadInput == readsInput) { | |
| 69 fWillUseInputColor = false; | |
| 70 } | |
| 71 } | |
| 72 | |
| 73 void setToOther(uint8_t validFlags, GrColor color, ReadInput readsInput) { | |
| 74 fValidFlags = validFlags; | |
| 75 fColor = color; | |
| 76 fIsSingleComponent = false; | |
| 77 fNonMulStageFound = true; | |
| 78 if (kWillNot_ReadInput == readsInput) { | |
| 79 fWillUseInputColor = false; | |
| 80 } | |
| 81 } | |
| 82 | |
| 83 void setToUnknown(ReadInput readsInput) { | |
| 84 this->internalSetToUnknown(); | |
| 85 fNonMulStageFound= true; | |
| 86 if (kWillNot_ReadInput == readsInput) { | |
| 87 fWillUseInputColor = false; | |
| 88 } | |
| 89 } | |
| 90 | |
| 91 bool isOpaque() const { | |
| 92 return ((fValidFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUnpack A(fColor)); | |
| 93 } | |
| 94 | |
| 95 bool isSolidWhite() const { | |
| 96 return (fValidFlags == kRGBA_GrColorComponentFlags && 0xFFFFFFFF == fCol or); | |
| 97 } | |
| 98 | |
| 99 GrColor color() const { return fColor; } | |
| 100 uint8_t validFlags() const { return fValidFlags; } | |
| 101 | |
| 102 /** | |
| 103 * If isSingleComponent is true, then the flag values for r, g, b, and a mus t all be the | |
| 104 * same. If the flags are all set then all color components must be equal. | |
| 105 */ | |
| 106 SkDEBUGCODE(void validate() const;) | |
| 107 | |
| 108 private: | |
| 109 void internalSetToTransparentBlack() { | |
| 110 fValidFlags = kRGBA_GrColorComponentFlags; | |
| 111 fColor = 0; | |
| 112 fIsSingleComponent = true; | |
| 113 } | |
| 114 | |
| 115 void internalSetToUnknown() { | |
| 116 fValidFlags = 0; | |
| 117 fIsSingleComponent = false; | |
| 118 } | |
| 119 | |
| 120 bool hasZeroAlpha() const { | |
| 121 return ((fValidFlags & kA_GrColorComponentFlag) && 0 == GrColorUnpackA(f Color)); | |
| 122 } | |
| 123 | |
| 124 SkDEBUGCODE(bool colorComponentsAllEqual() const;) | |
| 125 /** | |
| 126 * If alpha is valid, check that any valid R,G,B values are <= A | |
| 127 */ | |
| 128 SkDEBUGCODE(bool validPreMulColor() const;) | |
| 129 | |
| 130 // Friended class that have "controller" code which loop over stages calling | |
| 131 // computeInvarianteOutput(). These controllers may need to manually adjust the internal | |
| 132 // members of InvariantOutput | |
| 133 friend class GrDrawState; | |
| 134 friend class GrOptDrawState; | |
| 135 friend class GrPaint; | |
| 136 friend class GrProcessor; | |
|
bsalomon
2014/11/04 19:57:05
curious why GrProc needs this?
Can some of these
| |
| 137 | |
| 138 GrColor fColor; | |
| 139 uint32_t fValidFlags; | |
| 140 bool fIsSingleComponent; | |
| 141 bool fNonMulStageFound; | |
| 142 bool fWillUseInputColor; | |
| 143 }; | |
| 144 | |
| 145 #endif | |
| 146 | |
| OLD | NEW |