Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: src/effects/Sk1DPathEffect.cpp

Issue 1719993002: fix misc asserts and checks found by fuzzer (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: hide the creation of the typeface as well Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « samplecode/SampleFilterFuzz.cpp ('k') | src/effects/SkAlphaThresholdFilter.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "Sk1DPathEffect.h" 10 #include "Sk1DPathEffect.h"
(...skipping 17 matching lines...) Expand all
28 } 28 }
29 } while (meas.nextContour()); 29 } while (meas.nextContour());
30 return true; 30 return true;
31 } 31 }
32 32
33 /////////////////////////////////////////////////////////////////////////////// 33 ///////////////////////////////////////////////////////////////////////////////
34 34
35 SkPath1DPathEffect::SkPath1DPathEffect(const SkPath& path, SkScalar advance, 35 SkPath1DPathEffect::SkPath1DPathEffect(const SkPath& path, SkScalar advance,
36 SkScalar phase, Style style) : fPath(path) 36 SkScalar phase, Style style) : fPath(path)
37 { 37 {
38 if (advance <= 0 || path.isEmpty()) { 38 SkASSERT(advance > 0 && !path.isEmpty());
39 SkDEBUGF(("SkPath1DPathEffect can't use advance <= 0\n")); 39 // cleanup their phase parameter, inverting it so that it becomes an
40 fAdvance = 0; // signals we can't draw anything 40 // offset along the path (to match the interpretation in PostScript)
41 fInitialOffset = 0; 41 if (phase < 0) {
42 fStyle = kStyleCount; 42 phase = -phase;
43 if (phase > advance) {
44 phase = SkScalarMod(phase, advance);
45 }
43 } else { 46 } else {
44 // cleanup their phase parameter, inverting it so that it becomes an 47 if (phase > advance) {
45 // offset along the path (to match the interpretation in PostScript) 48 phase = SkScalarMod(phase, advance);
46 if (phase < 0) {
47 phase = -phase;
48 if (phase > advance) {
49 phase = SkScalarMod(phase, advance);
50 }
51 } else {
52 if (phase > advance) {
53 phase = SkScalarMod(phase, advance);
54 }
55 phase = advance - phase;
56 } 49 }
57 // now catch the edge case where phase == advance (within epsilon) 50 phase = advance - phase;
58 if (phase >= advance) { 51 }
59 phase = 0; 52 // now catch the edge case where phase == advance (within epsilon)
60 } 53 if (phase >= advance) {
61 SkASSERT(phase >= 0); 54 phase = 0;
55 }
56 SkASSERT(phase >= 0);
62 57
63 fAdvance = advance; 58 fAdvance = advance;
64 fInitialOffset = phase; 59 fInitialOffset = phase;
65 60
66 if ((unsigned)style >= kStyleCount) { 61 if ((unsigned)style > kMorph_Style) {
67 SkDEBUGF(("SkPath1DPathEffect style enum out of range %d\n", style)) ; 62 SkDEBUGF(("SkPath1DPathEffect style enum out of range %d\n", style));
68 }
69 fStyle = style;
70 } 63 }
64 fStyle = style;
71 } 65 }
72 66
73 bool SkPath1DPathEffect::filterPath(SkPath* dst, const SkPath& src, 67 bool SkPath1DPathEffect::filterPath(SkPath* dst, const SkPath& src,
74 SkStrokeRec* rec, const SkRect* cullRect) const { 68 SkStrokeRec* rec, const SkRect* cullRect) const {
75 if (fAdvance > 0) { 69 if (fAdvance > 0) {
76 rec->setFillStyle(); 70 rec->setFillStyle();
77 return this->INHERITED::filterPath(dst, src, rec, cullRect); 71 return this->INHERITED::filterPath(dst, src, rec, cullRect);
78 } 72 }
79 return false; 73 return false;
80 } 74 }
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 194
201 195
202 #ifndef SK_IGNORE_TO_STRING 196 #ifndef SK_IGNORE_TO_STRING
203 void SkPath1DPathEffect::toString(SkString* str) const { 197 void SkPath1DPathEffect::toString(SkString* str) const {
204 str->appendf("SkPath1DPathEffect: ("); 198 str->appendf("SkPath1DPathEffect: (");
205 // TODO: add path and style 199 // TODO: add path and style
206 str->appendf("advance: %.2f phase %.2f", fAdvance, fInitialOffset); 200 str->appendf("advance: %.2f phase %.2f", fAdvance, fInitialOffset);
207 str->appendf(")"); 201 str->appendf(")");
208 } 202 }
209 #endif 203 #endif
204
205 //////////////////////////////////////////////////////////////////////////////// ///////////////////
206
207 SkPathEffect* SkPath1DPathEffect::Create(const SkPath& path, SkScalar advance, S kScalar phase,
208 Style style) {
209 if (advance <= 0 || path.isEmpty()) {
210 return nullptr;
211 }
212 return new SkPath1DPathEffect(path, advance, phase, style);
213 }
OLDNEW
« no previous file with comments | « samplecode/SampleFilterFuzz.cpp ('k') | src/effects/SkAlphaThresholdFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698