OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
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 "SkAlphaThresholdFilter.h" | 8 #include "SkAlphaThresholdFilter.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkReadBuffer.h" | 10 #include "SkReadBuffer.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 maskTexture, | 69 maskTexture, |
70 innerThreshold, | 70 innerThreshold, |
71 outerThreshold)); | 71 outerThreshold)); |
72 } | 72 } |
73 | 73 |
74 virtual ~AlphaThresholdEffect() {}; | 74 virtual ~AlphaThresholdEffect() {}; |
75 | 75 |
76 static const char* Name() { return "Alpha Threshold"; } | 76 static const char* Name() { return "Alpha Threshold"; } |
77 | 77 |
78 virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERR
IDE; | 78 virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERR
IDE; |
| 79 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags
) const SK_OVERRIDE; |
| 80 |
79 float innerThreshold() const { return fInnerThreshold; } | 81 float innerThreshold() const { return fInnerThreshold; } |
80 float outerThreshold() const { return fOuterThreshold; } | 82 float outerThreshold() const { return fOuterThreshold; } |
81 | 83 |
82 typedef GrGLAlphaThresholdEffect GLProcessor; | 84 typedef GrGLAlphaThresholdEffect GLProcessor; |
83 | 85 |
84 private: | 86 private: |
85 AlphaThresholdEffect(GrTexture* texture, | 87 AlphaThresholdEffect(GrTexture* texture, |
86 GrTexture* maskTexture, | 88 GrTexture* maskTexture, |
87 float innerThreshold, | 89 float innerThreshold, |
88 float outerThreshold) | 90 float outerThreshold) |
89 : fInnerThreshold(innerThreshold) | 91 : fInnerThreshold(innerThreshold) |
90 , fOuterThreshold(outerThreshold) | 92 , fOuterThreshold(outerThreshold) |
91 , fImageCoordTransform(kLocal_GrCoordSet, | 93 , fImageCoordTransform(kLocal_GrCoordSet, |
92 GrCoordTransform::MakeDivByTextureWHMatrix(textur
e), texture) | 94 GrCoordTransform::MakeDivByTextureWHMatrix(textur
e), texture) |
93 , fImageTextureAccess(texture) | 95 , fImageTextureAccess(texture) |
94 , fMaskCoordTransform(kLocal_GrCoordSet, | 96 , fMaskCoordTransform(kLocal_GrCoordSet, |
95 GrCoordTransform::MakeDivByTextureWHMatrix(maskTex
ture), maskTexture) | 97 GrCoordTransform::MakeDivByTextureWHMatrix(maskTex
ture), maskTexture) |
96 , fMaskTextureAccess(maskTexture) { | 98 , fMaskTextureAccess(maskTexture) { |
97 this->addCoordTransform(&fImageCoordTransform); | 99 this->addCoordTransform(&fImageCoordTransform); |
98 this->addTextureAccess(&fImageTextureAccess); | 100 this->addTextureAccess(&fImageTextureAccess); |
99 this->addCoordTransform(&fMaskCoordTransform); | 101 this->addCoordTransform(&fMaskCoordTransform); |
100 this->addTextureAccess(&fMaskTextureAccess); | 102 this->addTextureAccess(&fMaskTextureAccess); |
101 } | 103 } |
102 | 104 |
103 virtual bool onIsEqual(const GrProcessor&) const SK_OVERRIDE; | 105 virtual bool onIsEqual(const GrProcessor&) const SK_OVERRIDE; |
104 | 106 |
105 virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERR
IDE; | |
106 | |
107 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 107 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
108 | 108 |
109 float fInnerThreshold; | 109 float fInnerThreshold; |
110 float fOuterThreshold; | 110 float fOuterThreshold; |
111 GrCoordTransform fImageCoordTransform; | 111 GrCoordTransform fImageCoordTransform; |
112 GrTextureAccess fImageTextureAccess; | 112 GrTextureAccess fImageTextureAccess; |
113 GrCoordTransform fMaskCoordTransform; | 113 GrCoordTransform fMaskCoordTransform; |
114 GrTextureAccess fMaskTextureAccess; | 114 GrTextureAccess fMaskTextureAccess; |
115 | 115 |
116 typedef GrFragmentProcessor INHERITED; | 116 typedef GrFragmentProcessor INHERITED; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 return GrTBackendFragmentProcessorFactory<AlphaThresholdEffect>::getInstance
(); | 221 return GrTBackendFragmentProcessorFactory<AlphaThresholdEffect>::getInstance
(); |
222 } | 222 } |
223 | 223 |
224 bool AlphaThresholdEffect::onIsEqual(const GrProcessor& sBase) const { | 224 bool AlphaThresholdEffect::onIsEqual(const GrProcessor& sBase) const { |
225 const AlphaThresholdEffect& s = sBase.cast<AlphaThresholdEffect>(); | 225 const AlphaThresholdEffect& s = sBase.cast<AlphaThresholdEffect>(); |
226 return (this->texture(0) == s.texture(0) && | 226 return (this->texture(0) == s.texture(0) && |
227 this->fInnerThreshold == s.fInnerThreshold && | 227 this->fInnerThreshold == s.fInnerThreshold && |
228 this->fOuterThreshold == s.fOuterThreshold); | 228 this->fOuterThreshold == s.fOuterThreshold); |
229 } | 229 } |
230 | 230 |
231 void AlphaThresholdEffect::onComputeInvariantOutput(InvariantOutput* inout) cons
t { | 231 void AlphaThresholdEffect::getConstantColorComponents(GrColor* color, uint32_t*
validFlags) const { |
232 if (inout->isOpaque() && GrPixelConfigIsOpaque(this->texture(0)->config()))
{ | 232 if ((*validFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUnpackA(*color
) && |
233 inout->fValidFlags = kA_GrColorComponentFlag; | 233 GrPixelConfigIsOpaque(this->texture(0)->config())) { |
| 234 *validFlags = kA_GrColorComponentFlag; |
234 } else { | 235 } else { |
235 inout->fValidFlags = 0; | 236 *validFlags = 0; |
236 } | 237 } |
237 inout->fIsSingleComponent = false; | |
238 } | 238 } |
239 | 239 |
240 #endif | 240 #endif |
241 | 241 |
242 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING | 242 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING |
243 SkAlphaThresholdFilterImpl::SkAlphaThresholdFilterImpl(SkReadBuffer& buffer) | 243 SkAlphaThresholdFilterImpl::SkAlphaThresholdFilterImpl(SkReadBuffer& buffer) |
244 : INHERITED(1, buffer) { | 244 : INHERITED(1, buffer) { |
245 fInnerThreshold = buffer.readScalar(); | 245 fInnerThreshold = buffer.readScalar(); |
246 fOuterThreshold = buffer.readScalar(); | 246 fOuterThreshold = buffer.readScalar(); |
247 buffer.readRegion(&fRegion); | 247 buffer.readRegion(&fRegion); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 (U8CPU)(SkColorGetG(source) *
scale), | 379 (U8CPU)(SkColorGetG(source) *
scale), |
380 (U8CPU)(SkColorGetB(source) *
scale)); | 380 (U8CPU)(SkColorGetB(source) *
scale)); |
381 } | 381 } |
382 } | 382 } |
383 dptr[y * dst->width() + x] = output_color; | 383 dptr[y * dst->width() + x] = output_color; |
384 } | 384 } |
385 } | 385 } |
386 | 386 |
387 return true; | 387 return true; |
388 } | 388 } |
OLD | NEW |