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 |
11 #include "GrColor.h" | 11 #include "GrColor.h" |
12 | 12 |
13 struct GrInitInvariantOutput { | |
14 GrInitInvariantOutput() | |
15 : fValidFlags(0) | |
16 , fColor(0) | |
17 , fIsSingleComponent(false) | |
18 , fIsLCDCoverage(false) {} | |
19 | |
20 void setKnownFourComponents(GrColor color) { | |
21 fColor = color; | |
22 fValidFlags = kRGBA_GrColorComponentFlags; | |
23 fIsSingleComponent = false; | |
24 } | |
25 | |
26 void setUnknownFourComponents() { | |
27 fValidFlags = 0; | |
28 fIsSingleComponent = false; | |
29 } | |
30 | |
31 void setUnknownOpaqueFourComponents() { | |
32 fColor = 0xff << GrColor_SHIFT_A; | |
33 fValidFlags = kA_GrColorComponentFlag; | |
34 fIsSingleComponent = false; | |
35 } | |
36 | |
37 void setKnownSingleComponent(uint8_t alpha) { | |
38 fColor = GrColorPackRGBA(alpha, alpha, alpha, alpha); | |
39 fValidFlags = kRGBA_GrColorComponentFlags; | |
40 fIsSingleComponent = true; | |
41 } | |
42 | |
43 void setUnknownSingleComponent() { | |
44 fValidFlags = 0; | |
45 fIsSingleComponent = true; | |
46 } | |
47 | |
48 void setUsingLCDCoverage() { fIsLCDCoverage = true; } | |
49 | |
50 uint32_t fValidFlags; | |
51 GrColor fColor; | |
52 bool fIsSingleComponent; | |
53 bool fIsLCDCoverage; // Temorary data member until texture pixel configs are
updated | |
54 }; | |
55 | |
56 class GrInvariantOutput { | 13 class GrInvariantOutput { |
57 public: | 14 public: |
58 GrInvariantOutput(GrColor color, GrColorComponentFlags flags, bool isSingleC
omponent) | 15 GrInvariantOutput(GrColor color, GrColorComponentFlags flags, bool isSingleC
omponent) |
59 : fColor(color) | 16 : fColor(color) |
60 , fValidFlags(flags) | 17 , fValidFlags(flags) |
61 , fIsSingleComponent(isSingleComponent) | 18 , fIsSingleComponent(isSingleComponent) |
62 , fNonMulStageFound(false) | 19 , fNonMulStageFound(false) |
63 , fWillUseInputColor(true) | 20 , fWillUseInputColor(true) |
64 , fIsLCDCoverage(false) {} | 21 , fIsLCDCoverage(false) {} |
65 | 22 |
66 GrInvariantOutput(const GrInitInvariantOutput& io) | |
67 : fColor(io.fColor) | |
68 , fValidFlags(io.fValidFlags) | |
69 , fIsSingleComponent(io.fIsSingleComponent) | |
70 , fNonMulStageFound(false) | |
71 , fWillUseInputColor(false) | |
72 , fIsLCDCoverage(io.fIsLCDCoverage) {} | |
73 | |
74 virtual ~GrInvariantOutput() {} | 23 virtual ~GrInvariantOutput() {} |
75 | 24 |
76 enum ReadInput { | 25 enum ReadInput { |
77 kWill_ReadInput, | 26 kWill_ReadInput, |
78 kWillNot_ReadInput, | 27 kWillNot_ReadInput, |
79 }; | 28 }; |
80 | 29 |
81 void mulByUnknownOpaqueFourComponents() { | 30 void mulByUnknownOpaqueColor() { |
82 if (this->isOpaque()) { | 31 if (this->isOpaque()) { |
83 fValidFlags = kA_GrColorComponentFlag; | 32 fValidFlags = kA_GrColorComponentFlag; |
84 fIsSingleComponent = false; | 33 fIsSingleComponent = false; |
85 } else { | 34 } else { |
86 // Since the current state is not opaque we no longer care if the co
lor being | 35 // Since the current state is not opaque we no longer care if the co
lor being |
87 // multiplied is opaque. | 36 // multiplied is opaque. |
88 this->mulByUnknownFourComponents(); | 37 this->mulByUnknownColor(); |
89 } | 38 } |
90 } | 39 } |
91 | 40 |
92 void mulByUnknownFourComponents() { | 41 void mulByUnknownColor() { |
93 if (this->hasZeroAlpha()) { | 42 if (this->hasZeroAlpha()) { |
94 this->internalSetToTransparentBlack(); | 43 this->internalSetToTransparentBlack(); |
95 } else { | 44 } else { |
96 this->internalSetToUnknown(); | 45 this->internalSetToUnknown(); |
97 } | 46 } |
98 } | 47 } |
99 | 48 |
100 void mulByUnknownSingleComponent() { | 49 void mulByUnknownAlpha() { |
101 if (this->hasZeroAlpha()) { | 50 if (this->hasZeroAlpha()) { |
102 this->internalSetToTransparentBlack(); | 51 this->internalSetToTransparentBlack(); |
103 } else { | 52 } else { |
104 // We don't need to change fIsSingleComponent in this case | 53 // We don't need to change fIsSingleComponent in this case |
105 fValidFlags = 0; | 54 fValidFlags = 0; |
106 } | 55 } |
107 } | 56 } |
108 | 57 |
109 void mulByKnownSingleComponent(uint8_t alpha) { | 58 void mulByKnownAlpha(uint8_t alpha) { |
110 if (this->hasZeroAlpha() || 0 == alpha) { | 59 if (this->hasZeroAlpha() || 0 == alpha) { |
111 this->internalSetToTransparentBlack(); | 60 this->internalSetToTransparentBlack(); |
112 } else { | 61 } else { |
113 if (alpha != 255) { | 62 if (alpha != 255) { |
114 // Multiply color by alpha | 63 // Multiply color by alpha |
115 fColor = GrColorPackRGBA(SkMulDiv255Round(GrColorUnpackR(fColor)
, alpha), | 64 fColor = GrColorPackRGBA(SkMulDiv255Round(GrColorUnpackR(fColor)
, alpha), |
116 SkMulDiv255Round(GrColorUnpackG(fColor)
, alpha), | 65 SkMulDiv255Round(GrColorUnpackG(fColor)
, alpha), |
117 SkMulDiv255Round(GrColorUnpackB(fColor)
, alpha), | 66 SkMulDiv255Round(GrColorUnpackB(fColor)
, alpha), |
118 SkMulDiv255Round(GrColorUnpackA(fColor)
, alpha)); | 67 SkMulDiv255Round(GrColorUnpackA(fColor)
, alpha)); |
119 } | 68 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 friend class GrProcOptInfo; | 115 friend class GrProcOptInfo; |
167 | 116 |
168 void reset(GrColor color, GrColorComponentFlags flags, bool isSingleComponen
t) { | 117 void reset(GrColor color, GrColorComponentFlags flags, bool isSingleComponen
t) { |
169 fColor = color; | 118 fColor = color; |
170 fValidFlags = flags; | 119 fValidFlags = flags; |
171 fIsSingleComponent = isSingleComponent; | 120 fIsSingleComponent = isSingleComponent; |
172 fNonMulStageFound = false; | 121 fNonMulStageFound = false; |
173 fWillUseInputColor = true; | 122 fWillUseInputColor = true; |
174 } | 123 } |
175 | 124 |
176 void reset(const GrInitInvariantOutput& io) { | |
177 fColor = io.fColor; | |
178 fValidFlags = io.fValidFlags; | |
179 fIsSingleComponent = io.fIsSingleComponent; | |
180 fNonMulStageFound = false; | |
181 fWillUseInputColor = true; | |
182 fIsLCDCoverage = io.fIsLCDCoverage; | |
183 } | |
184 | |
185 void internalSetToTransparentBlack() { | 125 void internalSetToTransparentBlack() { |
186 fValidFlags = kRGBA_GrColorComponentFlags; | 126 fValidFlags = kRGBA_GrColorComponentFlags; |
187 fColor = 0; | 127 fColor = 0; |
188 fIsSingleComponent = true; | 128 fIsSingleComponent = true; |
189 } | 129 } |
190 | 130 |
191 void internalSetToUnknown() { | 131 void internalSetToUnknown() { |
192 fValidFlags = 0; | 132 fValidFlags = 0; |
193 fIsSingleComponent = false; | 133 fIsSingleComponent = false; |
194 } | 134 } |
(...skipping 29 matching lines...) Expand all Loading... |
224 uint32_t fValidFlags; | 164 uint32_t fValidFlags; |
225 bool fIsSingleComponent; | 165 bool fIsSingleComponent; |
226 bool fNonMulStageFound; | 166 bool fNonMulStageFound; |
227 bool fWillUseInputColor; | 167 bool fWillUseInputColor; |
228 bool fIsLCDCoverage; // Temorary data member until texture pixel configs are
updated | 168 bool fIsLCDCoverage; // Temorary data member until texture pixel configs are
updated |
229 | 169 |
230 }; | 170 }; |
231 | 171 |
232 #endif | 172 #endif |
233 | 173 |
OLD | NEW |