Flutter Engine
The Flutter Engine
Classes | Public Types | Public Member Functions | Private Member Functions | Friends | List of all members
GrFragmentProcessor::ProgramImpl Class Referenceabstract

#include <GrFragmentProcessor.h>

Inheritance diagram for GrFragmentProcessor::ProgramImpl:
CircularRRectEffect::Impl EllipticalRRectEffect::Impl GrBicubicEffect::Impl GrPathTessellationShader::Impl GrSkSLFP::Impl GrStrokeTessellationShader::Impl GrTextureEffect::Impl

Classes

struct  EmitArgs
 
class  Iter
 

Public Types

using UniformHandle = GrGLSLUniformHandler::UniformHandle
 
using SamplerHandle = GrGLSLUniformHandler::SamplerHandle
 

Public Member Functions

 ProgramImpl ()=default
 
virtual ~ProgramImpl ()=default
 
virtual void emitCode (EmitArgs &)=0
 
void setData (const GrGLSLProgramDataManager &pdman, const GrFragmentProcessor &processor)
 
int numChildProcessors () const
 
ProgramImplchildProcessor (int index) const
 
void setFunctionName (SkString name)
 
const char * functionName () const
 
SkString invokeChild (int childIndex, EmitArgs &parentArgs, std::string_view skslCoords={})
 
SkString invokeChildWithMatrix (int childIndex, EmitArgs &parentArgs)
 
SkString invokeChild (int childIndex, const char *inputColor, EmitArgs &parentArgs, std::string_view skslCoords={})
 
SkString invokeChildWithMatrix (int childIndex, const char *inputColor, EmitArgs &parentArgs)
 
SkString invokeChild (int childIndex, const char *inputColor, const char *destColor, EmitArgs &parentArgs, std::string_view skslCoords={})
 
SkString invokeChildWithMatrix (int childIndex, const char *inputColor, const char *destColor, EmitArgs &parentArgs)
 

Private Member Functions

virtual void onSetData (const GrGLSLProgramDataManager &, const GrFragmentProcessor &)
 

Friends

class GrFragmentProcessor
 

Detailed Description

Definition at line 472 of file GrFragmentProcessor.h.

Member Typedef Documentation

◆ SamplerHandle

using GrFragmentProcessor::ProgramImpl::SamplerHandle = GrGLSLUniformHandler::SamplerHandle

Definition at line 479 of file GrFragmentProcessor.h.

◆ UniformHandle

Definition at line 478 of file GrFragmentProcessor.h.

Constructor & Destructor Documentation

◆ ProgramImpl()

GrFragmentProcessor::ProgramImpl::ProgramImpl ( )
default

◆ ~ProgramImpl()

virtual GrFragmentProcessor::ProgramImpl::~ProgramImpl ( )
virtualdefault

Member Function Documentation

◆ childProcessor()

ProgramImpl * GrFragmentProcessor::ProgramImpl::childProcessor ( int  index) const
inline

Definition at line 533 of file GrFragmentProcessor.h.

533{ return fChildProcessors[index].get(); }

◆ emitCode()

virtual void GrFragmentProcessor::ProgramImpl::emitCode ( EmitArgs )
pure virtual

◆ functionName()

const char * GrFragmentProcessor::ProgramImpl::functionName ( ) const
inline

Definition at line 540 of file GrFragmentProcessor.h.

540 {
541 SkASSERT(!fFunctionName.isEmpty());
542 return fFunctionName.c_str();
543 }
#define SkASSERT(cond)
Definition: SkAssert.h:116
bool isEmpty() const
Definition: SkString.h:130
const char * c_str() const
Definition: SkString.h:133

◆ invokeChild() [1/3]

SkString ProgramImpl::invokeChild ( int  childIndex,
const char *  inputColor,
const char *  destColor,
EmitArgs parentArgs,
std::string_view  skslCoords = {} 
)

