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

Side by Side Diff: include/gpu/GrProcessor.h

Issue 637003003: Opt state takes a GP instead of a GeometryStage (Closed) Base URL: https://skia.googlesource.com/skia.git@builder_cleanup
Patch Set: memory leaks fixed 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
« no previous file with comments | « no previous file | include/gpu/GrProcessorStage.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 2012 Google Inc. 2 * Copyright 2012 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 GrProcessor_DEFINED 8 #ifndef GrProcessor_DEFINED
9 #define GrProcessor_DEFINED 9 #define GrProcessor_DEFINED
10 10
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 this->assertEquality(other); 117 this->assertEquality(other);
118 } 118 }
119 #endif 119 #endif
120 return result; 120 return result;
121 } 121 }
122 122
123 /** Human-meaningful string to identify this effect; may be embedded 123 /** Human-meaningful string to identify this effect; may be embedded
124 in generated shader code. */ 124 in generated shader code. */
125 const char* name() const; 125 const char* name() const;
126 126
127 int numTransforms() const { return fCoordTransforms.count(); }
128
129 /** Returns the coordinate transformation at index. index must be valid acco rding to
130 numTransforms(). */
131 const GrCoordTransform& coordTransform(int index) const { return *fCoordTran sforms[index]; }
132
133 int numTextures() const { return fTextureAccesses.count(); } 127 int numTextures() const { return fTextureAccesses.count(); }
134 128
135 /** Returns the access pattern for the texture at index. index must be valid according to 129 /** Returns the access pattern for the texture at index. index must be valid according to
136 numTextures(). */ 130 numTextures(). */
137 const GrTextureAccess& textureAccess(int index) const { return *fTextureAcce sses[index]; } 131 const GrTextureAccess& textureAccess(int index) const { return *fTextureAcce sses[index]; }
138 132
139 /** Shortcut for textureAccess(index).texture(); */ 133 /** Shortcut for textureAccess(index).texture(); */
140 GrTexture* texture(int index) const { return this->textureAccess(index).getT exture(); } 134 GrTexture* texture(int index) const { return this->textureAccess(index).getT exture(); }
141 135
142 /** Will this effect read the fragment position? */ 136 /** Will this effect read the fragment position? */
143 bool willReadFragmentPosition() const { return fWillReadFragmentPosition; } 137 bool willReadFragmentPosition() const { return fWillReadFragmentPosition; }
144 138
145 void* operator new(size_t size); 139 void* operator new(size_t size);
146 void operator delete(void* target); 140 void operator delete(void* target);
147 141
148 void* operator new(size_t size, void* placement) { 142 void* operator new(size_t size, void* placement) {
149 return ::operator new(size, placement); 143 return ::operator new(size, placement);
150 } 144 }
151 void operator delete(void* target, void* placement) { 145 void operator delete(void* target, void* placement) {
152 ::operator delete(target, placement); 146 ::operator delete(target, placement);
153 } 147 }
154 148
155 /** 149 /**
156 * Helper for down-casting to a GrProcessor subclass 150 * Helper for down-casting to a GrProcessor subclass
157 */ 151 */
158 template <typename T> const T& cast() const { return *static_cast<const T*>( this); } 152 template <typename T> const T& cast() const { return *static_cast<const T*>( this); }
159 153
160 protected: 154 protected:
161 /** 155 /**
162 * Subclasses call this from their constructor to register coordinate transf ormations. The
163 * effect subclass manages the lifetime of the transformations (this functio n only stores a
164 * pointer). The GrCoordTransform is typically a member field of the GrProce ssor subclass. When
165 * the matrix has perspective, the transformed coordinates will have 3 compo nents. Otherwise
166 * they'll have 2. This must only be called from the constructor because GrP rocessors are
167 * immutable.
168 */
169 void addCoordTransform(const GrCoordTransform* coordTransform);
170
171 /**
172 * Subclasses call this from their constructor to register GrTextureAccesses . The effect 156 * Subclasses call this from their constructor to register GrTextureAccesses . The effect
173 * subclass manages the lifetime of the accesses (this function only stores a pointer). The 157 * subclass manages the lifetime of the accesses (this function only stores a pointer). The
174 * GrTextureAccess is typically a member field of the GrProcessor subclass. This must only be 158 * GrTextureAccess is typically a member field of the GrProcessor subclass. This must only be
175 * called from the constructor because GrProcessors are immutable. 159 * called from the constructor because GrProcessors are immutable.
176 */ 160 */
177 void addTextureAccess(const GrTextureAccess* textureAccess); 161 void addTextureAccess(const GrTextureAccess* textureAccess);
178 162
179 GrProcessor() 163 GrProcessor()
180 : fWillReadFragmentPosition(false) {} 164 : fWillReadFragmentPosition(false) {}
181 165
182 /** 166 /**
183 * If the effect will generate a backend-specific effect that will read the fragment position 167 * If the effect will generate a backend-specific effect that will read the fragment position
184 * in the FS then it must call this method from its constructor. Otherwise, the request to 168 * in the FS then it must call this method from its constructor. Otherwise, the request to
185 * access the fragment position will be denied. 169 * access the fragment position will be denied.
186 */ 170 */
187 void setWillReadFragmentPosition() { fWillReadFragmentPosition = true; } 171 void setWillReadFragmentPosition() { fWillReadFragmentPosition = true; }
188 172
189 private: 173 private:
190 SkDEBUGCODE(void assertEquality(const GrProcessor& other) const;) 174 SkDEBUGCODE(void assertEquality(const GrProcessor& other) const;)
191 175
192 /** Subclass implements this to support isEqual(). It will only be called if it is known that 176 /** Subclass implements this to support isEqual(). It will only be called if it is known that
193 the two effects are of the same subclass (i.e. they return the same obje ct from 177 the two effects are of the same subclass (i.e. they return the same obje ct from
194 getFactory()).*/ 178 getFactory()).*/
195 virtual bool onIsEqual(const GrProcessor& other) const = 0; 179 virtual bool onIsEqual(const GrProcessor& other) const = 0;
196 180
197 /** 181 /**
198 * Subclass implements this to support getConstantColorComponents(...). 182 * Subclass implements this to support getConstantColorComponents(...).
199 */ 183 */
200 virtual void onComputeInvariantOutput(InvariantOutput* inout) const = 0; 184 virtual void onComputeInvariantOutput(InvariantOutput* inout) const = 0;
201 friend class GrGeometryProcessor; // to set fRequiresVertexShader and build fVertexAttribTypes.
202 185
203 SkSTArray<4, const GrCoordTransform*, true> fCoordTransforms;
204 SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses; 186 SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses;
205 bool fWillReadFragmentPosition; 187 bool fWillReadFragmentPosition;
206 188
207 typedef GrProgramElement INHERITED; 189 typedef GrProgramElement INHERITED;
208 }; 190 };
209 191
210 class GrFragmentProcessor : public GrProcessor { 192 class GrFragmentProcessor : public GrProcessor {
211 public: 193 public:
212 GrFragmentProcessor() 194 GrFragmentProcessor()
213 : INHERITED() 195 : INHERITED()
214 , fWillReadDstColor(false) 196 , fWillReadDstColor(false)
215 , fWillUseInputColor(true) {} 197 , fWillUseInputColor(true) {}
216 198
217 virtual const GrBackendFragmentProcessorFactory& getFactory() const = 0; 199 virtual const GrBackendFragmentProcessorFactory& getFactory() const = 0;
218 200
201 int numTransforms() const { return fCoordTransforms.count(); }
202
203 /** Returns the coordinate transformation at index. index must be valid acco rding to
204 numTransforms(). */
205 const GrCoordTransform& coordTransform(int index) const { return *fCoordTran sforms[index]; }
206
219 /** Will this effect read the destination pixel value? */ 207 /** Will this effect read the destination pixel value? */
220 bool willReadDstColor() const { return fWillReadDstColor; } 208 bool willReadDstColor() const { return fWillReadDstColor; }
221 209
222 /** Will this effect read the source color value? */ 210 /** Will this effect read the source color value? */
223 bool willUseInputColor() const { return fWillUseInputColor; } 211 bool willUseInputColor() const { return fWillUseInputColor; }
224 212
225 protected: 213 protected:
226 /** 214 /**
215 * Fragment Processor subclasses call this from their constructor to registe r coordinate
216 * transformations. The processor subclass manages the lifetime of the trans formations (this
217 * function only stores a pointer). The GrCoordTransform is typically a memb er field of the
218 * GrProcessor subclass. When the matrix has perspective, the transformed co ordinates will have
219 * 3 components. Otherwise they'll have 2. This must only be called from the constructor because
220 * GrProcessors are immutable.
221 */
222 void addCoordTransform(const GrCoordTransform*);
223
224 /**
227 * If the effect subclass will read the destination pixel value then it must call this function 225 * If the effect subclass will read the destination pixel value then it must call this function
228 * from its constructor. Otherwise, when its generated backend-specific effe ct class attempts 226 * from its constructor. Otherwise, when its generated backend-specific effe ct class attempts
229 * to generate code that reads the destination pixel it will fail. 227 * to generate code that reads the destination pixel it will fail.
230 */ 228 */
231 void setWillReadDstColor() { fWillReadDstColor = true; } 229 void setWillReadDstColor() { fWillReadDstColor = true; }
232 230
233 /** 231 /**
234 * If the effect will generate a result that does not depend on the input co lor value then it 232 * If the effect will generate a result that does not depend on the input co lor value then it
235 * must call this function from its constructor. Otherwise, when its generat ed backend-specific 233 * must call this function from its constructor. Otherwise, when its generat ed backend-specific
236 * code might fail during variable binding due to unused variables. 234 * code might fail during variable binding due to unused variables.
237 */ 235 */
238 void setWillNotUseInputColor() { fWillUseInputColor = false; } 236 void setWillNotUseInputColor() { fWillUseInputColor = false; }
239 237
240 private: 238 private:
239 SkSTArray<4, const GrCoordTransform*, true> fCoordTransforms;
241 bool fWillReadDstColor; 240 bool fWillReadDstColor;
242 bool fWillUseInputColor; 241 bool fWillUseInputColor;
243 242
244 typedef GrProcessor INHERITED; 243 typedef GrProcessor INHERITED;
245 }; 244 };
246 245
247 /** 246 /**
248 * This creates an effect outside of the effect memory pool. The effect's destru ctor will be called 247 * This creates an effect outside of the effect memory pool. The effect's destru ctor will be called
249 * at global destruction time. NAME will be the name of the created GrProcessor. 248 * at global destruction time. NAME will be the name of the created GrProcessor.
250 */ 249 */
251 #define GR_CREATE_STATIC_FRAGMENT_PROCESSOR(NAME, EFFECT_CLASS, ARGS) \ 250 #define GR_CREATE_STATIC_FRAGMENT_PROCESSOR(NAME, EFFECT_CLASS, ARGS) \
252 static SkAlignedSStorage<sizeof(EFFECT_CLASS)> g_##NAME##_Storage; \ 251 static SkAlignedSStorage<sizeof(EFFECT_CLASS)> g_##NAME##_Storage; \
253 static GrFragmentProcessor* \ 252 static GrFragmentProcessor* \
254 NAME SkNEW_PLACEMENT_ARGS(g_##NAME##_Storage.get(), EFFECT_CLASS, ARGS); \ 253 NAME SkNEW_PLACEMENT_ARGS(g_##NAME##_Storage.get(), EFFECT_CLASS, ARGS); \
255 static SkAutoTDestroy<GrFragmentProcessor> NAME##_ad(NAME); 254 static SkAutoTDestroy<GrFragmentProcessor> NAME##_ad(NAME);
256 255
257 #endif 256 #endif
OLDNEW
« no previous file with comments | « no previous file | include/gpu/GrProcessorStage.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698