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( | |
175 verify_floats(transformValues, gXformType2ComponentCount[transformType] * count)); | |
176 | |
158 if (!this->gpu()->flushGLState(args)) { | 177 if (!this->gpu()->flushGLState(args)) { |
159 return; | 178 return; |
160 } | 179 } |
161 this->flushPathStencilSettings(*args.fStencil); | 180 this->flushPathStencilSettings(*args.fStencil); |
162 SkASSERT(!fHWPathStencilSettings.isTwoSided()); | 181 SkASSERT(!fHWPathStencilSettings.isTwoSided()); |
163 | 182 |
164 | 183 |
165 const GrGLPathRange* glPathRange = static_cast<const GrGLPathRange*>(pathRan ge); | 184 const GrGLPathRange* glPathRange = static_cast<const GrGLPathRange*>(pathRan ge); |
166 | 185 |
167 GrGLenum fillMode = | 186 GrGLenum fillMode = |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
203 coefficients[3] = SkScalarToFloat(matrix[SkMatrix::kMSkewY]); | 222 coefficients[3] = SkScalarToFloat(matrix[SkMatrix::kMSkewY]); |
204 coefficients[4] = SkScalarToFloat(matrix[SkMatrix::kMScaleY]); | 223 coefficients[4] = SkScalarToFloat(matrix[SkMatrix::kMScaleY]); |
205 coefficients[5] = SkScalarToFloat(matrix[SkMatrix::kMTransY]); | 224 coefficients[5] = SkScalarToFloat(matrix[SkMatrix::kMTransY]); |
206 } | 225 } |
207 | 226 |
208 if (components >= 3) { | 227 if (components >= 3) { |
209 coefficients[6] = SkScalarToFloat(matrix[SkMatrix::kMPersp0]); | 228 coefficients[6] = SkScalarToFloat(matrix[SkMatrix::kMPersp0]); |
210 coefficients[7] = SkScalarToFloat(matrix[SkMatrix::kMPersp1]); | 229 coefficients[7] = SkScalarToFloat(matrix[SkMatrix::kMPersp1]); |
211 coefficients[8] = SkScalarToFloat(matrix[SkMatrix::kMPersp2]); | 230 coefficients[8] = SkScalarToFloat(matrix[SkMatrix::kMPersp2]); |
212 } | 231 } |
232 SkDEBUGCODE( | |
jvanverth1
2016/03/03 15:29:06
Is there a reason this (and the change below it) i
Kimmo Kinnunen
2016/03/04 08:03:07
Done.
| |
233 verify_floats(coefficients, components * 3)); | |
213 | 234 |
214 GL_CALL(ProgramPathFragmentInputGen(program, location, genMode, components, coefficients)); | 235 GL_CALL(ProgramPathFragmentInputGen(program, location, genMode, components, coefficients)); |
215 } | 236 } |
216 | 237 |
217 void GrGLPathRendering::setProjectionMatrix(const SkMatrix& matrix, | 238 void GrGLPathRendering::setProjectionMatrix(const SkMatrix& matrix, |
218 const SkISize& renderTargetSize, | 239 const SkISize& renderTargetSize, |
219 GrSurfaceOrigin renderTargetOrigin) { | 240 GrSurfaceOrigin renderTargetOrigin) { |
220 | 241 |
221 SkASSERT(this->gpu()->glCaps().shaderCaps()->pathRenderingSupport()); | 242 SkASSERT(this->gpu()->glCaps().shaderCaps()->pathRenderingSupport()); |
222 | 243 |
223 if (renderTargetOrigin == fHWProjectionMatrixState.fRenderTargetOrigin && | 244 if (renderTargetOrigin == fHWProjectionMatrixState.fRenderTargetOrigin && |
224 renderTargetSize == fHWProjectionMatrixState.fRenderTargetSize && | 245 renderTargetSize == fHWProjectionMatrixState.fRenderTargetSize && |
225 matrix.cheapEqualTo(fHWProjectionMatrixState.fViewMatrix)) { | 246 matrix.cheapEqualTo(fHWProjectionMatrixState.fViewMatrix)) { |
226 return; | 247 return; |
227 } | 248 } |
228 | 249 |
229 fHWProjectionMatrixState.fViewMatrix = matrix; | 250 fHWProjectionMatrixState.fViewMatrix = matrix; |
230 fHWProjectionMatrixState.fRenderTargetSize = renderTargetSize; | 251 fHWProjectionMatrixState.fRenderTargetSize = renderTargetSize; |
231 fHWProjectionMatrixState.fRenderTargetOrigin = renderTargetOrigin; | 252 fHWProjectionMatrixState.fRenderTargetOrigin = renderTargetOrigin; |
232 | 253 |
233 float glMatrix[4 * 4]; | 254 float glMatrix[4 * 4]; |
234 fHWProjectionMatrixState.getRTAdjustedGLMatrix<4>(glMatrix); | 255 fHWProjectionMatrixState.getRTAdjustedGLMatrix<4>(glMatrix); |
256 SkDEBUGCODE( | |
257 verify_floats(glMatrix, SK_ARRAY_COUNT(glMatrix))); | |
235 GL_CALL(MatrixLoadf(GR_GL_PATH_PROJECTION, glMatrix)); | 258 GL_CALL(MatrixLoadf(GR_GL_PATH_PROJECTION, glMatrix)); |
236 } | 259 } |
237 | 260 |
238 GrGLuint GrGLPathRendering::genPaths(GrGLsizei range) { | 261 GrGLuint GrGLPathRendering::genPaths(GrGLsizei range) { |
239 SkASSERT(range > 0); | 262 SkASSERT(range > 0); |
240 GrGLuint firstID; | 263 GrGLuint firstID; |
241 if (fPreallocatedPathCount >= range) { | 264 if (fPreallocatedPathCount >= range) { |
242 firstID = fFirstPreallocatedPathID; | 265 firstID = fFirstPreallocatedPathID; |
243 fPreallocatedPathCount -= range; | 266 fPreallocatedPathCount -= range; |
244 fFirstPreallocatedPathID += range; | 267 fFirstPreallocatedPathID += range; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
305 funcMask != fHWPathStencilSettings.funcMask(kFront_Face)) { | 328 funcMask != fHWPathStencilSettings.funcMask(kFront_Face)) { |
306 GL_CALL(PathStencilFunc(GrToGLStencilFunc(func), funcRef, funcMask)) ; | 329 GL_CALL(PathStencilFunc(GrToGLStencilFunc(func), funcRef, funcMask)) ; |
307 } | 330 } |
308 fHWPathStencilSettings = stencilSettings; | 331 fHWPathStencilSettings = stencilSettings; |
309 } | 332 } |
310 } | 333 } |
311 | 334 |
312 inline GrGLGpu* GrGLPathRendering::gpu() { | 335 inline GrGLGpu* GrGLPathRendering::gpu() { |
313 return static_cast<GrGLGpu*>(fGpu); | 336 return static_cast<GrGLGpu*>(fGpu); |
314 } | 337 } |
OLD | NEW |