aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/effects/Sk1DPathEffect.cpp60
-rw-r--r--src/effects/SkAlphaThresholdFilter.cpp9
-rw-r--r--src/effects/SkDashPathEffect.cpp14
3 files changed, 54 insertions, 29 deletions
diff --git a/src/effects/Sk1DPathEffect.cpp b/src/effects/Sk1DPathEffect.cpp
index 041886e1db..4be6f975d3 100644
--- a/src/effects/Sk1DPathEffect.cpp
+++ b/src/effects/Sk1DPathEffect.cpp
@@ -35,39 +35,33 @@ bool Sk1DPathEffect::filterPath(SkPath* dst, const SkPath& src,
SkPath1DPathEffect::SkPath1DPathEffect(const SkPath& path, SkScalar advance,
SkScalar phase, Style style) : fPath(path)
{
- if (advance <= 0 || path.isEmpty()) {
- SkDEBUGF(("SkPath1DPathEffect can't use advance <= 0\n"));
- fAdvance = 0; // signals we can't draw anything
- fInitialOffset = 0;
- fStyle = kStyleCount;
- } else {
- // cleanup their phase parameter, inverting it so that it becomes an
- // offset along the path (to match the interpretation in PostScript)
- if (phase < 0) {
- phase = -phase;
- if (phase > advance) {
- phase = SkScalarMod(phase, advance);
- }
- } else {
- if (phase > advance) {
- phase = SkScalarMod(phase, advance);
- }
- phase = advance - phase;
+ SkASSERT(advance > 0 && !path.isEmpty());
+ // cleanup their phase parameter, inverting it so that it becomes an
+ // offset along the path (to match the interpretation in PostScript)
+ if (phase < 0) {
+ phase = -phase;
+ if (phase > advance) {
+ phase = SkScalarMod(phase, advance);
}
- // now catch the edge case where phase == advance (within epsilon)
- if (phase >= advance) {
- phase = 0;
+ } else {
+ if (phase > advance) {
+ phase = SkScalarMod(phase, advance);
}
- SkASSERT(phase >= 0);
+ phase = advance - phase;
+ }
+ // now catch the edge case where phase == advance (within epsilon)
+ if (phase >= advance) {
+ phase = 0;
+ }
+ SkASSERT(phase >= 0);
- fAdvance = advance;
- fInitialOffset = phase;
+ fAdvance = advance;
+ fInitialOffset = phase;
- if ((unsigned)style >= kStyleCount) {
- SkDEBUGF(("SkPath1DPathEffect style enum out of range %d\n", style));
- }
- fStyle = style;
+ if ((unsigned)style > kMorph_Style) {
+ SkDEBUGF(("SkPath1DPathEffect style enum out of range %d\n", style));
}
+ fStyle = style;
}
bool SkPath1DPathEffect::filterPath(SkPath* dst, const SkPath& src,
@@ -207,3 +201,13 @@ void SkPath1DPathEffect::toString(SkString* str) const {
str->appendf(")");
}
#endif
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+SkPathEffect* SkPath1DPathEffect::Create(const SkPath& path, SkScalar advance, SkScalar phase,
+ Style style) {
+ if (advance <= 0 || path.isEmpty()) {
+ return nullptr;
+ }
+ return new SkPath1DPathEffect(path, advance, phase, style);
+}
diff --git a/src/effects/SkAlphaThresholdFilter.cpp b/src/effects/SkAlphaThresholdFilter.cpp
index 79520602b7..d3d36f7630 100644
--- a/src/effects/SkAlphaThresholdFilter.cpp
+++ b/src/effects/SkAlphaThresholdFilter.cpp
@@ -45,11 +45,19 @@ SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkAlphaThresholdFilter)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkAlphaThresholdFilterImpl)
SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
+static SkScalar pin_0_1(SkScalar x) {
+ return SkMinScalar(SkMaxScalar(x, 0), 1);
+}
SkImageFilter* SkAlphaThresholdFilter::Create(const SkRegion& region,
SkScalar innerThreshold,
SkScalar outerThreshold,
SkImageFilter* input) {
+ innerThreshold = pin_0_1(innerThreshold);
+ outerThreshold = pin_0_1(outerThreshold);
+ if (!SkScalarIsFinite(innerThreshold) || !SkScalarIsFinite(outerThreshold)) {
+ return nullptr;
+ }
return new SkAlphaThresholdFilterImpl(region, innerThreshold, outerThreshold, input);
}
@@ -334,7 +342,6 @@ void SkAlphaThresholdFilterImpl::flatten(SkWriteBuffer& buffer) const {
bool SkAlphaThresholdFilterImpl::onFilterImageDeprecated(Proxy* proxy, const SkBitmap& src,
const Context& ctx, SkBitmap* dst,
SkIPoint* offset) const {
- SkASSERT(src.colorType() == kN32_SkColorType);
if (src.colorType() != kN32_SkColorType) {
return false;
diff --git a/src/effects/SkDashPathEffect.cpp b/src/effects/SkDashPathEffect.cpp
index 6e10e5466d..ced0aab69a 100644
--- a/src/effects/SkDashPathEffect.cpp
+++ b/src/effects/SkDashPathEffect.cpp
@@ -384,3 +384,17 @@ void SkDashPathEffect::toString(SkString* str) const {
str->appendf("))");
}
#endif
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
+
+SkPathEffect* SkDashPathEffect::Create(const SkScalar intervals[], int count, SkScalar phase) {
+ if ((count < 2) || !SkIsAlign2(count)) {
+ return nullptr;
+ }
+ for (int i = 0; i < count; i++) {
+ if (intervals[i] < 0) {
+ return nullptr;
+ }
+ }
+ return new SkDashPathEffect(intervals, count, phase);
+}