| 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" |
| 11 #include "GrDrawTargetCaps.h" | 11 #include "GrDrawTargetCaps.h" |
| 12 #include "GrGpu.h" | 12 #include "GrGpu.h" |
| 13 #include "GrProcOptInfo.h" | 13 #include "GrProcOptInfo.h" |
| 14 #include "GrXferProcessor.h" | 14 #include "GrXferProcessor.h" |
| 15 | 15 |
| 16 GrOptDrawState::GrOptDrawState(const GrDrawState& drawState, | 16 GrOptDrawState::GrOptDrawState(const GrDrawState& drawState, |
| 17 const GrGeometryProcessor* gp, | 17 GrColor color, |
| 18 const GrPathProcessor* pathProc, | 18 uint8_t coverage, |
| 19 const GrDrawTargetCaps& caps, | 19 const GrDrawTargetCaps& caps, |
| 20 const ScissorState& scissorState, | 20 const ScissorState& scissorState, |
| 21 const GrDeviceCoordTexture* dstCopy, | 21 const GrDeviceCoordTexture* dstCopy, |
| 22 GrGpu::DrawType drawType) | 22 GrGpu::DrawType drawType) |
| 23 : fFinalized(false) { | 23 : fFinalized(false) { |
| 24 GrColor coverageColor = GrColorPackRGBA(coverage, coverage, coverage, covera
ge); |
| 24 fDrawType = drawType; | 25 fDrawType = drawType; |
| 25 | 26 |
| 26 // Copy GeometryProcesssor from DS or ODS | 27 const GrProcOptInfo& colorPOI = drawState.colorProcInfo(color); |
| 27 if (gp) { | 28 const GrProcOptInfo& coveragePOI = drawState.coverageProcInfo(coverageColor)
; |
| 28 SkASSERT(!pathProc); | |
| 29 SkASSERT(!(GrGpu::IsPathRenderingDrawType(drawType) || | |
| 30 GrGpu::kStencilPath_DrawType == drawType)); | |
| 31 fGeometryProcessor.reset(gp); | |
| 32 fPrimitiveProcessor.reset(gp); | |
| 33 } else { | |
| 34 SkASSERT(!gp && pathProc && (GrGpu::IsPathRenderingDrawType(drawType) || | |
| 35 GrGpu::kStencilPath_DrawType == drawType)); | |
| 36 fPrimitiveProcessor.reset(pathProc); | |
| 37 } | |
| 38 | |
| 39 | |
| 40 const GrProcOptInfo& colorPOI = drawState.colorProcInfo(fPrimitiveProcessor)
; | |
| 41 const GrProcOptInfo& coveragePOI = drawState.coverageProcInfo(fPrimitiveProc
essor); | |
| 42 | 29 |
| 43 fColor = colorPOI.inputColorToEffectiveStage(); | 30 fColor = colorPOI.inputColorToEffectiveStage(); |
| 44 // TODO fix this when coverage stages work correctly | 31 fCoverage = coverage; |
| 45 // fCoverage = coveragePOI.inputColorToEffectiveStage(); | |
| 46 fCoverage = fPrimitiveProcessor->coverage(); | |
| 47 | 32 |
| 48 // Create XferProcessor from DS's XPFactory | 33 // Create XferProcessor from DS's XPFactory |
| 49 SkAutoTUnref<GrXferProcessor> xferProcessor( | 34 SkAutoTUnref<GrXferProcessor> xferProcessor( |
| 50 drawState.getXPFactory()->createXferProcessor(colorPOI, coveragePOI)); | 35 drawState.getXPFactory()->createXferProcessor(colorPOI, coveragePOI)); |
| 51 | 36 |
| 52 GrXferProcessor::OptFlags optFlags; | 37 GrXferProcessor::OptFlags optFlags; |
| 53 if (xferProcessor) { | 38 if (xferProcessor) { |
| 54 fXferProcessor.reset(xferProcessor.get()); | 39 fXferProcessor.reset(xferProcessor.get()); |
| 55 | 40 |
| 56 optFlags = xferProcessor->getOptimizations(colorPOI, | 41 optFlags = xferProcessor->getOptimizations(colorPOI, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 if (drawState.isHWAntialias()) { | 79 if (drawState.isHWAntialias()) { |
| 95 fFlags |= kHWAA_Flag; | 80 fFlags |= kHWAA_Flag; |
| 96 } | 81 } |
| 97 if (drawState.isColorWriteDisabled()) { | 82 if (drawState.isColorWriteDisabled()) { |
| 98 fFlags |= kDisableColorWrite_Flag; | 83 fFlags |= kDisableColorWrite_Flag; |
| 99 } | 84 } |
| 100 if (drawState.isDither()) { | 85 if (drawState.isDither()) { |
| 101 fFlags |= kDither_Flag; | 86 fFlags |= kDither_Flag; |
| 102 } | 87 } |
| 103 | 88 |
| 104 fDescInfo.fHasVertexColor = gp && gp->hasVertexColor(); | 89 fDescInfo.fHasVertexColor = drawState.hasGeometryProcessor() && |
| 90 drawState.getGeometryProcessor()->hasVertexColor
(); |
| 105 | 91 |
| 106 fDescInfo.fHasVertexCoverage = gp && gp->hasVertexCoverage(); | 92 fDescInfo.fHasVertexCoverage = drawState.hasGeometryProcessor() && |
| 93 drawState.getGeometryProcessor()->hasVertexCo
verage(); |
| 107 | 94 |
| 108 bool hasLocalCoords = gp && gp->hasLocalCoords(); | 95 bool hasLocalCoords = drawState.hasGeometryProcessor() && |
| 96 drawState.getGeometryProcessor()->hasLocalCoords(); |
| 109 | 97 |
| 110 int firstColorStageIdx = colorPOI.firstEffectiveStageIndex(); | 98 int firstColorStageIdx = colorPOI.firstEffectiveStageIndex(); |
| 111 fDescInfo.fInputColorIsUsed = colorPOI.inputColorIsUsed(); | 99 fDescInfo.fInputColorIsUsed = colorPOI.inputColorIsUsed(); |
| 112 if (colorPOI.removeVertexAttrib()) { | 100 if (colorPOI.removeVertexAttrib()) { |
| 113 fDescInfo.fHasVertexColor = false; | 101 fDescInfo.fHasVertexColor = false; |
| 114 } | 102 } |
| 115 | 103 |
| 116 // TODO: Once we can handle single or four channel input into coverage stage
s then we can use | 104 // TODO: Once we can handle single or four channel input into coverage stage
s then we can use |
| 117 // drawState's coverageProcInfo (like color above) to set this initial infor
mation. | 105 // drawState's coverageProcInfo (like color above) to set this initial infor
mation. |
| 118 int firstCoverageStageIdx = 0; | 106 int firstCoverageStageIdx = 0; |
| 119 fDescInfo.fInputCoverageIsUsed = true; | 107 fDescInfo.fInputCoverageIsUsed = true; |
| 120 | 108 |
| 109 |
| 121 GrXferProcessor::BlendInfo blendInfo; | 110 GrXferProcessor::BlendInfo blendInfo; |
| 122 fXferProcessor->getBlendInfo(&blendInfo); | 111 fXferProcessor->getBlendInfo(&blendInfo); |
| 123 fSrcBlend = blendInfo.fSrcBlend; | 112 fSrcBlend = blendInfo.fSrcBlend; |
| 124 fDstBlend = blendInfo.fDstBlend; | 113 fDstBlend = blendInfo.fDstBlend; |
| 125 fBlendConstant = blendInfo.fBlendConstant; | 114 fBlendConstant = blendInfo.fBlendConstant; |
| 126 | 115 |
| 127 this->adjustProgramFromOptimizations(drawState, optFlags, colorPOI, coverage
POI, | 116 this->adjustProgramFromOptimizations(drawState, optFlags, colorPOI, coverage
POI, |
| 128 &firstColorStageIdx, &firstCoverageStag
eIdx); | 117 &firstColorStageIdx, &firstCoverageStag
eIdx); |
| 129 | 118 |
| 130 fDescInfo.fRequiresLocalCoordAttrib = hasLocalCoords; | 119 fDescInfo.fRequiresLocalCoordAttrib = hasLocalCoords; |
| 131 | 120 |
| 121 // Copy GeometryProcesssor from DS or ODS |
| 122 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType) || |
| 123 GrGpu::kStencilPath_DrawType || |
| 124 drawState.hasGeometryProcessor()); |
| 125 fGeometryProcessor.reset(drawState.getGeometryProcessor()); |
| 126 |
| 132 // Copy Stages from DS to ODS | 127 // Copy Stages from DS to ODS |
| 133 for (int i = firstColorStageIdx; i < drawState.numColorStages(); ++i) { | 128 for (int i = firstColorStageIdx; i < drawState.numColorStages(); ++i) { |
| 134 SkNEW_APPEND_TO_TARRAY(&fFragmentStages, | 129 SkNEW_APPEND_TO_TARRAY(&fFragmentStages, |
| 135 GrPendingFragmentStage, | 130 GrPendingFragmentStage, |
| 136 (drawState.fColorStages[i], hasLocalCoords)); | 131 (drawState.fColorStages[i], hasLocalCoords)); |
| 137 } | 132 } |
| 138 | 133 |
| 139 fNumColorStages = fFragmentStages.count(); | 134 fNumColorStages = fFragmentStages.count(); |
| 140 for (int i = firstCoverageStageIdx; i < drawState.numCoverageStages(); ++i)
{ | 135 for (int i = firstCoverageStageIdx; i < drawState.numCoverageStages(); ++i)
{ |
| 141 SkNEW_APPEND_TO_TARRAY(&fFragmentStages, | 136 SkNEW_APPEND_TO_TARRAY(&fFragmentStages, |
| 142 GrPendingFragmentStage, | 137 GrPendingFragmentStage, |
| 143 (drawState.fCoverageStages[i], hasLocalCoords)); | 138 (drawState.fCoverageStages[i], hasLocalCoords)); |
| 144 } | 139 } |
| 145 | 140 |
| 146 // let the GP init the batch tracker | 141 // let the GP init the batch tracker |
| 147 if (gp) { | 142 if (drawState.hasGeometryProcessor()) { |
| 148 GrGeometryProcessor::InitBT init; | 143 GrGeometryProcessor::InitBT init; |
| 149 init.fOutputColor = fDescInfo.fInputColorIsUsed; | 144 init.fOutputColor = fDescInfo.fInputColorIsUsed; |
| 150 init.fOutputCoverage = fDescInfo.fInputCoverageIsUsed; | 145 init.fOutputCoverage = fDescInfo.fInputCoverageIsUsed; |
| 151 init.fColor = this->getColor(); | 146 init.fColor = this->getColor(); |
| 152 init.fCoverage = this->getCoverage(); | 147 init.fCoverage = this->getCoverage(); |
| 153 fGeometryProcessor->initBatchTracker(&fBatchTracker, init); | 148 fGeometryProcessor->initBatchTracker(&fBatchTracker, init); |
| 154 } | 149 } |
| 155 } | 150 } |
| 156 | 151 |
| 157 void GrOptDrawState::adjustProgramFromOptimizations(const GrDrawState& ds, | 152 void GrOptDrawState::adjustProgramFromOptimizations(const GrDrawState& ds, |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 SkASSERT(this->numFragmentStages() == that.numFragmentStages()); | 235 SkASSERT(this->numFragmentStages() == that.numFragmentStages()); |
| 241 for (int i = 0; i < this->numFragmentStages(); i++) { | 236 for (int i = 0; i < this->numFragmentStages(); i++) { |
| 242 | 237 |
| 243 if (this->getFragmentStage(i) != that.getFragmentStage(i)) { | 238 if (this->getFragmentStage(i) != that.getFragmentStage(i)) { |
| 244 return false; | 239 return false; |
| 245 } | 240 } |
| 246 } | 241 } |
| 247 return true; | 242 return true; |
| 248 } | 243 } |
| 249 | 244 |
| OLD | NEW |