Invokes a child proc in its own scope. Pass in the parent's EmitArgs and invokeChild will automatically extract the coords and samplers of that child and pass them on to the child's emitCode(). Also, any uniforms or functions emitted by the child will have their names mangled to prevent redefinitions. The returned string contains the output color (as a call to the child's helper function). It is legal to pass nullptr as inputColor, since all fragment processors are required to work without an input color.

When skslCoords is empty, the child is invoked at the sample coordinates from parentArgs. When skslCoords is not empty, is must be an SkSL expression that evaluates to a float2. That expression is passed to the child's processor function as the "_coords" argument.

Definition at line 856 of file GrFragmentProcessor.cpp.

860 {
861 SkASSERT(childIndex >= 0);
862
863 if (!inputColor) {
864 inputColor = args.fInputColor;
865 }
866
867 const GrFragmentProcessor* childProc = args.fFp.childProcessor(childIndex);
868 if (!childProc) {
869 // If no child processor is provided, return the input color as-is.
870 return SkString(inputColor);
871 }
872
873 auto invocation = SkStringPrintf("%s(%s", this->childProcessor(childIndex)->functionName(),
874 inputColor);
875
876 if (childProc->isBlendFunction()) {
877 if (!destColor) {
878 destColor = args.fFp.isBlendFunction() ? args.fDestColor : "half4(1)";
879 }
880 invocation.appendf(", %s", destColor);
881 }
882
883 // Assert that the child has no sample matrix. A uniform matrix sample call would go through
884 // invokeChildWithMatrix, not here.
885 SkASSERT(!childProc->sampleUsage().isUniformMatrix());
886
887 if (args.fFragBuilder->getProgramBuilder()->fragmentProcessorHasCoordsParam(childProc)) {
888 SkASSERT(!childProc->sampleUsage().isFragCoord() || skslCoords == "sk_FragCoord.xy");
889 // The child's function takes a half4 color and a float2 coordinate
890 if (!skslCoords.empty()) {
891 invocation.appendf(", %.*s", (int)skslCoords.size(), skslCoords.data());
892 } else {
893 invocation.appendf(", %s", args.fSampleCoord);
894 }
895 }
896
897 invocation.append(")");
898 return invocation;
899}
SK_API SkString SkStringPrintf(const char *format,...) SK_PRINTF_LIKE(1
Creates a new string and writes into it using a printf()-style format.
ProgramImpl * childProcessor(int index) const
const SkSL::SampleUsage & sampleUsage() const
bool isUniformMatrix() const
bool isFragCoord() const
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args

◆ invokeChild() [2/3]

SkString GrFragmentProcessor::ProgramImpl::invokeChild ( int  childIndex,
const char *  inputColor,
EmitArgs parentArgs,
std::string_view  skslCoords = {} 
)
inline

Definition at line 564 of file GrFragmentProcessor.h.

567 {}) {
568 return this->invokeChild(childIndex,
569 inputColor,
570 /*destColor=*/nullptr,
571 parentArgs,
572 skslCoords);
573 }
SkString invokeChild(int childIndex, EmitArgs &parentArgs, std::string_view skslCoords={})

◆ invokeChild() [3/3]

SkString GrFragmentProcessor::ProgramImpl::invokeChild ( int  childIndex,
EmitArgs parentArgs,
std::string_view  skslCoords = {} 
)
inline

Definition at line 546 of file GrFragmentProcessor.h.

548 {}) {
549 return this->invokeChild(childIndex,
550 /*inputColor=*/nullptr,
551 /*destColor=*/nullptr,
552 parentArgs,
553 skslCoords);
554 }

◆ invokeChildWithMatrix() [1/3]

SkString ProgramImpl::invokeChildWithMatrix ( int  childIndex,
const char *  inputColor,
const char *  destColor,
EmitArgs parentArgs 
)

As invokeChild, but transforms the coordinates according to the matrix expression attached to the child's SampleUsage object. This is only valid if the child is sampled with a const-uniform matrix.

Definition at line 901 of file GrFragmentProcessor.cpp.

904 {
905 SkASSERT(childIndex >= 0);
906
907 if (!inputColor) {
908 inputColor = args.fInputColor;
909 }
910
911 const GrFragmentProcessor* childProc = args.fFp.childProcessor(childIndex);
912 if (!childProc) {
913 // If no child processor is provided, return the input color as-is.
914 return SkString(inputColor);
915 }
916
917 SkASSERT(childProc->sampleUsage().isUniformMatrix());
918
919 // Every uniform matrix has the same (initial) name. Resolve that into the mangled name:
920 GrShaderVar uniform = args.fUniformHandler->getUniformMapping(
923 const SkString& matrixName(uniform.getName());
924
925 auto invocation = SkStringPrintf("%s(%s", this->childProcessor(childIndex)->functionName(),
926 inputColor);
927
928 if (childProc->isBlendFunction()) {
929 if (!destColor) {
930 destColor = args.fFp.isBlendFunction() ? args.fDestColor : "half4(1)";
931 }
932 invocation.appendf(", %s", destColor);
933 }
934
935 // Produce a string containing the call to the helper function. We have a uniform variable
936 // containing our transform (matrixName). If the parent coords were produced by uniform
937 // transforms, then the entire expression (matrixName * coords) is lifted to a vertex shader
938 // and is stored in a varying. In that case, childProc will not be sampled explicitly, so its
939 // function signature will not take in coords.
940 //
941 // In all other cases, we need to insert sksl to compute matrix * parent coords and then invoke
942 // the function.
943 if (args.fFragBuilder->getProgramBuilder()->fragmentProcessorHasCoordsParam(childProc)) {
944 // Only check perspective for this specific matrix transform, not the aggregate FP property.
945 // Any parent perspective will have already been applied when evaluated in the FS.
946 if (childProc->sampleUsage().hasPerspective()) {
947 invocation.appendf(", proj((%s) * %s.xy1)", matrixName.c_str(), args.fSampleCoord);
948 } else if (args.fShaderCaps->fNonsquareMatrixSupport) {
949 invocation.appendf(", float3x2(%s) * %s.xy1", matrixName.c_str(), args.fSampleCoord);
950 } else {
951 invocation.appendf(", ((%s) * %s.xy1).xy", matrixName.c_str(), args.fSampleCoord);
952 }
953 }
954
955 invocation.append(")");
956 return invocation;
957}
SkSLType getType() const
Definition: GrShaderVar.h:97
const SkString & getName() const
Definition: GrShaderVar.h:91
static const char * MatrixUniformName()
bool hasPerspective() const

◆ invokeChildWithMatrix() [2/3]

SkString GrFragmentProcessor::ProgramImpl::invokeChildWithMatrix ( int  childIndex,
const char *  inputColor,
EmitArgs parentArgs 
)
inline

Definition at line 575 of file GrFragmentProcessor.h.

577 {
578 return this->invokeChildWithMatrix(childIndex,
579 inputColor,
580 /*destColor=*/nullptr,
581 parentArgs);
582 }
SkString invokeChildWithMatrix(int childIndex, EmitArgs &parentArgs)

◆ invokeChildWithMatrix() [3/3]

SkString GrFragmentProcessor::ProgramImpl::invokeChildWithMatrix ( int  childIndex,
EmitArgs parentArgs 
)
inline

Definition at line 556 of file GrFragmentProcessor.h.

556 {
557 return this->invokeChildWithMatrix(childIndex,
558 /*inputColor=*/nullptr,
559 /*destColor=*/nullptr,
560 parentArgs);
561 }

◆ numChildProcessors()

int GrFragmentProcessor::ProgramImpl::numChildProcessors ( ) const
inline

Definition at line 531 of file GrFragmentProcessor.h.

531{ return fChildProcessors.size(); }

◆ onSetData()

virtual void GrFragmentProcessor::ProgramImpl::onSetData ( const GrGLSLProgramDataManager ,
const GrFragmentProcessor  
)
inlineprivatevirtual

A ProgramImpl instance can be reused with any GrFragmentProcessor that produces the same the same key; this function reads data from a GrFragmentProcessor and uploads any uniform variables required by the shaders created in emitCode(). The GrFragmentProcessor parameter is guaranteed to be of the same type that created this ProgramImpl and to have an identical key as the one that created this ProgramImpl.

Definition at line 643 of file GrFragmentProcessor.h.

643{}

◆ setData()

void ProgramImpl::setData ( const GrGLSLProgramDataManager pdman,
const GrFragmentProcessor processor 
)

Definition at line 851 of file GrFragmentProcessor.cpp.

852 {
853 this->onSetData(pdman, processor);
854}
virtual void onSetData(const GrGLSLProgramDataManager &, const GrFragmentProcessor &)

◆ setFunctionName()

void GrFragmentProcessor::ProgramImpl::setFunctionName ( SkString  name)
inline

Definition at line 535 of file GrFragmentProcessor.h.

535 {
536 SkASSERT(fFunctionName.isEmpty());
537 fFunctionName = std::move(name);
538 }
virtual const char * name() const =0

Friends And Related Function Documentation

◆ GrFragmentProcessor

friend class GrFragmentProcessor
friend

Definition at line 650 of file GrFragmentProcessor.h.


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