OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 | 8 |
9 #include "GrGpuGL.h" | 9 #include "GrGpuGL.h" |
10 #include "GrGLStencilBuffer.h" | 10 #include "GrGLStencilBuffer.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 static bool gPrintStartupSpew; | 113 static bool gPrintStartupSpew; |
114 | 114 |
115 GrGpuGL::GrGpuGL(const GrGLContext& ctx, GrContext* context) | 115 GrGpuGL::GrGpuGL(const GrGLContext& ctx, GrContext* context) |
116 : GrGpu(context) | 116 : GrGpu(context) |
117 , fGLContext(ctx) { | 117 , fGLContext(ctx) { |
118 | 118 |
119 SkASSERT(ctx.isInitialized()); | 119 SkASSERT(ctx.isInitialized()); |
120 fCaps.reset(SkRef(ctx.caps())); | 120 fCaps.reset(SkRef(ctx.caps())); |
121 | 121 |
122 fHWBoundTextures.reset(this->glCaps().maxFragmentTextureUnits()); | 122 fHWBoundTextures.reset(this->glCaps().maxFragmentTextureUnits()); |
123 fHWTexGenSettings.reset(this->glCaps().maxFixedFunctionTextureCoords()); | 123 fHWPathTexGenSettings.reset(this->glCaps().maxFixedFunctionTextureCoords()); |
124 | 124 |
125 GrGLClearErr(fGLContext.interface()); | 125 GrGLClearErr(fGLContext.interface()); |
126 if (gPrintStartupSpew) { | 126 if (gPrintStartupSpew) { |
127 const GrGLubyte* vendor; | 127 const GrGLubyte* vendor; |
128 const GrGLubyte* renderer; | 128 const GrGLubyte* renderer; |
129 const GrGLubyte* version; | 129 const GrGLubyte* version; |
130 GL_CALL_RET(vendor, GetString(GR_GL_VENDOR)); | 130 GL_CALL_RET(vendor, GetString(GR_GL_VENDOR)); |
131 GL_CALL_RET(renderer, GetString(GR_GL_RENDERER)); | 131 GL_CALL_RET(renderer, GetString(GR_GL_RENDERER)); |
132 GL_CALL_RET(version, GetString(GR_GL_VERSION)); | 132 GL_CALL_RET(version, GetString(GR_GL_VERSION)); |
133 GrPrintf("------------------------- create GrGpuGL %p --------------\n", | 133 GrPrintf("------------------------- create GrGpuGL %p --------------\n", |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 | 293 |
294 // Vertex | 294 // Vertex |
295 if (resetBits & kVertex_GrGLBackendState) { | 295 if (resetBits & kVertex_GrGLBackendState) { |
296 fHWGeometryState.invalidate(); | 296 fHWGeometryState.invalidate(); |
297 } | 297 } |
298 | 298 |
299 if (resetBits & kRenderTarget_GrGLBackendState) { | 299 if (resetBits & kRenderTarget_GrGLBackendState) { |
300 fHWBoundRenderTarget = NULL; | 300 fHWBoundRenderTarget = NULL; |
301 } | 301 } |
302 | 302 |
303 if (resetBits & (kFixedFunction_GrGLBackendState | kPathRendering_GrGLBacken
dState)) { | 303 if (resetBits & kPathRendering_GrGLBackendState) { |
304 if (this->glCaps().fixedFunctionSupport()) { | 304 if (this->caps()->pathRenderingSupport()) { |
305 fHWProjectionMatrixState.invalidate(); | 305 fHWProjectionMatrixState.invalidate(); |
306 // we don't use the model view matrix. | 306 // we don't use the model view matrix. |
307 GL_CALL(MatrixMode(GR_GL_MODELVIEW)); | 307 GL_CALL(MatrixMode(GR_GL_MODELVIEW)); |
308 GL_CALL(LoadIdentity()); | 308 GL_CALL(LoadIdentity()); |
309 | 309 |
310 for (int i = 0; i < this->glCaps().maxFixedFunctionTextureCoords();
++i) { | 310 for (int i = 0; i < this->glCaps().maxFixedFunctionTextureCoords();
++i) { |
311 GL_CALL(ActiveTexture(GR_GL_TEXTURE0 + i)); | 311 GL_CALL(PathTexGen(GR_GL_TEXTURE0 + i, GR_GL_NONE, 0, NULL)); |
312 GL_CALL(Disable(GR_GL_TEXTURE_GEN_S)); | 312 fHWPathTexGenSettings[i].fMode = GR_GL_NONE; |
313 GL_CALL(Disable(GR_GL_TEXTURE_GEN_T)); | 313 fHWPathTexGenSettings[i].fNumComponents = 0; |
314 GL_CALL(Disable(GR_GL_TEXTURE_GEN_Q)); | |
315 GL_CALL(Disable(GR_GL_TEXTURE_GEN_R)); | |
316 if (this->caps()->pathRenderingSupport()) { | |
317 GL_CALL(PathTexGen(GR_GL_TEXTURE0 + i, GR_GL_NONE, 0, NULL))
; | |
318 } | |
319 fHWTexGenSettings[i].fMode = GR_GL_NONE; | |
320 fHWTexGenSettings[i].fNumComponents = 0; | |
321 } | 314 } |
322 fHWActiveTexGenSets = 0; | 315 fHWActivePathTexGenSets = 0; |
323 } | 316 } |
324 if (this->caps()->pathRenderingSupport()) { | 317 fHWPathStencilSettings.invalidate(); |
325 fHWPathStencilSettings.invalidate(); | |
326 } | |
327 } | 318 } |
328 | 319 |
329 // we assume these values | 320 // we assume these values |
330 if (resetBits & kPixelStore_GrGLBackendState) { | 321 if (resetBits & kPixelStore_GrGLBackendState) { |
331 if (this->glCaps().unpackRowLengthSupport()) { | 322 if (this->glCaps().unpackRowLengthSupport()) { |
332 GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0)); | 323 GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0)); |
333 } | 324 } |
334 if (this->glCaps().packRowLengthSupport()) { | 325 if (this->glCaps().packRowLengthSupport()) { |
335 GL_CALL(PixelStorei(GR_GL_PACK_ROW_LENGTH, 0)); | 326 GL_CALL(PixelStorei(GR_GL_PACK_ROW_LENGTH, 0)); |
336 } | 327 } |
(...skipping 1886 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2223 GL_CALL(TexParameteriv(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_SWIZZLE_RGBA,
swizzle)); | 2214 GL_CALL(TexParameteriv(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_SWIZZLE_RGBA,
swizzle)); |
2224 } | 2215 } |
2225 } | 2216 } |
2226 texture->setCachedTexParams(newTexParams, this->getResetTimestamp()); | 2217 texture->setCachedTexParams(newTexParams, this->getResetTimestamp()); |
2227 } | 2218 } |
2228 | 2219 |
2229 void GrGpuGL::setProjectionMatrix(const SkMatrix& matrix, | 2220 void GrGpuGL::setProjectionMatrix(const SkMatrix& matrix, |
2230 const SkISize& renderTargetSize, | 2221 const SkISize& renderTargetSize, |
2231 GrSurfaceOrigin renderTargetOrigin) { | 2222 GrSurfaceOrigin renderTargetOrigin) { |
2232 | 2223 |
2233 SkASSERT(this->glCaps().fixedFunctionSupport()); | 2224 SkASSERT(this->glCaps().pathRenderingSupport()); |
2234 | 2225 |
2235 if (renderTargetOrigin == fHWProjectionMatrixState.fRenderTargetOrigin && | 2226 if (renderTargetOrigin == fHWProjectionMatrixState.fRenderTargetOrigin && |
2236 renderTargetSize == fHWProjectionMatrixState.fRenderTargetSize && | 2227 renderTargetSize == fHWProjectionMatrixState.fRenderTargetSize && |
2237 matrix.cheapEqualTo(fHWProjectionMatrixState.fViewMatrix)) { | 2228 matrix.cheapEqualTo(fHWProjectionMatrixState.fViewMatrix)) { |
2238 return; | 2229 return; |
2239 } | 2230 } |
2240 | 2231 |
2241 fHWProjectionMatrixState.fViewMatrix = matrix; | 2232 fHWProjectionMatrixState.fViewMatrix = matrix; |
2242 fHWProjectionMatrixState.fRenderTargetSize = renderTargetSize; | 2233 fHWProjectionMatrixState.fRenderTargetSize = renderTargetSize; |
2243 fHWProjectionMatrixState.fRenderTargetOrigin = renderTargetOrigin; | 2234 fHWProjectionMatrixState.fRenderTargetOrigin = renderTargetOrigin; |
2244 | 2235 |
2245 GrGLfloat glMatrix[4 * 4]; | 2236 GrGLfloat glMatrix[4 * 4]; |
2246 fHWProjectionMatrixState.getGLMatrix<4>(glMatrix); | 2237 fHWProjectionMatrixState.getGLMatrix<4>(glMatrix); |
2247 GL_CALL(MatrixMode(GR_GL_PROJECTION)); | 2238 GL_CALL(MatrixMode(GR_GL_PROJECTION)); |
2248 GL_CALL(LoadMatrixf(glMatrix)); | 2239 GL_CALL(LoadMatrixf(glMatrix)); |
2249 } | 2240 } |
2250 | 2241 |
2251 void GrGpuGL::enableTexGen(int unitIdx, | 2242 void GrGpuGL::enablePathTexGen(int unitIdx, |
2252 TexGenComponents components, | 2243 PathTexGenComponents components, |
2253 const GrGLfloat* coefficients) { | 2244 const GrGLfloat* coefficients) { |
2254 SkASSERT(this->glCaps().fixedFunctionSupport()); | 2245 SkASSERT(this->glCaps().pathRenderingSupport()); |
2255 SkASSERT(components >= kS_TexGenComponents && components <= kSTR_TexGenCompo
nents); | 2246 SkASSERT(components >= kS_PathTexGenComponents && |
| 2247 components <= kSTR_PathTexGenComponents); |
2256 SkASSERT(this->glCaps().maxFixedFunctionTextureCoords() >= unitIdx); | 2248 SkASSERT(this->glCaps().maxFixedFunctionTextureCoords() >= unitIdx); |
2257 | 2249 |
2258 if (GR_GL_OBJECT_LINEAR == fHWTexGenSettings[unitIdx].fMode && | 2250 if (GR_GL_OBJECT_LINEAR == fHWPathTexGenSettings[unitIdx].fMode && |
2259 components == fHWTexGenSettings[unitIdx].fNumComponents && | 2251 components == fHWPathTexGenSettings[unitIdx].fNumComponents && |
2260 !memcmp(coefficients, fHWTexGenSettings[unitIdx].fCoefficients, | 2252 !memcmp(coefficients, fHWPathTexGenSettings[unitIdx].fCoefficients, |
2261 3 * components * sizeof(GrGLfloat))) { | 2253 3 * components * sizeof(GrGLfloat))) { |
2262 return; | 2254 return; |
2263 } | 2255 } |
2264 | 2256 |
2265 this->setTextureUnit(unitIdx); | 2257 this->setTextureUnit(unitIdx); |
2266 | 2258 |
2267 if (GR_GL_OBJECT_LINEAR != fHWTexGenSettings[unitIdx].fMode) { | 2259 fHWPathTexGenSettings[unitIdx].fNumComponents = components; |
2268 for (int i = 0; i < 4; i++) { | 2260 GL_CALL(PathTexGen(GR_GL_TEXTURE0 + unitIdx, |
2269 GL_CALL(TexGeni(GR_GL_S + i, GR_GL_TEXTURE_GEN_MODE, GR_GL_OBJECT_LI
NEAR)); | 2261 GR_GL_OBJECT_LINEAR, |
2270 } | 2262 components, |
2271 fHWTexGenSettings[unitIdx].fMode = GR_GL_OBJECT_LINEAR; | 2263 coefficients)); |
2272 } | |
2273 | 2264 |
2274 for (int i = fHWTexGenSettings[unitIdx].fNumComponents; i < components; i++)
{ | 2265 memcpy(fHWPathTexGenSettings[unitIdx].fCoefficients, coefficients, |
2275 GL_CALL(Enable(GR_GL_TEXTURE_GEN_S + i)); | |
2276 } | |
2277 for (int i = components; i < fHWTexGenSettings[unitIdx].fNumComponents; i++)
{ | |
2278 GL_CALL(Disable(GR_GL_TEXTURE_GEN_S + i)); | |
2279 } | |
2280 fHWTexGenSettings[unitIdx].fNumComponents = components; | |
2281 | |
2282 for (int i = 0; i < components; i++) { | |
2283 GrGLfloat plane[] = {coefficients[0 + 3 * i], | |
2284 coefficients[1 + 3 * i], | |
2285 0, | |
2286 coefficients[2 + 3 * i]}; | |
2287 GL_CALL(TexGenfv(GR_GL_S + i, GR_GL_OBJECT_PLANE, plane)); | |
2288 } | |
2289 | |
2290 if (this->caps()->pathRenderingSupport()) { | |
2291 GL_CALL(PathTexGen(GR_GL_TEXTURE0 + unitIdx, | |
2292 GR_GL_OBJECT_LINEAR, | |
2293 components, | |
2294 coefficients)); | |
2295 } | |
2296 | |
2297 memcpy(fHWTexGenSettings[unitIdx].fCoefficients, coefficients, | |
2298 3 * components * sizeof(GrGLfloat)); | 2266 3 * components * sizeof(GrGLfloat)); |
2299 } | 2267 } |
2300 | 2268 |
2301 void GrGpuGL::enableTexGen(int unitIdx, TexGenComponents components, const SkMat
rix& matrix) { | 2269 void GrGpuGL::enablePathTexGen(int unitIdx, PathTexGenComponents components, |
| 2270 const SkMatrix& matrix) { |
2302 GrGLfloat coefficients[3 * 3]; | 2271 GrGLfloat coefficients[3 * 3]; |
2303 SkASSERT(this->glCaps().fixedFunctionSupport()); | 2272 SkASSERT(this->glCaps().pathRenderingSupport()); |
2304 SkASSERT(components >= kS_TexGenComponents && components <= kSTR_TexGenCompo
nents); | 2273 SkASSERT(components >= kS_PathTexGenComponents && |
| 2274 components <= kSTR_PathTexGenComponents); |
2305 | 2275 |
2306 coefficients[0] = SkScalarToFloat(matrix[SkMatrix::kMScaleX]); | 2276 coefficients[0] = SkScalarToFloat(matrix[SkMatrix::kMScaleX]); |
2307 coefficients[1] = SkScalarToFloat(matrix[SkMatrix::kMSkewX]); | 2277 coefficients[1] = SkScalarToFloat(matrix[SkMatrix::kMSkewX]); |
2308 coefficients[2] = SkScalarToFloat(matrix[SkMatrix::kMTransX]); | 2278 coefficients[2] = SkScalarToFloat(matrix[SkMatrix::kMTransX]); |
2309 | 2279 |
2310 if (components >= kST_TexGenComponents) { | 2280 if (components >= kST_PathTexGenComponents) { |
2311 coefficients[3] = SkScalarToFloat(matrix[SkMatrix::kMSkewY]); | 2281 coefficients[3] = SkScalarToFloat(matrix[SkMatrix::kMSkewY]); |
2312 coefficients[4] = SkScalarToFloat(matrix[SkMatrix::kMScaleY]); | 2282 coefficients[4] = SkScalarToFloat(matrix[SkMatrix::kMScaleY]); |
2313 coefficients[5] = SkScalarToFloat(matrix[SkMatrix::kMTransY]); | 2283 coefficients[5] = SkScalarToFloat(matrix[SkMatrix::kMTransY]); |
2314 } | 2284 } |
2315 | 2285 |
2316 if (components >= kSTR_TexGenComponents) { | 2286 if (components >= kSTR_PathTexGenComponents) { |
2317 coefficients[6] = SkScalarToFloat(matrix[SkMatrix::kMPersp0]); | 2287 coefficients[6] = SkScalarToFloat(matrix[SkMatrix::kMPersp0]); |
2318 coefficients[7] = SkScalarToFloat(matrix[SkMatrix::kMPersp1]); | 2288 coefficients[7] = SkScalarToFloat(matrix[SkMatrix::kMPersp1]); |
2319 coefficients[8] = SkScalarToFloat(matrix[SkMatrix::kMPersp2]); | 2289 coefficients[8] = SkScalarToFloat(matrix[SkMatrix::kMPersp2]); |
2320 } | 2290 } |
2321 | 2291 |
2322 enableTexGen(unitIdx, components, coefficients); | 2292 enablePathTexGen(unitIdx, components, coefficients); |
2323 } | 2293 } |
2324 | 2294 |
2325 void GrGpuGL::flushTexGenSettings(int numUsedTexCoordSets) { | 2295 void GrGpuGL::flushPathTexGenSettings(int numUsedTexCoordSets) { |
2326 SkASSERT(this->glCaps().fixedFunctionSupport()); | 2296 SkASSERT(this->glCaps().pathRenderingSupport()); |
2327 SkASSERT(this->glCaps().maxFixedFunctionTextureCoords() >= numUsedTexCoordSe
ts); | 2297 SkASSERT(this->glCaps().maxFixedFunctionTextureCoords() >= numUsedTexCoordSe
ts); |
2328 | 2298 |
2329 // Only write the inactive tex gens, since active tex gens were written | 2299 // Only write the inactive path tex gens, since active path tex gens were |
2330 // when they were enabled. | 2300 // written when they were enabled. |
2331 | 2301 |
2332 SkDEBUGCODE( | 2302 SkDEBUGCODE( |
2333 for (int i = 0; i < numUsedTexCoordSets; i++) { | 2303 for (int i = 0; i < numUsedTexCoordSets; i++) { |
2334 SkASSERT(0 != fHWTexGenSettings[i].fNumComponents); | 2304 SkASSERT(0 != fHWPathTexGenSettings[i].fNumComponents); |
2335 } | 2305 } |
2336 ); | 2306 ); |
2337 | 2307 |
2338 for (int i = numUsedTexCoordSets; i < fHWActiveTexGenSets; i++) { | 2308 for (int i = numUsedTexCoordSets; i < fHWActivePathTexGenSets; i++) { |
2339 SkASSERT(0 != fHWTexGenSettings[i].fNumComponents); | 2309 SkASSERT(0 != fHWPathTexGenSettings[i].fNumComponents); |
2340 | 2310 |
2341 this->setTextureUnit(i); | 2311 this->setTextureUnit(i); |
2342 for (int j = 0; j < fHWTexGenSettings[i].fNumComponents; j++) { | 2312 GL_CALL(PathTexGen(GR_GL_TEXTURE0 + i, GR_GL_NONE, 0, NULL)); |
2343 GL_CALL(Disable(GR_GL_TEXTURE_GEN_S + j)); | 2313 fHWPathTexGenSettings[i].fNumComponents = 0; |
2344 } | |
2345 | |
2346 if (this->caps()->pathRenderingSupport()) { | |
2347 GL_CALL(PathTexGen(GR_GL_TEXTURE0 + i, GR_GL_NONE, 0, NULL)); | |
2348 } | |
2349 | |
2350 fHWTexGenSettings[i].fNumComponents = 0; | |
2351 } | 2314 } |
2352 | 2315 |
2353 fHWActiveTexGenSets = numUsedTexCoordSets; | 2316 fHWActivePathTexGenSets = numUsedTexCoordSets; |
2354 } | 2317 } |
2355 | 2318 |
2356 void GrGpuGL::flushMiscFixedFunctionState() { | 2319 void GrGpuGL::flushMiscFixedFunctionState() { |
2357 | 2320 |
2358 const GrDrawState& drawState = this->getDrawState(); | 2321 const GrDrawState& drawState = this->getDrawState(); |
2359 | 2322 |
2360 if (drawState.isDitherState()) { | 2323 if (drawState.isDitherState()) { |
2361 if (kYes_TriState != fHWDitherEnabled) { | 2324 if (kYes_TriState != fHWDitherEnabled) { |
2362 GL_CALL(Enable(GR_GL_DITHER)); | 2325 GL_CALL(Enable(GR_GL_DITHER)); |
2363 fHWDitherEnabled = kYes_TriState; | 2326 fHWDitherEnabled = kYes_TriState; |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2842 this->setVertexArrayID(gpu, 0); | 2805 this->setVertexArrayID(gpu, 0); |
2843 } | 2806 } |
2844 int attrCount = gpu->glCaps().maxVertexAttributes(); | 2807 int attrCount = gpu->glCaps().maxVertexAttributes(); |
2845 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 2808 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
2846 fDefaultVertexArrayAttribState.resize(attrCount); | 2809 fDefaultVertexArrayAttribState.resize(attrCount); |
2847 } | 2810 } |
2848 attribState = &fDefaultVertexArrayAttribState; | 2811 attribState = &fDefaultVertexArrayAttribState; |
2849 } | 2812 } |
2850 return attribState; | 2813 return attribState; |
2851 } | 2814 } |
OLD | NEW |