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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 #include "effects/GrPorterDuffXferProcessor.h" | 55 #include "effects/GrPorterDuffXferProcessor.h" |
56 | 56 |
57 #include "SkGr.h" | 57 #include "SkGr.h" |
58 | 58 |
59 #include "gl/GrGLProcessor.h" | 59 #include "gl/GrGLProcessor.h" |
60 #include "gl/builders/GrGLProgramBuilder.h" | 60 #include "gl/builders/GrGLProgramBuilder.h" |
61 | 61 |
62 class AlphaThresholdEffect : public GrFragmentProcessor { | 62 class AlphaThresholdEffect : public GrFragmentProcessor { |
63 | 63 |
64 public: | 64 public: |
65 static GrFragmentProcessor* Create(GrTexture* texture, | 65 static GrFragmentProcessor* Create(GrShaderDataManager* shaderDataManager, |
| 66 GrTexture* texture, |
66 GrTexture* maskTexture, | 67 GrTexture* maskTexture, |
67 float innerThreshold, | 68 float innerThreshold, |
68 float outerThreshold) { | 69 float outerThreshold) { |
69 return SkNEW_ARGS(AlphaThresholdEffect, (texture, | 70 return SkNEW_ARGS(AlphaThresholdEffect, (shaderDataManager, |
| 71 texture, |
70 maskTexture, | 72 maskTexture, |
71 innerThreshold, | 73 innerThreshold, |
72 outerThreshold)); | 74 outerThreshold)); |
73 } | 75 } |
74 | 76 |
75 virtual ~AlphaThresholdEffect() {}; | 77 virtual ~AlphaThresholdEffect() {}; |
76 | 78 |
77 const char* name() const override { return "Alpha Threshold"; } | 79 const char* name() const override { return "Alpha Threshold"; } |
78 | 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 void getGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const over
ride; | 84 void getGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const over
ride; |
83 | 85 |
84 GrGLFragmentProcessor* createGLInstance() const override; | 86 GrGLFragmentProcessor* createGLInstance() const override; |
85 | 87 |
86 private: | 88 private: |
87 AlphaThresholdEffect(GrTexture* texture, | 89 AlphaThresholdEffect(GrShaderDataManager*, |
| 90 GrTexture* texture, |
88 GrTexture* maskTexture, | 91 GrTexture* maskTexture, |
89 float innerThreshold, | 92 float innerThreshold, |
90 float outerThreshold) | 93 float outerThreshold) |
91 : fInnerThreshold(innerThreshold) | 94 : fInnerThreshold(innerThreshold) |
92 , fOuterThreshold(outerThreshold) | 95 , fOuterThreshold(outerThreshold) |
93 , fImageCoordTransform(kLocal_GrCoordSet, | 96 , fImageCoordTransform(kLocal_GrCoordSet, |
94 GrCoordTransform::MakeDivByTextureWHMatrix(textur
e), texture, | 97 GrCoordTransform::MakeDivByTextureWHMatrix(textur
e), texture, |
95 GrTextureParams::kNone_FilterMode) | 98 GrTextureParams::kNone_FilterMode) |
96 , fImageTextureAccess(texture) | 99 , fImageTextureAccess(texture) |
97 , fMaskCoordTransform(kLocal_GrCoordSet, | 100 , fMaskCoordTransform(kLocal_GrCoordSet, |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(AlphaThresholdEffect); | 208 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(AlphaThresholdEffect); |
206 | 209 |
207 GrFragmentProcessor* AlphaThresholdEffect::TestCreate(SkRandom* random, | 210 GrFragmentProcessor* AlphaThresholdEffect::TestCreate(SkRandom* random, |
208 GrContext* context, | 211 GrContext* context, |
209 const GrCaps&, | 212 const GrCaps&, |
210 GrTexture** textures) { | 213 GrTexture** textures) { |
211 GrTexture* bmpTex = textures[GrProcessorUnitTest::kSkiaPMTextureIdx]; | 214 GrTexture* bmpTex = textures[GrProcessorUnitTest::kSkiaPMTextureIdx]; |
212 GrTexture* maskTex = textures[GrProcessorUnitTest::kAlphaTextureIdx]; | 215 GrTexture* maskTex = textures[GrProcessorUnitTest::kAlphaTextureIdx]; |
213 float inner_thresh = random->nextUScalar1(); | 216 float inner_thresh = random->nextUScalar1(); |
214 float outer_thresh = random->nextUScalar1(); | 217 float outer_thresh = random->nextUScalar1(); |
215 return AlphaThresholdEffect::Create(bmpTex, maskTex, inner_thresh, outer_thr
esh); | 218 GrShaderDataManager shaderDataManager; |
| 219 return AlphaThresholdEffect::Create(&shaderDataManager, bmpTex, maskTex, inn
er_thresh, |
| 220 outer_thresh); |
216 } | 221 } |
217 | 222 |
218 /////////////////////////////////////////////////////////////////////////////// | 223 /////////////////////////////////////////////////////////////////////////////// |
219 | 224 |
220 void AlphaThresholdEffect::getGLProcessorKey(const GrGLSLCaps& caps, | 225 void AlphaThresholdEffect::getGLProcessorKey(const GrGLSLCaps& caps, |
221 GrProcessorKeyBuilder* b) const { | 226 GrProcessorKeyBuilder* b) const { |
222 GrGLAlphaThresholdEffect::GenKey(*this, caps, b); | 227 GrGLAlphaThresholdEffect::GenKey(*this, caps, b); |
223 } | 228 } |
224 | 229 |
225 GrGLFragmentProcessor* AlphaThresholdEffect::createGLInstance() const { | 230 GrGLFragmentProcessor* AlphaThresholdEffect::createGLInstance() const { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 SkScalar outerThreshold, | 263 SkScalar outerThreshold, |
259 SkImageFilter* input) | 264 SkImageFilter* input) |
260 : INHERITED(1, &input) | 265 : INHERITED(1, &input) |
261 , fRegion(region) | 266 , fRegion(region) |
262 , fInnerThreshold(innerThreshold) | 267 , fInnerThreshold(innerThreshold) |
263 , fOuterThreshold(outerThreshold) { | 268 , fOuterThreshold(outerThreshold) { |
264 } | 269 } |
265 | 270 |
266 #if SK_SUPPORT_GPU | 271 #if SK_SUPPORT_GPU |
267 bool SkAlphaThresholdFilterImpl::asFragmentProcessor(GrFragmentProcessor** fp, | 272 bool SkAlphaThresholdFilterImpl::asFragmentProcessor(GrFragmentProcessor** fp, |
268 GrShaderDataManager*, | 273 GrShaderDataManager* shader
DataManager, |
269 GrTexture* texture, | 274 GrTexture* texture, |
270 const SkMatrix& in_matrix, | 275 const SkMatrix& in_matrix, |
271 const SkIRect&) const { | 276 const SkIRect&) const { |
272 if (fp) { | 277 if (fp) { |
273 GrContext* context = texture->getContext(); | 278 GrContext* context = texture->getContext(); |
274 GrSurfaceDesc maskDesc; | 279 GrSurfaceDesc maskDesc; |
275 if (context->caps()->isConfigRenderable(kAlpha_8_GrPixelConfig, false))
{ | 280 if (context->caps()->isConfigRenderable(kAlpha_8_GrPixelConfig, false))
{ |
276 maskDesc.fConfig = kAlpha_8_GrPixelConfig; | 281 maskDesc.fConfig = kAlpha_8_GrPixelConfig; |
277 } else { | 282 } else { |
278 maskDesc.fConfig = kRGBA_8888_GrPixelConfig; | 283 maskDesc.fConfig = kRGBA_8888_GrPixelConfig; |
(...skipping 17 matching lines...) Expand all Loading... |
296 drawContext->clear(maskTexture->asRenderTarget(), NULL, 0x0, true); | 301 drawContext->clear(maskTexture->asRenderTarget(), NULL, 0x0, true); |
297 | 302 |
298 while (!iter.done()) { | 303 while (!iter.done()) { |
299 SkRect rect = SkRect::Make(iter.rect()); | 304 SkRect rect = SkRect::Make(iter.rect()); |
300 drawContext->drawRect(maskTexture->asRenderTarget(), GrClip::Wid
eOpen(), grPaint, | 305 drawContext->drawRect(maskTexture->asRenderTarget(), GrClip::Wid
eOpen(), grPaint, |
301 in_matrix, rect); | 306 in_matrix, rect); |
302 iter.next(); | 307 iter.next(); |
303 } | 308 } |
304 } | 309 } |
305 | 310 |
306 *fp = AlphaThresholdEffect::Create(texture, | 311 *fp = AlphaThresholdEffect::Create(shaderDataManager, |
| 312 texture, |
307 maskTexture, | 313 maskTexture, |
308 fInnerThreshold, | 314 fInnerThreshold, |
309 fOuterThreshold); | 315 fOuterThreshold); |
310 } | 316 } |
311 return true; | 317 return true; |
312 } | 318 } |
313 #endif | 319 #endif |
314 | 320 |
315 void SkAlphaThresholdFilterImpl::flatten(SkWriteBuffer& buffer) const { | 321 void SkAlphaThresholdFilterImpl::flatten(SkWriteBuffer& buffer) const { |
316 this->INHERITED::flatten(buffer); | 322 this->INHERITED::flatten(buffer); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 } | 388 } |
383 | 389 |
384 #ifndef SK_IGNORE_TO_STRING | 390 #ifndef SK_IGNORE_TO_STRING |
385 void SkAlphaThresholdFilterImpl::toString(SkString* str) const { | 391 void SkAlphaThresholdFilterImpl::toString(SkString* str) const { |
386 str->appendf("SkAlphaThresholdImageFilter: ("); | 392 str->appendf("SkAlphaThresholdImageFilter: ("); |
387 str->appendf("inner: %f outer: %f", fInnerThreshold, fOuterThreshold); | 393 str->appendf("inner: %f outer: %f", fInnerThreshold, fOuterThreshold); |
388 str->append(")"); | 394 str->append(")"); |
389 } | 395 } |
390 #endif | 396 #endif |
391 | 397 |
OLD | NEW |