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

Side by Side Diff: src/core/SkGeometry.cpp

Issue 2359253002: Reland of ix for conic fuzz (Closed)
Patch Set: Created 4 years, 3 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 | « no previous file | tests/PathTest.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 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
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 "SkGeometry.h" 8 #include "SkGeometry.h"
9 #include "SkMatrix.h" 9 #include "SkMatrix.h"
10 #include "SkNx.h" 10 #include "SkNx.h"
(...skipping 1135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1146 SkScalar fpow2 = SkScalarLog2((x * x + y * y) / tol2) * 0.25f; 1146 SkScalar fpow2 = SkScalarLog2((x * x + y * y) / tol2) * 0.25f;
1147 int altPow2 = SkScalarCeilToInt(fpow2); 1147 int altPow2 = SkScalarCeilToInt(fpow2);
1148 if (altPow2 != pow2) { 1148 if (altPow2 != pow2) {
1149 SkDebugf("pow2 %d altPow2 %d fbits %g err %g tol %g\n", pow2, altPow 2, fpow2, err, tol); 1149 SkDebugf("pow2 %d altPow2 %d fbits %g err %g tol %g\n", pow2, altPow 2, fpow2, err, tol);
1150 } 1150 }
1151 pow2 = altPow2; 1151 pow2 = altPow2;
1152 } 1152 }
1153 return pow2; 1153 return pow2;
1154 } 1154 }
1155 1155
1156 // This was originally developed and tested for pathops: see SkOpTypes.h
1157 // returns true if (a <= b <= c) || (a >= b >= c)
1158 static bool between(SkScalar a, SkScalar b, SkScalar c) {
1159 return (a - b) * (c - b) <= 0;
1160 }
1161
1156 static SkPoint* subdivide(const SkConic& src, SkPoint pts[], int level) { 1162 static SkPoint* subdivide(const SkConic& src, SkPoint pts[], int level) {
1157 SkASSERT(level >= 0); 1163 SkASSERT(level >= 0);
1158 1164
1159 if (0 == level) { 1165 if (0 == level) {
1160 memcpy(pts, &src.fPts[1], 2 * sizeof(SkPoint)); 1166 memcpy(pts, &src.fPts[1], 2 * sizeof(SkPoint));
1161 return pts + 2; 1167 return pts + 2;
1162 } else { 1168 } else {
1163 SkConic dst[2]; 1169 SkConic dst[2];
1164 src.chop(dst); 1170 src.chop(dst);
1171 const SkScalar startY = src.fPts[0].fY;
1172 const SkScalar endY = src.fPts[2].fY;
1173 if (between(startY, src.fPts[1].fY, endY)) {
1174 // If the input is monotonic and the output is not, the scan convert er hangs.
1175 // Ensure that the chopped conics maintain their y-order.
1176 SkScalar midY = dst[0].fPts[2].fY;
1177 if (!between(startY, midY, endY)) {
1178 // If the computed midpoint is outside the ends, move it to the closer one.
1179 SkScalar closerY = SkTAbs(midY - startY) < SkTAbs(midY - endY) ? startY : endY;
1180 dst[0].fPts[2].fY = dst[1].fPts[0].fY = closerY;
1181 }
1182 if (!between(startY, dst[0].fPts[1].fY, dst[0].fPts[2].fY)) {
1183 // If the 1st control is not between the start and end, put it a t the start.
1184 // This also reduces the quad to a line.
1185 dst[0].fPts[1].fY = startY;
1186 }
1187 if (!between(dst[1].fPts[0].fY, dst[1].fPts[1].fY, endY)) {
1188 // If the 2nd control is not between the start and end, put it a t the end.
1189 // This also reduces the quad to a line.
1190 dst[1].fPts[1].fY = endY;
1191 }
1192 // Verify that all five points are in order.
1193 SkASSERT(between(startY, dst[0].fPts[1].fY, dst[0].fPts[2].fY));
1194 SkASSERT(between(dst[0].fPts[1].fY, dst[0].fPts[2].fY, dst[1].fPts[1 ].fY));
1195 SkASSERT(between(dst[0].fPts[2].fY, dst[1].fPts[1].fY, endY));
1196 }
1165 --level; 1197 --level;
1166 pts = subdivide(dst[0], pts, level); 1198 pts = subdivide(dst[0], pts, level);
1167 return subdivide(dst[1], pts, level); 1199 return subdivide(dst[1], pts, level);
1168 } 1200 }
1169 } 1201 }
1170 1202
1171 int SkConic::chopIntoQuadsPOW2(SkPoint pts[], int pow2) const { 1203 int SkConic::chopIntoQuadsPOW2(SkPoint pts[], int pow2) const {
1172 SkASSERT(pow2 >= 0); 1204 SkASSERT(pow2 >= 0);
1173 *pts = fPts[0]; 1205 *pts = fPts[0];
1174 SkDEBUGCODE(SkPoint* endPts); 1206 SkDEBUGCODE(SkPoint* endPts);
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
1365 matrix.preScale(SK_Scalar1, -SK_Scalar1); 1397 matrix.preScale(SK_Scalar1, -SK_Scalar1);
1366 } 1398 }
1367 if (userMatrix) { 1399 if (userMatrix) {
1368 matrix.postConcat(*userMatrix); 1400 matrix.postConcat(*userMatrix);
1369 } 1401 }
1370 for (int i = 0; i < conicCount; ++i) { 1402 for (int i = 0; i < conicCount; ++i) {
1371 matrix.mapPoints(dst[i].fPts, 3); 1403 matrix.mapPoints(dst[i].fPts, 3);
1372 } 1404 }
1373 return conicCount; 1405 return conicCount;
1374 } 1406 }
OLDNEW
« no previous file with comments | « no previous file | tests/PathTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698