OLD | NEW |
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 19 matching lines...) Expand all Loading... |
30 Dynamically allocated GrProcessors are managed by a per-thread memory pool.
The ref count of an | 30 Dynamically allocated GrProcessors are managed by a per-thread memory pool.
The ref count of an |
31 effect must reach 0 before the thread terminates and the pool is destroyed.
To create a static | 31 effect must reach 0 before the thread terminates and the pool is destroyed.
To create a static |
32 effect use the macro GR_CREATE_STATIC_EFFECT declared below. | 32 effect use the macro GR_CREATE_STATIC_EFFECT declared below. |
33 */ | 33 */ |
34 class GrProcessor : public GrProgramElement { | 34 class GrProcessor : public GrProgramElement { |
35 public: | 35 public: |
36 SK_DECLARE_INST_COUNT(GrProcessor) | 36 SK_DECLARE_INST_COUNT(GrProcessor) |
37 | 37 |
38 virtual ~GrProcessor(); | 38 virtual ~GrProcessor(); |
39 | 39 |
40 struct InvariantOutput{ | |
41 GrColor fColor; | |
42 uint32_t fValidFlags; | |
43 bool fIsSingleComponent; | |
44 | |
45 bool isOpaque() const { | |
46 return ((fValidFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUn
packA(fColor)); | |
47 } | |
48 | |
49 bool isSolidWhite() const { | |
50 return (fValidFlags == kRGBA_GrColorComponentFlags && | |
51 0xFFFFFFFF == GrColorUnpackA(fColor)); | |
52 } | |
53 | |
54 /** | |
55 * If isSingleComponent is true, then the flag values for r, g, b, and a
must all be the | |
56 * same. If the flags are all set then all color components must be equa
l. | |
57 */ | |
58 SkDEBUGCODE(void validate() const;) | |
59 | |
60 private: | |
61 SkDEBUGCODE(bool colorComponentsAllEqual() const;) | |
62 | |
63 /** | |
64 * If alpha is valid, check that any valid R,G,B values are <= A | |
65 */ | |
66 SkDEBUGCODE(bool validPreMulColor() const;) | |
67 }; | |
68 | |
69 /** | 40 /** |
70 * This function is used to perform optimizations. When called the invarient
Ouput param | 41 * This function is used to perform optimizations. When called the color and
validFlags params |
71 * indicate whether the input components to this effect in the FS will have
known values. | 42 * indicate whether the input components to this effect in the FS will have
known values. |
72 * In inout the validFlags member is a bitfield of GrColorComponentFlags. Th
e isSingleComponent | 43 * validFlags is a bitfield of GrColorComponentFlags. The function updates b
oth params to |
73 * member indicates whether the input will be 1 or 4 bytes. The function upd
ates the members of | 44 * indicate known values of its output. A component of the color param only
has meaning if the |
74 * inout to indicate known values of its output. A component of the color me
mber only has | 45 * corresponding bit in validFlags is set. |
75 * meaning if the corresponding bit in validFlags is set. | |
76 */ | 46 */ |
77 void computeInvariantOutput(InvariantOutput* inout) const { | 47 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags
) const = 0; |
78 this->onComputeInvariantOutput(inout); | |
79 #ifdef SK_DEBUG | |
80 inout->validate(); | |
81 #endif | |
82 } | |
83 | 48 |
84 /** This object, besides creating back-end-specific helper objects, is used
for run-time-type- | 49 /** This object, besides creating back-end-specific helper objects, is used
for run-time-type- |
85 identification. The factory should be an instance of templated class, | 50 identification. The factory should be an instance of templated class, |
86 GrTBackendEffectFactory. It is templated on the subclass of GrProcessor.
The subclass must | 51 GrTBackendEffectFactory. It is templated on the subclass of GrProcessor.
The subclass must |
87 have a nested type (or typedef) named GLProcessor which will be the subc
lass of | 52 have a nested type (or typedef) named GLProcessor which will be the subc
lass of |
88 GrGLProcessor created by the factory. | 53 GrGLProcessor created by the factory. |
89 | 54 |
90 Example: | 55 Example: |
91 class MyCustomEffect : public GrProcessor { | 56 class MyCustomEffect : public GrProcessor { |
92 ... | 57 ... |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 void setWillReadFragmentPosition() { fWillReadFragmentPosition = true; } | 151 void setWillReadFragmentPosition() { fWillReadFragmentPosition = true; } |
187 | 152 |
188 private: | 153 private: |
189 SkDEBUGCODE(void assertEquality(const GrProcessor& other) const;) | 154 SkDEBUGCODE(void assertEquality(const GrProcessor& other) const;) |
190 | 155 |
191 /** Subclass implements this to support isEqual(). It will only be called if
it is known that | 156 /** Subclass implements this to support isEqual(). It will only be called if
it is known that |
192 the two effects are of the same subclass (i.e. they return the same obje
ct from | 157 the two effects are of the same subclass (i.e. they return the same obje
ct from |
193 getFactory()).*/ | 158 getFactory()).*/ |
194 virtual bool onIsEqual(const GrProcessor& other) const = 0; | 159 virtual bool onIsEqual(const GrProcessor& other) const = 0; |
195 | 160 |
196 /** | |
197 * Subclass implements this to support getConstantColorComponents(...). | |
198 */ | |
199 virtual void onComputeInvariantOutput(InvariantOutput* inout) const = 0; | |
200 friend class GrGeometryProcessor; // to set fRequiresVertexShader and build
fVertexAttribTypes. | 161 friend class GrGeometryProcessor; // to set fRequiresVertexShader and build
fVertexAttribTypes. |
201 | 162 |
202 SkSTArray<4, const GrCoordTransform*, true> fCoordTransforms; | 163 SkSTArray<4, const GrCoordTransform*, true> fCoordTransforms; |
203 SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses; | 164 SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses; |
204 bool fWillReadFragmentPosition; | 165 bool fWillReadFragmentPosition; |
205 | 166 |
206 typedef GrProgramElement INHERITED; | 167 typedef GrProgramElement INHERITED; |
207 }; | 168 }; |
208 | 169 |
209 class GrFragmentProcessor : public GrProcessor { | 170 class GrFragmentProcessor : public GrProcessor { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 * This creates an effect outside of the effect memory pool. The effect's destru
ctor will be called | 208 * This creates an effect outside of the effect memory pool. The effect's destru
ctor will be called |
248 * at global destruction time. NAME will be the name of the created GrProcessor. | 209 * at global destruction time. NAME will be the name of the created GrProcessor. |
249 */ | 210 */ |
250 #define GR_CREATE_STATIC_FRAGMENT_PROCESSOR(NAME, EFFECT_CLASS, ARGS)
\ | 211 #define GR_CREATE_STATIC_FRAGMENT_PROCESSOR(NAME, EFFECT_CLASS, ARGS)
\ |
251 static SkAlignedSStorage<sizeof(EFFECT_CLASS)> g_##NAME##_Storage;
\ | 212 static SkAlignedSStorage<sizeof(EFFECT_CLASS)> g_##NAME##_Storage;
\ |
252 static GrFragmentProcessor*
\ | 213 static GrFragmentProcessor*
\ |
253 NAME SkNEW_PLACEMENT_ARGS(g_##NAME##_Storage.get(), EFFECT_CLASS, ARGS);
\ | 214 NAME SkNEW_PLACEMENT_ARGS(g_##NAME##_Storage.get(), EFFECT_CLASS, ARGS);
\ |
254 static SkAutoTDestroy<GrFragmentProcessor> NAME##_ad(NAME); | 215 static SkAutoTDestroy<GrFragmentProcessor> NAME##_ad(NAME); |
255 | 216 |
256 #endif | 217 #endif |
OLD | NEW |