blob: 72b3c60c2acd4df7a1cef4d5e88f12a5b961f631 [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.com7d72c452012-01-30 14:02:44 +0000153static inline bool single_pass_path(const GrPath& path, GrPathFill fill) {
bsalomon@google.com30085192011-08-19 15:42:31 +0000154#if STENCIL_OFF
155 return true;
156#else
bsalomon@google.com7d72c452012-01-30 14:02:44 +0000157 if (kEvenOdd_PathFill == fill || kWinding_PathFill == fill) {
158 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.
177 if (kHairLine_PathFill != fillType) {
178 *((*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,
192 int* indexCnt) {
bsalomon@google.com30085192011-08-19 15:42:31 +0000193 {
194 SK_TRACE_EVENT0("GrDefaultPathRenderer::createGeom");
195
196 GrScalar srcSpaceTolSqd = GrMul(srcSpaceTol, srcSpaceTol);
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000197 int contourCnt;
198 int maxPts = GrPathUtils::worstCasePointCount(path, &contourCnt,
bsalomon@google.com30085192011-08-19 15:42:31 +0000199 srcSpaceTol);
200
201 if (maxPts <= 0) {
202 return false;
203 }
204 if (maxPts > ((int)SK_MaxU16 + 1)) {
205 GrPrintf("Path not rendered, too many verts (%d)\n", maxPts);
206 return false;
207 }
208
209 GrVertexLayout layout = 0;
tomhudson@google.com93813632011-10-27 20:21:16 +0000210 for (int s = 0; s < GrDrawState::kNumStages; ++s) {
bsalomon@google.com39ee0ff2011-12-06 15:32:52 +0000211 if ((1 << s) & stageMask) {
bsalomon@google.com30085192011-08-19 15:42:31 +0000212 layout |= GrDrawTarget::StagePosAsTexCoordVertexLayoutBit(s);
213 }
214 }
215
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000216 bool indexed = contourCnt > 1;
bsalomon@google.com30085192011-08-19 15:42:31 +0000217
218 int maxIdxs = 0;
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000219 if (kHairLine_PathFill == fill) {
220 if (indexed) {
bsalomon@google.com30085192011-08-19 15:42:31 +0000221 maxIdxs = 2 * maxPts;
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000222 *primType = kLines_PrimitiveType;
bsalomon@google.com30085192011-08-19 15:42:31 +0000223 } else {
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000224 *primType = kLineStrip_PrimitiveType;
bsalomon@google.com30085192011-08-19 15:42:31 +0000225 }
226 } else {
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000227 if (indexed) {
bsalomon@google.com30085192011-08-19 15:42:31 +0000228 maxIdxs = 3 * maxPts;
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000229 *primType = kTriangles_PrimitiveType;
bsalomon@google.com30085192011-08-19 15:42:31 +0000230 } else {
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000231 *primType = kTriangleFan_PrimitiveType;
bsalomon@google.com30085192011-08-19 15:42:31 +0000232 }
233 }
234
235 GrPoint* base;
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000236 if (!target->reserveVertexSpace(layout, maxPts, (void**)&base)) {
bsalomon@google.com30085192011-08-19 15:42:31 +0000237 return false;
238 }
239 GrAssert(NULL != base);
240 GrPoint* vert = base;
241
242 uint16_t* idxBase = NULL;
243 uint16_t* idx = NULL;
244 uint16_t subpathIdxStart = 0;
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000245 if (indexed) {
246 if (!target->reserveIndexSpace(maxIdxs, (void**)&idxBase)) {
247 target->resetVertexSource();
bsalomon@google.com30085192011-08-19 15:42:31 +0000248 return false;
249 }
250 GrAssert(NULL != idxBase);
251 idx = idxBase;
252 }
253
bsalomon@google.com30085192011-08-19 15:42:31 +0000254 GrPoint pts[4];
255
256 bool first = true;
257 int subpath = 0;
258
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000259 SkPath::Iter iter(path, false);
bsalomon@google.com30085192011-08-19 15:42:31 +0000260
261 for (;;) {
262 GrPathCmd cmd = (GrPathCmd)iter.next(pts);
263 switch (cmd) {
264 case kMove_PathCmd:
265 if (!first) {
266 uint16_t currIdx = (uint16_t) (vert - base);
bsalomon@google.com30085192011-08-19 15:42:31 +0000267 subpathIdxStart = currIdx;
268 ++subpath;
269 }
270 *vert = pts[0];
271 vert++;
272 break;
273 case kLine_PathCmd:
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000274 if (indexed) {
bsalomon@google.com30085192011-08-19 15:42:31 +0000275 uint16_t prevIdx = (uint16_t)(vert - base) - 1;
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000276 append_countour_edge_indices(fill, subpathIdxStart,
bsalomon@google.com30085192011-08-19 15:42:31 +0000277 prevIdx, &idx);
278 }
279 *(vert++) = pts[1];
280 break;
281 case kQuadratic_PathCmd: {
282 // first pt of quad is the pt we ended on in previous step
283 uint16_t firstQPtIdx = (uint16_t)(vert - base) - 1;
284 uint16_t numPts = (uint16_t)
285 GrPathUtils::generateQuadraticPoints(
286 pts[0], pts[1], pts[2],
287 srcSpaceTolSqd, &vert,
288 GrPathUtils::quadraticPointCount(pts, srcSpaceTol));
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000289 if (indexed) {
bsalomon@google.com30085192011-08-19 15:42:31 +0000290 for (uint16_t i = 0; i < numPts; ++i) {
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000291 append_countour_edge_indices(fill, subpathIdxStart,
bsalomon@google.com30085192011-08-19 15:42:31 +0000292 firstQPtIdx + i, &idx);
293 }
294 }
295 break;
296 }
297 case kCubic_PathCmd: {
298 // first pt of cubic is the pt we ended on in previous step
299 uint16_t firstCPtIdx = (uint16_t)(vert - base) - 1;
300 uint16_t numPts = (uint16_t) GrPathUtils::generateCubicPoints(
301 pts[0], pts[1], pts[2], pts[3],
302 srcSpaceTolSqd, &vert,
303 GrPathUtils::cubicPointCount(pts, srcSpaceTol));
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000304 if (indexed) {
bsalomon@google.com30085192011-08-19 15:42:31 +0000305 for (uint16_t i = 0; i < numPts; ++i) {
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000306 append_countour_edge_indices(fill, subpathIdxStart,
bsalomon@google.com30085192011-08-19 15:42:31 +0000307 firstCPtIdx + i, &idx);
308 }
309 }
310 break;
311 }
312 case kClose_PathCmd:
313 break;
314 case kEnd_PathCmd:
315 uint16_t currIdx = (uint16_t) (vert - base);
bsalomon@google.com30085192011-08-19 15:42:31 +0000316 goto FINISHED;
317 }
318 first = false;
319 }
320FINISHED:
321 GrAssert((vert - base) <= maxPts);
322 GrAssert((idx - idxBase) <= maxIdxs);
323
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000324 *vertexCnt = vert - base;
325 *indexCnt = idx - idxBase;
bsalomon@google.com30085192011-08-19 15:42:31 +0000326
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000327 if (NULL != translate &&
328 (translate->fX || translate->fY)) {
bsalomon@google.com30085192011-08-19 15:42:31 +0000329 int count = vert - base;
330 for (int i = 0; i < count; i++) {
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000331 base[i].offset(translate->fX, translate->fY);
bsalomon@google.com30085192011-08-19 15:42:31 +0000332 }
333 }
334 }
bsalomon@google.com30085192011-08-19 15:42:31 +0000335 return true;
336}
337
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000338bool GrDefaultPathRenderer::internalDrawPath(const SkPath& path,
339 GrPathFill fill,
340 const GrVec* translate,
341 GrDrawTarget* target,
342 GrDrawState::StageMask stageMask,
343 bool stencilOnly) {
bsalomon@google.com30085192011-08-19 15:42:31 +0000344
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000345 GrMatrix viewM = target->getDrawState().getViewMatrix();
bsalomon@google.com181e9bd2011-09-07 18:42:30 +0000346 GrScalar tol = GR_Scalar1;
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000347 tol = GrPathUtils::scaleToleranceToSrc(tol, viewM, path.getBounds());
348 GrDrawState* drawState = target->drawState();
bsalomon@google.com30085192011-08-19 15:42:31 +0000349
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000350 int vertexCnt;
351 int indexCnt;
352 GrPrimitiveType primType;
353 if (!this->createGeom(path,
354 fill,
355 translate,
356 tol,
357 target,
358 stageMask,
359 &primType,
360 &vertexCnt,
361 &indexCnt)) {
362 return false;
bsalomon@google.com30085192011-08-19 15:42:31 +0000363 }
364
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000365 GrAssert(NULL != target);
366 GrDrawTarget::AutoStateRestore asr(target);
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000367 bool colorWritesWereDisabled = drawState->isColorWriteDisabled();
bsalomon@google.com30085192011-08-19 15:42:31 +0000368 // face culling doesn't make sense here
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000369 GrAssert(GrDrawState::kBoth_DrawFace == drawState->getDrawFace());
bsalomon@google.com30085192011-08-19 15:42:31 +0000370
371 int passCount = 0;
372 const GrStencilSettings* passes[3];
tomhudson@google.com93813632011-10-27 20:21:16 +0000373 GrDrawState::DrawFace drawFace[3];
bsalomon@google.com30085192011-08-19 15:42:31 +0000374 bool reverse = false;
375 bool lastPassIsBounds;
376
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000377 if (kHairLine_PathFill == fill) {
bsalomon@google.com30085192011-08-19 15:42:31 +0000378 passCount = 1;
379 if (stencilOnly) {
380 passes[0] = &gDirectToStencil;
381 } else {
382 passes[0] = NULL;
383 }
384 lastPassIsBounds = false;
tomhudson@google.com93813632011-10-27 20:21:16 +0000385 drawFace[0] = GrDrawState::kBoth_DrawFace;
bsalomon@google.com30085192011-08-19 15:42:31 +0000386 } else {
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000387 if (single_pass_path(path, fill)) {
bsalomon@google.com30085192011-08-19 15:42:31 +0000388 passCount = 1;
389 if (stencilOnly) {
390 passes[0] = &gDirectToStencil;
391 } else {
392 passes[0] = NULL;
393 }
tomhudson@google.com93813632011-10-27 20:21:16 +0000394 drawFace[0] = GrDrawState::kBoth_DrawFace;
bsalomon@google.com30085192011-08-19 15:42:31 +0000395 lastPassIsBounds = false;
396 } else {
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000397 switch (fill) {
bsalomon@google.com30085192011-08-19 15:42:31 +0000398 case kInverseEvenOdd_PathFill:
399 reverse = true;
400 // fallthrough
401 case kEvenOdd_PathFill:
402 passes[0] = &gEOStencilPass;
403 if (stencilOnly) {
404 passCount = 1;
405 lastPassIsBounds = false;
406 } else {
407 passCount = 2;
408 lastPassIsBounds = true;
409 if (reverse) {
410 passes[1] = &gInvEOColorPass;
411 } else {
412 passes[1] = &gEOColorPass;
413 }
414 }
tomhudson@google.com93813632011-10-27 20:21:16 +0000415 drawFace[0] = drawFace[1] = GrDrawState::kBoth_DrawFace;
bsalomon@google.com30085192011-08-19 15:42:31 +0000416 break;
417
418 case kInverseWinding_PathFill:
419 reverse = true;
420 // fallthrough
421 case kWinding_PathFill:
422 if (fSeparateStencil) {
423 if (fStencilWrapOps) {
424 passes[0] = &gWindStencilSeparateWithWrap;
425 } else {
426 passes[0] = &gWindStencilSeparateNoWrap;
427 }
428 passCount = 2;
tomhudson@google.com93813632011-10-27 20:21:16 +0000429 drawFace[0] = GrDrawState::kBoth_DrawFace;
bsalomon@google.com30085192011-08-19 15:42:31 +0000430 } else {
431 if (fStencilWrapOps) {
432 passes[0] = &gWindSingleStencilWithWrapInc;
433 passes[1] = &gWindSingleStencilWithWrapDec;
434 } else {
435 passes[0] = &gWindSingleStencilNoWrapInc;
436 passes[1] = &gWindSingleStencilNoWrapDec;
437 }
438 // which is cw and which is ccw is arbitrary.
tomhudson@google.com93813632011-10-27 20:21:16 +0000439 drawFace[0] = GrDrawState::kCW_DrawFace;
440 drawFace[1] = GrDrawState::kCCW_DrawFace;
bsalomon@google.com30085192011-08-19 15:42:31 +0000441 passCount = 3;
442 }
443 if (stencilOnly) {
444 lastPassIsBounds = false;
445 --passCount;
446 } else {
447 lastPassIsBounds = true;
tomhudson@google.com93813632011-10-27 20:21:16 +0000448 drawFace[passCount-1] = GrDrawState::kBoth_DrawFace;
bsalomon@google.com30085192011-08-19 15:42:31 +0000449 if (reverse) {
450 passes[passCount-1] = &gInvWindColorPass;
451 } else {
452 passes[passCount-1] = &gWindColorPass;
453 }
454 }
455 break;
456 default:
457 GrAssert(!"Unknown path fFill!");
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000458 return false;
bsalomon@google.com30085192011-08-19 15:42:31 +0000459 }
460 }
461 }
462
463 {
bsalomon@google.com30085192011-08-19 15:42:31 +0000464 for (int p = 0; p < passCount; ++p) {
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000465 drawState->setDrawFace(drawFace[p]);
bsalomon@google.com30085192011-08-19 15:42:31 +0000466 if (NULL != passes[p]) {
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000467 *drawState->stencil() = *passes[p];
bsalomon@google.com30085192011-08-19 15:42:31 +0000468 }
469
470 if (lastPassIsBounds && (p == passCount-1)) {
471 if (!colorWritesWereDisabled) {
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000472 drawState->disableState(GrDrawState::kNoColorWrites_StateBit);
bsalomon@google.com30085192011-08-19 15:42:31 +0000473 }
474 GrRect bounds;
475 if (reverse) {
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000476 GrAssert(NULL != drawState->getRenderTarget());
bsalomon@google.com30085192011-08-19 15:42:31 +0000477 // draw over the whole world.
478 bounds.setLTRB(0, 0,
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000479 GrIntToScalar(drawState->getRenderTarget()->width()),
480 GrIntToScalar(drawState->getRenderTarget()->height()));
bsalomon@google.com30085192011-08-19 15:42:31 +0000481 GrMatrix vmi;
bsalomon@google.com8c2fe992011-09-13 15:27:18 +0000482 // mapRect through persp matrix may not be correct
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000483 if (!drawState->getViewMatrix().hasPerspective() &&
484 drawState->getViewInverse(&vmi)) {
bsalomon@google.com30085192011-08-19 15:42:31 +0000485 vmi.mapRect(&bounds);
bsalomon@google.com8c2fe992011-09-13 15:27:18 +0000486 } else {
bsalomon@google.com39ee0ff2011-12-06 15:32:52 +0000487 if (stageMask) {
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000488 if (!drawState->getViewInverse(&vmi)) {
bsalomon@google.com8c2fe992011-09-13 15:27:18 +0000489 GrPrintf("Could not invert matrix.");
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000490 return false;
bsalomon@google.com8c2fe992011-09-13 15:27:18 +0000491 }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000492 drawState->preConcatSamplerMatrices(stageMask, vmi);
bsalomon@google.com8c2fe992011-09-13 15:27:18 +0000493 }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000494 drawState->setViewMatrix(GrMatrix::I());
bsalomon@google.com30085192011-08-19 15:42:31 +0000495 }
496 } else {
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000497 bounds = path.getBounds();
498 if (NULL != translate) {
499 bounds.offset(*translate);
500 }
bsalomon@google.com30085192011-08-19 15:42:31 +0000501 }
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000502 GrDrawTarget::AutoGeometryPush agp(target);
503 target->drawSimpleRect(bounds, NULL, stageMask);
bsalomon@google.com30085192011-08-19 15:42:31 +0000504 } else {
505 if (passCount > 1) {
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000506 drawState->enableState(GrDrawState::kNoColorWrites_StateBit);
bsalomon@google.com30085192011-08-19 15:42:31 +0000507 }
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000508 if (indexCnt) {
509 target->drawIndexed(primType, 0, 0,
510 vertexCnt, indexCnt);
bsalomon@google.com30085192011-08-19 15:42:31 +0000511 } else {
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000512 target->drawNonIndexed(primType, 0, vertexCnt);
bsalomon@google.com30085192011-08-19 15:42:31 +0000513 }
514 }
515 }
516 }
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000517 return true;
bsalomon@google.com30085192011-08-19 15:42:31 +0000518}
519
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000520bool GrDefaultPathRenderer::canDrawPath(const SkPath& path,
521 GrPathFill fill,
522 const GrDrawTarget* target,
523 bool antiAlias) const {
524 // this class can draw any path with any fill but doesn't do any
525 // anti-aliasing.
526 return !antiAlias;
bsalomon@google.com30085192011-08-19 15:42:31 +0000527}
528
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000529bool GrDefaultPathRenderer::onDrawPath(const SkPath& path,
530 GrPathFill fill,
531 const GrVec* translate,
532 GrDrawTarget* target,
533 GrDrawState::StageMask stageMask,
534 bool antiAlias) {
535 return this->internalDrawPath(path,
536 fill,
537 translate,
538 target,
539 stageMask,
540 false);
541}
542
543void GrDefaultPathRenderer::drawPathToStencil(const SkPath& path,
544 GrPathFill fill,
545 GrDrawTarget* target) {
546 GrAssert(kInverseEvenOdd_PathFill != fill);
547 GrAssert(kInverseWinding_PathFill != fill);
548 this->internalDrawPath(path, fill, NULL, target, 0, true);
bsalomon@google.com30085192011-08-19 15:42:31 +0000549}