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

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

Issue 504203004: Attach GrOptDrawState into shader building pipeline (Closed) Base URL: https://skia.googlesource.com/skia.git@opt2
Patch Set: Rebase Created 6 years, 3 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
« no previous file with comments | « src/gpu/GrOptDrawState.h ('k') | src/gpu/GrRODrawState.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 11
12 GrOptDrawState::GrOptDrawState(const GrDrawState& drawState) : INHERITED(drawSta te) { 12 GrOptDrawState::GrOptDrawState(const GrDrawState& drawState,
13 BlendOptFlags blendOptFlags,
14 GrBlendCoeff optSrcCoeff,
15 GrBlendCoeff optDstCoeff) : INHERITED(drawState) {
13 fColor = drawState.getColor(); 16 fColor = drawState.getColor();
14 fCoverage = drawState.getCoverage(); 17 fCoverage = drawState.getCoverage();
15 fViewMatrix = drawState.getViewMatrix(); 18 fViewMatrix = drawState.getViewMatrix();
16 fBlendConstant = drawState.getBlendConstant(); 19 fBlendConstant = drawState.getBlendConstant();
17 fFlagBits = drawState.getFlagBits(); 20 fFlagBits = drawState.getFlagBits();
18 fVAPtr = drawState.getVertexAttribs(); 21 fVAPtr = drawState.getVertexAttribs();
19 fVACount = drawState.getVertexAttribCount(); 22 fVACount = drawState.getVertexAttribCount();
20 fVAStride = drawState.getVertexStride(); 23 fVAStride = drawState.getVertexStride();
21 fStencilSettings = drawState.getStencil(); 24 fStencilSettings = drawState.getStencil();
22 fDrawFace = drawState.getDrawFace(); 25 fDrawFace = drawState.getDrawFace();
23 26 fBlendOptFlags = blendOptFlags;
24 fBlendOptFlags = drawState.getBlendOpts(false, &fSrcBlend, &fDstBlend); 27 fSrcBlend = optSrcCoeff;
28 fDstBlend = optDstCoeff;
25 29
26 memcpy(fFixedFunctionVertexAttribIndices, 30 memcpy(fFixedFunctionVertexAttribIndices,
27 drawState.getFixedFunctionVertexAttribIndices(), 31 drawState.getFixedFunctionVertexAttribIndices(),
28 sizeof(fFixedFunctionVertexAttribIndices)); 32 sizeof(fFixedFunctionVertexAttribIndices));
29 33
34
30 fInputColorIsUsed = true; 35 fInputColorIsUsed = true;
31 fInputCoverageIsUsed = true; 36 fInputCoverageIsUsed = true;
32 37
33 if (drawState.hasGeometryProcessor()) { 38 if (drawState.hasGeometryProcessor()) {
34 fGeometryProcessor.reset(SkNEW_ARGS(GrEffectStage, (*drawState.getGeomet ryProcessor()))); 39 fGeometryProcessor.reset(SkNEW_ARGS(GrEffectStage, (*drawState.getGeomet ryProcessor())));
35 } else { 40 } else {
36 fGeometryProcessor.reset(NULL); 41 fGeometryProcessor.reset(NULL);
37 } 42 }
38 43
39 this->copyEffectiveColorStages(drawState); 44 this->copyEffectiveColorStages(drawState);
40 this->copyEffectiveCoverageStages(drawState); 45 this->copyEffectiveCoverageStages(drawState);
46 this->adjustFromBlendOpts();
41 }; 47 };
42 48
49 void GrOptDrawState::adjustFromBlendOpts() {
50
51 switch (fBlendOptFlags) {
52 case kNone_BlendOpt:
53 case kSkipDraw_BlendOptFlag:
54 break;
55 case kCoverageAsAlpha_BlendOptFlag:
56 fFlagBits |= kCoverageDrawing_StateBit;
57 break;
58 case kEmitCoverage_BlendOptFlag:
59 fColor = 0xffffffff;
60 fInputColorIsUsed = true;
61 fColorStages.reset();
62 this->removeFixedFunctionVertexAttribs(0x1 << kColor_GrVertexAttribB inding);
63 break;
64 case kEmitTransBlack_BlendOptFlag:
65 fColor = 0;
66 fCoverage = 0xff;
67 fInputColorIsUsed = true;
68 fInputCoverageIsUsed = true;
69 fColorStages.reset();
70 fCoverageStages.reset();
71 this->removeFixedFunctionVertexAttribs(0x1 << kColor_GrVertexAttribB inding |
72 0x1 << kCoverage_GrVertexAttr ibBinding);
73 break;
74 default:
75 SkFAIL("Unknown BlendOptFlag");
76
77 }
78 }
79
43 void GrOptDrawState::removeFixedFunctionVertexAttribs(uint8_t removeVAFlag) { 80 void GrOptDrawState::removeFixedFunctionVertexAttribs(uint8_t removeVAFlag) {
44 int numToRemove = 0; 81 int numToRemove = 0;
45 uint8_t maskCheck = 0x1; 82 uint8_t maskCheck = 0x1;
46 // Count the number of vertex attributes that we will actually remove 83 // Count the number of vertex attributes that we will actually remove
47 for (int i = 0; i < kGrFixedFunctionVertexAttribBindingCnt; ++i) { 84 for (int i = 0; i < kGrFixedFunctionVertexAttribBindingCnt; ++i) {
48 if ((maskCheck & removeVAFlag) && -1 != fFixedFunctionVertexAttribIndice s[i]) { 85 if ((maskCheck & removeVAFlag) && -1 != fFixedFunctionVertexAttribIndice s[i]) {
49 ++numToRemove; 86 ++numToRemove;
50 } 87 }
51 maskCheck <<= 1; 88 maskCheck <<= 1;
52 } 89 }
90
53 fOptVA.reset(fVACount - numToRemove); 91 fOptVA.reset(fVACount - numToRemove);
54 92
55 GrVertexAttrib* dst = fOptVA.get(); 93 GrVertexAttrib* dst = fOptVA.get();
56 const GrVertexAttrib* src = fVAPtr; 94 const GrVertexAttrib* src = fVAPtr;
57 95
58 for (int i = 0, newIdx = 0; i < fVACount; ++i, ++src) { 96 for (int i = 0, newIdx = 0; i < fVACount; ++i, ++src) {
59 const GrVertexAttrib& currAttrib = *src; 97 const GrVertexAttrib& currAttrib = *src;
60 if (currAttrib.fBinding < kGrFixedFunctionVertexAttribBindingCnt) { 98 if (currAttrib.fBinding < kGrFixedFunctionVertexAttribBindingCnt) {
61 uint8_t maskCheck = 0x1 << currAttrib.fBinding; 99 uint8_t maskCheck = 0x1 << currAttrib.fBinding;
62 if (maskCheck & removeVAFlag) { 100 if (maskCheck & removeVAFlag) {
63 SkASSERT(-1 != fFixedFunctionVertexAttribIndices[currAttrib.fBin ding]); 101 SkASSERT(-1 != fFixedFunctionVertexAttribIndices[currAttrib.fBin ding]);
64 fFixedFunctionVertexAttribIndices[currAttrib.fBinding] = -1; 102 fFixedFunctionVertexAttribIndices[currAttrib.fBinding] = -1;
65 continue; 103 continue;
66 } 104 }
105 fFixedFunctionVertexAttribIndices[currAttrib.fBinding] = newIdx;
67 } 106 }
68 memcpy(dst, src, sizeof(GrVertexAttrib)); 107 memcpy(dst, src, sizeof(GrVertexAttrib));
69 fFixedFunctionVertexAttribIndices[currAttrib.fBinding] = newIdx;
70 ++newIdx; 108 ++newIdx;
71 ++dst; 109 ++dst;
72 } 110 }
73 fVACount -= numToRemove; 111 fVACount -= numToRemove;
74 fVAPtr = fOptVA.get(); 112 fVAPtr = fOptVA.get();
75 } 113 }
76 114
77 void GrOptDrawState::copyEffectiveColorStages(const GrDrawState& ds) { 115 void GrOptDrawState::copyEffectiveColorStages(const GrDrawState& ds) {
78 int firstColorStage = 0; 116 int firstColorStage = 0;
79 117
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 ds.numCoverageStages() - firstCoverageStage); 176 ds.numCoverageStages() - firstCoverageStage);
139 } else { 177 } else {
140 fCoverageStages.reset(); 178 fCoverageStages.reset();
141 } 179 }
142 } 180 }
143 181
144 bool GrOptDrawState::operator== (const GrOptDrawState& that) const { 182 bool GrOptDrawState::operator== (const GrOptDrawState& that) const {
145 return this->isEqual(that); 183 return this->isEqual(that);
146 } 184 }
147 185
OLDNEW
« no previous file with comments | « src/gpu/GrOptDrawState.h ('k') | src/gpu/GrRODrawState.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698