bsalomon@google.com | f75b84e | 2011-09-29 14:58:28 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 8 | #include "GrAAHairLinePathRenderer.h" |
| 9 | |
| 10 | #include "GrContext.h" |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 11 | #include "GrDrawState.h" |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 12 | #include "GrDrawTargetCaps.h" |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 13 | #include "GrEffect.h" |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 14 | #include "GrGpu.h" |
| 15 | #include "GrIndexBuffer.h" |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 16 | #include "GrPathUtils.h" |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 17 | #include "GrTBackendEffectFactory.h" |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 18 | #include "SkGeometry.h" |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 19 | #include "SkStroke.h" |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 20 | #include "SkTemplates.h" |
| 21 | |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 22 | #include "gl/GrGLEffect.h" |
| 23 | #include "gl/GrGLSL.h" |
bsalomon@google.com | 4647f90 | 2013-03-26 14:45:27 +0000 | [diff] [blame] | 24 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 25 | namespace { |
| 26 | // quadratics are rendered as 5-sided polys in order to bound the |
| 27 | // AA stroke around the center-curve. See comments in push_quad_index_buffer and |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 28 | // bloat_quad. Quadratics and conics share an index buffer |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 29 | static const int kVertsPerQuad = 5; |
| 30 | static const int kIdxsPerQuad = 9; |
| 31 | |
| 32 | static const int kVertsPerLineSeg = 4; |
| 33 | static const int kIdxsPerLineSeg = 6; |
| 34 | |
| 35 | static const int kNumQuadsInIdxBuffer = 256; |
| 36 | static const size_t kQuadIdxSBufize = kIdxsPerQuad * |
| 37 | sizeof(uint16_t) * |
| 38 | kNumQuadsInIdxBuffer; |
| 39 | |
| 40 | bool push_quad_index_data(GrIndexBuffer* qIdxBuffer) { |
| 41 | uint16_t* data = (uint16_t*) qIdxBuffer->lock(); |
| 42 | bool tempData = NULL == data; |
| 43 | if (tempData) { |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 44 | data = SkNEW_ARRAY(uint16_t, kNumQuadsInIdxBuffer * kIdxsPerQuad); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 45 | } |
| 46 | for (int i = 0; i < kNumQuadsInIdxBuffer; ++i) { |
| 47 | |
| 48 | // Each quadratic is rendered as a five sided polygon. This poly bounds |
| 49 | // the quadratic's bounding triangle but has been expanded so that the |
| 50 | // 1-pixel wide area around the curve is inside the poly. |
| 51 | // If a,b,c are the original control points then the poly a0,b0,c0,c1,a1 |
| 52 | // that is rendered would look like this: |
| 53 | // b0 |
| 54 | // b |
| 55 | // |
| 56 | // a0 c0 |
| 57 | // a c |
| 58 | // a1 c1 |
bsalomon@google.com | 0e5104c | 2012-04-10 16:20:41 +0000 | [diff] [blame] | 59 | // Each is drawn as three triangles specified by these 9 indices: |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 60 | int baseIdx = i * kIdxsPerQuad; |
| 61 | uint16_t baseVert = (uint16_t)(i * kVertsPerQuad); |
| 62 | data[0 + baseIdx] = baseVert + 0; // a0 |
| 63 | data[1 + baseIdx] = baseVert + 1; // a1 |
| 64 | data[2 + baseIdx] = baseVert + 2; // b0 |
| 65 | data[3 + baseIdx] = baseVert + 2; // b0 |
| 66 | data[4 + baseIdx] = baseVert + 4; // c1 |
| 67 | data[5 + baseIdx] = baseVert + 3; // c0 |
| 68 | data[6 + baseIdx] = baseVert + 1; // a1 |
| 69 | data[7 + baseIdx] = baseVert + 4; // c1 |
| 70 | data[8 + baseIdx] = baseVert + 2; // b0 |
| 71 | } |
| 72 | if (tempData) { |
| 73 | bool ret = qIdxBuffer->updateData(data, kQuadIdxSBufize); |
| 74 | delete[] data; |
| 75 | return ret; |
| 76 | } else { |
| 77 | qIdxBuffer->unlock(); |
| 78 | return true; |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | GrPathRenderer* GrAAHairLinePathRenderer::Create(GrContext* context) { |
bsalomon@google.com | a8a6a32 | 2011-09-23 14:19:58 +0000 | [diff] [blame] | 84 | const GrIndexBuffer* lIdxBuffer = context->getQuadIndexBuffer(); |
| 85 | if (NULL == lIdxBuffer) { |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 86 | return NULL; |
| 87 | } |
bsalomon@google.com | a8a6a32 | 2011-09-23 14:19:58 +0000 | [diff] [blame] | 88 | GrGpu* gpu = context->getGpu(); |
| 89 | GrIndexBuffer* qIdxBuf = gpu->createIndexBuffer(kQuadIdxSBufize, false); |
| 90 | SkAutoTUnref<GrIndexBuffer> qIdxBuffer(qIdxBuf); |
| 91 | if (NULL == qIdxBuf || |
| 92 | !push_quad_index_data(qIdxBuf)) { |
| 93 | return NULL; |
| 94 | } |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 95 | return SkNEW_ARGS(GrAAHairLinePathRenderer, |
| 96 | (context, lIdxBuffer, qIdxBuf)); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | GrAAHairLinePathRenderer::GrAAHairLinePathRenderer( |
| 100 | const GrContext* context, |
| 101 | const GrIndexBuffer* linesIndexBuffer, |
| 102 | const GrIndexBuffer* quadsIndexBuffer) { |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 103 | fLinesIndexBuffer = linesIndexBuffer; |
| 104 | linesIndexBuffer->ref(); |
| 105 | fQuadsIndexBuffer = quadsIndexBuffer; |
| 106 | quadsIndexBuffer->ref(); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | GrAAHairLinePathRenderer::~GrAAHairLinePathRenderer() { |
| 110 | fLinesIndexBuffer->unref(); |
| 111 | fQuadsIndexBuffer->unref(); |
| 112 | } |
| 113 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 114 | namespace { |
| 115 | |
bsalomon@google.com | 49313f6 | 2011-09-14 13:54:05 +0000 | [diff] [blame] | 116 | typedef SkTArray<SkPoint, true> PtArray; |
bsalomon@google.com | 9266901 | 2011-09-27 19:10:05 +0000 | [diff] [blame] | 117 | #define PREALLOC_PTARRAY(N) SkSTArray<(N),SkPoint, true> |
bsalomon@google.com | 49313f6 | 2011-09-14 13:54:05 +0000 | [diff] [blame] | 118 | typedef SkTArray<int, true> IntArray; |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 119 | typedef SkTArray<float, true> FloatArray; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 120 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 121 | // Takes 178th time of logf on Z600 / VC2010 |
| 122 | int get_float_exp(float x) { |
| 123 | GR_STATIC_ASSERT(sizeof(int) == sizeof(float)); |
| 124 | #if GR_DEBUG |
| 125 | static bool tested; |
| 126 | if (!tested) { |
| 127 | tested = true; |
| 128 | GrAssert(get_float_exp(0.25f) == -2); |
| 129 | GrAssert(get_float_exp(0.3f) == -2); |
| 130 | GrAssert(get_float_exp(0.5f) == -1); |
| 131 | GrAssert(get_float_exp(1.f) == 0); |
| 132 | GrAssert(get_float_exp(2.f) == 1); |
| 133 | GrAssert(get_float_exp(2.5f) == 1); |
| 134 | GrAssert(get_float_exp(8.f) == 3); |
| 135 | GrAssert(get_float_exp(100.f) == 6); |
| 136 | GrAssert(get_float_exp(1000.f) == 9); |
| 137 | GrAssert(get_float_exp(1024.f) == 10); |
| 138 | GrAssert(get_float_exp(3000000.f) == 21); |
| 139 | } |
| 140 | #endif |
bsalomon@google.com | 2ec7280 | 2011-09-21 21:46:03 +0000 | [diff] [blame] | 141 | const int* iptr = (const int*)&x; |
| 142 | return (((*iptr) & 0x7f800000) >> 23) - 127; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 143 | } |
| 144 | |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 145 | // Uses the max curvature function for quads to estimate |
| 146 | // where to chop the conic. If the max curvature is not |
| 147 | // found along the curve segment it will return 1 and |
egdaniel@google.com | 3f2a2d5 | 2013-08-01 17:09:11 +0000 | [diff] [blame^] | 148 | // dst[0] is the original conic. If it returns 2 the dst[0] |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 149 | // and dst[1] are the two new conics. |
egdaniel@google.com | 3f2a2d5 | 2013-08-01 17:09:11 +0000 | [diff] [blame^] | 150 | int split_conic(const SkPoint src[3], SkConic dst[2], const SkScalar weight) { |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 151 | SkScalar t = SkFindQuadMaxCurvature(src); |
| 152 | if (t == 0) { |
| 153 | if (dst) { |
| 154 | dst[0].set(src, weight); |
| 155 | } |
| 156 | return 1; |
| 157 | } else { |
| 158 | if (dst) { |
| 159 | SkConic conic; |
| 160 | conic.set(src, weight); |
| 161 | conic.chopAt(t, dst); |
| 162 | } |
| 163 | return 2; |
| 164 | } |
| 165 | } |
| 166 | |
egdaniel@google.com | 3f2a2d5 | 2013-08-01 17:09:11 +0000 | [diff] [blame^] | 167 | // Calls split_conic on the entire conic and then once more on each subsection. |
| 168 | // Most cases will result in either 1 conic (chop point is not within t range) |
| 169 | // or 3 points (split once and then one subsection is split again). |
| 170 | int chop_conic(const SkPoint src[3], SkConic dst[4], const SkScalar weight) { |
| 171 | SkConic dstTemp[2]; |
| 172 | int conicCnt = split_conic(src, dstTemp, weight); |
| 173 | if (2 == conicCnt) { |
| 174 | int conicCnt2 = split_conic(dstTemp[0].fPts, dst, dstTemp[0].fW); |
| 175 | conicCnt = conicCnt2 + split_conic(dstTemp[1].fPts, &dst[conicCnt2], dstTemp[1].fW); |
| 176 | } else { |
| 177 | dst[0] = dstTemp[0]; |
| 178 | } |
| 179 | return conicCnt; |
| 180 | } |
| 181 | |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 182 | // returns 0 if quad/conic is degen or close to it |
| 183 | // in this case approx the path with lines |
| 184 | // otherwise returns 1 |
| 185 | int is_degen_quad_or_conic(const SkPoint p[3]) { |
| 186 | static const SkScalar gDegenerateToLineTol = SK_Scalar1; |
| 187 | static const SkScalar gDegenerateToLineTolSqd = |
| 188 | SkScalarMul(gDegenerateToLineTol, gDegenerateToLineTol); |
| 189 | |
| 190 | if (p[0].distanceToSqd(p[1]) < gDegenerateToLineTolSqd || |
| 191 | p[1].distanceToSqd(p[2]) < gDegenerateToLineTolSqd) { |
| 192 | return 1; |
| 193 | } |
| 194 | |
| 195 | SkScalar dsqd = p[1].distanceToLineBetweenSqd(p[0], p[2]); |
| 196 | if (dsqd < gDegenerateToLineTolSqd) { |
| 197 | return 1; |
| 198 | } |
| 199 | |
| 200 | if (p[2].distanceToLineBetweenSqd(p[1], p[0]) < gDegenerateToLineTolSqd) { |
| 201 | return 1; |
| 202 | } |
| 203 | return 0; |
| 204 | } |
| 205 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 206 | // we subdivide the quads to avoid huge overfill |
| 207 | // if it returns -1 then should be drawn as lines |
| 208 | int num_quad_subdivs(const SkPoint p[3]) { |
| 209 | static const SkScalar gDegenerateToLineTol = SK_Scalar1; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 210 | static const SkScalar gDegenerateToLineTolSqd = |
bsalomon@google.com | 46a2a1e | 2011-09-06 22:10:52 +0000 | [diff] [blame] | 211 | SkScalarMul(gDegenerateToLineTol, gDegenerateToLineTol); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 212 | |
bsalomon@google.com | 46a2a1e | 2011-09-06 22:10:52 +0000 | [diff] [blame] | 213 | if (p[0].distanceToSqd(p[1]) < gDegenerateToLineTolSqd || |
| 214 | p[1].distanceToSqd(p[2]) < gDegenerateToLineTolSqd) { |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 215 | return -1; |
| 216 | } |
bsalomon@google.com | 46a2a1e | 2011-09-06 22:10:52 +0000 | [diff] [blame] | 217 | |
bsalomon@google.com | 8171288 | 2012-11-01 17:12:34 +0000 | [diff] [blame] | 218 | SkScalar dsqd = p[1].distanceToLineBetweenSqd(p[0], p[2]); |
bsalomon@google.com | 46a2a1e | 2011-09-06 22:10:52 +0000 | [diff] [blame] | 219 | if (dsqd < gDegenerateToLineTolSqd) { |
| 220 | return -1; |
| 221 | } |
| 222 | |
| 223 | if (p[2].distanceToLineBetweenSqd(p[1], p[0]) < gDegenerateToLineTolSqd) { |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 224 | return -1; |
| 225 | } |
| 226 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 227 | // tolerance of triangle height in pixels |
| 228 | // tuned on windows Quadro FX 380 / Z600 |
| 229 | // trade off of fill vs cpu time on verts |
| 230 | // maybe different when do this using gpu (geo or tess shaders) |
| 231 | static const SkScalar gSubdivTol = 175 * SK_Scalar1; |
| 232 | |
robertphillips@google.com | 7460b37 | 2012-04-25 16:54:51 +0000 | [diff] [blame] | 233 | if (dsqd <= SkScalarMul(gSubdivTol, gSubdivTol)) { |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 234 | return 0; |
| 235 | } else { |
robertphillips@google.com | 87379e1 | 2013-03-29 12:11:10 +0000 | [diff] [blame] | 236 | static const int kMaxSub = 4; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 237 | // subdividing the quad reduces d by 4. so we want x = log4(d/tol) |
| 238 | // = log4(d*d/tol*tol)/2 |
| 239 | // = log2(d*d/tol*tol) |
| 240 | |
| 241 | #ifdef SK_SCALAR_IS_FLOAT |
| 242 | // +1 since we're ignoring the mantissa contribution. |
| 243 | int log = get_float_exp(dsqd/(gSubdivTol*gSubdivTol)) + 1; |
| 244 | log = GrMin(GrMax(0, log), kMaxSub); |
| 245 | return log; |
| 246 | #else |
robertphillips@google.com | 7460b37 | 2012-04-25 16:54:51 +0000 | [diff] [blame] | 247 | SkScalar log = SkScalarLog( |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 248 | SkScalarDiv(dsqd, |
robertphillips@google.com | 7460b37 | 2012-04-25 16:54:51 +0000 | [diff] [blame] | 249 | SkScalarMul(gSubdivTol, gSubdivTol))); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 250 | static const SkScalar conv = SkScalarInvert(SkScalarLog(2)); |
| 251 | log = SkScalarMul(log, conv); |
| 252 | return GrMin(GrMax(0, SkScalarCeilToInt(log)),kMaxSub); |
| 253 | #endif |
| 254 | } |
| 255 | } |
| 256 | |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 257 | /** |
| 258 | * Generates the lines and quads to be rendered. Lines are always recorded in |
| 259 | * device space. We will do a device space bloat to account for the 1pixel |
| 260 | * thickness. |
| 261 | * Quads are recorded in device space unless m contains |
| 262 | * perspective, then in they are in src space. We do this because we will |
| 263 | * subdivide large quads to reduce over-fill. This subdivision has to be |
| 264 | * performed before applying the perspective matrix. |
| 265 | */ |
| 266 | int generate_lines_and_quads(const SkPath& path, |
| 267 | const SkMatrix& m, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 268 | const SkIRect& devClipBounds, |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 269 | PtArray* lines, |
| 270 | PtArray* quads, |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 271 | PtArray* conics, |
| 272 | IntArray* quadSubdivCnts, |
| 273 | FloatArray* conicWeights) { |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 274 | SkPath::Iter iter(path, false); |
| 275 | |
| 276 | int totalQuadCount = 0; |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 277 | SkRect bounds; |
| 278 | SkIRect ibounds; |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 279 | |
| 280 | bool persp = m.hasPerspective(); |
| 281 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 282 | for (;;) { |
commit-bot@chromium.org | 912e68e | 2013-05-24 18:51:55 +0000 | [diff] [blame] | 283 | GrPoint pathPts[4]; |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 284 | GrPoint devPts[4]; |
commit-bot@chromium.org | 912e68e | 2013-05-24 18:51:55 +0000 | [diff] [blame] | 285 | SkPath::Verb verb = iter.next(pathPts); |
bsalomon@google.com | 94b284d | 2013-05-10 17:14:06 +0000 | [diff] [blame] | 286 | switch (verb) { |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 287 | case SkPath::kConic_Verb: { |
egdaniel@google.com | 3f2a2d5 | 2013-08-01 17:09:11 +0000 | [diff] [blame^] | 288 | SkConic dst[4]; |
| 289 | // We chop the conics to create tighter clipping to hide error |
| 290 | // that appears near max curvature of very thin conics. Thin |
| 291 | // hyperbolas with high weight still show error. |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 292 | int conicCnt = chop_conic(pathPts, dst, iter.conicWeight()); |
| 293 | for (int i = 0; i < conicCnt; ++i) { |
| 294 | SkPoint* chopPnts = dst[i].fPts; |
| 295 | m.mapPoints(devPts, chopPnts, 3); |
| 296 | bounds.setBounds(devPts, 3); |
| 297 | bounds.outset(SK_Scalar1, SK_Scalar1); |
| 298 | bounds.roundOut(&ibounds); |
| 299 | if (SkIRect::Intersects(devClipBounds, ibounds)) { |
| 300 | if (is_degen_quad_or_conic(devPts)) { |
| 301 | SkPoint* pts = lines->push_back_n(4); |
| 302 | pts[0] = devPts[0]; |
| 303 | pts[1] = devPts[1]; |
| 304 | pts[2] = devPts[1]; |
| 305 | pts[3] = devPts[2]; |
| 306 | } else { |
| 307 | // when in perspective keep conics in src space |
| 308 | SkPoint* cPts = persp ? chopPnts : devPts; |
| 309 | SkPoint* pts = conics->push_back_n(3); |
| 310 | pts[0] = cPts[0]; |
| 311 | pts[1] = cPts[1]; |
| 312 | pts[2] = cPts[2]; |
| 313 | conicWeights->push_back() = dst[i].fW; |
| 314 | } |
| 315 | } |
| 316 | } |
reed@google.com | 277c3f8 | 2013-05-31 15:17:50 +0000 | [diff] [blame] | 317 | break; |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 318 | } |
| 319 | case SkPath::kMove_Verb: |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 320 | break; |
bsalomon@google.com | 94b284d | 2013-05-10 17:14:06 +0000 | [diff] [blame] | 321 | case SkPath::kLine_Verb: |
commit-bot@chromium.org | 912e68e | 2013-05-24 18:51:55 +0000 | [diff] [blame] | 322 | m.mapPoints(devPts, pathPts, 2); |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 323 | bounds.setBounds(devPts, 2); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 324 | bounds.outset(SK_Scalar1, SK_Scalar1); |
| 325 | bounds.roundOut(&ibounds); |
robertphillips@google.com | 7b11289 | 2012-07-31 15:18:21 +0000 | [diff] [blame] | 326 | if (SkIRect::Intersects(devClipBounds, ibounds)) { |
bsalomon@google.com | a996fec | 2011-09-13 18:49:13 +0000 | [diff] [blame] | 327 | SkPoint* pts = lines->push_back_n(2); |
| 328 | pts[0] = devPts[0]; |
| 329 | pts[1] = devPts[1]; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 330 | } |
| 331 | break; |
commit-bot@chromium.org | 912e68e | 2013-05-24 18:51:55 +0000 | [diff] [blame] | 332 | case SkPath::kQuad_Verb: { |
| 333 | SkPoint choppedPts[5]; |
| 334 | // Chopping the quad helps when the quad is either degenerate or nearly degenerate. |
| 335 | // When it is degenerate it allows the approximation with lines to work since the |
| 336 | // chop point (if there is one) will be at the parabola's vertex. In the nearly |
| 337 | // degenerate the QuadUVMatrix computed for the points is almost singular which |
| 338 | // can cause rendering artifacts. |
| 339 | int n = SkChopQuadAtMaxCurvature(pathPts, choppedPts); |
| 340 | for (int i = 0; i < n; ++i) { |
| 341 | SkPoint* quadPts = choppedPts + i * 2; |
| 342 | m.mapPoints(devPts, quadPts, 3); |
| 343 | bounds.setBounds(devPts, 3); |
| 344 | bounds.outset(SK_Scalar1, SK_Scalar1); |
| 345 | bounds.roundOut(&ibounds); |
| 346 | |
| 347 | if (SkIRect::Intersects(devClipBounds, ibounds)) { |
| 348 | int subdiv = num_quad_subdivs(devPts); |
| 349 | GrAssert(subdiv >= -1); |
| 350 | if (-1 == subdiv) { |
| 351 | SkPoint* pts = lines->push_back_n(4); |
| 352 | pts[0] = devPts[0]; |
| 353 | pts[1] = devPts[1]; |
| 354 | pts[2] = devPts[1]; |
| 355 | pts[3] = devPts[2]; |
| 356 | } else { |
| 357 | // when in perspective keep quads in src space |
| 358 | SkPoint* qPts = persp ? quadPts : devPts; |
| 359 | SkPoint* pts = quads->push_back_n(3); |
| 360 | pts[0] = qPts[0]; |
| 361 | pts[1] = qPts[1]; |
| 362 | pts[2] = qPts[2]; |
| 363 | quadSubdivCnts->push_back() = subdiv; |
| 364 | totalQuadCount += 1 << subdiv; |
| 365 | } |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 366 | } |
| 367 | } |
bsalomon@google.com | a51ab84 | 2012-07-10 19:53:34 +0000 | [diff] [blame] | 368 | break; |
commit-bot@chromium.org | 912e68e | 2013-05-24 18:51:55 +0000 | [diff] [blame] | 369 | } |
bsalomon@google.com | 94b284d | 2013-05-10 17:14:06 +0000 | [diff] [blame] | 370 | case SkPath::kCubic_Verb: |
commit-bot@chromium.org | 912e68e | 2013-05-24 18:51:55 +0000 | [diff] [blame] | 371 | m.mapPoints(devPts, pathPts, 4); |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 372 | bounds.setBounds(devPts, 4); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 373 | bounds.outset(SK_Scalar1, SK_Scalar1); |
| 374 | bounds.roundOut(&ibounds); |
robertphillips@google.com | 7b11289 | 2012-07-31 15:18:21 +0000 | [diff] [blame] | 375 | if (SkIRect::Intersects(devClipBounds, ibounds)) { |
bsalomon@google.com | 9266901 | 2011-09-27 19:10:05 +0000 | [diff] [blame] | 376 | PREALLOC_PTARRAY(32) q; |
bsalomon@google.com | a51ab84 | 2012-07-10 19:53:34 +0000 | [diff] [blame] | 377 | // we don't need a direction if we aren't constraining the subdivision |
| 378 | static const SkPath::Direction kDummyDir = SkPath::kCCW_Direction; |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 379 | // We convert cubics to quadratics (for now). |
| 380 | // In perspective have to do conversion in src space. |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 381 | if (persp) { |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 382 | SkScalar tolScale = |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 383 | GrPathUtils::scaleToleranceToSrc(SK_Scalar1, m, |
| 384 | path.getBounds()); |
commit-bot@chromium.org | 912e68e | 2013-05-24 18:51:55 +0000 | [diff] [blame] | 385 | GrPathUtils::convertCubicToQuads(pathPts, tolScale, false, kDummyDir, &q); |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 386 | } else { |
bsalomon@google.com | a51ab84 | 2012-07-10 19:53:34 +0000 | [diff] [blame] | 387 | GrPathUtils::convertCubicToQuads(devPts, SK_Scalar1, false, kDummyDir, &q); |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 388 | } |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 389 | for (int i = 0; i < q.count(); i += 3) { |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 390 | SkPoint* qInDevSpace; |
| 391 | // bounds has to be calculated in device space, but q is |
| 392 | // in src space when there is perspective. |
| 393 | if (persp) { |
| 394 | m.mapPoints(devPts, &q[i], 3); |
| 395 | bounds.setBounds(devPts, 3); |
| 396 | qInDevSpace = devPts; |
| 397 | } else { |
| 398 | bounds.setBounds(&q[i], 3); |
| 399 | qInDevSpace = &q[i]; |
| 400 | } |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 401 | bounds.outset(SK_Scalar1, SK_Scalar1); |
| 402 | bounds.roundOut(&ibounds); |
robertphillips@google.com | 7b11289 | 2012-07-31 15:18:21 +0000 | [diff] [blame] | 403 | if (SkIRect::Intersects(devClipBounds, ibounds)) { |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 404 | int subdiv = num_quad_subdivs(qInDevSpace); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 405 | GrAssert(subdiv >= -1); |
| 406 | if (-1 == subdiv) { |
bsalomon@google.com | a996fec | 2011-09-13 18:49:13 +0000 | [diff] [blame] | 407 | SkPoint* pts = lines->push_back_n(4); |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 408 | // lines should always be in device coords |
bsalomon@google.com | a996fec | 2011-09-13 18:49:13 +0000 | [diff] [blame] | 409 | pts[0] = qInDevSpace[0]; |
| 410 | pts[1] = qInDevSpace[1]; |
| 411 | pts[2] = qInDevSpace[1]; |
| 412 | pts[3] = qInDevSpace[2]; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 413 | } else { |
bsalomon@google.com | a996fec | 2011-09-13 18:49:13 +0000 | [diff] [blame] | 414 | SkPoint* pts = quads->push_back_n(3); |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 415 | // q is already in src space when there is no |
| 416 | // perspective and dev coords otherwise. |
bsalomon@google.com | a996fec | 2011-09-13 18:49:13 +0000 | [diff] [blame] | 417 | pts[0] = q[0 + i]; |
| 418 | pts[1] = q[1 + i]; |
| 419 | pts[2] = q[2 + i]; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 420 | quadSubdivCnts->push_back() = subdiv; |
| 421 | totalQuadCount += 1 << subdiv; |
| 422 | } |
| 423 | } |
| 424 | } |
| 425 | } |
bsalomon@google.com | a51ab84 | 2012-07-10 19:53:34 +0000 | [diff] [blame] | 426 | break; |
bsalomon@google.com | 94b284d | 2013-05-10 17:14:06 +0000 | [diff] [blame] | 427 | case SkPath::kClose_Verb: |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 428 | break; |
bsalomon@google.com | 94b284d | 2013-05-10 17:14:06 +0000 | [diff] [blame] | 429 | case SkPath::kDone_Verb: |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 430 | return totalQuadCount; |
| 431 | } |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | struct Vertex { |
| 436 | GrPoint fPos; |
| 437 | union { |
| 438 | struct { |
bsalomon@google.com | 8171288 | 2012-11-01 17:12:34 +0000 | [diff] [blame] | 439 | SkScalar fA; |
| 440 | SkScalar fB; |
| 441 | SkScalar fC; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 442 | } fLine; |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 443 | struct { |
egdaniel@google.com | 3f2a2d5 | 2013-08-01 17:09:11 +0000 | [diff] [blame^] | 444 | SkScalar fK; |
| 445 | SkScalar fL; |
| 446 | SkScalar fM; |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 447 | } fConic; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 448 | GrVec fQuadCoord; |
| 449 | struct { |
egdaniel@google.com | 3f2a2d5 | 2013-08-01 17:09:11 +0000 | [diff] [blame^] | 450 | SkScalar fBogus[4]; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 451 | }; |
| 452 | }; |
| 453 | }; |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 454 | |
egdaniel@google.com | 3f2a2d5 | 2013-08-01 17:09:11 +0000 | [diff] [blame^] | 455 | GR_STATIC_ASSERT(sizeof(Vertex) == 3 * sizeof(GrPoint)); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 456 | |
| 457 | void intersect_lines(const SkPoint& ptA, const SkVector& normA, |
| 458 | const SkPoint& ptB, const SkVector& normB, |
| 459 | SkPoint* result) { |
| 460 | |
| 461 | SkScalar lineAW = -normA.dot(ptA); |
| 462 | SkScalar lineBW = -normB.dot(ptB); |
| 463 | |
| 464 | SkScalar wInv = SkScalarMul(normA.fX, normB.fY) - |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 465 | SkScalarMul(normA.fY, normB.fX); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 466 | wInv = SkScalarInvert(wInv); |
| 467 | |
| 468 | result->fX = SkScalarMul(normA.fY, lineBW) - SkScalarMul(lineAW, normB.fY); |
| 469 | result->fX = SkScalarMul(result->fX, wInv); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 470 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 471 | result->fY = SkScalarMul(lineAW, normB.fX) - SkScalarMul(normA.fX, lineBW); |
| 472 | result->fY = SkScalarMul(result->fY, wInv); |
| 473 | } |
| 474 | |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 475 | void bloat_quad(const SkPoint qpts[3], const SkMatrix* toDevice, |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 476 | const SkMatrix* toSrc, Vertex verts[kVertsPerQuad], |
| 477 | SkRect* devBounds) { |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 478 | GrAssert(!toDevice == !toSrc); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 479 | // original quad is specified by tri a,b,c |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 480 | SkPoint a = qpts[0]; |
| 481 | SkPoint b = qpts[1]; |
| 482 | SkPoint c = qpts[2]; |
| 483 | |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 484 | // this should be in the src space, not dev coords, when we have perspective |
bsalomon@google.com | 1971317 | 2012-03-15 13:51:08 +0000 | [diff] [blame] | 485 | GrPathUtils::QuadUVMatrix DevToUV(qpts); |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 486 | |
| 487 | if (toDevice) { |
| 488 | toDevice->mapPoints(&a, 1); |
| 489 | toDevice->mapPoints(&b, 1); |
| 490 | toDevice->mapPoints(&c, 1); |
| 491 | } |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 492 | // make a new poly where we replace a and c by a 1-pixel wide edges orthog |
| 493 | // to edges ab and bc: |
| 494 | // |
| 495 | // before | after |
| 496 | // | b0 |
| 497 | // b | |
| 498 | // | |
| 499 | // | a0 c0 |
| 500 | // a c | a1 c1 |
| 501 | // |
| 502 | // edges a0->b0 and b0->c0 are parallel to original edges a->b and b->c, |
| 503 | // respectively. |
| 504 | Vertex& a0 = verts[0]; |
| 505 | Vertex& a1 = verts[1]; |
| 506 | Vertex& b0 = verts[2]; |
| 507 | Vertex& c0 = verts[3]; |
| 508 | Vertex& c1 = verts[4]; |
| 509 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 510 | SkVector ab = b; |
| 511 | ab -= a; |
| 512 | SkVector ac = c; |
| 513 | ac -= a; |
| 514 | SkVector cb = b; |
| 515 | cb -= c; |
| 516 | |
| 517 | // We should have already handled degenerates |
| 518 | GrAssert(ab.length() > 0 && cb.length() > 0); |
| 519 | |
| 520 | ab.normalize(); |
| 521 | SkVector abN; |
| 522 | abN.setOrthog(ab, SkVector::kLeft_Side); |
| 523 | if (abN.dot(ac) > 0) { |
| 524 | abN.negate(); |
| 525 | } |
| 526 | |
| 527 | cb.normalize(); |
| 528 | SkVector cbN; |
| 529 | cbN.setOrthog(cb, SkVector::kLeft_Side); |
| 530 | if (cbN.dot(ac) < 0) { |
| 531 | cbN.negate(); |
| 532 | } |
| 533 | |
| 534 | a0.fPos = a; |
| 535 | a0.fPos += abN; |
| 536 | a1.fPos = a; |
| 537 | a1.fPos -= abN; |
| 538 | |
| 539 | c0.fPos = c; |
| 540 | c0.fPos += cbN; |
| 541 | c1.fPos = c; |
| 542 | c1.fPos -= cbN; |
| 543 | |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 544 | // This point may not be within 1 pixel of a control point. We update the bounding box to |
| 545 | // include it. |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 546 | intersect_lines(a0.fPos, abN, c0.fPos, cbN, &b0.fPos); |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 547 | devBounds->growToInclude(b0.fPos.fX, b0.fPos.fY); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 548 | |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 549 | if (toSrc) { |
| 550 | toSrc->mapPointsWithStride(&verts[0].fPos, sizeof(Vertex), kVertsPerQuad); |
| 551 | } |
bsalomon@google.com | 1971317 | 2012-03-15 13:51:08 +0000 | [diff] [blame] | 552 | DevToUV.apply<kVertsPerQuad, sizeof(Vertex), sizeof(GrPoint)>(verts); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 553 | } |
| 554 | |
egdaniel@google.com | 3f2a2d5 | 2013-08-01 17:09:11 +0000 | [diff] [blame^] | 555 | // Input: |
| 556 | // Three control points: p[0], p[1], p[2] and weight: w |
| 557 | // Output: |
| 558 | // Let: |
| 559 | // l = (2*w * (y1 - y0), 2*w * (x0 - x1), 2*w * (x1*y0 - x0*y1)) |
| 560 | // m = (2*w * (y2 - y1), 2*w * (x1 - x2), 2*w * (x2*y1 - x1*y2)) |
| 561 | // k = (y2 - y0, x0 - x2, (x2 - x0)*y0 - (y2 - y0)*x0 ) |
| 562 | void calc_conic_klm(const SkPoint p[3], const SkScalar weight, |
| 563 | SkScalar k[3], SkScalar l[3], SkScalar m[3]) { |
| 564 | const SkScalar w2 = 2 * weight; |
| 565 | l[0] = w2 * (p[1].fY - p[0].fY); |
| 566 | l[1] = w2 * (p[0].fX - p[1].fX); |
| 567 | l[2] = w2 * (p[1].fX * p[0].fY - p[0].fX * p[1].fY); |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 568 | |
egdaniel@google.com | 3f2a2d5 | 2013-08-01 17:09:11 +0000 | [diff] [blame^] | 569 | m[0] = w2 * (p[2].fY - p[1].fY); |
| 570 | m[1] = w2 * (p[1].fX - p[2].fX); |
| 571 | m[2] = w2 * (p[2].fX * p[1].fY - p[1].fX * p[2].fY); |
| 572 | |
| 573 | k[0] = p[2].fY - p[0].fY; |
| 574 | k[1] = p[0].fX - p[2].fX; |
| 575 | k[2] = (p[2].fX - p[0].fX) * p[0].fY - (p[2].fY - p[0].fY) * p[0].fX; |
| 576 | |
| 577 | // scale the max absolute value of coeffs to 10 |
| 578 | SkScalar scale = 0.0f; |
| 579 | for (int i = 0; i < 3; ++i) { |
| 580 | scale = SkMaxScalar(scale, SkScalarAbs(k[i])); |
| 581 | scale = SkMaxScalar(scale, SkScalarAbs(l[i])); |
| 582 | scale = SkMaxScalar(scale, SkScalarAbs(m[i])); |
| 583 | } |
| 584 | GrAssert(scale > 0); |
| 585 | scale /= 10.0f; |
| 586 | k[0] /= scale; |
| 587 | k[1] /= scale; |
| 588 | k[2] /= scale; |
| 589 | l[0] /= scale; |
| 590 | l[1] /= scale; |
| 591 | l[2] /= scale; |
| 592 | m[0] /= scale; |
| 593 | m[1] /= scale; |
| 594 | m[2] /= scale; |
| 595 | } |
| 596 | |
| 597 | // Equations based off of Loop-Blinn Quadratic GPU Rendering |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 598 | // Input Parametric: |
| 599 | // P(t) = (P0*(1-t)^2 + 2*w*P1*t*(1-t) + P2*t^2) / (1-t)^2 + 2*w*t*(1-t) + t^2) |
| 600 | // Output Implicit: |
egdaniel@google.com | 3f2a2d5 | 2013-08-01 17:09:11 +0000 | [diff] [blame^] | 601 | // f(x, y, w) = f(P) = K^2 - LM |
| 602 | // K = dot(k, P), L = dot(l, P), M = dot(m, P) |
| 603 | // k, l, m are calculated in function calc_conic_klm |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 604 | void set_conic_coeffs(const SkPoint p[3], Vertex verts[kVertsPerQuad], const float weight) { |
egdaniel@google.com | 3f2a2d5 | 2013-08-01 17:09:11 +0000 | [diff] [blame^] | 605 | SkScalar k[3]; |
| 606 | SkScalar l[3]; |
| 607 | SkScalar m[3]; |
| 608 | |
| 609 | calc_conic_klm(p, weight, k, l, m); |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 610 | |
| 611 | for (int i = 0; i < kVertsPerQuad; ++i) { |
egdaniel@google.com | 3f2a2d5 | 2013-08-01 17:09:11 +0000 | [diff] [blame^] | 612 | const SkPoint pnt = verts[i].fPos; |
| 613 | verts[i].fConic.fK = pnt.fX * k[0] + pnt.fY * k[1] + k[2]; |
| 614 | verts[i].fConic.fL = pnt.fX * l[0] + pnt.fY * l[1] + l[2]; |
| 615 | verts[i].fConic.fM = pnt.fX * m[0] + pnt.fY * m[1] + m[2]; |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 616 | } |
| 617 | } |
| 618 | |
| 619 | void add_conics(const SkPoint p[3], |
| 620 | float weight, |
| 621 | const SkMatrix* toDevice, |
| 622 | const SkMatrix* toSrc, |
| 623 | Vertex** vert, |
| 624 | SkRect* devBounds) { |
| 625 | bloat_quad(p, toDevice, toSrc, *vert, devBounds); |
| 626 | set_conic_coeffs(p, *vert, weight); |
| 627 | *vert += kVertsPerQuad; |
| 628 | } |
| 629 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 630 | void add_quads(const SkPoint p[3], |
| 631 | int subdiv, |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 632 | const SkMatrix* toDevice, |
| 633 | const SkMatrix* toSrc, |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 634 | Vertex** vert, |
| 635 | SkRect* devBounds) { |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 636 | GrAssert(subdiv >= 0); |
| 637 | if (subdiv) { |
| 638 | SkPoint newP[5]; |
| 639 | SkChopQuadAtHalf(p, newP); |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 640 | add_quads(newP + 0, subdiv-1, toDevice, toSrc, vert, devBounds); |
| 641 | add_quads(newP + 2, subdiv-1, toDevice, toSrc, vert, devBounds); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 642 | } else { |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 643 | bloat_quad(p, toDevice, toSrc, *vert, devBounds); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 644 | *vert += kVertsPerQuad; |
| 645 | } |
| 646 | } |
| 647 | |
| 648 | void add_line(const SkPoint p[2], |
| 649 | int rtHeight, |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 650 | const SkMatrix* toSrc, |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 651 | Vertex** vert) { |
| 652 | const SkPoint& a = p[0]; |
| 653 | const SkPoint& b = p[1]; |
| 654 | |
| 655 | SkVector orthVec = b; |
| 656 | orthVec -= a; |
| 657 | |
| 658 | if (orthVec.setLength(SK_Scalar1)) { |
| 659 | orthVec.setOrthog(orthVec); |
| 660 | |
bsalomon@google.com | 706f668 | 2012-10-23 14:53:55 +0000 | [diff] [blame] | 661 | SkScalar lineC = -(a.dot(orthVec)); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 662 | for (int i = 0; i < kVertsPerLineSeg; ++i) { |
| 663 | (*vert)[i].fPos = (i < 2) ? a : b; |
| 664 | if (0 == i || 3 == i) { |
| 665 | (*vert)[i].fPos -= orthVec; |
| 666 | } else { |
| 667 | (*vert)[i].fPos += orthVec; |
| 668 | } |
bsalomon@google.com | 706f668 | 2012-10-23 14:53:55 +0000 | [diff] [blame] | 669 | (*vert)[i].fLine.fA = orthVec.fX; |
| 670 | (*vert)[i].fLine.fB = orthVec.fY; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 671 | (*vert)[i].fLine.fC = lineC; |
| 672 | } |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 673 | if (NULL != toSrc) { |
| 674 | toSrc->mapPointsWithStride(&(*vert)->fPos, |
| 675 | sizeof(Vertex), |
| 676 | kVertsPerLineSeg); |
| 677 | } |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 678 | } else { |
| 679 | // just make it degenerate and likely offscreen |
| 680 | (*vert)[0].fPos.set(SK_ScalarMax, SK_ScalarMax); |
| 681 | (*vert)[1].fPos.set(SK_ScalarMax, SK_ScalarMax); |
| 682 | (*vert)[2].fPos.set(SK_ScalarMax, SK_ScalarMax); |
| 683 | (*vert)[3].fPos.set(SK_ScalarMax, SK_ScalarMax); |
| 684 | } |
| 685 | |
| 686 | *vert += kVertsPerLineSeg; |
| 687 | } |
| 688 | |
| 689 | } |
| 690 | |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 691 | /** |
egdaniel@google.com | 3f2a2d5 | 2013-08-01 17:09:11 +0000 | [diff] [blame^] | 692 | * Shader is based off of Loop-Blinn Quadratic GPU Rendering |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 693 | * The output of this effect is a hairline edge for conics. |
egdaniel@google.com | 3f2a2d5 | 2013-08-01 17:09:11 +0000 | [diff] [blame^] | 694 | * Conics specified by implicit equation K^2 - LM. |
| 695 | * K, L, and M, are the first three values of the vertex attribute, |
| 696 | * the fourth value is not used. Distance is calculated using a |
| 697 | * first order approximation from the taylor series. |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 698 | * Coverage is max(0, 1-distance). |
| 699 | */ |
egdaniel@google.com | 3f2a2d5 | 2013-08-01 17:09:11 +0000 | [diff] [blame^] | 700 | |
| 701 | /** |
| 702 | * Test were also run using a second order distance approximation. |
| 703 | * There were two versions of the second order approx. The first version |
| 704 | * is of roughly the form: |
| 705 | * f(q) = |f(p)| - ||f'(p)||*||q-p|| - ||f''(p)||*||q-p||^2. |
| 706 | * The second is similar: |
| 707 | * f(q) = |f(p)| + ||f'(p)||*||q-p|| + ||f''(p)||*||q-p||^2. |
| 708 | * The exact version of the equations can be found in the paper |
| 709 | * "Distance Approximations for Rasterizing Implicit Curves" by Gabriel Taubin |
| 710 | * |
| 711 | * In both versions we solve the quadratic for ||q-p||. |
| 712 | * Version 1: |
| 713 | * gFM is magnitude of first partials and gFM2 is magnitude of 2nd partials (as derived from paper) |
| 714 | * builder->fsCodeAppend("\t\tedgeAlpha = (sqrt(gFM*gFM+4.0*func*gF2M) - gFM)/(2.0*gF2M);\n"); |
| 715 | * Version 2: |
| 716 | * builder->fsCodeAppend("\t\tedgeAlpha = (gFM - sqrt(gFM*gFM-4.0*func*gF2M))/(2.0*gF2M);\n"); |
| 717 | * |
| 718 | * Also note that 2nd partials of k,l,m are zero |
| 719 | * |
| 720 | * When comparing the two second order approximations to the first order approximations, |
| 721 | * the following results were found. Version 1 tends to underestimate the distances, thus it |
| 722 | * basically increases all the error that we were already seeing in the first order |
| 723 | * approx. So this version is not the one to use. Version 2 has the opposite effect |
| 724 | * and tends to overestimate the distances. This is much closer to what we are |
| 725 | * looking for. It is able to render ellipses (even thin ones) without the need to chop. |
| 726 | * However, it can not handle thin hyperbolas well and thus would still rely on |
| 727 | * chopping to tighten the clipping. Another side effect of the overestimating is |
| 728 | * that the curves become much thinner and "ropey". If all that was ever rendered |
| 729 | * were "not too thin" curves and ellipses then 2nd order may have an advantage since |
| 730 | * only one geometry would need to be rendered. However no benches were run comparing |
| 731 | * chopped first order and non chopped 2nd order. |
| 732 | */ |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 733 | class HairConicEdgeEffect : public GrEffect { |
| 734 | public: |
| 735 | static GrEffectRef* Create() { |
| 736 | GR_CREATE_STATIC_EFFECT(gHairConicEdgeEffect, HairConicEdgeEffect, ()); |
| 737 | gHairConicEdgeEffect->ref(); |
| 738 | return gHairConicEdgeEffect; |
| 739 | } |
| 740 | |
| 741 | virtual ~HairConicEdgeEffect() {} |
| 742 | |
| 743 | static const char* Name() { return "HairConicEdge"; } |
| 744 | |
| 745 | virtual void getConstantColorComponents(GrColor* color, |
| 746 | uint32_t* validFlags) const SK_OVERRIDE { |
| 747 | *validFlags = 0; |
| 748 | } |
| 749 | |
| 750 | virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE { |
| 751 | return GrTBackendEffectFactory<HairConicEdgeEffect>::getInstance(); |
| 752 | } |
| 753 | |
| 754 | class GLEffect : public GrGLEffect { |
| 755 | public: |
| 756 | GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) |
| 757 | : INHERITED (factory) {} |
| 758 | |
| 759 | virtual void emitCode(GrGLShaderBuilder* builder, |
| 760 | const GrDrawEffect& drawEffect, |
| 761 | EffectKey key, |
| 762 | const char* outputColor, |
| 763 | const char* inputColor, |
| 764 | const TextureSamplerArray& samplers) SK_OVERRIDE { |
egdaniel@google.com | 3f2a2d5 | 2013-08-01 17:09:11 +0000 | [diff] [blame^] | 765 | const char *vsName, *fsName; |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 766 | |
| 767 | SkAssertResult(builder->enableFeature( |
| 768 | GrGLShaderBuilder::kStandardDerivatives_GLSLFeature)); |
egdaniel@google.com | 3f2a2d5 | 2013-08-01 17:09:11 +0000 | [diff] [blame^] | 769 | builder->addVarying(kVec4f_GrSLType, "ConicCoeffs", |
| 770 | &vsName, &fsName); |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 771 | const SkString* attr0Name = |
| 772 | builder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0]); |
egdaniel@google.com | 3f2a2d5 | 2013-08-01 17:09:11 +0000 | [diff] [blame^] | 773 | builder->vsCodeAppendf("\t%s = %s;\n", vsName, attr0Name->c_str()); |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 774 | |
egdaniel@google.com | 3f2a2d5 | 2013-08-01 17:09:11 +0000 | [diff] [blame^] | 775 | builder->fsCodeAppend("\t\tfloat edgeAlpha;\n"); |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 776 | |
egdaniel@google.com | 3f2a2d5 | 2013-08-01 17:09:11 +0000 | [diff] [blame^] | 777 | builder->fsCodeAppendf("\t\tvec3 dklmdx = dFdx(%s.xyz);\n", fsName); |
| 778 | builder->fsCodeAppendf("\t\tvec3 dklmdy = dFdy(%s.xyz);\n", fsName); |
| 779 | builder->fsCodeAppendf("\t\tfloat dfdx =\n" |
| 780 | "\t\t\t2.0*%s.x*dklmdx.x - %s.y*dklmdx.z - %s.z*dklmdx.y;\n", |
| 781 | fsName, fsName, fsName); |
| 782 | builder->fsCodeAppendf("\t\tfloat dfdy =\n" |
| 783 | "\t\t\t2.0*%s.x*dklmdy.x - %s.y*dklmdy.z - %s.z*dklmdy.y;\n", |
| 784 | fsName, fsName, fsName); |
| 785 | builder->fsCodeAppend("\t\tvec2 gF = vec2(dfdx, dfdy);\n"); |
| 786 | builder->fsCodeAppend("\t\tfloat gFM = sqrt(dot(gF, gF));\n"); |
| 787 | builder->fsCodeAppendf("\t\tfloat func = abs(%s.x*%s.x - %s.y*%s.z);\n", fsName, fsName, |
| 788 | fsName, fsName); |
| 789 | builder->fsCodeAppend("\t\tedgeAlpha = func / gFM;\n"); |
| 790 | builder->fsCodeAppend("\t\tedgeAlpha = max(1.0 - edgeAlpha, 0.0);\n"); |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 791 | // Add line below for smooth cubic ramp |
| 792 | // builder->fsCodeAppend("\t\tedgeAlpha = edgeAlpha*edgeAlpha*(3.0-2.0*edgeAlpha);\n"); |
| 793 | |
| 794 | SkString modulate; |
| 795 | GrGLSLModulatef<4>(&modulate, inputColor, "edgeAlpha"); |
| 796 | builder->fsCodeAppendf("\t%s = %s;\n", outputColor, modulate.c_str()); |
| 797 | } |
| 798 | |
| 799 | static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&) { |
| 800 | return 0x0; |
| 801 | } |
| 802 | |
| 803 | virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE {} |
| 804 | |
| 805 | private: |
| 806 | typedef GrGLEffect INHERITED; |
| 807 | }; |
| 808 | |
| 809 | private: |
| 810 | HairConicEdgeEffect() { |
| 811 | this->addVertexAttrib(kVec4f_GrSLType); |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE { |
| 815 | return true; |
| 816 | } |
| 817 | |
| 818 | GR_DECLARE_EFFECT_TEST; |
| 819 | |
| 820 | typedef GrEffect INHERITED; |
| 821 | }; |
| 822 | |
| 823 | GR_DEFINE_EFFECT_TEST(HairConicEdgeEffect); |
| 824 | |
| 825 | GrEffectRef* HairConicEdgeEffect::TestCreate(SkMWCRandom* random, |
| 826 | GrContext*, |
| 827 | const GrDrawTargetCaps& caps, |
| 828 | GrTexture*[]) { |
egdaniel@google.com | 3f2a2d5 | 2013-08-01 17:09:11 +0000 | [diff] [blame^] | 829 | return caps.shaderDerivativeSupport() ? HairConicEdgeEffect::Create() : NULL; |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 830 | } |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 831 | |
| 832 | /** |
| 833 | * The output of this effect is a hairline edge for quadratics. |
| 834 | * Quadratic specified by 0=u^2-v canonical coords. u and v are the first |
| 835 | * two components of the vertex attribute. Uses unsigned distance. |
skia.committer@gmail.com | 041e2db | 2013-04-03 07:01:14 +0000 | [diff] [blame] | 836 | * Coverage is min(0, 1-distance). 3rd & 4th component unused. |
| 837 | * Requires shader derivative instruction support. |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 838 | */ |
| 839 | class HairQuadEdgeEffect : public GrEffect { |
| 840 | public: |
| 841 | |
| 842 | static GrEffectRef* Create() { |
bsalomon@google.com | d42aca3 | 2013-04-23 15:37:27 +0000 | [diff] [blame] | 843 | GR_CREATE_STATIC_EFFECT(gHairQuadEdgeEffect, HairQuadEdgeEffect, ()); |
| 844 | gHairQuadEdgeEffect->ref(); |
| 845 | return gHairQuadEdgeEffect; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 846 | } |
| 847 | |
| 848 | virtual ~HairQuadEdgeEffect() {} |
| 849 | |
| 850 | static const char* Name() { return "HairQuadEdge"; } |
| 851 | |
skia.committer@gmail.com | 041e2db | 2013-04-03 07:01:14 +0000 | [diff] [blame] | 852 | virtual void getConstantColorComponents(GrColor* color, |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 853 | uint32_t* validFlags) const SK_OVERRIDE { |
| 854 | *validFlags = 0; |
| 855 | } |
| 856 | |
| 857 | virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE { |
| 858 | return GrTBackendEffectFactory<HairQuadEdgeEffect>::getInstance(); |
| 859 | } |
| 860 | |
| 861 | class GLEffect : public GrGLEffect { |
| 862 | public: |
| 863 | GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) |
| 864 | : INHERITED (factory) {} |
| 865 | |
| 866 | virtual void emitCode(GrGLShaderBuilder* builder, |
| 867 | const GrDrawEffect& drawEffect, |
| 868 | EffectKey key, |
| 869 | const char* outputColor, |
| 870 | const char* inputColor, |
| 871 | const TextureSamplerArray& samplers) SK_OVERRIDE { |
| 872 | const char *vsName, *fsName; |
| 873 | const SkString* attrName = |
| 874 | builder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0]); |
| 875 | builder->fsCodeAppendf("\t\tfloat edgeAlpha;\n"); |
| 876 | |
| 877 | SkAssertResult(builder->enableFeature( |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 878 | GrGLShaderBuilder::kStandardDerivatives_GLSLFeature)); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 879 | builder->addVarying(kVec4f_GrSLType, "HairQuadEdge", &vsName, &fsName); |
| 880 | |
| 881 | builder->fsCodeAppendf("\t\tvec2 duvdx = dFdx(%s.xy);\n", fsName); |
| 882 | builder->fsCodeAppendf("\t\tvec2 duvdy = dFdy(%s.xy);\n", fsName); |
| 883 | builder->fsCodeAppendf("\t\tvec2 gF = vec2(2.0*%s.x*duvdx.x - duvdx.y,\n" |
| 884 | "\t\t 2.0*%s.x*duvdy.x - duvdy.y);\n", |
| 885 | fsName, fsName); |
| 886 | builder->fsCodeAppendf("\t\tedgeAlpha = (%s.x*%s.x - %s.y);\n", fsName, fsName, |
| 887 | fsName); |
| 888 | builder->fsCodeAppend("\t\tedgeAlpha = sqrt(edgeAlpha*edgeAlpha / dot(gF, gF));\n"); |
| 889 | builder->fsCodeAppend("\t\tedgeAlpha = max(1.0 - edgeAlpha, 0.0);\n"); |
| 890 | |
| 891 | SkString modulate; |
bsalomon@google.com | 018f179 | 2013-04-18 19:36:09 +0000 | [diff] [blame] | 892 | GrGLSLModulatef<4>(&modulate, inputColor, "edgeAlpha"); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 893 | builder->fsCodeAppendf("\t%s = %s;\n", outputColor, modulate.c_str()); |
| 894 | |
| 895 | builder->vsCodeAppendf("\t%s = %s;\n", vsName, attrName->c_str()); |
| 896 | } |
| 897 | |
| 898 | static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&) { |
| 899 | return 0x0; |
| 900 | } |
| 901 | |
| 902 | virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE {} |
| 903 | |
| 904 | private: |
| 905 | typedef GrGLEffect INHERITED; |
| 906 | }; |
| 907 | |
| 908 | private: |
skia.committer@gmail.com | 041e2db | 2013-04-03 07:01:14 +0000 | [diff] [blame] | 909 | HairQuadEdgeEffect() { |
| 910 | this->addVertexAttrib(kVec4f_GrSLType); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 911 | } |
| 912 | |
| 913 | virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE { |
| 914 | return true; |
| 915 | } |
| 916 | |
| 917 | GR_DECLARE_EFFECT_TEST; |
| 918 | |
| 919 | typedef GrEffect INHERITED; |
| 920 | }; |
| 921 | |
| 922 | GR_DEFINE_EFFECT_TEST(HairQuadEdgeEffect); |
| 923 | |
| 924 | GrEffectRef* HairQuadEdgeEffect::TestCreate(SkMWCRandom* random, |
| 925 | GrContext*, |
| 926 | const GrDrawTargetCaps& caps, |
| 927 | GrTexture*[]) { |
| 928 | // Doesn't work without derivative instructions. |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 929 | return caps.shaderDerivativeSupport() ? HairQuadEdgeEffect::Create() : NULL; |
| 930 | } |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 931 | |
| 932 | /////////////////////////////////////////////////////////////////////////////// |
| 933 | |
| 934 | /** |
skia.committer@gmail.com | 041e2db | 2013-04-03 07:01:14 +0000 | [diff] [blame] | 935 | * The output of this effect is a 1-pixel wide line. |
| 936 | * Input is 2D implicit device coord line eq (a*x + b*y +c = 0). 4th component unused. |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 937 | */ |
| 938 | class HairLineEdgeEffect : public GrEffect { |
| 939 | public: |
| 940 | |
| 941 | static GrEffectRef* Create() { |
bsalomon@google.com | d42aca3 | 2013-04-23 15:37:27 +0000 | [diff] [blame] | 942 | GR_CREATE_STATIC_EFFECT(gHairLineEdge, HairLineEdgeEffect, ()); |
| 943 | gHairLineEdge->ref(); |
| 944 | return gHairLineEdge; |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | virtual ~HairLineEdgeEffect() {} |
| 948 | |
| 949 | static const char* Name() { return "HairLineEdge"; } |
| 950 | |
skia.committer@gmail.com | 041e2db | 2013-04-03 07:01:14 +0000 | [diff] [blame] | 951 | virtual void getConstantColorComponents(GrColor* color, |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 952 | uint32_t* validFlags) const SK_OVERRIDE { |
| 953 | *validFlags = 0; |
| 954 | } |
| 955 | |
| 956 | virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE { |
| 957 | return GrTBackendEffectFactory<HairLineEdgeEffect>::getInstance(); |
| 958 | } |
| 959 | |
| 960 | class GLEffect : public GrGLEffect { |
| 961 | public: |
| 962 | GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) |
| 963 | : INHERITED (factory) {} |
| 964 | |
| 965 | virtual void emitCode(GrGLShaderBuilder* builder, |
| 966 | const GrDrawEffect& drawEffect, |
| 967 | EffectKey key, |
| 968 | const char* outputColor, |
| 969 | const char* inputColor, |
| 970 | const TextureSamplerArray& samplers) SK_OVERRIDE { |
| 971 | const char *vsName, *fsName; |
| 972 | const SkString* attrName = |
| 973 | builder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0]); |
| 974 | builder->fsCodeAppendf("\t\tfloat edgeAlpha;\n"); |
| 975 | |
| 976 | builder->addVarying(kVec4f_GrSLType, "HairLineEdge", &vsName, &fsName); |
| 977 | |
| 978 | builder->fsCodeAppendf("\t\tedgeAlpha = abs(dot(vec3(%s.xy,1), %s.xyz));\n", |
| 979 | builder->fragmentPosition(), fsName); |
| 980 | builder->fsCodeAppendf("\t\tedgeAlpha = max(1.0 - edgeAlpha, 0.0);\n"); |
| 981 | |
| 982 | SkString modulate; |
bsalomon@google.com | 018f179 | 2013-04-18 19:36:09 +0000 | [diff] [blame] | 983 | GrGLSLModulatef<4>(&modulate, inputColor, "edgeAlpha"); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 984 | builder->fsCodeAppendf("\t%s = %s;\n", outputColor, modulate.c_str()); |
| 985 | |
| 986 | builder->vsCodeAppendf("\t%s = %s;\n", vsName, attrName->c_str()); |
| 987 | } |
| 988 | |
| 989 | static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&) { |
| 990 | return 0x0; |
| 991 | } |
| 992 | |
| 993 | virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE {} |
| 994 | |
| 995 | private: |
| 996 | typedef GrGLEffect INHERITED; |
| 997 | }; |
| 998 | |
| 999 | private: |
skia.committer@gmail.com | 041e2db | 2013-04-03 07:01:14 +0000 | [diff] [blame] | 1000 | HairLineEdgeEffect() { |
| 1001 | this->addVertexAttrib(kVec4f_GrSLType); |
commit-bot@chromium.org | 8d47ddc | 2013-05-09 14:55:46 +0000 | [diff] [blame] | 1002 | this->setWillReadFragmentPosition(); |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE { |
| 1006 | return true; |
| 1007 | } |
| 1008 | |
| 1009 | GR_DECLARE_EFFECT_TEST; |
| 1010 | |
| 1011 | typedef GrEffect INHERITED; |
| 1012 | }; |
| 1013 | |
| 1014 | GR_DEFINE_EFFECT_TEST(HairLineEdgeEffect); |
| 1015 | |
| 1016 | GrEffectRef* HairLineEdgeEffect::TestCreate(SkMWCRandom* random, |
| 1017 | GrContext*, |
| 1018 | const GrDrawTargetCaps& caps, |
| 1019 | GrTexture*[]) { |
| 1020 | return HairLineEdgeEffect::Create(); |
| 1021 | } |
| 1022 | |
| 1023 | /////////////////////////////////////////////////////////////////////////////// |
| 1024 | |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 1025 | namespace { |
| 1026 | |
| 1027 | // position + edge |
| 1028 | extern const GrVertexAttrib gHairlineAttribs[] = { |
| 1029 | {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}, |
| 1030 | {kVec4f_GrVertexAttribType, sizeof(GrPoint), kEffect_GrVertexAttribBinding} |
| 1031 | }; |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 1032 | }; |
| 1033 | |
bsalomon@google.com | b372942 | 2012-03-07 19:13:28 +0000 | [diff] [blame] | 1034 | bool GrAAHairLinePathRenderer::createGeom( |
| 1035 | const SkPath& path, |
bsalomon@google.com | b372942 | 2012-03-07 19:13:28 +0000 | [diff] [blame] | 1036 | GrDrawTarget* target, |
bsalomon@google.com | b372942 | 2012-03-07 19:13:28 +0000 | [diff] [blame] | 1037 | int* lineCnt, |
| 1038 | int* quadCnt, |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 1039 | int* conicCnt, |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 1040 | GrDrawTarget::AutoReleaseGeometry* arg, |
| 1041 | SkRect* devBounds) { |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 1042 | GrDrawState* drawState = target->drawState(); |
| 1043 | int rtHeight = drawState->getRenderTarget()->height(); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 1044 | |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 1045 | SkIRect devClipBounds; |
commit-bot@chromium.org | 912e68e | 2013-05-24 18:51:55 +0000 | [diff] [blame] | 1046 | target->getClip()->getConservativeBounds(drawState->getRenderTarget(), &devClipBounds); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 1047 | |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 1048 | SkMatrix viewM = drawState->getViewMatrix(); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 1049 | |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 1050 | // All the vertices that we compute are within 1 of path control points with the exception of |
| 1051 | // one of the bounding vertices for each quad. The add_quads() function will update the bounds |
| 1052 | // for each quad added. |
| 1053 | *devBounds = path.getBounds(); |
| 1054 | viewM.mapRect(devBounds); |
| 1055 | devBounds->outset(SK_Scalar1, SK_Scalar1); |
| 1056 | |
bsalomon@google.com | 9266901 | 2011-09-27 19:10:05 +0000 | [diff] [blame] | 1057 | PREALLOC_PTARRAY(128) lines; |
| 1058 | PREALLOC_PTARRAY(128) quads; |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 1059 | PREALLOC_PTARRAY(128) conics; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 1060 | IntArray qSubdivs; |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 1061 | FloatArray cWeights; |
bsalomon@google.com | 0f11e1a | 2012-10-08 14:48:36 +0000 | [diff] [blame] | 1062 | *quadCnt = generate_lines_and_quads(path, viewM, devClipBounds, |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 1063 | &lines, &quads, &conics, &qSubdivs, &cWeights); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 1064 | |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 1065 | *lineCnt = lines.count() / 2; |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 1066 | *conicCnt = conics.count() / 3; |
| 1067 | int vertCnt = kVertsPerLineSeg * *lineCnt + kVertsPerQuad * *quadCnt + |
| 1068 | kVertsPerQuad * *conicCnt; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 1069 | |
egdaniel@google.com | 3f2a2d5 | 2013-08-01 17:09:11 +0000 | [diff] [blame^] | 1070 | target->drawState()->setVertexAttribs<gHairlineAttribs>(SK_ARRAY_COUNT(gHairlineAttribs)); |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 1071 | GrAssert(sizeof(Vertex) == target->getDrawState().getVertexSize()); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 1072 | |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 1073 | if (!arg->set(target, vertCnt, 0)) { |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 1074 | return false; |
| 1075 | } |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 1076 | |
bsalomon@google.com | b372942 | 2012-03-07 19:13:28 +0000 | [diff] [blame] | 1077 | Vertex* verts = reinterpret_cast<Vertex*>(arg->vertices()); |
| 1078 | |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 1079 | const SkMatrix* toDevice = NULL; |
| 1080 | const SkMatrix* toSrc = NULL; |
| 1081 | SkMatrix ivm; |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 1082 | |
| 1083 | if (viewM.hasPerspective()) { |
| 1084 | if (viewM.invert(&ivm)) { |
| 1085 | toDevice = &viewM; |
| 1086 | toSrc = &ivm; |
| 1087 | } |
| 1088 | } |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 1089 | |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 1090 | for (int i = 0; i < *lineCnt; ++i) { |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 1091 | add_line(&lines[2*i], rtHeight, toSrc, &verts); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 1092 | } |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 1093 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 1094 | int unsubdivQuadCnt = quads.count() / 3; |
| 1095 | for (int i = 0; i < unsubdivQuadCnt; ++i) { |
| 1096 | GrAssert(qSubdivs[i] >= 0); |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 1097 | add_quads(&quads[3*i], qSubdivs[i], toDevice, toSrc, &verts, devBounds); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 1098 | } |
| 1099 | |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 1100 | // Start Conics |
| 1101 | for (int i = 0; i < *conicCnt; ++i) { |
| 1102 | add_conics(&conics[3*i], cWeights[i], toDevice, toSrc, &verts, devBounds); |
| 1103 | } |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 1104 | return true; |
| 1105 | } |
| 1106 | |
robertphillips@google.com | 8a4fc40 | 2012-05-24 12:42:24 +0000 | [diff] [blame] | 1107 | bool GrAAHairLinePathRenderer::canDrawPath(const SkPath& path, |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 1108 | const SkStrokeRec& stroke, |
robertphillips@google.com | 8a4fc40 | 2012-05-24 12:42:24 +0000 | [diff] [blame] | 1109 | const GrDrawTarget* target, |
| 1110 | bool antiAlias) const { |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 1111 | if (!stroke.isHairlineStyle() || !antiAlias) { |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 1112 | return false; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 1113 | } |
| 1114 | |
egdaniel@google.com | 3f2a2d5 | 2013-08-01 17:09:11 +0000 | [diff] [blame^] | 1115 | if (SkPath::kLine_SegmentMask == path.getSegmentMasks() || |
| 1116 | target->caps()->shaderDerivativeSupport()) { |
| 1117 | return true; |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 1118 | } |
egdaniel@google.com | 3f2a2d5 | 2013-08-01 17:09:11 +0000 | [diff] [blame^] | 1119 | return false; |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 1120 | } |
| 1121 | |
| 1122 | bool GrAAHairLinePathRenderer::onDrawPath(const SkPath& path, |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 1123 | const SkStrokeRec&, |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 1124 | GrDrawTarget* target, |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 1125 | bool antiAlias) { |
| 1126 | |
| 1127 | int lineCnt; |
| 1128 | int quadCnt; |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 1129 | int conicCnt; |
bsalomon@google.com | b372942 | 2012-03-07 19:13:28 +0000 | [diff] [blame] | 1130 | GrDrawTarget::AutoReleaseGeometry arg; |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 1131 | SkRect devBounds; |
| 1132 | |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 1133 | if (!this->createGeom(path, |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 1134 | target, |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 1135 | &lineCnt, |
bsalomon@google.com | b372942 | 2012-03-07 19:13:28 +0000 | [diff] [blame] | 1136 | &quadCnt, |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 1137 | &conicCnt, |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 1138 | &arg, |
| 1139 | &devBounds)) { |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 1140 | return false; |
| 1141 | } |
| 1142 | |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 1143 | GrDrawTarget::AutoStateRestore asr; |
bsalomon@google.com | 4647f90 | 2013-03-26 14:45:27 +0000 | [diff] [blame] | 1144 | |
bsalomon@google.com | a834746 | 2012-10-08 18:59:39 +0000 | [diff] [blame] | 1145 | // createGeom transforms the geometry to device space when the matrix does not have |
| 1146 | // perspective. |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 1147 | if (target->getDrawState().getViewMatrix().hasPerspective()) { |
| 1148 | asr.set(target, GrDrawTarget::kPreserve_ASRInit); |
| 1149 | } else if (!asr.setIdentity(target, GrDrawTarget::kPreserve_ASRInit)) { |
| 1150 | return false; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 1151 | } |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 1152 | GrDrawState* drawState = target->drawState(); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 1153 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 1154 | // TODO: See whether rendering lines as degenerate quads improves perf |
| 1155 | // when we have a mix |
bsalomon@google.com | a834746 | 2012-10-08 18:59:39 +0000 | [diff] [blame] | 1156 | |
bsalomon@google.com | 4647f90 | 2013-03-26 14:45:27 +0000 | [diff] [blame] | 1157 | static const int kEdgeAttrIndex = 1; |
bsalomon@google.com | a834746 | 2012-10-08 18:59:39 +0000 | [diff] [blame] | 1158 | |
commit-bot@chromium.org | 90c240a | 2013-04-02 17:57:21 +0000 | [diff] [blame] | 1159 | GrEffectRef* hairLineEffect = HairLineEdgeEffect::Create(); |
| 1160 | GrEffectRef* hairQuadEffect = HairQuadEdgeEffect::Create(); |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 1161 | GrEffectRef* hairConicEffect = HairConicEdgeEffect::Create(); |
skia.committer@gmail.com | 37cbc7f | 2013-03-27 07:01:04 +0000 | [diff] [blame] | 1162 | |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 1163 | // Check devBounds |
| 1164 | #if GR_DEBUG |
| 1165 | SkRect tolDevBounds = devBounds; |
| 1166 | tolDevBounds.outset(SK_Scalar1 / 10000, SK_Scalar1 / 10000); |
| 1167 | SkRect actualBounds; |
| 1168 | Vertex* verts = reinterpret_cast<Vertex*>(arg.vertices()); |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 1169 | int vCount = kVertsPerLineSeg * lineCnt + kVertsPerQuad * quadCnt + kVertsPerQuad * conicCnt; |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 1170 | bool first = true; |
| 1171 | for (int i = 0; i < vCount; ++i) { |
| 1172 | SkPoint pos = verts[i].fPos; |
| 1173 | // This is a hack to workaround the fact that we move some degenerate segments offscreen. |
| 1174 | if (SK_ScalarMax == pos.fX) { |
| 1175 | continue; |
| 1176 | } |
| 1177 | drawState->getViewMatrix().mapPoints(&pos, 1); |
| 1178 | if (first) { |
| 1179 | actualBounds.set(pos.fX, pos.fY, pos.fX, pos.fY); |
| 1180 | first = false; |
| 1181 | } else { |
| 1182 | actualBounds.growToInclude(pos.fX, pos.fY); |
| 1183 | } |
| 1184 | } |
| 1185 | if (!first) { |
| 1186 | GrAssert(tolDevBounds.contains(actualBounds)); |
| 1187 | } |
| 1188 | #endif |
| 1189 | |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 1190 | { |
| 1191 | GrDrawState::AutoRestoreEffects are(drawState); |
| 1192 | target->setIndexSourceToBuffer(fLinesIndexBuffer); |
| 1193 | int lines = 0; |
| 1194 | int nBufLines = fLinesIndexBuffer->maxQuads(); |
| 1195 | drawState->addCoverageEffect(hairLineEffect, kEdgeAttrIndex)->unref(); |
| 1196 | while (lines < lineCnt) { |
| 1197 | int n = GrMin(lineCnt - lines, nBufLines); |
| 1198 | target->drawIndexed(kTriangles_GrPrimitiveType, |
| 1199 | kVertsPerLineSeg*lines, // startV |
| 1200 | 0, // startI |
| 1201 | kVertsPerLineSeg*n, // vCount |
| 1202 | kIdxsPerLineSeg*n, |
| 1203 | &devBounds); // iCount |
| 1204 | lines += n; |
| 1205 | } |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 1206 | } |
| 1207 | |
egdaniel@google.com | 5383a75 | 2013-07-12 20:15:34 +0000 | [diff] [blame] | 1208 | { |
| 1209 | GrDrawState::AutoRestoreEffects are(drawState); |
| 1210 | target->setIndexSourceToBuffer(fQuadsIndexBuffer); |
| 1211 | int quads = 0; |
| 1212 | drawState->addCoverageEffect(hairQuadEffect, kEdgeAttrIndex)->unref(); |
| 1213 | while (quads < quadCnt) { |
| 1214 | int n = GrMin(quadCnt - quads, kNumQuadsInIdxBuffer); |
| 1215 | target->drawIndexed(kTriangles_GrPrimitiveType, |
| 1216 | kVertsPerLineSeg * lineCnt + kVertsPerQuad*quads, // startV |
| 1217 | 0, // startI |
| 1218 | kVertsPerQuad*n, // vCount |
| 1219 | kIdxsPerQuad*n, // iCount |
| 1220 | &devBounds); |
| 1221 | quads += n; |
| 1222 | } |
| 1223 | } |
| 1224 | |
| 1225 | { |
| 1226 | GrDrawState::AutoRestoreEffects are(drawState); |
| 1227 | int conics = 0; |
| 1228 | drawState->addCoverageEffect(hairConicEffect, 1, 2)->unref(); |
| 1229 | while (conics < conicCnt) { |
| 1230 | int n = GrMin(conicCnt - conics, kNumQuadsInIdxBuffer); |
| 1231 | target->drawIndexed(kTriangles_GrPrimitiveType, |
| 1232 | kVertsPerLineSeg*lineCnt + |
| 1233 | kVertsPerQuad*(quadCnt + conics), // startV |
| 1234 | 0, // startI |
| 1235 | kVertsPerQuad*n, // vCount |
| 1236 | kIdxsPerQuad*n, // iCount |
| 1237 | &devBounds); |
| 1238 | conics += n; |
| 1239 | } |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 1240 | } |
bsalomon@google.com | 0406b9e | 2013-04-02 21:00:15 +0000 | [diff] [blame] | 1241 | target->resetIndexSource(); |
bsalomon@google.com | 4647f90 | 2013-03-26 14:45:27 +0000 | [diff] [blame] | 1242 | |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 1243 | return true; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 1244 | } |