blob: 17363db5609d2be964126d4941957fc28672137b [file] [log] [blame]
bsalomon@google.com30085192011-08-19 15:42:31 +00001
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
9#include "GrDefaultPathRenderer.h"
10
11#include "GrContext.h"
tomhudson@google.com93813632011-10-27 20:21:16 +000012#include "GrDrawState.h"
bsalomon@google.com30085192011-08-19 15:42:31 +000013#include "GrPathUtils.h"
tomhudson@google.comdd5f7442011-08-30 15:13:55 +000014#include "SkString.h"
bsalomon@google.com30085192011-08-19 15:42:31 +000015#include "SkTrace.h"
16
17
18GrDefaultPathRenderer::GrDefaultPathRenderer(bool separateStencilSupport,
19 bool stencilWrapOpsSupport)
20 : fSeparateStencil(separateStencilSupport)
bsalomon@google.comc2099d22012-03-02 21:26:50 +000021 , fStencilWrapOps(stencilWrapOpsSupport) {
bsalomon@google.com289533a2011-10-27 12:34:25 +000022}
23
24
bsalomon@google.com30085192011-08-19 15:42:31 +000025////////////////////////////////////////////////////////////////////////////////
26// Stencil rules for paths
27
28////// Even/Odd
29
bsalomon@google.com6b2445e2011-12-15 19:47:46 +000030GR_STATIC_CONST_SAME_STENCIL(gEOStencilPass,
31 kInvert_StencilOp,
32 kKeep_StencilOp,
33 kAlwaysIfInClip_StencilFunc,
34 0xffff,
35 0xffff,
36 0xffff);
bsalomon@google.com30085192011-08-19 15:42:31 +000037
38// ok not to check clip b/c stencil pass only wrote inside clip
bsalomon@google.com6b2445e2011-12-15 19:47:46 +000039GR_STATIC_CONST_SAME_STENCIL(gEOColorPass,
40 kZero_StencilOp,
41 kZero_StencilOp,
42 kNotEqual_StencilFunc,
43 0xffff,
44 0x0000,
45 0xffff);
bsalomon@google.com30085192011-08-19 15:42:31 +000046
47// have to check clip b/c outside clip will always be zero.
bsalomon@google.com6b2445e2011-12-15 19:47:46 +000048GR_STATIC_CONST_SAME_STENCIL(gInvEOColorPass,
49 kZero_StencilOp,
50 kZero_StencilOp,
51 kEqualIfInClip_StencilFunc,
52 0xffff,
53 0x0000,
54 0xffff);
bsalomon@google.com30085192011-08-19 15:42:31 +000055
56////// Winding
57
58// when we have separate stencil we increment front faces / decrement back faces
59// when we don't have wrap incr and decr we use the stencil test to simulate
60// them.
61
bsalomon@google.com6b2445e2011-12-15 19:47:46 +000062GR_STATIC_CONST_STENCIL(gWindStencilSeparateWithWrap,
bsalomon@google.com30085192011-08-19 15:42:31 +000063 kIncWrap_StencilOp, kDecWrap_StencilOp,
64 kKeep_StencilOp, kKeep_StencilOp,
65 kAlwaysIfInClip_StencilFunc, kAlwaysIfInClip_StencilFunc,
tomhudson@google.com62b09682011-11-09 16:39:17 +000066 0xffff, 0xffff,
67 0xffff, 0xffff,
bsalomon@google.com6b2445e2011-12-15 19:47:46 +000068 0xffff, 0xffff);
bsalomon@google.com30085192011-08-19 15:42:31 +000069
70// if inc'ing the max value, invert to make 0
71// if dec'ing zero invert to make all ones.
72// we can't avoid touching the stencil on both passing and
73// failing, so we can't resctrict ourselves to the clip.
bsalomon@google.com6b2445e2011-12-15 19:47:46 +000074GR_STATIC_CONST_STENCIL(gWindStencilSeparateNoWrap,
bsalomon@google.com30085192011-08-19 15:42:31 +000075 kInvert_StencilOp, kInvert_StencilOp,
76 kIncClamp_StencilOp, kDecClamp_StencilOp,
77 kEqual_StencilFunc, kEqual_StencilFunc,
tomhudson@google.com62b09682011-11-09 16:39:17 +000078 0xffff, 0xffff,
79 0xffff, 0x0000,
bsalomon@google.com6b2445e2011-12-15 19:47:46 +000080 0xffff, 0xffff);
bsalomon@google.com30085192011-08-19 15:42:31 +000081
82// When there are no separate faces we do two passes to setup the winding rule
83// stencil. First we draw the front faces and inc, then we draw the back faces
84// and dec. These are same as the above two split into the incrementing and
85// decrementing passes.
bsalomon@google.com6b2445e2011-12-15 19:47:46 +000086GR_STATIC_CONST_SAME_STENCIL(gWindSingleStencilWithWrapInc,
87 kIncWrap_StencilOp,
88 kKeep_StencilOp,
89 kAlwaysIfInClip_StencilFunc,
90 0xffff,
91 0xffff,
92 0xffff);
bsalomon@google.com30085192011-08-19 15:42:31 +000093
bsalomon@google.com6b2445e2011-12-15 19:47:46 +000094GR_STATIC_CONST_SAME_STENCIL(gWindSingleStencilWithWrapDec,
95 kDecWrap_StencilOp,
96 kKeep_StencilOp,
97 kAlwaysIfInClip_StencilFunc,
98 0xffff,
99 0xffff,
100 0xffff);
bsalomon@google.com30085192011-08-19 15:42:31 +0000101
bsalomon@google.com6b2445e2011-12-15 19:47:46 +0000102GR_STATIC_CONST_SAME_STENCIL(gWindSingleStencilNoWrapInc,
103 kInvert_StencilOp,
104 kIncClamp_StencilOp,
105 kEqual_StencilFunc,
106 0xffff,
107 0xffff,
108 0xffff);
109
110GR_STATIC_CONST_SAME_STENCIL(gWindSingleStencilNoWrapDec,
111 kInvert_StencilOp,
112 kDecClamp_StencilOp,
113 kEqual_StencilFunc,
114 0xffff,
115 0x0000,
116 0xffff);
117
118// Color passes are the same whether we use the two-sided stencil or two passes
119
120GR_STATIC_CONST_SAME_STENCIL(gWindColorPass,
121 kZero_StencilOp,
122 kZero_StencilOp,
123 kNonZeroIfInClip_StencilFunc,
124 0xffff,
125 0x0000,
126 0xffff);
127
128GR_STATIC_CONST_SAME_STENCIL(gInvWindColorPass,
129 kZero_StencilOp,
130 kZero_StencilOp,
131 kEqualIfInClip_StencilFunc,
132 0xffff,
133 0x0000,
134 0xffff);
bsalomon@google.com30085192011-08-19 15:42:31 +0000135
136////// Normal render to stencil
137
138// Sometimes the default path renderer can draw a path directly to the stencil
139// buffer without having to first resolve the interior / exterior.
bsalomon@google.com6b2445e2011-12-15 19:47:46 +0000140GR_STATIC_CONST_SAME_STENCIL(gDirectToStencil,
141 kZero_StencilOp,
142 kIncClamp_StencilOp,
143 kAlwaysIfInClip_StencilFunc,
144 0xffff,
145 0x0000,
146 0xffff);
bsalomon@google.com30085192011-08-19 15:42:31 +0000147
148////////////////////////////////////////////////////////////////////////////////
149// Helpers for drawPath
150
bsalomon@google.com30085192011-08-19 15:42:31 +0000151#define STENCIL_OFF 0 // Always disable stencil (even when needed)
152
bsalomon@google.com8d033a12012-04-27 15:52:53 +0000153static inline bool single_pass_path(const SkPath& path, GrPathFill fill) {
bsalomon@google.com30085192011-08-19 15:42:31 +0000154#if STENCIL_OFF
155 return true;
156#else
bsalomon@google.com47059542012-06-06 20:51:20 +0000157 if (kEvenOdd_GrPathFill == fill || kWinding_GrPathFill == fill) {
bsalomon@google.com7d72c452012-01-30 14:02:44 +0000158 return path.isConvex();
bsalomon@google.com30085192011-08-19 15:42:31 +0000159 }
160 return false;
161#endif
162}
163
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000164bool GrDefaultPathRenderer::requiresStencilPass(const SkPath& path,
165 GrPathFill fill,
166 const GrDrawTarget* target) const {
bsalomon@google.com7d72c452012-01-30 14:02:44 +0000167 return !single_pass_path(path, fill);
bsalomon@google.com30085192011-08-19 15:42:31 +0000168}
169
bsalomon@google.com30085192011-08-19 15:42:31 +0000170static inline void append_countour_edge_indices(GrPathFill fillType,
171 uint16_t fanCenterIdx,
172 uint16_t edgeV0Idx,
173 uint16_t** indices) {
174 // when drawing lines we're appending line segments along
175 // the contour. When applying the other fill rules we're
176 // drawing triangle fans around fanCenterIdx.
bsalomon@google.com47059542012-06-06 20:51:20 +0000177 if (kHairLine_GrPathFill != fillType) {
bsalomon@google.com30085192011-08-19 15:42:31 +0000178 *((*indices)++) = fanCenterIdx;
179 }
180 *((*indices)++) = edgeV0Idx;
181 *((*indices)++) = edgeV0Idx + 1;
182}
183
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000184bool GrDefaultPathRenderer::createGeom(const SkPath& path,
185 GrPathFill fill,
186 const GrVec* translate,
187 GrScalar srcSpaceTol,
188 GrDrawTarget* target,
189 GrDrawState::StageMask stageMask,
190 GrPrimitiveType* primType,
191 int* vertexCnt,
bsalomon@google.comb3729422012-03-07 19:13:28 +0000192 int* indexCnt,
193 GrDrawTarget::AutoReleaseGeometry* arg) {
bsalomon@google.com30085192011-08-19 15:42:31 +0000194 {
195 SK_TRACE_EVENT0("GrDefaultPathRenderer::createGeom");
196
197 GrScalar srcSpaceTolSqd = GrMul(srcSpaceTol, srcSpaceTol);
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000198 int contourCnt;
199 int maxPts = GrPathUtils::worstCasePointCount(path, &contourCnt,
bsalomon@google.com30085192011-08-19 15:42:31 +0000200 srcSpaceTol);
201
202 if (maxPts <= 0) {
203 return false;
204 }
205 if (maxPts > ((int)SK_MaxU16 + 1)) {
206 GrPrintf("Path not rendered, too many verts (%d)\n", maxPts);
207 return false;
208 }
209
210 GrVertexLayout layout = 0;
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000211 bool indexed = contourCnt > 1;
bsalomon@google.com30085192011-08-19 15:42:31 +0000212
213 int maxIdxs = 0;
bsalomon@google.com47059542012-06-06 20:51:20 +0000214 if (kHairLine_GrPathFill == fill) {
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000215 if (indexed) {
bsalomon@google.com30085192011-08-19 15:42:31 +0000216 maxIdxs = 2 * maxPts;
bsalomon@google.com47059542012-06-06 20:51:20 +0000217 *primType = kLines_GrPrimitiveType;
bsalomon@google.com30085192011-08-19 15:42:31 +0000218 } else {
bsalomon@google.com47059542012-06-06 20:51:20 +0000219 *primType = kLineStrip_GrPrimitiveType;
bsalomon@google.com30085192011-08-19 15:42:31 +0000220 }
221 } else {
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000222 if (indexed) {
bsalomon@google.com30085192011-08-19 15:42:31 +0000223 maxIdxs = 3 * maxPts;
bsalomon@google.com47059542012-06-06 20:51:20 +0000224 *primType = kTriangles_GrPrimitiveType;
bsalomon@google.com30085192011-08-19 15:42:31 +0000225 } else {
bsalomon@google.com47059542012-06-06 20:51:20 +0000226 *primType = kTriangleFan_GrPrimitiveType;
bsalomon@google.com30085192011-08-19 15:42:31 +0000227 }
228 }
229
bsalomon@google.comb3729422012-03-07 19:13:28 +0000230
231 if (!arg->set(target, layout, maxPts, maxIdxs)) {
bsalomon@google.com30085192011-08-19 15:42:31 +0000232 return false;
233 }
bsalomon@google.comb3729422012-03-07 19:13:28 +0000234
235 uint16_t* idxBase = reinterpret_cast<uint16_t*>(arg->indices());;
236 uint16_t* idx = idxBase;
237 uint16_t subpathIdxStart = 0;
238
239 GrPoint* base = reinterpret_cast<GrPoint*>(arg->vertices());
bsalomon@google.com30085192011-08-19 15:42:31 +0000240 GrAssert(NULL != base);
241 GrPoint* vert = base;
242
bsalomon@google.com30085192011-08-19 15:42:31 +0000243 GrPoint pts[4];
244
245 bool first = true;
246 int subpath = 0;
247
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000248 SkPath::Iter iter(path, false);
bsalomon@google.com30085192011-08-19 15:42:31 +0000249
250 for (;;) {
251 GrPathCmd cmd = (GrPathCmd)iter.next(pts);
252 switch (cmd) {
253 case kMove_PathCmd:
254 if (!first) {
255 uint16_t currIdx = (uint16_t) (vert - base);
bsalomon@google.com30085192011-08-19 15:42:31 +0000256 subpathIdxStart = currIdx;
257 ++subpath;
258 }
259 *vert = pts[0];
260 vert++;
261 break;
262 case kLine_PathCmd:
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000263 if (indexed) {
bsalomon@google.com30085192011-08-19 15:42:31 +0000264 uint16_t prevIdx = (uint16_t)(vert - base) - 1;
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000265 append_countour_edge_indices(fill, subpathIdxStart,
bsalomon@google.com30085192011-08-19 15:42:31 +0000266 prevIdx, &idx);
267 }
268 *(vert++) = pts[1];
269 break;
270 case kQuadratic_PathCmd: {
271 // first pt of quad is the pt we ended on in previous step
272 uint16_t firstQPtIdx = (uint16_t)(vert - base) - 1;
273 uint16_t numPts = (uint16_t)
274 GrPathUtils::generateQuadraticPoints(
275 pts[0], pts[1], pts[2],
276 srcSpaceTolSqd, &vert,
277 GrPathUtils::quadraticPointCount(pts, srcSpaceTol));
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000278 if (indexed) {
bsalomon@google.com30085192011-08-19 15:42:31 +0000279 for (uint16_t i = 0; i < numPts; ++i) {
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000280 append_countour_edge_indices(fill, subpathIdxStart,
bsalomon@google.com30085192011-08-19 15:42:31 +0000281 firstQPtIdx + i, &idx);
282 }
283 }
284 break;
285 }
286 case kCubic_PathCmd: {
287 // first pt of cubic is the pt we ended on in previous step
288 uint16_t firstCPtIdx = (uint16_t)(vert - base) - 1;
289 uint16_t numPts = (uint16_t) GrPathUtils::generateCubicPoints(
290 pts[0], pts[1], pts[2], pts[3],
291 srcSpaceTolSqd, &vert,
292 GrPathUtils::cubicPointCount(pts, srcSpaceTol));
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000293 if (indexed) {
bsalomon@google.com30085192011-08-19 15:42:31 +0000294 for (uint16_t i = 0; i < numPts; ++i) {
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000295 append_countour_edge_indices(fill, subpathIdxStart,
bsalomon@google.com30085192011-08-19 15:42:31 +0000296 firstCPtIdx + i, &idx);
297 }
298 }
299 break;
300 }
301 case kClose_PathCmd:
302 break;
303 case kEnd_PathCmd:
caryclark@google.comcf6285b2012-06-06 12:09:01 +0000304 // uint16_t currIdx = (uint16_t) (vert - base);
bsalomon@google.com30085192011-08-19 15:42:31 +0000305 goto FINISHED;
306 }
307 first = false;
308 }
309FINISHED:
310 GrAssert((vert - base) <= maxPts);
311 GrAssert((idx - idxBase) <= maxIdxs);
312
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000313 *vertexCnt = vert - base;
314 *indexCnt = idx - idxBase;
bsalomon@google.com30085192011-08-19 15:42:31 +0000315
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000316 if (NULL != translate &&
317 (translate->fX || translate->fY)) {
bsalomon@google.com30085192011-08-19 15:42:31 +0000318 int count = vert - base;
319 for (int i = 0; i < count; i++) {
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000320 base[i].offset(translate->fX, translate->fY);
bsalomon@google.com30085192011-08-19 15:42:31 +0000321 }
322 }
323 }
bsalomon@google.com30085192011-08-19 15:42:31 +0000324 return true;
325}
326
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000327bool GrDefaultPathRenderer::internalDrawPath(const SkPath& path,
328 GrPathFill fill,
329 const GrVec* translate,
330 GrDrawTarget* target,
331 GrDrawState::StageMask stageMask,
332 bool stencilOnly) {
bsalomon@google.com30085192011-08-19 15:42:31 +0000333
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000334 GrMatrix viewM = target->getDrawState().getViewMatrix();
bsalomon@google.com181e9bd2011-09-07 18:42:30 +0000335 GrScalar tol = GR_Scalar1;
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000336 tol = GrPathUtils::scaleToleranceToSrc(tol, viewM, path.getBounds());
bsalomon@google.com30085192011-08-19 15:42:31 +0000337
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000338 int vertexCnt;
339 int indexCnt;
340 GrPrimitiveType primType;
bsalomon@google.comb3729422012-03-07 19:13:28 +0000341 GrDrawTarget::AutoReleaseGeometry arg;
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000342 if (!this->createGeom(path,
343 fill,
344 translate,
345 tol,
346 target,
347 stageMask,
348 &primType,
349 &vertexCnt,
bsalomon@google.comb3729422012-03-07 19:13:28 +0000350 &indexCnt,
351 &arg)) {
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000352 return false;
bsalomon@google.com30085192011-08-19 15:42:31 +0000353 }
354
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000355 GrAssert(NULL != target);
bsalomon@google.com873ea0c2012-03-30 15:55:32 +0000356 GrDrawTarget::AutoStateRestore asr(target, GrDrawTarget::kPreserve_ASRInit);
357 GrDrawState* drawState = target->drawState();
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000358 bool colorWritesWereDisabled = drawState->isColorWriteDisabled();
bsalomon@google.com30085192011-08-19 15:42:31 +0000359 // face culling doesn't make sense here
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000360 GrAssert(GrDrawState::kBoth_DrawFace == drawState->getDrawFace());
bsalomon@google.com30085192011-08-19 15:42:31 +0000361
362 int passCount = 0;
363 const GrStencilSettings* passes[3];
tomhudson@google.com93813632011-10-27 20:21:16 +0000364 GrDrawState::DrawFace drawFace[3];
bsalomon@google.com30085192011-08-19 15:42:31 +0000365 bool reverse = false;
366 bool lastPassIsBounds;
367
bsalomon@google.com47059542012-06-06 20:51:20 +0000368 if (kHairLine_GrPathFill == fill) {
bsalomon@google.com30085192011-08-19 15:42:31 +0000369 passCount = 1;
370 if (stencilOnly) {
371 passes[0] = &gDirectToStencil;
372 } else {
373 passes[0] = NULL;
374 }
375 lastPassIsBounds = false;
tomhudson@google.com93813632011-10-27 20:21:16 +0000376 drawFace[0] = GrDrawState::kBoth_DrawFace;
bsalomon@google.com30085192011-08-19 15:42:31 +0000377 } else {
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000378 if (single_pass_path(path, fill)) {
bsalomon@google.com30085192011-08-19 15:42:31 +0000379 passCount = 1;
380 if (stencilOnly) {
381 passes[0] = &gDirectToStencil;
382 } else {
383 passes[0] = NULL;
384 }
tomhudson@google.com93813632011-10-27 20:21:16 +0000385 drawFace[0] = GrDrawState::kBoth_DrawFace;
bsalomon@google.com30085192011-08-19 15:42:31 +0000386 lastPassIsBounds = false;
387 } else {
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000388 switch (fill) {
bsalomon@google.com47059542012-06-06 20:51:20 +0000389 case kInverseEvenOdd_GrPathFill:
bsalomon@google.com30085192011-08-19 15:42:31 +0000390 reverse = true;
391 // fallthrough
bsalomon@google.com47059542012-06-06 20:51:20 +0000392 case kEvenOdd_GrPathFill:
bsalomon@google.com30085192011-08-19 15:42:31 +0000393 passes[0] = &gEOStencilPass;
394 if (stencilOnly) {
395 passCount = 1;
396 lastPassIsBounds = false;
397 } else {
398 passCount = 2;
399 lastPassIsBounds = true;
400 if (reverse) {
401 passes[1] = &gInvEOColorPass;
402 } else {
403 passes[1] = &gEOColorPass;
404 }
405 }
tomhudson@google.com93813632011-10-27 20:21:16 +0000406 drawFace[0] = drawFace[1] = GrDrawState::kBoth_DrawFace;
bsalomon@google.com30085192011-08-19 15:42:31 +0000407 break;
408
bsalomon@google.com47059542012-06-06 20:51:20 +0000409 case kInverseWinding_GrPathFill:
bsalomon@google.com30085192011-08-19 15:42:31 +0000410 reverse = true;
411 // fallthrough
bsalomon@google.com47059542012-06-06 20:51:20 +0000412 case kWinding_GrPathFill:
bsalomon@google.com30085192011-08-19 15:42:31 +0000413 if (fSeparateStencil) {
414 if (fStencilWrapOps) {
415 passes[0] = &gWindStencilSeparateWithWrap;
416 } else {
417 passes[0] = &gWindStencilSeparateNoWrap;
418 }
419 passCount = 2;
tomhudson@google.com93813632011-10-27 20:21:16 +0000420 drawFace[0] = GrDrawState::kBoth_DrawFace;
bsalomon@google.com30085192011-08-19 15:42:31 +0000421 } else {
422 if (fStencilWrapOps) {
423 passes[0] = &gWindSingleStencilWithWrapInc;
424 passes[1] = &gWindSingleStencilWithWrapDec;
425 } else {
426 passes[0] = &gWindSingleStencilNoWrapInc;
427 passes[1] = &gWindSingleStencilNoWrapDec;
428 }
429 // which is cw and which is ccw is arbitrary.
tomhudson@google.com93813632011-10-27 20:21:16 +0000430 drawFace[0] = GrDrawState::kCW_DrawFace;
431 drawFace[1] = GrDrawState::kCCW_DrawFace;
bsalomon@google.com30085192011-08-19 15:42:31 +0000432 passCount = 3;
433 }
434 if (stencilOnly) {
435 lastPassIsBounds = false;
436 --passCount;
437 } else {
438 lastPassIsBounds = true;
tomhudson@google.com93813632011-10-27 20:21:16 +0000439 drawFace[passCount-1] = GrDrawState::kBoth_DrawFace;
bsalomon@google.com30085192011-08-19 15:42:31 +0000440 if (reverse) {
441 passes[passCount-1] = &gInvWindColorPass;
442 } else {
443 passes[passCount-1] = &gWindColorPass;
444 }
445 }
446 break;
447 default:
448 GrAssert(!"Unknown path fFill!");
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000449 return false;
bsalomon@google.com30085192011-08-19 15:42:31 +0000450 }
451 }
452 }
453
454 {
bsalomon@google.com30085192011-08-19 15:42:31 +0000455 for (int p = 0; p < passCount; ++p) {
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000456 drawState->setDrawFace(drawFace[p]);
bsalomon@google.com30085192011-08-19 15:42:31 +0000457 if (NULL != passes[p]) {
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000458 *drawState->stencil() = *passes[p];
bsalomon@google.com30085192011-08-19 15:42:31 +0000459 }
460
461 if (lastPassIsBounds && (p == passCount-1)) {
462 if (!colorWritesWereDisabled) {
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000463 drawState->disableState(GrDrawState::kNoColorWrites_StateBit);
bsalomon@google.com30085192011-08-19 15:42:31 +0000464 }
465 GrRect bounds;
466 if (reverse) {
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000467 GrAssert(NULL != drawState->getRenderTarget());
bsalomon@google.com30085192011-08-19 15:42:31 +0000468 // draw over the whole world.
469 bounds.setLTRB(0, 0,
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000470 GrIntToScalar(drawState->getRenderTarget()->width()),
471 GrIntToScalar(drawState->getRenderTarget()->height()));
bsalomon@google.com30085192011-08-19 15:42:31 +0000472 GrMatrix vmi;
bsalomon@google.com8c2fe992011-09-13 15:27:18 +0000473 // mapRect through persp matrix may not be correct
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000474 if (!drawState->getViewMatrix().hasPerspective() &&
475 drawState->getViewInverse(&vmi)) {
bsalomon@google.com30085192011-08-19 15:42:31 +0000476 vmi.mapRect(&bounds);
bsalomon@google.com8c2fe992011-09-13 15:27:18 +0000477 } else {
bsalomon@google.com39ee0ff2011-12-06 15:32:52 +0000478 if (stageMask) {
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000479 if (!drawState->getViewInverse(&vmi)) {
bsalomon@google.com8c2fe992011-09-13 15:27:18 +0000480 GrPrintf("Could not invert matrix.");
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000481 return false;
bsalomon@google.com8c2fe992011-09-13 15:27:18 +0000482 }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000483 drawState->preConcatSamplerMatrices(stageMask, vmi);
bsalomon@google.com8c2fe992011-09-13 15:27:18 +0000484 }
bsalomon@google.comb3e40c02012-03-20 15:36:32 +0000485 drawState->viewMatrix()->reset();
bsalomon@google.com30085192011-08-19 15:42:31 +0000486 }
487 } else {
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000488 bounds = path.getBounds();
489 if (NULL != translate) {
490 bounds.offset(*translate);
491 }
bsalomon@google.com30085192011-08-19 15:42:31 +0000492 }
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000493 GrDrawTarget::AutoGeometryPush agp(target);
494 target->drawSimpleRect(bounds, NULL, stageMask);
bsalomon@google.com30085192011-08-19 15:42:31 +0000495 } else {
496 if (passCount > 1) {
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000497 drawState->enableState(GrDrawState::kNoColorWrites_StateBit);
bsalomon@google.com30085192011-08-19 15:42:31 +0000498 }
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000499 if (indexCnt) {
500 target->drawIndexed(primType, 0, 0,
501 vertexCnt, indexCnt);
bsalomon@google.com30085192011-08-19 15:42:31 +0000502 } else {
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000503 target->drawNonIndexed(primType, 0, vertexCnt);
bsalomon@google.com30085192011-08-19 15:42:31 +0000504 }
505 }
506 }
507 }
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000508 return true;
bsalomon@google.com30085192011-08-19 15:42:31 +0000509}
510
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000511bool GrDefaultPathRenderer::canDrawPath(const SkPath& path,
512 GrPathFill fill,
513 const GrDrawTarget* target,
514 bool antiAlias) const {
515 // this class can draw any path with any fill but doesn't do any
516 // anti-aliasing.
517 return !antiAlias;
bsalomon@google.com30085192011-08-19 15:42:31 +0000518}
519
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000520bool GrDefaultPathRenderer::onDrawPath(const SkPath& path,
521 GrPathFill fill,
522 const GrVec* translate,
523 GrDrawTarget* target,
524 GrDrawState::StageMask stageMask,
525 bool antiAlias) {
526 return this->internalDrawPath(path,
527 fill,
528 translate,
529 target,
530 stageMask,
531 false);
532}
533
534void GrDefaultPathRenderer::drawPathToStencil(const SkPath& path,
535 GrPathFill fill,
536 GrDrawTarget* target) {
bsalomon@google.com47059542012-06-06 20:51:20 +0000537 GrAssert(kInverseEvenOdd_GrPathFill != fill);
538 GrAssert(kInverseWinding_GrPathFill != fill);
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000539 this->internalDrawPath(path, fill, NULL, target, 0, true);
bsalomon@google.com30085192011-08-19 15:42:31 +0000540}