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