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