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" |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 void GrGpuGL::abandonResources(){ | 195 void GrGpuGL::abandonResources(){ |
196 INHERITED::abandonResources(); | 196 INHERITED::abandonResources(); |
197 fProgramCache->abandon(); | 197 fProgramCache->abandon(); |
198 fHWProgramID = 0; | 198 fHWProgramID = 0; |
199 } | 199 } |
200 | 200 |
201 //////////////////////////////////////////////////////////////////////////////// | 201 //////////////////////////////////////////////////////////////////////////////// |
202 | 202 |
203 #define GL_CALL(X) GR_GL_CALL(this->glInterface(), X) | 203 #define GL_CALL(X) GR_GL_CALL(this->glInterface(), X) |
204 | 204 |
205 void GrGpuGL::flushPathStencilMatrix() { | |
206 const SkMatrix& viewMatrix = this->getDrawState().getViewMatrix(); | |
207 const GrRenderTarget* rt = this->getDrawState().getRenderTarget(); | |
208 SkISize size; | |
209 size.set(rt->width(), rt->height()); | |
210 const SkMatrix& vm = this->getDrawState().getViewMatrix(); | |
211 | |
212 if (fHWProjectionMatrixState.fRenderTargetOrigin != rt->origin() || | |
213 !fHWProjectionMatrixState.fViewMatrix.cheapEqualTo(viewMatrix) || | |
214 fHWProjectionMatrixState.fRenderTargetSize!= size) { | |
215 | |
216 fHWProjectionMatrixState.fViewMatrix = vm; | |
217 fHWProjectionMatrixState.fRenderTargetSize = size; | |
218 fHWProjectionMatrixState.fRenderTargetOrigin = rt->origin(); | |
219 | |
220 GrGLfloat projectionMatrix[4 * 4]; | |
221 fHWProjectionMatrixState.getGLMatrix<4>(projectionMatrix); | |
222 GL_CALL(MatrixMode(GR_GL_PROJECTION)); | |
223 GL_CALL(LoadMatrixf(projectionMatrix)); | |
224 } | |
225 } | |
226 | |
227 bool GrGpuGL::flushGraphicsState(DrawType type, const GrDeviceCoordTexture* dstC
opy) { | 205 bool GrGpuGL::flushGraphicsState(DrawType type, const GrDeviceCoordTexture* dstC
opy) { |
228 const GrDrawState& drawState = this->getDrawState(); | 206 const GrDrawState& drawState = this->getDrawState(); |
229 | 207 |
230 // GrGpu::setupClipAndFlushState should have already checked this and bailed
if not true. | 208 // GrGpu::setupClipAndFlushState should have already checked this and bailed
if not true. |
231 SkASSERT(NULL != drawState.getRenderTarget()); | 209 SkASSERT(NULL != drawState.getRenderTarget()); |
232 | 210 |
233 if (kStencilPath_DrawType == type) { | 211 if (kStencilPath_DrawType == type) { |
234 this->flushPathStencilMatrix(); | 212 const GrRenderTarget* rt = this->getDrawState().getRenderTarget(); |
| 213 SkISize size; |
| 214 size.set(rt->width(), rt->height()); |
| 215 this->setProjectionMatrix(drawState.getViewMatrix(), size, rt->origin())
; |
235 } else { | 216 } else { |
236 this->flushMiscFixedFunctionState(); | 217 this->flushMiscFixedFunctionState(); |
237 | 218 |
238 GrBlendCoeff srcCoeff; | 219 GrBlendCoeff srcCoeff; |
239 GrBlendCoeff dstCoeff; | 220 GrBlendCoeff dstCoeff; |
240 GrDrawState::BlendOptFlags blendOpts = drawState.getBlendOpts(false, &sr
cCoeff, &dstCoeff); | 221 GrDrawState::BlendOptFlags blendOpts = drawState.getBlendOpts(false, &sr
cCoeff, &dstCoeff); |
241 if (GrDrawState::kSkipDraw_BlendOptFlag & blendOpts) { | 222 if (GrDrawState::kSkipDraw_BlendOptFlag & blendOpts) { |
242 return false; | 223 return false; |
243 } | 224 } |
244 | 225 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 GrCrash("Unknown geometry src type!"); | 326 GrCrash("Unknown geometry src type!"); |
346 } | 327 } |
347 | 328 |
348 SkASSERT(NULL != ibuf); | 329 SkASSERT(NULL != ibuf); |
349 SkASSERT(!ibuf->isLocked()); | 330 SkASSERT(!ibuf->isLocked()); |
350 *indexOffsetInBytes += ibuf->baseOffset(); | 331 *indexOffsetInBytes += ibuf->baseOffset(); |
351 } | 332 } |
352 GrGLAttribArrayState* attribState = | 333 GrGLAttribArrayState* attribState = |
353 fHWGeometryState.bindArrayAndBuffersToDraw(this, vbuf, ibuf); | 334 fHWGeometryState.bindArrayAndBuffersToDraw(this, vbuf, ibuf); |
354 | 335 |
355 uint32_t usedAttribArraysMask = 0; | 336 if (!fCurrentProgram->hasVertexShader()) { |
356 const GrVertexAttrib* vertexAttrib = this->getDrawState().getVertexAttribs()
; | 337 int posIdx = this->getDrawState().positionAttributeIndex(); |
357 int vertexAttribCount = this->getDrawState().getVertexAttribCount(); | 338 const GrVertexAttrib* vertexArray = this->getDrawState().getVertexAttrib
s() + posIdx; |
358 for (int vertexAttribIndex = 0; vertexAttribIndex < vertexAttribCount; | 339 GrVertexAttribType vertexArrayType = vertexArray->fType; |
359 ++vertexAttribIndex, ++vertexAttrib) { | 340 SkASSERT(!GrGLAttribTypeToLayout(vertexArrayType).fNormalized); |
| 341 SkASSERT(GrGLAttribTypeToLayout(vertexArrayType).fCount == 2); |
| 342 attribState->setFixedFunctionVertexArray(this, |
| 343 vbuf, |
| 344 2, |
| 345 GrGLAttribTypeToLayout(vertexAr
rayType).fType, |
| 346 stride, |
| 347 reinterpret_cast<GrGLvoid*>( |
| 348 vertexOffsetInBytes + vertexArr
ay->fOffset)); |
| 349 attribState->disableUnusedArrays(this, 0, true); |
| 350 } else { |
| 351 uint32_t usedAttribArraysMask = 0; |
| 352 const GrVertexAttrib* vertexAttrib = this->getDrawState().getVertexAttri
bs(); |
| 353 int vertexAttribCount = this->getDrawState().getVertexAttribCount(); |
| 354 for (int vertexAttribIndex = 0; vertexAttribIndex < vertexAttribCount; |
| 355 ++vertexAttribIndex, ++vertexAttrib) { |
360 | 356 |
361 usedAttribArraysMask |= (1 << vertexAttribIndex); | 357 usedAttribArraysMask |= (1 << vertexAttribIndex); |
362 GrVertexAttribType attribType = vertexAttrib->fType; | 358 GrVertexAttribType attribType = vertexAttrib->fType; |
363 attribState->set(this, | 359 attribState->set(this, |
364 vertexAttribIndex, | 360 vertexAttribIndex, |
365 vbuf, | 361 vbuf, |
366 GrGLAttribTypeToLayout(attribType).fCount, | 362 GrGLAttribTypeToLayout(attribType).fCount, |
367 GrGLAttribTypeToLayout(attribType).fType, | 363 GrGLAttribTypeToLayout(attribType).fType, |
368 GrGLAttribTypeToLayout(attribType).fNormalized, | 364 GrGLAttribTypeToLayout(attribType).fNormalized, |
369 stride, | 365 stride, |
370 reinterpret_cast<GrGLvoid*>( | 366 reinterpret_cast<GrGLvoid*>( |
371 vertexOffsetInBytes + vertexAttrib->fOffset)); | 367 vertexOffsetInBytes + vertexAttrib->fOffset)); |
| 368 } |
| 369 |
| 370 attribState->disableUnusedArrays(this, usedAttribArraysMask, false); |
372 } | 371 } |
373 | |
374 attribState->disableUnusedArrays(this, usedAttribArraysMask, false); | |
375 } | 372 } |
OLD | NEW |