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 GrTBackendEffectFactory_DEFINED | 8 #ifndef GrTBackendEffectFactory_DEFINED |
9 #define GrTBackendEffectFactory_DEFINED | 9 #define GrTBackendEffectFactory_DEFINED |
10 | 10 |
11 #include "GrBackendEffectFactory.h" | 11 #include "GrBackendEffectFactory.h" |
| 12 #include "GrDrawEffect.h" |
12 #include "gl/GrGLProgramEffects.h" | 13 #include "gl/GrGLProgramEffects.h" |
13 | 14 |
14 /** | 15 /** |
15 * Implements GrBackendEffectFactory for a GrEffect subclass as a singleton. Thi
s can be used by | 16 * Implements GrBackendEffectFactory for a GrEffect subclass as a singleton. Thi
s can be used by |
16 * most GrEffect subclasses to implement the GrEffect::getFactory() method: | 17 * most GrEffect subclasses to implement the GrEffect::getFactory() method: |
17 * | 18 * |
18 * const GrBackendEffectFactory& MyEffect::getFactory() const { | 19 * const GrBackendEffectFactory& MyEffect::getFactory() const { |
19 * return GrTBackendEffectFactory<MyEffect>::getInstance(); | 20 * return GrTBackendEffectFactory<MyEffect>::getInstance(); |
20 * } | 21 * } |
21 * | 22 * |
22 * Using this class requires that the GrEffect subclass always produces the same
GrGLEffect | 23 * Using this class requires that the GrEffect subclass always produces the same
GrGLEffect |
23 * subclass. Additionally, It adds the following requirements to the GrEffect an
d GrGLEffect | 24 * subclass. Additionally, It adds the following requirements to the GrEffect an
d GrGLEffect |
24 * subclasses: | 25 * subclasses: |
25 * | 26 * |
26 * 1. The GrGLEffect used by GrEffect subclass MyEffect must be named or typedef
'ed to | 27 * 1. The GrGLEffect used by GrEffect subclass MyEffect must be named or typedef
'ed to |
27 * MyEffect::GLEffect. | 28 * MyEffect::GLEffect. |
28 * 2. MyEffect::GLEffect must have a static function: | 29 * 2. MyEffect::GLEffect must have a static function: |
29 * EffectKey GenKey(const GrEffect, const GrGLCaps&) | 30 * EffectKey GenKey(const GrDrawEffect, const GrGLCaps&) |
30 * which generates a key that maps 1 to 1 with code variations emitted by | 31 * which generates a key that maps 1 to 1 with code variations emitted by |
31 * MyEffect::GLEffect::emitCode(). | 32 * MyEffect::GLEffect::emitCode(). |
32 * 3. MyEffect must have a static function: | 33 * 3. MyEffect must have a static function: |
33 * const char* Name() | 34 * const char* Name() |
34 * which returns a human-readable name for the effect. | 35 * which returns a human-readable name for the effect. |
35 */ | 36 */ |
36 template <typename EffectClass> | 37 template <typename EffectClass> |
37 class GrTBackendEffectFactory : public GrBackendEffectFactory { | 38 class GrTBackendEffectFactory : public GrBackendEffectFactory { |
38 | 39 |
39 public: | 40 public: |
40 typedef typename EffectClass::GLEffect GLEffect; | 41 typedef typename EffectClass::GLEffect GLEffect; |
41 | 42 |
42 /** Returns a human-readable name for the effect. Implemented using GLEffect
::Name as described | 43 /** Returns a human-readable name for the effect. Implemented using GLEffect
::Name as described |
43 * in this class's comment. */ | 44 * in this class's comment. */ |
44 virtual const char* name() const SK_OVERRIDE { return EffectClass::Name(); } | 45 virtual const char* name() const SK_OVERRIDE { return EffectClass::Name(); } |
45 | 46 |
46 | 47 |
47 /** Implemented using GLEffect::GenKey as described in this class's comment.
*/ | 48 /** Implemented using GLEffect::GenKey as described in this class's comment.
*/ |
48 virtual void getGLEffectKey(const GrEffect& effect, | 49 virtual void getGLEffectKey(const GrDrawEffect& drawEffect, |
49 const GrGLCaps& caps, | 50 const GrGLCaps& caps, |
50 GrEffectKeyBuilder* b) const SK_OVERRIDE { | 51 GrEffectKeyBuilder* b) const SK_OVERRIDE { |
51 GLEffect::GenKey(effect, caps, b); | 52 GLEffect::GenKey(drawEffect, caps, b); |
52 } | 53 } |
53 | 54 |
54 /** Returns a new instance of the appropriate *GL* implementation class | 55 /** Returns a new instance of the appropriate *GL* implementation class |
55 for the given GrEffect; caller is responsible for deleting | 56 for the given GrEffect; caller is responsible for deleting |
56 the object. */ | 57 the object. */ |
57 virtual GrGLEffect* createGLInstance(const GrEffect& effect) const SK_OVERRI
DE { | 58 virtual GrGLEffect* createGLInstance(const GrDrawEffect& drawEffect) const S
K_OVERRIDE { |
58 return SkNEW_ARGS(GLEffect, (*this, effect)); | 59 return SkNEW_ARGS(GLEffect, (*this, drawEffect)); |
59 } | 60 } |
60 | 61 |
61 /** This class is a singleton. This function returns the single instance. */ | 62 /** This class is a singleton. This function returns the single instance. */ |
62 static const GrBackendEffectFactory& getInstance() { | 63 static const GrBackendEffectFactory& getInstance() { |
63 static SkAlignedSTStorage<1, GrTBackendEffectFactory> gInstanceMem; | 64 static SkAlignedSTStorage<1, GrTBackendEffectFactory> gInstanceMem; |
64 static const GrTBackendEffectFactory* gInstance; | 65 static const GrTBackendEffectFactory* gInstance; |
65 if (!gInstance) { | 66 if (!gInstance) { |
66 gInstance = SkNEW_PLACEMENT(gInstanceMem.get(), | 67 gInstance = SkNEW_PLACEMENT(gInstanceMem.get(), |
67 GrTBackendEffectFactory); | 68 GrTBackendEffectFactory); |
68 } | 69 } |
69 return *gInstance; | 70 return *gInstance; |
70 } | 71 } |
71 | 72 |
72 protected: | 73 protected: |
73 GrTBackendEffectFactory() {} | 74 GrTBackendEffectFactory() {} |
74 }; | 75 }; |
75 | 76 |
76 #endif | 77 #endif |
OLD | NEW |