| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "GrOptDrawState.h" | 8 #include "GrOptDrawState.h" |
| 9 | 9 |
| 10 #include "GrDefaultGeoProcFactory.h" | 10 #include "GrDefaultGeoProcFactory.h" |
| 11 #include "GrDrawState.h" | 11 #include "GrDrawState.h" |
| 12 #include "GrDrawTargetCaps.h" | 12 #include "GrDrawTargetCaps.h" |
| 13 #include "GrGpu.h" | 13 #include "GrGpu.h" |
| 14 #include "GrProcOptInfo.h" | 14 #include "GrProcOptInfo.h" |
| 15 | 15 |
| 16 GrOptDrawState::GrOptDrawState(const GrDrawState& drawState, | 16 GrOptDrawState::GrOptDrawState(const GrDrawState& drawState, |
| 17 BlendOptFlags blendOptFlags, | 17 BlendOptFlags blendOptFlags, |
| 18 GrBlendCoeff optSrcCoeff, | 18 GrBlendCoeff optSrcCoeff, |
| 19 GrBlendCoeff optDstCoeff, | 19 GrBlendCoeff optDstCoeff, |
| 20 GrGpu* gpu, | 20 GrGpu* gpu, |
| 21 const ScissorState& scissorState, |
| 21 const GrDeviceCoordTexture* dstCopy, | 22 const GrDeviceCoordTexture* dstCopy, |
| 22 GrGpu::DrawType drawType) | 23 GrGpu::DrawType drawType) |
| 23 : fRenderTarget(drawState.fRenderTarget.get()) { | 24 : fRenderTarget(drawState.fRenderTarget.get()) { |
| 25 fScissorState = scissorState; |
| 24 fViewMatrix = drawState.getViewMatrix(); | 26 fViewMatrix = drawState.getViewMatrix(); |
| 25 fBlendConstant = drawState.getBlendConstant(); | 27 fBlendConstant = drawState.getBlendConstant(); |
| 26 fFlagBits = drawState.getFlagBits(); | 28 fFlagBits = drawState.getFlagBits(); |
| 27 fVAPtr = drawState.getVertexAttribs(); | 29 fVAPtr = drawState.getVertexAttribs(); |
| 28 fVACount = drawState.getVertexAttribCount(); | 30 fVACount = drawState.getVertexAttribCount(); |
| 29 fVAStride = drawState.getVertexStride(); | 31 fVAStride = drawState.getVertexStride(); |
| 30 fStencilSettings = drawState.getStencil(); | 32 fStencilSettings = drawState.getStencil(); |
| 31 fDrawFace = (DrawFace)drawState.getDrawFace(); | 33 fDrawFace = (DrawFace)drawState.getDrawFace(); |
| 32 fBlendOptFlags = blendOptFlags; | 34 fBlendOptFlags = blendOptFlags; |
| 33 fSrcBlend = optSrcCoeff; | 35 fSrcBlend = optSrcCoeff; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 } | 86 } |
| 85 | 87 |
| 86 this->setOutputStateInfo(drawState, *gpu->caps(), &descInfo); | 88 this->setOutputStateInfo(drawState, *gpu->caps(), &descInfo); |
| 87 | 89 |
| 88 // now create a key | 90 // now create a key |
| 89 gpu->buildProgramDesc(*this, descInfo, drawType, dstCopy, &fDesc); | 91 gpu->buildProgramDesc(*this, descInfo, drawType, dstCopy, &fDesc); |
| 90 }; | 92 }; |
| 91 | 93 |
| 92 GrOptDrawState* GrOptDrawState::Create(const GrDrawState& drawState, | 94 GrOptDrawState* GrOptDrawState::Create(const GrDrawState& drawState, |
| 93 GrGpu* gpu, | 95 GrGpu* gpu, |
| 96 const ScissorState& scissorState, |
| 94 const GrDeviceCoordTexture* dstCopy, | 97 const GrDeviceCoordTexture* dstCopy, |
| 95 GrGpu::DrawType drawType) { | 98 GrGpu::DrawType drawType) { |
| 96 GrBlendCoeff srcCoeff; | 99 GrBlendCoeff srcCoeff; |
| 97 GrBlendCoeff dstCoeff; | 100 GrBlendCoeff dstCoeff; |
| 98 BlendOptFlags blendFlags = (BlendOptFlags) drawState.getBlendOpts(false, | 101 BlendOptFlags blendFlags = (BlendOptFlags) drawState.getBlendOpts(false, |
| 99 &srcCoeff, | 102 &srcCoeff, |
| 100 &dstCoeff)
; | 103 &dstCoeff)
; |
| 101 | 104 |
| 102 // If our blend coeffs are set to 0,1 we know we will not end up drawing unl
ess we are | 105 // If our blend coeffs are set to 0,1 we know we will not end up drawing unl
ess we are |
| 103 // stenciling. When path rendering the stencil settings are not always set o
n the draw state | 106 // stenciling. When path rendering the stencil settings are not always set o
n the draw state |
| 104 // so we must check the draw type. In cases where we will skip drawing we si
mply return a | 107 // so we must check the draw type. In cases where we will skip drawing we si
mply return a |
| 105 // null GrOptDrawState. | 108 // null GrOptDrawState. |
| 106 if (kZero_GrBlendCoeff == srcCoeff && kOne_GrBlendCoeff == dstCoeff && | 109 if (kZero_GrBlendCoeff == srcCoeff && kOne_GrBlendCoeff == dstCoeff && |
| 107 !drawState.getStencil().doesWrite() && GrGpu::kStencilPath_DrawType != d
rawType) { | 110 !drawState.getStencil().doesWrite() && GrGpu::kStencilPath_DrawType != d
rawType) { |
| 108 return NULL; | 111 return NULL; |
| 109 } | 112 } |
| 110 | 113 |
| 111 return SkNEW_ARGS(GrOptDrawState, (drawState, blendFlags, srcCoeff, | 114 return SkNEW_ARGS(GrOptDrawState, (drawState, blendFlags, srcCoeff, |
| 112 dstCoeff, gpu, dstCopy, drawType)); | 115 dstCoeff, gpu, scissorState, dstCopy, dra
wType)); |
| 113 } | 116 } |
| 114 | 117 |
| 115 void GrOptDrawState::setOutputStateInfo(const GrDrawState& ds, | 118 void GrOptDrawState::setOutputStateInfo(const GrDrawState& ds, |
| 116 const GrDrawTargetCaps& caps, | 119 const GrDrawTargetCaps& caps, |
| 117 GrProgramDesc::DescInfo* descInfo) { | 120 GrProgramDesc::DescInfo* descInfo) { |
| 118 // Set this default and then possibly change our mind if there is coverage. | 121 // Set this default and then possibly change our mind if there is coverage. |
| 119 descInfo->fPrimaryOutputType = GrProgramDesc::kModulate_PrimaryOutputType; | 122 descInfo->fPrimaryOutputType = GrProgramDesc::kModulate_PrimaryOutputType; |
| 120 descInfo->fSecondaryOutputType = GrProgramDesc::kNone_SecondaryOutputType; | 123 descInfo->fSecondaryOutputType = GrProgramDesc::kNone_SecondaryOutputType; |
| 121 | 124 |
| 122 // If we do have coverage determine whether it matters. Dual source blendin
g is expensive so | 125 // If we do have coverage determine whether it matters. Dual source blendin
g is expensive so |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 bool GrOptDrawState::operator== (const GrOptDrawState& that) const { | 257 bool GrOptDrawState::operator== (const GrOptDrawState& that) const { |
| 255 if (this->fDesc != that.fDesc) { | 258 if (this->fDesc != that.fDesc) { |
| 256 return false; | 259 return false; |
| 257 } | 260 } |
| 258 bool usingVertexColors = that.fDesc.header().fColorAttributeIndex != -1; | 261 bool usingVertexColors = that.fDesc.header().fColorAttributeIndex != -1; |
| 259 if (!usingVertexColors && this->fColor != that.fColor) { | 262 if (!usingVertexColors && this->fColor != that.fColor) { |
| 260 return false; | 263 return false; |
| 261 } | 264 } |
| 262 | 265 |
| 263 if (this->getRenderTarget() != that.getRenderTarget() || | 266 if (this->getRenderTarget() != that.getRenderTarget() || |
| 267 this->fScissorState != that.fScissorState || |
| 264 !this->fViewMatrix.cheapEqualTo(that.fViewMatrix) || | 268 !this->fViewMatrix.cheapEqualTo(that.fViewMatrix) || |
| 265 this->fSrcBlend != that.fSrcBlend || | 269 this->fSrcBlend != that.fSrcBlend || |
| 266 this->fDstBlend != that.fDstBlend || | 270 this->fDstBlend != that.fDstBlend || |
| 267 this->fBlendConstant != that.fBlendConstant || | 271 this->fBlendConstant != that.fBlendConstant || |
| 268 this->fFlagBits != that.fFlagBits || | 272 this->fFlagBits != that.fFlagBits || |
| 269 this->fVACount != that.fVACount || | 273 this->fVACount != that.fVACount || |
| 270 this->fVAStride != that.fVAStride || | 274 this->fVAStride != that.fVAStride || |
| 271 memcmp(this->fVAPtr, that.fVAPtr, this->fVACount * sizeof(GrVertexAttrib
)) || | 275 memcmp(this->fVAPtr, that.fVAPtr, this->fVACount * sizeof(GrVertexAttrib
)) || |
| 272 this->fStencilSettings != that.fStencilSettings || | 276 this->fStencilSettings != that.fStencilSettings || |
| 273 this->fDrawFace != that.fDrawFace) { | 277 this->fDrawFace != that.fDrawFace) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 293 SkASSERT(this->numFragmentStages() == that.numFragmentStages()); | 297 SkASSERT(this->numFragmentStages() == that.numFragmentStages()); |
| 294 for (int i = 0; i < this->numFragmentStages(); i++) { | 298 for (int i = 0; i < this->numFragmentStages(); i++) { |
| 295 | 299 |
| 296 if (this->getFragmentStage(i) != that.getFragmentStage(i)) { | 300 if (this->getFragmentStage(i) != that.getFragmentStage(i)) { |
| 297 return false; | 301 return false; |
| 298 } | 302 } |
| 299 } | 303 } |
| 300 return true; | 304 return true; |
| 301 } | 305 } |
| 302 | 306 |
| OLD | NEW |