| 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 "builders/GrGLProgramBuilder.h" | 10 #include "builders/GrGLProgramBuilder.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 SkDELETE(fEntries[i]); | 84 SkDELETE(fEntries[i]); |
| 85 } | 85 } |
| 86 fCount = 0; | 86 fCount = 0; |
| 87 } | 87 } |
| 88 | 88 |
| 89 int GrGpuGL::ProgramCache::search(const GrProgramDesc& desc) const { | 89 int GrGpuGL::ProgramCache::search(const GrProgramDesc& desc) const { |
| 90 ProgDescLess less; | 90 ProgDescLess less; |
| 91 return SkTSearch(fEntries, fCount, desc, sizeof(Entry*), less); | 91 return SkTSearch(fEntries, fCount, desc, sizeof(Entry*), less); |
| 92 } | 92 } |
| 93 | 93 |
| 94 GrGLProgram* GrGpuGL::ProgramCache::getProgram(const GrOptDrawState& optState) { | 94 GrGLProgram* GrGpuGL::ProgramCache::getProgram(const GrOptDrawState& optState, D
rawType type) { |
| 95 #ifdef PROGRAM_CACHE_STATS | 95 #ifdef PROGRAM_CACHE_STATS |
| 96 ++fTotalRequests; | 96 ++fTotalRequests; |
| 97 #endif | 97 #endif |
| 98 | 98 |
| 99 Entry* entry = NULL; | 99 Entry* entry = NULL; |
| 100 | 100 |
| 101 uint32_t hashIdx = optState.programDesc().getChecksum(); | 101 uint32_t hashIdx = optState.programDesc().getChecksum(); |
| 102 hashIdx ^= hashIdx >> 16; | 102 hashIdx ^= hashIdx >> 16; |
| 103 if (kHashBits <= 8) { | 103 if (kHashBits <= 8) { |
| 104 hashIdx ^= hashIdx >> 8; | 104 hashIdx ^= hashIdx >> 8; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 119 ++fHashMisses; | 119 ++fHashMisses; |
| 120 #endif | 120 #endif |
| 121 } | 121 } |
| 122 } | 122 } |
| 123 | 123 |
| 124 if (NULL == entry) { | 124 if (NULL == entry) { |
| 125 // We have a cache miss | 125 // We have a cache miss |
| 126 #ifdef PROGRAM_CACHE_STATS | 126 #ifdef PROGRAM_CACHE_STATS |
| 127 ++fCacheMisses; | 127 ++fCacheMisses; |
| 128 #endif | 128 #endif |
| 129 GrGLProgram* program = GrGLProgramBuilder::CreateProgram(optState, fGpu)
; | 129 GrGLProgram* program = GrGLProgramBuilder::CreateProgram(optState, type,
fGpu); |
| 130 if (NULL == program) { | 130 if (NULL == program) { |
| 131 return NULL; | 131 return NULL; |
| 132 } | 132 } |
| 133 int purgeIdx = 0; | 133 int purgeIdx = 0; |
| 134 if (fCount < kMaxEntries) { | 134 if (fCount < kMaxEntries) { |
| 135 entry = SkNEW(Entry); | 135 entry = SkNEW(Entry); |
| 136 purgeIdx = fCount++; | 136 purgeIdx = fCount++; |
| 137 fEntries[purgeIdx] = entry; | 137 fEntries[purgeIdx] = entry; |
| 138 } else { | 138 } else { |
| 139 SkASSERT(fCount == kMaxEntries); | 139 SkASSERT(fCount == kMaxEntries); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 } | 194 } |
| 195 } | 195 } |
| 196 ++fCurrLRUStamp; | 196 ++fCurrLRUStamp; |
| 197 return entry->fProgram; | 197 return entry->fProgram; |
| 198 } | 198 } |
| 199 | 199 |
| 200 //////////////////////////////////////////////////////////////////////////////// | 200 //////////////////////////////////////////////////////////////////////////////// |
| 201 | 201 |
| 202 #define GL_CALL(X) GR_GL_CALL(this->glInterface(), X) | 202 #define GL_CALL(X) GR_GL_CALL(this->glInterface(), X) |
| 203 | 203 |
| 204 bool GrGpuGL::flushGraphicsState(const GrOptDrawState& optState) { | 204 bool GrGpuGL::flushGraphicsState(const GrOptDrawState& optState, DrawType type)
{ |
| 205 // GrGpu::setupClipAndFlushState should have already checked this and bailed
if not true. | 205 // GrGpu::setupClipAndFlushState should have already checked this and bailed
if not true. |
| 206 SkASSERT(optState.getRenderTarget()); | 206 SkASSERT(optState.getRenderTarget()); |
| 207 | 207 |
| 208 if (kStencilPath_DrawType == optState.drawType()) { | 208 if (kStencilPath_DrawType == type) { |
| 209 const GrRenderTarget* rt = optState.getRenderTarget(); | 209 const GrRenderTarget* rt = optState.getRenderTarget(); |
| 210 SkISize size; | 210 SkISize size; |
| 211 size.set(rt->width(), rt->height()); | 211 size.set(rt->width(), rt->height()); |
| 212 this->glPathRendering()->setProjectionMatrix(optState.getViewMatrix(), s
ize, rt->origin()); | 212 this->glPathRendering()->setProjectionMatrix(optState.getViewMatrix(), s
ize, rt->origin()); |
| 213 } else { | 213 } else { |
| 214 this->flushMiscFixedFunctionState(optState); | 214 this->flushMiscFixedFunctionState(optState); |
| 215 | 215 |
| 216 GrBlendCoeff srcCoeff = optState.getSrcBlendCoeff(); | 216 GrBlendCoeff srcCoeff = optState.getSrcBlendCoeff(); |
| 217 GrBlendCoeff dstCoeff = optState.getDstBlendCoeff(); | 217 GrBlendCoeff dstCoeff = optState.getDstBlendCoeff(); |
| 218 | 218 |
| 219 fCurrentProgram.reset(fProgramCache->getProgram(optState)); | 219 fCurrentProgram.reset(fProgramCache->getProgram(optState, type)); |
| 220 if (NULL == fCurrentProgram.get()) { | 220 if (NULL == fCurrentProgram.get()) { |
| 221 SkDEBUGFAIL("Failed to create program!"); | 221 SkDEBUGFAIL("Failed to create program!"); |
| 222 return false; | 222 return false; |
| 223 } | 223 } |
| 224 | 224 |
| 225 fCurrentProgram.get()->ref(); | 225 fCurrentProgram.get()->ref(); |
| 226 | 226 |
| 227 GrGLuint programID = fCurrentProgram->programID(); | 227 GrGLuint programID = fCurrentProgram->programID(); |
| 228 if (fHWProgramID != programID) { | 228 if (fHWProgramID != programID) { |
| 229 GL_CALL(UseProgram(programID)); | 229 GL_CALL(UseProgram(programID)); |
| 230 fHWProgramID = programID; | 230 fHWProgramID = programID; |
| 231 } | 231 } |
| 232 | 232 |
| 233 this->flushBlend(optState, kDrawLines_DrawType == optState.drawType(), s
rcCoeff, dstCoeff); | 233 this->flushBlend(optState, kDrawLines_DrawType == type, srcCoeff, dstCoe
ff); |
| 234 | 234 |
| 235 fCurrentProgram->setData(optState); | 235 fCurrentProgram->setData(optState, type); |
| 236 } | 236 } |
| 237 | 237 |
| 238 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(optState.getRenderTa
rget()); | 238 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(optState.getRenderTa
rget()); |
| 239 this->flushStencil(optState.getStencil(), optState.drawType()); | 239 this->flushStencil(optState.getStencil(), type); |
| 240 this->flushScissor(optState.getScissorState(), glRT->getViewport(), glRT->or
igin()); | 240 this->flushScissor(optState.getScissorState(), glRT->getViewport(), glRT->or
igin()); |
| 241 this->flushAAState(optState); | 241 this->flushAAState(optState, type); |
| 242 | 242 |
| 243 // This must come after textures are flushed because a texture may need | 243 // This must come after textures are flushed because a texture may need |
| 244 // to be msaa-resolved (which will modify bound FBO state). | 244 // to be msaa-resolved (which will modify bound FBO state). |
| 245 this->flushRenderTarget(glRT, NULL); | 245 this->flushRenderTarget(glRT, NULL); |
| 246 | 246 |
| 247 return true; | 247 return true; |
| 248 } | 248 } |
| 249 | 249 |
| 250 void GrGpuGL::setupGeometry(const GrOptDrawState& optState, | 250 void GrGpuGL::setupGeometry(const GrOptDrawState& optState, |
| 251 const GrDrawTarget::DrawInfo& info, | 251 const GrDrawTarget::DrawInfo& info, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 } | 302 } |
| 303 | 303 |
| 304 void GrGpuGL::buildProgramDesc(const GrOptDrawState& optState, | 304 void GrGpuGL::buildProgramDesc(const GrOptDrawState& optState, |
| 305 const GrProgramDesc::DescInfo& descInfo, | 305 const GrProgramDesc::DescInfo& descInfo, |
| 306 GrGpu::DrawType drawType, | 306 GrGpu::DrawType drawType, |
| 307 GrProgramDesc* desc) { | 307 GrProgramDesc* desc) { |
| 308 if (!GrGLProgramDescBuilder::Build(optState, descInfo, drawType, this, desc)
) { | 308 if (!GrGLProgramDescBuilder::Build(optState, descInfo, drawType, this, desc)
) { |
| 309 SkDEBUGFAIL("Failed to generate GL program descriptor"); | 309 SkDEBUGFAIL("Failed to generate GL program descriptor"); |
| 310 } | 310 } |
| 311 } | 311 } |
| OLD | NEW |