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