| 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 #include "SkColorMatrixFilter.h" | 8 #include "SkColorMatrixFilter.h" |
| 9 #include "SkColorMatrix.h" | 9 #include "SkColorMatrix.h" |
| 10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 } | 337 } |
| 338 | 338 |
| 339 virtual void getConstantColorComponents(GrColor* color, | 339 virtual void getConstantColorComponents(GrColor* color, |
| 340 uint32_t* validFlags) const SK_OVERR
IDE { | 340 uint32_t* validFlags) const SK_OVERR
IDE { |
| 341 // We only bother to check whether the alpha channel will be constant. I
f SkColorMatrix had | 341 // We only bother to check whether the alpha channel will be constant. I
f SkColorMatrix had |
| 342 // type flags it might be worth checking the other components. | 342 // type flags it might be worth checking the other components. |
| 343 | 343 |
| 344 // The matrix is defined such the 4th row determines the output alpha. T
he first four | 344 // The matrix is defined such the 4th row determines the output alpha. T
he first four |
| 345 // columns of that row multiply the input r, g, b, and a, respectively,
and the last column | 345 // columns of that row multiply the input r, g, b, and a, respectively,
and the last column |
| 346 // is the "translation". | 346 // is the "translation". |
| 347 static const ValidComponentFlags kRGBAFlags[] = { | 347 static const uint32_t kRGBAFlags[] = { |
| 348 kR_ValidComponentFlag, | 348 kR_GrColorComponentFlag, |
| 349 kG_ValidComponentFlag, | 349 kG_GrColorComponentFlag, |
| 350 kB_ValidComponentFlag, | 350 kB_GrColorComponentFlag, |
| 351 kA_ValidComponentFlag | 351 kA_GrColorComponentFlag |
| 352 }; | 352 }; |
| 353 static const int kShifts[] = { | 353 static const int kShifts[] = { |
| 354 GrColor_SHIFT_R, GrColor_SHIFT_G, GrColor_SHIFT_B, GrColor_SHIFT_A, | 354 GrColor_SHIFT_R, GrColor_SHIFT_G, GrColor_SHIFT_B, GrColor_SHIFT_A, |
| 355 }; | 355 }; |
| 356 enum { | 356 enum { |
| 357 kAlphaRowStartIdx = 15, | 357 kAlphaRowStartIdx = 15, |
| 358 kAlphaRowTranslateIdx = 19, | 358 kAlphaRowTranslateIdx = 19, |
| 359 }; | 359 }; |
| 360 | 360 |
| 361 SkScalar outputA = 0; | 361 SkScalar outputA = 0; |
| 362 for (int i = 0; i < 4; ++i) { | 362 for (int i = 0; i < 4; ++i) { |
| 363 // If any relevant component of the color to be passed through the m
atrix is non-const | 363 // If any relevant component of the color to be passed through the m
atrix is non-const |
| 364 // then we can't know the final result. | 364 // then we can't know the final result. |
| 365 if (0 != fMatrix.fMat[kAlphaRowStartIdx + i]) { | 365 if (0 != fMatrix.fMat[kAlphaRowStartIdx + i]) { |
| 366 if (!(*validFlags & kRGBAFlags[i])) { | 366 if (!(*validFlags & kRGBAFlags[i])) { |
| 367 *validFlags = 0; | 367 *validFlags = 0; |
| 368 return; | 368 return; |
| 369 } else { | 369 } else { |
| 370 uint32_t component = (*color >> kShifts[i]) & 0xFF; | 370 uint32_t component = (*color >> kShifts[i]) & 0xFF; |
| 371 outputA += fMatrix.fMat[kAlphaRowStartIdx + i] * component; | 371 outputA += fMatrix.fMat[kAlphaRowStartIdx + i] * component; |
| 372 } | 372 } |
| 373 } | 373 } |
| 374 } | 374 } |
| 375 outputA += fMatrix.fMat[kAlphaRowTranslateIdx]; | 375 outputA += fMatrix.fMat[kAlphaRowTranslateIdx]; |
| 376 *validFlags = kA_ValidComponentFlag; | 376 *validFlags = kA_GrColorComponentFlag; |
| 377 // We pin the color to [0,1]. This would happen to the *final* color out
put from the frag | 377 // We pin the color to [0,1]. This would happen to the *final* color out
put from the frag |
| 378 // shader but currently the effect does not pin its own output. So in th
e case of over/ | 378 // shader but currently the effect does not pin its own output. So in th
e case of over/ |
| 379 // underflow this may deviate from the actual result. Maybe the effect s
hould pin its | 379 // underflow this may deviate from the actual result. Maybe the effect s
hould pin its |
| 380 // result if the matrix could over/underflow for any component? | 380 // result if the matrix could over/underflow for any component? |
| 381 *color = static_cast<uint8_t>(SkScalarPin(outputA, 0, 255)) << GrColor_S
HIFT_A; | 381 *color = static_cast<uint8_t>(SkScalarPin(outputA, 0, 255)) << GrColor_S
HIFT_A; |
| 382 } | 382 } |
| 383 | 383 |
| 384 GR_DECLARE_EFFECT_TEST; | 384 GR_DECLARE_EFFECT_TEST; |
| 385 | 385 |
| 386 class GLEffect : public GrGLEffect { | 386 class GLEffect : public GrGLEffect { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 colorMatrix.fMat[i] = random->nextSScalar1(); | 470 colorMatrix.fMat[i] = random->nextSScalar1(); |
| 471 } | 471 } |
| 472 return ColorMatrixEffect::Create(colorMatrix); | 472 return ColorMatrixEffect::Create(colorMatrix); |
| 473 } | 473 } |
| 474 | 474 |
| 475 GrEffectRef* SkColorMatrixFilter::asNewEffect(GrContext*) const { | 475 GrEffectRef* SkColorMatrixFilter::asNewEffect(GrContext*) const { |
| 476 return ColorMatrixEffect::Create(fMatrix); | 476 return ColorMatrixEffect::Create(fMatrix); |
| 477 } | 477 } |
| 478 | 478 |
| 479 #endif | 479 #endif |
| OLD | NEW |