Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Friends | List of all members
GrSkSLFP Class Reference

#include <GrSkSLFP.h>

Inheritance diagram for GrSkSLFP:
GrFragmentProcessor GrProcessor

Classes

struct  GrIgnoreOptFlags
 
struct  GrOptionalUniform
 
struct  GrSpecializedUniform
 
class  Impl
 

Public Types

enum class  OptFlags : uint32_t { kNone = kNone_OptimizationFlags , kCompatibleWithCoverageAsAlpha = kCompatibleWithCoverageAsAlpha_OptimizationFlag , kPreservesOpaqueInput = kPreservesOpaqueInput_OptimizationFlag , kAll = kCompatibleWithCoverageAsAlpha | kPreservesOpaqueInput }
 
- Public Types inherited from GrProcessor
enum  ClassID {
  kNull_ClassID , kAttributeTestProcessor_ClassID , kBigKeyProcessor_ClassID , kBlendFragmentProcessor_ClassID ,
  kBlockInputFragmentProcessor_ClassID , kButtCapStrokedCircleGeometryProcessor_ClassID , kCircleGeometryProcessor_ClassID , kCircularRRectEffect_ClassID ,
  kClockwiseTestProcessor_ClassID , kColorTableEffect_ClassID , kCoverageSetOpXP_ClassID , kCustomXP_ClassID ,
  kDashingCircleEffect_ClassID , kDashingLineEffect_ClassID , kDefaultGeoProc_ClassID , kDeviceSpace_ClassID ,
  kDIEllipseGeometryProcessor_ClassID , kDisableColorXP_ClassID , kDrawAtlasPathShader_ClassID , kEllipseGeometryProcessor_ClassID ,
  kEllipticalRRectEffect_ClassID , kFwidthSquircleTestProcessor_ClassID , kGP_ClassID , kGrBicubicEffect_ClassID ,
  kGrBitmapTextGeoProc_ClassID , kGrColorSpaceXformEffect_ClassID , kGrConicEffect_ClassID , kGrConvexPolyEffect_ClassID ,
  kGrDiffuseLightingEffect_ClassID , kGrDisplacementMapEffect_ClassID , kGrDistanceFieldA8TextGeoProc_ClassID , kGrDistanceFieldLCDTextGeoProc_ClassID ,
  kGrDistanceFieldPathGeoProc_ClassID , kGrFillRRectOp_Processor_ClassID , kGrGaussianConvolutionFragmentProcessor_ClassID , kGrMatrixConvolutionEffect_ClassID ,
  kGrMatrixEffect_ClassID , kGrMeshTestProcessor_ClassID , kGrMorphologyEffect_ClassID , kGrPerlinNoise2Effect_ClassID ,
  kGrPipelineDynamicStateTestProcessor_ClassID , kGrQuadEffect_ClassID , kGrRRectShadowGeoProc_ClassID , kGrSkSLFP_ClassID ,
  kGrSpecularLightingEffect_ClassID , kGrTextureEffect_ClassID , kGrUnrolledBinaryGradientColorizer_ClassID , kGrYUVtoRGBEffect_ClassID ,
  kHighPrecisionFragmentProcessor_ClassID , kLatticeGP_ClassID , kPDLCDXferProcessor_ClassID , kPorterDuffXferProcessor_ClassID ,
  kPremulFragmentProcessor_ClassID , kQuadEdgeEffect_ClassID , kQuadPerEdgeAAGeometryProcessor_ClassID , kSeriesFragmentProcessor_ClassID ,
  kShaderPDXferProcessor_ClassID , kSurfaceColorProcessor_ClassID , kSwizzleFragmentProcessor_ClassID , kTessellate_BoundingBoxShader_ClassID ,
  kTessellate_GrModulateAtlasCoverageEffect_ClassID , kTessellate_GrStrokeTessellationShader_ClassID , kTessellate_HullShader_ClassID , kTessellate_MiddleOutShader_ClassID ,
  kTessellate_SimpleTriangleShader_ClassID , kTessellationTestTriShader_ClassID , kTestFP_ClassID , kTestRectOp_ClassID ,
  kVertexColorSpaceBenchGP_ClassID , kVerticesGP_ClassID
}
 

