OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #ifndef GrPaint_DEFINED | 10 #ifndef GrPaint_DEFINED |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 void setAntiAlias(bool aa) { fAntiAlias = aa; } | 78 void setAntiAlias(bool aa) { fAntiAlias = aa; } |
79 bool isAntiAlias() const { return fAntiAlias; } | 79 bool isAntiAlias() const { return fAntiAlias; } |
80 | 80 |
81 /** | 81 /** |
82 * Should dithering be applied. Defaults to false. | 82 * Should dithering be applied. Defaults to false. |
83 */ | 83 */ |
84 void setDither(bool dither) { fDither = dither; } | 84 void setDither(bool dither) { fDither = dither; } |
85 bool isDither() const { return fDither; } | 85 bool isDither() const { return fDither; } |
86 | 86 |
87 /** | 87 /** |
88 * Enables a SkXfermode::Mode-based color filter applied to the primitive co
lor. The constant | |
89 * color passed to this function is considered the "src" color and the primi
tive's color is | |
90 * considered the "dst" color. Defaults to kDst_Mode which equates to simply
passing through | |
91 * the primitive color unmodified. | |
92 */ | |
93 void setXfermodeColorFilter(SkXfermode::Mode mode, GrColor color) { | |
94 fColorFilterColor = color; | |
95 fColorFilterXfermode = mode; | |
96 } | |
97 SkXfermode::Mode getColorFilterMode() const { return fColorFilterXfermode; } | |
98 GrColor getColorFilterColor() const { return fColorFilterColor; } | |
99 | |
100 /** | |
101 * Disables the SkXfermode::Mode color filter. | |
102 */ | |
103 void resetColorFilter() { | |
104 fColorFilterXfermode = SkXfermode::kDst_Mode; | |
105 fColorFilterColor = GrColorPackRGBA(0xff, 0xff, 0xff, 0xff); | |
106 } | |
107 | |
108 /** | |
109 * Appends an additional color effect to the color computation. | 88 * Appends an additional color effect to the color computation. |
110 */ | 89 */ |
111 const GrEffectRef* addColorEffect(const GrEffectRef* effect, int attr0 = -1,
int attr1 = -1) { | 90 const GrEffectRef* addColorEffect(const GrEffectRef* effect, int attr0 = -1,
int attr1 = -1) { |
112 SkASSERT(NULL != effect); | 91 SkASSERT(NULL != effect); |
| 92 if (!(*effect)->willUseInputColor()) { |
| 93 fColorStages.reset(); |
| 94 } |
113 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrEffectStage, (effect, attr0, att
r1)); | 95 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrEffectStage, (effect, attr0, att
r1)); |
114 return effect; | 96 return effect; |
115 } | 97 } |
116 | 98 |
117 /** | 99 /** |
118 * Appends an additional coverage effect to the coverage computation. | 100 * Appends an additional coverage effect to the coverage computation. |
119 */ | 101 */ |
120 const GrEffectRef* addCoverageEffect(const GrEffectRef* effect, int attr0 =
-1, int attr1 = -1) { | 102 const GrEffectRef* addCoverageEffect(const GrEffectRef* effect, int attr0 =
-1, int attr1 = -1) { |
121 SkASSERT(NULL != effect); | 103 SkASSERT(NULL != effect); |
| 104 if (!(*effect)->willUseInputColor()) { |
| 105 fCoverageStages.reset(); |
| 106 } |
122 SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrEffectStage, (effect, attr0,
attr1)); | 107 SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrEffectStage, (effect, attr0,
attr1)); |
123 return effect; | 108 return effect; |
124 } | 109 } |
125 | 110 |
126 /** | 111 /** |
127 * Helpers for adding color or coverage effects that sample a texture. The m
atrix is applied | 112 * Helpers for adding color or coverage effects that sample a texture. The m
atrix is applied |
128 * to the src space position to compute texture coordinates. | 113 * to the src space position to compute texture coordinates. |
129 */ | 114 */ |
130 void addColorTextureEffect(GrTexture* texture, const SkMatrix& matrix); | 115 void addColorTextureEffect(GrTexture* texture, const SkMatrix& matrix); |
131 void addCoverageTextureEffect(GrTexture* texture, const SkMatrix& matrix); | 116 void addCoverageTextureEffect(GrTexture* texture, const SkMatrix& matrix); |
(...skipping 14 matching lines...) Expand all Loading... |
146 | 131 |
147 GrPaint& operator=(const GrPaint& paint) { | 132 GrPaint& operator=(const GrPaint& paint) { |
148 fSrcBlendCoeff = paint.fSrcBlendCoeff; | 133 fSrcBlendCoeff = paint.fSrcBlendCoeff; |
149 fDstBlendCoeff = paint.fDstBlendCoeff; | 134 fDstBlendCoeff = paint.fDstBlendCoeff; |
150 fAntiAlias = paint.fAntiAlias; | 135 fAntiAlias = paint.fAntiAlias; |
151 fDither = paint.fDither; | 136 fDither = paint.fDither; |
152 | 137 |
153 fColor = paint.fColor; | 138 fColor = paint.fColor; |
154 fCoverage = paint.fCoverage; | 139 fCoverage = paint.fCoverage; |
155 | 140 |
156 fColorFilterColor = paint.fColorFilterColor; | |
157 fColorFilterXfermode = paint.fColorFilterXfermode; | |
158 | |
159 fColorStages = paint.fColorStages; | 141 fColorStages = paint.fColorStages; |
160 fCoverageStages = paint.fCoverageStages; | 142 fCoverageStages = paint.fCoverageStages; |
161 | 143 |
162 return *this; | 144 return *this; |
163 } | 145 } |
164 | 146 |
165 /** | 147 /** |
166 * Resets the paint to the defaults. | 148 * Resets the paint to the defaults. |
167 */ | 149 */ |
168 void reset() { | 150 void reset() { |
169 this->resetBlend(); | 151 this->resetBlend(); |
170 this->resetOptions(); | 152 this->resetOptions(); |
171 this->resetColor(); | 153 this->resetColor(); |
172 this->resetCoverage(); | 154 this->resetCoverage(); |
173 this->resetStages(); | 155 this->resetStages(); |
174 this->resetColorFilter(); | |
175 } | 156 } |
176 | 157 |
177 /** | 158 /** |
178 * Determines whether the drawing with this paint is opaque with respect to
both color blending | 159 * Determines whether the drawing with this paint is opaque with respect to
both color blending |
179 * and fractional coverage. It does not consider whether AA has been enabled
on the paint or | 160 * and fractional coverage. It does not consider whether AA has been enabled
on the paint or |
180 * not. Depending upon whether multisampling or coverage-based AA is in use,
AA may make the | 161 * not. Depending upon whether multisampling or coverage-based AA is in use,
AA may make the |
181 * result only apply to the interior of primitives. | 162 * result only apply to the interior of primitives. |
182 * | 163 * |
183 */ | 164 */ |
184 bool isOpaque() const; | 165 bool isOpaque() const; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 SkSTArray<2, GrEffectStage> fCoverageStages; | 219 SkSTArray<2, GrEffectStage> fCoverageStages; |
239 | 220 |
240 GrBlendCoeff fSrcBlendCoeff; | 221 GrBlendCoeff fSrcBlendCoeff; |
241 GrBlendCoeff fDstBlendCoeff; | 222 GrBlendCoeff fDstBlendCoeff; |
242 bool fAntiAlias; | 223 bool fAntiAlias; |
243 bool fDither; | 224 bool fDither; |
244 | 225 |
245 GrColor fColor; | 226 GrColor fColor; |
246 uint8_t fCoverage; | 227 uint8_t fCoverage; |
247 | 228 |
248 GrColor fColorFilterColor; | |
249 SkXfermode::Mode fColorFilterXfermode; | |
250 | |
251 void resetBlend() { | 229 void resetBlend() { |
252 fSrcBlendCoeff = kOne_GrBlendCoeff; | 230 fSrcBlendCoeff = kOne_GrBlendCoeff; |
253 fDstBlendCoeff = kZero_GrBlendCoeff; | 231 fDstBlendCoeff = kZero_GrBlendCoeff; |
254 } | 232 } |
255 | 233 |
256 void resetOptions() { | 234 void resetOptions() { |
257 fAntiAlias = false; | 235 fAntiAlias = false; |
258 fDither = false; | 236 fDither = false; |
259 } | 237 } |
260 | 238 |
261 void resetColor() { | 239 void resetColor() { |
262 fColor = GrColorPackRGBA(0xff, 0xff, 0xff, 0xff); | 240 fColor = GrColorPackRGBA(0xff, 0xff, 0xff, 0xff); |
263 } | 241 } |
264 | 242 |
265 void resetCoverage() { | 243 void resetCoverage() { |
266 fCoverage = 0xff; | 244 fCoverage = 0xff; |
267 } | 245 } |
268 | 246 |
269 void resetStages() { | 247 void resetStages() { |
270 fColorStages.reset(); | 248 fColorStages.reset(); |
271 fCoverageStages.reset(); | 249 fCoverageStages.reset(); |
272 } | 250 } |
273 }; | 251 }; |
274 | 252 |
275 #endif | 253 #endif |
OLD | NEW |