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

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

Issue 660573002: Split GrFragmentProcessor into its own header (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add file to git 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 | « include/gpu/GrGeometryProcessor.h ('k') | 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
11 #include "GrBackendProcessorFactory.h" 11 #include "GrBackendProcessorFactory.h"
12 #include "GrColor.h" 12 #include "GrColor.h"
13 #include "GrProcessorUnitTest.h" 13 #include "GrProcessorUnitTest.h"
14 #include "GrProgramElement.h" 14 #include "GrProgramElement.h"
15 #include "GrShaderVar.h"
16 #include "GrTextureAccess.h" 15 #include "GrTextureAccess.h"
17 #include "GrTypesPriv.h"
18 #include "SkString.h"
19 16
20 class GrBackendProcessorFactory;
21 class GrContext; 17 class GrContext;
22 class GrCoordTransform; 18 class GrCoordTransform;
23 19
24 /** Provides custom vertex shader, fragment shader, uniform data for a particula r stage of the 20 /** Provides custom vertex shader, fragment shader, uniform data for a particula r stage of the
25 Ganesh shading pipeline. 21 Ganesh shading pipeline.
26 Subclasses must have a function that produces a human-readable name: 22 Subclasses must have a function that produces a human-readable name:
27 static const char* Name(); 23 static const char* Name();
28 GrProcessor objects *must* be immutable: after being constructed, their fiel ds may not change. 24 GrProcessor objects *must* be immutable: after being constructed, their fiel ds may not change.
29 25
30 Dynamically allocated GrProcessors are managed by a per-thread memory pool. The ref count of an 26 Dynamically allocated GrProcessors are managed by a per-thread memory pool. The ref count of an
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 * Subclass implements this to support getConstantColorComponents(...). 229 * Subclass implements this to support getConstantColorComponents(...).
234 */ 230 */
235 virtual void onComputeInvariantOutput(InvariantOutput* inout) const = 0; 231 virtual void onComputeInvariantOutput(InvariantOutput* inout) const = 0;
236 232
237 SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses; 233 SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses;
238 bool fWillReadFragmentPosition; 234 bool fWillReadFragmentPosition;
239 235
240 typedef GrProgramElement INHERITED; 236 typedef GrProgramElement INHERITED;
241 }; 237 };
242 238
243 class GrFragmentProcessor : public GrProcessor {
244 public:
245 GrFragmentProcessor()
246 : INHERITED()
247 , fWillReadDstColor(false)
248 , fWillUseInputColor(true) {}
249
250 virtual const GrBackendFragmentProcessorFactory& getFactory() const = 0;
251
252 int numTransforms() const { return fCoordTransforms.count(); }
253
254 /** Returns the coordinate transformation at index. index must be valid acco rding to
255 numTransforms(). */
256 const GrCoordTransform& coordTransform(int index) const { return *fCoordTran sforms[index]; }
257
258 /** Will this effect read the destination pixel value? */
259 bool willReadDstColor() const { return fWillReadDstColor; }
260
261 /** Will this effect read the source color value? */
262 bool willUseInputColor() const { return fWillUseInputColor; }
263
264 /** Returns true if this and other effect conservatively draw identically. I t can only return
265 true when the two effects are of the same subclass (i.e. they return the same object from
266 from getFactory()).
267
268 A return value of true from isEqual() should not be used to test whether the effects would
269 generate the same shader code. To test for identical code generation use the effects' keys
270 computed by the GrBackendEffectFactory. */
271 bool isEqual(const GrFragmentProcessor& other) const {
272 if (&this->getFactory() != &other.getFactory()) {
273 return false;
274 }
275 bool result = this->onIsEqual(other);
276 #ifdef SK_DEBUG
277 if (result) {
278 this->assertTexturesEqual(other);
279 }
280 #endif 239 #endif
281 return result;
282 }
283
284 protected:
285 /**
286 * Fragment Processor subclasses call this from their constructor to registe r coordinate
287 * transformations. The processor subclass manages the lifetime of the trans formations (this
288 * function only stores a pointer). The GrCoordTransform is typically a memb er field of the
289 * GrProcessor subclass. When the matrix has perspective, the transformed co ordinates will have
290 * 3 components. Otherwise they'll have 2. This must only be called from the constructor because
291 * GrProcessors are immutable.
292 */
293 void addCoordTransform(const GrCoordTransform*);
294
295 /**
296 * If the effect subclass will read the destination pixel value then it must call this function
297 * from its constructor. Otherwise, when its generated backend-specific effe ct class attempts
298 * to generate code that reads the destination pixel it will fail.
299 */
300 void setWillReadDstColor() { fWillReadDstColor = true; }
301
302 /**
303 * If the effect will generate a result that does not depend on the input co lor value then it
304 * must call this function from its constructor. Otherwise, when its generat ed backend-specific
305 * code might fail during variable binding due to unused variables.
306 */
307 void setWillNotUseInputColor() { fWillUseInputColor = false; }
308
309 private:
310 /** Subclass implements this to support isEqual(). It will only be called if it is known that
311 the two effects are of the same subclass (i.e. they return the same obje ct from
312 getFactory()).*/
313 virtual bool onIsEqual(const GrFragmentProcessor& other) const = 0;
314
315 SkSTArray<4, const GrCoordTransform*, true> fCoordTransforms;
316 bool fWillReadDstColor;
317 bool fWillUseInputColor;
318
319 typedef GrProcessor INHERITED;
320 };
321
322 /**
323 * This creates an effect outside of the effect memory pool. The effect's destru ctor will be called
324 * at global destruction time. NAME will be the name of the created GrProcessor.
325 */
326 #define GR_CREATE_STATIC_FRAGMENT_PROCESSOR(NAME, EFFECT_CLASS, ARGS) \
327 static SkAlignedSStorage<sizeof(EFFECT_CLASS)> g_##NAME##_Storage; \
328 static GrFragmentProcessor* \
329 NAME SkNEW_PLACEMENT_ARGS(g_##NAME##_Storage.get(), EFFECT_CLASS, ARGS); \
330 static SkAutoTDestroy<GrFragmentProcessor> NAME##_ad(NAME);
331
332 #endif
OLDNEW
« no previous file with comments | « include/gpu/GrGeometryProcessor.h ('k') | include/gpu/GrProcessorStage.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698