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

Side by Side Diff: src/gpu/GrGeometryProcessor.h

Issue 794843002: Revert of Remove GP from drawstate, revision of invariant output for GP (Closed) Base URL: https://skia.googlesource.com/skia.git@color-to-gp
Patch Set: Created 6 years 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/GrDrawTarget.cpp ('k') | src/gpu/GrInOrderDrawBuffer.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 2013 Google Inc. 2 * Copyright 2013 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 #ifndef GrGeometryProcessor_DEFINED 8 #ifndef GrGeometryProcessor_DEFINED
9 #define GrGeometryProcessor_DEFINED 9 #define GrGeometryProcessor_DEFINED
10 10
(...skipping 21 matching lines...) Expand all
32 static const size_t kMaxSize = 32; 32 static const size_t kMaxSize = 32;
33 33
34 private: 34 private:
35 uint8_t fData[kMaxSize]; 35 uint8_t fData[kMaxSize];
36 }; 36 };
37 37
38 class GrGLCaps; 38 class GrGLCaps;
39 class GrGLGeometryProcessor; 39 class GrGLGeometryProcessor;
40 class GrOptDrawState; 40 class GrOptDrawState;
41 41
42 struct GrInitInvariantOutput;
43
44 /*
45 * GrGeometryProcessors and GrPathProcessors may effect invariantColor
46 */
47 class GrPrimitiveProcessor : public GrProcessor {
48 public:
49 // TODO GPs and PPs have to provide an initial coverage because the coverage invariant code is
50 // broken right now
51 virtual uint8_t coverage() const = 0;
52 virtual void getInvariantOutputColor(GrInitInvariantOutput* out) const = 0;
53 virtual void getInvariantOutputCoverage(GrInitInvariantOutput* out) const = 0;
54
55 private:
56 typedef GrProcessor INHERITED;
57 };
58
59 /** 42 /**
60 * A GrGeometryProcessor is used to perform computation in the vertex shader and 43 * A GrGeometryProcessor is used to perform computation in the vertex shader and
61 * add support for custom vertex attributes. A GrGemeotryProcessor is typically 44 * add support for custom vertex attributes. A GrGemeotryProcessor is typically
62 * tied to the code that does a specific type of high-level primitive rendering 45 * tied to the code that does a specific type of high-level primitive rendering
63 * (e.g. anti-aliased circle rendering). The GrGeometryProcessor used for a draw is 46 * (e.g. anti-aliased circle rendering). The GrGeometryProcessor used for a draw is
64 * specified using GrDrawState. There can only be one geometry processor active for 47 * specified using GrDrawState. There can only be one geometry processor active for
65 * a draw. The custom vertex attributes required by the geometry processor must be 48 * a draw. The custom vertex attributes required by the geometry processor must be
66 * added to the vertex attribute array specified on the GrDrawState. 49 * added to the vertex attribute array specified on the GrDrawState.
67 * GrGeometryProcessor subclasses should be immutable after construction. 50 * GrGeometryProcessor subclasses should be immutable after construction.
68 */ 51 */
69 class GrGeometryProcessor : public GrPrimitiveProcessor { 52 class GrGeometryProcessor : public GrProcessor {
70 public: 53 public:
71 GrGeometryProcessor(GrColor color, uint8_t coverage = 0xff) 54 GrGeometryProcessor(GrColor color, uint8_t coverage = 0xff)
72 : fVertexStride(0) 55 : fVertexStride(0)
73 , fColor(color) 56 , fColor(color)
74 , fCoverage(coverage) 57 , fCoverage(coverage)
75 , fWillUseGeoShader(false) 58 , fWillUseGeoShader(false)
76 , fHasVertexColor(false) 59 , fHasVertexColor(false)
77 , fHasVertexCoverage(false) 60 , fHasVertexCoverage(false)
78 , fHasLocalCoords(false) {} 61 , fHasLocalCoords(false) {}
79 62
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 true when the two prcoessors are of the same subclass (i.e. they return the same object from 107 true when the two prcoessors are of the same subclass (i.e. they return the same object from
125 from getFactory()). 108 from getFactory()).
126 A return value of true from isEqual() should not be used to test whether the processors 109 A return value of true from isEqual() should not be used to test whether the processors
127 would generate the same shader code. To test for identical code generati on use the 110 would generate the same shader code. To test for identical code generati on use the
128 processors' keys computed by the GrBackendEffectFactory. */ 111 processors' keys computed by the GrBackendEffectFactory. */
129 bool isEqual(const GrGeometryProcessor& that) const { 112 bool isEqual(const GrGeometryProcessor& that) const {
130 if (this->classID() != that.classID() || !this->hasSameTextureAccesses(t hat)) { 113 if (this->classID() != that.classID() || !this->hasSameTextureAccesses(t hat)) {
131 return false; 114 return false;
132 } 115 }
133 116
134 if (!fHasVertexColor && this->color() != that.color()) { 117 if (!fHasVertexColor && this->getColor() != that.getColor()) {
135 return false; 118 return false;
136 } 119 }
137 120
138 // TODO this is fragile, most gps set their coverage to 0xff so this is okay. In the long 121 if (!fHasVertexCoverage && this->getCoverage() != that.getCoverage()) {
139 // term this should move to subclasses which set explicit coverage
140 if (!fHasVertexCoverage && this->coverage() != that.coverage()) {
141 return false; 122 return false;
142 } 123 }
143 return this->onIsEqual(that); 124 return this->onIsEqual(that);
144 } 125 }
145 126
146 struct InitBT { 127 struct InitBT {
147 bool fOutputColor; 128 bool fOutputColor;
148 bool fOutputCoverage; 129 bool fOutputCoverage;
149 GrColor fColor; 130 GrColor fColor;
150 GrColor fCoverage; 131 GrColor fCoverage;
151 }; 132 };
152 133
153 virtual void initBatchTracker(GrBatchTracker*, const InitBT&) const {} 134 virtual void initBatchTracker(GrBatchTracker*, const InitBT&) const {}
154 135
155 GrColor color() const { return fColor; } 136 GrColor getColor() const { return fColor; }
156 uint8_t coverage() const { return fCoverage; } 137 uint8_t getCoverage() const { return fCoverage; }
157 138
158 // TODO this is a total hack until the gp can own whether or not it uses uni form 139 // TODO this is a total hack until the gp can own whether or not it uses uni form
159 // color / coverage 140 // color / coverage
160 bool hasVertexColor() const { return fHasVertexColor; } 141 bool hasVertexColor() const { return fHasVertexColor; }
161 bool hasVertexCoverage() const { return fHasVertexCoverage; } 142 bool hasVertexCoverage() const { return fHasVertexCoverage; }
162 bool hasLocalCoords() const { return fHasLocalCoords; } 143 bool hasLocalCoords() const { return fHasLocalCoords; }
163 144
164 void getInvariantOutputColor(GrInitInvariantOutput* out) const SK_OVERRIDE; 145 void computeInvariantColor(GrInvariantOutput* inout) const;
165 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const SK_OVERRID E;
166 146
167 protected: 147 protected:
168 /** 148 /**
169 * Subclasses call this from their constructor to register vertex attributes . Attributes 149 * Subclasses call this from their constructor to register vertex attributes . Attributes
170 * will be padded to the nearest 4 bytes for performance reasons. 150 * will be padded to the nearest 4 bytes for performance reasons.
171 * TODO After deferred geometry, we should do all of this inline in Generate Geometry alongside 151 * TODO After deferred geometry, we should do all of this inline in Generate Geometry alongside
172 * the struct used to actually populate the attributes 152 * the struct used to actually populate the attributes
173 */ 153 */
174 const GrAttribute& addVertexAttrib(const GrAttribute& attribute) { 154 const GrAttribute& addVertexAttrib(const GrAttribute& attribute) {
175 fVertexStride += attribute.fOffset; 155 fVertexStride += attribute.fOffset;
176 return fAttribs.push_back(attribute); 156 return fAttribs.push_back(attribute);
177 } 157 }
178 158
179 void setWillUseGeoShader() { fWillUseGeoShader = true; } 159 void setWillUseGeoShader() { fWillUseGeoShader = true; }
180 160
181 // TODO hack see above 161 // TODO hack see above
182 void setHasVertexColor() { fHasVertexColor = true; } 162 void setHasVertexColor() { fHasVertexColor = true; }
183 void setHasVertexCoverage() { fHasVertexCoverage = true; } 163 void setHasVertexCoverage() { fHasVertexCoverage = true; }
184 void setHasLocalCoords() { fHasLocalCoords = true; } 164 void setHasLocalCoords() { fHasLocalCoords = true; }
185 165
186 virtual void onGetInvariantOutputColor(GrInitInvariantOutput*) const {}
187 virtual void onGetInvariantOutputCoverage(GrInitInvariantOutput*) const = 0;
188
189 private: 166 private:
190 virtual bool onIsEqual(const GrGeometryProcessor&) const = 0; 167 virtual bool onIsEqual(const GrGeometryProcessor&) const = 0;
191 168
192 SkSTArray<kMaxVertexAttribs, GrAttribute, true> fAttribs; 169 SkSTArray<kMaxVertexAttribs, GrAttribute, true> fAttribs;
193 size_t fVertexStride; 170 size_t fVertexStride;
194 GrColor fColor; 171 GrColor fColor;
195 uint8_t fCoverage; 172 uint8_t fCoverage;
196 bool fWillUseGeoShader; 173 bool fWillUseGeoShader;
197 bool fHasVertexColor; 174 bool fHasVertexColor;
198 bool fHasVertexCoverage; 175 bool fHasVertexCoverage;
199 bool fHasLocalCoords; 176 bool fHasLocalCoords;
200 177
201 typedef GrProcessor INHERITED; 178 typedef GrProcessor INHERITED;
202 }; 179 };
203
204 /*
205 * The path equivalent of the GP. For now this just manages color. In the long term we plan on
206 * extending this class to handle all nvpr uniform / varying / program work.
207 */
208 class GrPathProcessor : public GrPrimitiveProcessor {
209 public:
210 static GrPathProcessor* Create(GrColor color) {
211 return SkNEW_ARGS(GrPathProcessor, (color));
212 }
213
214 const char* name() const SK_OVERRIDE { return "PathProcessor"; }
215 uint8_t coverage() const SK_OVERRIDE { return 0xff; }
216 void getInvariantOutputColor(GrInitInvariantOutput* out) const SK_OVERRIDE;
217 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const SK_OVERRID E;
218
219 private:
220 GrPathProcessor(GrColor color) : fColor(color) {}
221 GrColor fColor;
222
223 typedef GrProcessor INHERITED;
224 };
225 #endif 180 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrDrawTarget.cpp ('k') | src/gpu/GrInOrderDrawBuffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698