| 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 "SkDevice.h" | 10 #include "SkDevice.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 SkRegion fRegion; | 38 SkRegion fRegion; |
| 39 SkScalar fInnerThreshold; | 39 SkScalar fInnerThreshold; |
| 40 SkScalar fOuterThreshold; | 40 SkScalar fOuterThreshold; |
| 41 typedef SkImageFilter INHERITED; | 41 typedef SkImageFilter INHERITED; |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkAlphaThresholdFilter) | 44 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkAlphaThresholdFilter) |
| 45 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkAlphaThresholdFilterImpl) | 45 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkAlphaThresholdFilterImpl) |
| 46 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 46 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
| 47 | 47 |
| 48 static bool outside_unit(SkScalar x) { | |
| 49 return x < 0 || x > 1; | |
| 50 } | |
| 51 | 48 |
| 52 SkImageFilter* SkAlphaThresholdFilter::Create(const SkRegion& region, | 49 SkImageFilter* SkAlphaThresholdFilter::Create(const SkRegion& region, |
| 53 SkScalar innerThreshold, | 50 SkScalar innerThreshold, |
| 54 SkScalar outerThreshold, | 51 SkScalar outerThreshold, |
| 55 SkImageFilter* input) { | 52 SkImageFilter* input) { |
| 56 if (outside_unit(innerThreshold) || outside_unit(outerThreshold) || | |
| 57 innerThreshold > outerThreshold) | |
| 58 { | |
| 59 return nullptr; | |
| 60 } | |
| 61 return new SkAlphaThresholdFilterImpl(region, innerThreshold, outerThreshold
, input); | 53 return new SkAlphaThresholdFilterImpl(region, innerThreshold, outerThreshold
, input); |
| 62 } | 54 } |
| 63 | 55 |
| 64 #if SK_SUPPORT_GPU | 56 #if SK_SUPPORT_GPU |
| 65 #include "GrContext.h" | 57 #include "GrContext.h" |
| 66 #include "GrCoordTransform.h" | 58 #include "GrCoordTransform.h" |
| 67 #include "GrFragmentProcessor.h" | 59 #include "GrFragmentProcessor.h" |
| 68 #include "GrInvariantOutput.h" | 60 #include "GrInvariantOutput.h" |
| 69 #include "GrTextureAccess.h" | 61 #include "GrTextureAccess.h" |
| 70 #include "effects/GrPorterDuffXferProcessor.h" | 62 #include "effects/GrPorterDuffXferProcessor.h" |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 void SkAlphaThresholdFilterImpl::flatten(SkWriteBuffer& buffer) const { | 327 void SkAlphaThresholdFilterImpl::flatten(SkWriteBuffer& buffer) const { |
| 336 this->INHERITED::flatten(buffer); | 328 this->INHERITED::flatten(buffer); |
| 337 buffer.writeScalar(fInnerThreshold); | 329 buffer.writeScalar(fInnerThreshold); |
| 338 buffer.writeScalar(fOuterThreshold); | 330 buffer.writeScalar(fOuterThreshold); |
| 339 buffer.writeRegion(fRegion); | 331 buffer.writeRegion(fRegion); |
| 340 } | 332 } |
| 341 | 333 |
| 342 bool SkAlphaThresholdFilterImpl::onFilterImageDeprecated(Proxy* proxy, const SkB
itmap& src, | 334 bool SkAlphaThresholdFilterImpl::onFilterImageDeprecated(Proxy* proxy, const SkB
itmap& src, |
| 343 const Context& ctx, SkB
itmap* dst, | 335 const Context& ctx, SkB
itmap* dst, |
| 344 SkIPoint* offset) const
{ | 336 SkIPoint* offset) const
{ |
| 337 SkASSERT(src.colorType() == kN32_SkColorType); |
| 345 | 338 |
| 346 if (src.colorType() != kN32_SkColorType) { | 339 if (src.colorType() != kN32_SkColorType) { |
| 347 return false; | 340 return false; |
| 348 } | 341 } |
| 349 | 342 |
| 350 SkMatrix localInverse; | 343 SkMatrix localInverse; |
| 351 if (!ctx.ctm().invert(&localInverse)) { | 344 if (!ctx.ctm().invert(&localInverse)) { |
| 352 return false; | 345 return false; |
| 353 } | 346 } |
| 354 | 347 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 } | 397 } |
| 405 | 398 |
| 406 #ifndef SK_IGNORE_TO_STRING | 399 #ifndef SK_IGNORE_TO_STRING |
| 407 void SkAlphaThresholdFilterImpl::toString(SkString* str) const { | 400 void SkAlphaThresholdFilterImpl::toString(SkString* str) const { |
| 408 str->appendf("SkAlphaThresholdImageFilter: ("); | 401 str->appendf("SkAlphaThresholdImageFilter: ("); |
| 409 str->appendf("inner: %f outer: %f", fInnerThreshold, fOuterThreshold); | 402 str->appendf("inner: %f outer: %f", fInnerThreshold, fOuterThreshold); |
| 410 str->append(")"); | 403 str->append(")"); |
| 411 } | 404 } |
| 412 #endif | 405 #endif |
| 413 | 406 |
| OLD | NEW |