OLD | NEW |
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 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 GrPathRendererChain::kNoRestriction_StencilSupport; | 74 GrPathRendererChain::kNoRestriction_StencilSupport; |
75 | 75 |
76 /** | 76 /** |
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 SkPath& path, | 84 StencilSupport getStencilSupport(const GrDrawTarget* target, |
85 const SkStrokeRec& stroke, | 85 const GrDrawState* drawState, |
86 const GrDrawTarget* target) const { | 86 const SkPath& path, |
| 87 const SkStrokeRec& stroke) const { |
87 SkASSERT(!path.isInverseFillType()); | 88 SkASSERT(!path.isInverseFillType()); |
88 return this->onGetStencilSupport(path, stroke, target); | 89 return this->onGetStencilSupport(target, drawState, path, stroke); |
89 } | 90 } |
90 | 91 |
91 /** | 92 /** |
92 * 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 |
93 * 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 |
94 * renderer capable of rendering a path. | 95 * renderer capable of rendering a path. |
95 * | 96 * |
96 * @param path The path to draw | 97 * @param path The path to draw |
97 * @param stroke The stroke information (width, join, cap) | 98 * @param stroke The stroke information (width, join, cap) |
98 * @param target The target that the path will be rendered to | 99 * @param target The target that the path will be rendered to |
99 * @param antiAlias True if anti-aliasing is required. | 100 * @param antiAlias True if anti-aliasing is required. |
100 * | 101 * |
101 * @return true if the path can be drawn by this object, false otherwise. | 102 * @return true if the path can be drawn by this object, false otherwise. |
102 */ | 103 */ |
103 virtual bool canDrawPath(const SkPath& path, | 104 virtual bool canDrawPath(const GrDrawTarget* target, |
| 105 const GrDrawState* drawState, |
| 106 const SkPath& path, |
104 const SkStrokeRec& rec, | 107 const SkStrokeRec& rec, |
105 const GrDrawTarget* target, | |
106 bool antiAlias) const = 0; | 108 bool antiAlias) const = 0; |
107 /** | 109 /** |
108 * Draws the path into the draw target. If getStencilSupport() would return
kNoRestriction then | 110 * Draws the path into the draw target. If getStencilSupport() would return
kNoRestriction then |
109 * the subclass must respect the stencil settings of the target's draw state
. | 111 * the subclass must respect the stencil settings of the target's draw state
. |
110 * | 112 * |
111 * @param path the path to draw. | 113 * @param path the path to draw. |
112 * @param stroke the stroke information (width, join, cap) | 114 * @param stroke the stroke information (width, join, cap) |
113 * @param target target that the path will be rendered to | 115 * @param target target that the path will be rendered to |
114 * @param antiAlias true if anti-aliasing is required. | 116 * @param antiAlias true if anti-aliasing is required. |
115 */ | 117 */ |
116 bool drawPath(const SkPath& path, | 118 bool drawPath(GrDrawTarget* target, |
| 119 GrDrawState* ds, |
| 120 const SkPath& path, |
117 const SkStrokeRec& stroke, | 121 const SkStrokeRec& stroke, |
118 GrDrawTarget* target, | |
119 bool antiAlias) { | 122 bool antiAlias) { |
120 SkASSERT(!path.isEmpty()); | 123 SkASSERT(!path.isEmpty()); |
121 SkASSERT(this->canDrawPath(path, stroke, target, antiAlias)); | 124 SkASSERT(this->canDrawPath(target, ds, path, stroke, antiAlias)); |
122 SkASSERT(target->drawState()->getStencil().isDisabled() || | 125 SkASSERT(ds->getStencil().isDisabled() || |
123 kNoRestriction_StencilSupport == this->getStencilSupport(path,
stroke, target)); | 126 kNoRestriction_StencilSupport == this->getStencilSupport(target
, ds, path, |
124 return this->onDrawPath(path, stroke, target, antiAlias); | 127 stroke
)); |
| 128 return this->onDrawPath(target, ds, path, stroke, antiAlias); |
125 } | 129 } |
126 | 130 |
127 /** | 131 /** |
128 * Draws the path to the stencil buffer. Assume the writable stencil bits ar
e already | 132 * Draws the path to the stencil buffer. Assume the writable stencil bits ar
e already |
129 * initialized to zero. The pixels inside the path will have non-zero stenci
l values afterwards. | 133 * initialized to zero. The pixels inside the path will have non-zero stenci
l values afterwards. |
130 * | 134 * |
131 * @param path the path to draw. | 135 * @param path the path to draw. |
132 * @param stroke the stroke information (width, join, cap) | 136 * @param stroke the stroke information (width, join, cap) |
133 * @param target target that the path will be rendered to | 137 * @param target target that the path will be rendered to |
134 */ | 138 */ |
135 void stencilPath(const SkPath& path, const SkStrokeRec& stroke, GrDrawTarget
* target) { | 139 void stencilPath(GrDrawTarget* target, |
| 140 GrDrawState* ds, |
| 141 const SkPath& path, |
| 142 const SkStrokeRec& stroke) { |
136 SkASSERT(!path.isEmpty()); | 143 SkASSERT(!path.isEmpty()); |
137 SkASSERT(kNoSupport_StencilSupport != this->getStencilSupport(path, stro
ke, target)); | 144 SkASSERT(kNoSupport_StencilSupport != this->getStencilSupport(target, ds
, path, stroke)); |
138 this->onStencilPath(path, stroke, target); | 145 this->onStencilPath(target, ds, path, stroke); |
139 } | 146 } |
140 | 147 |
141 // Helper for determining if we can treat a thin stroke as a hairline w/ cov
erage. | 148 // Helper for determining if we can treat a thin stroke as a hairline w/ cov
erage. |
142 // If we can, we draw lots faster (raster device does this same test). | 149 // If we can, we draw lots faster (raster device does this same test). |
143 static bool IsStrokeHairlineOrEquivalent(const SkStrokeRec& stroke, const Sk
Matrix& matrix, | 150 static bool IsStrokeHairlineOrEquivalent(const SkStrokeRec& stroke, const Sk
Matrix& matrix, |
144 SkScalar* outCoverage) { | 151 SkScalar* outCoverage) { |
145 if (stroke.isHairlineStyle()) { | 152 if (stroke.isHairlineStyle()) { |
146 if (outCoverage) { | 153 if (outCoverage) { |
147 *outCoverage = SK_Scalar1; | 154 *outCoverage = SK_Scalar1; |
148 } | 155 } |
149 return true; | 156 return true; |
150 } | 157 } |
151 return stroke.getStyle() == SkStrokeRec::kStroke_Style && | 158 return stroke.getStyle() == SkStrokeRec::kStroke_Style && |
152 SkDrawTreatAAStrokeAsHairline(stroke.getWidth(), matrix, outCoverage
); | 159 SkDrawTreatAAStrokeAsHairline(stroke.getWidth(), matrix, outCoverage
); |
153 } | 160 } |
154 | 161 |
155 protected: | 162 protected: |
156 /** | 163 /** |
157 * Subclass overrides if it has any limitations of stenciling support. | 164 * Subclass overrides if it has any limitations of stenciling support. |
158 */ | 165 */ |
159 virtual StencilSupport onGetStencilSupport(const SkPath&, | 166 virtual StencilSupport onGetStencilSupport(const GrDrawTarget*, |
160 const SkStrokeRec&, | 167 const GrDrawState*, |
161 const GrDrawTarget*) const { | 168 const SkPath&, |
| 169 const SkStrokeRec&) const { |
162 return kNoRestriction_StencilSupport; | 170 return kNoRestriction_StencilSupport; |
163 } | 171 } |
164 | 172 |
165 /** | 173 /** |
166 * Subclass implementation of drawPath() | 174 * Subclass implementation of drawPath() |
167 */ | 175 */ |
168 virtual bool onDrawPath(const SkPath& path, | 176 virtual bool onDrawPath(GrDrawTarget*, |
169 const SkStrokeRec& stroke, | 177 GrDrawState*, |
170 GrDrawTarget* target, | 178 const SkPath&, |
| 179 const SkStrokeRec&, |
171 bool antiAlias) = 0; | 180 bool antiAlias) = 0; |
172 | 181 |
173 /** | 182 /** |
174 * Subclass implementation of stencilPath(). Subclass must override iff it e
ver returns | 183 * Subclass implementation of stencilPath(). Subclass must override iff it e
ver returns |
175 * kStencilOnly in onGetStencilSupport(). | 184 * kStencilOnly in onGetStencilSupport(). |
176 */ | 185 */ |
177 virtual void onStencilPath(const SkPath& path, const SkStrokeRec& stroke, G
rDrawTarget* target) { | 186 virtual void onStencilPath(GrDrawTarget* target, |
178 GrDrawTarget::AutoStateRestore asr(target, GrDrawTarget::kPreserve_ASRIn
it); | 187 GrDrawState* drawState, |
179 GrDrawState* drawState = target->drawState(); | 188 const SkPath& path, |
| 189 const SkStrokeRec& stroke) { |
180 GR_STATIC_CONST_SAME_STENCIL(kIncrementStencil, | 190 GR_STATIC_CONST_SAME_STENCIL(kIncrementStencil, |
181 kReplace_StencilOp, | 191 kReplace_StencilOp, |
182 kReplace_StencilOp, | 192 kReplace_StencilOp, |
183 kAlways_StencilFunc, | 193 kAlways_StencilFunc, |
184 0xffff, | 194 0xffff, |
185 0xffff, | 195 0xffff, |
186 0xffff); | 196 0xffff); |
187 drawState->setStencil(kIncrementStencil); | 197 drawState->setStencil(kIncrementStencil); |
188 drawState->enableState(GrDrawState::kNoColorWrites_StateBit); | 198 drawState->enableState(GrDrawState::kNoColorWrites_StateBit); |
189 this->drawPath(path, stroke, target, false); | 199 this->drawPath(target, drawState, path, stroke, false); |
190 } | 200 } |
191 | 201 |
192 // Helper for getting the device bounds of a path. Inverse filled paths will
have bounds set | 202 // Helper for getting the device bounds of a path. Inverse filled paths will
have bounds set |
193 // by devSize. Non-inverse path bounds will not necessarily be clipped to de
vSize. | 203 // by devSize. Non-inverse path bounds will not necessarily be clipped to de
vSize. |
194 static void GetPathDevBounds(const SkPath& path, | 204 static void GetPathDevBounds(const SkPath& path, |
195 int devW, | 205 int devW, |
196 int devH, | 206 int devH, |
197 const SkMatrix& matrix, | 207 const SkMatrix& matrix, |
198 SkRect* bounds); | 208 SkRect* bounds); |
199 | 209 |
200 // Helper version that gets the dev width and height from a GrSurface. | 210 // Helper version that gets the dev width and height from a GrSurface. |
201 static void GetPathDevBounds(const SkPath& path, | 211 static void GetPathDevBounds(const SkPath& path, |
202 const GrSurface* device, | 212 const GrSurface* device, |
203 const SkMatrix& matrix, | 213 const SkMatrix& matrix, |
204 SkRect* bounds) { | 214 SkRect* bounds) { |
205 GetPathDevBounds(path, device->width(), device->height(), matrix, bounds
); | 215 GetPathDevBounds(path, device->width(), device->height(), matrix, bounds
); |
206 } | 216 } |
207 | 217 |
208 private: | 218 private: |
209 | 219 |
210 typedef SkRefCnt INHERITED; | 220 typedef SkRefCnt INHERITED; |
211 }; | 221 }; |
212 | 222 |
213 #endif | 223 #endif |
OLD | NEW |