Chromium Code Reviews| 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 #include "GrGpuGL.h" | 8 #include "GrGpuGL.h" |
| 9 | 9 |
| 10 #include "GrEffect.h" | 10 #include "GrEffect.h" |
| 11 #include "GrGLEffect.h" | 11 #include "GrGLEffect.h" |
| 12 #include "GrGLPathRendering.h" | |
| 13 #include "GrOptDrawState.h" | |
| 12 #include "SkRTConf.h" | 14 #include "SkRTConf.h" |
| 13 #include "GrGLPathRendering.h" | |
| 14 #include "SkTSearch.h" | 15 #include "SkTSearch.h" |
| 15 | 16 |
| 16 #ifdef PROGRAM_CACHE_STATS | 17 #ifdef PROGRAM_CACHE_STATS |
| 17 SK_CONF_DECLARE(bool, c_DisplayCache, "gpu.displayCache", false, | 18 SK_CONF_DECLARE(bool, c_DisplayCache, "gpu.displayCache", false, |
| 18 "Display program cache usage."); | 19 "Display program cache usage."); |
| 19 #endif | 20 #endif |
| 20 | 21 |
| 21 typedef GrGLProgramDataManager::UniformHandle UniformHandle; | 22 typedef GrGLProgramDataManager::UniformHandle UniformHandle; |
| 22 | 23 |
| 23 struct GrGpuGL::ProgramCache::Entry { | 24 struct GrGpuGL::ProgramCache::Entry { |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 197 } | 198 } |
| 198 ++fCurrLRUStamp; | 199 ++fCurrLRUStamp; |
| 199 return entry->fProgram; | 200 return entry->fProgram; |
| 200 } | 201 } |
| 201 | 202 |
| 202 //////////////////////////////////////////////////////////////////////////////// | 203 //////////////////////////////////////////////////////////////////////////////// |
| 203 | 204 |
| 204 #define GL_CALL(X) GR_GL_CALL(this->glInterface(), X) | 205 #define GL_CALL(X) GR_GL_CALL(this->glInterface(), X) |
| 205 | 206 |
| 206 bool GrGpuGL::flushGraphicsState(DrawType type, const GrDeviceCoordTexture* dstC opy) { | 207 bool GrGpuGL::flushGraphicsState(DrawType type, const GrDeviceCoordTexture* dstC opy) { |
| 207 const GrDrawState& drawState = this->getDrawState(); | 208 const GrOptDrawState& optState = *this->getDrawState().createOptState(); |
| 209 optState.unref(); | |
|
bsalomon
2014/09/15 14:04:34
This seems really dangerous... it is assuming an i
egdaniel
2014/09/15 17:51:35
Done.
| |
| 208 | 210 |
| 209 // GrGpu::setupClipAndFlushState should have already checked this and bailed if not true. | 211 // GrGpu::setupClipAndFlushState should have already checked this and bailed if not true. |
| 210 SkASSERT(drawState.getRenderTarget()); | 212 SkASSERT(optState.getRenderTarget()); |
| 211 | 213 |
| 212 if (kStencilPath_DrawType == type) { | 214 if (kStencilPath_DrawType == type) { |
| 213 const GrRenderTarget* rt = this->getDrawState().getRenderTarget(); | 215 const GrRenderTarget* rt = optState.getRenderTarget(); |
| 214 SkISize size; | 216 SkISize size; |
| 215 size.set(rt->width(), rt->height()); | 217 size.set(rt->width(), rt->height()); |
| 216 this->glPathRendering()->setProjectionMatrix(drawState.getViewMatrix(), size, rt->origin()); | 218 this->glPathRendering()->setProjectionMatrix(optState.getViewMatrix(), s ize, rt->origin()); |
| 217 } else { | 219 } else { |
| 218 this->flushMiscFixedFunctionState(); | 220 this->flushMiscFixedFunctionState(); |
| 219 | 221 |
| 220 GrBlendCoeff srcCoeff; | 222 GrBlendCoeff srcCoeff = optState.getSrcBlendCoeff(); |
| 221 GrBlendCoeff dstCoeff; | 223 GrBlendCoeff dstCoeff = optState.getDstBlendCoeff(); |
| 222 GrDrawState::BlendOptFlags blendOpts = drawState.getBlendOpts(false, &sr cCoeff, &dstCoeff); | 224 |
| 223 if (GrDrawState::kSkipDraw_BlendOptFlag & blendOpts) { | 225 // In these blend coeff's we end up drawing nothing so we can skip draw all together |
| 226 if (kZero_GrBlendCoeff == srcCoeff && kOne_GrBlendCoeff == dstCoeff && | |
| 227 !optState.getStencil().doesWrite()) { | |
| 224 return false; | 228 return false; |
| 225 } | 229 } |
| 226 | 230 |
| 227 const GrEffectStage* geometryProcessor = NULL; | 231 const GrEffectStage* geometryProcessor = NULL; |
| 228 SkSTArray<8, const GrEffectStage*, true> colorStages; | 232 SkSTArray<8, const GrEffectStage*, true> colorStages; |
| 229 SkSTArray<8, const GrEffectStage*, true> coverageStages; | 233 SkSTArray<8, const GrEffectStage*, true> coverageStages; |
| 230 GrGLProgramDesc desc; | 234 GrGLProgramDesc desc; |
| 231 if (!GrGLProgramDesc::Build(this->getDrawState(), | 235 if (!GrGLProgramDesc::Build(optState, |
| 232 type, | 236 type, |
| 233 blendOpts, | |
| 234 srcCoeff, | 237 srcCoeff, |
| 235 dstCoeff, | 238 dstCoeff, |
| 236 this, | 239 this, |
| 237 dstCopy, | 240 dstCopy, |
| 238 &geometryProcessor, | 241 &geometryProcessor, |
| 239 &colorStages, | 242 &colorStages, |
| 240 &coverageStages, | 243 &coverageStages, |
| 241 &desc)) { | 244 &desc)) { |
| 242 SkDEBUGFAIL("Failed to generate GL program descriptor"); | 245 SkDEBUGFAIL("Failed to generate GL program descriptor"); |
| 243 return false; | 246 return false; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 256 | 259 |
| 257 GrGLuint programID = fCurrentProgram->programID(); | 260 GrGLuint programID = fCurrentProgram->programID(); |
| 258 if (fHWProgramID != programID) { | 261 if (fHWProgramID != programID) { |
| 259 GL_CALL(UseProgram(programID)); | 262 GL_CALL(UseProgram(programID)); |
| 260 fHWProgramID = programID; | 263 fHWProgramID = programID; |
| 261 } | 264 } |
| 262 | 265 |
| 263 fCurrentProgram->overrideBlend(&srcCoeff, &dstCoeff); | 266 fCurrentProgram->overrideBlend(&srcCoeff, &dstCoeff); |
| 264 this->flushBlend(kDrawLines_DrawType == type, srcCoeff, dstCoeff); | 267 this->flushBlend(kDrawLines_DrawType == type, srcCoeff, dstCoeff); |
| 265 | 268 |
| 266 fCurrentProgram->setData(type, | 269 fCurrentProgram->setData(optState, |
| 267 blendOpts, | 270 type, |
| 268 geometryProcessor, | 271 geometryProcessor, |
| 269 colorStages.begin(), | 272 colorStages.begin(), |
| 270 coverageStages.begin(), | 273 coverageStages.begin(), |
| 271 dstCopy, | 274 dstCopy, |
| 272 &fSharedGLProgramState); | 275 &fSharedGLProgramState); |
| 273 } | 276 } |
| 274 | 277 |
| 275 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(drawState.getRenderT arget()); | 278 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(optState.getRenderTa rget()); |
| 276 this->flushStencil(type); | 279 this->flushStencil(type); |
| 277 this->flushScissor(glRT->getViewport(), glRT->origin()); | 280 this->flushScissor(glRT->getViewport(), glRT->origin()); |
| 278 this->flushAAState(type); | 281 this->flushAAState(type); |
| 279 | 282 |
| 280 SkIRect* devRect = NULL; | 283 SkIRect* devRect = NULL; |
| 281 SkIRect devClipBounds; | 284 SkIRect devClipBounds; |
| 282 if (drawState.isClipState()) { | 285 if (optState.isClipState()) { |
| 283 this->getClip()->getConservativeBounds(drawState.getRenderTarget(), &dev ClipBounds); | 286 this->getClip()->getConservativeBounds(optState.getRenderTarget(), &devC lipBounds); |
| 284 devRect = &devClipBounds; | 287 devRect = &devClipBounds; |
| 285 } | 288 } |
| 286 // This must come after textures are flushed because a texture may need | 289 // This must come after textures are flushed because a texture may need |
| 287 // to be msaa-resolved (which will modify bound FBO state). | 290 // to be msaa-resolved (which will modify bound FBO state). |
| 288 this->flushRenderTarget(glRT, devRect); | 291 this->flushRenderTarget(glRT, devRect); |
| 289 | 292 |
| 290 return true; | 293 return true; |
| 291 } | 294 } |
| 292 | 295 |
| 293 void GrGpuGL::setupGeometry(const DrawInfo& info, size_t* indexOffsetInBytes) { | 296 void GrGpuGL::setupGeometry(const DrawInfo& info, size_t* indexOffsetInBytes) { |
| 294 | 297 |
| 295 GrGLsizei stride = static_cast<GrGLsizei>(this->getDrawState().getVertexStri de()); | 298 const GrOptDrawState& optState = *this->getDrawState().createOptState(); |
| 299 optState.unref(); | |
|
bsalomon
2014/09/15 14:04:34
ditto
egdaniel
2014/09/15 17:51:35
Done.
| |
| 300 | |
| 301 GrGLsizei stride = static_cast<GrGLsizei>(optState.getVertexStride()); | |
| 296 | 302 |
| 297 size_t vertexOffsetInBytes = stride * info.startVertex(); | 303 size_t vertexOffsetInBytes = stride * info.startVertex(); |
| 298 | 304 |
| 299 const GeometryPoolState& geoPoolState = this->getGeomPoolState(); | 305 const GeometryPoolState& geoPoolState = this->getGeomPoolState(); |
| 300 | 306 |
| 301 GrGLVertexBuffer* vbuf; | 307 GrGLVertexBuffer* vbuf; |
| 302 switch (this->getGeomSrc().fVertexSrc) { | 308 switch (this->getGeomSrc().fVertexSrc) { |
| 303 case kBuffer_GeometrySrcType: | 309 case kBuffer_GeometrySrcType: |
| 304 vbuf = (GrGLVertexBuffer*) this->getGeomSrc().fVertexBuffer; | 310 vbuf = (GrGLVertexBuffer*) this->getGeomSrc().fVertexBuffer; |
| 305 break; | 311 break; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 339 } | 345 } |
| 340 | 346 |
| 341 SkASSERT(ibuf); | 347 SkASSERT(ibuf); |
| 342 SkASSERT(!ibuf->isMapped()); | 348 SkASSERT(!ibuf->isMapped()); |
| 343 *indexOffsetInBytes += ibuf->baseOffset(); | 349 *indexOffsetInBytes += ibuf->baseOffset(); |
| 344 } | 350 } |
| 345 GrGLAttribArrayState* attribState = | 351 GrGLAttribArrayState* attribState = |
| 346 fHWGeometryState.bindArrayAndBuffersToDraw(this, vbuf, ibuf); | 352 fHWGeometryState.bindArrayAndBuffersToDraw(this, vbuf, ibuf); |
| 347 | 353 |
| 348 if (fCurrentProgram->hasVertexShader()) { | 354 if (fCurrentProgram->hasVertexShader()) { |
| 349 int vertexAttribCount = this->getDrawState().getVertexAttribCount(); | 355 int vertexAttribCount = optState.getVertexAttribCount(); |
| 350 uint32_t usedAttribArraysMask = 0; | 356 uint32_t usedAttribArraysMask = 0; |
| 351 const GrVertexAttrib* vertexAttrib = this->getDrawState().getVertexAttri bs(); | 357 const GrVertexAttrib* vertexAttrib = optState.getVertexAttribs(); |
| 352 | |
| 353 bool canIgnoreColorAttrib = this->getDrawState().canIgnoreColorAttribute (); | |
| 354 | 358 |
| 355 for (int vertexAttribIndex = 0; vertexAttribIndex < vertexAttribCount; | 359 for (int vertexAttribIndex = 0; vertexAttribIndex < vertexAttribCount; |
| 356 ++vertexAttribIndex, ++vertexAttrib) { | 360 ++vertexAttribIndex, ++vertexAttrib) { |
| 357 | |
| 358 if (kColor_GrVertexAttribBinding != vertexAttrib->fBinding || !canIg noreColorAttrib) { | |
| 359 usedAttribArraysMask |= (1 << vertexAttribIndex); | 361 usedAttribArraysMask |= (1 << vertexAttribIndex); |
| 360 GrVertexAttribType attribType = vertexAttrib->fType; | 362 GrVertexAttribType attribType = vertexAttrib->fType; |
| 361 attribState->set(this, | 363 attribState->set(this, |
| 362 vertexAttribIndex, | 364 vertexAttribIndex, |
| 363 vbuf, | 365 vbuf, |
| 364 GrGLAttribTypeToLayout(attribType).fCount, | 366 GrGLAttribTypeToLayout(attribType).fCount, |
| 365 GrGLAttribTypeToLayout(attribType).fType, | 367 GrGLAttribTypeToLayout(attribType).fType, |
| 366 GrGLAttribTypeToLayout(attribType).fNormalized, | 368 GrGLAttribTypeToLayout(attribType).fNormalized, |
| 367 stride, | 369 stride, |
| 368 reinterpret_cast<GrGLvoid*>( | 370 reinterpret_cast<GrGLvoid*>( |
| 369 vertexOffsetInBytes + vertexAttrib->fOffset)); | 371 vertexOffsetInBytes + vertexAttrib->fOffset)); |
| 370 } | |
| 371 } | 372 } |
| 372 attribState->disableUnusedArrays(this, usedAttribArraysMask); | 373 attribState->disableUnusedArrays(this, usedAttribArraysMask); |
| 373 } | 374 } |
| 374 } | 375 } |
| OLD | NEW |