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 GrEffect_DEFINED | 8 #ifndef GrEffect_DEFINED |
9 #define GrEffect_DEFINED | 9 #define GrEffect_DEFINED |
10 | 10 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 void* operator new(size_t size); | 123 void* operator new(size_t size); |
124 void operator delete(void* target); | 124 void operator delete(void* target); |
125 | 125 |
126 void* operator new(size_t size, void* placement) { | 126 void* operator new(size_t size, void* placement) { |
127 return ::operator new(size, placement); | 127 return ::operator new(size, placement); |
128 } | 128 } |
129 void operator delete(void* target, void* placement) { | 129 void operator delete(void* target, void* placement) { |
130 ::operator delete(target, placement); | 130 ::operator delete(target, placement); |
131 } | 131 } |
132 | 132 |
133 /** | |
134 * Helper for down-casting to a GrEffect subclass | |
135 */ | |
136 template <typename T> const T& cast() const { return *static_cast<const T*>(
this); } | |
137 | |
138 protected: | 133 protected: |
139 /** | 134 /** |
140 * Subclasses call this from their constructor to register coordinate transf
ormations. The | 135 * Subclasses call this from their constructor to register coordinate transf
ormations. The |
141 * effect subclass manages the lifetime of the transformations (this functio
n only stores a | 136 * effect subclass manages the lifetime of the transformations (this functio
n only stores a |
142 * pointer). The GrCoordTransform is typically a member field of the GrEffec
t subclass. When the | 137 * pointer). The GrCoordTransform is typically a member field of the GrEffec
t subclass. When the |
143 * matrix has perspective, the transformed coordinates will have 3 component
s. Otherwise they'll | 138 * matrix has perspective, the transformed coordinates will have 3 component
s. Otherwise they'll |
144 * have 2. This must only be called from the constructor because GrEffects a
re immutable. | 139 * have 2. This must only be called from the constructor because GrEffects a
re immutable. |
145 */ | 140 */ |
146 void addCoordTransform(const GrCoordTransform* coordTransform); | 141 void addCoordTransform(const GrCoordTransform* coordTransform); |
147 | 142 |
148 /** | 143 /** |
149 * Subclasses call this from their constructor to register GrTextureAccesses
. The effect | 144 * Subclasses call this from their constructor to register GrTextureAccesses
. The effect |
150 * subclass manages the lifetime of the accesses (this function only stores
a pointer). The | 145 * subclass manages the lifetime of the accesses (this function only stores
a pointer). The |
151 * GrTextureAccess is typically a member field of the GrEffect subclass. Thi
s must only be | 146 * GrTextureAccess is typically a member field of the GrEffect subclass. Thi
s must only be |
152 * called from the constructor because GrEffects are immutable. | 147 * called from the constructor because GrEffects are immutable. |
153 */ | 148 */ |
154 void addTextureAccess(const GrTextureAccess* textureAccess); | 149 void addTextureAccess(const GrTextureAccess* textureAccess); |
155 | 150 |
156 GrEffect() | 151 GrEffect() |
157 : fWillReadDstColor(false) | 152 : fWillReadDstColor(false) |
158 , fWillReadFragmentPosition(false) | 153 , fWillReadFragmentPosition(false) |
159 , fWillUseInputColor(true) | 154 , fWillUseInputColor(true) |
160 , fRequiresVertexShader(false) {} | 155 , fRequiresVertexShader(false) {} |
161 | 156 |
162 /** | 157 /** |
| 158 * Helper for down-casting to a GrEffect subclass |
| 159 */ |
| 160 template <typename T> static const T& CastEffect(const GrEffect& effect) { |
| 161 return *static_cast<const T*>(&effect); |
| 162 } |
| 163 |
| 164 /** |
163 * If the effect subclass will read the destination pixel value then it must
call this function | 165 * If the effect subclass will read the destination pixel value then it must
call this function |
164 * from its constructor. Otherwise, when its generated backend-specific effe
ct class attempts | 166 * from its constructor. Otherwise, when its generated backend-specific effe
ct class attempts |
165 * to generate code that reads the destination pixel it will fail. | 167 * to generate code that reads the destination pixel it will fail. |
166 */ | 168 */ |
167 void setWillReadDstColor() { fWillReadDstColor = true; } | 169 void setWillReadDstColor() { fWillReadDstColor = true; } |
168 | 170 |
169 /** | 171 /** |
170 * If the effect will generate a backend-specific effect that will read the
fragment position | 172 * If the effect will generate a backend-specific effect that will read the
fragment position |
171 * in the FS then it must call this method from its constructor. Otherwise,
the request to | 173 * in the FS then it must call this method from its constructor. Otherwise,
the request to |
172 * access the fragment position will be denied. | 174 * access the fragment position will be denied. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 /** | 206 /** |
205 * This creates an effect outside of the effect memory pool. The effect's destru
ctor will be called | 207 * This creates an effect outside of the effect memory pool. The effect's destru
ctor will be called |
206 * at global destruction time. NAME will be the name of the created GrEffect. | 208 * at global destruction time. NAME will be the name of the created GrEffect. |
207 */ | 209 */ |
208 #define GR_CREATE_STATIC_EFFECT(NAME, EFFECT_CLASS, ARGS)
\ | 210 #define GR_CREATE_STATIC_EFFECT(NAME, EFFECT_CLASS, ARGS)
\ |
209 static SkAlignedSStorage<sizeof(EFFECT_CLASS)> g_##NAME##_Storage;
\ | 211 static SkAlignedSStorage<sizeof(EFFECT_CLASS)> g_##NAME##_Storage;
\ |
210 static GrEffect* NAME SkNEW_PLACEMENT_ARGS(g_##NAME##_Storage.get(), EFFECT_CLAS
S, ARGS); \ | 212 static GrEffect* NAME SkNEW_PLACEMENT_ARGS(g_##NAME##_Storage.get(), EFFECT_CLAS
S, ARGS); \ |
211 static SkAutoTDestroy<GrEffect> NAME##_ad(NAME); | 213 static SkAutoTDestroy<GrEffect> NAME##_ad(NAME); |
212 | 214 |
213 #endif | 215 #endif |
OLD | NEW |