Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(179)

Unified Diff: src/effects/SkColorMatrixFilter.cpp

Issue 608253002: Add isSingleComponent bool to getConstantColorComponent (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix isSolidWhite Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/effects/SkColorFilters.cpp ('k') | src/effects/SkDisplacementMapEffect.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/effects/SkColorMatrixFilter.cpp
diff --git a/src/effects/SkColorMatrixFilter.cpp b/src/effects/SkColorMatrixFilter.cpp
index 5ac455253e17db25f7b0efb4c846131212439326..8549fd72e12a719a3f94713218defa1b77dfb930 100644
--- a/src/effects/SkColorMatrixFilter.cpp
+++ b/src/effects/SkColorMatrixFilter.cpp
@@ -349,51 +349,6 @@ public:
return GrTBackendFragmentProcessorFactory<ColorMatrixEffect>::getInstance();
}
- virtual void getConstantColorComponents(GrColor* color,
- uint32_t* validFlags) const SK_OVERRIDE {
- // We only bother to check whether the alpha channel will be constant. If SkColorMatrix had
- // type flags it might be worth checking the other components.
-
- // The matrix is defined such the 4th row determines the output alpha. The first four
- // columns of that row multiply the input r, g, b, and a, respectively, and the last column
- // is the "translation".
- static const uint32_t kRGBAFlags[] = {
- kR_GrColorComponentFlag,
- kG_GrColorComponentFlag,
- kB_GrColorComponentFlag,
- kA_GrColorComponentFlag
- };
- static const int kShifts[] = {
- GrColor_SHIFT_R, GrColor_SHIFT_G, GrColor_SHIFT_B, GrColor_SHIFT_A,
- };
- enum {
- kAlphaRowStartIdx = 15,
- kAlphaRowTranslateIdx = 19,
- };
-
- SkScalar outputA = 0;
- for (int i = 0; i < 4; ++i) {
- // If any relevant component of the color to be passed through the matrix is non-const
- // then we can't know the final result.
- if (0 != fMatrix.fMat[kAlphaRowStartIdx + i]) {
- if (!(*validFlags & kRGBAFlags[i])) {
- *validFlags = 0;
- return;
- } else {
- uint32_t component = (*color >> kShifts[i]) & 0xFF;
- outputA += fMatrix.fMat[kAlphaRowStartIdx + i] * component;
- }
- }
- }
- outputA += fMatrix.fMat[kAlphaRowTranslateIdx];
- *validFlags = kA_GrColorComponentFlag;
- // We pin the color to [0,1]. This would happen to the *final* color output from the frag
- // shader but currently the effect does not pin its own output. So in the case of over/
- // underflow this may deviate from the actual result. Maybe the effect should pin its
- // result if the matrix could over/underflow for any component?
- *color = static_cast<uint8_t>(SkScalarPin(outputA, 0, 255)) << GrColor_SHIFT_A;
- }
-
GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
class GLProcessor : public GrGLFragmentProcessor {
@@ -471,6 +426,51 @@ private:
return cme.fMatrix == fMatrix;
}
+ virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE {
+ // We only bother to check whether the alpha channel will be constant. If SkColorMatrix had
+ // type flags it might be worth checking the other components.
+
+ // The matrix is defined such the 4th row determines the output alpha. The first four
+ // columns of that row multiply the input r, g, b, and a, respectively, and the last column
+ // is the "translation".
+ static const uint32_t kRGBAFlags[] = {
+ kR_GrColorComponentFlag,
+ kG_GrColorComponentFlag,
+ kB_GrColorComponentFlag,
+ kA_GrColorComponentFlag
+ };
+ static const int kShifts[] = {
+ GrColor_SHIFT_R, GrColor_SHIFT_G, GrColor_SHIFT_B, GrColor_SHIFT_A,
+ };
+ enum {
+ kAlphaRowStartIdx = 15,
+ kAlphaRowTranslateIdx = 19,
+ };
+
+ SkScalar outputA = 0;
+ for (int i = 0; i < 4; ++i) {
+ // If any relevant component of the color to be passed through the matrix is non-const
+ // then we can't know the final result.
+ if (0 != fMatrix.fMat[kAlphaRowStartIdx + i]) {
+ if (!(inout->fValidFlags & kRGBAFlags[i])) {
+ inout->fValidFlags = 0;
+ return;
+ } else {
+ uint32_t component = (inout->fColor >> kShifts[i]) & 0xFF;
+ outputA += fMatrix.fMat[kAlphaRowStartIdx + i] * component;
+ }
+ }
+ }
+ outputA += fMatrix.fMat[kAlphaRowTranslateIdx];
+ inout->fValidFlags = kA_GrColorComponentFlag;
+ // We pin the color to [0,1]. This would happen to the *final* color output from the frag
+ // shader but currently the effect does not pin its own output. So in the case of over/
+ // underflow this may deviate from the actual result. Maybe the effect should pin its
+ // result if the matrix could over/underflow for any component?
+ inout->fColor = static_cast<uint8_t>(SkScalarPin(outputA, 0, 255)) << GrColor_SHIFT_A;
+ inout->fIsSingleComponent = false;
+ }
+
SkColorMatrix fMatrix;
typedef GrFragmentProcessor INHERITED;
« no previous file with comments | « src/effects/SkColorFilters.cpp ('k') | src/effects/SkDisplacementMapEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698