Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: include/gpu/GrTBackendProcessorFactory.h

Issue 660563003: More effect->processor cleanup (Closed) Base URL: https://skia.googlesource.com/skia.git@comments
Patch Set: more Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/gpu/GrProcessor.h ('k') | src/gpu/gl/GrGLProcessor.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 #include "GrBackendProcessorFactory.h" 11 #include "GrBackendProcessorFactory.h"
12 12
13 /** 13 /**
14 * Implements GrBackendEffectFactory for a GrProcessor subclass as a singleton. This can be used by 14 * Implements GrBackendProcessorFactory for a GrProcessor subclass as a singleto n. This can be used
15 * most GrProcessor subclasses to implement the GrProcessor::getFactory() method : 15 * by most GrProcessor subclasses to implement the GrProcessor::getFactory() met hod:
16 * 16 *
17 * const GrBackendEffectFactory& MyEffect::getFactory() const { 17 * const GrBackendProcessorFactory& MyProcessor::getFactory() const {
18 * return GrTBackendEffectFactory<MyEffect>::getInstance(); 18 * return GrTBackendProcessorFactory<MyProcessor>::getInstance();
19 * } 19 * }
20 * 20 *
21 * Using this class requires that the GrProcessor subclass always produces the s ame GrGLProcessor 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 22 * subclass. Additionally, it adds the following requirements to the GrProcessor and GrGLProcessor
23 * subclasses: 23 * subclasses:
24 * 24 *
25 * 1. The GrGLProcessor used by GrProcessor subclass MyEffect must be named or t ypedef'ed to 25 * 1. The GrGLProcessor used by GrProcessor subclass MyProcessor must be named o r typedef'ed to
26 * MyEffect::GLProcessor. 26 * MyProcessor::GLProcessor.
27 * 2. MyEffect::GLProcessor must have a static function: 27 * 2. MyProcessor::GLProcessor must have a static function:
28 * EffectKey GenKey(const GrProcessor, const GrGLCaps&) 28 void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKeyBuilder* b)
29 * which generates a key that maps 1 to 1 with code variations emitted by 29 * which generates a key that maps 1 to 1 with code variations emitted by
30 * MyEffect::GLProcessor::emitCode(). 30 * MyProcessor::GLProcessor::emitCode().
31 * 3. MyEffect must have a static function: 31 * 3. MyProcessor must have a static function:
32 * const char* Name() 32 * const char* Name()
33 * which returns a human-readable name for the effect. 33 * which returns a human-readable name for the processor.
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 effect. Implemented using GLProces sor::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 44
45 /** Implemented using GLProcessor::GenKey as described in this class's comme nt. */ 45 /** Implemented using GLProcessor::GenKey as described in this class's comme nt. */
46 virtual void getGLProcessorKey(const GrProcessor& effect, 46 virtual void getGLProcessorKey(const GrProcessor& processor,
47 const GrGLCaps& caps, 47 const GrGLCaps& caps,
48 GrProcessorKeyBuilder* b) const SK_OVERRIDE { 48 GrProcessorKeyBuilder* b) const SK_OVERRIDE {
49 GLProcessor::GenKey(effect, caps, b); 49 GLProcessor::GenKey(processor, caps, b);
50 } 50 }
51 51
52 /** Returns a new instance of the appropriate *GL* implementation class 52 /** Returns a new instance of the appropriate *GL* implementation class
53 for the given GrProcessor; caller is responsible for deleting 53 for the given GrProcessor; caller is responsible for deleting
54 the object. */ 54 the object. */
55 virtual GLProcessorBase* createGLInstance(const ProcessorBase& effect) const SK_OVERRIDE { 55 virtual GLProcessorBase* createGLInstance(const ProcessorBase& processor) co nst SK_OVERRIDE {
56 return SkNEW_ARGS(GLProcessor, (*this, effect)); 56 return SkNEW_ARGS(GLProcessor, (*this, processor));
57 } 57 }
58 58
59 /** This class is a singleton. This function returns the single instance. */ 59 /** This class is a singleton. This function returns the single instance. */
60 static const BackEnd& getInstance() { 60 static const BackEnd& getInstance() {
61 static SkAlignedSTStorage<1, GrTBackendProcessorFactory> gInstanceMem; 61 static SkAlignedSTStorage<1, GrTBackendProcessorFactory> gInstanceMem;
62 static const GrTBackendProcessorFactory* gInstance; 62 static const GrTBackendProcessorFactory* gInstance;
63 if (!gInstance) { 63 if (!gInstance) {
64 gInstance = SkNEW_PLACEMENT(gInstanceMem.get(), 64 gInstance = SkNEW_PLACEMENT(gInstanceMem.get(),
65 GrTBackendProcessorFactory); 65 GrTBackendProcessorFactory);
66 } 66 }
67 return *gInstance; 67 return *gInstance;
68 } 68 }
69 69
70 protected: 70 protected:
71 GrTBackendProcessorFactory() {} 71 GrTBackendProcessorFactory() {}
72 }; 72 };
73 73
74 /* 74 /*
75 * Every effect so far derives from one of the following subclasses of GrTBacken dProcessorFactory. 75 * Every processor so far derives from one of the following subclasses of
76 * All of this machinery is necessary to ensure that creatGLInstace is typesafe and does not 76 * GrTBackendProcessorFactory. All of this machinery is necessary to ensure that creatGLInstace is
77 * require any casting 77 * typesafe and does not require any casting.
78 */ 78 */
79 template <class ProcessorClass> 79 template <class ProcessorClass>
80 class GrTBackendGeometryProcessorFactory 80 class GrTBackendGeometryProcessorFactory
81 : public GrTBackendProcessorFactory<ProcessorClass, 81 : public GrTBackendProcessorFactory<ProcessorClass,
82 GrBackendGeometryProcessorFactory, 82 GrBackendGeometryProcessorFactory,
83 GrGeometryProcessor, 83 GrGeometryProcessor,
84 GrGLGeometryProcessor> { 84 GrGLGeometryProcessor> {
85 protected: 85 protected:
86 GrTBackendGeometryProcessorFactory() {} 86 GrTBackendGeometryProcessorFactory() {}
87 }; 87 };
88 88
89 template <class ProcessorClass> 89 template <class ProcessorClass>
90 class GrTBackendFragmentProcessorFactory 90 class GrTBackendFragmentProcessorFactory
91 : public GrTBackendProcessorFactory<ProcessorClass, 91 : public GrTBackendProcessorFactory<ProcessorClass,
92 GrBackendFragmentProcessorFactory, 92 GrBackendFragmentProcessorFactory,
93 GrFragmentProcessor, 93 GrFragmentProcessor,
94 GrGLFragmentProcessor> { 94 GrGLFragmentProcessor> {
95 protected: 95 protected:
96 GrTBackendFragmentProcessorFactory() {} 96 GrTBackendFragmentProcessorFactory() {}
97 }; 97 };
98 98
99 99
100 #endif 100 #endif
OLDNEW
« no previous file with comments | « include/gpu/GrProcessor.h ('k') | src/gpu/gl/GrGLProcessor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698