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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 , fIsLCDCoverage(io.fIsLCDCoverage) {} | 72 , fIsLCDCoverage(io.fIsLCDCoverage) {} |
73 | 73 |
74 virtual ~GrInvariantOutput() {} | 74 virtual ~GrInvariantOutput() {} |
75 | 75 |
76 enum ReadInput { | 76 enum ReadInput { |
77 kWill_ReadInput, | 77 kWill_ReadInput, |
78 kWillNot_ReadInput, | 78 kWillNot_ReadInput, |
79 }; | 79 }; |
80 | 80 |
81 void mulByUnknownOpaqueFourComponents() { | 81 void mulByUnknownOpaqueFourComponents() { |
82 SkDEBUGCODE(this->validate()); | |
83 if (this->isOpaque()) { | 82 if (this->isOpaque()) { |
84 fValidFlags = kA_GrColorComponentFlag; | 83 fValidFlags = kA_GrColorComponentFlag; |
85 fIsSingleComponent = false; | 84 fIsSingleComponent = false; |
86 } else { | 85 } else { |
87 // Since the current state is not opaque we no longer care if the co
lor being | 86 // Since the current state is not opaque we no longer care if the co
lor being |
88 // multiplied is opaque. | 87 // multiplied is opaque. |
89 this->mulByUnknownFourComponents(); | 88 this->mulByUnknownFourComponents(); |
90 } | 89 } |
91 SkDEBUGCODE(this->validate()); | |
92 } | 90 } |
93 | 91 |
94 void mulByUnknownFourComponents() { | 92 void mulByUnknownFourComponents() { |
95 SkDEBUGCODE(this->validate()); | |
96 if (this->hasZeroAlpha()) { | 93 if (this->hasZeroAlpha()) { |
97 this->internalSetToTransparentBlack(); | 94 this->internalSetToTransparentBlack(); |
98 } else { | 95 } else { |
99 this->internalSetToUnknown(); | 96 this->internalSetToUnknown(); |
100 } | 97 } |
101 SkDEBUGCODE(this->validate()); | |
102 } | 98 } |
103 | 99 |
104 void mulByUnknownSingleComponent() { | 100 void mulByUnknownSingleComponent() { |
105 SkDEBUGCODE(this->validate()); | |
106 if (this->hasZeroAlpha()) { | 101 if (this->hasZeroAlpha()) { |
107 this->internalSetToTransparentBlack(); | 102 this->internalSetToTransparentBlack(); |
108 } else { | 103 } else { |
109 // We don't need to change fIsSingleComponent in this case | 104 // We don't need to change fIsSingleComponent in this case |
110 fValidFlags = 0; | 105 fValidFlags = 0; |
111 } | 106 } |
112 SkDEBUGCODE(this->validate()); | |
113 } | 107 } |
114 | 108 |
115 void mulByKnownSingleComponent(uint8_t alpha) { | 109 void mulByKnownSingleComponent(uint8_t alpha) { |
116 SkDEBUGCODE(this->validate()); | |
117 if (this->hasZeroAlpha() || 0 == alpha) { | 110 if (this->hasZeroAlpha() || 0 == alpha) { |
118 this->internalSetToTransparentBlack(); | 111 this->internalSetToTransparentBlack(); |
119 } else { | 112 } else { |
120 if (alpha != 255) { | 113 if (alpha != 255) { |
121 // Multiply color by alpha | 114 // Multiply color by alpha |
122 fColor = GrColorPackRGBA(SkMulDiv255Round(GrColorUnpackR(fColor)
, alpha), | 115 fColor = GrColorPackRGBA(SkMulDiv255Round(GrColorUnpackR(fColor)
, alpha), |
123 SkMulDiv255Round(GrColorUnpackG(fColor)
, alpha), | 116 SkMulDiv255Round(GrColorUnpackG(fColor)
, alpha), |
124 SkMulDiv255Round(GrColorUnpackB(fColor)
, alpha), | 117 SkMulDiv255Round(GrColorUnpackB(fColor)
, alpha), |
125 SkMulDiv255Round(GrColorUnpackA(fColor)
, alpha)); | 118 SkMulDiv255Round(GrColorUnpackA(fColor)
, alpha)); |
126 // We don't need to change fIsSingleComponent in this case | |
127 } | 119 } |
128 } | 120 } |
129 SkDEBUGCODE(this->validate()); | |
130 } | |
131 | |
132 void mulByKnownFourComponents(GrColor color) { | |
133 SkDEBUGCODE(this->validate()); | |
134 uint32_t a; | |
135 if (GetAlphaAndCheckSingleChannel(color, &a)) { | |
136 this->mulByKnownSingleComponent(a); | |
137 } else { | |
138 if (color != 0xffffffff) { | |
139 fColor = GrColorPackRGBA( | |
140 SkMulDiv255Round(GrColorUnpackR(fColor), GrColorUnpackR(colo
r)), | |
141 SkMulDiv255Round(GrColorUnpackG(fColor), GrColorUnpackG(colo
r)), | |
142 SkMulDiv255Round(GrColorUnpackB(fColor), GrColorUnpackB(colo
r)), | |
143 SkMulDiv255Round(GrColorUnpackA(fColor), a)); | |
144 if (kRGBA_GrColorComponentFlags == fValidFlags) { | |
145 fIsSingleComponent = GetAlphaAndCheckSingleChannel(fColor, &
a); | |
146 } | |
147 } | |
148 } | |
149 SkDEBUGCODE(this->validate()); | |
150 } | |
151 | |
152 // Ignores the incoming color's RGB and muls its alpha by color. | |
153 void mulAlphaByKnownFourComponents(GrColor color) { | |
154 SkDEBUGCODE(this->validate()); | |
155 uint32_t a; | |
156 if (GetAlphaAndCheckSingleChannel(color, &a)) { | |
157 this->mulAlphaByKnownSingleComponent(a); | |
158 } else if (fValidFlags & kA_GrColorComponentFlag) { | |
159 GrColor preAlpha = GrColorUnpackA(fColor); | |
160 if (0 == preAlpha) { | |
161 this->internalSetToTransparentBlack(); | |
162 } else { | |
163 fColor = GrColorPackRGBA( | |
164 SkMulDiv255Round(preAlpha, GrColorUnpackR(color)), | |
165 SkMulDiv255Round(preAlpha, GrColorUnpackG(color)), | |
166 SkMulDiv255Round(preAlpha, GrColorUnpackB(color)), | |
167 SkMulDiv255Round(preAlpha, a)); | |
168 fValidFlags = kRGBA_GrColorComponentFlags; | |
169 } | |
170 } else { | |
171 fValidFlags = 0; | |
172 } | |
173 SkDEBUGCODE(this->validate()); | |
174 } | |
175 | |
176 // Ignores the incoming color's RGB and muls its alpha by the alpha param an
d sets all channels | |
177 // equal to that value. | |
178 void mulAlphaByKnownSingleComponent(uint8_t alpha) { | |
179 SkDEBUGCODE(this->validate()); | |
180 if (0 == alpha || this->hasZeroAlpha()) { | |
181 this->internalSetToTransparentBlack(); | |
182 } else { | |
183 if (fValidFlags & kA_GrColorComponentFlag) { | |
184 GrColor a = GrColorUnpackA(fColor); | |
185 a = SkMulDiv255Round(alpha, a); | |
186 fColor = GrColorPackRGBA(a, a, a, a); | |
187 fValidFlags = kRGBA_GrColorComponentFlags; | |
188 } else { | |
189 fValidFlags = 0; | |
190 } | |
191 fIsSingleComponent = true; | |
192 } | |
193 SkDEBUGCODE(this->validate()); | |
194 } | 121 } |
195 | 122 |
196 void invalidateComponents(uint8_t invalidateFlags, ReadInput readsInput) { | 123 void invalidateComponents(uint8_t invalidateFlags, ReadInput readsInput) { |
197 SkDEBUGCODE(this->validate()); | |
198 fValidFlags &= ~invalidateFlags; | 124 fValidFlags &= ~invalidateFlags; |
199 fIsSingleComponent = false; | 125 fIsSingleComponent = false; |
200 fNonMulStageFound = true; | 126 fNonMulStageFound = true; |
201 if (kWillNot_ReadInput == readsInput) { | 127 if (kWillNot_ReadInput == readsInput) { |
202 fWillUseInputColor = false; | 128 fWillUseInputColor = false; |
203 } | 129 } |
204 SkDEBUGCODE(this->validate()); | |
205 } | 130 } |
206 | 131 |
207 void setToOther(uint8_t validFlags, GrColor color, ReadInput readsInput) { | 132 void setToOther(uint8_t validFlags, GrColor color, ReadInput readsInput) { |
208 SkDEBUGCODE(this->validate()); | |
209 fValidFlags = validFlags; | 133 fValidFlags = validFlags; |
210 fColor = color; | 134 fColor = color; |
211 fIsSingleComponent = false; | 135 fIsSingleComponent = false; |
212 fNonMulStageFound = true; | 136 fNonMulStageFound = true; |
213 if (kWillNot_ReadInput == readsInput) { | 137 if (kWillNot_ReadInput == readsInput) { |
214 fWillUseInputColor = false; | 138 fWillUseInputColor = false; |
215 } | 139 } |
216 if (kRGBA_GrColorComponentFlags == fValidFlags) { | |
217 uint32_t a; | |
218 if (GetAlphaAndCheckSingleChannel(color, &a)) { | |
219 fIsSingleComponent = true; | |
220 } | |
221 } else if (kA_GrColorComponentFlag & fValidFlags) { | |
222 // Assuming fColor is premul means if a is 0 the color must be all 0
s. | |
223 if (!GrColorUnpackA(fColor)) { | |
224 this->internalSetToTransparentBlack(); | |
225 } | |
226 } | |
227 SkDEBUGCODE(this->validate()); | |
228 } | 140 } |
229 | 141 |
230 void setToUnknown(ReadInput readsInput) { | 142 void setToUnknown(ReadInput readsInput) { |
231 SkDEBUGCODE(this->validate()); | |
232 this->internalSetToUnknown(); | 143 this->internalSetToUnknown(); |
233 fNonMulStageFound= true; | 144 fNonMulStageFound= true; |
234 if (kWillNot_ReadInput == readsInput) { | 145 if (kWillNot_ReadInput == readsInput) { |
235 fWillUseInputColor = false; | 146 fWillUseInputColor = false; |
236 } | 147 } |
237 SkDEBUGCODE(this->validate()); | |
238 } | 148 } |
239 | 149 |
240 // Temporary setter to handle LCD text correctly until we improve texture pi
xel config queries | 150 // Temporary setter to handle LCD text correctly until we improve texture pi
xel config queries |
241 // and thus can rely solely on number of coverage components for RGA vs sing
le channel coverage. | 151 // and thus can rely solely on number of coverage components for RGA vs sing
le channel coverage. |
242 void setUsingLCDCoverage() { | 152 void setUsingLCDCoverage() { |
243 fIsLCDCoverage = true; | 153 fIsLCDCoverage = true; |
244 } | 154 } |
245 | 155 |
246 GrColor color() const { return fColor; } | 156 GrColor color() const { return fColor; } |
247 uint8_t validFlags() const { return fValidFlags; } | 157 uint8_t validFlags() const { return fValidFlags; } |
248 | 158 |
249 /** | 159 /** |
250 * If isSingleComponent is true, then the flag values for r, g, b, and a mus
t all be the | 160 * If isSingleComponent is true, then the flag values for r, g, b, and a mus
t all be the |
251 * same. If the flags are all set then all color components must be equal. | 161 * same. If the flags are all set then all color components must be equal. |
252 */ | 162 */ |
253 SkDEBUGCODE(void validate() const;) | 163 SkDEBUGCODE(void validate() const;) |
254 | 164 |
255 private: | 165 private: |
256 friend class GrProcOptInfo; | 166 friend class GrProcOptInfo; |
257 | 167 |
258 /** Extracts the alpha channel and returns true if r,g,b == a. */ | |
259 static bool GetAlphaAndCheckSingleChannel(GrColor color, uint32_t* alpha) { | |
260 *alpha = GrColorUnpackA(color); | |
261 return *alpha == GrColorUnpackR(color) && *alpha == GrColorUnpackG(color
) && | |
262 *alpha == GrColorUnpackB(color); | |
263 } | |
264 | |
265 void reset(GrColor color, GrColorComponentFlags flags, bool isSingleComponen
t) { | 168 void reset(GrColor color, GrColorComponentFlags flags, bool isSingleComponen
t) { |
266 fColor = color; | 169 fColor = color; |
267 fValidFlags = flags; | 170 fValidFlags = flags; |
268 fIsSingleComponent = isSingleComponent; | 171 fIsSingleComponent = isSingleComponent; |
269 fNonMulStageFound = false; | 172 fNonMulStageFound = false; |
270 fWillUseInputColor = true; | 173 fWillUseInputColor = true; |
271 } | 174 } |
272 | 175 |
273 void reset(const GrInitInvariantOutput& io) { | 176 void reset(const GrInitInvariantOutput& io) { |
274 fColor = io.fColor; | 177 fColor = io.fColor; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 uint32_t fValidFlags; | 225 uint32_t fValidFlags; |
323 bool fIsSingleComponent; | 226 bool fIsSingleComponent; |
324 bool fNonMulStageFound; | 227 bool fNonMulStageFound; |
325 bool fWillUseInputColor; | 228 bool fWillUseInputColor; |
326 bool fIsLCDCoverage; // Temorary data member until texture pixel configs are
updated | 229 bool fIsLCDCoverage; // Temorary data member until texture pixel configs are
updated |
327 | 230 |
328 }; | 231 }; |
329 | 232 |
330 #endif | 233 #endif |
331 | 234 |
OLD | NEW |