Chromium Code Reviews| 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> static const T& CastEffect(const GrEffect& effect) { | |
|
bsalomon
2014/09/15 19:54:25
How about
template <typename T> const T& cast() c
| |
| 137 return *static_cast<const T*>(&effect); | |
| 138 } | |
| 139 | |
| 133 protected: | 140 protected: |
| 134 /** | 141 /** |
| 135 * Subclasses call this from their constructor to register coordinate transf ormations. The | 142 * Subclasses call this from their constructor to register coordinate transf ormations. The |
| 136 * effect subclass manages the lifetime of the transformations (this functio n only stores a | 143 * effect subclass manages the lifetime of the transformations (this functio n only stores a |
| 137 * pointer). The GrCoordTransform is typically a member field of the GrEffec t subclass. When the | 144 * pointer). The GrCoordTransform is typically a member field of the GrEffec t subclass. When the |
| 138 * matrix has perspective, the transformed coordinates will have 3 component s. Otherwise they'll | 145 * matrix has perspective, the transformed coordinates will have 3 component s. Otherwise they'll |
| 139 * have 2. This must only be called from the constructor because GrEffects a re immutable. | 146 * have 2. This must only be called from the constructor because GrEffects a re immutable. |
| 140 */ | 147 */ |
| 141 void addCoordTransform(const GrCoordTransform* coordTransform); | 148 void addCoordTransform(const GrCoordTransform* coordTransform); |
| 142 | 149 |
| 143 /** | 150 /** |
| 144 * Subclasses call this from their constructor to register GrTextureAccesses . The effect | 151 * Subclasses call this from their constructor to register GrTextureAccesses . The effect |
| 145 * subclass manages the lifetime of the accesses (this function only stores a pointer). The | 152 * subclass manages the lifetime of the accesses (this function only stores a pointer). The |
| 146 * GrTextureAccess is typically a member field of the GrEffect subclass. Thi s must only be | 153 * GrTextureAccess is typically a member field of the GrEffect subclass. Thi s must only be |
| 147 * called from the constructor because GrEffects are immutable. | 154 * called from the constructor because GrEffects are immutable. |
| 148 */ | 155 */ |
| 149 void addTextureAccess(const GrTextureAccess* textureAccess); | 156 void addTextureAccess(const GrTextureAccess* textureAccess); |
| 150 | 157 |
| 151 GrEffect() | 158 GrEffect() |
| 152 : fWillReadDstColor(false) | 159 : fWillReadDstColor(false) |
| 153 , fWillReadFragmentPosition(false) | 160 , fWillReadFragmentPosition(false) |
| 154 , fWillUseInputColor(true) | 161 , fWillUseInputColor(true) |
| 155 , fRequiresVertexShader(false) {} | 162 , fRequiresVertexShader(false) {} |
| 156 | 163 |
| 157 /** | 164 /** |
| 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 /** | |
| 165 * 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 |
| 166 * 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 |
| 167 * to generate code that reads the destination pixel it will fail. | 167 * to generate code that reads the destination pixel it will fail. |
| 168 */ | 168 */ |
| 169 void setWillReadDstColor() { fWillReadDstColor = true; } | 169 void setWillReadDstColor() { fWillReadDstColor = true; } |
| 170 | 170 |
| 171 /** | 171 /** |
| 172 * 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 |
| 173 * 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 |
| 174 * 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... | |
| 206 /** | 206 /** |
| 207 * 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 |
| 208 * 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. |
| 209 */ | 209 */ |
| 210 #define GR_CREATE_STATIC_EFFECT(NAME, EFFECT_CLASS, ARGS) \ | 210 #define GR_CREATE_STATIC_EFFECT(NAME, EFFECT_CLASS, ARGS) \ |
| 211 static SkAlignedSStorage<sizeof(EFFECT_CLASS)> g_##NAME##_Storage; \ | 211 static SkAlignedSStorage<sizeof(EFFECT_CLASS)> g_##NAME##_Storage; \ |
| 212 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); \ |
| 213 static SkAutoTDestroy<GrEffect> NAME##_ad(NAME); | 213 static SkAutoTDestroy<GrEffect> NAME##_ad(NAME); |
| 214 | 214 |
| 215 #endif | 215 #endif |
| OLD | NEW |