Public Member Functions

const char * name () const override
 
std::unique_ptr< GrFragmentProcessorclone () const override
 
- Public Member Functions inherited from GrFragmentProcessor
const GrFragmentProcessorparent () const
 
std::unique_ptr< ProgramImplmakeProgramImpl () const
 
void addToKey (const GrShaderCaps &caps, skgpu::KeyBuilder *b) const
 
int numChildProcessors () const
 
int numNonNullChildProcessors () const
 
GrFragmentProcessorchildProcessor (int index)
 
const GrFragmentProcessorchildProcessor (int index) const
 
 SkDEBUGCODE (bool isInstantiated() const ;) bool willReadDstColor() const
 
bool isBlendFunction () const
 
bool usesSampleCoordsDirectly () const
 
bool usesSampleCoords () const
 
const SkSL::SampleUsagesampleUsage () const
 
bool compatibleWithCoverageAsAlpha () const
 
bool preservesOpaqueInput () const
 
bool hasConstantOutputForConstantInput (SkPMColor4f inputColor, SkPMColor4f *outputColor) const
 
bool hasConstantOutputForConstantInput () const
 
void clearConstantOutputForConstantInputFlag ()
 
bool isEqual (const GrFragmentProcessor &that) const
 
void visitProxies (const GrVisitProxyFunc &) const
 
void visitTextureEffects (const std::function< void(const GrTextureEffect &)> &) const
 
void visitWithImpls (const std::function< void(const GrFragmentProcessor &, ProgramImpl &)> &, ProgramImpl &) const
 
GrTextureEffectasTextureEffect ()
 
const GrTextureEffectasTextureEffect () const
 
- Public Member Functions inherited from GrProcessor
virtual ~GrProcessor ()=default
 
void * operator new (size_t size)
 
