| 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 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 SK_TO_STRING_OVERRIDE() | 22 SK_TO_STRING_OVERRIDE() |
| 23 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkAlphaThresholdFilterIm
pl) | 23 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkAlphaThresholdFilterIm
pl) |
| 24 | 24 |
| 25 protected: | 25 protected: |
| 26 void flatten(SkWriteBuffer&) const override; | 26 void flatten(SkWriteBuffer&) const override; |
| 27 | 27 |
| 28 bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, | 28 bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, |
| 29 SkBitmap* result, SkIPoint* offset) const override; | 29 SkBitmap* result, SkIPoint* offset) const override; |
| 30 #if SK_SUPPORT_GPU | 30 #if SK_SUPPORT_GPU |
| 31 bool asFragmentProcessor(GrFragmentProcessor**, GrProcessorDataManager*, GrT
exture*, | 31 bool asFragmentProcessor(GrFragmentProcessor**, GrTexture*, const SkMatrix&, |
| 32 const SkMatrix&, const SkIRect& bounds) const overr
ide; | 32 const SkIRect& bounds) const override; |
| 33 #endif | 33 #endif |
| 34 | 34 |
| 35 private: | 35 private: |
| 36 SkRegion fRegion; | 36 SkRegion fRegion; |
| 37 SkScalar fInnerThreshold; | 37 SkScalar fInnerThreshold; |
| 38 SkScalar fOuterThreshold; | 38 SkScalar fOuterThreshold; |
| 39 typedef SkImageFilter INHERITED; | 39 typedef SkImageFilter INHERITED; |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 SkImageFilter* SkAlphaThresholdFilter::Create(const SkRegion& region, | 42 SkImageFilter* SkAlphaThresholdFilter::Create(const SkRegion& region, |
| (...skipping 12 matching lines...) Expand all 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/GrGLFragmentProcessor.h" | 59 #include "gl/GrGLFragmentProcessor.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(GrProcessorDataManager* procDataManager, | 65 static GrFragmentProcessor* Create(GrTexture* texture, |
| 66 GrTexture* texture, | |
| 67 GrTexture* maskTexture, | 66 GrTexture* maskTexture, |
| 68 float innerThreshold, | 67 float innerThreshold, |
| 69 float outerThreshold) { | 68 float outerThreshold) { |
| 70 return new AlphaThresholdEffect(procDataManager, texture, maskTexture, i
nnerThreshold, | 69 return new AlphaThresholdEffect(texture, maskTexture, innerThreshold, ou
terThreshold); |
| 71 outerThreshold); | |
| 72 } | 70 } |
| 73 | 71 |
| 74 virtual ~AlphaThresholdEffect() {}; | 72 virtual ~AlphaThresholdEffect() {}; |
| 75 | 73 |
| 76 const char* name() const override { return "Alpha Threshold"; } | 74 const char* name() const override { return "Alpha Threshold"; } |
| 77 | 75 |
| 78 float innerThreshold() const { return fInnerThreshold; } | 76 float innerThreshold() const { return fInnerThreshold; } |
| 79 float outerThreshold() const { return fOuterThreshold; } | 77 float outerThreshold() const { return fOuterThreshold; } |
| 80 | 78 |
| 81 private: | 79 private: |
| 82 AlphaThresholdEffect(GrProcessorDataManager*, | 80 AlphaThresholdEffect(GrTexture* texture, |
| 83 GrTexture* texture, | |
| 84 GrTexture* maskTexture, | 81 GrTexture* maskTexture, |
| 85 float innerThreshold, | 82 float innerThreshold, |
| 86 float outerThreshold) | 83 float outerThreshold) |
| 87 : fInnerThreshold(innerThreshold) | 84 : fInnerThreshold(innerThreshold) |
| 88 , fOuterThreshold(outerThreshold) | 85 , fOuterThreshold(outerThreshold) |
| 89 , fImageCoordTransform(kLocal_GrCoordSet, | 86 , fImageCoordTransform(kLocal_GrCoordSet, |
| 90 GrCoordTransform::MakeDivByTextureWHMatrix(textur
e), texture, | 87 GrCoordTransform::MakeDivByTextureWHMatrix(textur
e), texture, |
| 91 GrTextureParams::kNone_FilterMode) | 88 GrTextureParams::kNone_FilterMode) |
| 92 , fImageTextureAccess(texture) | 89 , fImageTextureAccess(texture) |
| 93 , fMaskCoordTransform(kLocal_GrCoordSet, | 90 , fMaskCoordTransform(kLocal_GrCoordSet, |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 | 190 |
| 194 ///////////////////////////////////////////////////////////////////// | 191 ///////////////////////////////////////////////////////////////////// |
| 195 | 192 |
| 196 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(AlphaThresholdEffect); | 193 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(AlphaThresholdEffect); |
| 197 | 194 |
| 198 const GrFragmentProcessor* AlphaThresholdEffect::TestCreate(GrProcessorTestData*
d) { | 195 const GrFragmentProcessor* AlphaThresholdEffect::TestCreate(GrProcessorTestData*
d) { |
| 199 GrTexture* bmpTex = d->fTextures[GrProcessorUnitTest::kSkiaPMTextureIdx]; | 196 GrTexture* bmpTex = d->fTextures[GrProcessorUnitTest::kSkiaPMTextureIdx]; |
| 200 GrTexture* maskTex = d->fTextures[GrProcessorUnitTest::kAlphaTextureIdx]; | 197 GrTexture* maskTex = d->fTextures[GrProcessorUnitTest::kAlphaTextureIdx]; |
| 201 float innerThresh = d->fRandom->nextUScalar1(); | 198 float innerThresh = d->fRandom->nextUScalar1(); |
| 202 float outerThresh = d->fRandom->nextUScalar1(); | 199 float outerThresh = d->fRandom->nextUScalar1(); |
| 203 return AlphaThresholdEffect::Create(d->fProcDataManager, bmpTex, maskTex, in
nerThresh, | 200 return AlphaThresholdEffect::Create(bmpTex, maskTex, innerThresh, outerThres
h); |
| 204 outerThresh); | |
| 205 } | 201 } |
| 206 | 202 |
| 207 /////////////////////////////////////////////////////////////////////////////// | 203 /////////////////////////////////////////////////////////////////////////////// |
| 208 | 204 |
| 209 void AlphaThresholdEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, | 205 void AlphaThresholdEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, |
| 210 GrProcessorKeyBuilder* b) const { | 206 GrProcessorKeyBuilder* b) const { |
| 211 GrGLAlphaThresholdEffect::GenKey(*this, caps, b); | 207 GrGLAlphaThresholdEffect::GenKey(*this, caps, b); |
| 212 } | 208 } |
| 213 | 209 |
| 214 GrGLFragmentProcessor* AlphaThresholdEffect::onCreateGLInstance() const { | 210 GrGLFragmentProcessor* AlphaThresholdEffect::onCreateGLInstance() const { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 SkScalar outerThreshold, | 243 SkScalar outerThreshold, |
| 248 SkImageFilter* input) | 244 SkImageFilter* input) |
| 249 : INHERITED(1, &input) | 245 : INHERITED(1, &input) |
| 250 , fRegion(region) | 246 , fRegion(region) |
| 251 , fInnerThreshold(innerThreshold) | 247 , fInnerThreshold(innerThreshold) |
| 252 , fOuterThreshold(outerThreshold) { | 248 , fOuterThreshold(outerThreshold) { |
| 253 } | 249 } |
| 254 | 250 |
| 255 #if SK_SUPPORT_GPU | 251 #if SK_SUPPORT_GPU |
| 256 bool SkAlphaThresholdFilterImpl::asFragmentProcessor(GrFragmentProcessor** fp, | 252 bool SkAlphaThresholdFilterImpl::asFragmentProcessor(GrFragmentProcessor** fp, |
| 257 GrProcessorDataManager* pro
cDataManager, | |
| 258 GrTexture* texture, | 253 GrTexture* texture, |
| 259 const SkMatrix& in_matrix, | 254 const SkMatrix& in_matrix, |
| 260 const SkIRect&) const { | 255 const SkIRect&) const { |
| 261 if (fp) { | 256 if (fp) { |
| 262 GrContext* context = texture->getContext(); | 257 GrContext* context = texture->getContext(); |
| 263 GrSurfaceDesc maskDesc; | 258 GrSurfaceDesc maskDesc; |
| 264 if (context->caps()->isConfigRenderable(kAlpha_8_GrPixelConfig, false))
{ | 259 if (context->caps()->isConfigRenderable(kAlpha_8_GrPixelConfig, false))
{ |
| 265 maskDesc.fConfig = kAlpha_8_GrPixelConfig; | 260 maskDesc.fConfig = kAlpha_8_GrPixelConfig; |
| 266 } else { | 261 } else { |
| 267 maskDesc.fConfig = kRGBA_8888_GrPixelConfig; | 262 maskDesc.fConfig = kRGBA_8888_GrPixelConfig; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 285 drawContext->clear(maskTexture->asRenderTarget(), nullptr, 0x0, true
); | 280 drawContext->clear(maskTexture->asRenderTarget(), nullptr, 0x0, true
); |
| 286 | 281 |
| 287 while (!iter.done()) { | 282 while (!iter.done()) { |
| 288 SkRect rect = SkRect::Make(iter.rect()); | 283 SkRect rect = SkRect::Make(iter.rect()); |
| 289 drawContext->drawRect(maskTexture->asRenderTarget(), GrClip::Wid
eOpen(), grPaint, | 284 drawContext->drawRect(maskTexture->asRenderTarget(), GrClip::Wid
eOpen(), grPaint, |
| 290 in_matrix, rect); | 285 in_matrix, rect); |
| 291 iter.next(); | 286 iter.next(); |
| 292 } | 287 } |
| 293 } | 288 } |
| 294 | 289 |
| 295 *fp = AlphaThresholdEffect::Create(procDataManager, | 290 *fp = AlphaThresholdEffect::Create(texture, |
| 296 texture, | |
| 297 maskTexture, | 291 maskTexture, |
| 298 fInnerThreshold, | 292 fInnerThreshold, |
| 299 fOuterThreshold); | 293 fOuterThreshold); |
| 300 } | 294 } |
| 301 return true; | 295 return true; |
| 302 } | 296 } |
| 303 #endif | 297 #endif |
| 304 | 298 |
| 305 void SkAlphaThresholdFilterImpl::flatten(SkWriteBuffer& buffer) const { | 299 void SkAlphaThresholdFilterImpl::flatten(SkWriteBuffer& buffer) const { |
| 306 this->INHERITED::flatten(buffer); | 300 this->INHERITED::flatten(buffer); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 } | 366 } |
| 373 | 367 |
| 374 #ifndef SK_IGNORE_TO_STRING | 368 #ifndef SK_IGNORE_TO_STRING |
| 375 void SkAlphaThresholdFilterImpl::toString(SkString* str) const { | 369 void SkAlphaThresholdFilterImpl::toString(SkString* str) const { |
| 376 str->appendf("SkAlphaThresholdImageFilter: ("); | 370 str->appendf("SkAlphaThresholdImageFilter: ("); |
| 377 str->appendf("inner: %f outer: %f", fInnerThreshold, fOuterThreshold); | 371 str->appendf("inner: %f outer: %f", fInnerThreshold, fOuterThreshold); |
| 378 str->append(")"); | 372 str->append(")"); |
| 379 } | 373 } |
| 380 #endif | 374 #endif |
| 381 | 375 |
| OLD | NEW |