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 "GrGLNameAllocator.h" | 10 #include "GrGLNameAllocator.h" |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 | 273 |
274 // We should set glPolygonMode(FRONT_AND_BACK,FILL) here, too. It is
n't | 274 // We should set glPolygonMode(FRONT_AND_BACK,FILL) here, too. It is
n't |
275 // currently part of our gl interface. There are probably others as | 275 // currently part of our gl interface. There are probably others as |
276 // well. | 276 // well. |
277 } | 277 } |
278 fHWWriteToColor = kUnknown_TriState; | 278 fHWWriteToColor = kUnknown_TriState; |
279 // we only ever use lines in hairline mode | 279 // we only ever use lines in hairline mode |
280 GL_CALL(LineWidth(1)); | 280 GL_CALL(LineWidth(1)); |
281 } | 281 } |
282 | 282 |
283 if (resetBits & kMSAAEnable_GrGLBackendState) { | 283 if (resetBits & kAA_GrGLBackendState) { |
284 fMSAAEnabled = kUnknown_TriState; | 284 fHWAAState.invalidate(); |
285 } | 285 } |
286 | 286 |
287 fHWActiveTextureUnitIdx = -1; // invalid | 287 fHWActiveTextureUnitIdx = -1; // invalid |
288 | 288 |
289 if (resetBits & kTextureBinding_GrGLBackendState) { | 289 if (resetBits & kTextureBinding_GrGLBackendState) { |
290 for (int s = 0; s < fHWBoundTextureUniqueIDs.count(); ++s) { | 290 for (int s = 0; s < fHWBoundTextureUniqueIDs.count(); ++s) { |
291 fHWBoundTextureUniqueIDs[s] = SK_InvalidUniqueID; | 291 fHWBoundTextureUniqueIDs[s] = SK_InvalidUniqueID; |
292 } | 292 } |
293 } | 293 } |
294 | 294 |
(...skipping 1862 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2157 // the target is not multisampled. Single pixel wide lines are rendered thicker
than 1 pixel wide. | 2157 // the target is not multisampled. Single pixel wide lines are rendered thicker
than 1 pixel wide. |
2158 #if 0 | 2158 #if 0 |
2159 // Replace RT_HAS_MSAA with this definition once this driver bug is no longe
r a relevant concern | 2159 // Replace RT_HAS_MSAA with this definition once this driver bug is no longe
r a relevant concern |
2160 #define RT_HAS_MSAA rt->isMultisampled() | 2160 #define RT_HAS_MSAA rt->isMultisampled() |
2161 #else | 2161 #else |
2162 #define RT_HAS_MSAA (rt->isMultisampled() || kDrawLines_DrawType == type) | 2162 #define RT_HAS_MSAA (rt->isMultisampled() || kDrawLines_DrawType == type) |
2163 #endif | 2163 #endif |
2164 | 2164 |
2165 const GrRenderTarget* rt = this->getDrawState().getRenderTarget(); | 2165 const GrRenderTarget* rt = this->getDrawState().getRenderTarget(); |
2166 if (kGL_GrGLStandard == this->glStandard()) { | 2166 if (kGL_GrGLStandard == this->glStandard()) { |
2167 if (RT_HAS_MSAA) { | 2167 // ES doesn't support toggling GL_MULTISAMPLE and doesn't have |
| 2168 // smooth lines. |
| 2169 // we prefer smooth lines over multisampled lines |
| 2170 bool smoothLines = false; |
| 2171 |
| 2172 if (kDrawLines_DrawType == type) { |
| 2173 smoothLines = this->willUseHWAALines(); |
| 2174 if (smoothLines) { |
| 2175 if (kYes_TriState != fHWAAState.fSmoothLineEnabled) { |
| 2176 GL_CALL(Enable(GR_GL_LINE_SMOOTH)); |
| 2177 fHWAAState.fSmoothLineEnabled = kYes_TriState; |
| 2178 // must disable msaa to use line smoothing |
| 2179 if (RT_HAS_MSAA && |
| 2180 kNo_TriState != fHWAAState.fMSAAEnabled) { |
| 2181 GL_CALL(Disable(GR_GL_MULTISAMPLE)); |
| 2182 fHWAAState.fMSAAEnabled = kNo_TriState; |
| 2183 } |
| 2184 } |
| 2185 } else { |
| 2186 if (kNo_TriState != fHWAAState.fSmoothLineEnabled) { |
| 2187 GL_CALL(Disable(GR_GL_LINE_SMOOTH)); |
| 2188 fHWAAState.fSmoothLineEnabled = kNo_TriState; |
| 2189 } |
| 2190 } |
| 2191 } |
| 2192 if (!smoothLines && RT_HAS_MSAA) { |
2168 // FIXME: GL_NV_pr doesn't seem to like MSAA disabled. The paths | 2193 // FIXME: GL_NV_pr doesn't seem to like MSAA disabled. The paths |
2169 // convex hulls of each segment appear to get filled. | 2194 // convex hulls of each segment appear to get filled. |
2170 bool enableMSAA = kStencilPath_DrawType == type || | 2195 bool enableMSAA = kStencilPath_DrawType == type || |
2171 this->getDrawState().isHWAntialiasState(); | 2196 this->getDrawState().isHWAntialiasState(); |
2172 if (enableMSAA) { | 2197 if (enableMSAA) { |
2173 if (kYes_TriState != fMSAAEnabled) { | 2198 if (kYes_TriState != fHWAAState.fMSAAEnabled) { |
2174 GL_CALL(Enable(GR_GL_MULTISAMPLE)); | 2199 GL_CALL(Enable(GR_GL_MULTISAMPLE)); |
2175 fMSAAEnabled = kYes_TriState; | 2200 fHWAAState.fMSAAEnabled = kYes_TriState; |
2176 } | 2201 } |
2177 } else { | 2202 } else { |
2178 if (kNo_TriState != fMSAAEnabled) { | 2203 if (kNo_TriState != fHWAAState.fMSAAEnabled) { |
2179 GL_CALL(Disable(GR_GL_MULTISAMPLE)); | 2204 GL_CALL(Disable(GR_GL_MULTISAMPLE)); |
2180 fMSAAEnabled = kNo_TriState; | 2205 fHWAAState.fMSAAEnabled = kNo_TriState; |
2181 } | 2206 } |
2182 } | 2207 } |
2183 } | 2208 } |
2184 } | 2209 } |
2185 } | 2210 } |
2186 | 2211 |
2187 void GrGpuGL::flushPathStencilSettings(SkPath::FillType fill) { | 2212 void GrGpuGL::flushPathStencilSettings(SkPath::FillType fill) { |
2188 GrStencilSettings pathStencilSettings; | 2213 GrStencilSettings pathStencilSettings; |
2189 this->getPathStencilSettingsForFillType(fill, &pathStencilSettings); | 2214 this->getPathStencilSettingsForFillType(fill, &pathStencilSettings); |
2190 if (fHWPathStencilSettings != pathStencilSettings) { | 2215 if (fHWPathStencilSettings != pathStencilSettings) { |
2191 // Just the func, ref, and mask is set here. The op and write mask are p
arams to the call | 2216 // Just the func, ref, and mask is set here. The op and write mask are p
arams to the call |
2192 // that draws the path to the SB (glStencilFillPath) | 2217 // that draws the path to the SB (glStencilFillPath) |
2193 GrGLenum func = | 2218 GrGLenum func = |
2194 gr_to_gl_stencil_func(pathStencilSettings.func(GrStencilSettings::kF
ront_Face)); | 2219 gr_to_gl_stencil_func(pathStencilSettings.func(GrStencilSettings::kF
ront_Face)); |
2195 GL_CALL(PathStencilFunc(func, | 2220 GL_CALL(PathStencilFunc(func, |
2196 pathStencilSettings.funcRef(GrStencilSettings::k
Front_Face), | 2221 pathStencilSettings.funcRef(GrStencilSettings::k
Front_Face), |
2197 pathStencilSettings.funcMask(GrStencilSettings::
kFront_Face))); | 2222 pathStencilSettings.funcMask(GrStencilSettings::
kFront_Face))); |
2198 | 2223 |
2199 fHWPathStencilSettings = pathStencilSettings; | 2224 fHWPathStencilSettings = pathStencilSettings; |
2200 } | 2225 } |
2201 } | 2226 } |
2202 | 2227 |
2203 void GrGpuGL::flushBlend(bool isLines, | 2228 void GrGpuGL::flushBlend(bool isLines, |
2204 GrBlendCoeff srcCoeff, | 2229 GrBlendCoeff srcCoeff, |
2205 GrBlendCoeff dstCoeff) { | 2230 GrBlendCoeff dstCoeff) { |
2206 // any optimization to disable blending should have already been applied and | 2231 if (isLines && this->willUseHWAALines()) { |
2207 // tweaked the coeffs to (1, 0). | |
2208 bool blendOff = kOne_GrBlendCoeff == srcCoeff && kZero_GrBlendCoeff == dstCo
eff; | |
2209 if (blendOff) { | |
2210 if (kNo_TriState != fHWBlendState.fEnabled) { | |
2211 GL_CALL(Disable(GR_GL_BLEND)); | |
2212 fHWBlendState.fEnabled = kNo_TriState; | |
2213 } | |
2214 } else { | |
2215 if (kYes_TriState != fHWBlendState.fEnabled) { | 2232 if (kYes_TriState != fHWBlendState.fEnabled) { |
2216 GL_CALL(Enable(GR_GL_BLEND)); | 2233 GL_CALL(Enable(GR_GL_BLEND)); |
2217 fHWBlendState.fEnabled = kYes_TriState; | 2234 fHWBlendState.fEnabled = kYes_TriState; |
2218 } | 2235 } |
2219 if (fHWBlendState.fSrcCoeff != srcCoeff || | 2236 if (kSA_GrBlendCoeff != fHWBlendState.fSrcCoeff || |
2220 fHWBlendState.fDstCoeff != dstCoeff) { | 2237 kISA_GrBlendCoeff != fHWBlendState.fDstCoeff) { |
2221 GL_CALL(BlendFunc(gXfermodeCoeff2Blend[srcCoeff], | 2238 GL_CALL(BlendFunc(gXfermodeCoeff2Blend[kSA_GrBlendCoeff], |
2222 gXfermodeCoeff2Blend[dstCoeff])); | 2239 gXfermodeCoeff2Blend[kISA_GrBlendCoeff])); |
2223 fHWBlendState.fSrcCoeff = srcCoeff; | 2240 fHWBlendState.fSrcCoeff = kSA_GrBlendCoeff; |
2224 fHWBlendState.fDstCoeff = dstCoeff; | 2241 fHWBlendState.fDstCoeff = kISA_GrBlendCoeff; |
2225 } | 2242 } |
2226 GrColor blendConst = this->getDrawState().getBlendConstant(); | 2243 } else { |
2227 if ((BlendCoeffReferencesConstant(srcCoeff) || | 2244 // any optimization to disable blending should |
2228 BlendCoeffReferencesConstant(dstCoeff)) && | 2245 // have already been applied and tweaked the coeffs |
2229 (!fHWBlendState.fConstColorValid || | 2246 // to (1, 0). |
2230 fHWBlendState.fConstColor != blendConst)) { | 2247 bool blendOff = kOne_GrBlendCoeff == srcCoeff && |
2231 GrGLfloat c[4]; | 2248 kZero_GrBlendCoeff == dstCoeff; |
2232 GrColorToRGBAFloat(blendConst, c); | 2249 if (blendOff) { |
2233 GL_CALL(BlendColor(c[0], c[1], c[2], c[3])); | 2250 if (kNo_TriState != fHWBlendState.fEnabled) { |
2234 fHWBlendState.fConstColor = blendConst; | 2251 GL_CALL(Disable(GR_GL_BLEND)); |
2235 fHWBlendState.fConstColorValid = true; | 2252 fHWBlendState.fEnabled = kNo_TriState; |
| 2253 } |
| 2254 } else { |
| 2255 if (kYes_TriState != fHWBlendState.fEnabled) { |
| 2256 GL_CALL(Enable(GR_GL_BLEND)); |
| 2257 fHWBlendState.fEnabled = kYes_TriState; |
| 2258 } |
| 2259 if (fHWBlendState.fSrcCoeff != srcCoeff || |
| 2260 fHWBlendState.fDstCoeff != dstCoeff) { |
| 2261 GL_CALL(BlendFunc(gXfermodeCoeff2Blend[srcCoeff], |
| 2262 gXfermodeCoeff2Blend[dstCoeff])); |
| 2263 fHWBlendState.fSrcCoeff = srcCoeff; |
| 2264 fHWBlendState.fDstCoeff = dstCoeff; |
| 2265 } |
| 2266 GrColor blendConst = this->getDrawState().getBlendConstant(); |
| 2267 if ((BlendCoeffReferencesConstant(srcCoeff) || |
| 2268 BlendCoeffReferencesConstant(dstCoeff)) && |
| 2269 (!fHWBlendState.fConstColorValid || |
| 2270 fHWBlendState.fConstColor != blendConst)) { |
| 2271 GrGLfloat c[4]; |
| 2272 GrColorToRGBAFloat(blendConst, c); |
| 2273 GL_CALL(BlendColor(c[0], c[1], c[2], c[3])); |
| 2274 fHWBlendState.fConstColor = blendConst; |
| 2275 fHWBlendState.fConstColorValid = true; |
| 2276 } |
2236 } | 2277 } |
2237 } | 2278 } |
2238 } | 2279 } |
2239 | 2280 |
2240 static inline GrGLenum tile_to_gl_wrap(SkShader::TileMode tm) { | 2281 static inline GrGLenum tile_to_gl_wrap(SkShader::TileMode tm) { |
2241 static const GrGLenum gWrapModes[] = { | 2282 static const GrGLenum gWrapModes[] = { |
2242 GR_GL_CLAMP_TO_EDGE, | 2283 GR_GL_CLAMP_TO_EDGE, |
2243 GR_GL_REPEAT, | 2284 GR_GL_REPEAT, |
2244 GR_GL_MIRRORED_REPEAT | 2285 GR_GL_MIRRORED_REPEAT |
2245 }; | 2286 }; |
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2977 this->setVertexArrayID(gpu, 0); | 3018 this->setVertexArrayID(gpu, 0); |
2978 } | 3019 } |
2979 int attrCount = gpu->glCaps().maxVertexAttributes(); | 3020 int attrCount = gpu->glCaps().maxVertexAttributes(); |
2980 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 3021 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
2981 fDefaultVertexArrayAttribState.resize(attrCount); | 3022 fDefaultVertexArrayAttribState.resize(attrCount); |
2982 } | 3023 } |
2983 attribState = &fDefaultVertexArrayAttribState; | 3024 attribState = &fDefaultVertexArrayAttribState; |
2984 } | 3025 } |
2985 return attribState; | 3026 return attribState; |
2986 } | 3027 } |
OLD | NEW |