Skia
2DGraphicsLibrary
 All Classes Namespaces 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< GrProcessor >

Classes

class  FPItemIter
 Iterates over all the Ts owned by a GrFragmentProcessor and its children or over all the Ts owned by the forest of GrFragmentProcessors in a GrPipeline. More...
 
class  Iter
 Pre-order traversal of a FP hierarchy, or of the forest of FPs in a GrPipeline. More...
 

Public Types

using CoordTransformIter = FPItemIter< GrCoordTransform, GrFragmentProcessor,&GrFragmentProcessor::numCoordTransforms,&GrFragmentProcessor::coordTransform >
 
using TextureAccessIter = FPItemIter< TextureSampler, GrProcessor,&GrProcessor::numTextureSamplers,&GrProcessor::textureSampler >
 
- Public Types inherited from GrProcessor
enum  RequiredFeatures { kNone_RequiredFeatures = 0, kSampleLocations_RequiredFeature = 1 << 0 }
 Platform specific built-in features that a processor can request for the fragment shader.
 

Public Member Functions

GrGLSLFragmentProcessor * createGLSLInstance () const
 
void getGLSLProcessorKey (const GrShaderCaps &caps, GrProcessorKeyBuilder *b) const
 
int numCoordTransforms () const
 
const GrCoordTransformcoordTransform (int index) const
 Returns the coordinate transformation at index. More...
 
const SkTArray< const
GrCoordTransform *, true > & 
coordTransforms () 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 compatibleWithCoverageAsAlpha () const
 A GrDrawOp may premultiply its antialiasing coverage into its GrGeometryProcessor's color output under the following scenario: More...
 
bool preservesOpaqueInput () const
 If this is true then all opaque input colors to the processor produce opaque output colors.
 
bool hasConstantOutputForConstantInput (GrColor4f inputColor, GrColor4f *outputColor) const
 Tests whether given a constant input color the processor produces a constant output color (for all fragments). More...
 
bool hasConstantOutputForConstantInput () const
 
bool isEqual (const GrFragmentProcessor &that) const
 Returns true if this and other processor conservatively draw identically. 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
 Human-readable dump of all information.
 
int numTextureSamplers () const
 
const TextureSamplertextureSampler (int index) const
 Returns the access pattern for the texture at index. More...
 
int numBuffers () const
 
const BufferAccessbufferAccess (int index) const
 Returns the access pattern for the buffer at index. More...
 
int numImageStorages () const
 
const ImageStorageAccessimageStorageAccess (int index) const
 Returns the access object for the image 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< GrProcessor >
void ref () const
 
void unref () const
 
void validate () const
 

Static Public Member Functions

