OLD | NEW |
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 #include "GrGLPath.h" | 9 #include "GrGLPath.h" |
10 #include "GrGLPathRendering.h" | 10 #include "GrGLPathRendering.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 for (size_t i = 0; i < amount; ++i) { | 84 for (size_t i = 0; i < amount; ++i) { |
85 coords[i * 2] = SkScalarToFloat(points[first_point + i].fX); | 85 coords[i * 2] = SkScalarToFloat(points[first_point + i].fX); |
86 coords[i * 2 + 1] = SkScalarToFloat(points[first_point + i].fY); | 86 coords[i * 2 + 1] = SkScalarToFloat(points[first_point + i].fY); |
87 } | 87 } |
88 } | 88 } |
89 } | 89 } |
90 | 90 |
91 void GrGLPath::InitPathObject(GrGLGpu* gpu, | 91 void GrGLPath::InitPathObject(GrGLGpu* gpu, |
92 GrGLuint pathID, | 92 GrGLuint pathID, |
93 const SkPath& skPath, | 93 const SkPath& skPath, |
94 const SkStrokeRec& stroke) { | 94 const GrStrokeInfo& stroke) { |
| 95 SkASSERT(!stroke.isDashed()); |
95 if (!skPath.isEmpty()) { | 96 if (!skPath.isEmpty()) { |
96 int verbCnt = skPath.countVerbs(); | 97 int verbCnt = skPath.countVerbs(); |
97 int pointCnt = skPath.countPoints(); | 98 int pointCnt = skPath.countPoints(); |
98 int minCoordCnt = pointCnt * 2; | 99 int minCoordCnt = pointCnt * 2; |
99 | 100 |
100 SkSTArray<16, GrGLubyte, true> pathCommands(verbCnt); | 101 SkSTArray<16, GrGLubyte, true> pathCommands(verbCnt); |
101 SkSTArray<16, GrGLfloat, true> pathCoords(minCoordCnt); | 102 SkSTArray<16, GrGLfloat, true> pathCoords(minCoordCnt); |
102 | 103 |
103 SkDEBUGCODE(int numCoords = 0); | 104 SkDEBUGCODE(int numCoords = 0); |
104 | 105 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 | 162 |
162 SkASSERT(verbCnt == pathCommands.count()); | 163 SkASSERT(verbCnt == pathCommands.count()); |
163 SkASSERT(numCoords == pathCoords.count()); | 164 SkASSERT(numCoords == pathCoords.count()); |
164 | 165 |
165 GR_GL_CALL(gpu->glInterface(), PathCommands(pathID, pathCommands.count()
, &pathCommands[0], | 166 GR_GL_CALL(gpu->glInterface(), PathCommands(pathID, pathCommands.count()
, &pathCommands[0], |
166 pathCoords.count(), GR_GL_FLOAT, &pathCoords[0])); | 167 pathCoords.count(), GR_GL_FLOAT, &pathCoords[0])); |
167 } else { | 168 } else { |
168 GR_GL_CALL(gpu->glInterface(), PathCommands(pathID, 0, NULL, 0, GR_GL_FL
OAT, NULL)); | 169 GR_GL_CALL(gpu->glInterface(), PathCommands(pathID, 0, NULL, 0, GR_GL_FL
OAT, NULL)); |
169 } | 170 } |
170 | 171 |
171 if (stroke.needToApply()) { | 172 const SkStrokeRec& strokeRec = stroke.getStrokeRec(); |
172 SkASSERT(!stroke.isHairlineStyle()); | 173 if (strokeRec.needToApply()) { |
| 174 SkASSERT(!strokeRec.isHairlineStyle()); |
173 GR_GL_CALL(gpu->glInterface(), | 175 GR_GL_CALL(gpu->glInterface(), |
174 PathParameterf(pathID, GR_GL_PATH_STROKE_WIDTH, SkScalarToFloat(stro
ke.getWidth()))); | 176 PathParameterf(pathID, GR_GL_PATH_STROKE_WIDTH, SkScalarToFloat(stro
keRec.getWidth()))); |
175 GR_GL_CALL(gpu->glInterface(), | 177 GR_GL_CALL(gpu->glInterface(), |
176 PathParameterf(pathID, GR_GL_PATH_MITER_LIMIT, SkScalarToFloat(strok
e.getMiter()))); | 178 PathParameterf(pathID, GR_GL_PATH_MITER_LIMIT, SkScalarToFloat(strok
eRec.getMiter()))); |
177 GrGLenum join = join_to_gl_join(stroke.getJoin()); | 179 GrGLenum join = join_to_gl_join(strokeRec.getJoin()); |
178 GR_GL_CALL(gpu->glInterface(), PathParameteri(pathID, GR_GL_PATH_JOIN_ST
YLE, join)); | 180 GR_GL_CALL(gpu->glInterface(), PathParameteri(pathID, GR_GL_PATH_JOIN_ST
YLE, join)); |
179 GrGLenum cap = cap_to_gl_cap(stroke.getCap()); | 181 GrGLenum cap = cap_to_gl_cap(strokeRec.getCap()); |
180 GR_GL_CALL(gpu->glInterface(), PathParameteri(pathID, GR_GL_PATH_END_CAP
S, cap)); | 182 GR_GL_CALL(gpu->glInterface(), PathParameteri(pathID, GR_GL_PATH_END_CAP
S, cap)); |
181 } | 183 } |
182 } | 184 } |
183 | 185 |
184 GrGLPath::GrGLPath(GrGLGpu* gpu, const SkPath& path, const SkStrokeRec& stroke) | 186 GrGLPath::GrGLPath(GrGLGpu* gpu, const SkPath& origSkPath, const GrStrokeInfo& o
rigStroke) |
185 : INHERITED(gpu, path, stroke), | 187 : INHERITED(gpu, origSkPath, origStroke), |
186 fPathID(gpu->glPathRendering()->genPaths(1)) { | 188 fPathID(gpu->glPathRendering()->genPaths(1)) { |
187 | 189 |
188 InitPathObject(gpu, fPathID, fSkPath, stroke); | 190 // Convert a dashing to either a stroke or a fill. |
| 191 const SkPath* skPath = &origSkPath; |
| 192 SkTLazy<SkPath> tmpPath; |
| 193 const GrStrokeInfo* stroke = &origStroke; |
| 194 GrStrokeInfo tmpStroke(origStroke, false); |
189 | 195 |
190 if (stroke.needToApply()) { | 196 if (stroke->isDashed()) { |
| 197 if (stroke->applyDash(tmpPath.init(), &tmpStroke, *skPath)) { |
| 198 skPath = tmpPath.get(); |
| 199 stroke = &tmpStroke; |
| 200 } |
| 201 } |
| 202 |
| 203 InitPathObject(gpu, fPathID, *skPath, *stroke); |
| 204 |
| 205 const SkStrokeRec& strokeRec = stroke->getStrokeRec(); |
| 206 fShouldStroke = strokeRec.needToApply(); |
| 207 fShouldFill = stroke->isFillStyle() || |
| 208 strokeRec.getStyle() == SkStrokeRec::kStrokeAndFill_Style; |
| 209 |
| 210 if (fShouldStroke) { |
191 // FIXME: try to account for stroking, without rasterizing the stroke. | 211 // FIXME: try to account for stroking, without rasterizing the stroke. |
192 fBounds.outset(stroke.getWidth(), stroke.getWidth()); | 212 fBounds.outset(strokeRec.getWidth(), strokeRec.getWidth()); |
193 } | 213 } |
| 214 |
194 this->registerWithCache(); | 215 this->registerWithCache(); |
195 } | 216 } |
196 | 217 |
197 void GrGLPath::onRelease() { | 218 void GrGLPath::onRelease() { |
198 if (0 != fPathID && !this->isWrapped()) { | 219 if (0 != fPathID && !this->isWrapped()) { |
199 static_cast<GrGLGpu*>(this->getGpu())->glPathRendering()->deletePaths(fP
athID, 1); | 220 static_cast<GrGLGpu*>(this->getGpu())->glPathRendering()->deletePaths(fP
athID, 1); |
200 fPathID = 0; | 221 fPathID = 0; |
201 } | 222 } |
202 | 223 |
203 INHERITED::onRelease(); | 224 INHERITED::onRelease(); |
204 } | 225 } |
205 | 226 |
206 void GrGLPath::onAbandon() { | 227 void GrGLPath::onAbandon() { |
207 fPathID = 0; | 228 fPathID = 0; |
208 | 229 |
209 INHERITED::onAbandon(); | 230 INHERITED::onAbandon(); |
210 } | 231 } |
OLD | NEW |