| 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 "GrDrawState.h" | 10 #include "GrDrawState.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 // Copy GeometryProcesssor from DS or ODS | 26 // Copy GeometryProcesssor from DS or ODS |
| 27 if (gp) { | 27 if (gp) { |
| 28 SkASSERT(!pathProc); | 28 SkASSERT(!pathProc); |
| 29 SkASSERT(!(GrGpu::IsPathRenderingDrawType(drawType) || | 29 SkASSERT(!(GrGpu::IsPathRenderingDrawType(drawType) || |
| 30 GrGpu::kStencilPath_DrawType == drawType)); | 30 GrGpu::kStencilPath_DrawType == drawType)); |
| 31 fGeometryProcessor.reset(gp); | 31 fGeometryProcessor.reset(gp); |
| 32 fPrimitiveProcessor.reset(gp); | 32 fPrimitiveProcessor.reset(gp); |
| 33 } else { | 33 } else { |
| 34 SkASSERT(!gp && pathProc && (GrGpu::IsPathRenderingDrawType(drawType) || | 34 SkASSERT(!gp && pathProc && (GrGpu::IsPathRenderingDrawType(drawType) || |
| 35 GrGpu::kStencilPath_DrawType == drawType)); | 35 GrGpu::kStencilPath_DrawType == drawType)); |
| 36 fPrimitiveProcessor.reset(pathProc); | 36 fPrimitiveProcessor.reset(pathProc); |
| 37 } | 37 } |
| 38 | 38 |
| 39 | 39 |
| 40 const GrProcOptInfo& colorPOI = drawState.colorProcInfo(fPrimitiveProcessor)
; | 40 const GrProcOptInfo& colorPOI = drawState.colorProcInfo(fPrimitiveProcessor)
; |
| 41 const GrProcOptInfo& coveragePOI = drawState.coverageProcInfo(fPrimitiveProc
essor); | 41 const GrProcOptInfo& coveragePOI = drawState.coverageProcInfo(fPrimitiveProc
essor); |
| 42 | |
| 43 fColor = colorPOI.inputColorToEffectiveStage(); | |
| 44 // TODO fix this when coverage stages work correctly | |
| 45 // fCoverage = coveragePOI.inputColorToEffectiveStage(); | |
| 46 fCoverage = fPrimitiveProcessor->coverage(); | |
| 47 | 42 |
| 48 // Create XferProcessor from DS's XPFactory | 43 // Create XferProcessor from DS's XPFactory |
| 49 SkAutoTUnref<GrXferProcessor> xferProcessor( | 44 SkAutoTUnref<GrXferProcessor> xferProcessor( |
| 50 drawState.getXPFactory()->createXferProcessor(colorPOI, coveragePOI)); | 45 drawState.getXPFactory()->createXferProcessor(colorPOI, coveragePOI)); |
| 51 | 46 |
| 47 GrColor color = GrColor_ILLEGAL; |
| 48 if (colorPOI.firstEffectiveStageIndex() != 0) { |
| 49 color = colorPOI.inputColorToEffectiveStage(); |
| 50 } |
| 51 |
| 52 uint8_t coverage; |
| 52 GrXferProcessor::OptFlags optFlags; | 53 GrXferProcessor::OptFlags optFlags; |
| 53 if (xferProcessor) { | 54 if (xferProcessor) { |
| 54 fXferProcessor.reset(xferProcessor.get()); | 55 fXferProcessor.reset(xferProcessor.get()); |
| 55 | 56 |
| 56 optFlags = xferProcessor->getOptimizations(colorPOI, | 57 optFlags = xferProcessor->getOptimizations(colorPOI, |
| 57 coveragePOI, | 58 coveragePOI, |
| 58 drawState.isCoverageDrawing()
, | 59 drawState.isCoverageDrawing()
, |
| 59 drawState.isColorWriteDisable
d(), | 60 drawState.isColorWriteDisable
d(), |
| 60 drawState.getStencil().doesWr
ite(), | 61 drawState.getStencil().doesWr
ite(), |
| 61 &fColor, | 62 &color, |
| 62 &fCoverage, | 63 &coverage, |
| 63 caps); | 64 caps); |
| 64 } | 65 } |
| 65 | 66 |
| 66 // When path rendering the stencil settings are not always set on the draw s
tate | 67 // When path rendering the stencil settings are not always set on the draw s
tate |
| 67 // so we must check the draw type. In cases where we will skip drawing we si
mply return a | 68 // so we must check the draw type. In cases where we will skip drawing we si
mply return a |
| 68 // null GrOptDrawState. | 69 // null GrOptDrawState. |
| 69 if (!xferProcessor || ((GrXferProcessor::kSkipDraw_OptFlag & optFlags) && | 70 if (!xferProcessor || ((GrXferProcessor::kSkipDraw_OptFlag & optFlags) && |
| 70 GrGpu::kStencilPath_DrawType != drawType)) { | 71 GrGpu::kStencilPath_DrawType != drawType)) { |
| 71 // Set the fields that don't default init and return. The lack of a rend
er target will | 72 // Set the fields that don't default init and return. The lack of a rend
er target will |
| 72 // indicate that this can be skipped. | 73 // indicate that this can be skipped. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 91 if (drawState.isHWAntialias()) { | 92 if (drawState.isHWAntialias()) { |
| 92 fFlags |= kHWAA_Flag; | 93 fFlags |= kHWAA_Flag; |
| 93 } | 94 } |
| 94 if (drawState.isColorWriteDisabled()) { | 95 if (drawState.isColorWriteDisabled()) { |
| 95 fFlags |= kDisableColorWrite_Flag; | 96 fFlags |= kDisableColorWrite_Flag; |
| 96 } | 97 } |
| 97 if (drawState.isDither()) { | 98 if (drawState.isDither()) { |
| 98 fFlags |= kDither_Flag; | 99 fFlags |= kDither_Flag; |
| 99 } | 100 } |
| 100 | 101 |
| 101 fDescInfo.fHasVertexColor = gp && gp->hasVertexColor(); | 102 // TODO move local coords completely into GP |
| 102 | |
| 103 fDescInfo.fHasVertexCoverage = gp && gp->hasVertexCoverage(); | |
| 104 | |
| 105 bool hasLocalCoords = gp && gp->hasLocalCoords(); | 103 bool hasLocalCoords = gp && gp->hasLocalCoords(); |
| 106 | 104 |
| 107 int firstColorStageIdx = colorPOI.firstEffectiveStageIndex(); | 105 int firstColorStageIdx = colorPOI.firstEffectiveStageIndex(); |
| 108 fDescInfo.fInputColorIsUsed = colorPOI.inputColorIsUsed(); | |
| 109 if (colorPOI.removeVertexAttrib()) { | |
| 110 fDescInfo.fHasVertexColor = false; | |
| 111 } | |
| 112 | 106 |
| 113 // TODO: Once we can handle single or four channel input into coverage stage
s then we can use | 107 // TODO: Once we can handle single or four channel input into coverage stage
s then we can use |
| 114 // drawState's coverageProcInfo (like color above) to set this initial infor
mation. | 108 // drawState's coverageProcInfo (like color above) to set this initial infor
mation. |
| 115 int firstCoverageStageIdx = 0; | 109 int firstCoverageStageIdx = 0; |
| 116 fDescInfo.fInputCoverageIsUsed = true; | |
| 117 | 110 |
| 118 GrXferProcessor::BlendInfo blendInfo; | 111 GrXferProcessor::BlendInfo blendInfo; |
| 119 fXferProcessor->getBlendInfo(&blendInfo); | 112 fXferProcessor->getBlendInfo(&blendInfo); |
| 120 | 113 |
| 121 this->adjustProgramFromOptimizations(drawState, optFlags, colorPOI, coverage
POI, | 114 this->adjustProgramFromOptimizations(drawState, optFlags, colorPOI, coverage
POI, |
| 122 &firstColorStageIdx, &firstCoverageStag
eIdx); | 115 &firstColorStageIdx, &firstCoverageStag
eIdx); |
| 123 | 116 |
| 124 fDescInfo.fRequiresLocalCoordAttrib = hasLocalCoords; | 117 fDescInfo.fRequiresLocalCoordAttrib = hasLocalCoords; |
| 125 | 118 |
| 126 // Copy Stages from DS to ODS | 119 // Copy Stages from DS to ODS |
| 127 for (int i = firstColorStageIdx; i < drawState.numColorStages(); ++i) { | 120 for (int i = firstColorStageIdx; i < drawState.numColorStages(); ++i) { |
| 128 SkNEW_APPEND_TO_TARRAY(&fFragmentStages, | 121 SkNEW_APPEND_TO_TARRAY(&fFragmentStages, |
| 129 GrPendingFragmentStage, | 122 GrPendingFragmentStage, |
| 130 (drawState.fColorStages[i], hasLocalCoords)); | 123 (drawState.fColorStages[i], hasLocalCoords)); |
| 131 } | 124 } |
| 132 | 125 |
| 133 fNumColorStages = fFragmentStages.count(); | 126 fNumColorStages = fFragmentStages.count(); |
| 134 for (int i = firstCoverageStageIdx; i < drawState.numCoverageStages(); ++i)
{ | 127 for (int i = firstCoverageStageIdx; i < drawState.numCoverageStages(); ++i)
{ |
| 135 SkNEW_APPEND_TO_TARRAY(&fFragmentStages, | 128 SkNEW_APPEND_TO_TARRAY(&fFragmentStages, |
| 136 GrPendingFragmentStage, | 129 GrPendingFragmentStage, |
| 137 (drawState.fCoverageStages[i], hasLocalCoords)); | 130 (drawState.fCoverageStages[i], hasLocalCoords)); |
| 138 } | 131 } |
| 139 | 132 |
| 140 // let the GP init the batch tracker | 133 // let the GP init the batch tracker |
| 141 if (gp) { | 134 GrGeometryProcessor::InitBT init; |
| 142 GrGeometryProcessor::InitBT init; | 135 init.fColorIgnored = SkToBool(optFlags & GrXferProcessor::kClearColorStages_
OptFlag); |
| 143 init.fOutputColor = fDescInfo.fInputColorIsUsed; | 136 init.fOverrideColor = init.fColorIgnored ? GrColor_ILLEGAL : color; |
| 144 init.fOutputCoverage = fDescInfo.fInputCoverageIsUsed; | 137 init.fCoverageIgnored = SkToBool(optFlags & GrXferProcessor::kClearCoverageS
tages_OptFlag); |
| 145 init.fColor = this->getColor(); | 138 fPrimitiveProcessor->initBatchTracker(&fBatchTracker, init); |
| 146 init.fCoverage = this->getCoverage(); | |
| 147 fGeometryProcessor->initBatchTracker(&fBatchTracker, init); | |
| 148 } | |
| 149 } | 139 } |
| 150 | 140 |
| 151 void GrOptDrawState::adjustProgramFromOptimizations(const GrDrawState& ds, | 141 void GrOptDrawState::adjustProgramFromOptimizations(const GrDrawState& ds, |
| 152 GrXferProcessor::OptFlags fl
ags, | 142 GrXferProcessor::OptFlags fl
ags, |
| 153 const GrProcOptInfo& colorPO
I, | 143 const GrProcOptInfo& colorPO
I, |
| 154 const GrProcOptInfo& coverag
ePOI, | 144 const GrProcOptInfo& coverag
ePOI, |
| 155 int* firstColorStageIdx, | 145 int* firstColorStageIdx, |
| 156 int* firstCoverageStageIdx)
{ | 146 int* firstCoverageStageIdx)
{ |
| 157 fDescInfo.fReadsDst = false; | 147 fDescInfo.fReadsDst = false; |
| 158 fDescInfo.fReadsFragPosition = false; | 148 fDescInfo.fReadsFragPosition = false; |
| 159 | 149 |
| 160 if (flags & GrXferProcessor::kClearColorStages_OptFlag) { | 150 if (flags & GrXferProcessor::kClearColorStages_OptFlag) { |
| 161 fDescInfo.fInputColorIsUsed = true; | |
| 162 *firstColorStageIdx = ds.numColorStages(); | 151 *firstColorStageIdx = ds.numColorStages(); |
| 163 fDescInfo.fHasVertexColor = false; | |
| 164 } else { | 152 } else { |
| 165 fDescInfo.fReadsDst = colorPOI.readsDst(); | 153 fDescInfo.fReadsDst = colorPOI.readsDst(); |
| 166 fDescInfo.fReadsFragPosition = colorPOI.readsFragPosition(); | 154 fDescInfo.fReadsFragPosition = colorPOI.readsFragPosition(); |
| 167 } | 155 } |
| 168 | 156 |
| 169 if (flags & GrXferProcessor::kClearCoverageStages_OptFlag) { | 157 if (flags & GrXferProcessor::kClearCoverageStages_OptFlag) { |
| 170 fDescInfo.fInputCoverageIsUsed = true; | |
| 171 *firstCoverageStageIdx = ds.numCoverageStages(); | 158 *firstCoverageStageIdx = ds.numCoverageStages(); |
| 172 fDescInfo.fHasVertexCoverage = false; | |
| 173 } else { | 159 } else { |
| 174 if (coveragePOI.readsDst()) { | 160 if (coveragePOI.readsDst()) { |
| 175 fDescInfo.fReadsDst = true; | 161 fDescInfo.fReadsDst = true; |
| 176 } | 162 } |
| 177 if (coveragePOI.readsFragPosition()) { | 163 if (coveragePOI.readsFragPosition()) { |
| 178 fDescInfo.fReadsFragPosition = true; | 164 fDescInfo.fReadsFragPosition = true; |
| 179 } | 165 } |
| 180 } | 166 } |
| 181 } | 167 } |
| 182 | 168 |
| 183 void GrOptDrawState::finalize(GrGpu* gpu) { | 169 void GrOptDrawState::finalize(GrGpu* gpu) { |
| 184 gpu->buildProgramDesc(*this, fDescInfo, fDrawType, &fDesc); | 170 gpu->buildProgramDesc(*this, fDescInfo, fDrawType, &fDesc); |
| 185 fFinalized = true; | 171 fFinalized = true; |
| 186 } | 172 } |
| 187 | 173 |
| 188 //////////////////////////////////////////////////////////////////////////////// | 174 //////////////////////////////////////////////////////////////////////////////// |
| 189 | 175 |
| 190 bool GrOptDrawState::operator== (const GrOptDrawState& that) const { | 176 bool GrOptDrawState::operator== (const GrOptDrawState& that) const { |
| 191 if (fDescInfo != that.fDescInfo) { | 177 if (fDescInfo != that.fDescInfo) { |
| 192 return false; | 178 return false; |
| 193 } | 179 } |
| 194 | 180 |
| 195 if (!fDescInfo.fHasVertexColor && this->fColor != that.fColor) { | |
| 196 return false; | |
| 197 } | |
| 198 | |
| 199 if (this->getRenderTarget() != that.getRenderTarget() || | 181 if (this->getRenderTarget() != that.getRenderTarget() || |
| 200 this->fFragmentStages.count() != that.fFragmentStages.count() || | 182 this->fFragmentStages.count() != that.fFragmentStages.count() || |
| 201 this->fNumColorStages != that.fNumColorStages || | 183 this->fNumColorStages != that.fNumColorStages || |
| 202 this->fScissorState != that.fScissorState || | 184 this->fScissorState != that.fScissorState || |
| 203 !this->fViewMatrix.cheapEqualTo(that.fViewMatrix) || | 185 !this->fViewMatrix.cheapEqualTo(that.fViewMatrix) || |
| 204 this->fDrawType != that.fDrawType || | 186 this->fDrawType != that.fDrawType || |
| 205 this->fFlags != that.fFlags || | 187 this->fFlags != that.fFlags || |
| 206 this->fStencilSettings != that.fStencilSettings || | 188 this->fStencilSettings != that.fStencilSettings || |
| 207 this->fDrawFace != that.fDrawFace || | 189 this->fDrawFace != that.fDrawFace || |
| 208 this->fDstCopy.texture() != that.fDstCopy.texture()) { | 190 this->fDstCopy.texture() != that.fDstCopy.texture()) { |
| 209 return false; | 191 return false; |
| 210 } | 192 } |
| 211 | 193 |
| 212 if (!fDescInfo.fHasVertexCoverage && this->fCoverage != that.fCoverage) { | 194 if (!this->getPrimitiveProcessor()->canMakeEqual(fBatchTracker, |
| 195 *that.getPrimitiveProcessor
(), |
| 196 that.getBatchTracker())) { |
| 213 return false; | 197 return false; |
| 214 } | 198 } |
| 215 | 199 |
| 216 if (this->hasGeometryProcessor()) { | |
| 217 if (!that.hasGeometryProcessor()) { | |
| 218 return false; | |
| 219 } else if (!this->getGeometryProcessor()->isEqual(*that.getGeometryProce
ssor())) { | |
| 220 return false; | |
| 221 } | |
| 222 } else if (that.hasGeometryProcessor()) { | |
| 223 return false; | |
| 224 } | |
| 225 | |
| 226 if (!this->getXferProcessor()->isEqual(*that.getXferProcessor())) { | 200 if (!this->getXferProcessor()->isEqual(*that.getXferProcessor())) { |
| 227 return false; | 201 return false; |
| 228 } | 202 } |
| 229 | 203 |
| 230 // The program desc comparison should have already assured that the stage co
unts match. | 204 // The program desc comparison should have already assured that the stage co
unts match. |
| 231 SkASSERT(this->numFragmentStages() == that.numFragmentStages()); | 205 SkASSERT(this->numFragmentStages() == that.numFragmentStages()); |
| 232 for (int i = 0; i < this->numFragmentStages(); i++) { | 206 for (int i = 0; i < this->numFragmentStages(); i++) { |
| 233 | 207 |
| 234 if (this->getFragmentStage(i) != that.getFragmentStage(i)) { | 208 if (this->getFragmentStage(i) != that.getFragmentStage(i)) { |
| 235 return false; | 209 return false; |
| 236 } | 210 } |
| 237 } | 211 } |
| 212 |
| 213 // Now update the GrPrimitiveProcessor's batch tracker |
| 214 fPrimitiveProcessor->makeEqual(&fBatchTracker, that.getBatchTracker()); |
| 238 return true; | 215 return true; |
| 239 } | 216 } |
| 240 | 217 |
| OLD | NEW |