OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
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 #include "SkBlitRow.h" | 8 #include "SkBlitRow.h" |
9 #include "SkColorFilter.h" | 9 #include "SkColorFilter.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 // TODO: Make the effect take the coeffs rather than mode since we alrea
dy do the | 188 // TODO: Make the effect take the coeffs rather than mode since we alrea
dy do the |
189 // conversion here. | 189 // conversion here. |
190 SkXfermode::Coeff srcCoeff, dstCoeff; | 190 SkXfermode::Coeff srcCoeff, dstCoeff; |
191 if (!SkXfermode::ModeAsCoeff(mode, &srcCoeff, &dstCoeff)) { | 191 if (!SkXfermode::ModeAsCoeff(mode, &srcCoeff, &dstCoeff)) { |
192 SkDebugf("Failing to create color filter for mode %d\n", mode); | 192 SkDebugf("Failing to create color filter for mode %d\n", mode); |
193 return NULL; | 193 return NULL; |
194 } | 194 } |
195 return SkNEW_ARGS(ModeColorFilterEffect, (c, mode)); | 195 return SkNEW_ARGS(ModeColorFilterEffect, (c, mode)); |
196 } | 196 } |
197 | 197 |
| 198 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags
) const SK_OVERRIDE; |
| 199 |
198 bool willUseFilterColor() const { | 200 bool willUseFilterColor() const { |
199 SkXfermode::Coeff dstCoeff; | 201 SkXfermode::Coeff dstCoeff; |
200 SkXfermode::Coeff srcCoeff; | 202 SkXfermode::Coeff srcCoeff; |
201 SkAssertResult(SkXfermode::ModeAsCoeff(fMode, &srcCoeff, &dstCoeff)); | 203 SkAssertResult(SkXfermode::ModeAsCoeff(fMode, &srcCoeff, &dstCoeff)); |
202 if (SkXfermode::kZero_Coeff == srcCoeff) { | 204 if (SkXfermode::kZero_Coeff == srcCoeff) { |
203 return GrBlendCoeffRefsSrc(sk_blend_to_grblend(dstCoeff)); | 205 return GrBlendCoeffRefsSrc(sk_blend_to_grblend(dstCoeff)); |
204 } | 206 } |
205 return true; | 207 return true; |
206 } | 208 } |
207 | 209 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 !GrBlendCoeffRefsDst(sk_blend_to_grblend(srcCoeff))) { | 286 !GrBlendCoeffRefsDst(sk_blend_to_grblend(srcCoeff))) { |
285 this->setWillNotUseInputColor(); | 287 this->setWillNotUseInputColor(); |
286 } | 288 } |
287 } | 289 } |
288 | 290 |
289 virtual bool onIsEqual(const GrProcessor& other) const SK_OVERRIDE { | 291 virtual bool onIsEqual(const GrProcessor& other) const SK_OVERRIDE { |
290 const ModeColorFilterEffect& s = other.cast<ModeColorFilterEffect>(); | 292 const ModeColorFilterEffect& s = other.cast<ModeColorFilterEffect>(); |
291 return fMode == s.fMode && fColor == s.fColor; | 293 return fMode == s.fMode && fColor == s.fColor; |
292 } | 294 } |
293 | 295 |
294 virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERR
IDE; | |
295 | |
296 SkXfermode::Mode fMode; | 296 SkXfermode::Mode fMode; |
297 GrColor fColor; | 297 GrColor fColor; |
298 | 298 |
299 typedef GrFragmentProcessor INHERITED; | 299 typedef GrFragmentProcessor INHERITED; |
300 }; | 300 }; |
301 | 301 |
302 namespace { | 302 namespace { |
303 | 303 |
304 /** Function color_component_to_int tries to reproduce the GLSL rounding. The sp
ec doesn't specify | 304 /** Function color_component_to_int tries to reproduce the GLSL rounding. The sp
ec doesn't specify |
305 * to which direction the 0.5 goes. | 305 * to which direction the 0.5 goes. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 uint32_t getValidComponents() const { return fFlags; } | 375 uint32_t getValidComponents() const { return fFlags; } |
376 | 376 |
377 typedef MaskedColorExpr AExpr; | 377 typedef MaskedColorExpr AExpr; |
378 private: | 378 private: |
379 float fColor[4]; | 379 float fColor[4]; |
380 uint32_t fFlags; | 380 uint32_t fFlags; |
381 }; | 381 }; |
382 | 382 |
383 } | 383 } |
384 | 384 |
385 void ModeColorFilterEffect::onComputeInvariantOutput(InvariantOutput* inout) con
st { | 385 void ModeColorFilterEffect::getConstantColorComponents(GrColor* color, uint32_t*
validFlags) const { |
386 float inputColor[4]; | 386 float inputColor[4]; |
387 GrColorToRGBAFloat(inout->fColor, inputColor); | 387 GrColorToRGBAFloat(*color, inputColor); |
388 float filterColor[4]; | 388 float filterColor[4]; |
389 GrColorToRGBAFloat(fColor, filterColor); | 389 GrColorToRGBAFloat(fColor, filterColor); |
390 MaskedColorExpr result = | 390 MaskedColorExpr result = |
391 color_filter_expression(fMode, | 391 color_filter_expression(fMode, |
392 MaskedColorExpr(filterColor, kRGBA_GrColorCompon
entFlags), | 392 MaskedColorExpr(filterColor, kRGBA_GrColorCompon
entFlags), |
393 MaskedColorExpr(inputColor, inout->fValidFlags))
; | 393 MaskedColorExpr(inputColor, *validFlags)); |
394 | 394 |
395 inout->fColor = result.getColor(); | 395 *color = result.getColor(); |
396 inout->fValidFlags = result.getValidComponents(); | 396 *validFlags = result.getValidComponents(); |
397 inout->fIsSingleComponent = false; | |
398 } | 397 } |
399 | 398 |
400 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(ModeColorFilterEffect); | 399 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(ModeColorFilterEffect); |
401 GrFragmentProcessor* ModeColorFilterEffect::TestCreate(SkRandom* rand, | 400 GrFragmentProcessor* ModeColorFilterEffect::TestCreate(SkRandom* rand, |
402 GrContext*, | 401 GrContext*, |
403 const GrDrawTargetCaps&, | 402 const GrDrawTargetCaps&, |
404 GrTexture*[]) { | 403 GrTexture*[]) { |
405 SkXfermode::Mode mode = SkXfermode::kDst_Mode; | 404 SkXfermode::Mode mode = SkXfermode::kDst_Mode; |
406 while (SkXfermode::kDst_Mode == mode) { | 405 while (SkXfermode::kDst_Mode == mode) { |
407 mode = static_cast<SkXfermode::Mode>(rand->nextRangeU(0, SkXfermode::kLa
stCoeffMode)); | 406 mode = static_cast<SkXfermode::Mode>(rand->nextRangeU(0, SkXfermode::kLa
stCoeffMode)); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 matrix.postTranslate(SkIntToScalar(SkColorGetR(add)), | 545 matrix.postTranslate(SkIntToScalar(SkColorGetR(add)), |
547 SkIntToScalar(SkColorGetG(add)), | 546 SkIntToScalar(SkColorGetG(add)), |
548 SkIntToScalar(SkColorGetB(add)), | 547 SkIntToScalar(SkColorGetB(add)), |
549 0); | 548 0); |
550 return SkColorMatrixFilter::Create(matrix); | 549 return SkColorMatrixFilter::Create(matrix); |
551 } | 550 } |
552 | 551 |
553 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkColorFilter) | 552 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkColorFilter) |
554 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkModeColorFilter) | 553 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkModeColorFilter) |
555 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 554 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |