Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 GrInvariantOutput_DEFINED | 8 #ifndef GrInvariantOutput_DEFINED |
| 9 #define GrInvariantOutput_DEFINED | 9 #define GrInvariantOutput_DEFINED |
| 10 | 10 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 void mulByKnownSingleComponent(uint8_t alpha) { | 109 void mulByKnownSingleComponent(uint8_t alpha) { |
| 110 if (this->hasZeroAlpha() || 0 == alpha) { | 110 if (this->hasZeroAlpha() || 0 == alpha) { |
| 111 this->internalSetToTransparentBlack(); | 111 this->internalSetToTransparentBlack(); |
| 112 } else { | 112 } else { |
| 113 if (alpha != 255) { | 113 if (alpha != 255) { |
| 114 // Multiply color by alpha | 114 // Multiply color by alpha |
| 115 fColor = GrColorPackRGBA(SkMulDiv255Round(GrColorUnpackR(fColor) , alpha), | 115 fColor = GrColorPackRGBA(SkMulDiv255Round(GrColorUnpackR(fColor) , alpha), |
| 116 SkMulDiv255Round(GrColorUnpackG(fColor) , alpha), | 116 SkMulDiv255Round(GrColorUnpackG(fColor) , alpha), |
| 117 SkMulDiv255Round(GrColorUnpackB(fColor) , alpha), | 117 SkMulDiv255Round(GrColorUnpackB(fColor) , alpha), |
| 118 SkMulDiv255Round(GrColorUnpackA(fColor) , alpha)); | 118 SkMulDiv255Round(GrColorUnpackA(fColor) , alpha)); |
| 119 // We don't need to change fIsSingleComponent in this case | |
| 119 } | 120 } |
| 120 } | 121 } |
| 121 } | 122 } |
| 122 | 123 |
| 124 void mulByKnownFourComponents(GrColor color) { | |
| 125 GrColor a = GrColorUnpackA(color); | |
| 126 if (a == GrColorUnpackR(color) && | |
| 127 a == GrColorUnpackG(color) && | |
| 128 a == GrColorUnpackB(color)) { | |
| 129 this->mulByKnownSingleComponent(a); | |
| 130 } else { | |
| 131 if (color != 0xffffffff) { | |
| 132 fColor = GrColorPackRGBA( | |
| 133 SkMulDiv255Round(GrColorUnpackR(fColor), GrColorUnpackR(colo r)), | |
| 134 SkMulDiv255Round(GrColorUnpackG(fColor), GrColorUnpackG(colo r)), | |
| 135 SkMulDiv255Round(GrColorUnpackB(fColor), GrColorUnpackB(colo r)), | |
| 136 SkMulDiv255Round(GrColorUnpackA(fColor), GrColorUnpackA(colo r))); | |
| 137 if (kRGBA_GrColorComponentFlags == fValidFlags) { | |
| 138 GrColor a = GrColorUnpackA(fColor); | |
| 139 fIsSingleComponent = a == GrColorUnpackR(fColor) && | |
| 140 a == GrColorUnpackG(fColor) && | |
| 141 a == GrColorUnpackB(fColor); | |
| 142 } | |
| 143 } | |
| 144 } | |
| 145 } | |
| 146 | |
| 147 // Ignores the incoming color's RGB and muls its alpha by color. | |
| 148 void mulAlphaByKnownFourComponents(GrColor color) { | |
| 149 GrColor a = GrColorUnpackA(color); | |
| 150 if (a == GrColorUnpackR(color) && | |
| 151 a == GrColorUnpackG(color) && | |
| 152 a == GrColorUnpackB(color)) { | |
| 153 this->mulAlphaByKnownSingleComponent(a); | |
| 154 } else if (fValidFlags & kA_GrColorComponentFlag) { | |
| 155 GrColor alpha = GrColorUnpackA(fColor); | |
| 156 if (0 == alpha) { | |
| 157 this->internalSetToTransparentBlack(); | |
| 158 } else { | |
| 159 fColor = GrColorPackRGBA( | |
| 160 SkMulDiv255Round(alpha, GrColorUnpackR(color)), | |
| 161 SkMulDiv255Round(alpha, GrColorUnpackG(color)), | |
| 162 SkMulDiv255Round(alpha, GrColorUnpackB(color)), | |
| 163 SkMulDiv255Round(alpha, GrColorUnpackA(color))); | |
| 164 fValidFlags = kRGBA_GrColorComponentFlags; | |
| 165 } | |
| 166 } else { | |
| 167 fValidFlags = 0; | |
| 168 } | |
| 169 } | |
| 170 | |
| 171 // Ignores the incoming color's RGB and muls its alpha by the alpha param an d sets all channels | |
| 172 // equal to that value. | |
| 173 void mulAlphaByKnownSingleComponent(uint8_t alpha) { | |
| 174 if (0 == alpha || 0 == this->hasZeroAlpha()) { | |
| 175 this->internalSetToTransparentBlack(); | |
| 176 } else { | |
| 177 if (fValidFlags & kA_GrColorComponentFlag) { | |
| 178 GrColor a = GrColorUnpackA(fColor); | |
| 179 a = SkMulDiv255Round(alpha, a); | |
| 180 fColor = GrColorPackRGBA(a, a, a, a); | |
| 181 fValidFlags = kRGBA_GrColorComponentFlags; | |
| 182 } else { | |
| 183 fValidFlags = 0; | |
| 184 } | |
| 185 fIsSingleComponent = true; | |
| 186 } | |
| 187 } | |
| 188 | |
| 123 void invalidateComponents(uint8_t invalidateFlags, ReadInput readsInput) { | 189 void invalidateComponents(uint8_t invalidateFlags, ReadInput readsInput) { |
| 124 fValidFlags &= ~invalidateFlags; | 190 fValidFlags &= ~invalidateFlags; |
| 125 fIsSingleComponent = false; | 191 fIsSingleComponent = false; |
| 126 fNonMulStageFound = true; | 192 fNonMulStageFound = true; |
| 127 if (kWillNot_ReadInput == readsInput) { | 193 if (kWillNot_ReadInput == readsInput) { |
| 128 fWillUseInputColor = false; | 194 fWillUseInputColor = false; |
| 129 } | 195 } |
| 130 } | 196 } |
| 131 | 197 |
| 132 void setToOther(uint8_t validFlags, GrColor color, ReadInput readsInput) { | 198 void setToOther(uint8_t validFlags, GrColor color, ReadInput readsInput) { |
| 133 fValidFlags = validFlags; | 199 fValidFlags = validFlags; |
| 134 fColor = color; | 200 fColor = color; |
| 135 fIsSingleComponent = false; | 201 fIsSingleComponent = false; |
| 136 fNonMulStageFound = true; | 202 fNonMulStageFound = true; |
| 137 if (kWillNot_ReadInput == readsInput) { | 203 if (kWillNot_ReadInput == readsInput) { |
| 138 fWillUseInputColor = false; | 204 fWillUseInputColor = false; |
| 139 } | 205 } |
| 206 if (kRGBA_GrColorComponentFlags == fValidFlags) { | |
| 207 GrColor a = GrColorUnpackA(fColor); | |
|
egdaniel
2015/03/31 21:02:54
Maybe we should create some shared helper that can
bsalomon
2015/04/01 19:54:27
Done.
| |
| 208 if (GrColorUnpackR(fColor) == a && | |
| 209 GrColorUnpackG(fColor) == a && | |
| 210 GrColorUnpackB(fColor) == a) { | |
| 211 fIsSingleComponent = true; | |
| 212 } | |
| 213 } else if (kA_GrColorComponentFlag & fValidFlags) { | |
| 214 // Assuming fColor is premul means if a is 0 the color | |
| 215 // must be all 0s. | |
| 216 if (!GrColorUnpackA(fColor)) { | |
| 217 SkASSERT(!(kR_GrColorComponentFlag & fValidFlags) || !GrColorUnp ackR(fColor)); | |
|
egdaniel
2015/03/31 21:02:54
are there asserts really needed? seems like we are
bsalomon
2015/04/01 19:54:26
I think if we're going to assume that we're always
| |
| 218 SkASSERT(!(kG_GrColorComponentFlag & fValidFlags) || !GrColorUnp ackG(fColor)); | |
| 219 SkASSERT(!(kB_GrColorComponentFlag & fValidFlags) || !GrColorUnp ackB(fColor)); | |
| 220 fColor = 0; | |
|
egdaniel
2015/03/31 21:02:54
just call internalSetToTransparentBlacK()?
| |
| 221 fIsSingleComponent = true; | |
| 222 fValidFlags = kRGBA_GrColorComponentFlags; | |
| 223 } | |
| 224 } | |
| 140 } | 225 } |
| 141 | 226 |
| 142 void setToUnknown(ReadInput readsInput) { | 227 void setToUnknown(ReadInput readsInput) { |
| 143 this->internalSetToUnknown(); | 228 this->internalSetToUnknown(); |
| 144 fNonMulStageFound= true; | 229 fNonMulStageFound= true; |
| 145 if (kWillNot_ReadInput == readsInput) { | 230 if (kWillNot_ReadInput == readsInput) { |
| 146 fWillUseInputColor = false; | 231 fWillUseInputColor = false; |
| 147 } | 232 } |
| 148 } | 233 } |
| 149 | 234 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 225 uint32_t fValidFlags; | 310 uint32_t fValidFlags; |
| 226 bool fIsSingleComponent; | 311 bool fIsSingleComponent; |
| 227 bool fNonMulStageFound; | 312 bool fNonMulStageFound; |
| 228 bool fWillUseInputColor; | 313 bool fWillUseInputColor; |
| 229 bool fIsLCDCoverage; // Temorary data member until texture pixel configs are updated | 314 bool fIsLCDCoverage; // Temorary data member until texture pixel configs are updated |
| 230 | 315 |
| 231 }; | 316 }; |
| 232 | 317 |
| 233 #endif | 318 #endif |
| 234 | 319 |
| OLD | NEW |