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 GrTBackendProcessorFactory_DEFINED | 8 #ifndef GrTBackendProcessorFactory_DEFINED |
9 #define GrTBackendProcessorFactory_DEFINED | 9 #define GrTBackendProcessorFactory_DEFINED |
10 | 10 |
(...skipping 23 matching lines...) Expand all Loading... |
34 */ | 34 */ |
35 template <class ProcessorClass, class BackEnd, class ProcessorBase, class GLProc
essorBase> | 35 template <class ProcessorClass, class BackEnd, class ProcessorBase, class GLProc
essorBase> |
36 class GrTBackendProcessorFactory : public BackEnd { | 36 class GrTBackendProcessorFactory : public BackEnd { |
37 public: | 37 public: |
38 typedef typename ProcessorClass::GLProcessor GLProcessor; | 38 typedef typename ProcessorClass::GLProcessor GLProcessor; |
39 | 39 |
40 /** Returns a human-readable name for the processor. Implemented using GLPro
cessor::Name as | 40 /** Returns a human-readable name for the processor. Implemented using GLPro
cessor::Name as |
41 * described in this class's comment. */ | 41 * described in this class's comment. */ |
42 virtual const char* name() const SK_OVERRIDE { return ProcessorClass::Name()
; } | 42 virtual const char* name() const SK_OVERRIDE { return ProcessorClass::Name()
; } |
43 | 43 |
44 | |
45 /** Implemented using GLProcessor::GenKey as described in this class's comme
nt. */ | |
46 virtual void getGLProcessorKey(const GrProcessor& processor, | |
47 const GrGLCaps& caps, | |
48 GrProcessorKeyBuilder* b) const SK_OVERRIDE { | |
49 GLProcessor::GenKey(processor, caps, b); | |
50 } | |
51 | |
52 /** Returns a new instance of the appropriate *GL* implementation class | 44 /** Returns a new instance of the appropriate *GL* implementation class |
53 for the given GrProcessor; caller is responsible for deleting | 45 for the given GrProcessor; caller is responsible for deleting |
54 the object. */ | 46 the object. */ |
55 virtual GLProcessorBase* createGLInstance(const ProcessorBase& processor) co
nst SK_OVERRIDE { | 47 virtual GLProcessorBase* createGLInstance(const ProcessorBase& processor) co
nst SK_OVERRIDE { |
56 return SkNEW_ARGS(GLProcessor, (*this, processor)); | 48 return SkNEW_ARGS(GLProcessor, (*this, processor)); |
57 } | 49 } |
58 | 50 |
59 /** This class is a singleton. This function returns the single instance. */ | 51 /** This class is a singleton. This function returns the single instance. */ |
60 static const BackEnd& getInstance() { | 52 static const BackEnd& getInstance() { |
61 static SkAlignedSTStorage<1, GrTBackendProcessorFactory> gInstanceMem; | 53 static SkAlignedSTStorage<1, GrTBackendProcessorFactory> gInstanceMem; |
62 static const GrTBackendProcessorFactory* gInstance; | 54 static const GrTBackendProcessorFactory* gInstance; |
63 if (!gInstance) { | 55 if (!gInstance) { |
64 gInstance = SkNEW_PLACEMENT(gInstanceMem.get(), | 56 gInstance = SkNEW_PLACEMENT(gInstanceMem.get(), |
65 GrTBackendProcessorFactory); | 57 GrTBackendProcessorFactory); |
66 } | 58 } |
67 return *gInstance; | 59 return *gInstance; |
68 } | 60 } |
69 | 61 |
70 protected: | 62 protected: |
71 GrTBackendProcessorFactory() {} | 63 GrTBackendProcessorFactory() {} |
72 }; | 64 }; |
73 | 65 |
74 /* | 66 /* |
75 * Every processor so far derives from one of the following subclasses of | 67 * Every processor so far derives from one of the following subclasses of |
76 * GrTBackendProcessorFactory. All of this machinery is necessary to ensure that
creatGLInstace is | 68 * GrTBackendProcessorFactory. All of this machinery is necessary to ensure that
creatGLInstace is |
77 * typesafe and does not require any casting. | 69 * typesafe and does not require any casting. |
78 */ | 70 */ |
79 template <class ProcessorClass> | 71 template <class ProcessorClass> |
80 class GrTBackendGeometryProcessorFactory | 72 class GrTBackendGeometryProcessorFactory : public GrBackendGeometryProcessorFact
ory { |
81 : public GrTBackendProcessorFactory<ProcessorClass, | 73 public: |
82 GrBackendGeometryProcessorFactory, | 74 typedef typename ProcessorClass::GLProcessor GLProcessor; |
83 GrGeometryProcessor, | 75 |
84 GrGLGeometryProcessor> { | 76 /** Returns a human-readable name for the processor. Implemented using GLPro
cessor::Name as |
| 77 * described in this class's comment. */ |
| 78 virtual const char* name() const SK_OVERRIDE { return ProcessorClass::Name()
; } |
| 79 |
| 80 /** Implemented using GLProcessor::GenKey as described in this class's comme
nt. */ |
| 81 virtual void getGLProcessorKey(const GrGeometryProcessor& processor, |
| 82 const GrBatchTracker& bt, |
| 83 const GrGLCaps& caps, |
| 84 GrProcessorKeyBuilder* b) const SK_OVERRIDE { |
| 85 GLProcessor::GenKey(processor, bt, caps, b); |
| 86 } |
| 87 |
| 88 |
| 89 /** Returns a new instance of the appropriate *GL* implementation class |
| 90 for the given GrProcessor; caller is responsible for deleting |
| 91 the object. */ |
| 92 virtual GrGLGeometryProcessor* createGLInstance(const GrGeometryProcessor& g
p, |
| 93 const GrBatchTracker& bt) co
nst SK_OVERRIDE { |
| 94 return SkNEW_ARGS(GLProcessor, (*this, gp, bt)); |
| 95 } |
| 96 |
| 97 /** This class is a singleton. This function returns the single instance. */ |
| 98 static const GrBackendGeometryProcessorFactory& getInstance() { |
| 99 static SkAlignedSTStorage<1, GrTBackendGeometryProcessorFactory> gInstan
ceMem; |
| 100 static const GrTBackendGeometryProcessorFactory* gInstance; |
| 101 if (!gInstance) { |
| 102 gInstance = SkNEW_PLACEMENT(gInstanceMem.get(), |
| 103 GrTBackendGeometryProcessorFactory); |
| 104 } |
| 105 return *gInstance; |
| 106 } |
85 protected: | 107 protected: |
86 GrTBackendGeometryProcessorFactory() {} | 108 GrTBackendGeometryProcessorFactory() {} |
87 }; | 109 }; |
88 | 110 |
89 template <class ProcessorClass> | 111 template <class ProcessorClass> |
90 class GrTBackendFragmentProcessorFactory | 112 class GrTBackendFragmentProcessorFactory : public GrBackendFragmentProcessorFact
ory { |
91 : public GrTBackendProcessorFactory<ProcessorClass, | 113 public: |
92 GrBackendFragmentProcessorFactory, | 114 typedef typename ProcessorClass::GLProcessor GLProcessor; |
93 GrFragmentProcessor, | 115 |
94 GrGLFragmentProcessor> { | 116 /** Returns a human-readable name for the processor. Implemented using GLPro
cessor::Name as |
| 117 * described in this class's comment. */ |
| 118 virtual const char* name() const SK_OVERRIDE { return ProcessorClass::Name()
; } |
| 119 |
| 120 /** Implemented using GLProcessor::GenKey as described in this class's comme
nt. */ |
| 121 virtual void getGLProcessorKey(const GrFragmentProcessor& processor, |
| 122 const GrGLCaps& caps, |
| 123 GrProcessorKeyBuilder* b) const SK_OVERRIDE { |
| 124 GLProcessor::GenKey(processor, caps, b); |
| 125 } |
| 126 |
| 127 /** Returns a new instance of the appropriate *GL* implementation class |
| 128 for the given GrProcessor; caller is responsible for deleting |
| 129 the object. */ |
| 130 virtual GrGLFragmentProcessor* createGLInstance(const GrFragmentProcessor& g
p) const SK_OVERRIDE { |
| 131 return SkNEW_ARGS(GLProcessor, (*this, gp)); |
| 132 } |
| 133 |
| 134 /** This class is a singleton. This function returns the single instance. */ |
| 135 static const GrBackendFragmentProcessorFactory& getInstance() { |
| 136 static SkAlignedSTStorage<1, GrTBackendFragmentProcessorFactory> gInstan
ceMem; |
| 137 static const GrTBackendFragmentProcessorFactory* gInstance; |
| 138 if (!gInstance) { |
| 139 gInstance = SkNEW_PLACEMENT(gInstanceMem.get(), |
| 140 GrTBackendFragmentProcessorFactory); |
| 141 } |
| 142 return *gInstance; |
| 143 } |
95 protected: | 144 protected: |
96 GrTBackendFragmentProcessorFactory() {} | 145 GrTBackendFragmentProcessorFactory() {} |
97 }; | 146 }; |
98 | 147 |
99 | |
100 #endif | 148 #endif |
OLD | NEW |