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

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

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

Powered by Google App Engine
This is Rietveld 408576698