| 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 |
| 9 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
| 10 #include "SkDevice.h" | 11 #include "SkDevice.h" |
| 11 #include "SkReadBuffer.h" | 12 #include "SkReadBuffer.h" |
| 12 #include "SkWriteBuffer.h" | 13 #include "SkWriteBuffer.h" |
| 13 #include "SkRegion.h" | 14 #include "SkRegion.h" |
| 14 #if SK_SUPPORT_GPU | 15 #if SK_SUPPORT_GPU |
| 15 #include "GrDrawContext.h" | 16 #include "GrDrawContext.h" |
| 16 #endif | 17 #endif |
| 17 | 18 |
| 18 class SK_API SkAlphaThresholdFilterImpl : public SkImageFilter { | 19 class SK_API SkAlphaThresholdFilterImpl : public SkImageFilter { |
| 19 public: | 20 public: |
| 20 SkAlphaThresholdFilterImpl(const SkRegion& region, SkScalar innerThreshold, | 21 SkAlphaThresholdFilterImpl(const SkRegion& region, SkScalar innerThreshold, |
| 21 SkScalar outerThreshold, SkImageFilter* input); | 22 SkScalar outerThreshold, sk_sp<SkImageFilter> inp
ut); |
| 22 | 23 |
| 23 SK_TO_STRING_OVERRIDE() | 24 SK_TO_STRING_OVERRIDE() |
| 24 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkAlphaThresholdFilterIm
pl) | 25 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkAlphaThresholdFilterIm
pl) |
| 25 friend void SkAlphaThresholdFilter::InitializeFlattenables(); | 26 friend void SkAlphaThresholdFilter::InitializeFlattenables(); |
| 26 | 27 |
| 27 protected: | 28 protected: |
| 28 void flatten(SkWriteBuffer&) const override; | 29 void flatten(SkWriteBuffer&) const override; |
| 29 | 30 |
| 30 bool onFilterImageDeprecated(Proxy*, const SkBitmap& src, const Context&, | 31 bool onFilterImageDeprecated(Proxy*, const SkBitmap& src, const Context&, |
| 31 SkBitmap* result, SkIPoint* offset) const overr
ide; | 32 SkBitmap* result, SkIPoint* offset) const overr
ide; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 42 }; | 43 }; |
| 43 | 44 |
| 44 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkAlphaThresholdFilter) | 45 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkAlphaThresholdFilter) |
| 45 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkAlphaThresholdFilterImpl) | 46 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkAlphaThresholdFilterImpl) |
| 46 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 47 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
| 47 | 48 |
| 48 static SkScalar pin_0_1(SkScalar x) { | 49 static SkScalar pin_0_1(SkScalar x) { |
| 49 return SkMinScalar(SkMaxScalar(x, 0), 1); | 50 return SkMinScalar(SkMaxScalar(x, 0), 1); |
| 50 } | 51 } |
| 51 | 52 |
| 52 SkImageFilter* SkAlphaThresholdFilter::Create(const SkRegion& region, | 53 sk_sp<SkImageFilter> SkAlphaThresholdFilter::Make(const SkRegion& region, |
| 53 SkScalar innerThreshold, | 54 SkScalar innerThreshold, |
| 54 SkScalar outerThreshold, | 55 SkScalar outerThreshold, |
| 55 SkImageFilter* input) { | 56 sk_sp<SkImageFilter> input) { |
| 56 innerThreshold = pin_0_1(innerThreshold); | 57 innerThreshold = pin_0_1(innerThreshold); |
| 57 outerThreshold = pin_0_1(outerThreshold); | 58 outerThreshold = pin_0_1(outerThreshold); |
| 58 if (!SkScalarIsFinite(innerThreshold) || !SkScalarIsFinite(outerThreshold))
{ | 59 if (!SkScalarIsFinite(innerThreshold) || !SkScalarIsFinite(outerThreshold))
{ |
| 59 return nullptr; | 60 return nullptr; |
| 60 } | 61 } |
| 61 return new SkAlphaThresholdFilterImpl(region, innerThreshold, outerThreshold
, input); | 62 return sk_sp<SkImageFilter>(new SkAlphaThresholdFilterImpl(region, innerThre
shold, |
| 63 outerThreshold, s
td::move(input))); |
| 62 } | 64 } |
| 63 | 65 |
| 64 #if SK_SUPPORT_GPU | 66 #if SK_SUPPORT_GPU |
| 65 #include "GrContext.h" | 67 #include "GrContext.h" |
| 66 #include "GrCoordTransform.h" | 68 #include "GrCoordTransform.h" |
| 67 #include "GrFragmentProcessor.h" | 69 #include "GrFragmentProcessor.h" |
| 68 #include "GrInvariantOutput.h" | 70 #include "GrInvariantOutput.h" |
| 69 #include "GrTextureAccess.h" | 71 #include "GrTextureAccess.h" |
| 70 #include "effects/GrPorterDuffXferProcessor.h" | 72 #include "effects/GrPorterDuffXferProcessor.h" |
| 71 | 73 |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 } | 264 } |
| 263 | 265 |
| 264 #endif | 266 #endif |
| 265 | 267 |
| 266 SkFlattenable* SkAlphaThresholdFilterImpl::CreateProc(SkReadBuffer& buffer) { | 268 SkFlattenable* SkAlphaThresholdFilterImpl::CreateProc(SkReadBuffer& buffer) { |
| 267 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); | 269 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); |
| 268 SkScalar inner = buffer.readScalar(); | 270 SkScalar inner = buffer.readScalar(); |
| 269 SkScalar outer = buffer.readScalar(); | 271 SkScalar outer = buffer.readScalar(); |
| 270 SkRegion rgn; | 272 SkRegion rgn; |
| 271 buffer.readRegion(&rgn); | 273 buffer.readRegion(&rgn); |
| 272 return SkAlphaThresholdFilter::Create(rgn, inner, outer, common.getInput(0).
get()); | 274 return SkAlphaThresholdFilter::Make(rgn, inner, outer, common.getInput(0)).r
elease(); |
| 273 } | 275 } |
| 274 | 276 |
| 275 SkAlphaThresholdFilterImpl::SkAlphaThresholdFilterImpl(const SkRegion& region, | 277 SkAlphaThresholdFilterImpl::SkAlphaThresholdFilterImpl(const SkRegion& region, |
| 276 SkScalar innerThreshold, | 278 SkScalar innerThreshold, |
| 277 SkScalar outerThreshold, | 279 SkScalar outerThreshold, |
| 278 SkImageFilter* input) | 280 sk_sp<SkImageFilter> inpu
t) |
| 279 : INHERITED(1, &input) | 281 : INHERITED(&input, 1, nullptr) |
| 280 , fRegion(region) | 282 , fRegion(region) |
| 281 , fInnerThreshold(innerThreshold) | 283 , fInnerThreshold(innerThreshold) |
| 282 , fOuterThreshold(outerThreshold) { | 284 , fOuterThreshold(outerThreshold) { |
| 283 } | 285 } |
| 284 | 286 |
| 285 #if SK_SUPPORT_GPU | 287 #if SK_SUPPORT_GPU |
| 286 bool SkAlphaThresholdFilterImpl::asFragmentProcessor(GrFragmentProcessor** fp, | 288 bool SkAlphaThresholdFilterImpl::asFragmentProcessor(GrFragmentProcessor** fp, |
| 287 GrTexture* texture, | 289 GrTexture* texture, |
| 288 const SkMatrix& inMatrix, | 290 const SkMatrix& inMatrix, |
| 289 const SkIRect& bounds) cons
t { | 291 const SkIRect& bounds) cons
t { |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 return true; | 405 return true; |
| 404 } | 406 } |
| 405 | 407 |
| 406 #ifndef SK_IGNORE_TO_STRING | 408 #ifndef SK_IGNORE_TO_STRING |
| 407 void SkAlphaThresholdFilterImpl::toString(SkString* str) const { | 409 void SkAlphaThresholdFilterImpl::toString(SkString* str) const { |
| 408 str->appendf("SkAlphaThresholdImageFilter: ("); | 410 str->appendf("SkAlphaThresholdImageFilter: ("); |
| 409 str->appendf("inner: %f outer: %f", fInnerThreshold, fOuterThreshold); | 411 str->appendf("inner: %f outer: %f", fInnerThreshold, fOuterThreshold); |
| 410 str->append(")"); | 412 str->append(")"); |
| 411 } | 413 } |
| 412 #endif | 414 #endif |
| OLD | NEW |