| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "GrAAHairLinePathRenderer.h" | 8 #include "GrAAHairLinePathRenderer.h" |
| 9 | 9 |
| 10 #include "GrBatch.h" | 10 #include "GrBatch.h" |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 conicCnt = conicCnt2 + split_conic(dstTemp[1].fPts, &dst[conicCnt2], dst
Temp[1].fW); | 177 conicCnt = conicCnt2 + split_conic(dstTemp[1].fPts, &dst[conicCnt2], dst
Temp[1].fW); |
| 178 } else { | 178 } else { |
| 179 dst[0] = dstTemp[0]; | 179 dst[0] = dstTemp[0]; |
| 180 } | 180 } |
| 181 return conicCnt; | 181 return conicCnt; |
| 182 } | 182 } |
| 183 | 183 |
| 184 // returns 0 if quad/conic is degen or close to it | 184 // returns 0 if quad/conic is degen or close to it |
| 185 // in this case approx the path with lines | 185 // in this case approx the path with lines |
| 186 // otherwise returns 1 | 186 // otherwise returns 1 |
| 187 int is_degen_quad_or_conic(const SkPoint p[3]) { | 187 int is_degen_quad_or_conic(const SkPoint p[3], SkScalar* dsqd) { |
| 188 static const SkScalar gDegenerateToLineTol = SK_Scalar1; | 188 static const SkScalar gDegenerateToLineTol = SK_Scalar1; |
| 189 static const SkScalar gDegenerateToLineTolSqd = | 189 static const SkScalar gDegenerateToLineTolSqd = |
| 190 SkScalarMul(gDegenerateToLineTol, gDegenerateToLineTol); | 190 SkScalarMul(gDegenerateToLineTol, gDegenerateToLineTol); |
| 191 | 191 |
| 192 if (p[0].distanceToSqd(p[1]) < gDegenerateToLineTolSqd || | 192 if (p[0].distanceToSqd(p[1]) < gDegenerateToLineTolSqd || |
| 193 p[1].distanceToSqd(p[2]) < gDegenerateToLineTolSqd) { | 193 p[1].distanceToSqd(p[2]) < gDegenerateToLineTolSqd) { |
| 194 return 1; | 194 return 1; |
| 195 } | 195 } |
| 196 | 196 |
| 197 SkScalar dsqd = p[1].distanceToLineBetweenSqd(p[0], p[2]); | 197 *dsqd = p[1].distanceToLineBetweenSqd(p[0], p[2]); |
| 198 if (dsqd < gDegenerateToLineTolSqd) { | 198 if (*dsqd < gDegenerateToLineTolSqd) { |
| 199 return 1; | 199 return 1; |
| 200 } | 200 } |
| 201 | 201 |
| 202 if (p[2].distanceToLineBetweenSqd(p[1], p[0]) < gDegenerateToLineTolSqd) { | 202 if (p[2].distanceToLineBetweenSqd(p[1], p[0]) < gDegenerateToLineTolSqd) { |
| 203 return 1; | 203 return 1; |
| 204 } | 204 } |
| 205 return 0; | 205 return 0; |
| 206 } | 206 } |
| 207 | 207 |
| 208 int is_degen_quad_or_conic(const SkPoint p[3]) { |
| 209 SkScalar dsqd; |
| 210 return is_degen_quad_or_conic(p, &dsqd); |
| 211 } |
| 212 |
| 208 // we subdivide the quads to avoid huge overfill | 213 // we subdivide the quads to avoid huge overfill |
| 209 // if it returns -1 then should be drawn as lines | 214 // if it returns -1 then should be drawn as lines |
| 210 int num_quad_subdivs(const SkPoint p[3]) { | 215 int num_quad_subdivs(const SkPoint p[3]) { |
| 211 static const SkScalar gDegenerateToLineTol = SK_Scalar1; | 216 SkScalar dsqd; |
| 212 static const SkScalar gDegenerateToLineTolSqd = | 217 if (is_degen_quad_or_conic(p, &dsqd)) { |
| 213 SkScalarMul(gDegenerateToLineTol, gDegenerateToLineTol); | |
| 214 | |
| 215 if (p[0].distanceToSqd(p[1]) < gDegenerateToLineTolSqd || | |
| 216 p[1].distanceToSqd(p[2]) < gDegenerateToLineTolSqd) { | |
| 217 return -1; | 218 return -1; |
| 218 } | 219 } |
| 219 | 220 |
| 220 SkScalar dsqd = p[1].distanceToLineBetweenSqd(p[0], p[2]); | |
| 221 if (dsqd < gDegenerateToLineTolSqd) { | |
| 222 return -1; | |
| 223 } | |
| 224 | |
| 225 if (p[2].distanceToLineBetweenSqd(p[1], p[0]) < gDegenerateToLineTolSqd) { | |
| 226 return -1; | |
| 227 } | |
| 228 | |
| 229 // tolerance of triangle height in pixels | 221 // tolerance of triangle height in pixels |
| 230 // tuned on windows Quadro FX 380 / Z600 | 222 // tuned on windows Quadro FX 380 / Z600 |
| 231 // trade off of fill vs cpu time on verts | 223 // trade off of fill vs cpu time on verts |
| 232 // maybe different when do this using gpu (geo or tess shaders) | 224 // maybe different when do this using gpu (geo or tess shaders) |
| 233 static const SkScalar gSubdivTol = 175 * SK_Scalar1; | 225 static const SkScalar gSubdivTol = 175 * SK_Scalar1; |
| 234 | 226 |
| 235 if (dsqd <= SkScalarMul(gSubdivTol, gSubdivTol)) { | 227 if (dsqd <= SkScalarMul(gSubdivTol, gSubdivTol)) { |
| 236 return 0; | 228 return 0; |
| 237 } else { | 229 } else { |
| 238 static const int kMaxSub = 4; | 230 static const int kMaxSub = 4; |
| (...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1051 geometry.fPath = path; | 1043 geometry.fPath = path; |
| 1052 SkDEBUGCODE(geometry.fDevBounds = devRect;) | 1044 SkDEBUGCODE(geometry.fDevBounds = devRect;) |
| 1053 geometry.fDevClipBounds = devClipBounds; | 1045 geometry.fDevClipBounds = devClipBounds; |
| 1054 | 1046 |
| 1055 SkAutoTUnref<GrBatch> batch(AAHairlineBatch::Create(geometry, fLinesIndexBuf
fer, | 1047 SkAutoTUnref<GrBatch> batch(AAHairlineBatch::Create(geometry, fLinesIndexBuf
fer, |
| 1056 fQuadsIndexBuffer)); | 1048 fQuadsIndexBuffer)); |
| 1057 target->drawBatch(pipelineBuilder, batch, &devRect); | 1049 target->drawBatch(pipelineBuilder, batch, &devRect); |
| 1058 | 1050 |
| 1059 return true; | 1051 return true; |
| 1060 } | 1052 } |
| OLD | NEW |