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

Side by Side Diff: include/gpu/GrFragmentProcessor.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 | « gyp/gpu.gypi ('k') | include/gpu/GrGeometryProcessor.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 #ifndef GrFragmentProcessor_DEFINED
9 #define GrFragmentProcessor_DEFINED
10
11 #include "GrProcessor.h"
12
13 class GrCoordTransform;
14
15 /** Provides custom fragment shader code. Fragment processors receive an input c olor (vec4f) and
16 produce an output color. They may reference textures and uniforms. They may use
17 GrCoordTransforms to receive a transformation of the local coordinates that map from local space
18 to the fragment being processed.
19 */
20 class GrFragmentProcessor : public GrProcessor {
21 public:
22 GrFragmentProcessor()
23 : INHERITED()
24 , fWillReadDstColor(false)
25 , fWillUseInputColor(true) {}
26
27 virtual const GrBackendFragmentProcessorFactory& getFactory() const = 0;
28
29 int numTransforms() const { return fCoordTransforms.count(); }
30
31 /** Returns the coordinate transformation at index. index must be valid acco rding to
32 numTransforms(). */
33 const GrCoordTransform& coordTransform(int index) const { return *fCoordTran sforms[index]; }
34
35 /** Will this prceossor read the destination pixel value? */
36 bool willReadDstColor() const { return fWillReadDstColor; }
37
38 /** Will this prceossor read the source color value? */
39 bool willUseInputColor() const { return fWillUseInputColor; }
40
41 /** Returns true if this and other prceossor conservatively draw identically . It can only return
42 true when the two prceossor are of the same subclass (i.e. they return t he same object from
43 from getFactory()).
44
45 A return value of true from isEqual() should not be used to test whether the prceossor would
46 generate the same shader code. To test for identical code generation use the prceossor' keys
47 computed by the GrBackendProcessorFactory. */
48 bool isEqual(const GrFragmentProcessor& other) const {
49 if (&this->getFactory() != &other.getFactory()) {
50 return false;
51 }
52 bool result = this->onIsEqual(other);
53 #ifdef SK_DEBUG
54 if (result) {
55 this->assertTexturesEqual(other);
56 }
57 #endif
58 return result;
59 }
60
61 protected:
62 /**
63 * Fragment Processor subclasses call this from their constructor to registe r coordinate
64 * transformations. The processor subclass manages the lifetime of the trans formations (this
65 * function only stores a pointer). The GrCoordTransform is typically a memb er field of the
66 * GrProcessor subclass. When the matrix has perspective, the transformed co ordinates will have
67 * 3 components. Otherwise they'll have 2. This must only be called from the constructor because
68 * GrProcessors are immutable.
69 */
70 void addCoordTransform(const GrCoordTransform*);
71
72 /**
73 * If the prceossor subclass will read the destination pixel value then it m ust call this function
74 * from its constructor. Otherwise, when its generated backend-specific prce ossor class attempts
75 * to generate code that reads the destination pixel it will fail.
76 */
77 void setWillReadDstColor() { fWillReadDstColor = true; }
78
79 /**
80 * If the prceossor will generate a result that does not depend on the input color value then it
81 * must call this function from its constructor. Otherwise, when its generat ed backend-specific
82 * code might fail during variable binding due to unused variables.
83 */
84 void setWillNotUseInputColor() { fWillUseInputColor = false; }
85
86 private:
87 /** Subclass implements this to support isEqual(). It will only be called if it is known that
88 the two prceossor are of the same subclass (i.e. they return the same ob ject from
89 getFactory()).*/
90 virtual bool onIsEqual(const GrFragmentProcessor& other) const = 0;
91
92 SkSTArray<4, const GrCoordTransform*, true> fCoordTransforms;
93 bool fWillReadDstColor;
94 bool fWillUseInputColor;
95
96 typedef GrProcessor INHERITED;
97 };
98
99 /**
100 * This creates an effect outside of the effect memory pool. The effect's destru ctor will be called
101 * at global destruction time. NAME will be the name of the created GrProcessor.
102 */
103 #define GR_CREATE_STATIC_FRAGMENT_PROCESSOR(NAME, FP_CLASS, ARGS) \
104 static SkAlignedSStorage<sizeof(FP_CLASS)> g_##NAME##_Storage; \
105 static GrFragmentProcessor* NAME SkNEW_PLACEMENT_ARGS(g_##NAME##_Storage.get(), FP_CLASS, ARGS); \
106 static SkAutoTDestroy<GrFragmentProcessor> NAME##_ad(NAME);
107
108 #endif
OLDNEW
« no previous file with comments | « gyp/gpu.gypi ('k') | include/gpu/GrGeometryProcessor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698