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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 fCaps.stencilThenCoverSupport = | 65 fCaps.stencilThenCoverSupport = |
66 NULL != glInterface->fFunctions.fStencilThenCoverFillPath && | 66 NULL != glInterface->fFunctions.fStencilThenCoverFillPath && |
67 NULL != glInterface->fFunctions.fStencilThenCoverStrokePath && | 67 NULL != glInterface->fFunctions.fStencilThenCoverStrokePath && |
68 NULL != glInterface->fFunctions.fStencilThenCoverFillPathInstanced && | 68 NULL != glInterface->fFunctions.fStencilThenCoverFillPathInstanced && |
69 NULL != glInterface->fFunctions.fStencilThenCoverStrokePathInstanced; | 69 NULL != glInterface->fFunctions.fStencilThenCoverStrokePathInstanced; |
70 fCaps.fragmentInputGenSupport = | 70 fCaps.fragmentInputGenSupport = |
71 NULL != glInterface->fFunctions.fProgramPathFragmentInputGen; | 71 NULL != glInterface->fFunctions.fProgramPathFragmentInputGen; |
72 fCaps.glyphLoadingSupport = | 72 fCaps.glyphLoadingSupport = |
73 NULL != glInterface->fFunctions.fPathMemoryGlyphIndexArray; | 73 NULL != glInterface->fFunctions.fPathMemoryGlyphIndexArray; |
74 | 74 |
75 if (!fCaps.fragmentInputGenSupport) { | 75 SkASSERT(fCaps.fragmentInputGenSupport); |
76 fHWPathTexGenSettings.reset(fGpu->glCaps().maxFixedFunctionTextureCoords
()); | |
77 } | |
78 } | 76 } |
79 | 77 |
80 GrGLPathRendering::~GrGLPathRendering() { | 78 GrGLPathRendering::~GrGLPathRendering() { |
81 } | 79 } |
82 | 80 |
83 void GrGLPathRendering::abandonGpuResources() { | 81 void GrGLPathRendering::abandonGpuResources() { |
84 fPathNameAllocator.reset(NULL); | 82 fPathNameAllocator.reset(NULL); |
85 } | 83 } |
86 | 84 |
87 void GrGLPathRendering::resetContext() { | 85 void GrGLPathRendering::resetContext() { |
88 fHWProjectionMatrixState.invalidate(); | 86 fHWProjectionMatrixState.invalidate(); |
89 // we don't use the model view matrix. | 87 // we don't use the model view matrix. |
90 GrGLenum matrixMode = | 88 GL_CALL(MatrixLoadIdentity(GR_GL_PATH_MODELVIEW)); |
91 fGpu->glCaps().nvprSupport() == GrGLCaps::kNormal_NvprSupport ? GR_G
L_PATH_MODELVIEW : | |
92 GR_G
L_MODELVIEW; | |
93 GL_CALL(MatrixLoadIdentity(matrixMode)); | |
94 | 89 |
95 if (!caps().fragmentInputGenSupport) { | 90 SkASSERT(fCaps.fragmentInputGenSupport); |
96 for (int i = 0; i < fGpu->glCaps().maxFixedFunctionTextureCoords(); ++i)
{ | |
97 GL_CALL(PathTexGen(GR_GL_TEXTURE0 + i, GR_GL_NONE, 0, NULL)); | |
98 fHWPathTexGenSettings[i].fMode = GR_GL_NONE; | |
99 fHWPathTexGenSettings[i].fNumComponents = 0; | |
100 } | |
101 fHWActivePathTexGenSets = 0; | |
102 } | |
103 fHWPathStencilSettings.invalidate(); | 91 fHWPathStencilSettings.invalidate(); |
104 } | 92 } |
105 | 93 |
106 GrPath* GrGLPathRendering::createPath(const SkPath& inPath, const SkStrokeRec& s
troke) { | 94 GrPath* GrGLPathRendering::createPath(const SkPath& inPath, const SkStrokeRec& s
troke) { |
107 return SkNEW_ARGS(GrGLPath, (fGpu, inPath, stroke)); | 95 return SkNEW_ARGS(GrGLPath, (fGpu, inPath, stroke)); |
108 } | 96 } |
109 | 97 |
110 GrPathRange* GrGLPathRendering::createPathRange(GrPathRange::PathGenerator* path
Generator, | 98 GrPathRange* GrGLPathRendering::createPathRange(GrPathRange::PathGenerator* path
Generator, |
111 const SkStrokeRec& stroke) { | 99 const SkStrokeRec& stroke) { |
112 return SkNEW_ARGS(GrGLPathRange, (fGpu, pathGenerator, stroke)); | 100 return SkNEW_ARGS(GrGLPathRange, (fGpu, pathGenerator, stroke)); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 0xffff, writeMask, GR_GL_BOUNDING_BOX_OF_BOUNDING_BO
XES, | 223 0xffff, writeMask, GR_GL_BOUNDING_BOX_OF_BOUNDING_BO
XES, |
236 gXformType2GLType[transformType], transformValues); | 224 gXformType2GLType[transformType], transformValues); |
237 } else { | 225 } else { |
238 this->stencilThenCoverFillPathInstanced( | 226 this->stencilThenCoverFillPathInstanced( |
239 count, gIndexType2GLType[indexType], indices, baseID
, | 227 count, gIndexType2GLType[indexType], indices, baseID
, |
240 fillMode, writeMask, GR_GL_BOUNDING_BOX_OF_BOUNDING_
BOXES, | 228 fillMode, writeMask, GR_GL_BOUNDING_BOX_OF_BOUNDING_
BOXES, |
241 gXformType2GLType[transformType], transformValues); | 229 gXformType2GLType[transformType], transformValues); |
242 } | 230 } |
243 } | 231 } |
244 | 232 |
245 void GrGLPathRendering::enablePathTexGen(int unitIdx, PathTexGenComponents compo
nents, | |
246 const GrGLfloat* coefficients) { | |
247 SkASSERT(components >= kS_PathTexGenComponents && | |
248 components <= kSTR_PathTexGenComponents); | |
249 SkASSERT(fGpu->glCaps().maxFixedFunctionTextureCoords() >= unitIdx); | |
250 | |
251 if (GR_GL_OBJECT_LINEAR == fHWPathTexGenSettings[unitIdx].fMode && | |
252 components == fHWPathTexGenSettings[unitIdx].fNumComponents && | |
253 !memcmp(coefficients, fHWPathTexGenSettings[unitIdx].fCoefficients, | |
254 3 * components * sizeof(GrGLfloat))) { | |
255 return; | |
256 } | |
257 | |
258 fGpu->setTextureUnit(unitIdx); | |
259 | |
260 fHWPathTexGenSettings[unitIdx].fNumComponents = components; | |
261 GL_CALL(PathTexGen(GR_GL_TEXTURE0 + unitIdx, GR_GL_OBJECT_LINEAR, components
, coefficients)); | |
262 | |
263 memcpy(fHWPathTexGenSettings[unitIdx].fCoefficients, coefficients, | |
264 3 * components * sizeof(GrGLfloat)); | |
265 } | |
266 | |
267 void GrGLPathRendering::enablePathTexGen(int unitIdx, PathTexGenComponents compo
nents, | |
268 const SkMatrix& matrix) { | |
269 GrGLfloat coefficients[3 * 3]; | |
270 SkASSERT(components >= kS_PathTexGenComponents && | |
271 components <= kSTR_PathTexGenComponents); | |
272 | |
273 coefficients[0] = SkScalarToFloat(matrix[SkMatrix::kMScaleX]); | |
274 coefficients[1] = SkScalarToFloat(matrix[SkMatrix::kMSkewX]); | |
275 coefficients[2] = SkScalarToFloat(matrix[SkMatrix::kMTransX]); | |
276 | |
277 if (components >= kST_PathTexGenComponents) { | |
278 coefficients[3] = SkScalarToFloat(matrix[SkMatrix::kMSkewY]); | |
279 coefficients[4] = SkScalarToFloat(matrix[SkMatrix::kMScaleY]); | |
280 coefficients[5] = SkScalarToFloat(matrix[SkMatrix::kMTransY]); | |
281 } | |
282 | |
283 if (components >= kSTR_PathTexGenComponents) { | |
284 coefficients[6] = SkScalarToFloat(matrix[SkMatrix::kMPersp0]); | |
285 coefficients[7] = SkScalarToFloat(matrix[SkMatrix::kMPersp1]); | |
286 coefficients[8] = SkScalarToFloat(matrix[SkMatrix::kMPersp2]); | |
287 } | |
288 | |
289 this->enablePathTexGen(unitIdx, components, coefficients); | |
290 } | |
291 | |
292 void GrGLPathRendering::flushPathTexGenSettings(int numUsedTexCoordSets) { | |
293 SkASSERT(fGpu->glCaps().maxFixedFunctionTextureCoords() >= numUsedTexCoordSe
ts); | |
294 | |
295 // Only write the inactive path tex gens, since active path tex gens were | |
296 // written when they were enabled. | |
297 | |
298 SkDEBUGCODE( | |
299 for (int i = 0; i < numUsedTexCoordSets; i++) { | |
300 SkASSERT(0 != fHWPathTexGenSettings[i].fNumComponents); | |
301 } | |
302 ); | |
303 | |
304 for (int i = numUsedTexCoordSets; i < fHWActivePathTexGenSets; i++) { | |
305 SkASSERT(0 != fHWPathTexGenSettings[i].fNumComponents); | |
306 | |
307 fGpu->setTextureUnit(i); | |
308 GL_CALL(PathTexGen(GR_GL_TEXTURE0 + i, GR_GL_NONE, 0, NULL)); | |
309 fHWPathTexGenSettings[i].fNumComponents = 0; | |
310 } | |
311 | |
312 fHWActivePathTexGenSets = numUsedTexCoordSets; | |
313 } | |
314 | |
315 void GrGLPathRendering::setProgramPathFragmentInputTransform(GrGLuint program, G
rGLint location, | 233 void GrGLPathRendering::setProgramPathFragmentInputTransform(GrGLuint program, G
rGLint location, |
316 GrGLenum genMode, G
rGLint components, | 234 GrGLenum genMode, G
rGLint components, |
317 const SkMatrix& mat
rix) { | 235 const SkMatrix& mat
rix) { |
318 SkASSERT(caps().fragmentInputGenSupport); | 236 SkASSERT(caps().fragmentInputGenSupport); |
319 GrGLfloat coefficients[3 * 3]; | 237 GrGLfloat coefficients[3 * 3]; |
320 SkASSERT(components >= 1 && components <= 3); | 238 SkASSERT(components >= 1 && components <= 3); |
321 | 239 |
322 coefficients[0] = SkScalarToFloat(matrix[SkMatrix::kMScaleX]); | 240 coefficients[0] = SkScalarToFloat(matrix[SkMatrix::kMScaleX]); |
323 coefficients[1] = SkScalarToFloat(matrix[SkMatrix::kMSkewX]); | 241 coefficients[1] = SkScalarToFloat(matrix[SkMatrix::kMSkewX]); |
324 coefficients[2] = SkScalarToFloat(matrix[SkMatrix::kMTransX]); | 242 coefficients[2] = SkScalarToFloat(matrix[SkMatrix::kMTransX]); |
(...skipping 24 matching lines...) Expand all Loading... |
349 matrix.cheapEqualTo(fHWProjectionMatrixState.fViewMatrix)) { | 267 matrix.cheapEqualTo(fHWProjectionMatrixState.fViewMatrix)) { |
350 return; | 268 return; |
351 } | 269 } |
352 | 270 |
353 fHWProjectionMatrixState.fViewMatrix = matrix; | 271 fHWProjectionMatrixState.fViewMatrix = matrix; |
354 fHWProjectionMatrixState.fRenderTargetSize = renderTargetSize; | 272 fHWProjectionMatrixState.fRenderTargetSize = renderTargetSize; |
355 fHWProjectionMatrixState.fRenderTargetOrigin = renderTargetOrigin; | 273 fHWProjectionMatrixState.fRenderTargetOrigin = renderTargetOrigin; |
356 | 274 |
357 GrGLfloat glMatrix[4 * 4]; | 275 GrGLfloat glMatrix[4 * 4]; |
358 fHWProjectionMatrixState.getRTAdjustedGLMatrix<4>(glMatrix); | 276 fHWProjectionMatrixState.getRTAdjustedGLMatrix<4>(glMatrix); |
359 GrGLenum matrixMode = | 277 GL_CALL(MatrixLoadf(GR_GL_PATH_PROJECTION, glMatrix)); |
360 fGpu->glCaps().nvprSupport() == GrGLCaps::kNormal_NvprSupport ? GR_
GL_PATH_PROJECTION : | |
361 GR_
GL_PROJECTION; | |
362 GL_CALL(MatrixLoadf(matrixMode, glMatrix)); | |
363 } | 278 } |
364 | 279 |
365 GrGLuint GrGLPathRendering::genPaths(GrGLsizei range) { | 280 GrGLuint GrGLPathRendering::genPaths(GrGLsizei range) { |
366 if (range > 1) { | 281 if (range > 1) { |
367 GrGLuint name; | 282 GrGLuint name; |
368 GL_CALL_RET(name, GenPaths(range)); | 283 GL_CALL_RET(name, GenPaths(range)); |
369 return name; | 284 return name; |
370 } | 285 } |
371 | 286 |
372 if (NULL == fPathNameAllocator.get()) { | 287 if (NULL == fPathNameAllocator.get()) { |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 reference, mask, coverMode,
transformType, | 385 reference, mask, coverMode,
transformType, |
471 transformValues)); | 386 transformValues)); |
472 return; | 387 return; |
473 } | 388 } |
474 | 389 |
475 GL_CALL(StencilStrokePathInstanced(numPaths, pathNameType, paths, pathBase, | 390 GL_CALL(StencilStrokePathInstanced(numPaths, pathNameType, paths, pathBase, |
476 reference, mask, transformType, transform
Values)); | 391 reference, mask, transformType, transform
Values)); |
477 GL_CALL(CoverStrokePathInstanced(numPaths, pathNameType, paths, pathBase, | 392 GL_CALL(CoverStrokePathInstanced(numPaths, pathNameType, paths, pathBase, |
478 coverMode, transformType, transformValues))
; | 393 coverMode, transformType, transformValues))
; |
479 } | 394 } |
OLD | NEW |