bsalomon@google.com | f75b84e | 2011-09-29 14:58:28 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 9 | #include "GrAAHairLinePathRenderer.h" |
| 10 | |
| 11 | #include "GrContext.h" |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 12 | #include "GrDrawState.h" |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 13 | #include "GrGpu.h" |
| 14 | #include "GrIndexBuffer.h" |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 15 | #include "GrPathUtils.h" |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 16 | #include "SkGeometry.h" |
| 17 | #include "SkTemplates.h" |
| 18 | |
| 19 | namespace { |
| 20 | // quadratics are rendered as 5-sided polys in order to bound the |
| 21 | // AA stroke around the center-curve. See comments in push_quad_index_buffer and |
| 22 | // bloat_quad. |
| 23 | static const int kVertsPerQuad = 5; |
| 24 | static const int kIdxsPerQuad = 9; |
| 25 | |
| 26 | static const int kVertsPerLineSeg = 4; |
| 27 | static const int kIdxsPerLineSeg = 6; |
| 28 | |
| 29 | static const int kNumQuadsInIdxBuffer = 256; |
| 30 | static const size_t kQuadIdxSBufize = kIdxsPerQuad * |
| 31 | sizeof(uint16_t) * |
| 32 | kNumQuadsInIdxBuffer; |
| 33 | |
| 34 | bool push_quad_index_data(GrIndexBuffer* qIdxBuffer) { |
| 35 | uint16_t* data = (uint16_t*) qIdxBuffer->lock(); |
| 36 | bool tempData = NULL == data; |
| 37 | if (tempData) { |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 38 | data = SkNEW_ARRAY(uint16_t, kNumQuadsInIdxBuffer * kIdxsPerQuad); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 39 | } |
| 40 | for (int i = 0; i < kNumQuadsInIdxBuffer; ++i) { |
| 41 | |
| 42 | // Each quadratic is rendered as a five sided polygon. This poly bounds |
| 43 | // the quadratic's bounding triangle but has been expanded so that the |
| 44 | // 1-pixel wide area around the curve is inside the poly. |
| 45 | // If a,b,c are the original control points then the poly a0,b0,c0,c1,a1 |
| 46 | // that is rendered would look like this: |
| 47 | // b0 |
| 48 | // b |
| 49 | // |
| 50 | // a0 c0 |
| 51 | // a c |
| 52 | // a1 c1 |
bsalomon@google.com | 0e5104c | 2012-04-10 16:20:41 +0000 | [diff] [blame] | 53 | // Each is drawn as three triangles specified by these 9 indices: |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 54 | int baseIdx = i * kIdxsPerQuad; |
| 55 | uint16_t baseVert = (uint16_t)(i * kVertsPerQuad); |
| 56 | data[0 + baseIdx] = baseVert + 0; // a0 |
| 57 | data[1 + baseIdx] = baseVert + 1; // a1 |
| 58 | data[2 + baseIdx] = baseVert + 2; // b0 |
| 59 | data[3 + baseIdx] = baseVert + 2; // b0 |
| 60 | data[4 + baseIdx] = baseVert + 4; // c1 |
| 61 | data[5 + baseIdx] = baseVert + 3; // c0 |
| 62 | data[6 + baseIdx] = baseVert + 1; // a1 |
| 63 | data[7 + baseIdx] = baseVert + 4; // c1 |
| 64 | data[8 + baseIdx] = baseVert + 2; // b0 |
| 65 | } |
| 66 | if (tempData) { |
| 67 | bool ret = qIdxBuffer->updateData(data, kQuadIdxSBufize); |
| 68 | delete[] data; |
| 69 | return ret; |
| 70 | } else { |
| 71 | qIdxBuffer->unlock(); |
| 72 | return true; |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | GrPathRenderer* GrAAHairLinePathRenderer::Create(GrContext* context) { |
bsalomon@google.com | a8a6a32 | 2011-09-23 14:19:58 +0000 | [diff] [blame] | 78 | const GrIndexBuffer* lIdxBuffer = context->getQuadIndexBuffer(); |
| 79 | if (NULL == lIdxBuffer) { |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 80 | return NULL; |
| 81 | } |
bsalomon@google.com | a8a6a32 | 2011-09-23 14:19:58 +0000 | [diff] [blame] | 82 | GrGpu* gpu = context->getGpu(); |
| 83 | GrIndexBuffer* qIdxBuf = gpu->createIndexBuffer(kQuadIdxSBufize, false); |
| 84 | SkAutoTUnref<GrIndexBuffer> qIdxBuffer(qIdxBuf); |
| 85 | if (NULL == qIdxBuf || |
| 86 | !push_quad_index_data(qIdxBuf)) { |
| 87 | return NULL; |
| 88 | } |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 89 | return SkNEW_ARGS(GrAAHairLinePathRenderer, |
| 90 | (context, lIdxBuffer, qIdxBuf)); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | GrAAHairLinePathRenderer::GrAAHairLinePathRenderer( |
| 94 | const GrContext* context, |
| 95 | const GrIndexBuffer* linesIndexBuffer, |
| 96 | const GrIndexBuffer* quadsIndexBuffer) { |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 97 | fLinesIndexBuffer = linesIndexBuffer; |
| 98 | linesIndexBuffer->ref(); |
| 99 | fQuadsIndexBuffer = quadsIndexBuffer; |
| 100 | quadsIndexBuffer->ref(); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | GrAAHairLinePathRenderer::~GrAAHairLinePathRenderer() { |
| 104 | fLinesIndexBuffer->unref(); |
| 105 | fQuadsIndexBuffer->unref(); |
| 106 | } |
| 107 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 108 | namespace { |
| 109 | |
bsalomon@google.com | 49313f6 | 2011-09-14 13:54:05 +0000 | [diff] [blame] | 110 | typedef SkTArray<SkPoint, true> PtArray; |
bsalomon@google.com | 9266901 | 2011-09-27 19:10:05 +0000 | [diff] [blame] | 111 | #define PREALLOC_PTARRAY(N) SkSTArray<(N),SkPoint, true> |
bsalomon@google.com | 49313f6 | 2011-09-14 13:54:05 +0000 | [diff] [blame] | 112 | typedef SkTArray<int, true> IntArray; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 113 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 114 | // Takes 178th time of logf on Z600 / VC2010 |
| 115 | int get_float_exp(float x) { |
| 116 | GR_STATIC_ASSERT(sizeof(int) == sizeof(float)); |
| 117 | #if GR_DEBUG |
| 118 | static bool tested; |
| 119 | if (!tested) { |
| 120 | tested = true; |
| 121 | GrAssert(get_float_exp(0.25f) == -2); |
| 122 | GrAssert(get_float_exp(0.3f) == -2); |
| 123 | GrAssert(get_float_exp(0.5f) == -1); |
| 124 | GrAssert(get_float_exp(1.f) == 0); |
| 125 | GrAssert(get_float_exp(2.f) == 1); |
| 126 | GrAssert(get_float_exp(2.5f) == 1); |
| 127 | GrAssert(get_float_exp(8.f) == 3); |
| 128 | GrAssert(get_float_exp(100.f) == 6); |
| 129 | GrAssert(get_float_exp(1000.f) == 9); |
| 130 | GrAssert(get_float_exp(1024.f) == 10); |
| 131 | GrAssert(get_float_exp(3000000.f) == 21); |
| 132 | } |
| 133 | #endif |
bsalomon@google.com | 2ec7280 | 2011-09-21 21:46:03 +0000 | [diff] [blame] | 134 | const int* iptr = (const int*)&x; |
| 135 | return (((*iptr) & 0x7f800000) >> 23) - 127; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | // we subdivide the quads to avoid huge overfill |
| 139 | // if it returns -1 then should be drawn as lines |
| 140 | int num_quad_subdivs(const SkPoint p[3]) { |
| 141 | static const SkScalar gDegenerateToLineTol = SK_Scalar1; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 142 | static const SkScalar gDegenerateToLineTolSqd = |
bsalomon@google.com | 46a2a1e | 2011-09-06 22:10:52 +0000 | [diff] [blame] | 143 | SkScalarMul(gDegenerateToLineTol, gDegenerateToLineTol); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 144 | |
bsalomon@google.com | 46a2a1e | 2011-09-06 22:10:52 +0000 | [diff] [blame] | 145 | if (p[0].distanceToSqd(p[1]) < gDegenerateToLineTolSqd || |
| 146 | p[1].distanceToSqd(p[2]) < gDegenerateToLineTolSqd) { |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 147 | return -1; |
| 148 | } |
bsalomon@google.com | 46a2a1e | 2011-09-06 22:10:52 +0000 | [diff] [blame] | 149 | |
bsalomon@google.com | 8171288 | 2012-11-01 17:12:34 +0000 | [diff] [blame] | 150 | SkScalar dsqd = p[1].distanceToLineBetweenSqd(p[0], p[2]); |
bsalomon@google.com | 46a2a1e | 2011-09-06 22:10:52 +0000 | [diff] [blame] | 151 | if (dsqd < gDegenerateToLineTolSqd) { |
| 152 | return -1; |
| 153 | } |
| 154 | |
| 155 | if (p[2].distanceToLineBetweenSqd(p[1], p[0]) < gDegenerateToLineTolSqd) { |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 156 | return -1; |
| 157 | } |
| 158 | |
| 159 | static const int kMaxSub = 4; |
| 160 | // tolerance of triangle height in pixels |
| 161 | // tuned on windows Quadro FX 380 / Z600 |
| 162 | // trade off of fill vs cpu time on verts |
| 163 | // maybe different when do this using gpu (geo or tess shaders) |
| 164 | static const SkScalar gSubdivTol = 175 * SK_Scalar1; |
| 165 | |
robertphillips@google.com | 7460b37 | 2012-04-25 16:54:51 +0000 | [diff] [blame] | 166 | if (dsqd <= SkScalarMul(gSubdivTol, gSubdivTol)) { |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 167 | return 0; |
| 168 | } else { |
| 169 | // subdividing the quad reduces d by 4. so we want x = log4(d/tol) |
| 170 | // = log4(d*d/tol*tol)/2 |
| 171 | // = log2(d*d/tol*tol) |
| 172 | |
| 173 | #ifdef SK_SCALAR_IS_FLOAT |
| 174 | // +1 since we're ignoring the mantissa contribution. |
| 175 | int log = get_float_exp(dsqd/(gSubdivTol*gSubdivTol)) + 1; |
| 176 | log = GrMin(GrMax(0, log), kMaxSub); |
| 177 | return log; |
| 178 | #else |
robertphillips@google.com | 7460b37 | 2012-04-25 16:54:51 +0000 | [diff] [blame] | 179 | SkScalar log = SkScalarLog( |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 180 | SkScalarDiv(dsqd, |
robertphillips@google.com | 7460b37 | 2012-04-25 16:54:51 +0000 | [diff] [blame] | 181 | SkScalarMul(gSubdivTol, gSubdivTol))); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 182 | static const SkScalar conv = SkScalarInvert(SkScalarLog(2)); |
| 183 | log = SkScalarMul(log, conv); |
| 184 | return GrMin(GrMax(0, SkScalarCeilToInt(log)),kMaxSub); |
| 185 | #endif |
| 186 | } |
| 187 | } |
| 188 | |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 189 | /** |
| 190 | * Generates the lines and quads to be rendered. Lines are always recorded in |
| 191 | * device space. We will do a device space bloat to account for the 1pixel |
| 192 | * thickness. |
| 193 | * Quads are recorded in device space unless m contains |
| 194 | * perspective, then in they are in src space. We do this because we will |
| 195 | * subdivide large quads to reduce over-fill. This subdivision has to be |
| 196 | * performed before applying the perspective matrix. |
| 197 | */ |
| 198 | int generate_lines_and_quads(const SkPath& path, |
| 199 | const SkMatrix& m, |
robertphillips@google.com | 7b11289 | 2012-07-31 15:18:21 +0000 | [diff] [blame] | 200 | const GrIRect& devClipBounds, |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 201 | PtArray* lines, |
| 202 | PtArray* quads, |
| 203 | IntArray* quadSubdivCnts) { |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 204 | SkPath::Iter iter(path, false); |
| 205 | |
| 206 | int totalQuadCount = 0; |
| 207 | GrRect bounds; |
| 208 | GrIRect ibounds; |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 209 | |
| 210 | bool persp = m.hasPerspective(); |
| 211 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 212 | for (;;) { |
| 213 | GrPoint pts[4]; |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 214 | GrPoint devPts[4]; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 215 | GrPathCmd cmd = (GrPathCmd)iter.next(pts); |
| 216 | switch (cmd) { |
| 217 | case kMove_PathCmd: |
| 218 | break; |
| 219 | case kLine_PathCmd: |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 220 | m.mapPoints(devPts, pts, 2); |
| 221 | bounds.setBounds(devPts, 2); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 222 | bounds.outset(SK_Scalar1, SK_Scalar1); |
| 223 | bounds.roundOut(&ibounds); |
robertphillips@google.com | 7b11289 | 2012-07-31 15:18:21 +0000 | [diff] [blame] | 224 | if (SkIRect::Intersects(devClipBounds, ibounds)) { |
bsalomon@google.com | a996fec | 2011-09-13 18:49:13 +0000 | [diff] [blame] | 225 | SkPoint* pts = lines->push_back_n(2); |
| 226 | pts[0] = devPts[0]; |
| 227 | pts[1] = devPts[1]; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 228 | } |
| 229 | break; |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 230 | case kQuadratic_PathCmd: |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 231 | m.mapPoints(devPts, pts, 3); |
| 232 | bounds.setBounds(devPts, 3); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 233 | bounds.outset(SK_Scalar1, SK_Scalar1); |
| 234 | bounds.roundOut(&ibounds); |
robertphillips@google.com | 7b11289 | 2012-07-31 15:18:21 +0000 | [diff] [blame] | 235 | if (SkIRect::Intersects(devClipBounds, ibounds)) { |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 236 | int subdiv = num_quad_subdivs(devPts); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 237 | GrAssert(subdiv >= -1); |
| 238 | if (-1 == subdiv) { |
bsalomon@google.com | a996fec | 2011-09-13 18:49:13 +0000 | [diff] [blame] | 239 | SkPoint* pts = lines->push_back_n(4); |
| 240 | pts[0] = devPts[0]; |
| 241 | pts[1] = devPts[1]; |
| 242 | pts[2] = devPts[1]; |
| 243 | pts[3] = devPts[2]; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 244 | } else { |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 245 | // when in perspective keep quads in src space |
| 246 | SkPoint* qPts = persp ? pts : devPts; |
bsalomon@google.com | a996fec | 2011-09-13 18:49:13 +0000 | [diff] [blame] | 247 | SkPoint* pts = quads->push_back_n(3); |
| 248 | pts[0] = qPts[0]; |
| 249 | pts[1] = qPts[1]; |
| 250 | pts[2] = qPts[2]; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 251 | quadSubdivCnts->push_back() = subdiv; |
| 252 | totalQuadCount += 1 << subdiv; |
| 253 | } |
| 254 | } |
bsalomon@google.com | a51ab84 | 2012-07-10 19:53:34 +0000 | [diff] [blame] | 255 | break; |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 256 | case kCubic_PathCmd: |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 257 | m.mapPoints(devPts, pts, 4); |
| 258 | bounds.setBounds(devPts, 4); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 259 | bounds.outset(SK_Scalar1, SK_Scalar1); |
| 260 | bounds.roundOut(&ibounds); |
robertphillips@google.com | 7b11289 | 2012-07-31 15:18:21 +0000 | [diff] [blame] | 261 | if (SkIRect::Intersects(devClipBounds, ibounds)) { |
bsalomon@google.com | 9266901 | 2011-09-27 19:10:05 +0000 | [diff] [blame] | 262 | PREALLOC_PTARRAY(32) q; |
bsalomon@google.com | a51ab84 | 2012-07-10 19:53:34 +0000 | [diff] [blame] | 263 | // we don't need a direction if we aren't constraining the subdivision |
| 264 | static const SkPath::Direction kDummyDir = SkPath::kCCW_Direction; |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 265 | // We convert cubics to quadratics (for now). |
| 266 | // In perspective have to do conversion in src space. |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 267 | if (persp) { |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 268 | SkScalar tolScale = |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 269 | GrPathUtils::scaleToleranceToSrc(SK_Scalar1, m, |
| 270 | path.getBounds()); |
bsalomon@google.com | a51ab84 | 2012-07-10 19:53:34 +0000 | [diff] [blame] | 271 | GrPathUtils::convertCubicToQuads(pts, tolScale, false, kDummyDir, &q); |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 272 | } else { |
bsalomon@google.com | a51ab84 | 2012-07-10 19:53:34 +0000 | [diff] [blame] | 273 | GrPathUtils::convertCubicToQuads(devPts, SK_Scalar1, false, kDummyDir, &q); |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 274 | } |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 275 | for (int i = 0; i < q.count(); i += 3) { |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 276 | SkPoint* qInDevSpace; |
| 277 | // bounds has to be calculated in device space, but q is |
| 278 | // in src space when there is perspective. |
| 279 | if (persp) { |
| 280 | m.mapPoints(devPts, &q[i], 3); |
| 281 | bounds.setBounds(devPts, 3); |
| 282 | qInDevSpace = devPts; |
| 283 | } else { |
| 284 | bounds.setBounds(&q[i], 3); |
| 285 | qInDevSpace = &q[i]; |
| 286 | } |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 287 | bounds.outset(SK_Scalar1, SK_Scalar1); |
| 288 | bounds.roundOut(&ibounds); |
robertphillips@google.com | 7b11289 | 2012-07-31 15:18:21 +0000 | [diff] [blame] | 289 | if (SkIRect::Intersects(devClipBounds, ibounds)) { |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 290 | int subdiv = num_quad_subdivs(qInDevSpace); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 291 | GrAssert(subdiv >= -1); |
| 292 | if (-1 == subdiv) { |
bsalomon@google.com | a996fec | 2011-09-13 18:49:13 +0000 | [diff] [blame] | 293 | SkPoint* pts = lines->push_back_n(4); |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 294 | // lines should always be in device coords |
bsalomon@google.com | a996fec | 2011-09-13 18:49:13 +0000 | [diff] [blame] | 295 | pts[0] = qInDevSpace[0]; |
| 296 | pts[1] = qInDevSpace[1]; |
| 297 | pts[2] = qInDevSpace[1]; |
| 298 | pts[3] = qInDevSpace[2]; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 299 | } else { |
bsalomon@google.com | a996fec | 2011-09-13 18:49:13 +0000 | [diff] [blame] | 300 | SkPoint* pts = quads->push_back_n(3); |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 301 | // q is already in src space when there is no |
| 302 | // perspective and dev coords otherwise. |
bsalomon@google.com | a996fec | 2011-09-13 18:49:13 +0000 | [diff] [blame] | 303 | pts[0] = q[0 + i]; |
| 304 | pts[1] = q[1 + i]; |
| 305 | pts[2] = q[2 + i]; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 306 | quadSubdivCnts->push_back() = subdiv; |
| 307 | totalQuadCount += 1 << subdiv; |
| 308 | } |
| 309 | } |
| 310 | } |
| 311 | } |
bsalomon@google.com | a51ab84 | 2012-07-10 19:53:34 +0000 | [diff] [blame] | 312 | break; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 313 | case kClose_PathCmd: |
| 314 | break; |
| 315 | case kEnd_PathCmd: |
| 316 | return totalQuadCount; |
| 317 | } |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | struct Vertex { |
| 322 | GrPoint fPos; |
| 323 | union { |
| 324 | struct { |
bsalomon@google.com | 8171288 | 2012-11-01 17:12:34 +0000 | [diff] [blame] | 325 | SkScalar fA; |
| 326 | SkScalar fB; |
| 327 | SkScalar fC; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 328 | } fLine; |
| 329 | GrVec fQuadCoord; |
| 330 | struct { |
bsalomon@google.com | 8171288 | 2012-11-01 17:12:34 +0000 | [diff] [blame] | 331 | SkScalar fBogus[4]; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 332 | }; |
| 333 | }; |
| 334 | }; |
| 335 | GR_STATIC_ASSERT(sizeof(Vertex) == 3 * sizeof(GrPoint)); |
| 336 | |
| 337 | void intersect_lines(const SkPoint& ptA, const SkVector& normA, |
| 338 | const SkPoint& ptB, const SkVector& normB, |
| 339 | SkPoint* result) { |
| 340 | |
| 341 | SkScalar lineAW = -normA.dot(ptA); |
| 342 | SkScalar lineBW = -normB.dot(ptB); |
| 343 | |
| 344 | SkScalar wInv = SkScalarMul(normA.fX, normB.fY) - |
| 345 | SkScalarMul(normA.fY, normB.fX); |
| 346 | wInv = SkScalarInvert(wInv); |
| 347 | |
| 348 | result->fX = SkScalarMul(normA.fY, lineBW) - SkScalarMul(lineAW, normB.fY); |
| 349 | result->fX = SkScalarMul(result->fX, wInv); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 350 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 351 | result->fY = SkScalarMul(lineAW, normB.fX) - SkScalarMul(normA.fX, lineBW); |
| 352 | result->fY = SkScalarMul(result->fY, wInv); |
| 353 | } |
| 354 | |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 355 | void bloat_quad(const SkPoint qpts[3], const GrMatrix* toDevice, |
| 356 | const GrMatrix* toSrc, Vertex verts[kVertsPerQuad]) { |
| 357 | GrAssert(!toDevice == !toSrc); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 358 | // original quad is specified by tri a,b,c |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 359 | SkPoint a = qpts[0]; |
| 360 | SkPoint b = qpts[1]; |
| 361 | SkPoint c = qpts[2]; |
| 362 | |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 363 | // 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] | 364 | GrPathUtils::QuadUVMatrix DevToUV(qpts); |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 365 | |
| 366 | if (toDevice) { |
| 367 | toDevice->mapPoints(&a, 1); |
| 368 | toDevice->mapPoints(&b, 1); |
| 369 | toDevice->mapPoints(&c, 1); |
| 370 | } |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 371 | // make a new poly where we replace a and c by a 1-pixel wide edges orthog |
| 372 | // to edges ab and bc: |
| 373 | // |
| 374 | // before | after |
| 375 | // | b0 |
| 376 | // b | |
| 377 | // | |
| 378 | // | a0 c0 |
| 379 | // a c | a1 c1 |
| 380 | // |
| 381 | // edges a0->b0 and b0->c0 are parallel to original edges a->b and b->c, |
| 382 | // respectively. |
| 383 | Vertex& a0 = verts[0]; |
| 384 | Vertex& a1 = verts[1]; |
| 385 | Vertex& b0 = verts[2]; |
| 386 | Vertex& c0 = verts[3]; |
| 387 | Vertex& c1 = verts[4]; |
| 388 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 389 | SkVector ab = b; |
| 390 | ab -= a; |
| 391 | SkVector ac = c; |
| 392 | ac -= a; |
| 393 | SkVector cb = b; |
| 394 | cb -= c; |
| 395 | |
| 396 | // We should have already handled degenerates |
| 397 | GrAssert(ab.length() > 0 && cb.length() > 0); |
| 398 | |
| 399 | ab.normalize(); |
| 400 | SkVector abN; |
| 401 | abN.setOrthog(ab, SkVector::kLeft_Side); |
| 402 | if (abN.dot(ac) > 0) { |
| 403 | abN.negate(); |
| 404 | } |
| 405 | |
| 406 | cb.normalize(); |
| 407 | SkVector cbN; |
| 408 | cbN.setOrthog(cb, SkVector::kLeft_Side); |
| 409 | if (cbN.dot(ac) < 0) { |
| 410 | cbN.negate(); |
| 411 | } |
| 412 | |
| 413 | a0.fPos = a; |
| 414 | a0.fPos += abN; |
| 415 | a1.fPos = a; |
| 416 | a1.fPos -= abN; |
| 417 | |
| 418 | c0.fPos = c; |
| 419 | c0.fPos += cbN; |
| 420 | c1.fPos = c; |
| 421 | c1.fPos -= cbN; |
| 422 | |
| 423 | intersect_lines(a0.fPos, abN, c0.fPos, cbN, &b0.fPos); |
| 424 | |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 425 | if (toSrc) { |
| 426 | toSrc->mapPointsWithStride(&verts[0].fPos, sizeof(Vertex), kVertsPerQuad); |
| 427 | } |
bsalomon@google.com | 1971317 | 2012-03-15 13:51:08 +0000 | [diff] [blame] | 428 | DevToUV.apply<kVertsPerQuad, sizeof(Vertex), sizeof(GrPoint)>(verts); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | void add_quads(const SkPoint p[3], |
| 432 | int subdiv, |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 433 | const GrMatrix* toDevice, |
| 434 | const GrMatrix* toSrc, |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 435 | Vertex** vert) { |
| 436 | GrAssert(subdiv >= 0); |
| 437 | if (subdiv) { |
| 438 | SkPoint newP[5]; |
| 439 | SkChopQuadAtHalf(p, newP); |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 440 | add_quads(newP + 0, subdiv-1, toDevice, toSrc, vert); |
| 441 | add_quads(newP + 2, subdiv-1, toDevice, toSrc, vert); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 442 | } else { |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 443 | bloat_quad(p, toDevice, toSrc, *vert); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 444 | *vert += kVertsPerQuad; |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | void add_line(const SkPoint p[2], |
| 449 | int rtHeight, |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 450 | const SkMatrix* toSrc, |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 451 | Vertex** vert) { |
| 452 | const SkPoint& a = p[0]; |
| 453 | const SkPoint& b = p[1]; |
| 454 | |
| 455 | SkVector orthVec = b; |
| 456 | orthVec -= a; |
| 457 | |
| 458 | if (orthVec.setLength(SK_Scalar1)) { |
| 459 | orthVec.setOrthog(orthVec); |
| 460 | |
bsalomon@google.com | 706f668 | 2012-10-23 14:53:55 +0000 | [diff] [blame] | 461 | SkScalar lineC = -(a.dot(orthVec)); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 462 | for (int i = 0; i < kVertsPerLineSeg; ++i) { |
| 463 | (*vert)[i].fPos = (i < 2) ? a : b; |
| 464 | if (0 == i || 3 == i) { |
| 465 | (*vert)[i].fPos -= orthVec; |
| 466 | } else { |
| 467 | (*vert)[i].fPos += orthVec; |
| 468 | } |
bsalomon@google.com | 706f668 | 2012-10-23 14:53:55 +0000 | [diff] [blame] | 469 | (*vert)[i].fLine.fA = orthVec.fX; |
| 470 | (*vert)[i].fLine.fB = orthVec.fY; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 471 | (*vert)[i].fLine.fC = lineC; |
| 472 | } |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 473 | if (NULL != toSrc) { |
| 474 | toSrc->mapPointsWithStride(&(*vert)->fPos, |
| 475 | sizeof(Vertex), |
| 476 | kVertsPerLineSeg); |
| 477 | } |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 478 | } else { |
| 479 | // just make it degenerate and likely offscreen |
| 480 | (*vert)[0].fPos.set(SK_ScalarMax, SK_ScalarMax); |
| 481 | (*vert)[1].fPos.set(SK_ScalarMax, SK_ScalarMax); |
| 482 | (*vert)[2].fPos.set(SK_ScalarMax, SK_ScalarMax); |
| 483 | (*vert)[3].fPos.set(SK_ScalarMax, SK_ScalarMax); |
| 484 | } |
| 485 | |
| 486 | *vert += kVertsPerLineSeg; |
| 487 | } |
| 488 | |
| 489 | } |
| 490 | |
bsalomon@google.com | b372942 | 2012-03-07 19:13:28 +0000 | [diff] [blame] | 491 | bool GrAAHairLinePathRenderer::createGeom( |
| 492 | const SkPath& path, |
bsalomon@google.com | b372942 | 2012-03-07 19:13:28 +0000 | [diff] [blame] | 493 | GrDrawTarget* target, |
bsalomon@google.com | b372942 | 2012-03-07 19:13:28 +0000 | [diff] [blame] | 494 | int* lineCnt, |
| 495 | int* quadCnt, |
| 496 | GrDrawTarget::AutoReleaseGeometry* arg) { |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 497 | const GrDrawState& drawState = target->getDrawState(); |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 498 | int rtHeight = drawState.getRenderTarget()->height(); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 499 | |
robertphillips@google.com | 7b11289 | 2012-07-31 15:18:21 +0000 | [diff] [blame] | 500 | GrIRect devClipBounds; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 501 | target->getClip()->getConservativeBounds(drawState.getRenderTarget(), |
robertphillips@google.com | 7b11289 | 2012-07-31 15:18:21 +0000 | [diff] [blame] | 502 | &devClipBounds); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 503 | |
| 504 | GrVertexLayout layout = GrDrawTarget::kEdge_VertexLayoutBit; |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 505 | GrMatrix viewM = drawState.getViewMatrix(); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 506 | |
bsalomon@google.com | 9266901 | 2011-09-27 19:10:05 +0000 | [diff] [blame] | 507 | PREALLOC_PTARRAY(128) lines; |
| 508 | PREALLOC_PTARRAY(128) quads; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 509 | IntArray qSubdivs; |
bsalomon@google.com | 0f11e1a | 2012-10-08 14:48:36 +0000 | [diff] [blame] | 510 | *quadCnt = generate_lines_and_quads(path, viewM, devClipBounds, |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 511 | &lines, &quads, &qSubdivs); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 512 | |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 513 | *lineCnt = lines.count() / 2; |
| 514 | int vertCnt = kVertsPerLineSeg * *lineCnt + kVertsPerQuad * *quadCnt; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 515 | |
| 516 | GrAssert(sizeof(Vertex) == GrDrawTarget::VertexSize(layout)); |
| 517 | |
bsalomon@google.com | b372942 | 2012-03-07 19:13:28 +0000 | [diff] [blame] | 518 | if (!arg->set(target, layout, vertCnt, 0)) { |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 519 | return false; |
| 520 | } |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 521 | |
bsalomon@google.com | b372942 | 2012-03-07 19:13:28 +0000 | [diff] [blame] | 522 | Vertex* verts = reinterpret_cast<Vertex*>(arg->vertices()); |
| 523 | |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 524 | const GrMatrix* toDevice = NULL; |
| 525 | const GrMatrix* toSrc = NULL; |
| 526 | GrMatrix ivm; |
| 527 | |
| 528 | if (viewM.hasPerspective()) { |
| 529 | if (viewM.invert(&ivm)) { |
| 530 | toDevice = &viewM; |
| 531 | toSrc = &ivm; |
| 532 | } |
| 533 | } |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 534 | |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 535 | for (int i = 0; i < *lineCnt; ++i) { |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 536 | add_line(&lines[2*i], rtHeight, toSrc, &verts); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 537 | } |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 538 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 539 | int unsubdivQuadCnt = quads.count() / 3; |
| 540 | for (int i = 0; i < unsubdivQuadCnt; ++i) { |
| 541 | GrAssert(qSubdivs[i] >= 0); |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 542 | add_quads(&quads[3*i], qSubdivs[i], toDevice, toSrc, &verts); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 543 | } |
| 544 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 545 | return true; |
| 546 | } |
| 547 | |
robertphillips@google.com | 8a4fc40 | 2012-05-24 12:42:24 +0000 | [diff] [blame] | 548 | bool GrAAHairLinePathRenderer::canDrawPath(const SkPath& path, |
| 549 | GrPathFill fill, |
| 550 | const GrDrawTarget* target, |
| 551 | bool antiAlias) const { |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 552 | if (fill != kHairLine_GrPathFill || !antiAlias) { |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 553 | return false; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 554 | } |
| 555 | |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 556 | static const uint32_t gReqDerivMask = SkPath::kCubic_SegmentMask | |
| 557 | SkPath::kQuad_SegmentMask; |
bsalomon@google.com | f660187 | 2012-08-28 21:11:35 +0000 | [diff] [blame] | 558 | if (!target->getCaps().shaderDerivativeSupport() && |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 559 | (gReqDerivMask & path.getSegmentMasks())) { |
| 560 | return false; |
| 561 | } |
| 562 | return true; |
| 563 | } |
| 564 | |
| 565 | bool GrAAHairLinePathRenderer::onDrawPath(const SkPath& path, |
| 566 | GrPathFill fill, |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 567 | GrDrawTarget* target, |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 568 | bool antiAlias) { |
| 569 | |
| 570 | int lineCnt; |
| 571 | int quadCnt; |
bsalomon@google.com | b372942 | 2012-03-07 19:13:28 +0000 | [diff] [blame] | 572 | GrDrawTarget::AutoReleaseGeometry arg; |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 573 | if (!this->createGeom(path, |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 574 | target, |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 575 | &lineCnt, |
bsalomon@google.com | b372942 | 2012-03-07 19:13:28 +0000 | [diff] [blame] | 576 | &quadCnt, |
| 577 | &arg)) { |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 578 | return false; |
| 579 | } |
| 580 | |
bsalomon@google.com | a834746 | 2012-10-08 18:59:39 +0000 | [diff] [blame] | 581 | GrDrawState::AutoDeviceCoordDraw adcd; |
bsalomon@google.com | 873ea0c | 2012-03-30 15:55:32 +0000 | [diff] [blame] | 582 | GrDrawState* drawState = target->drawState(); |
bsalomon@google.com | a834746 | 2012-10-08 18:59:39 +0000 | [diff] [blame] | 583 | // createGeom transforms the geometry to device space when the matrix does not have |
| 584 | // perspective. |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 585 | if (!drawState->getViewMatrix().hasPerspective()) { |
bsalomon@google.com | a834746 | 2012-10-08 18:59:39 +0000 | [diff] [blame] | 586 | adcd.set(drawState); |
| 587 | if (!adcd.succeeded()) { |
bsalomon@google.com | e3d3216 | 2012-07-20 13:37:06 +0000 | [diff] [blame] | 588 | return false; |
bsalomon@google.com | dbeeac3 | 2011-09-12 14:59:34 +0000 | [diff] [blame] | 589 | } |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 590 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 591 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 592 | // TODO: See whether rendering lines as degenerate quads improves perf |
| 593 | // when we have a mix |
bsalomon@google.com | a834746 | 2012-10-08 18:59:39 +0000 | [diff] [blame] | 594 | |
| 595 | GrDrawState::VertexEdgeType oldEdgeType = drawState->getVertexEdgeType(); |
| 596 | |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 597 | target->setIndexSourceToBuffer(fLinesIndexBuffer); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 598 | int lines = 0; |
| 599 | int nBufLines = fLinesIndexBuffer->maxQuads(); |
bsalomon@google.com | a834746 | 2012-10-08 18:59:39 +0000 | [diff] [blame] | 600 | drawState->setVertexEdgeType(GrDrawState::kHairLine_EdgeType); |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 601 | while (lines < lineCnt) { |
| 602 | int n = GrMin(lineCnt - lines, nBufLines); |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 603 | target->drawIndexed(kTriangles_GrPrimitiveType, |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 604 | kVertsPerLineSeg*lines, // startV |
| 605 | 0, // startI |
| 606 | kVertsPerLineSeg*n, // vCount |
| 607 | kIdxsPerLineSeg*n); // iCount |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 608 | lines += n; |
| 609 | } |
| 610 | |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 611 | target->setIndexSourceToBuffer(fQuadsIndexBuffer); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 612 | int quads = 0; |
bsalomon@google.com | a834746 | 2012-10-08 18:59:39 +0000 | [diff] [blame] | 613 | drawState->setVertexEdgeType(GrDrawState::kHairQuad_EdgeType); |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 614 | while (quads < quadCnt) { |
| 615 | int n = GrMin(quadCnt - quads, kNumQuadsInIdxBuffer); |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 616 | target->drawIndexed(kTriangles_GrPrimitiveType, |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 617 | 4 * lineCnt + kVertsPerQuad*quads, // startV |
| 618 | 0, // startI |
| 619 | kVertsPerQuad*n, // vCount |
| 620 | kIdxsPerQuad*n); // iCount |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 621 | quads += n; |
| 622 | } |
bsalomon@google.com | a834746 | 2012-10-08 18:59:39 +0000 | [diff] [blame] | 623 | drawState->setVertexEdgeType(oldEdgeType); |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 624 | return true; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 625 | } |
| 626 | |