Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(634)

Side by Side Diff: include/gpu/GrInvariantOutput.h

Issue 978713002: Add constant color GrFP. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 if (0 == color) {
egdaniel 2015/03/04 20:22:34 we definitely don't need the 0 check here since it
bsalomon 2015/03/31 19:33:42 Done.
131 this->internalSetToTransparentBlack();
132 } else {
133 if (color != 0xffffffff) {
134 fColor = GrColorPackRGBA(
135 SkMulDiv255Round(GrColorUnpackR(fColor), GrColorUnpackR(colo r)),
136 SkMulDiv255Round(GrColorUnpackG(fColor), GrColorUnpackG(colo r)),
137 SkMulDiv255Round(GrColorUnpackB(fColor), GrColorUnpackB(colo r)),
138 SkMulDiv255Round(GrColorUnpackA(fColor), GrColorUnpackA(colo r)));
139 if (kRGBA_GrColorComponentFlags == fValidFlags) {
140 GrColor a = GrColorUnpackA(fColor);
141 fIsSingleComponent = a == GrColorUnpackR(fColor) &&
142 a == GrColorUnpackG(fColor) &&
143 a == GrColorUnpackB(fColor);
144 }
145 }
146 }
147 }
148
149 // Ignores the incoming color's RGB and muls its alpha by color.
150 void mulAlphaByKnownFourComponents(GrColor color) {
151 GrColor a = GrColorUnpackA(color);
152 if (a == GrColorUnpackR(color) &&
153 a == GrColorUnpackG(color) &&
154 a == GrColorUnpackB(color)) {
155 this->mulAlphaByKnownSingleComponent(a);
156 } else if (0 == color) {
egdaniel 2015/03/04 20:22:34 same as above.
bsalomon 2015/03/31 19:33:42 Done.
157 this->internalSetToTransparentBlack();
158 } else if (fValidFlags & kA_GrColorComponentFlag) {
159 GrColor alpha = GrColorUnpackA(fColor);
160 if (0 == alpha) {
161 this->internalSetToTransparentBlack();
162 } else {
163 fColor = GrColorPackRGBA(
164 SkMulDiv255Round(alpha, GrColorUnpackR(color)),
165 SkMulDiv255Round(alpha, GrColorUnpackG(color)),
166 SkMulDiv255Round(alpha, GrColorUnpackB(color)),
167 SkMulDiv255Round(alpha, GrColorUnpackA(color)));
168 fValidFlags = kRGBA_GrColorComponentFlags;
169 }
170 } else {
171 fValidFlags = 0;
172 }
173 }
174
175 // Ignores the incoming color's RGB and muls its alpha by the alpha param an d sets all channels
176 // equal to that value.
177 void mulAlphaByKnownSingleComponent(uint8_t alpha) {
178 if (0 == alpha || 0 == this->hasZeroAlpha()) {
179 this->internalSetToTransparentBlack();
180 } else {
181 if (fValidFlags & kA_GrColorComponentFlag) {
182 GrColor a = GrColorUnpackA(fColor);
183 a = SkMulDiv255Round(alpha, a);
184 fColor = GrColorPackRGBA(a, a, a, a);
185 fValidFlags = kRGBA_GrColorComponentFlags;
186 } else {
187 fValidFlags = 0;
188 }
189 fIsSingleComponent = true;
190 }
191 }
192
123 void invalidateComponents(uint8_t invalidateFlags, ReadInput readsInput) { 193 void invalidateComponents(uint8_t invalidateFlags, ReadInput readsInput) {
124 fValidFlags &= ~invalidateFlags; 194 fValidFlags &= ~invalidateFlags;
125 fIsSingleComponent = false; 195 fIsSingleComponent = false;
126 fNonMulStageFound = true; 196 fNonMulStageFound = true;
127 if (kWillNot_ReadInput == readsInput) { 197 if (kWillNot_ReadInput == readsInput) {
128 fWillUseInputColor = false; 198 fWillUseInputColor = false;
129 } 199 }
130 } 200 }
131 201
132 void setToOther(uint8_t validFlags, GrColor color, ReadInput readsInput) { 202 void setToOther(uint8_t validFlags, GrColor color, ReadInput readsInput) {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 uint32_t fValidFlags; 295 uint32_t fValidFlags;
226 bool fIsSingleComponent; 296 bool fIsSingleComponent;
227 bool fNonMulStageFound; 297 bool fNonMulStageFound;
228 bool fWillUseInputColor; 298 bool fWillUseInputColor;
229 bool fIsLCDCoverage; // Temorary data member until texture pixel configs are updated 299 bool fIsLCDCoverage; // Temorary data member until texture pixel configs are updated
230 300
231 }; 301 };
232 302
233 #endif 303 #endif
234 304
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698