| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright 2012 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 #ifndef GrTBackendProcessorFactory_DEFINED | |
| 9 #define GrTBackendProcessorFactory_DEFINED | |
| 10 | |
| 11 #include "GrBackendProcessorFactory.h" | |
| 12 | |
| 13 /** | |
| 14 * Implements GrBackendProcessorFactory for a GrProcessor subclass as a singleto
n. This can be used | |
| 15 * by most GrProcessor subclasses to implement the GrProcessor::getFactory() met
hod: | |
| 16 * | |
| 17 * const GrBackendProcessorFactory& MyProcessor::getFactory() const { | |
| 18 * return GrTBackendProcessorFactory<MyProcessor>::getInstance(); | |
| 19 * } | |
| 20 * | |
| 21 * Using this class requires that the GrProcessor subclass always produces the s
ame GrGLProcessor | |
| 22 * subclass. Additionally, it adds the following requirements to the GrProcessor
and GrGLProcessor | |
| 23 * subclasses: | |
| 24 * | |
| 25 * 1. The GrGLProcessor used by GrProcessor subclass MyProcessor must be named o
r typedef'ed to | |
| 26 * MyProcessor::GLProcessor. | |
| 27 * 2. MyProcessor::GLProcessor must have a static function: | |
| 28 void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKeyBuilder*
b) | |
| 29 * which generates a key that maps 1 to 1 with code variations emitted by | |
| 30 * MyProcessor::GLProcessor::emitCode(). | |
| 31 * 3. MyProcessor must have a static function: | |
| 32 * const char* Name() | |
| 33 * which returns a human-readable name for the processor. | |
| 34 */ | |
| 35 template <class ProcessorClass, class BackEnd, class ProcessorBase, class GLProc
essorBase> | |
| 36 class GrTBackendProcessorFactory : public BackEnd { | |
| 37 public: | |
| 38 typedef typename ProcessorClass::GLProcessor GLProcessor; | |
| 39 | |
| 40 /** Returns a human-readable name for the processor. Implemented using GLPro
cessor::Name as | |
| 41 * described in this class's comment. */ | |
| 42 virtual const char* name() const SK_OVERRIDE { return ProcessorClass::Name()
; } | |
| 43 | |
| 44 /** Returns a new instance of the appropriate *GL* implementation class | |
| 45 for the given GrProcessor; caller is responsible for deleting | |
| 46 the object. */ | |
| 47 virtual GLProcessorBase* createGLInstance(const ProcessorBase& processor) co
nst SK_OVERRIDE { | |
| 48 return SkNEW_ARGS(GLProcessor, (*this, processor)); | |
| 49 } | |
| 50 | |
| 51 /** This class is a singleton. This function returns the single instance. */ | |
| 52 static const BackEnd& getInstance() { | |
| 53 static SkAlignedSTStorage<1, GrTBackendProcessorFactory> gInstanceMem; | |
| 54 static const GrTBackendProcessorFactory* gInstance; | |
| 55 if (!gInstance) { | |
| 56 gInstance = SkNEW_PLACEMENT(gInstanceMem.get(), | |
| 57 GrTBackendProcessorFactory); | |
| 58 } | |
| 59 return *gInstance; | |
| 60 } | |
| 61 | |
| 62 protected: | |
| 63 GrTBackendProcessorFactory() {} | |
| 64 }; | |
| 65 | |
| 66 /* | |
| 67 * Every processor so far derives from one of the following subclasses of | |
| 68 * GrTBackendProcessorFactory. All of this machinery is necessary to ensure that
creatGLInstace is | |
| 69 * typesafe and does not require any casting. | |
| 70 */ | |
| 71 template <class ProcessorClass> | |
| 72 class GrTBackendGeometryProcessorFactory : public GrBackendGeometryProcessorFact
ory { | |
| 73 public: | |
| 74 typedef typename ProcessorClass::GLProcessor GLProcessor; | |
| 75 | |
| 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 } | |
| 107 protected: | |
| 108 GrTBackendGeometryProcessorFactory() {} | |
| 109 }; | |
| 110 | |
| 111 template <class ProcessorClass> | |
| 112 class GrTBackendFragmentProcessorFactory : public GrBackendFragmentProcessorFact
ory { | |
| 113 public: | |
| 114 typedef typename ProcessorClass::GLProcessor GLProcessor; | |
| 115 | |
| 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 } | |
| 144 protected: | |
| 145 GrTBackendFragmentProcessorFactory() {} | |
| 146 }; | |
| 147 | |
| 148 #endif | |
| OLD | NEW |