void * operator new (size_t object_size, size_t footer_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 Tcast () const
 
ClassID classID () const
 

Static Public Member Functions

template<typename T >
static GrSpecializedUniform< TSpecialize (const T &value)
 
template<typename T >
static GrSpecializedUniform< TSpecializeIf (bool condition, const T &value)
 
template<typename T >
static GrOptionalUniform< TWhen (bool condition, const T &value)
 
static GrIgnoreOptFlags IgnoreOptFlags (std::unique_ptr< GrFragmentProcessor > child)
 
static std::unique_ptr< GrSkSLFPMakeWithData (sk_sp< SkRuntimeEffect > effect, const char *name, sk_sp< SkColorSpace > dstColorSpace, std::unique_ptr< GrFragmentProcessor > inputFP, std::unique_ptr< GrFragmentProcessor > destColorFP, const sk_sp< const SkData > &uniforms, SkSpan< std::unique_ptr< GrFragmentProcessor > > childFPs)
 
template<typename... Args>
static std::unique_ptr< GrSkSLFPMake (const SkRuntimeEffect *effect, const char *name, std::unique_ptr< GrFragmentProcessor > inputFP, OptFlags optFlags, Args &&... args)
 
- Static Public Member Functions inherited from GrFragmentProcessor
static std::unique_ptr< GrFragmentProcessorMakeColor (SkPMColor4f color)
 
static std::unique_ptr< GrFragmentProcessorMulInputByChildAlpha (std::unique_ptr< GrFragmentProcessor > child)
 
static std::unique_ptr< GrFragmentProcessorApplyPaintAlpha (std::unique_ptr< GrFragmentProcessor > child)
 
static std::unique_ptr< GrFragmentProcessorModulateRGBA (std::unique_ptr< GrFragmentProcessor > child, const SkPMColor4f &color)
 
static std::unique_ptr< GrFragmentProcessorOverrideInput (std::unique_ptr< GrFragmentProcessor >, const SkPMColor4f &)
 
static std::unique_ptr< GrFragmentProcessorDisableCoverageAsAlpha (std::unique_ptr< GrFragmentProcessor >)
 
static std::unique_ptr< GrFragmentProcessorDestColor ()
 
static std::unique_ptr< GrFragmentProcessorSwizzleOutput (std::unique_ptr< GrFragmentProcessor >, const skgpu::Swizzle &)
 
static std::unique_ptr< GrFragmentProcessorClampOutput (std::unique_ptr< GrFragmentProcessor >)
 
static std::unique_ptr< GrFragmentProcessorCompose (std::unique_ptr< GrFragmentProcessor > f, std::unique_ptr< GrFragmentProcessor > g)
 
static std::unique_ptr< GrFragmentProcessorColorMatrix (std::unique_ptr< GrFragmentProcessor > child, const float matrix[20], bool unpremulInput, bool clampRGBOutput, bool premulOutput)
 
static std::unique_ptr< GrFragmentProcessorSurfaceColor ()
 
static std::unique_ptr< GrFragmentProcessorDeviceSpace (std::unique_ptr< GrFragmentProcessor >)
 
static std::unique_ptr< GrFragmentProcessorRect (std::unique_ptr< GrFragmentProcessor >, GrClipEdgeType, SkRect)
 
static GrFPResult Circle (std::unique_ptr< GrFragmentProcessor >, GrClipEdgeType, SkPoint center, float radius)
 
static GrFPResult Ellipse (std::unique_ptr< GrFragmentProcessor >, GrClipEdgeType, SkPoint center, SkPoint radii, const GrShaderCaps &)
 
static std::unique_ptr< GrFragmentProcessorHighPrecision (std::unique_ptr< GrFragmentProcessor >)
 

Private Member Functions

std::unique_ptr< ProgramImplonMakeProgramImpl () const override
 
void onAddToKey (const GrShaderCaps &, skgpu::KeyBuilder *) const override
 
bool onIsEqual (const GrFragmentProcessor &) const override
 
SkPMColor4f constantOutputForConstantInput (const SkPMColor4f &) const override
 

Friends

class GrSkSLFPFactory
 

Additional Inherited Members

- Protected Types inherited from GrFragmentProcessor
enum  OptimizationFlags : uint32_t {
  kNone_OptimizationFlags , kCompatibleWithCoverageAsAlpha_OptimizationFlag = 0x1 , kPreservesOpaqueInput_OptimizationFlag = 0x2 , kConstantOutputForConstantInput_OptimizationFlag = 0x4 ,
  kAll_OptimizationFlags
}
 
- Protected Member Functions inherited from GrFragmentProcessor
 GrFragmentProcessor (ClassID classID, OptimizationFlags optimizationFlags)
 
 GrFragmentProcessor (const GrFragmentProcessor &src)
 
OptimizationFlags optimizationFlags () const
 
void registerChild (std::unique_ptr< GrFragmentProcessor > child, SkSL::SampleUsage sampleUsage=SkSL::SampleUsage::PassThrough())
 
void cloneAndRegisterAllChildProcessors (const GrFragmentProcessor &src)
 
void setUsesSampleCoordsDirectly ()
 
void setWillReadDstColor ()
 
void setIsBlendFunction ()
 
void mergeOptimizationFlags (OptimizationFlags flags)
 
- Protected Member Functions inherited from GrProcessor
 GrProcessor (ClassID classID)
 
 GrProcessor (const GrProcessor &)=delete
 
GrProcessoroperator= (const GrProcessor &)=delete
 
- Static Protected Member Functions inherited from GrFragmentProcessor
static OptimizationFlags ModulateForSamplerOptFlags (SkAlphaType alphaType, bool samplingDecal)
 
static OptimizationFlags ModulateForClampedSamplerOptFlags (SkAlphaType alphaType)
 
static OptimizationFlags ProcessorOptimizationFlags (const GrFragmentProcessor *fp)
 
static SkPMColor4f ConstantOutputForConstantInput (const GrFragmentProcessor *fp, const SkPMColor4f &input)
 
- Protected Attributes inherited from GrProcessor
const ClassID fClassID
 

Detailed Description

Definition at line 69 of file GrSkSLFP.h.

Member Enumeration Documentation

◆ OptFlags

enum class GrSkSLFP::OptFlags : uint32_t
strong

Member Function Documentation

◆ clone()

std::unique_ptr< GrFragmentProcessor > GrSkSLFP::clone ( ) const
overridevirtual

Makes a copy of this fragment processor that draws equivalently to the original. If the processor has child processors they are cloned as well.

Implements GrFragmentProcessor.

Definition at line 448 of file GrSkSLFP.cpp.

448 {
449 return std::unique_ptr<GrFragmentProcessor>(new (UniformPayloadSize(fEffect.get()))
450 GrSkSLFP(*this));
451}
T * get() const
Definition SkRefCnt.h:303

◆ constantOutputForConstantInput()

SkPMColor4f GrSkSLFP::constantOutputForConstantInput ( const SkPMColor4f inputColor) const
overrideprivatevirtual

Reimplemented from GrFragmentProcessor.

Definition at line 453 of file GrSkSLFP.cpp.

453 {
454 SkPMColor4f color = (fInputChildIndex >= 0)
455 ? ConstantOutputForConstantInput(this->childProcessor(fInputChildIndex), inputColor)
456 : inputColor;
457
458 class ConstantOutputForConstantInput_SkRPCallbacks : public SkSL::RP::Callbacks {
459 public:
460 bool appendShader(int index) override {
461 SkDEBUGFAIL("constant-output-for-constant-input unsupported when child shaders present");
462 return false;
463 }
464 bool appendColorFilter(int index) override {
465 SkDEBUGFAIL("constant-output-for-constant-input unsupported when child shaders present");
466 return false;
467 }
468 bool appendBlender(int index) override {
469 SkDEBUGFAIL("constant-output-for-constant-input unsupported when child shaders present");
470 return false;
471 }
472 void toLinearSrgb(const void* color) override { /* identity color conversion */ }
473 void fromLinearSrgb(const void* color) override { /* identity color conversion */ }
474 };
475
476 if (const SkSL::RP::Program* program = fEffect->getRPProgram(/*debugTrace=*/nullptr)) {
477 // No color conversion is happening here, so we can use untransformed uniforms.
478 SkSpan<const float> uniforms{reinterpret_cast<const float*>(this->uniformData()),
479 fUniformSize / sizeof(float)};
480 SkSTArenaAlloc<2048> alloc; // sufficient for a tiny SkSL program
481 SkRasterPipeline pipeline(&alloc);
482 pipeline.appendConstantColor(&alloc, color.vec());
483 ConstantOutputForConstantInput_SkRPCallbacks callbacks;
484 if (program->appendStages(&pipeline, &alloc, &callbacks, uniforms)) {
485 SkPMColor4f outputColor;
486 SkRasterPipeline_MemoryCtx outputCtx = {&outputColor, 0};
487 pipeline.append(SkRasterPipelineOp::store_f32, &outputCtx);
488 pipeline.run(0, 0, 1, 1);
489 return outputColor;
490 }
491 }
492
493 // We weren't able to run the Raster Pipeline program.
494 return color;
495}
SkColor4f color
#define SkDEBUGFAIL(message)
Definition SkAssert.h:118
GrFragmentProcessor * childProcessor(int index)
static SkPMColor4f ConstantOutputForConstantInput(const GrFragmentProcessor *fp, const SkPMColor4f &input)

◆ IgnoreOptFlags()

static GrIgnoreOptFlags GrSkSLFP::IgnoreOptFlags ( std::unique_ptr< GrFragmentProcessor child)
inlinestatic

Definition at line 96 of file GrSkSLFP.h.

96 {
97 return {std::move(child)};
98 }

◆ Make()

template<typename... Args>
static std::unique_ptr< GrSkSLFP > GrSkSLFP::Make ( const SkRuntimeEffect effect,
const char *  name,
std::unique_ptr< GrFragmentProcessor inputFP,
OptFlags  optFlags,
Args &&...  args 
)
inlinestatic

Definition at line 158 of file GrSkSLFP.h.

162 {
163#ifdef SK_DEBUG
164 checkArgs(effect->fUniforms.begin(),
165 effect->fUniforms.end(),
166 effect->fChildren.begin(),
167 effect->fChildren.end(),
168 std::forward<Args>(args)...);
169#endif
170 // This factory is used internally (for "runtime FPs"). We don't pass/know the destination
171 // color space, so these effects can't use the color transform intrinsics. Callers of this
172 // factory should instead construct an GrColorSpaceXformEffect as part of the FP tree.
173 SkASSERT(!effect->usesColorTransform());
174
175 size_t uniformPayloadSize = UniformPayloadSize(effect);
176 std::unique_ptr<GrSkSLFP> fp(new (uniformPayloadSize) GrSkSLFP(sk_ref_sp(effect),
177 name, optFlags));
178 fp->appendArgs(fp->uniformData(), fp->specialized(), std::forward<Args>(args)...);
179 if (inputFP) {
180 fp->setInput(std::move(inputFP));
181 }
182 return fp;
183 }
#define SkASSERT(cond)
Definition SkAssert.h:116
sk_sp< T > sk_ref_sp(T *obj)
Definition SkRefCnt.h:381
const char * name() const override
Definition GrSkSLFP.h:185
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
const uint32_t fp

◆ MakeWithData()

std::unique_ptr< GrSkSLFP > GrSkSLFP::MakeWithData ( sk_sp< SkRuntimeEffect effect,
const char *  name,
sk_sp< SkColorSpace dstColorSpace,
std::unique_ptr< GrFragmentProcessor inputFP,
std::unique_ptr< GrFragmentProcessor destColorFP,
const sk_sp< const SkData > &  uniforms,
SkSpan< std::unique_ptr< GrFragmentProcessor > >  childFPs 
)
static

Both factories support a single 'input' FP, as well as a collection of other 'child' FPs. The 'child' FPs correspond to the children declared in the effect's SkSL. The inputFP is optional, and intended for instances that have color filter semantics. This is an implicit child - if present, it's evaluated to produce the input color fed to the SkSL. Otherwise, the SkSL receives this FP's input color directly. Creates a new fragment processor from an SkRuntimeEffect and a data blob containing values for all of the 'uniform' variables in the SkSL source. The layout of the uniforms blob is dictated by the SkRuntimeEffect.

Definition at line 289 of file GrSkSLFP.cpp.

296 {
297 if (uniforms->size() != effect->uniformSize()) {
298 return nullptr;
299 }
300 size_t uniformSize = uniforms->size();
301 size_t specializedSize = effect->uniforms().size() * sizeof(Specialized);
302 std::unique_ptr<GrSkSLFP> fp(new (uniformSize + specializedSize)
303 GrSkSLFP(std::move(effect), name, OptFlags::kNone));
304 sk_careful_memcpy(fp->uniformData(), uniforms->data(), uniformSize);
305 for (auto& childFP : childFPs) {
306 fp->addChild(std::move(childFP), /*mergeOptFlags=*/true);
307 }
308 if (inputFP) {
309 fp->setInput(std::move(inputFP));
310 }
311 if (destColorFP) {
312 fp->setDestColorFP(std::move(destColorFP));
313 }
314 if (fp->fEffect->usesColorTransform() && dstColorSpace) {
315 fp->addColorTransformChildren(dstColorSpace.get());
316 }
317 return fp;
318}
static void * sk_careful_memcpy(void *dst, const void *src, size_t len)
Definition SkMalloc.h:125
const void * data() const
Definition SkData.h:37
size_t size() const
Definition SkData.h:30
size_t uniformSize() const
SkSpan< const Uniform > uniforms() const

◆ name()

const char * GrSkSLFP::name ( ) const
inlineoverridevirtual

Human-meaningful string to identify this processor; may be embedded in generated shader code and must be a legal SkSL identifier prefix.

Implements GrProcessor.

Definition at line 185 of file GrSkSLFP.h.

185{ return fName; }

◆ onAddToKey()

void GrSkSLFP::onAddToKey ( const GrShaderCaps caps,
skgpu::KeyBuilder b 
) const
overrideprivatevirtual

Implements GrFragmentProcessor.

Definition at line 416 of file GrSkSLFP.cpp.

416 {
417 // In the unlikely event of a hash collision, we also include the uniform size in the key.
418 // That ensures that we will (at worst) use the wrong program, but one that expects the same
419 // amount of uniform data.
420 b->add32(fEffect->hash());
421 b->add32(fUniformSize);
422
423 const Specialized* specialized = this->specialized();
424 const uint8_t* uniformData = this->uniformData();
425 size_t uniformCount = this->uniformCount();
426 auto iter = fEffect->uniforms().begin();
427
428 for (size_t i = 0; i < uniformCount; ++i, ++iter) {
429 bool specialize = specialized[i] == Specialized::kYes;
430 b->addBool(specialize, "specialize");
431 if (specialize) {
432 b->addBytes(iter->sizeInBytes(), uniformData + iter->offset, iter->name);
433 }
434 }
435}
static bool b

◆ onIsEqual()

bool GrSkSLFP::onIsEqual ( const GrFragmentProcessor ) const
overrideprivatevirtual

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. have the same ClassID).

