8#ifndef GrFragmentProcessor_DEFINED
9#define GrFragmentProcessor_DEFINED
39using GrFPResult = std::tuple<
bool , std::unique_ptr<GrFragmentProcessor>>;
64 std::unique_ptr<GrFragmentProcessor> child);
71 std::unique_ptr<GrFragmentProcessor> child);
78 static std::unique_ptr<GrFragmentProcessor>
ModulateRGBA(
86 static std::unique_ptr<GrFragmentProcessor>
OverrideInput(std::unique_ptr<GrFragmentProcessor>,
95 std::unique_ptr<GrFragmentProcessor>);
101 static std::unique_ptr<GrFragmentProcessor>
DestColor();
107 static std::unique_ptr<GrFragmentProcessor>
SwizzleOutput(std::unique_ptr<GrFragmentProcessor>,
114 static std::unique_ptr<GrFragmentProcessor>
ClampOutput(std::unique_ptr<GrFragmentProcessor>);
121 static std::unique_ptr<GrFragmentProcessor>
Compose(std::unique_ptr<GrFragmentProcessor>
f,
122 std::unique_ptr<GrFragmentProcessor> g);
128 static std::unique_ptr<GrFragmentProcessor>
ColorMatrix(
129 std::unique_ptr<GrFragmentProcessor> child,
139 static std::unique_ptr<GrFragmentProcessor>
SurfaceColor();
145 static std::unique_ptr<GrFragmentProcessor>
DeviceSpace(std::unique_ptr<GrFragmentProcessor>);
152 static std::unique_ptr<GrFragmentProcessor>
Rect(std::unique_ptr<GrFragmentProcessor>,
171 static std::unique_ptr<GrFragmentProcessor>
HighPrecision(std::unique_ptr<GrFragmentProcessor>);
177 virtual std::unique_ptr<GrFragmentProcessor>
clone()
const = 0;
186 for (
const auto& child : fChildProcessors) {
188 child->addToKey(caps,
b);
198 return fChildProcessors[index].get();
204 bool willReadDstColor()
const {
229 kUsesSampleCoordsIndirectly_Flag));
278 fFlags &= ~kConstantOutputForConstantInput_OptimizationFlag;
300#if defined(GR_TEST_UTILS)
373 SkASSERT(
fp->hasConstantOutputForConstantInput());
374 return fp->constantOutputForConstantInput(input);
391 void registerChild(std::unique_ptr<GrFragmentProcessor> child,
403 fFlags |= kUsesSampleCoordsDirectly_Flag;
409 fFlags |= kWillReadDstColor_Flag;
415 fFlags |= kIsBlendFunction_Flag;
425 SK_ABORT(
"Subclass must override this if advertising this optimization.");
447 kUsesSampleCoordsIndirectly_Flag = kFirstPrivateFlag,
453 kUsesSampleCoordsDirectly_Flag = kFirstPrivateFlag << 1,
456 kIsBlendFunction_Flag = kFirstPrivateFlag << 2,
459 kWillReadDstColor_Flag = kFirstPrivateFlag << 3,
506 const char* inputColor,
507 const char* destColor,
508 const char* sampleCoord)
513 ,
fInputColor(inputColor ? inputColor :
"half4(1.0)")
537 fFunctionName = std::move(
name);
542 return fFunctionName.
c_str();
548 std::string_view skslCoords = {}) {
565 const char* inputColor,
567 std::string_view skslCoords = {}) {
576 const char* inputColor,
596 const char* inputColor,
597 const char* destColor,
598 EmitArgs& parentArgs,
599 std::string_view skslCoords = {});
607 const char* inputColor,
608 const char* destColor,
609 EmitArgs& parentArgs);
619 Iter(std::unique_ptr<ProgramImpl> fps[],
int cnt);
625 explicit operator bool()
const {
return !fFPStack.empty(); }
658 return {
false, std::move(
fp)};
662 return {
true, std::move(
fp)};
666 return {
true, std::move(
fp)};
static GrFPResult GrFPNullableSuccess(std::unique_ptr< GrFragmentProcessor > fp)
static GrFPResult GrFPSuccess(std::unique_ptr< GrFragmentProcessor > fp)
std::tuple< bool, std::unique_ptr< GrFragmentProcessor > > GrFPResult
static GrFPResult GrFPFailure(std::unique_ptr< GrFragmentProcessor > fp)
std::function< void(GrSurfaceProxy *, skgpu::Mipmapped)> GrVisitProxyFunc
@ kOpaque_SkAlphaType
pixel is opaque
#define SK_ABORT(message,...)
#define SK_MAKE_BITFIELD_OPS(X)
#define SK_DECL_BITFIELD_OPS_FRIENDS(X)
#define INHERITED(method,...)
static constexpr bool SkToBool(const T &x)
static SkScalar center(float pos0, float pos1)
Iter(std::unique_ptr< ProgramImpl > fps[], int cnt)
ProgramImpl & operator*() const
ProgramImpl * operator->() const
Iter & operator=(const Iter &)=delete
Iter(const Iter &)=delete
SkString invokeChildWithMatrix(int childIndex, EmitArgs &parentArgs)
GrGLSLUniformHandler::SamplerHandle SamplerHandle
SkString invokeChildWithMatrix(int childIndex, const char *inputColor, EmitArgs &parentArgs)
const char * functionName() const
SkString invokeChild(int childIndex, const char *inputColor, EmitArgs &parentArgs, std::string_view skslCoords={})
void setData(const GrGLSLProgramDataManager &pdman, const GrFragmentProcessor &processor)
void setFunctionName(SkString name)
virtual void onSetData(const GrGLSLProgramDataManager &, const GrFragmentProcessor &)
GrGLSLUniformHandler::UniformHandle UniformHandle
SkString invokeChild(int childIndex, EmitArgs &parentArgs, std::string_view skslCoords={})
int numChildProcessors() const
virtual void emitCode(EmitArgs &)=0
ProgramImpl * childProcessor(int index) const
virtual ~ProgramImpl()=default
void cloneAndRegisterAllChildProcessors(const GrFragmentProcessor &src)
bool usesSampleCoords() const
bool usesSampleCoordsDirectly() const
virtual SkPMColor4f constantOutputForConstantInput(const SkPMColor4f &) const
static std::unique_ptr< GrFragmentProcessor > SwizzleOutput(std::unique_ptr< GrFragmentProcessor >, const skgpu::Swizzle &)
void clearConstantOutputForConstantInputFlag()
void setWillReadDstColor()
static std::unique_ptr< GrFragmentProcessor > ClampOutput(std::unique_ptr< GrFragmentProcessor >)
bool preservesOpaqueInput() const
void addToKey(const GrShaderCaps &caps, skgpu::KeyBuilder *b) const
static GrFPResult Circle(std::unique_ptr< GrFragmentProcessor >, GrClipEdgeType, SkPoint center, float radius)
GrFragmentProcessor(ClassID classID, OptimizationFlags optimizationFlags)
virtual std::unique_ptr< GrFragmentProcessor > clone() const =0
int numNonNullChildProcessors() const
static OptimizationFlags ProcessorOptimizationFlags(const GrFragmentProcessor *fp)
static std::unique_ptr< GrFragmentProcessor > MakeColor(SkPMColor4f color)
std::unique_ptr< ProgramImpl > makeProgramImpl() const
bool hasConstantOutputForConstantInput(SkPMColor4f inputColor, SkPMColor4f *outputColor) const
int numChildProcessors() const
void mergeOptimizationFlags(OptimizationFlags flags)
static std::unique_ptr< GrFragmentProcessor > ModulateRGBA(std::unique_ptr< GrFragmentProcessor > child, const SkPMColor4f &color)
static std::unique_ptr< GrFragmentProcessor > DeviceSpace(std::unique_ptr< GrFragmentProcessor >)
static OptimizationFlags ModulateForClampedSamplerOptFlags(SkAlphaType alphaType)
SkDEBUGCODE(bool isInstantiated() const ;) bool willReadDstColor() const
static std::unique_ptr< GrFragmentProcessor > OverrideInput(std::unique_ptr< GrFragmentProcessor >, const SkPMColor4f &)
const GrFragmentProcessor * parent() const
static std::unique_ptr< GrFragmentProcessor > SurfaceColor()
GrTextureEffect * asTextureEffect()
bool isEqual(const GrFragmentProcessor &that) const
GrFragmentProcessor * childProcessor(int index)
void visitProxies(const GrVisitProxyFunc &) const
bool isBlendFunction() const
void visitWithImpls(const std::function< void(const GrFragmentProcessor &, ProgramImpl &)> &, ProgramImpl &) const
GrFragmentProcessor(const GrFragmentProcessor &src)
void registerChild(std::unique_ptr< GrFragmentProcessor > child, SkSL::SampleUsage sampleUsage=SkSL::SampleUsage::PassThrough())
static std::unique_ptr< GrFragmentProcessor > Rect(std::unique_ptr< GrFragmentProcessor >, GrClipEdgeType, SkRect)
static std::unique_ptr< GrFragmentProcessor > ApplyPaintAlpha(std::unique_ptr< GrFragmentProcessor > child)
OptimizationFlags optimizationFlags() const
static std::unique_ptr< GrFragmentProcessor > MulInputByChildAlpha(std::unique_ptr< GrFragmentProcessor > child)
void setIsBlendFunction()
const SkSL::SampleUsage & sampleUsage() const
virtual void onAddToKey(const GrShaderCaps &, skgpu::KeyBuilder *) const =0
bool compatibleWithCoverageAsAlpha() const
static std::unique_ptr< GrFragmentProcessor > HighPrecision(std::unique_ptr< GrFragmentProcessor >)
static std::unique_ptr< GrFragmentProcessor > DestColor()
static std::unique_ptr< GrFragmentProcessor > ColorMatrix(std::unique_ptr< GrFragmentProcessor > child, const float matrix[20], bool unpremulInput, bool clampRGBOutput, bool premulOutput)
void setUsesSampleCoordsDirectly()
@ kNone_OptimizationFlags
@ kPreservesOpaqueInput_OptimizationFlag
@ kCompatibleWithCoverageAsAlpha_OptimizationFlag
@ kConstantOutputForConstantInput_OptimizationFlag
static std::unique_ptr< GrFragmentProcessor > DisableCoverageAsAlpha(std::unique_ptr< GrFragmentProcessor >)
static std::unique_ptr< GrFragmentProcessor > Compose(std::unique_ptr< GrFragmentProcessor > f, std::unique_ptr< GrFragmentProcessor > g)
bool hasConstantOutputForConstantInput() const
const GrFragmentProcessor * childProcessor(int index) const
static SkPMColor4f ConstantOutputForConstantInput(const GrFragmentProcessor *fp, const SkPMColor4f &input)
virtual bool onIsEqual(const GrFragmentProcessor &) const =0
static GrFPResult Ellipse(std::unique_ptr< GrFragmentProcessor >, GrClipEdgeType, SkPoint center, SkPoint radii, const GrShaderCaps &)
void visitTextureEffects(const std::function< void(const GrTextureEffect &)> &) const
static OptimizationFlags ModulateForSamplerOptFlags(SkAlphaType alphaType, bool samplingDecal)
virtual std::unique_ptr< ProgramImpl > onMakeProgramImpl() const =0
GrProcessor(ClassID classID)
virtual const char * name() const =0
static SampleUsage PassThrough()
const char * c_str() const
FlutterSemanticsFlag flags
Dart_NativeFunction function
unsigned useCenter Optional< SkMatrix > matrix
const GrFragmentProcessor & fFp
const GrShaderCaps * fShaderCaps
const char * fSampleCoord
GrGLSLUniformHandler * fUniformHandler
GrGLSLFPFragmentBuilder * fFragBuilder
EmitArgs(GrGLSLFPFragmentBuilder *fragBuilder, GrGLSLUniformHandler *uniformHandler, const GrShaderCaps *caps, const GrFragmentProcessor &fp, const char *inputColor, const char *destColor, const char *sampleCoord)