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

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

Issue 508663002: Create an optimized draw state but not hooked in yet to gpu pipeline (Closed) Base URL: https://skia.googlesource.com/skia.git@drawBase
Patch Set: Review changes 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
(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
12 GrOptDrawState::GrOptDrawState(const GrDrawState& drawState) : INHERITED(drawSta te) {
13 fColor = drawState.getColor();
14 fCoverage = drawState.getCoverage();
15 fViewMatrix = drawState.getViewMatrix();
16 fBlendConstant = drawState.getBlendConstant();
17 fFlagBits = drawState.getFlagBits();
18 fVAPtr = drawState.getVertexAttribs();
19 fVACount = drawState.getVertexAttribCount();
20 fStencilSettings = drawState.getStencil();
21 fDrawFace = drawState.getDrawFace();
22
23 fBlendOptFlags = drawState.getBlendOpts(false, &fSrcBlend, &fDstBlend);
24
25 memcpy(fFixedFunctionVertexAttribIndices,
26 drawState.getFixedFunctionVertexAttribIndices(),
27 sizeof(fFixedFunctionVertexAttribIndices));
28
29 fInputColorIsUsed = true;
30 fInputCoverageIsUsed = true;
31
32 this->copyEffectiveColorStages(drawState);
33 this->copyEffectiveCoverageStages(drawState);
34 };
35
36 void GrOptDrawState::removeFixedFunctionVertexAttribs(uint8_t removeVAFlag) {
37 int numToRemove = 0;
38 uint8_t maskCheck = 0x1;
39 // Count the number of vertex attributes that we will actually remove
40 for (int i = 0; i < kGrFixedFunctionVertexAttribBindingCnt; ++i) {
41 if ((maskCheck & removeVAFlag) && -1 != fFixedFunctionVertexAttribIndice s[i]) {
42 ++numToRemove;
43 }
44 maskCheck <<= 1;
45 }
46 fOptVA.reset(fVACount - numToRemove);
47
48 GrVertexAttrib* dst = fOptVA.get();
49 const GrVertexAttrib* src = fVAPtr;
50
51 for (int i = 0, newIdx = 0; i < fVACount; ++i, ++src) {
52 const GrVertexAttrib& currAttrib = *src;
53 if (currAttrib.fBinding < kGrFixedFunctionVertexAttribBindingCnt) {
54 uint8_t maskCheck = 0x1 << currAttrib.fBinding;
55 if (maskCheck & removeVAFlag) {
56 SkASSERT(-1 != fFixedFunctionVertexAttribIndices[currAttrib.fBin ding]);
57 fFixedFunctionVertexAttribIndices[currAttrib.fBinding] = -1;
58 continue;
59 }
60 }
61 memcpy(dst, src, sizeof(GrVertexAttrib));
62 fFixedFunctionVertexAttribIndices[currAttrib.fBinding] = newIdx;
63 ++newIdx;
64 ++dst;
65 }
66 fVACount -= numToRemove;
67 fVAPtr = fOptVA.get();
68 }
69
70 void GrOptDrawState::copyEffectiveColorStages(const GrDrawState& ds) {
71 int firstColorStage = 0;
72
73 // Set up color and flags for ConstantColorComponent checks
74 GrColor color;
75 uint32_t validComponentFlags;
76 if (!this->hasColorVertexAttribute()) {
77 color = ds.getColor();
78 validComponentFlags = kRGBA_GrColorComponentFlags;
79 } else {
80 if (ds.vertexColorsAreOpaque()) {
81 color = 0xFF << GrColor_SHIFT_A;
82 validComponentFlags = kA_GrColorComponentFlag;
83 } else {
84 validComponentFlags = 0;
85 color = 0; // not strictly necessary but we get false alarms from to ols about uninit.
86 }
87 }
88
89 for (int i = 0; i < ds.numColorStages(); ++i) {
90 const GrEffect* effect = ds.getColorStage(i).getEffect();
91 if (!effect->willUseInputColor()) {
92 firstColorStage = i;
93 fInputColorIsUsed = false;
94 }
95 effect->getConstantColorComponents(&color, &validComponentFlags);
96 if (kRGBA_GrColorComponentFlags == validComponentFlags) {
97 firstColorStage = i + 1;
98 fColor = color;
99 fInputColorIsUsed = true;
100 this->removeFixedFunctionVertexAttribs(0x1 << kColor_GrVertexAttribB inding);
101 }
102 }
103 if (firstColorStage < ds.numColorStages()) {
104 fColorStages.reset(&ds.getColorStage(firstColorStage),
105 ds.numColorStages() - firstColorStage);
106 } else {
107 fColorStages.reset();
108 }
109 }
110
111 void GrOptDrawState::copyEffectiveCoverageStages(const GrDrawState& ds) {
112 int firstCoverageStage = 0;
113 /**
bsalomon 2014/08/27 13:30:38 Will doxygen see this comment? Maybe just use // s
114 * We do not try to optimize out constantColor coverage effects here. It is extremely rare
115 * to have a coverage effect that returns a constant value for all four chan nels. Thus we
116 * save having to make extra virtual calls by not checking for it.
117 */
118 for (int i = 0; i < ds.numCoverageStages(); ++i) {
119 const GrEffect* effect = ds.getCoverageStage(i).getEffect();
120 if (!effect->willUseInputColor()) {
121 firstCoverageStage = i;
122 fInputCoverageIsUsed = false;
123 }
124 }
125 if (ds.numCoverageStages() > 0) {
126 fCoverageStages.reset(&ds.getCoverageStage(firstCoverageStage),
127 ds.numCoverageStages() - firstCoverageStage);
128 } else {
129 fCoverageStages.reset();
130 }
131 }
132
133 bool GrOptDrawState::operator== (const GrOptDrawState& that) const {
134 if(!this->isEqual(that)) {
135 return false;
136 }
137
138 // Need to check the original vertex size since we remove unused VA's which may icoorectly make
139 // two OptDrawStates incorrectly seem to be identical. In reality the origin al VA's may have
140 // been different and thus the vertex data being passed into the shaders is in different
141 // formats.
142 return fVertexSize == that.fVertexSize;
143 }
144
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