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 | |
200 bool willUseFilterColor() const { | 198 bool willUseFilterColor() const { |
201 SkXfermode::Coeff dstCoeff; | 199 SkXfermode::Coeff dstCoeff; |
202 SkXfermode::Coeff srcCoeff; | 200 SkXfermode::Coeff srcCoeff; |
203 SkAssertResult(SkXfermode::ModeAsCoeff(fMode, &srcCoeff, &dstCoeff)); | 201 SkAssertResult(SkXfermode::ModeAsCoeff(fMode, &srcCoeff, &dstCoeff)); |
204 if (SkXfermode::kZero_Coeff == srcCoeff) { | 202 if (SkXfermode::kZero_Coeff == srcCoeff) { |
205 return GrBlendCoeffRefsSrc(sk_blend_to_grblend(dstCoeff)); | 203 return GrBlendCoeffRefsSrc(sk_blend_to_grblend(dstCoeff)); |
206 } | 204 } |
207 return true; | 205 return true; |
208 } | 206 } |
209 | 207 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 !GrBlendCoeffRefsDst(sk_blend_to_grblend(srcCoeff))) { | 284 !GrBlendCoeffRefsDst(sk_blend_to_grblend(srcCoeff))) { |
287 this->setWillNotUseInputColor(); | 285 this->setWillNotUseInputColor(); |
288 } | 286 } |
289 } | 287 } |
290 | 288 |
291 virtual bool onIsEqual(const GrProcessor& other) const SK_OVERRIDE { | 289 virtual bool onIsEqual(const GrProcessor& other) const SK_OVERRIDE { |
292 const ModeColorFilterEffect& s = other.cast<ModeColorFilterEffect>(); | 290 const ModeColorFilterEffect& s = other.cast<ModeColorFilterEffect>(); |
293 return fMode == s.fMode && fColor == s.fColor; | 291 return fMode == s.fMode && fColor == s.fColor; |
294 } | 292 } |
295 | 293 |
| 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::getConstantColorComponents(GrColor* color, uint32_t*
validFlags) const { | 385 void ModeColorFilterEffect::onComputeInvariantOutput(InvariantOutput* inout) con
st { |
386 float inputColor[4]; | 386 float inputColor[4]; |
387 GrColorToRGBAFloat(*color, inputColor); | 387 GrColorToRGBAFloat(inout->fColor, 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, *validFlags)); | 393 MaskedColorExpr(inputColor, inout->fValidFlags))
; |
394 | 394 |
395 *color = result.getColor(); | 395 inout->fColor = result.getColor(); |
396 *validFlags = result.getValidComponents(); | 396 inout->fValidFlags = result.getValidComponents(); |
| 397 inout->fIsSingleComponent = false; |
397 } | 398 } |
398 | 399 |
399 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(ModeColorFilterEffect); | 400 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(ModeColorFilterEffect); |
400 GrFragmentProcessor* ModeColorFilterEffect::TestCreate(SkRandom* rand, | 401 GrFragmentProcessor* ModeColorFilterEffect::TestCreate(SkRandom* rand, |
401 GrContext*, | 402 GrContext*, |
402 const GrDrawTargetCaps&, | 403 const GrDrawTargetCaps&, |
403 GrTexture*[]) { | 404 GrTexture*[]) { |
404 SkXfermode::Mode mode = SkXfermode::kDst_Mode; | 405 SkXfermode::Mode mode = SkXfermode::kDst_Mode; |
405 while (SkXfermode::kDst_Mode == mode) { | 406 while (SkXfermode::kDst_Mode == mode) { |
406 mode = static_cast<SkXfermode::Mode>(rand->nextRangeU(0, SkXfermode::kLa
stCoeffMode)); | 407 mode = static_cast<SkXfermode::Mode>(rand->nextRangeU(0, SkXfermode::kLa
stCoeffMode)); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 matrix.postTranslate(SkIntToScalar(SkColorGetR(add)), | 546 matrix.postTranslate(SkIntToScalar(SkColorGetR(add)), |
546 SkIntToScalar(SkColorGetG(add)), | 547 SkIntToScalar(SkColorGetG(add)), |
547 SkIntToScalar(SkColorGetB(add)), | 548 SkIntToScalar(SkColorGetB(add)), |
548 0); | 549 0); |
549 return SkColorMatrixFilter::Create(matrix); | 550 return SkColorMatrixFilter::Create(matrix); |
550 } | 551 } |
551 | 552 |
552 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkColorFilter) | 553 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkColorFilter) |
553 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkModeColorFilter) | 554 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkModeColorFilter) |
554 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 555 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |