Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(584)

Side by Side Diff: src/gpu/GrOptDrawState.cpp

Issue 674543004: OptState owns program descriptor (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "gl/GrGpuGL.h"
12 13
13 GrOptDrawState::GrOptDrawState(const GrDrawState& drawState, 14 GrOptDrawState::GrOptDrawState(const GrDrawState& drawState,
14 BlendOptFlags blendOptFlags, 15 BlendOptFlags blendOptFlags,
15 GrBlendCoeff optSrcCoeff, 16 GrBlendCoeff optSrcCoeff,
16 GrBlendCoeff optDstCoeff, 17 GrBlendCoeff optDstCoeff,
17 const GrDrawTargetCaps& caps) { 18 GrGpu* gpu,
19 const GrDeviceCoordTexture* dstCopy,
20 GrGpu::DrawType drawType) {
18 fRenderTarget.set(SkSafeRef(drawState.getRenderTarget()), kWrite_GrIOType); 21 fRenderTarget.set(SkSafeRef(drawState.getRenderTarget()), kWrite_GrIOType);
19 fColor = drawState.getColor(); 22 fColor = drawState.getColor();
20 fCoverage = drawState.getCoverage(); 23 fCoverage = drawState.getCoverage();
21 fViewMatrix = drawState.getViewMatrix(); 24 fViewMatrix = drawState.getViewMatrix();
22 fBlendConstant = drawState.getBlendConstant(); 25 fBlendConstant = drawState.getBlendConstant();
23 fFlagBits = drawState.getFlagBits(); 26 fFlagBits = drawState.getFlagBits();
24 fVAPtr = drawState.getVertexAttribs(); 27 fVAPtr = drawState.getVertexAttribs();
25 fVACount = drawState.getVertexAttribCount(); 28 fVACount = drawState.getVertexAttribCount();
26 fVAStride = drawState.getVertexStride(); 29 fVAStride = drawState.getVertexStride();
27 fStencilSettings = drawState.getStencil(); 30 fStencilSettings = drawState.getStencil();
(...skipping 17 matching lines...) Expand all
45 48
46 this->computeEffectiveColorStages(drawState, &firstColorStageIdx, &fixedFunc tionVAToRemove); 49 this->computeEffectiveColorStages(drawState, &firstColorStageIdx, &fixedFunc tionVAToRemove);
47 this->computeEffectiveCoverageStages(drawState, &firstCoverageStageIdx); 50 this->computeEffectiveCoverageStages(drawState, &firstCoverageStageIdx);
48 this->adjustFromBlendOpts(drawState, &firstColorStageIdx, &firstCoverageStag eIdx, 51 this->adjustFromBlendOpts(drawState, &firstColorStageIdx, &firstCoverageStag eIdx,
49 &fixedFunctionVAToRemove); 52 &fixedFunctionVAToRemove);
50 // Should not be setting any more FFVA to be removed at this point 53 // Should not be setting any more FFVA to be removed at this point
51 if (0 != fixedFunctionVAToRemove) { 54 if (0 != fixedFunctionVAToRemove) {
52 this->removeFixedFunctionVertexAttribs(fixedFunctionVAToRemove); 55 this->removeFixedFunctionVertexAttribs(fixedFunctionVAToRemove);
53 } 56 }
54 this->getStageStats(drawState, firstColorStageIdx, firstCoverageStageIdx); 57 this->getStageStats(drawState, firstColorStageIdx, firstCoverageStageIdx);
55 this->setOutputStateInfo(drawState, caps, firstCoverageStageIdx, &separateCo verageFromColor); 58 this->setOutputStateInfo(drawState, *gpu->caps(), firstCoverageStageIdx,
59 &separateCoverageFromColor);
56 60
57 // Copy GeometryProcesssor from DS or ODS 61 // Copy GeometryProcesssor from DS or ODS
58 if (drawState.hasGeometryProcessor()) { 62 if (drawState.hasGeometryProcessor()) {
59 fGeometryProcessor.initAndRef(drawState.fGeometryProcessor); 63 fGeometryProcessor.initAndRef(drawState.fGeometryProcessor);
60 } else { 64 } else {
61 fGeometryProcessor.reset(NULL); 65 fGeometryProcessor.reset(NULL);
62 } 66 }
63 67
64 // Copy Color Stages from DS to ODS 68 // Copy Color Stages from DS to ODS
65 if (firstColorStageIdx < drawState.numColorStages()) { 69 if (firstColorStageIdx < drawState.numColorStages()) {
66 fFragmentStages.reset(&drawState.getColorStage(firstColorStageIdx), 70 fFragmentStages.reset(&drawState.getColorStage(firstColorStageIdx),
67 drawState.numColorStages() - firstColorStageIdx); 71 drawState.numColorStages() - firstColorStageIdx);
68 } else { 72 } else {
69 fFragmentStages.reset(); 73 fFragmentStages.reset();
70 } 74 }
71 75
72 fNumColorStages = fFragmentStages.count(); 76 fNumColorStages = fFragmentStages.count();
73 77
74 // Copy Coverage Stages from DS to ODS 78 // Copy Coverage Stages from DS to ODS
75 if (firstCoverageStageIdx < drawState.numCoverageStages()) { 79 if (firstCoverageStageIdx < drawState.numCoverageStages()) {
76 fFragmentStages.push_back_n(drawState.numCoverageStages() - firstCoverag eStageIdx, 80 fFragmentStages.push_back_n(drawState.numCoverageStages() - firstCoverag eStageIdx,
77 &drawState.getCoverageStage(firstCoverageSta geIdx)); 81 &drawState.getCoverageStage(firstCoverageSta geIdx));
78 if (!separateCoverageFromColor) { 82 if (!separateCoverageFromColor) {
79 fNumColorStages = fFragmentStages.count(); 83 fNumColorStages = fFragmentStages.count();
80 } 84 }
81 } 85 }
86
87 // now create a key
88 gpu->buildKey(this, drawType, dstCopy, &fDesc);
82 }; 89 };
83 90
84 GrOptDrawState* GrOptDrawState::Create(const GrDrawState& drawState, const GrDra wTargetCaps& caps, 91 GrOptDrawState* GrOptDrawState::Create(const GrDrawState& drawState,
92 GrGpu* gpu,
93 const GrDeviceCoordTexture* dstCopy,
85 GrGpu::DrawType drawType) { 94 GrGpu::DrawType drawType) {
95 const GrDrawTargetCaps& caps = *gpu->caps();
86 if (NULL == drawState.fCachedOptState || caps.getUniqueID() != drawState.fCa chedCapsID) { 96 if (NULL == drawState.fCachedOptState || caps.getUniqueID() != drawState.fCa chedCapsID) {
87 GrBlendCoeff srcCoeff; 97 GrBlendCoeff srcCoeff;
88 GrBlendCoeff dstCoeff; 98 GrBlendCoeff dstCoeff;
89 BlendOptFlags blendFlags = (BlendOptFlags) drawState.getBlendOpts(false, 99 BlendOptFlags blendFlags = (BlendOptFlags) drawState.getBlendOpts(false,
90 &srcCo eff, 100 &srcCo eff,
91 &dstCo eff); 101 &dstCo eff);
92 102
93 // If our blend coeffs are set to 0,1 we know we will not end up drawing unless we are 103 // If our blend coeffs are set to 0,1 we know we will not end up drawing unless we are
94 // stenciling. When path rendering the stencil settings are not always s et on the draw state 104 // stenciling. When path rendering the stencil settings are not always s et on the draw state
95 // so we must check the draw type. In cases where we will skip drawing w e simply return a 105 // so we must check the draw type. In cases where we will skip drawing w e simply return a
96 // null GrOptDrawState. 106 // null GrOptDrawState.
97 if (kZero_GrBlendCoeff == srcCoeff && kOne_GrBlendCoeff == dstCoeff && 107 if (kZero_GrBlendCoeff == srcCoeff && kOne_GrBlendCoeff == dstCoeff &&
98 !drawState.getStencil().doesWrite() && GrGpu::kStencilPath_DrawType != drawType) { 108 !drawState.getStencil().doesWrite() && GrGpu::kStencilPath_DrawType != drawType) {
99 return NULL; 109 return NULL;
100 } 110 }
101 111
102 drawState.fCachedOptState = SkNEW_ARGS(GrOptDrawState, (drawState, blend Flags, srcCoeff, 112 drawState.fCachedOptState = SkNEW_ARGS(GrOptDrawState, (drawState, blend Flags, srcCoeff,
103 dstCoeff, caps)) ; 113 dstCoeff, gpu, d stCopy, drawType));
104 drawState.fCachedCapsID = caps.getUniqueID(); 114 drawState.fCachedCapsID = caps.getUniqueID();
105 } else { 115 } else {
106 #ifdef SK_DEBUG 116 #ifdef SK_DEBUG
107 GrBlendCoeff srcCoeff; 117 GrBlendCoeff srcCoeff;
108 GrBlendCoeff dstCoeff; 118 GrBlendCoeff dstCoeff;
109 BlendOptFlags blendFlags = (BlendOptFlags) drawState.getBlendOpts(false, 119 BlendOptFlags blendFlags = (BlendOptFlags) drawState.getBlendOpts(false,
110 &srcCo eff, 120 &srcCo eff,
111 &dstCo eff); 121 &dstCo eff);
112 SkASSERT(GrOptDrawState(drawState, blendFlags, srcCoeff, dstCoeff, caps) == 122 SkASSERT(GrOptDrawState(drawState, blendFlags, srcCoeff, dstCoeff, gpu, dstCopy,
113 *drawState.fCachedOptState); 123 drawType) == *drawState.fCachedOptState);
114 #endif 124 #endif
115 } 125 }
116 drawState.fCachedOptState->ref(); 126 drawState.fCachedOptState->ref();
117 return drawState.fCachedOptState; 127 return drawState.fCachedOptState;
118 } 128 }
119 129
120 void GrOptDrawState::setOutputStateInfo(const GrDrawState& ds, 130 void GrOptDrawState::setOutputStateInfo(const GrDrawState& ds,
121 const GrDrawTargetCaps& caps, 131 const GrDrawTargetCaps& caps,
122 int firstCoverageStageIdx, 132 int firstCoverageStageIdx,
123 bool* separateCoverageFromColor) { 133 bool* separateCoverageFromColor) {
124 // Set this default and then possibly change our mind if there is coverage. 134 // Set this default and then possibly change our mind if there is coverage.
125 fPrimaryOutputType = kModulate_PrimaryOutputType; 135 fPrimaryOutputType = GrProgramDesc::kModulate_PrimaryOutputType;
126 fSecondaryOutputType = kNone_SecondaryOutputType; 136 fSecondaryOutputType = GrProgramDesc::kNone_SecondaryOutputType;
127 137
128 // If we do have coverage determine whether it matters. 138 // If we do have coverage determine whether it matters.
129 *separateCoverageFromColor = this->hasGeometryProcessor(); 139 *separateCoverageFromColor = this->hasGeometryProcessor();
130 if (!this->isCoverageDrawing() && 140 if (!this->isCoverageDrawing() &&
131 (ds.numCoverageStages() - firstCoverageStageIdx > 0 || 141 (ds.numCoverageStages() - firstCoverageStageIdx > 0 ||
132 ds.hasGeometryProcessor() || 142 ds.hasGeometryProcessor() ||
133 this->hasCoverageVertexAttribute())) { 143 this->hasCoverageVertexAttribute())) {
134 144
135 if (caps.dualSourceBlendingSupport()) { 145 if (caps.dualSourceBlendingSupport()) {
136 if (kZero_GrBlendCoeff == fDstBlend) { 146 if (kZero_GrBlendCoeff == fDstBlend) {
137 // write the coverage value to second color 147 // write the coverage value to second color
138 fSecondaryOutputType = kCoverage_SecondaryOutputType; 148 fSecondaryOutputType = GrProgramDesc:: kCoverage_SecondaryOutput Type;
139 *separateCoverageFromColor = true; 149 *separateCoverageFromColor = true;
140 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; 150 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff;
141 } else if (kSA_GrBlendCoeff == fDstBlend) { 151 } else if (kSA_GrBlendCoeff == fDstBlend) {
142 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered. 152 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered.
143 fSecondaryOutputType = kCoverageISA_SecondaryOutputType; 153 fSecondaryOutputType = GrProgramDesc::kCoverageISA_SecondaryOutp utType;
144 *separateCoverageFromColor = true; 154 *separateCoverageFromColor = true;
145 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; 155 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff;
146 } else if (kSC_GrBlendCoeff == fDstBlend) { 156 } else if (kSC_GrBlendCoeff == fDstBlend) {
147 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered. 157 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered.
148 fSecondaryOutputType = kCoverageISC_SecondaryOutputType; 158 fSecondaryOutputType = GrProgramDesc::kCoverageISC_SecondaryOutp utType;
149 *separateCoverageFromColor = true; 159 *separateCoverageFromColor = true;
150 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; 160 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff;
151 } 161 }
152 } else if (fReadsDst && 162 } else if (fReadsDst &&
153 kOne_GrBlendCoeff == fSrcBlend && 163 kOne_GrBlendCoeff == fSrcBlend &&
154 kZero_GrBlendCoeff == fDstBlend) { 164 kZero_GrBlendCoeff == fDstBlend) {
155 fPrimaryOutputType = kCombineWithDst_PrimaryOutputType; 165 fPrimaryOutputType = GrProgramDesc::kCombineWithDst_PrimaryOutputTyp e;
156 *separateCoverageFromColor = true; 166 *separateCoverageFromColor = true;
157 } 167 }
158 } 168 }
159 } 169 }
160 170
161 void GrOptDrawState::adjustFromBlendOpts(const GrDrawState& ds, 171 void GrOptDrawState::adjustFromBlendOpts(const GrDrawState& ds,
162 int* firstColorStageIdx, 172 int* firstColorStageIdx,
163 int* firstCoverageStageIdx, 173 int* firstCoverageStageIdx,
164 uint8_t* fixedFunctionVAToRemove) { 174 uint8_t* fixedFunctionVAToRemove) {
165 switch (fBlendOptFlags) { 175 switch (fBlendOptFlags) {
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 } 385 }
376 } 386 }
377 387
378 SkASSERT(0 == memcmp(this->fFixedFunctionVertexAttribIndices, 388 SkASSERT(0 == memcmp(this->fFixedFunctionVertexAttribIndices,
379 that.fFixedFunctionVertexAttribIndices, 389 that.fFixedFunctionVertexAttribIndices,
380 sizeof(this->fFixedFunctionVertexAttribIndices))); 390 sizeof(this->fFixedFunctionVertexAttribIndices)));
381 391
382 return true; 392 return true;
383 } 393 }
384 394
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698