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/GrGLUtil.h" | 9 #include "gl/GrGLUtil.h" |
10 #include "gl/GrGLGpu.h" | 10 #include "gl/GrGLGpu.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 GR_GL_TRANSPOSE_AFFINE_2D | 42 GR_GL_TRANSPOSE_AFFINE_2D |
43 }; | 43 }; |
44 | 44 |
45 GR_STATIC_ASSERT(0 == GrPathRendering::kNone_PathTransformType); | 45 GR_STATIC_ASSERT(0 == GrPathRendering::kNone_PathTransformType); |
46 GR_STATIC_ASSERT(1 == GrPathRendering::kTranslateX_PathTransformType); | 46 GR_STATIC_ASSERT(1 == GrPathRendering::kTranslateX_PathTransformType); |
47 GR_STATIC_ASSERT(2 == GrPathRendering::kTranslateY_PathTransformType); | 47 GR_STATIC_ASSERT(2 == GrPathRendering::kTranslateY_PathTransformType); |
48 GR_STATIC_ASSERT(3 == GrPathRendering::kTranslate_PathTransformType); | 48 GR_STATIC_ASSERT(3 == GrPathRendering::kTranslate_PathTransformType); |
49 GR_STATIC_ASSERT(4 == GrPathRendering::kAffine_PathTransformType); | 49 GR_STATIC_ASSERT(4 == GrPathRendering::kAffine_PathTransformType); |
50 GR_STATIC_ASSERT(GrPathRendering::kAffine_PathTransformType == GrPathRendering::
kLast_PathTransformType); | 50 GR_STATIC_ASSERT(GrPathRendering::kAffine_PathTransformType == GrPathRendering::
kLast_PathTransformType); |
51 | 51 |
| 52 #ifdef SK_DEBUG |
| 53 static const GrGLenum gXformType2ComponentCount[] = { |
| 54 0, |
| 55 1, |
| 56 1, |
| 57 2, |
| 58 6 |
| 59 }; |
| 60 |
| 61 static void verify_floats(const float* floats, int count) { |
| 62 for (int i = 0; i < count; ++i) { |
| 63 SkASSERT(!SkScalarIsNaN(SkFloatToScalar(floats[i]))); |
| 64 } |
| 65 } |
| 66 #endif |
| 67 |
52 static GrGLenum gr_stencil_op_to_gl_path_rendering_fill_mode(GrStencilOp op) { | 68 static GrGLenum gr_stencil_op_to_gl_path_rendering_fill_mode(GrStencilOp op) { |
53 switch (op) { | 69 switch (op) { |
54 default: | 70 default: |
55 SkFAIL("Unexpected path fill."); | 71 SkFAIL("Unexpected path fill."); |
56 /* fallthrough */; | 72 /* fallthrough */; |
57 case kIncClamp_StencilOp: | 73 case kIncClamp_StencilOp: |
58 return GR_GL_COUNT_UP; | 74 return GR_GL_COUNT_UP; |
59 case kInvert_StencilOp: | 75 case kInvert_StencilOp: |
60 return GR_GL_INVERT; | 76 return GR_GL_INVERT; |
61 } | 77 } |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 } else { | 164 } else { |
149 GL_CALL(StencilThenCoverFillPath(glPath->pathID(), fillMode, writeMask, | 165 GL_CALL(StencilThenCoverFillPath(glPath->pathID(), fillMode, writeMask, |
150 GR_GL_BOUNDING_BOX)); | 166 GR_GL_BOUNDING_BOX)); |
151 } | 167 } |
152 } | 168 } |
153 | 169 |
154 void GrGLPathRendering::onDrawPaths(const DrawPathArgs& args, const GrPathRange*
pathRange, | 170 void GrGLPathRendering::onDrawPaths(const DrawPathArgs& args, const GrPathRange*
pathRange, |
155 const void* indices, PathIndexType indexType
, | 171 const void* indices, PathIndexType indexType
, |
156 const float transformValues[], PathTransform
Type transformType, | 172 const float transformValues[], PathTransform
Type transformType, |
157 int count) { | 173 int count) { |
| 174 SkDEBUGCODE(verify_floats(transformValues, gXformType2ComponentCount[transfo
rmType] * count)); |
| 175 |
158 if (!this->gpu()->flushGLState(args)) { | 176 if (!this->gpu()->flushGLState(args)) { |
159 return; | 177 return; |
160 } | 178 } |
161 this->flushPathStencilSettings(*args.fStencil); | 179 this->flushPathStencilSettings(*args.fStencil); |
162 SkASSERT(!fHWPathStencilSettings.isTwoSided()); | 180 SkASSERT(!fHWPathStencilSettings.isTwoSided()); |
163 | 181 |
164 | 182 |
165 const GrGLPathRange* glPathRange = static_cast<const GrGLPathRange*>(pathRan
ge); | 183 const GrGLPathRange* glPathRange = static_cast<const GrGLPathRange*>(pathRan
ge); |
166 | 184 |
167 GrGLenum fillMode = | 185 GrGLenum fillMode = |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 coefficients[3] = SkScalarToFloat(matrix[SkMatrix::kMSkewY]); | 221 coefficients[3] = SkScalarToFloat(matrix[SkMatrix::kMSkewY]); |
204 coefficients[4] = SkScalarToFloat(matrix[SkMatrix::kMScaleY]); | 222 coefficients[4] = SkScalarToFloat(matrix[SkMatrix::kMScaleY]); |
205 coefficients[5] = SkScalarToFloat(matrix[SkMatrix::kMTransY]); | 223 coefficients[5] = SkScalarToFloat(matrix[SkMatrix::kMTransY]); |
206 } | 224 } |
207 | 225 |
208 if (components >= 3) { | 226 if (components >= 3) { |
209 coefficients[6] = SkScalarToFloat(matrix[SkMatrix::kMPersp0]); | 227 coefficients[6] = SkScalarToFloat(matrix[SkMatrix::kMPersp0]); |
210 coefficients[7] = SkScalarToFloat(matrix[SkMatrix::kMPersp1]); | 228 coefficients[7] = SkScalarToFloat(matrix[SkMatrix::kMPersp1]); |
211 coefficients[8] = SkScalarToFloat(matrix[SkMatrix::kMPersp2]); | 229 coefficients[8] = SkScalarToFloat(matrix[SkMatrix::kMPersp2]); |
212 } | 230 } |
| 231 SkDEBUGCODE(verify_floats(coefficients, components * 3)); |
213 | 232 |
214 GL_CALL(ProgramPathFragmentInputGen(program, location, genMode, components,
coefficients)); | 233 GL_CALL(ProgramPathFragmentInputGen(program, location, genMode, components,
coefficients)); |
215 } | 234 } |
216 | 235 |
217 void GrGLPathRendering::setProjectionMatrix(const SkMatrix& matrix, | 236 void GrGLPathRendering::setProjectionMatrix(const SkMatrix& matrix, |
218 const SkISize& renderTargetSize, | 237 const SkISize& renderTargetSize, |
219 GrSurfaceOrigin renderTargetOrigin)
{ | 238 GrSurfaceOrigin renderTargetOrigin)
{ |
220 | 239 |
221 SkASSERT(this->gpu()->glCaps().shaderCaps()->pathRenderingSupport()); | 240 SkASSERT(this->gpu()->glCaps().shaderCaps()->pathRenderingSupport()); |
222 | 241 |
223 if (renderTargetOrigin == fHWProjectionMatrixState.fRenderTargetOrigin && | 242 if (renderTargetOrigin == fHWProjectionMatrixState.fRenderTargetOrigin && |
224 renderTargetSize == fHWProjectionMatrixState.fRenderTargetSize && | 243 renderTargetSize == fHWProjectionMatrixState.fRenderTargetSize && |
225 matrix.cheapEqualTo(fHWProjectionMatrixState.fViewMatrix)) { | 244 matrix.cheapEqualTo(fHWProjectionMatrixState.fViewMatrix)) { |
226 return; | 245 return; |
227 } | 246 } |
228 | 247 |
229 fHWProjectionMatrixState.fViewMatrix = matrix; | 248 fHWProjectionMatrixState.fViewMatrix = matrix; |
230 fHWProjectionMatrixState.fRenderTargetSize = renderTargetSize; | 249 fHWProjectionMatrixState.fRenderTargetSize = renderTargetSize; |
231 fHWProjectionMatrixState.fRenderTargetOrigin = renderTargetOrigin; | 250 fHWProjectionMatrixState.fRenderTargetOrigin = renderTargetOrigin; |
232 | 251 |
233 float glMatrix[4 * 4]; | 252 float glMatrix[4 * 4]; |
234 fHWProjectionMatrixState.getRTAdjustedGLMatrix<4>(glMatrix); | 253 fHWProjectionMatrixState.getRTAdjustedGLMatrix<4>(glMatrix); |
| 254 SkDEBUGCODE(verify_floats(glMatrix, SK_ARRAY_COUNT(glMatrix))); |
235 GL_CALL(MatrixLoadf(GR_GL_PATH_PROJECTION, glMatrix)); | 255 GL_CALL(MatrixLoadf(GR_GL_PATH_PROJECTION, glMatrix)); |
236 } | 256 } |
237 | 257 |
238 GrGLuint GrGLPathRendering::genPaths(GrGLsizei range) { | 258 GrGLuint GrGLPathRendering::genPaths(GrGLsizei range) { |
239 SkASSERT(range > 0); | 259 SkASSERT(range > 0); |
240 GrGLuint firstID; | 260 GrGLuint firstID; |
241 if (fPreallocatedPathCount >= range) { | 261 if (fPreallocatedPathCount >= range) { |
242 firstID = fFirstPreallocatedPathID; | 262 firstID = fFirstPreallocatedPathID; |
243 fPreallocatedPathCount -= range; | 263 fPreallocatedPathCount -= range; |
244 fFirstPreallocatedPathID += range; | 264 fFirstPreallocatedPathID += range; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 funcMask != fHWPathStencilSettings.funcMask(kFront_Face)) { | 325 funcMask != fHWPathStencilSettings.funcMask(kFront_Face)) { |
306 GL_CALL(PathStencilFunc(GrToGLStencilFunc(func), funcRef, funcMask))
; | 326 GL_CALL(PathStencilFunc(GrToGLStencilFunc(func), funcRef, funcMask))
; |
307 } | 327 } |
308 fHWPathStencilSettings = stencilSettings; | 328 fHWPathStencilSettings = stencilSettings; |
309 } | 329 } |
310 } | 330 } |
311 | 331 |
312 inline GrGLGpu* GrGLPathRendering::gpu() { | 332 inline GrGLGpu* GrGLPathRendering::gpu() { |
313 return static_cast<GrGLGpu*>(fGpu); | 333 return static_cast<GrGLGpu*>(fGpu); |
314 } | 334 } |
OLD | NEW |