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 InvarientOutput{ | |
bsalomon
2014/09/30 00:41:01
"Invariant" (gulp)
There might be some more usefu
egdaniel
2014/10/02 14:58:33
Fixed speeling
| |
41 GrColor color; | |
42 uint32_t validFlags; | |
bsalomon
2014/09/30 00:41:01
fColor, fValidFlags, fIsSingleComponent
egdaniel
2014/10/02 14:58:33
Done.
| |
43 bool isSingleComponent; | |
44 | |
45 bool hasOpaqueAlpha() const { | |
bsalomon
2014/09/30 00:41:01
isOpaque?
egdaniel
2014/10/02 14:58:33
Done.
| |
46 return ((validFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUnp ackA(color)); | |
47 } | |
48 | |
49 bool hasOpaqueColor() const { | |
50 return (validFlags == kRGBA_GrColorComponentFlags && | |
bsalomon
2014/09/30 00:41:01
isSolidWhite?
egdaniel
2014/10/02 14:58:33
Done.
| |
51 0xFFFFFFFF == GrColorUnpackA(color)); | |
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 | |
40 /** | 64 /** |
41 * This function is used to perform optimizations. When called the color and validFlags params | 65 * This function is used to perform optimizations. When called the invarient Ouput param |
42 * indicate whether the input components to this effect in the FS will have known values. | 66 * indicate whether the input components to this effect in the FS will have known values. |
43 * validFlags is a bitfield of GrColorComponentFlags. The function updates b oth params to | 67 * In invarientOutput the validFlags member is a bitfield of GrColorComponen tFlags. The |
44 * indicate known values of its output. A component of the color param only has meaning if the | 68 * isSingleComponent member indicates whether the input will be 1 or 4 bytes . The function |
45 * corresponding bit in validFlags is set. | 69 * updates the members of invarientOutput to indicate known values of its ou tput. A component |
70 * of the color member only has meaning if the corresponding bit in validFla gs is set. | |
46 */ | 71 */ |
47 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags ) const = 0; | 72 void computeInvarientOutput(InvarientOutput* invarientOutput) const { |
bsalomon
2014/09/30 00:41:01
Because the param is inout it feels weird to call
egdaniel
2014/10/02 14:58:33
Done.
| |
73 this->onComputeInvarientOutput(invarientOutput); | |
74 #ifdef SK_DEBUG | |
75 invarientOutput->validate(); | |
76 #endif | |
77 } | |
48 | 78 |
49 /** This object, besides creating back-end-specific helper objects, is used for run-time-type- | 79 /** This object, besides creating back-end-specific helper objects, is used for run-time-type- |
50 identification. The factory should be an instance of templated class, | 80 identification. The factory should be an instance of templated class, |
51 GrTBackendEffectFactory. It is templated on the subclass of GrProcessor. The subclass must | 81 GrTBackendEffectFactory. It is templated on the subclass of GrProcessor. The subclass must |
52 have a nested type (or typedef) named GLProcessor which will be the subc lass of | 82 have a nested type (or typedef) named GLProcessor which will be the subc lass of |
53 GrGLProcessor created by the factory. | 83 GrGLProcessor created by the factory. |
54 | 84 |
55 Example: | 85 Example: |
56 class MyCustomEffect : public GrProcessor { | 86 class MyCustomEffect : public GrProcessor { |
57 ... | 87 ... |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 void setWillReadFragmentPosition() { fWillReadFragmentPosition = true; } | 181 void setWillReadFragmentPosition() { fWillReadFragmentPosition = true; } |
152 | 182 |
153 private: | 183 private: |
154 SkDEBUGCODE(void assertEquality(const GrProcessor& other) const;) | 184 SkDEBUGCODE(void assertEquality(const GrProcessor& other) const;) |
155 | 185 |
156 /** Subclass implements this to support isEqual(). It will only be called if it is known that | 186 /** Subclass implements this to support isEqual(). It will only be called if it is known that |
157 the two effects are of the same subclass (i.e. they return the same obje ct from | 187 the two effects are of the same subclass (i.e. they return the same obje ct from |
158 getFactory()).*/ | 188 getFactory()).*/ |
159 virtual bool onIsEqual(const GrProcessor& other) const = 0; | 189 virtual bool onIsEqual(const GrProcessor& other) const = 0; |
160 | 190 |
191 /** | |
192 * Subclass implements this to support getConstantColorComponents(...). | |
193 */ | |
194 virtual void onComputeInvarientOutput(InvarientOutput* invarientOutput) cons t = 0; | |
161 friend class GrGeometryProcessor; // to set fRequiresVertexShader and build fVertexAttribTypes. | 195 friend class GrGeometryProcessor; // to set fRequiresVertexShader and build fVertexAttribTypes. |
162 | 196 |
163 SkSTArray<4, const GrCoordTransform*, true> fCoordTransforms; | 197 SkSTArray<4, const GrCoordTransform*, true> fCoordTransforms; |
164 SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses; | 198 SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses; |
165 bool fWillReadFragmentPosition; | 199 bool fWillReadFragmentPosition; |
166 | 200 |
167 typedef GrProgramElement INHERITED; | 201 typedef GrProgramElement INHERITED; |
168 }; | 202 }; |
169 | 203 |
170 class GrFragmentProcessor : public GrProcessor { | 204 class GrFragmentProcessor : public GrProcessor { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
208 * This creates an effect outside of the effect memory pool. The effect's destru ctor will be called | 242 * This creates an effect outside of the effect memory pool. The effect's destru ctor will be called |
209 * at global destruction time. NAME will be the name of the created GrProcessor. | 243 * at global destruction time. NAME will be the name of the created GrProcessor. |
210 */ | 244 */ |
211 #define GR_CREATE_STATIC_FRAGMENT_PROCESSOR(NAME, EFFECT_CLASS, ARGS) \ | 245 #define GR_CREATE_STATIC_FRAGMENT_PROCESSOR(NAME, EFFECT_CLASS, ARGS) \ |
212 static SkAlignedSStorage<sizeof(EFFECT_CLASS)> g_##NAME##_Storage; \ | 246 static SkAlignedSStorage<sizeof(EFFECT_CLASS)> g_##NAME##_Storage; \ |
213 static GrFragmentProcessor* \ | 247 static GrFragmentProcessor* \ |
214 NAME SkNEW_PLACEMENT_ARGS(g_##NAME##_Storage.get(), EFFECT_CLASS, ARGS); \ | 248 NAME SkNEW_PLACEMENT_ARGS(g_##NAME##_Storage.get(), EFFECT_CLASS, ARGS); \ |
215 static SkAutoTDestroy<GrFragmentProcessor> NAME##_ad(NAME); | 249 static SkAutoTDestroy<GrFragmentProcessor> NAME##_ad(NAME); |
216 | 250 |
217 #endif | 251 #endif |
OLD | NEW |