Implements GrFragmentProcessor.

Definition at line 437 of file GrSkSLFP.cpp.

437 {
438 const GrSkSLFP& sk = other.cast<GrSkSLFP>();
439 const size_t specializedSize = this->uniformCount() * sizeof(Specialized);
440 return fEffect->hash() == sk.fEffect->hash() &&
441 this->uniformCount() == sk.uniformCount() &&
442 fUniformSize == sk.fUniformSize &&
443 !sk_careful_memcmp(this->uniformData(),
444 sk.uniformData(),
445 fUniformSize + specializedSize);
446}
static int sk_careful_memcmp(const void *a, const void *b, size_t len)
Definition SkMalloc.h:143
const T & cast() const

◆ onMakeProgramImpl()

std::unique_ptr< GrFragmentProcessor::ProgramImpl > GrSkSLFP::onMakeProgramImpl ( ) const
overrideprivatevirtual

Returns a new instance of the appropriate ProgramImpl subclass for the given GrFragmentProcessor. It will emit the appropriate code and live with the cached program to setup uniform data for each draw that uses the program.

Implements GrFragmentProcessor.

Definition at line 412 of file GrSkSLFP.cpp.

412 {
413 return std::make_unique<Impl>();
414}

◆ Specialize()

template<typename T >
static GrSpecializedUniform< T > GrSkSLFP::Specialize ( const T value)
inlinestatic

Definition at line 76 of file GrSkSLFP.h.

76 {
77 return {true, value};
78 }
uint8_t value

◆ SpecializeIf()

template<typename T >
static GrSpecializedUniform< T > GrSkSLFP::SpecializeIf ( bool  condition,
const T value 
)
inlinestatic

Definition at line 80 of file GrSkSLFP.h.

80 {
81 return {condition, value};
82 }

◆ When()

template<typename T >
static GrOptionalUniform< T > GrSkSLFP::When ( bool  condition,
const T value 
)
inlinestatic

Definition at line 89 of file GrSkSLFP.h.

89 {
90 return {condition, value};
91 }

Friends And Related Symbol Documentation

◆ GrSkSLFPFactory

friend class GrSkSLFPFactory
friend

Definition at line 444 of file GrSkSLFP.h.


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