Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Side by Side Diff: src/gpu/GrStencilAndCoverPathRenderer.cpp

Issue 22686002: Implement path cover with nv_path_rendering (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebase Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2012 Google Inc. 3 * Copyright 2012 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "GrStencilAndCoverPathRenderer.h" 10 #include "GrStencilAndCoverPathRenderer.h"
11 #include "GrContext.h" 11 #include "GrContext.h"
12 #include "GrDrawTargetCaps.h" 12 #include "GrDrawTargetCaps.h"
13 #include "GrGpu.h" 13 #include "GrGpu.h"
14 #include "GrPath.h" 14 #include "GrPath.h"
15 #include "SkStrokeRec.h" 15 #include "SkStrokeRec.h"
16 16
17 GrPathRenderer* GrStencilAndCoverPathRenderer::Create(GrContext* context) { 17 GrPathRenderer* GrStencilAndCoverPathRenderer::Create(GrContext* context) {
18 SkASSERT(NULL != context); 18 SkASSERT(NULL != context);
19 SkASSERT(NULL != context->getGpu()); 19 SkASSERT(NULL != context->getGpu());
20 if (context->getGpu()->caps()->pathStencilingSupport()) { 20 if (context->getGpu()->caps()->pathRenderingSupport()) {
21 return SkNEW_ARGS(GrStencilAndCoverPathRenderer, (context->getGpu())); 21 return SkNEW_ARGS(GrStencilAndCoverPathRenderer, (context->getGpu()));
22 } else { 22 } else {
23 return NULL; 23 return NULL;
24 } 24 }
25 } 25 }
26 26
27 GrStencilAndCoverPathRenderer::GrStencilAndCoverPathRenderer(GrGpu* gpu) { 27 GrStencilAndCoverPathRenderer::GrStencilAndCoverPathRenderer(GrGpu* gpu) {
28 SkASSERT(gpu->caps()->pathStencilingSupport()); 28 SkASSERT(gpu->caps()->pathRenderingSupport());
29 fGpu = gpu; 29 fGpu = gpu;
30 gpu->ref(); 30 gpu->ref();
31 } 31 }
32 32
33 GrStencilAndCoverPathRenderer::~GrStencilAndCoverPathRenderer() { 33 GrStencilAndCoverPathRenderer::~GrStencilAndCoverPathRenderer() {
34 fGpu->unref(); 34 fGpu->unref();
35 } 35 }
36 36
37 bool GrStencilAndCoverPathRenderer::canDrawPath(const SkPath& path, 37 bool GrStencilAndCoverPathRenderer::canDrawPath(const SkPath& path,
38 const SkStrokeRec& stroke, 38 const SkStrokeRec& stroke,
39 const GrDrawTarget* target, 39 const GrDrawTarget* target,
40 bool antiAlias) const { 40 bool antiAlias) const {
41 return stroke.isFillStyle() && 41 return stroke.isFillStyle() &&
42 !antiAlias && // doesn't do per-path AA, relies on the target having MSAA 42 !antiAlias && // doesn't do per-path AA, relies on the target having MSAA
43 !target->getDrawState().willEffectReadDstColor() && // not supported yet
Chris Dalton 2013/10/07 22:22:45 I'm trying to understand why reading the dst color
Kimmo Kinnunen 2013/10/08 12:14:09 True, should've mentioned in commit msg that it is
bsalomon 2013/10/08 14:05:08 Do you mean there are cases where requiring the ds
44 NULL != target->getDrawState().getRenderTarget()->getStencilBuffer() &&
43 target->getDrawState().getStencil().isDisabled(); 45 target->getDrawState().getStencil().isDisabled();
44 } 46 }
45 47
46 GrPathRenderer::StencilSupport GrStencilAndCoverPathRenderer::onGetStencilSuppor t( 48 GrPathRenderer::StencilSupport GrStencilAndCoverPathRenderer::onGetStencilSuppor t(
47 const SkPath&, 49 const SkPath&,
48 const SkStrokeRec& , 50 const SkStrokeRec& ,
49 const GrDrawTarget*) con st { 51 const GrDrawTarget*) con st {
50 return GrPathRenderer::kStencilOnly_StencilSupport; 52 return GrPathRenderer::kStencilOnly_StencilSupport;
51 } 53 }
52 54
(...skipping 10 matching lines...) Expand all
63 GrDrawTarget* target, 65 GrDrawTarget* target,
64 bool antiAlias) { 66 bool antiAlias) {
65 SkASSERT(!antiAlias); 67 SkASSERT(!antiAlias);
66 SkASSERT(!stroke.isHairlineStyle()); 68 SkASSERT(!stroke.isHairlineStyle());
67 69
68 GrDrawState* drawState = target->drawState(); 70 GrDrawState* drawState = target->drawState();
69 SkASSERT(drawState->getStencil().isDisabled()); 71 SkASSERT(drawState->getStencil().isDisabled());
70 72
71 SkAutoTUnref<GrPath> p(fGpu->createPath(path)); 73 SkAutoTUnref<GrPath> p(fGpu->createPath(path));
72 74
73 SkPath::FillType nonInvertedFill = SkPath::ConvertToNonInverseFillType(path. getFillType()); 75 if (path.isInverseFillType()) {
74 target->stencilPath(p, stroke, nonInvertedFill);
75
76 // TODO: Use built in cover operation rather than a rect draw. This will req uire making our
77 // fragment shaders be able to eat varyings generated by a matrix.
78
79 // fill the path, zero out the stencil
80 SkRect bounds = p->getBounds();
81 SkScalar bloat = drawState->getViewMatrix().getMaxStretch() * SK_ScalarHalf;
82 GrDrawState::AutoViewMatrixRestore avmr;
83
84 if (nonInvertedFill == path.getFillType()) {
85 GR_STATIC_CONST_SAME_STENCIL(kStencilPass,
86 kZero_StencilOp,
87 kZero_StencilOp,
88 kNotEqual_StencilFunc,
89 0xffff,
90 0x0000,
91 0xffff);
92 *drawState->stencil() = kStencilPass;
93 } else {
94 GR_STATIC_CONST_SAME_STENCIL(kInvertedStencilPass, 76 GR_STATIC_CONST_SAME_STENCIL(kInvertedStencilPass,
95 kZero_StencilOp, 77 kZero_StencilOp,
96 kZero_StencilOp, 78 kZero_StencilOp,
97 // We know our rect will hit pixels outside the clip and the user bi ts will be 0 79 // We know our rect will hit pixels outside the clip and the user bi ts will be 0
98 // outside the clip. So we can't just fill where the user bits are 0 . We also need to 80 // outside the clip. So we can't just fill where the user bits are 0 . We also need to
99 // check that the clip bit is set. 81 // check that the clip bit is set.
100 kEqualIfInClip_StencilFunc, 82 kEqualIfInClip_StencilFunc,
101 0xffff, 83 0xffff,
102 0x0000, 84 0x0000,
103 0xffff); 85 0xffff);
104 SkMatrix vmi; 86
105 bounds.setLTRB(0, 0,
106 SkIntToScalar(drawState->getRenderTarget()->width()),
107 SkIntToScalar(drawState->getRenderTarget()->height()));
108 // mapRect through persp matrix may not be correct
109 if (!drawState->getViewMatrix().hasPerspective() && drawState->getViewIn verse(&vmi)) {
110 vmi.mapRect(&bounds);
111 // theoretically could set bloat = 0, instead leave it because of ma trix inversion
112 // precision.
113 } else {
114 avmr.setIdentity(drawState);
115 bloat = 0;
116 }
117 *drawState->stencil() = kInvertedStencilPass; 87 *drawState->stencil() = kInvertedStencilPass;
88 } else {
89 GR_STATIC_CONST_SAME_STENCIL(kStencilPass,
90 kZero_StencilOp,
91 kZero_StencilOp,
92 kNotEqual_StencilFunc,
93 0xffff,
94 0x0000,
95 0xffff);
96
97 *drawState->stencil() = kStencilPass;
118 } 98 }
119 bounds.outset(bloat, bloat); 99
120 target->drawSimpleRect(bounds, NULL); 100 target->fillPath(p, stroke, path.getFillType());
101
121 target->drawState()->stencil()->setDisabled(); 102 target->drawState()->stencil()->setDisabled();
122 return true; 103 return true;
123 } 104 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698