| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright 2014 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 #include "GrOptDrawState.h" | |
| 9 | |
| 10 #include "GrDrawState.h" | |
| 11 #include "GrDrawTargetCaps.h" | |
| 12 #include "GrGpu.h" | |
| 13 #include "GrProcOptInfo.h" | |
| 14 #include "GrXferProcessor.h" | |
| 15 | |
| 16 GrOptDrawState::GrOptDrawState(const GrDrawState& drawState, | |
| 17 const GrPrimitiveProcessor* primProc, | |
| 18 const GrDrawTargetCaps& caps, | |
| 19 const GrScissorState& scissorState, | |
| 20 const GrDeviceCoordTexture* dstCopy) { | |
| 21 const GrProcOptInfo& colorPOI = drawState.colorProcInfo(primProc); | |
| 22 const GrProcOptInfo& coveragePOI = drawState.coverageProcInfo(primProc); | |
| 23 | |
| 24 // Create XferProcessor from DS's XPFactory | |
| 25 SkAutoTUnref<GrXferProcessor> xferProcessor( | |
| 26 drawState.getXPFactory()->createXferProcessor(colorPOI, coveragePOI)); | |
| 27 | |
| 28 GrColor overrideColor = GrColor_ILLEGAL; | |
| 29 if (colorPOI.firstEffectiveStageIndex() != 0) { | |
| 30 overrideColor = colorPOI.inputColorToEffectiveStage(); | |
| 31 } | |
| 32 | |
| 33 GrXferProcessor::OptFlags optFlags; | |
| 34 if (xferProcessor) { | |
| 35 fXferProcessor.reset(xferProcessor.get()); | |
| 36 | |
| 37 optFlags = xferProcessor->getOptimizations(colorPOI, | |
| 38 coveragePOI, | |
| 39 drawState.getStencil().doesWr
ite(), | |
| 40 &overrideColor, | |
| 41 caps); | |
| 42 } | |
| 43 | |
| 44 // When path rendering the stencil settings are not always set on the draw s
tate | |
| 45 // so we must check the draw type. In cases where we will skip drawing we si
mply return a | |
| 46 // null GrOptDrawState. | |
| 47 if (!xferProcessor || (GrXferProcessor::kSkipDraw_OptFlag & optFlags)) { | |
| 48 // Set the fields that don't default init and return. The lack of a rend
er target will | |
| 49 // indicate that this can be skipped. | |
| 50 fFlags = 0; | |
| 51 fDrawFace = GrDrawState::kInvalid_DrawFace; | |
| 52 return; | |
| 53 } | |
| 54 | |
| 55 fRenderTarget.reset(drawState.fRenderTarget.get()); | |
| 56 SkASSERT(fRenderTarget); | |
| 57 fScissorState = scissorState; | |
| 58 fStencilSettings = drawState.getStencil(); | |
| 59 fDrawFace = drawState.getDrawFace(); | |
| 60 // TODO move this out of optDrawState | |
| 61 if (dstCopy) { | |
| 62 fDstCopy = *dstCopy; | |
| 63 } | |
| 64 | |
| 65 fFlags = 0; | |
| 66 if (drawState.isHWAntialias()) { | |
| 67 fFlags |= kHWAA_Flag; | |
| 68 } | |
| 69 if (drawState.isDither()) { | |
| 70 fFlags |= kDither_Flag; | |
| 71 } | |
| 72 | |
| 73 int firstColorStageIdx = colorPOI.firstEffectiveStageIndex(); | |
| 74 | |
| 75 // TODO: Once we can handle single or four channel input into coverage stage
s then we can use | |
| 76 // drawState's coverageProcInfo (like color above) to set this initial infor
mation. | |
| 77 int firstCoverageStageIdx = 0; | |
| 78 | |
| 79 GrXferProcessor::BlendInfo blendInfo; | |
| 80 fXferProcessor->getBlendInfo(&blendInfo); | |
| 81 | |
| 82 this->adjustProgramFromOptimizations(drawState, optFlags, colorPOI, coverage
POI, | |
| 83 &firstColorStageIdx, &firstCoverageStag
eIdx); | |
| 84 | |
| 85 fDescInfo.fReadsDst = fXferProcessor->willReadDstColor(); | |
| 86 | |
| 87 bool usesLocalCoords = false; | |
| 88 | |
| 89 // Copy Stages from DS to ODS | |
| 90 for (int i = firstColorStageIdx; i < drawState.numColorStages(); ++i) { | |
| 91 SkNEW_APPEND_TO_TARRAY(&fFragmentStages, | |
| 92 GrPendingFragmentStage, | |
| 93 (drawState.fColorStages[i])); | |
| 94 usesLocalCoords = usesLocalCoords || | |
| 95 drawState.fColorStages[i].processor()->usesLocalCoords
(); | |
| 96 } | |
| 97 | |
| 98 fNumColorStages = fFragmentStages.count(); | |
| 99 for (int i = firstCoverageStageIdx; i < drawState.numCoverageStages(); ++i)
{ | |
| 100 SkNEW_APPEND_TO_TARRAY(&fFragmentStages, | |
| 101 GrPendingFragmentStage, | |
| 102 (drawState.fCoverageStages[i])); | |
| 103 usesLocalCoords = usesLocalCoords || | |
| 104 drawState.fCoverageStages[i].processor()->usesLocalCoo
rds(); | |
| 105 } | |
| 106 | |
| 107 // let the GP init the batch tracker | |
| 108 fInitBT.fColorIgnored = SkToBool(optFlags & GrXferProcessor::kIgnoreColor_Op
tFlag); | |
| 109 fInitBT.fOverrideColor = fInitBT.fColorIgnored ? GrColor_ILLEGAL : overrideC
olor; | |
| 110 fInitBT.fCoverageIgnored = SkToBool(optFlags & GrXferProcessor::kIgnoreCover
age_OptFlag); | |
| 111 fInitBT.fUsesLocalCoords = usesLocalCoords; | |
| 112 } | |
| 113 | |
| 114 void GrOptDrawState::adjustProgramFromOptimizations(const GrDrawState& ds, | |
| 115 GrXferProcessor::OptFlags fl
ags, | |
| 116 const GrProcOptInfo& colorPO
I, | |
| 117 const GrProcOptInfo& coverag
ePOI, | |
| 118 int* firstColorStageIdx, | |
| 119 int* firstCoverageStageIdx)
{ | |
| 120 fDescInfo.fReadsFragPosition = false; | |
| 121 | |
| 122 if ((flags & GrXferProcessor::kIgnoreColor_OptFlag) || | |
| 123 (flags & GrXferProcessor::kOverrideColor_OptFlag)) { | |
| 124 *firstColorStageIdx = ds.numColorStages(); | |
| 125 } else { | |
| 126 fDescInfo.fReadsFragPosition = colorPOI.readsFragPosition(); | |
| 127 } | |
| 128 | |
| 129 if (flags & GrXferProcessor::kIgnoreCoverage_OptFlag) { | |
| 130 *firstCoverageStageIdx = ds.numCoverageStages(); | |
| 131 } else { | |
| 132 if (coveragePOI.readsFragPosition()) { | |
| 133 fDescInfo.fReadsFragPosition = true; | |
| 134 } | |
| 135 } | |
| 136 } | |
| 137 | |
| 138 //////////////////////////////////////////////////////////////////////////////// | |
| 139 | |
| 140 bool GrOptDrawState::isEqual(const GrOptDrawState& that) const { | |
| 141 if (this->getRenderTarget() != that.getRenderTarget() || | |
| 142 this->fFragmentStages.count() != that.fFragmentStages.count() || | |
| 143 this->fNumColorStages != that.fNumColorStages || | |
| 144 this->fScissorState != that.fScissorState || | |
| 145 this->fFlags != that.fFlags || | |
| 146 this->fStencilSettings != that.fStencilSettings || | |
| 147 this->fDrawFace != that.fDrawFace || | |
| 148 this->fDstCopy.texture() != that.fDstCopy.texture()) { | |
| 149 return false; | |
| 150 } | |
| 151 | |
| 152 if (!this->getXferProcessor()->isEqual(*that.getXferProcessor())) { | |
| 153 return false; | |
| 154 } | |
| 155 | |
| 156 // The program desc comparison should have already assured that the stage co
unts match. | |
| 157 SkASSERT(this->numFragmentStages() == that.numFragmentStages()); | |
| 158 for (int i = 0; i < this->numFragmentStages(); i++) { | |
| 159 | |
| 160 if (this->getFragmentStage(i) != that.getFragmentStage(i)) { | |
| 161 return false; | |
| 162 } | |
| 163 } | |
| 164 return true; | |
| 165 } | |
| 166 | |
| OLD | NEW |