OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "gl/GrGLPathRendering.h" | 8 #include "gl/GrGLPathRendering.h" |
9 #include "gl/GrGLNameAllocator.h" | 9 #include "gl/GrGLNameAllocator.h" |
10 #include "gl/GrGLUtil.h" | 10 #include "gl/GrGLUtil.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 | 84 |
85 void GrGLPathRendering::resetContext() { | 85 void GrGLPathRendering::resetContext() { |
86 fHWProjectionMatrixState.invalidate(); | 86 fHWProjectionMatrixState.invalidate(); |
87 // we don't use the model view matrix. | 87 // we don't use the model view matrix. |
88 GL_CALL(MatrixLoadIdentity(GR_GL_PATH_MODELVIEW)); | 88 GL_CALL(MatrixLoadIdentity(GR_GL_PATH_MODELVIEW)); |
89 | 89 |
90 SkASSERT(fCaps.fragmentInputGenSupport); | 90 SkASSERT(fCaps.fragmentInputGenSupport); |
91 fHWPathStencilSettings.invalidate(); | 91 fHWPathStencilSettings.invalidate(); |
92 } | 92 } |
93 | 93 |
94 GrPath* GrGLPathRendering::createPath(const SkPath& inPath, const SkStrokeRec& s
troke) { | 94 GrPath* GrGLPathRendering::createPath(const SkPath& inPath, const GrStrokeInfo&
stroke) { |
95 return SkNEW_ARGS(GrGLPath, (fGpu, inPath, stroke)); | 95 return SkNEW_ARGS(GrGLPath, (fGpu, inPath, stroke)); |
96 } | 96 } |
97 | 97 |
98 GrPathRange* GrGLPathRendering::createPathRange(GrPathRange::PathGenerator* path
Generator, | 98 GrPathRange* GrGLPathRendering::createPathRange(GrPathRange::PathGenerator* path
Generator, |
99 const SkStrokeRec& stroke) { | 99 const GrStrokeInfo& stroke) { |
100 return SkNEW_ARGS(GrGLPathRange, (fGpu, pathGenerator, stroke)); | 100 return SkNEW_ARGS(GrGLPathRange, (fGpu, pathGenerator, stroke)); |
101 } | 101 } |
102 | 102 |
103 GrPathRange* GrGLPathRendering::createGlyphs(const SkTypeface* typeface, | 103 GrPathRange* GrGLPathRendering::createGlyphs(const SkTypeface* typeface, |
104 const SkDescriptor* desc, | 104 const SkDescriptor* desc, |
105 const SkStrokeRec& stroke) { | 105 const GrStrokeInfo& stroke) { |
106 if (NULL != desc || !caps().glyphLoadingSupport) { | 106 if (NULL != desc || !caps().glyphLoadingSupport || stroke.isDashed()) { |
107 return GrPathRendering::createGlyphs(typeface, desc, stroke); | 107 return GrPathRendering::createGlyphs(typeface, desc, stroke); |
108 } | 108 } |
109 | 109 |
110 if (NULL == typeface) { | 110 if (NULL == typeface) { |
111 typeface = SkTypeface::GetDefaultTypeface(); | 111 typeface = SkTypeface::GetDefaultTypeface(); |
112 SkASSERT(NULL != typeface); | 112 SkASSERT(NULL != typeface); |
113 } | 113 } |
114 | 114 |
115 int faceIndex; | 115 int faceIndex; |
116 SkAutoTDelete<SkStream> fontStream(typeface->openStream(&faceIndex)); | 116 SkAutoTDelete<SkStream> fontStream(typeface->openStream(&faceIndex)); |
(...skipping 28 matching lines...) Expand all Loading... |
145 } | 145 } |
146 | 146 |
147 // This is a crude approximation. We may want to consider giving this class | 147 // This is a crude approximation. We may want to consider giving this class |
148 // a pseudo PathGenerator whose sole purpose is to track the approximate gpu | 148 // a pseudo PathGenerator whose sole purpose is to track the approximate gpu |
149 // memory size. | 149 // memory size. |
150 const size_t gpuMemorySize = fontDataLength / 4; | 150 const size_t gpuMemorySize = fontDataLength / 4; |
151 return SkNEW_ARGS(GrGLPathRange, (fGpu, basePathID, numPaths, gpuMemorySize,
stroke)); | 151 return SkNEW_ARGS(GrGLPathRange, (fGpu, basePathID, numPaths, gpuMemorySize,
stroke)); |
152 } | 152 } |
153 | 153 |
154 void GrGLPathRendering::stencilPath(const GrPath* path, const GrStencilSettings&
stencilSettings) { | 154 void GrGLPathRendering::stencilPath(const GrPath* path, const GrStencilSettings&
stencilSettings) { |
155 GrGLuint id = static_cast<const GrGLPath*>(path)->pathID(); | 155 const GrGLPath* glPath = static_cast<const GrGLPath*>(path); |
156 | 156 |
157 this->flushPathStencilSettings(stencilSettings); | 157 this->flushPathStencilSettings(stencilSettings); |
158 SkASSERT(!fHWPathStencilSettings.isTwoSided()); | 158 SkASSERT(!fHWPathStencilSettings.isTwoSided()); |
159 | 159 |
160 const SkStrokeRec& stroke = path->getStroke(); | 160 GrGLenum fillMode = gr_stencil_op_to_gl_path_rendering_fill_mode( |
161 | 161 fHWPathStencilSettings.passOp(GrStencilSettings::kFront_Face)); |
162 GrGLenum fillMode = | |
163 gr_stencil_op_to_gl_path_rendering_fill_mode(fHWPathStencilSettings.pass
Op(GrStencilSettings::kFront_Face)); | |
164 GrGLint writeMask = fHWPathStencilSettings.writeMask(GrStencilSettings::kFro
nt_Face); | 162 GrGLint writeMask = fHWPathStencilSettings.writeMask(GrStencilSettings::kFro
nt_Face); |
165 | 163 |
166 if (stroke.isFillStyle() || SkStrokeRec::kStrokeAndFill_Style == stroke.getS
tyle()) { | 164 if (glPath->shouldFill()) { |
167 GL_CALL(StencilFillPath(id, fillMode, writeMask)); | 165 GL_CALL(StencilFillPath(glPath->pathID(), fillMode, writeMask)); |
168 } | 166 } |
169 if (stroke.needToApply()) { | 167 if (glPath->shouldStroke()) { |
170 GL_CALL(StencilStrokePath(id, 0xffff, writeMask)); | 168 GL_CALL(StencilStrokePath(glPath->pathID(), 0xffff, writeMask)); |
171 } | 169 } |
172 } | 170 } |
173 | 171 |
174 void GrGLPathRendering::drawPath(const GrPath* path, const GrStencilSettings& st
encilSettings) { | 172 void GrGLPathRendering::drawPath(const GrPath* path, const GrStencilSettings& st
encilSettings) { |
175 GrGLuint id = static_cast<const GrGLPath*>(path)->pathID(); | 173 const GrGLPath* glPath = static_cast<const GrGLPath*>(path); |
176 | 174 |
177 this->flushPathStencilSettings(stencilSettings); | 175 this->flushPathStencilSettings(stencilSettings); |
178 SkASSERT(!fHWPathStencilSettings.isTwoSided()); | 176 SkASSERT(!fHWPathStencilSettings.isTwoSided()); |
179 | 177 |
180 const SkStrokeRec& stroke = path->getStroke(); | 178 GrGLenum fillMode = gr_stencil_op_to_gl_path_rendering_fill_mode( |
181 | 179 fHWPathStencilSettings.passOp(GrStencilSettings::kFront_Face)); |
182 GrGLenum fillMode = | |
183 gr_stencil_op_to_gl_path_rendering_fill_mode(fHWPathStencilSettings.pass
Op(GrStencilSettings::kFront_Face)); | |
184 GrGLint writeMask = fHWPathStencilSettings.writeMask(GrStencilSettings::kFro
nt_Face); | 180 GrGLint writeMask = fHWPathStencilSettings.writeMask(GrStencilSettings::kFro
nt_Face); |
185 | 181 |
186 if (stroke.needToApply()) { | 182 if (glPath->shouldStroke()) { |
187 if (SkStrokeRec::kStrokeAndFill_Style == stroke.getStyle()) { | 183 if (glPath->shouldFill()) { |
188 GL_CALL(StencilFillPath(id, fillMode, writeMask)); | 184 GL_CALL(StencilFillPath(glPath->pathID(), fillMode, writeMask)); |
189 } | 185 } |
190 this->stencilThenCoverStrokePath(id, 0xffff, writeMask, GR_GL_BOUNDING_B
OX); | 186 this->stencilThenCoverStrokePath(glPath->pathID(), 0xffff, writeMask, GR
_GL_BOUNDING_BOX); |
191 } else { | 187 } else { |
192 this->stencilThenCoverFillPath(id, fillMode, writeMask, GR_GL_BOUNDING_B
OX); | 188 this->stencilThenCoverFillPath(glPath->pathID(), fillMode, writeMask, GR
_GL_BOUNDING_BOX); |
193 } | 189 } |
194 } | 190 } |
195 | 191 |
196 void GrGLPathRendering::drawPaths(const GrPathRange* pathRange, | 192 void GrGLPathRendering::drawPaths(const GrPathRange* pathRange, |
197 const void* indices, PathIndexType indexType, | 193 const void* indices, PathIndexType indexType, |
198 const float transformValues[], PathTransformTy
pe transformType, | 194 const float transformValues[], PathTransformTy
pe transformType, |
199 int count, const GrStencilSettings& stencilSet
tings) { | 195 int count, const GrStencilSettings& stencilSet
tings) { |
200 SkASSERT(fGpu->caps()->shaderCaps()->pathRenderingSupport()); | 196 SkASSERT(fGpu->caps()->shaderCaps()->pathRenderingSupport()); |
201 | 197 |
202 GrGLuint baseID = static_cast<const GrGLPathRange*>(pathRange)->basePathID()
; | 198 const GrGLPathRange* glPathRange = static_cast<const GrGLPathRange*>(pathRan
ge); |
203 | 199 |
204 this->flushPathStencilSettings(stencilSettings); | 200 this->flushPathStencilSettings(stencilSettings); |
205 SkASSERT(!fHWPathStencilSettings.isTwoSided()); | 201 SkASSERT(!fHWPathStencilSettings.isTwoSided()); |
206 | 202 |
207 const SkStrokeRec& stroke = pathRange->getStroke(); | |
208 | |
209 GrGLenum fillMode = | 203 GrGLenum fillMode = |
210 gr_stencil_op_to_gl_path_rendering_fill_mode( | 204 gr_stencil_op_to_gl_path_rendering_fill_mode( |
211 fHWPathStencilSettings.passOp(GrStencilSettings::kFront_Face)); | 205 fHWPathStencilSettings.passOp(GrStencilSettings::kFront_Face)); |
212 GrGLint writeMask = | 206 GrGLint writeMask = |
213 fHWPathStencilSettings.writeMask(GrStencilSettings::kFront_Face); | 207 fHWPathStencilSettings.writeMask(GrStencilSettings::kFront_Face); |
214 | 208 |
215 if (stroke.needToApply()) { | 209 if (glPathRange->shouldStroke()) { |
216 if (SkStrokeRec::kStrokeAndFill_Style == stroke.getStyle()) { | 210 if (glPathRange->shouldFill()) { |
217 GL_CALL(StencilFillPathInstanced( | 211 GL_CALL(StencilFillPathInstanced( |
218 count, gIndexType2GLType[indexType], indices, baseID
, fillMode, | 212 count, gIndexType2GLType[indexType], indices, glPath
Range->basePathID(), |
219 writeMask, gXformType2GLType[transformType], transfo
rmValues)); | 213 fillMode, writeMask, gXformType2GLType[transformType
], |
| 214 transformValues)); |
220 } | 215 } |
221 this->stencilThenCoverStrokePathInstanced( | 216 this->stencilThenCoverStrokePathInstanced( |
222 count, gIndexType2GLType[indexType], indices, baseID
, | 217 count, gIndexType2GLType[indexType], indices, glPath
Range->basePathID(), |
223 0xffff, writeMask, GR_GL_BOUNDING_BOX_OF_BOUNDING_BO
XES, | 218 0xffff, writeMask, GR_GL_BOUNDING_BOX_OF_BOUNDING_BO
XES, |
224 gXformType2GLType[transformType], transformValues); | 219 gXformType2GLType[transformType], transformValues); |
225 } else { | 220 } else { |
226 this->stencilThenCoverFillPathInstanced( | 221 this->stencilThenCoverFillPathInstanced( |
227 count, gIndexType2GLType[indexType], indices, baseID
, | 222 count, gIndexType2GLType[indexType], indices, glPath
Range->basePathID(), |
228 fillMode, writeMask, GR_GL_BOUNDING_BOX_OF_BOUNDING_
BOXES, | 223 fillMode, writeMask, GR_GL_BOUNDING_BOX_OF_BOUNDING_
BOXES, |
229 gXformType2GLType[transformType], transformValues); | 224 gXformType2GLType[transformType], transformValues); |
230 } | 225 } |
231 } | 226 } |
232 | 227 |
233 void GrGLPathRendering::setProgramPathFragmentInputTransform(GrGLuint program, G
rGLint location, | 228 void GrGLPathRendering::setProgramPathFragmentInputTransform(GrGLuint program, G
rGLint location, |
234 GrGLenum genMode, G
rGLint components, | 229 GrGLenum genMode, G
rGLint components, |
235 const SkMatrix& mat
rix) { | 230 const SkMatrix& mat
rix) { |
236 SkASSERT(caps().fragmentInputGenSupport); | 231 SkASSERT(caps().fragmentInputGenSupport); |
237 GrGLfloat coefficients[3 * 3]; | 232 GrGLfloat coefficients[3 * 3]; |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 reference, mask, coverMode,
transformType, | 380 reference, mask, coverMode,
transformType, |
386 transformValues)); | 381 transformValues)); |
387 return; | 382 return; |
388 } | 383 } |
389 | 384 |
390 GL_CALL(StencilStrokePathInstanced(numPaths, pathNameType, paths, pathBase, | 385 GL_CALL(StencilStrokePathInstanced(numPaths, pathNameType, paths, pathBase, |
391 reference, mask, transformType, transform
Values)); | 386 reference, mask, transformType, transform
Values)); |
392 GL_CALL(CoverStrokePathInstanced(numPaths, pathNameType, paths, pathBase, | 387 GL_CALL(CoverStrokePathInstanced(numPaths, pathNameType, paths, pathBase, |
393 coverMode, transformType, transformValues))
; | 388 coverMode, transformType, transformValues))
; |
394 } | 389 } |
OLD | NEW |