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 GrProcessor_DEFINED | 8 #ifndef GrProcessor_DEFINED |
9 #define GrProcessor_DEFINED | 9 #define GrProcessor_DEFINED |
10 | 10 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 | 72 |
73 int numTextures() const { return fTextureAccesses.count(); } | 73 int numTextures() const { return fTextureAccesses.count(); } |
74 | 74 |
75 /** Returns the access pattern for the texture at index. index must be valid
according to | 75 /** Returns the access pattern for the texture at index. index must be valid
according to |
76 numTextures(). */ | 76 numTextures(). */ |
77 const GrTextureAccess& textureAccess(int index) const { return *fTextureAcce
sses[index]; } | 77 const GrTextureAccess& textureAccess(int index) const { return *fTextureAcce
sses[index]; } |
78 | 78 |
79 /** Shortcut for textureAccess(index).texture(); */ | 79 /** Shortcut for textureAccess(index).texture(); */ |
80 GrTexture* texture(int index) const { return this->textureAccess(index).getT
exture(); } | 80 GrTexture* texture(int index) const { return this->textureAccess(index).getT
exture(); } |
81 | 81 |
82 /** Will this processor read the fragment position? */ | 82 /** |
83 bool willReadFragmentPosition() const { return fWillReadFragmentPosition; } | 83 * Platform specific built-in features that a processor can request for the
fragment shader. |
| 84 */ |
| 85 enum RequiredFeatures { |
| 86 kNone_RequiredFeatures = 0, |
| 87 kFragmentPosition_RequiredFeature = 1 |
| 88 }; |
| 89 |
| 90 GR_DECL_BITFIELD_OPS_FRIENDS(RequiredFeatures); |
| 91 |
| 92 RequiredFeatures requiredFeatures() const { return fRequiredFeatures; } |
84 | 93 |
85 void* operator new(size_t size); | 94 void* operator new(size_t size); |
86 void operator delete(void* target); | 95 void operator delete(void* target); |
87 | 96 |
88 void* operator new(size_t size, void* placement) { | 97 void* operator new(size_t size, void* placement) { |
89 return ::operator new(size, placement); | 98 return ::operator new(size, placement); |
90 } | 99 } |
91 void operator delete(void* target, void* placement) { | 100 void operator delete(void* target, void* placement) { |
92 ::operator delete(target, placement); | 101 ::operator delete(target, placement); |
93 } | 102 } |
94 | 103 |
95 /** | 104 /** |
96 * Helper for down-casting to a GrProcessor subclass | 105 * Helper for down-casting to a GrProcessor subclass |
97 */ | 106 */ |
98 template <typename T> const T& cast() const { return *static_cast<const T*>(
this); } | 107 template <typename T> const T& cast() const { return *static_cast<const T*>(
this); } |
99 | 108 |
100 uint32_t classID() const { SkASSERT(kIllegalProcessorClassID != fClassID); r
eturn fClassID; } | 109 uint32_t classID() const { SkASSERT(kIllegalProcessorClassID != fClassID); r
eturn fClassID; } |
101 | 110 |
102 protected: | 111 protected: |
103 GrProcessor() : fClassID(kIllegalProcessorClassID), fWillReadFragmentPositio
n(false) {} | 112 GrProcessor() : fClassID(kIllegalProcessorClassID), fRequiredFeatures(kNone_
RequiredFeatures) {} |
104 | 113 |
105 /** | 114 /** |
106 * Subclasses call this from their constructor to register GrTextureAccesses
. The processor | 115 * Subclasses call this from their constructor to register GrTextureAccesses
. The processor |
107 * subclass manages the lifetime of the accesses (this function only stores
a pointer). The | 116 * subclass manages the lifetime of the accesses (this function only stores
a pointer). The |
108 * GrTextureAccess is typically a member field of the GrProcessor subclass.
This must only be | 117 * GrTextureAccess is typically a member field of the GrProcessor subclass.
This must only be |
109 * called from the constructor because GrProcessors are immutable. | 118 * called from the constructor because GrProcessors are immutable. |
110 */ | 119 */ |
111 virtual void addTextureAccess(const GrTextureAccess* textureAccess); | 120 virtual void addTextureAccess(const GrTextureAccess* textureAccess); |
112 | 121 |
113 bool hasSameTextureAccesses(const GrProcessor&) const; | 122 bool hasSameTextureAccesses(const GrProcessor&) const; |
114 | 123 |
115 /** | 124 /** |
116 * If the prcoessor will generate a backend-specific processor that will rea
d the fragment | 125 * If the prcoessor will generate a backend-specific processor that will rea
d the fragment |
117 * position in the FS then it must call this method from its constructor. Ot
herwise, the | 126 * position in the FS then it must call this method from its constructor. Ot
herwise, the |
118 * request to access the fragment position will be denied. | 127 * request to access the fragment position will be denied. |
119 */ | 128 */ |
120 void setWillReadFragmentPosition() { fWillReadFragmentPosition = true; } | 129 void setWillReadFragmentPosition() { fRequiredFeatures |= kFragmentPosition_
RequiredFeature; } |
| 130 |
| 131 void combineRequiredFeatures(const GrProcessor& other) { |
| 132 fRequiredFeatures |= other.fRequiredFeatures; |
| 133 } |
121 | 134 |
122 template <typename PROC_SUBCLASS> void initClassID() { | 135 template <typename PROC_SUBCLASS> void initClassID() { |
123 static uint32_t kClassID = GenClassID(); | 136 static uint32_t kClassID = GenClassID(); |
124 fClassID = kClassID; | 137 fClassID = kClassID; |
125 } | 138 } |
126 | 139 |
127 uint32_t fClassID; | 140 uint32_t fClassID; |
128 SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses; | 141 SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses; |
129 | 142 |
130 private: | 143 private: |
131 static uint32_t GenClassID() { | 144 static uint32_t GenClassID() { |
132 // fCurrProcessorClassID has been initialized to kIllegalProcessorClassI
D. The | 145 // fCurrProcessorClassID has been initialized to kIllegalProcessorClassI
D. The |
133 // atomic inc returns the old value not the incremented value. So we add | 146 // atomic inc returns the old value not the incremented value. So we add |
134 // 1 to the returned value. | 147 // 1 to the returned value. |
135 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(&gCurrProcessorClassID
)) + 1; | 148 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(&gCurrProcessorClassID
)) + 1; |
136 if (!id) { | 149 if (!id) { |
137 SkFAIL("This should never wrap as it should only be called once for
each GrProcessor " | 150 SkFAIL("This should never wrap as it should only be called once for
each GrProcessor " |
138 "subclass."); | 151 "subclass."); |
139 } | 152 } |
140 return id; | 153 return id; |
141 } | 154 } |
142 | 155 |
143 enum { | 156 enum { |
144 kIllegalProcessorClassID = 0, | 157 kIllegalProcessorClassID = 0, |
145 }; | 158 }; |
146 static int32_t gCurrProcessorClassID; | 159 static int32_t gCurrProcessorClassID; |
147 | 160 |
148 bool fWillReadFragmentPosition; | 161 RequiredFeatures fRequiredFeatures; |
149 | 162 |
150 typedef GrProgramElement INHERITED; | 163 typedef GrProgramElement INHERITED; |
151 }; | 164 }; |
152 | 165 |
| 166 GR_MAKE_BITFIELD_OPS(GrProcessor::RequiredFeatures); |
| 167 |
153 #endif | 168 #endif |
OLD | NEW |