static sk_sp< GrFragmentProcessorMulOutputByInputAlpha (sk_sp< GrFragmentProcessor >)
 In many instances (e.g. More...
 
static sk_sp< GrFragmentProcessorMakeInputPremulAndMulByOutput (sk_sp< GrFragmentProcessor >)
 This assumes that the input color to the returned processor will be unpremul and that the passed processor (which becomes the returned processor's child) produces a premul output. More...
 
static sk_sp< GrFragmentProcessorOverrideInput (sk_sp< GrFragmentProcessor >, GrColor4f)
 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< GrFragmentProcessorPremulOutput (sk_sp< GrFragmentProcessor >)
 Returns a fragment processor that calls the passed in fragment processor, and then premuls the output.
 
static sk_sp< GrFragmentProcessorUnpremulOutput (sk_sp< GrFragmentProcessor >)
 Returns a fragment processor that calls the passed in fragment processor, and then unpremuls the output.
 
static sk_sp< GrFragmentProcessorSwizzleOutput (sk_sp< GrFragmentProcessor >, const GrSwizzle &)
 Returns a fragment processor that calls the passed in fragment processor, and then swizzles the output.
 
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 Types

enum  OptimizationFlags : uint32_t {
  kNone_OptimizationFlags, kCompatibleWithCoverageAsAlpha_OptimizationFlag = 0x1, kPreservesOpaqueInput_OptimizationFlag = 0x2, kConstantOutputForConstantInput_OptimizationFlag = 0x4,
  kAll_OptimizationFlags
}
 

Protected Member Functions

 GrFragmentProcessor (OptimizationFlags optimizationFlags)
 
OptimizationFlags optimizationFlags () const
 
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...
 
void setWillUseDistanceVectorField ()
 Sub-classes should call this in their constructors if they need access to a distance vector field to the nearest edge.
 
- Protected Member Functions inherited from GrProcessor
void addTextureSampler (const TextureSampler *)
 Subclasses call these from their constructor to register sampler/image sources. More...
 
void addBufferAccess (const BufferAccess *)
 
void addImageStorageAccess (const ImageStorageAccess *)
 
bool hasSameSamplersAndAccesses (const GrProcessor &) const
 
void setWillUseSampleLocations ()
 If the prcoessor will generate code that uses platform specific built-in features, then it must call these methods from its constructor. More...
 
void combineRequiredFeatures (const GrProcessor &other)
 
template<typename PROC_SUBCLASS >
void initClassID ()
 
- Protected Member Functions inherited from GrProgramElement< GrProcessor >
void addPendingExecution () const
 
void completedExecution () const
 

Static Protected Member Functions

static GrColor4f ConstantOutputForConstantInput (const GrFragmentProcessor &fp, GrColor4f input)
 This allows one subclass to access another subclass's implementation of constantOutputForConstantInput. More...
 

Private Types

enum  PrivateFlags { kFirstPrivateFlag = kAll_OptimizationFlags + 1, kUsesLocalCoords_Flag = kFirstPrivateFlag, kUsesDistanceVectorField_Flag = kFirstPrivateFlag << 1 }
 
typedef GrProcessor INHERITED
 

Private Member Functions

void notifyRefCntIsZero () const final
 This will be called when the ref cnt is zero. More...
 
virtual GrColor4f constantOutputForConstantInput (GrColor4f) const
 
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 GrShaderCaps &, GrProcessorKeyBuilder *) 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

uint32_t fFlags = 0
 
SkSTArray< 4, const
GrCoordTransform *, true > 
fCoordTransforms
 
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.
 

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.

bool GrFragmentProcessor::compatibleWithCoverageAsAlpha ( ) const
inline

A GrDrawOp may premultiply its antialiasing coverage into its GrGeometryProcessor's color output under the following scenario:

  • all the color fragment processors report true to this query,
  • all the coverage fragment processors report true to this query,
  • the blend mode arithmetic allows for it it. To be compatible a fragment processor's output must be a modulation of its input color or alpha with a computed premultiplied color or alpha that is in 0..1 range. The computed color or alpha that is modulated against the input cannot depend on the input's alpha. The computed value cannot depend on the input's color channels unless it unpremultiplies the input color channels by the input alpha.
static GrColor4f GrFragmentProcessor::ConstantOutputForConstantInput ( const GrFragmentProcessor fp,
GrColor4f  input 
)
inlinestaticprotected

This allows one subclass to access another subclass's implementation of constantOutputForConstantInput.

It must only be called when hasConstantOutputForConstantInput() is known to be true.

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

Returns the coordinate transformation at index.

index must be valid according to numTransforms().

bool GrFragmentProcessor::hasConstantOutputForConstantInput ( GrColor4f  inputColor,
GrColor4f outputColor 
) const
inline

Tests whether given a constant input color the processor produces a constant output color (for all fragments).

If true outputColor will contain the constant color produces for inputColor.

bool GrFragmentProcessor::isEqual ( const GrFragmentProcessor that) 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::MakeInputPremulAndMulByOutput ( sk_sp< GrFragmentProcessor )
static

This assumes that the input color to the returned processor will be unpremul and that the passed processor (which becomes the returned processor's child) produces a premul output.

The result of the returned processor is a premul of its input color modulated by the child processor's premul output.

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.

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< GrProcessor >.

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 GrShaderCaps ,
GrProcessorKeyBuilder  
) 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 ,
GrColor4f   
)
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.


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