Skia
2DGraphicsLibrary
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GrFragmentProcessor Class Referenceabstract

Provides custom fragment shader code. More...

#include <GrFragmentProcessor.h>

Inheritance diagram for GrFragmentProcessor:
GrProcessor GrProgramElement

Public Member Functions

GrGLSLFragmentProcessor * createGLSLInstance () const
 
void getGLSLProcessorKey (const GrGLSLCaps &caps, GrProcessorKeyBuilder *b) const
 
int numTexturesExclChildren () const
 
int numBuffersExclChildren () const
 
int numTransformsExclChildren () const
 
int numTransforms () const
 
const GrCoordTransformcoordTransform (int index) const
 Returns the coordinate transformation at index. More...
 
const SkTArray< const
GrCoordTransform *, true > & 
coordTransforms () const
 
void gatherCoordTransforms (SkTArray< const GrCoordTransform *, true > *outTransforms) const
 
int numChildProcessors () const
 
const GrFragmentProcessorchildProcessor (int index) const
 
bool usesLocalCoords () const
 Do any of the coordtransforms for this processor require local coords?
 
bool usesDistanceVectorField () const
 Does this FP need a vector to the nearest edge?
 
bool isEqual (const GrFragmentProcessor &that, bool ignoreCoordTransforms) const
 Returns true if this and other processor conservatively draw identically. More...
 
void computeInvariantOutput (GrInvariantOutput *inout) const
 This function is used to perform optimizations. More...
 
- Public Member Functions inherited from GrProcessor
virtual const char * name () const =0
 Human-meaningful string to identify this prcoessor; may be embedded in generated shader code. More...
 
virtual SkString dumpInfo () const
 
int numTextures () const
 
const GrTextureAccesstextureAccess (int index) const
 Returns the access pattern for the texture at index. More...
 
GrTexturetexture (int index) const
 Shortcut for textureAccess(index).texture();.
 
int numBuffers () const
 
const GrBufferAccessbufferAccess (int index) const
 Returns the access pattern for the buffer at index. More...
 
 GR_DECL_BITFIELD_OPS_FRIENDS (RequiredFeatures)
 
RequiredFeatures requiredFeatures () const
 
void * operator new (size_t size)
 
void operator delete (void *target)
 
void * operator new (size_t size, void *placement)
 
void operator delete (void *target, void *placement)
 
template<typename T >
const T & cast () const
 Helper for down-casting to a GrProcessor subclass.
 
uint32_t classID () const
 
- Public Member Functions inherited from GrProgramElement
void ref () const
 
void unref () const
 
uint32_t getUniqueID () const
 Gets an id that is unique for this GrProgramElement object. More...
 
void validate () const
 

Static Public Member Functions

