8 #ifndef GrProcessor_DEFINED
9 #define GrProcessor_DEFINED
12 #include "GrProcessorUnitTest.h"
13 #include "GrProgramElement.h"
14 #include "GrTextureAccess.h"
15 #include "GrBufferAccess.h"
18 #include "../private/SkAtomics.h"
31 SkASSERT(0 == fData->count() %
sizeof(uint32_t));
34 void add32(uint32_t v) {
36 fData->push_back_n(4, reinterpret_cast<uint8_t*>(&v));
41 uint32_t* SK_WARN_UNUSED_RESULT
add32n(
int count) {
44 return reinterpret_cast<uint32_t*
>(fData->push_back_n(4 * count));
47 size_t size()
const {
return sizeof(uint32_t) * fCount; }
50 SkTArray<uint8_t, true>* fData;
66 virtual const char*
name()
const = 0;
71 str.appendf(
"Missing data");
75 int numTextures()
const {
return fTextureAccesses.count(); }
84 int numBuffers()
const {
return fBufferAccesses.count(); }
89 return *fBufferAccesses[index];
96 kNone_RequiredFeatures = 0,
97 kFragmentPosition_RequiredFeature = 1 << 0,
98 kSampleLocations_RequiredFeature = 1 << 1
105 void*
operator new(
size_t size);
106 void operator delete(
void* target);
108 void*
operator new(
size_t size,
void* placement) {
109 return ::operator
new(size, placement);
111 void operator delete(
void* target,
void* placement) {
112 ::operator
delete(target, placement);
118 template <
typename T>
const T&
cast()
const {
return *
static_cast<const T*
>(
this); }
120 uint32_t classID()
const { SkASSERT(kIllegalProcessorClassID != fClassID);
return fClassID; }
123 GrProcessor() : fClassID(kIllegalProcessorClassID), fRequiredFeatures(kNone_RequiredFeatures) {}
143 void setWillUseSampleLocations() { fRequiredFeatures |= kSampleLocations_RequiredFeature; }
145 void combineRequiredFeatures(
const GrProcessor& other) {
146 fRequiredFeatures |= other.fRequiredFeatures;
149 template <
typename PROC_SUBCLASS>
void initClassID() {
150 static uint32_t kClassID = GenClassID();
155 SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses;
156 SkSTArray<2, const GrBufferAccess*, true> fBufferAccesses;
159 static uint32_t GenClassID() {
163 uint32_t
id =
static_cast<uint32_t
>(sk_atomic_inc(&gCurrProcessorClassID)) + 1;
165 SkFAIL(
"This should never wrap as it should only be called once for each GrProcessor "
172 kIllegalProcessorClassID = 0,
174 static int32_t gCurrProcessorClassID;
Used to represent a texture that is required by a GrProcessor.
Definition: GrTextureAccess.h:21
RequiredFeatures
Platform specific built-in features that a processor can request for the fragment shader...
Definition: GrProcessor.h:95
Used to represent a texel buffer that will be read in a GrProcessor.
Definition: GrBufferAccess.h:18
uint32_t *SK_WARN_UNUSED_RESULT add32n(int count)
Inserts count uint32_ts into the key.
Definition: GrProcessor.h:41
void setWillReadFragmentPosition()
If the prcoessor will generate code that uses platform specific built-in features, then it must call these methods from its constructor.
Definition: GrProcessor.h:142
Used by processors to build their keys.
Definition: GrProcessor.h:28
Base class for GrProcessor.
Definition: GrProgramElement.h:44
GrTexture * texture(int index) const
Shortcut for textureAccess(index).texture();.
Definition: GrProcessor.h:82
Definition: GrInvariantOutput.h:57
Definition: GrContext.h:48
const GrBufferAccess & bufferAccess(int index) const
Returns the access pattern for the buffer at index.
Definition: GrProcessor.h:88
const GrTextureAccess & textureAccess(int index) const
Returns the access pattern for the texture at index.
Definition: GrProcessor.h:79
const T & cast() const
Helper for down-casting to a GrProcessor subclass.
Definition: GrProcessor.h:118
virtual const char * name() const =0
Human-meaningful string to identify this prcoessor; may be embedded in generated shader code...
Provides custom shader code to the Ganesh shading pipeline.
Definition: GrProcessor.h:60
virtual void addTextureAccess(const GrTextureAccess *textureAccess)
Subclasses call these from their constructor to register sampler sources.
Definition: GrTexture.h:19
Light weight class for managing strings.
Definition: SkString.h:121