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 GrBackendProcessorFactory_DEFINED | 8 #ifndef GrBackendProcessorFactory_DEFINED |
9 #define GrBackendProcessorFactory_DEFINED | 9 #define GrBackendProcessorFactory_DEFINED |
10 | 10 |
11 #include "GrTypes.h" | 11 #include "GrTypes.h" |
12 #include "SkTemplates.h" | 12 #include "SkTemplates.h" |
13 #include "SkThread.h" | 13 #include "SkThread.h" |
14 #include "SkTypes.h" | 14 #include "SkTypes.h" |
15 #include "SkTArray.h" | 15 #include "SkTArray.h" |
16 | 16 |
17 class GrGLProcessor; | 17 class GrGLProcessor; |
18 class GrGLCaps; | 18 class GrGLCaps; |
19 class GrProcessor; | 19 class GrProcessor; |
20 | 20 |
21 /** | 21 /** |
22 * Used by effects to build their keys. It incorporates each per-processor key i
nto a larger shader | 22 * Used by processors to build their keys. It incorporates each per-processor ke
y into a larger shader |
23 * key. | 23 * key. |
24 */ | 24 */ |
25 class GrProcessorKeyBuilder { | 25 class GrProcessorKeyBuilder { |
26 public: | 26 public: |
27 GrProcessorKeyBuilder(SkTArray<unsigned char, true>* data) : fData(data), fC
ount(0) { | 27 GrProcessorKeyBuilder(SkTArray<unsigned char, true>* data) : fData(data), fC
ount(0) { |
28 SkASSERT(0 == fData->count() % sizeof(uint32_t)); | 28 SkASSERT(0 == fData->count() % sizeof(uint32_t)); |
29 } | 29 } |
30 | 30 |
31 void add32(uint32_t v) { | 31 void add32(uint32_t v) { |
32 ++fCount; | 32 ++fCount; |
33 fData->push_back_n(4, reinterpret_cast<uint8_t*>(&v)); | 33 fData->push_back_n(4, reinterpret_cast<uint8_t*>(&v)); |
34 } | 34 } |
35 | 35 |
36 /** Inserts count uint32_ts into the key. The returned pointer is only valid
until the next | 36 /** Inserts count uint32_ts into the key. The returned pointer is only valid
until the next |
37 add*() call. */ | 37 add*() call. */ |
38 uint32_t* SK_WARN_UNUSED_RESULT add32n(int count) { | 38 uint32_t* SK_WARN_UNUSED_RESULT add32n(int count) { |
39 SkASSERT(count > 0); | 39 SkASSERT(count > 0); |
40 fCount += count; | 40 fCount += count; |
41 return reinterpret_cast<uint32_t*>(fData->push_back_n(4 * count)); | 41 return reinterpret_cast<uint32_t*>(fData->push_back_n(4 * count)); |
42 } | 42 } |
43 | 43 |
44 size_t size() const { return sizeof(uint32_t) * fCount; } | 44 size_t size() const { return sizeof(uint32_t) * fCount; } |
45 | 45 |
46 private: | 46 private: |
47 SkTArray<uint8_t, true>* fData; // unowned ptr to the larger key. | 47 SkTArray<uint8_t, true>* fData; // unowned ptr to the larger key. |
48 int fCount; // number of uint32_ts added to fData by the
effect. | 48 int fCount; // number of uint32_ts added to fData by the
processor. |
49 }; | 49 }; |
50 | 50 |
51 /** | 51 /** |
52 * This class is used to pass the key that was created for a GrGLProcessor back
to it | 52 * This class is used to pass the key that was created for a GrGLProcessor back
to it |
53 * when it emits code. It may allow the emit step to skip calculations that were | 53 * when it emits code. It may allow the emit step to skip calculations that were |
54 * performed when computing the key. | 54 * performed when computing the key. |
55 */ | 55 */ |
56 class GrProcessorKey { | 56 class GrProcessorKey { |
57 public: | 57 public: |
58 GrProcessorKey(const uint32_t* key, int count) : fKey(key), fCount(count) { | 58 GrProcessorKey(const uint32_t* key, int count) : fKey(key), fCount(count) { |
59 SkASSERT(0 == reinterpret_cast<intptr_t>(key) % sizeof(uint32_t)); | 59 SkASSERT(0 == reinterpret_cast<intptr_t>(key) % sizeof(uint32_t)); |
60 } | 60 } |
61 | 61 |
62 /** Gets the uint32_t values that the effect inserted into the key. */ | 62 /** Gets the uint32_t values that the processor inserted into the key. */ |
63 uint32_t get32(int index) const { | 63 uint32_t get32(int index) const { |
64 SkASSERT(index >=0 && index < fCount); | 64 SkASSERT(index >=0 && index < fCount); |
65 return fKey[index]; | 65 return fKey[index]; |
66 } | 66 } |
67 | 67 |
68 /** Gets the number of uint32_t values that the effect inserted into the key
. */ | 68 /** Gets the number of uint32_t values that the processor inserted into the
key. */ |
69 int count32() const { return fCount; } | 69 int count32() const { return fCount; } |
70 | 70 |
71 private: | 71 private: |
72 const uint32_t* fKey; // unowned ptr into the larger key. | 72 const uint32_t* fKey; // unowned ptr into the larger key. |
73 int fCount; // number of uint32_ts inserted by the effec
t into its key. | 73 int fCount; // number of uint32_ts inserted by the proce
ssor into its key. |
74 }; | 74 }; |
75 | 75 |
76 /** | 76 /** |
77 * Given a GrProcessor of a particular type, creates the corresponding graphics-
backend-specific | 77 * Given a GrProcessor of a particular type, creates the corresponding graphics-
backend-specific |
78 * effect object. It also tracks equivalence of shaders generated via a key. The
factory for an | 78 * processor object. It also tracks equivalence of shaders generated via a key.
The factory for an |
79 * effect is accessed via GrProcessor::getFactory(). Each factory instance is as
signed an ID at | 79 * processor is accessed via GrProcessor::getFactory(). Each factory instance is
assigned an ID at |
80 * construction. The ID of GrProcessor::getFactory() is used as a type identifie
r. Thus, a | 80 * construction. The ID of GrProcessor::getFactory() is used as a type identifie
r. Thus, a |
81 * GrProcessor subclass must always return the same object from getFactory() and
that factory object | 81 * GrProcessor subclass must always return the same object from getFactory() and
that factory object |
82 * must be unique to the GrProcessor subclass (and unique from any further deriv
ed subclasses). | 82 * must be unique to the GrProcessor subclass (and unique from any further deriv
ed subclasses). |
83 * | 83 * |
84 * Rather than subclassing this class themselves, it is recommended that GrProce
ssor authors use | 84 * Rather than subclassing this class themselves, it is recommended that GrProce
ssor authors use |
85 * the templated subclass GrTBackendEffectFactory by writing their getFactory()
method as: | 85 * the templated subclass GrTBackendProcessorFactory by writing their getFactory
() method as: |
86 * | 86 * |
87 * const GrBackendEffectFactory& MyEffect::getFactory() const { | 87 * const GrBackendProcessorFactory& MyProcessor::getFactory() const { |
88 * return GrTBackendEffectFactory<MyEffect>::getInstance(); | 88 * return GrTBackendProcessorFactory<MyProcessor>::getInstance(); |
89 * } | 89 * } |
90 * | 90 * |
91 * Using GrTBackendEffectFactory places a few constraints on the effect. See tha
t class's comments. | 91 * Using GrTBackendProcessorFactory places a few constraints on the processor. S
ee that class's |
| 92 * comments. |
92 */ | 93 */ |
93 class GrBackendProcessorFactory : SkNoncopyable { | 94 class GrBackendProcessorFactory : SkNoncopyable { |
94 public: | 95 public: |
95 /** | 96 /** |
96 * Generates an effect's key. The key is based on the aspects of the GrProce
ssor object's | 97 * Generates an processor's key. The key is based on the aspects of the GrPr
ocessor object's |
97 * configuration that affect GLSL code generation. Two GrProcessor instances
that would cause | 98 * configuration that affect GLSL code generation. Two GrProcessor instances
that would cause |
98 * this->createGLInstance()->emitCode() to produce different code must produ
ce different keys. | 99 * this->createGLInstance()->emitCode() to produce different code must produ
ce different keys. |
99 */ | 100 */ |
100 virtual void getGLProcessorKey(const GrProcessor&, const GrGLCaps&, | 101 virtual void getGLProcessorKey(const GrProcessor&, const GrGLCaps&, |
101 GrProcessorKeyBuilder*) const = 0; | 102 GrProcessorKeyBuilder*) const = 0; |
102 | 103 |
103 /** | 104 /** |
104 * Produces a human-reable name for the effect. | 105 * Produces a human-reable name for the v. |
105 */ | 106 */ |
106 virtual const char* name() const = 0; | 107 virtual const char* name() const = 0; |
107 | 108 |
108 /** | 109 /** |
109 * A unique value for every instance of this factory. It is automatically in
corporated into the | 110 * A unique value for every instance of this factory. It is automatically in
corporated into the |
110 * effect's key. This allows keys generated by getGLProcessorKey() to only b
e unique within a | 111 * processor's key. This allows keys generated by getGLProcessorKey() to onl
y be unique within a |
111 * GrProcessor subclass and not necessarily across subclasses. | 112 * GrProcessor subclass and not necessarily across subclasses. |
112 */ | 113 */ |
113 uint32_t effectClassID() const { return fEffectClassID; } | 114 uint32_t effectClassID() const { return fEffectClassID; } |
114 | 115 |
115 protected: | 116 protected: |
116 GrBackendProcessorFactory() : fEffectClassID(GenID()) {} | 117 GrBackendProcessorFactory() : fEffectClassID(GenID()) {} |
117 virtual ~GrBackendProcessorFactory() {} | 118 virtual ~GrBackendProcessorFactory() {} |
118 | 119 |
119 private: | 120 private: |
120 enum { | 121 enum { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 class GrBackendGeometryProcessorFactory : public GrBackendProcessorFactory { | 160 class GrBackendGeometryProcessorFactory : public GrBackendProcessorFactory { |
160 public: | 161 public: |
161 /** | 162 /** |
162 * Creates a GrGLProcessor instance that is used both to generate code for t
he GrProcessor in a | 163 * Creates a GrGLProcessor instance that is used both to generate code for t
he GrProcessor in a |
163 * GLSL program and to manage updating uniforms for the program when it is u
sed. | 164 * GLSL program and to manage updating uniforms for the program when it is u
sed. |
164 */ | 165 */ |
165 virtual GrGLGeometryProcessor* createGLInstance(const GrGeometryProcessor&)
const = 0; | 166 virtual GrGLGeometryProcessor* createGLInstance(const GrGeometryProcessor&)
const = 0; |
166 }; | 167 }; |
167 | 168 |
168 #endif | 169 #endif |
OLD | NEW |