static sk_sp< GrFragmentProcessorMulOutputByInputAlpha (sk_sp< GrFragmentProcessor >)
 In many instances (e.g. More...
 
static sk_sp< GrFragmentProcessorMulOutputByInputUnpremulColor (sk_sp< GrFragmentProcessor >)
 Similar to the above but it modulates the output r,g,b of the child processor by the input rgb and then multiplies all the components by the input alpha. More...
 
static sk_sp< GrFragmentProcessorOverrideInput (sk_sp< GrFragmentProcessor >, GrColor)
 Returns a parent fragment processor that adopts the passed fragment processor as a child. More...
 
static sk_sp< GrFragmentProcessorPremulInput (sk_sp< GrFragmentProcessor >)
 Returns a fragment processor that premuls the input before calling the passed in fragment processor.
 
static sk_sp< GrFragmentProcessorRunInSeries (sk_sp< GrFragmentProcessor > *, int cnt)
 Returns a fragment processor that runs the passed in array of fragment processors in a series. More...
 

Protected Member Functions

void addTextureAccess (const GrTextureAccess *textureAccess) override
 Subclasses call these from their constructor to register sampler sources. More...
 
void addBufferAccess (const GrBufferAccess *) override
 
void addCoordTransform (const GrCoordTransform *)
 Fragment Processor subclasses call this from their constructor to register coordinate transformations. More...
 
int registerChildProcessor (sk_sp< GrFragmentProcessor > child)
 FragmentProcessor subclasses call this from their constructor to register any child FragmentProcessors they have. More...
 
virtual void onComputeInvariantOutput (GrInvariantOutput *inout) const =0
 Subclass implements this to support getConstantColorComponents(...). More...
 
- Protected Member Functions inherited from GrProcessor
bool hasSameSamplers (const GrProcessor &) const
 
void setWillReadFragmentPosition ()
 If the prcoessor will generate code that uses platform specific built-in features, then it must call these methods from its constructor. More...
 
void setWillUseSampleLocations ()
 
void combineRequiredFeatures (const GrProcessor &other)
 
template<typename PROC_SUBCLASS >
void initClassID ()
 
- Protected Member Functions inherited from GrProgramElement
void addGpuResource (const GrGpuResourceRef *res)
 Subclasses registers their resources using this function. More...
 
void addPendingExecution () const
 
void completedExecution () const
 

Protected Attributes

bool fUsesDistanceVectorField
 
- Protected Attributes inherited from GrProcessor
uint32_t fClassID
 
SkSTArray< 4, const
GrTextureAccess *, true > 
fTextureAccesses
 
SkSTArray< 2, const
GrBufferAccess *, true > 
fBufferAccesses
 

Private Types

typedef GrProcessor INHERITED
 

Private Member Functions

void notifyRefCntIsZero () const final
 This will be called when the ref cnt is zero. More...
 
virtual GrGLSLFragmentProcessor * onCreateGLSLInstance () const =0
 Returns a new instance of the appropriate GL implementation class for the given GrFragmentProcessor; caller is responsible for deleting the object. More...
 
virtual void onGetGLSLProcessorKey (const GrGLSLCaps &caps, GrProcessorKeyBuilder *b) const =0
 Implemented using GLFragmentProcessor::GenKey as described in this class's comment. More...
 
virtual bool onIsEqual (const GrFragmentProcessor &) const =0
 Subclass implements this to support isEqual(). More...
 
bool hasSameTransforms (const GrFragmentProcessor &) const
 

Private Attributes

bool fUsesLocalCoords
 
SkSTArray< 4, const
GrCoordTransform *, true > 
fCoordTransforms
 fCoordTransforms stores the transforms of this proc, followed by all the transforms of this proc's children. More...
 
int fNumTexturesExclChildren
 
int fNumBuffersExclChildren
 
int fNumTransformsExclChildren
 
SkSTArray
< 1, GrFragmentProcessor
*, true > 
fChildProcessors
 This is not SkSTArray<1, sk_sp<GrFragmentProcessor>> because this class holds strong references until notifyRefCntIsZero and then it holds pending executions.
 

Additional Inherited Members

- Public Types inherited from GrProcessor
enum  RequiredFeatures { kNone_RequiredFeatures = 0, kFragmentPosition_RequiredFeature = 1 << 0, kSampleLocations_RequiredFeature = 1 << 1 }
 Platform specific built-in features that a processor can request for the fragment shader.
 

Detailed Description

Provides custom fragment shader code.

Fragment processors receive an input color (vec4f) and produce an output color. They may reference textures and uniforms. They may use GrCoordTransforms to receive a transformation of the local coordinates that map from local space to the fragment being processed.

Member Function Documentation

void GrFragmentProcessor::addCoordTransform ( const GrCoordTransform )
protected

Fragment Processor subclasses call this from their constructor to register coordinate transformations.

Coord transforms provide a mechanism for a processor to receive coordinates in their FS code. The matrix expresses a transformation from local space. For a given fragment the matrix will be applied to the local coordinate that maps to the fragment.

When the transformation has perspective, the transformed coordinates will have 3 components. Otherwise they'll have 2.

This must only be called from the constructor because GrProcessors are immutable. The processor subclass manages the lifetime of the transformations (this function only stores a pointer). The GrCoordTransform is typically a member field of the GrProcessor subclass.

A processor subclass that has multiple methods of construction should always add its coord transforms in a consistent order. The non-virtual implementation of isEqual() automatically compares transforms and will assume they line up across the two processor instances.

void GrFragmentProcessor::addTextureAccess ( const GrTextureAccess textureAccess)
overrideprotectedvirtual

Subclasses call these from their constructor to register sampler sources.

The processor subclass manages the lifetime of the objects (these functions only store pointers). The GrTextureAccess and/or GrBufferAccess instances are typically member fields of the GrProcessor subclass. These must only be called from the constructor because GrProcessors are immutable.

Reimplemented from GrProcessor.

void GrFragmentProcessor::computeInvariantOutput ( GrInvariantOutput inout) const
inline

This function is used to perform optimizations.

When called the invarientOuput param indicate whether the input components to this processor in the FS will have known values. In inout the validFlags member is a bitfield of GrColorComponentFlags. The isSingleComponent member indicates whether the input will be 1 or 4 bytes. The function updates the members of inout to indicate known values of its output. A component of the color member only has meaning if the corresponding bit in validFlags is set.

const GrCoordTransform& GrFragmentProcessor::coordTransform ( int  index) const
inline

Returns the coordinate transformation at index.

index must be valid according to numTransforms().

bool GrFragmentProcessor::isEqual ( const GrFragmentProcessor that,
bool  ignoreCoordTransforms 
) const

Returns true if this and other processor conservatively draw identically.

It can only return true when the two processor are of the same subclass (i.e. they return the same object from from getFactory()).

A return value of true from isEqual() should not be used to test whether the processor would generate the same shader code. To test for identical code generation use getGLSLProcessorKey

static sk_sp<GrFragmentProcessor> GrFragmentProcessor::MulOutputByInputAlpha ( sk_sp< GrFragmentProcessor )
static

In many instances (e.g.

SkShader::asFragmentProcessor() implementations) it is desirable to only consider the input color's alpha. However, there is a competing desire to have reusable GrFragmentProcessor subclasses that can be used in other scenarios where the entire input color is considered. This function exists to filter the input color and pass it to a FP. It does so by returning a parent FP that multiplies the passed in FPs output by the parent's input alpha. The passed in FP will not receive an input color.

static sk_sp<GrFragmentProcessor> GrFragmentProcessor::MulOutputByInputUnpremulColor ( sk_sp< GrFragmentProcessor )
static

Similar to the above but it modulates the output r,g,b of the child processor by the input rgb and then multiplies all the components by the input alpha.

This effectively modulates the child processor's premul color by a unpremul'ed input and produces a premul output

void GrFragmentProcessor::notifyRefCntIsZero ( ) const
finalprivatevirtual

This will be called when the ref cnt is zero.

The object may or may not have pending executions.

Implements GrProgramElement.

virtual void GrFragmentProcessor::onComputeInvariantOutput ( GrInvariantOutput inout) const
protectedpure virtual

Subclass implements this to support getConstantColorComponents(...).

Note: it's up to the subclass implementation to do any recursive call to compute the child procs' output invariants; computeInvariantOutput will not be recursive.

virtual GrGLSLFragmentProcessor* GrFragmentProcessor::onCreateGLSLInstance ( ) const
privatepure virtual

Returns a new instance of the appropriate GL implementation class for the given GrFragmentProcessor; caller is responsible for deleting the object.

virtual void GrFragmentProcessor::onGetGLSLProcessorKey ( const GrGLSLCaps &  caps,
GrProcessorKeyBuilder b 
) const
privatepure virtual

Implemented using GLFragmentProcessor::GenKey as described in this class's comment.

virtual bool GrFragmentProcessor::onIsEqual ( const GrFragmentProcessor ) const
privatepure virtual

Subclass implements this to support isEqual().

It will only be called if it is known that the two processors are of the same subclass (i.e. they return the same object from getFactory()). The processor subclass should not compare its coord transforms as that will be performed automatically in the non-virtual isEqual().

static sk_sp<GrFragmentProcessor> GrFragmentProcessor::OverrideInput ( sk_sp< GrFragmentProcessor ,
GrColor   
)
static

Returns a parent fragment processor that adopts the passed fragment processor as a child.

The parent will ignore its input color and instead feed the passed in color as input to the child.

int GrFragmentProcessor::registerChildProcessor ( sk_sp< GrFragmentProcessor child)
protected

FragmentProcessor subclasses call this from their constructor to register any child FragmentProcessors they have.

This must be called AFTER all texture accesses and coord transforms have been added. This is for processors whose shader code will be composed of nested processors whose output colors will be combined somehow to produce its output color. Registering these child processors will allow the ProgramBuilder to automatically handle their transformed coords and texture accesses and mangle their uniform and output color names.

static sk_sp<GrFragmentProcessor> GrFragmentProcessor::RunInSeries ( sk_sp< GrFragmentProcessor > *  ,
int  cnt 
)
static

Returns a fragment processor that runs the passed in array of fragment processors in a series.

The original input is passed to the first, the first's output is passed to the second, etc. The output of the returned processor is the output of the last processor of the series.

The array elements with be moved.

Member Data Documentation

SkSTArray<4, const GrCoordTransform*, true> GrFragmentProcessor::fCoordTransforms
private

fCoordTransforms stores the transforms of this proc, followed by all the transforms of this proc's children.

In other words, each proc stores all the transforms of its subtree as if they were collected using preorder traversal.

Example: Suppose we have frag proc A, who has two children B and D. B has a child C, and D has two children E and F. Suppose procs A, B, C, D, E, F have 1, 2, 1, 1, 3, 2 transforms respectively. The following shows what the fCoordTransforms array of each proc would contain:

                              (A)
                   [a1,b1,b2,c1,d1,e1,e2,e3,f1,f2]
                             /    \
                           /        \
                       (B)           (D)
                   [b1,b2,c1]   [d1,e1,e2,e3,f1,f2]
                     /             /    \
                   /             /        \
                 (C)          (E)          (F)
                [c1]      [e1,e2,e3]      [f1,f2]

The same goes for fTextureAccesses with textures.


The documentation for this class was generated from the following file: