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

Side by Side Diff: src/gpu/GrPathRenderer.h

Issue 1100073003: Extract gpu line dashing to GrDashLinePathRenderer (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: address review comments Created 5 years, 7 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
« no previous file with comments | « src/gpu/GrDefaultPathRenderer.cpp ('k') | src/gpu/GrPathRendererChain.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 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 #ifndef GrPathRenderer_DEFINED 9 #ifndef GrPathRenderer_DEFINED
10 #define GrPathRenderer_DEFINED 10 #define GrPathRenderer_DEFINED
11 11
12 #include "GrDrawTarget.h" 12 #include "GrDrawTarget.h"
13 #include "GrPathRendererChain.h" 13 #include "GrPathRendererChain.h"
14 #include "GrStencil.h" 14 #include "GrStencil.h"
15 #include "GrStrokeInfo.h"
15 16
16 #include "SkDrawProcs.h" 17 #include "SkDrawProcs.h"
17 #include "SkStrokeRec.h"
18 #include "SkTArray.h" 18 #include "SkTArray.h"
19 19
20 class SkPath; 20 class SkPath;
21 21
22 struct GrPoint; 22 struct GrPoint;
23 23
24 /** 24 /**
25 * Base class for drawing paths into a GrDrawTarget. 25 * Base class for drawing paths into a GrDrawTarget.
26 * 26 *
27 * Derived classes can use stages GrPaint::kTotalStages through GrPipelineBuild er::kNumStages-1. 27 * Derived classes can use stages GrPaint::kTotalStages through GrPipelineBuild er::kNumStages-1.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 * This function is to get the stencil support for a particular path. The pa th's fill must 77 * This function is to get the stencil support for a particular path. The pa th's fill must
78 * not be an inverse type. 78 * not be an inverse type.
79 * 79 *
80 * @param target target that the path will be rendered to 80 * @param target target that the path will be rendered to
81 * @param path the path that will be drawn 81 * @param path the path that will be drawn
82 * @param stroke the stroke information (width, join, cap). 82 * @param stroke the stroke information (width, join, cap).
83 */ 83 */
84 StencilSupport getStencilSupport(const GrDrawTarget* target, 84 StencilSupport getStencilSupport(const GrDrawTarget* target,
85 const GrPipelineBuilder* pipelineBuilder, 85 const GrPipelineBuilder* pipelineBuilder,
86 const SkPath& path, 86 const SkPath& path,
87 const SkStrokeRec& stroke) const { 87 const GrStrokeInfo& stroke) const {
88 SkASSERT(!path.isInverseFillType()); 88 SkASSERT(!path.isInverseFillType());
89 return this->onGetStencilSupport(target, pipelineBuilder, path, stroke); 89 return this->onGetStencilSupport(target, pipelineBuilder, path, stroke);
90 } 90 }
91 91
92 /** 92 /**
93 * Returns true if this path renderer is able to render the path. Returning false allows the 93 * Returns true if this path renderer is able to render the path. Returning false allows the
94 * caller to fallback to another path renderer This function is called when searching for a path 94 * caller to fallback to another path renderer This function is called when searching for a path
95 * renderer capable of rendering a path. 95 * renderer capable of rendering a path.
96 * 96 *
97 * @param target The target that the path will be rendered to 97 * @param target The target that the path will be rendered to
98 * @param pipelineBuilder The pipelineBuilder 98 * @param pipelineBuilder The pipelineBuilder
99 * @param viewMatrix The viewMatrix 99 * @param viewMatrix The viewMatrix
100 * @param path The path to draw 100 * @param path The path to draw
101 * @param stroke The stroke information (width, join, cap) 101 * @param stroke The stroke information (width, join, cap)
102 * @param antiAlias True if anti-aliasing is required. 102 * @param antiAlias True if anti-aliasing is required.
103 * 103 *
104 * @return true if the path can be drawn by this object, false otherwise. 104 * @return true if the path can be drawn by this object, false otherwise.
105 */ 105 */
106 virtual bool canDrawPath(const GrDrawTarget* target, 106 virtual bool canDrawPath(const GrDrawTarget* target,
107 const GrPipelineBuilder* pipelineBuilder, 107 const GrPipelineBuilder* pipelineBuilder,
108 const SkMatrix& viewMatrix, 108 const SkMatrix& viewMatrix,
109 const SkPath& path, 109 const SkPath& path,
110 const SkStrokeRec& rec, 110 const GrStrokeInfo& rec,
111 bool antiAlias) const = 0; 111 bool antiAlias) const = 0;
112 /** 112 /**
113 * Draws the path into the draw target. If getStencilSupport() would return kNoRestriction then 113 * Draws the path into the draw target. If getStencilSupport() would return kNoRestriction then
114 * the subclass must respect the stencil settings of the target's draw state . 114 * the subclass must respect the stencil settings of the target's draw state .
115 * 115 *
116 * @param target The target that the path will be rendered to 116 * @param target The target that the path will be rendered to
117 * @param pipelineBuilder The pipelineBuilder 117 * @param pipelineBuilder The pipelineBuilder
118 * @param viewMatrix The viewMatrix 118 * @param viewMatrix The viewMatrix
119 * @param path the path to draw. 119 * @param path the path to draw.
120 * @param stroke the stroke information (width, join, cap) 120 * @param stroke the stroke information (width, join, cap)
121 * @param antiAlias true if anti-aliasing is required. 121 * @param antiAlias true if anti-aliasing is required.
122 */ 122 */
123 bool drawPath(GrDrawTarget* target, 123 bool drawPath(GrDrawTarget* target,
124 GrPipelineBuilder* ds, 124 GrPipelineBuilder* ds,
125 GrColor color, 125 GrColor color,
126 const SkMatrix& viewMatrix, 126 const SkMatrix& viewMatrix,
127 const SkPath& path, 127 const SkPath& path,
128 const SkStrokeRec& stroke, 128 const GrStrokeInfo& stroke,
129 bool antiAlias) { 129 bool antiAlias) {
130 SkASSERT(!path.isEmpty()); 130 SkASSERT(!path.isEmpty());
131 SkASSERT(this->canDrawPath(target, ds, viewMatrix, path, stroke, antiAli as)); 131 SkASSERT(this->canDrawPath(target, ds, viewMatrix, path, stroke, antiAli as));
132 SkASSERT(ds->getStencil().isDisabled() || 132 SkASSERT(ds->getStencil().isDisabled() ||
133 kNoRestriction_StencilSupport == this->getStencilSupport(target , ds, path, 133 kNoRestriction_StencilSupport == this->getStencilSupport(target , ds, path,
134 stroke )); 134 stroke ));
135 return this->onDrawPath(target, ds, color, viewMatrix, path, stroke, ant iAlias); 135 return this->onDrawPath(target, ds, color, viewMatrix, path, stroke, ant iAlias);
136 } 136 }
137 137
138 /** 138 /**
139 * Draws the path to the stencil buffer. Assume the writable stencil bits ar e already 139 * Draws the path to the stencil buffer. Assume the writable stencil bits ar e already
140 * initialized to zero. The pixels inside the path will have non-zero stenci l values afterwards. 140 * initialized to zero. The pixels inside the path will have non-zero stenci l values afterwards.
141 * 141 *
142 * @param path the path to draw. 142 * @param path the path to draw.
143 * @param stroke the stroke information (width, join, cap) 143 * @param stroke the stroke information (width, join, cap)
144 * @param target target that the path will be rendered to 144 * @param target target that the path will be rendered to
145 */ 145 */
146 void stencilPath(GrDrawTarget* target, 146 void stencilPath(GrDrawTarget* target,
147 GrPipelineBuilder* ds, 147 GrPipelineBuilder* ds,
148 const SkMatrix& viewMatrix, 148 const SkMatrix& viewMatrix,
149 const SkPath& path, 149 const SkPath& path,
150 const SkStrokeRec& stroke) { 150 const GrStrokeInfo& stroke) {
151 SkASSERT(!path.isEmpty()); 151 SkASSERT(!path.isEmpty());
152 SkASSERT(kNoSupport_StencilSupport != this->getStencilSupport(target, ds , path, stroke)); 152 SkASSERT(kNoSupport_StencilSupport != this->getStencilSupport(target, ds , path, stroke));
153 this->onStencilPath(target, ds, viewMatrix, path, stroke); 153 this->onStencilPath(target, ds, viewMatrix, path, stroke);
154 } 154 }
155 155
156 // Helper for determining if we can treat a thin stroke as a hairline w/ cov erage. 156 // Helper for determining if we can treat a thin stroke as a hairline w/ cov erage.
157 // If we can, we draw lots faster (raster device does this same test). 157 // If we can, we draw lots faster (raster device does this same test).
158 static bool IsStrokeHairlineOrEquivalent(const SkStrokeRec& stroke, const Sk Matrix& matrix, 158 static bool IsStrokeHairlineOrEquivalent(const GrStrokeInfo& stroke, const S kMatrix& matrix,
159 SkScalar* outCoverage) { 159 SkScalar* outCoverage) {
160 if (stroke.isHairlineStyle()) { 160 if (stroke.isDashed()) {
161 return false;
162 }
163 if (stroke.getStrokeRec().isHairlineStyle()) {
161 if (outCoverage) { 164 if (outCoverage) {
162 *outCoverage = SK_Scalar1; 165 *outCoverage = SK_Scalar1;
163 } 166 }
164 return true; 167 return true;
165 } 168 }
166 return stroke.getStyle() == SkStrokeRec::kStroke_Style && 169 return stroke.getStrokeRec().getStyle() == SkStrokeRec::kStroke_Style &&
167 SkDrawTreatAAStrokeAsHairline(stroke.getWidth(), matrix, outCoverage ); 170 SkDrawTreatAAStrokeAsHairline(stroke.getStrokeRec().getWidth(), matr ix, outCoverage);
168 } 171 }
169 172
170 protected: 173 protected:
171 /** 174 /**
172 * Subclass overrides if it has any limitations of stenciling support. 175 * Subclass overrides if it has any limitations of stenciling support.
173 */ 176 */
174 virtual StencilSupport onGetStencilSupport(const GrDrawTarget*, 177 virtual StencilSupport onGetStencilSupport(const GrDrawTarget*,
175 const GrPipelineBuilder*, 178 const GrPipelineBuilder*,
176 const SkPath&, 179 const SkPath&,
177 const SkStrokeRec&) const { 180 const GrStrokeInfo&) const {
178 return kNoRestriction_StencilSupport; 181 return kNoRestriction_StencilSupport;
179 } 182 }
180 183
181 /** 184 /**
182 * Subclass implementation of drawPath() 185 * Subclass implementation of drawPath()
183 */ 186 */
184 virtual bool onDrawPath(GrDrawTarget*, 187 virtual bool onDrawPath(GrDrawTarget*,
185 GrPipelineBuilder*, 188 GrPipelineBuilder*,
186 GrColor, 189 GrColor,
187 const SkMatrix& viewMatrix, 190 const SkMatrix& viewMatrix,
188 const SkPath&, 191 const SkPath&,
189 const SkStrokeRec&, 192 const GrStrokeInfo&,
190 bool antiAlias) = 0; 193 bool antiAlias) = 0;
191 194
192 /** 195 /**
193 * Subclass implementation of stencilPath(). Subclass must override iff it e ver returns 196 * Subclass implementation of stencilPath(). Subclass must override iff it e ver returns
194 * kStencilOnly in onGetStencilSupport(). 197 * kStencilOnly in onGetStencilSupport().
195 */ 198 */
196 virtual void onStencilPath(GrDrawTarget* target, 199 virtual void onStencilPath(GrDrawTarget* target,
197 GrPipelineBuilder* pipelineBuilder, 200 GrPipelineBuilder* pipelineBuilder,
198 const SkMatrix& viewMatrix, 201 const SkMatrix& viewMatrix,
199 const SkPath& path, 202 const SkPath& path,
200 const SkStrokeRec& stroke) { 203 const GrStrokeInfo& stroke) {
201 GR_STATIC_CONST_SAME_STENCIL(kIncrementStencil, 204 GR_STATIC_CONST_SAME_STENCIL(kIncrementStencil,
202 kReplace_StencilOp, 205 kReplace_StencilOp,
203 kReplace_StencilOp, 206 kReplace_StencilOp,
204 kAlways_StencilFunc, 207 kAlways_StencilFunc,
205 0xffff, 208 0xffff,
206 0xffff, 209 0xffff,
207 0xffff); 210 0xffff);
208 pipelineBuilder->setStencil(kIncrementStencil); 211 pipelineBuilder->setStencil(kIncrementStencil);
209 pipelineBuilder->setDisableColorXPFactory(); 212 pipelineBuilder->setDisableColorXPFactory();
210 this->drawPath(target, pipelineBuilder, GrColor_WHITE, viewMatrix, path, stroke, false); 213 this->drawPath(target, pipelineBuilder, GrColor_WHITE, viewMatrix, path, stroke, false);
(...skipping 14 matching lines...) Expand all
225 SkRect* bounds) { 228 SkRect* bounds) {
226 GetPathDevBounds(path, device->width(), device->height(), matrix, bounds ); 229 GetPathDevBounds(path, device->width(), device->height(), matrix, bounds );
227 } 230 }
228 231
229 private: 232 private:
230 233
231 typedef SkRefCnt INHERITED; 234 typedef SkRefCnt INHERITED;
232 }; 235 };
233 236
234 #endif 237 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrDefaultPathRenderer.cpp ('k') | src/gpu/GrPathRendererChain.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698