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

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

Issue 687563008: Beginning to refactor nvpr code (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: cleanup Created 6 years, 1 month 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
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 /*
18 * For now paths only natively support winding and even odd fill types
19 */
20 static GrPathRendering::FillType convert_skpath_filltype(SkPath::FillType fill) {
21 switch (fill) {
22 default:
23 SkFAIL("Incomplete Switch\n");
24 case SkPath::kWinding_FillType:
25 case SkPath::kInverseWinding_FillType:
26 return GrPathRendering::kWinding_FillType;
27 case SkPath::kEvenOdd_FillType:
28 case SkPath::kInverseEvenOdd_FillType:
29 return GrPathRendering::kEvenOdd_FillType;
30 }
31 }
32
17 GrPathRenderer* GrStencilAndCoverPathRenderer::Create(GrContext* context) { 33 GrPathRenderer* GrStencilAndCoverPathRenderer::Create(GrContext* context) {
18 SkASSERT(context); 34 SkASSERT(context);
19 SkASSERT(context->getGpu()); 35 SkASSERT(context->getGpu());
20 if (context->getGpu()->caps()->pathRenderingSupport()) { 36 if (context->getGpu()->caps()->pathRenderingSupport()) {
21 return SkNEW_ARGS(GrStencilAndCoverPathRenderer, (context->getGpu())); 37 return SkNEW_ARGS(GrStencilAndCoverPathRenderer, (context->getGpu()));
22 } else { 38 } else {
23 return NULL; 39 return NULL;
24 } 40 }
25 } 41 }
26 42
(...skipping 10 matching lines...) Expand all
37 bool GrStencilAndCoverPathRenderer::canDrawPath(const SkPath& path, 53 bool GrStencilAndCoverPathRenderer::canDrawPath(const SkPath& path,
38 const SkStrokeRec& stroke, 54 const SkStrokeRec& stroke,
39 const GrDrawTarget* target, 55 const GrDrawTarget* target,
40 bool antiAlias) const { 56 bool antiAlias) const {
41 return !stroke.isHairlineStyle() && 57 return !stroke.isHairlineStyle() &&
42 !antiAlias && // doesn't do per-path AA, relies on the target having MSAA 58 !antiAlias && // doesn't do per-path AA, relies on the target having MSAA
43 target->getDrawState().getRenderTarget()->getStencilBuffer() && 59 target->getDrawState().getRenderTarget()->getStencilBuffer() &&
44 target->getDrawState().getStencil().isDisabled(); 60 target->getDrawState().getStencil().isDisabled();
45 } 61 }
46 62
47 GrPathRenderer::StencilSupport GrStencilAndCoverPathRenderer::onGetStencilSuppor t( 63 GrPathRenderer::StencilSupport
48 const SkPath&, 64 GrStencilAndCoverPathRenderer::onGetStencilSupport(const SkPath&,
49 const SkStrokeRec& , 65 const SkStrokeRec& ,
50 const GrDrawTarget*) con st { 66 const GrDrawTarget*) const {
51 return GrPathRenderer::kStencilOnly_StencilSupport; 67 return GrPathRenderer::kStencilOnly_StencilSupport;
52 } 68 }
53 69
54 static GrPath* get_gr_path(GrGpu* gpu, const SkPath& skPath, const SkStrokeRec& stroke) { 70 static GrPath* get_gr_path(GrGpu* gpu, const SkPath& skPath, const SkStrokeRec& stroke) {
55 GrContext* ctx = gpu->getContext(); 71 GrContext* ctx = gpu->getContext();
56 GrResourceKey resourceKey = GrPath::ComputeKey(skPath, stroke); 72 GrResourceKey resourceKey = GrPath::ComputeKey(skPath, stroke);
57 SkAutoTUnref<GrPath> path(static_cast<GrPath*>(ctx->findAndRefCachedResource (resourceKey))); 73 SkAutoTUnref<GrPath> path(static_cast<GrPath*>(ctx->findAndRefCachedResource (resourceKey)));
58 if (NULL == path || !path->isEqualTo(skPath, stroke)) { 74 if (NULL == path || !path->isEqualTo(skPath, stroke)) {
59 path.reset(gpu->pathRendering()->createPath(skPath, stroke)); 75 path.reset(gpu->pathRendering()->createPath(skPath, stroke));
60 ctx->addResourceToCache(resourceKey, path); 76 ctx->addResourceToCache(resourceKey, path);
61 } 77 }
62 return path.detach(); 78 return path.detach();
63 } 79 }
64 80
65 void GrStencilAndCoverPathRenderer::onStencilPath(const SkPath& path, 81 void GrStencilAndCoverPathRenderer::onStencilPath(const SkPath& path,
66 const SkStrokeRec& stroke, 82 const SkStrokeRec& stroke,
67 GrDrawTarget* target) { 83 GrDrawTarget* target) {
68 SkASSERT(!path.isInverseFillType()); 84 SkASSERT(!path.isInverseFillType());
69 SkAutoTUnref<GrPath> p(get_gr_path(fGpu, path, stroke)); 85 SkAutoTUnref<GrPath> p(get_gr_path(fGpu, path, stroke));
70 target->stencilPath(p, path.getFillType()); 86 target->stencilPath(p, convert_skpath_filltype(path.getFillType()));
71 } 87 }
72 88
73 bool GrStencilAndCoverPathRenderer::onDrawPath(const SkPath& path, 89 bool GrStencilAndCoverPathRenderer::onDrawPath(const SkPath& path,
74 const SkStrokeRec& stroke, 90 const SkStrokeRec& stroke,
75 GrDrawTarget* target, 91 GrDrawTarget* target,
76 bool antiAlias) { 92 bool antiAlias) {
77 SkASSERT(!antiAlias); 93 SkASSERT(!antiAlias);
78 SkASSERT(!stroke.isHairlineStyle()); 94 SkASSERT(!stroke.isHairlineStyle());
79 95
80 GrDrawState* drawState = target->drawState(); 96 GrDrawState* drawState = target->drawState();
81 SkASSERT(drawState->getStencil().isDisabled()); 97 SkASSERT(drawState->getStencil().isDisabled());
82 98
83 SkAutoTUnref<GrPath> p(get_gr_path(fGpu, path, stroke)); 99 SkAutoTUnref<GrPath> p(get_gr_path(fGpu, path, stroke));
84 100
85 if (path.isInverseFillType()) { 101 if (path.isInverseFillType()) {
86 GR_STATIC_CONST_SAME_STENCIL(kInvertedStencilPass, 102 GR_STATIC_CONST_SAME_STENCIL(kInvertedStencilPass,
87 kZero_StencilOp, 103 kZero_StencilOp,
88 kZero_StencilOp, 104 kZero_StencilOp,
89 // We know our rect will hit pixels outside the clip and the user bi ts will be 0 105 // We know our rect will hit pixels outside the clip and the user bi ts will be 0
90 // outside the clip. So we can't just fill where the user bits are 0 . We also need to 106 // outside the clip. So we can't just fill where the user bits are 0 . We also need to
91 // check that the clip bit is set. 107 // check that the clip bit is set.
92 kEqualIfInClip_StencilFunc, 108 kEqualIfInClip_StencilFunc,
93 0xffff, 109 0xffff,
94 0x0000, 110 0x0000,
95 0xffff); 111 0xffff);
96 112
97 *drawState->stencil() = kInvertedStencilPass; 113 drawState->setStencil(kInvertedStencilPass);
Kimmo Kinnunen 2014/11/03 20:39:12 So this hunk was intentionally moved from here dow
bsalomon 2014/11/03 20:46:07 This CL arose out a of a desire to make GrGpu no l
joshualitt 2014/11/03 20:51:46 Ahh, so I should explain. It seems very possible
114
115 // fake inverse with a stencil and cover
116 target->stencilPath(p, convert_skpath_filltype(path.getFillType()));
117
118 GrDrawState::AutoViewMatrixRestore avmr;
119 SkRect bounds = SkRect::MakeLTRB(0, 0,
120 SkIntToScalar(drawState->getRenderTarge t()->width()),
121 SkIntToScalar(drawState->getRenderTarge t()->height()));
122 SkMatrix vmi;
123 // mapRect through persp matrix may not be correct
124 if (!drawState->getViewMatrix().hasPerspective() && drawState->getViewIn verse(&vmi)) {
125 vmi.mapRect(&bounds);
126 // theoretically could set bloat = 0, instead leave it because of ma trix inversion
127 // precision.
128 SkScalar bloat = drawState->getViewMatrix().getMaxScale() * SK_Scala rHalf;
129 bounds.outset(bloat, bloat);
130 } else {
131 avmr.setIdentity(drawState);
132 }
133 target->drawSimpleRect(bounds);
98 } else { 134 } else {
99 GR_STATIC_CONST_SAME_STENCIL(kStencilPass, 135 GR_STATIC_CONST_SAME_STENCIL(kStencilPass,
100 kZero_StencilOp, 136 kZero_StencilOp,
101 kZero_StencilOp, 137 kZero_StencilOp,
102 kNotEqual_StencilFunc, 138 kNotEqual_StencilFunc,
103 0xffff, 139 0xffff,
104 0x0000, 140 0x0000,
105 0xffff); 141 0xffff);
106 142
107 *drawState->stencil() = kStencilPass; 143 drawState->setStencil(kStencilPass);
144 target->drawPath(p, convert_skpath_filltype(path.getFillType()));
108 } 145 }
109 146
110 target->drawPath(p, path.getFillType());
111
112 target->drawState()->stencil()->setDisabled(); 147 target->drawState()->stencil()->setDisabled();
113 return true; 148 return true;
114 } 149 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698