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 |
11 #include "GrColor.h" | 11 #include "GrColor.h" |
12 #include "GrProcessorUnitTest.h" | 12 #include "GrProcessorUnitTest.h" |
13 #include "GrProgramElement.h" | 13 #include "GrProgramElement.h" |
14 #include "GrTextureAccess.h" | 14 #include "GrTextureAccess.h" |
| 15 #include "GrBufferAccess.h" |
15 #include "SkMath.h" | 16 #include "SkMath.h" |
16 #include "SkString.h" | 17 #include "SkString.h" |
17 | 18 |
18 class GrContext; | 19 class GrContext; |
19 class GrCoordTransform; | 20 class GrCoordTransform; |
20 class GrInvariantOutput; | 21 class GrInvariantOutput; |
21 | 22 |
22 /** | 23 /** |
23 * Used by processors to build their keys. It incorporates each per-processor ke
y into a larger | 24 * Used by processors to build their keys. It incorporates each per-processor ke
y into a larger |
24 * shader key. | 25 * shader key. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 | 73 |
73 int numTextures() const { return fTextureAccesses.count(); } | 74 int numTextures() const { return fTextureAccesses.count(); } |
74 | 75 |
75 /** Returns the access pattern for the texture at index. index must be valid
according to | 76 /** Returns the access pattern for the texture at index. index must be valid
according to |
76 numTextures(). */ | 77 numTextures(). */ |
77 const GrTextureAccess& textureAccess(int index) const { return *fTextureAcce
sses[index]; } | 78 const GrTextureAccess& textureAccess(int index) const { return *fTextureAcce
sses[index]; } |
78 | 79 |
79 /** Shortcut for textureAccess(index).texture(); */ | 80 /** Shortcut for textureAccess(index).texture(); */ |
80 GrTexture* texture(int index) const { return this->textureAccess(index).getT
exture(); } | 81 GrTexture* texture(int index) const { return this->textureAccess(index).getT
exture(); } |
81 | 82 |
| 83 int numBuffers() const { return fBufferAccesses.count(); } |
| 84 |
| 85 /** Returns the access pattern for the buffer at index. index must be valid
according to |
| 86 numBuffers(). */ |
| 87 const GrBufferAccess& bufferAccess(int index) const { |
| 88 return *fBufferAccesses[index]; |
| 89 } |
| 90 |
82 /** | 91 /** |
83 * Platform specific built-in features that a processor can request for the
fragment shader. | 92 * Platform specific built-in features that a processor can request for the
fragment shader. |
84 */ | 93 */ |
85 enum RequiredFeatures { | 94 enum RequiredFeatures { |
86 kNone_RequiredFeatures = 0, | 95 kNone_RequiredFeatures = 0, |
87 kFragmentPosition_RequiredFeature = 1 << 0, | 96 kFragmentPosition_RequiredFeature = 1 << 0, |
88 kSampleLocations_RequiredFeature = 1 << 1 | 97 kSampleLocations_RequiredFeature = 1 << 1 |
89 }; | 98 }; |
90 | 99 |
91 GR_DECL_BITFIELD_OPS_FRIENDS(RequiredFeatures); | 100 GR_DECL_BITFIELD_OPS_FRIENDS(RequiredFeatures); |
(...skipping 14 matching lines...) Expand all Loading... |
106 * Helper for down-casting to a GrProcessor subclass | 115 * Helper for down-casting to a GrProcessor subclass |
107 */ | 116 */ |
108 template <typename T> const T& cast() const { return *static_cast<const T*>(
this); } | 117 template <typename T> const T& cast() const { return *static_cast<const T*>(
this); } |
109 | 118 |
110 uint32_t classID() const { SkASSERT(kIllegalProcessorClassID != fClassID); r
eturn fClassID; } | 119 uint32_t classID() const { SkASSERT(kIllegalProcessorClassID != fClassID); r
eturn fClassID; } |
111 | 120 |
112 protected: | 121 protected: |
113 GrProcessor() : fClassID(kIllegalProcessorClassID), fRequiredFeatures(kNone_
RequiredFeatures) {} | 122 GrProcessor() : fClassID(kIllegalProcessorClassID), fRequiredFeatures(kNone_
RequiredFeatures) {} |
114 | 123 |
115 /** | 124 /** |
116 * Subclasses call this from their constructor to register GrTextureAccesses
. The processor | 125 * Subclasses call these from their constructor to register sampler sources.
The processor |
117 * subclass manages the lifetime of the accesses (this function only stores
a pointer). The | 126 * subclass manages the lifetime of the objects (these functions only store
pointers). The |
118 * GrTextureAccess is typically a member field of the GrProcessor subclass.
This must only be | 127 * GrTextureAccess and/or GrBufferAccess instances are typically member fiel
ds of the |
119 * called from the constructor because GrProcessors are immutable. | 128 * GrProcessor subclass. These must only be called from the constructor beca
use GrProcessors |
| 129 * are immutable. |
120 */ | 130 */ |
121 virtual void addTextureAccess(const GrTextureAccess* textureAccess); | 131 virtual void addTextureAccess(const GrTextureAccess* textureAccess); |
| 132 virtual void addBufferAccess(const GrBufferAccess* bufferAccess); |
122 | 133 |
123 bool hasSameTextureAccesses(const GrProcessor&) const; | 134 bool hasSameSamplers(const GrProcessor&) const; |
124 | 135 |
125 /** | 136 /** |
126 * If the prcoessor will generate code that uses platform specific built-in
features, then it | 137 * If the prcoessor will generate code that uses platform specific built-in
features, then it |
127 * must call these methods from its constructor. Otherwise, requests to use
these features will | 138 * must call these methods from its constructor. Otherwise, requests to use
these features will |
128 * be denied. | 139 * be denied. |
129 */ | 140 */ |
130 void setWillReadFragmentPosition() { fRequiredFeatures |= kFragmentPosition_
RequiredFeature; } | 141 void setWillReadFragmentPosition() { fRequiredFeatures |= kFragmentPosition_
RequiredFeature; } |
131 void setWillUseSampleLocations() { fRequiredFeatures |= kSampleLocations_Req
uiredFeature; } | 142 void setWillUseSampleLocations() { fRequiredFeatures |= kSampleLocations_Req
uiredFeature; } |
132 | 143 |
133 void combineRequiredFeatures(const GrProcessor& other) { | 144 void combineRequiredFeatures(const GrProcessor& other) { |
134 fRequiredFeatures |= other.fRequiredFeatures; | 145 fRequiredFeatures |= other.fRequiredFeatures; |
135 } | 146 } |
136 | 147 |
137 template <typename PROC_SUBCLASS> void initClassID() { | 148 template <typename PROC_SUBCLASS> void initClassID() { |
138 static uint32_t kClassID = GenClassID(); | 149 static uint32_t kClassID = GenClassID(); |
139 fClassID = kClassID; | 150 fClassID = kClassID; |
140 } | 151 } |
141 | 152 |
142 uint32_t fClassID; | 153 uint32_t fClassID; |
143 SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses; | 154 SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses; |
| 155 SkSTArray<2, const GrBufferAccess*, true> fBufferAccesses; |
144 | 156 |
145 private: | 157 private: |
146 static uint32_t GenClassID() { | 158 static uint32_t GenClassID() { |
147 // fCurrProcessorClassID has been initialized to kIllegalProcessorClassI
D. The | 159 // fCurrProcessorClassID has been initialized to kIllegalProcessorClassI
D. The |
148 // atomic inc returns the old value not the incremented value. So we add | 160 // atomic inc returns the old value not the incremented value. So we add |
149 // 1 to the returned value. | 161 // 1 to the returned value. |
150 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(&gCurrProcessorClassID
)) + 1; | 162 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(&gCurrProcessorClassID
)) + 1; |
151 if (!id) { | 163 if (!id) { |
152 SkFAIL("This should never wrap as it should only be called once for
each GrProcessor " | 164 SkFAIL("This should never wrap as it should only be called once for
each GrProcessor " |
153 "subclass."); | 165 "subclass."); |
154 } | 166 } |
155 return id; | 167 return id; |
156 } | 168 } |
157 | 169 |
158 enum { | 170 enum { |
159 kIllegalProcessorClassID = 0, | 171 kIllegalProcessorClassID = 0, |
160 }; | 172 }; |
161 static int32_t gCurrProcessorClassID; | 173 static int32_t gCurrProcessorClassID; |
162 | 174 |
163 RequiredFeatures fRequiredFeatures; | 175 RequiredFeatures fRequiredFeatures; |
164 | 176 |
165 typedef GrProgramElement INHERITED; | 177 typedef GrProgramElement INHERITED; |
166 }; | 178 }; |
167 | 179 |
168 GR_MAKE_BITFIELD_OPS(GrProcessor::RequiredFeatures); | 180 GR_MAKE_BITFIELD_OPS(GrProcessor::RequiredFeatures); |
169 | 181 |
170 #endif | 182 #endif |
OLD | NEW |