class SkArenaAlloc; class SkCapabilities; class SkColorSpace; class SkData; class SkMatrix; class SkReadBuffer; class SkShader; class SkWriteBuffer; struct SkColorSpaceXformSteps;
namespace SkShaders { class MatrixRec;
}
namespace SkSL { class Context; class Variable; struct Program;
}
// Private (experimental) API for creating runtime shaders with late-bound uniforms. // The callback must produce a uniform data blob of the correct size for the effect. // It is invoked at "draw" time (essentially, when a draw call is made against the canvas // using the resulting shader). There are no strong guarantees about timing. // Serializing the resulting shader will immediately invoke the callback (and record the // resulting uniforms). using UniformsCallback = std::function<sk_sp<const SkData>(const UniformsCallbackContext&)>; static sk_sp<SkShader> MakeDeferredShader(const SkRuntimeEffect* effect,
UniformsCallback uniformsCallback,
SkSpan<const SkRuntimeEffect::ChildPtr> children, const SkMatrix* localMatrix = nullptr);
// Helper function when creating an effect for a GrSkSLFP that verifies an effect will // implement the GrFragmentProcessor "constant output for constant input" optimization flag. staticbool SupportsConstantOutputForConstantInput(const SkRuntimeEffect* effect) { // This optimization is only implemented for color filters without any children. if (!effect->allowColorFilter() || !effect->children().empty()) { returnfalse;
} returntrue;
}
// If there are layout(color) uniforms then this performs color space transformation on the // color values and returns a new SkData. Otherwise, the original data is returned. static sk_sp<const SkData> TransformUniforms(SkSpan<const SkRuntimeEffect::Uniform> uniforms,
sk_sp<const SkData> originalData, const SkColorSpaceXformSteps&); static sk_sp<const SkData> TransformUniforms(SkSpan<const SkRuntimeEffect::Uniform> uniforms,
sk_sp<const SkData> originalData, const SkColorSpace* dstCS); static SkSpan<constfloat> UniformsAsSpan(
SkSpan<const SkRuntimeEffect::Uniform> uniforms,
sk_sp<const SkData> originalData, bool alwaysCopyIntoAlloc, const SkColorSpace* destColorSpace,
SkArenaAlloc* alloc);
// These internal APIs for creating runtime effects vary from the public API in two ways: // // 1) they're used in contexts where it's not useful to receive an error message; // 2) they're cached. // // Users of the public SkRuntimeEffect::Make*() can of course cache however they like themselves; // keeping these APIs private means users will not be forced into our cache or cache policy.
// Internal API that assumes (and asserts) that the shader code is valid, but does no internal // caching. Used when the caller will cache the result in a static variable. Ownership is passed to // the caller; the effect will be leaked if it the pointer is not stored or explicitly deleted. inline SkRuntimeEffect* SkMakeRuntimeEffect(
SkRuntimeEffect::Result (*make)(SkString, const SkRuntimeEffect::Options&), constchar* sksl,
SkRuntimeEffect::Options options = SkRuntimeEffect::Options{}) { #ifdefined(SK_DEBUG) // Our SKSL snippets we embed in Skia should not have comments or excess indentation. // Removing them helps trim down code size and speeds up parsing if (SkStrContains(sksl, "//") || SkStrContains(sksl, " ")) {
SkDEBUGFAILF("Found SkSL snippet that can be minified: \n %s\n", sksl);
} #endif
SkRuntimeEffectPriv::AllowPrivateAccess(&options); auto result = make(SkString{sksl}, options); if (!result.effect) {
SK_ABORT("%s", result.errorText.c_str());
} return result.effect.release();
}
class RuntimeEffectRPCallbacks : public SkSL::RP::Callbacks { public: // SkStageRec::fPaintColor is used (strictly) to tint alpha-only image shaders with the paint // color. We want to suppress that behavior when they're sampled from runtime effects, so we // just override the paint color here. See also: SkImageShader::appendStages.
RuntimeEffectRPCallbacks(const SkStageRec& s, const SkShaders::MatrixRec& m,
SkSpan<const SkRuntimeEffect::ChildPtr> c,
SkSpan<const SkSL::SampleUsage> u)
: fStage{s.fPipeline,
s.fAlloc,
s.fDstColorType,
s.fDstCS,
SkColors::kTransparent,
s.fSurfaceProps}
, fMatrix(m)
, fChildren(c)
, fSampleUsages(u) {}
// TODO: If an effect calls these intrinsics more than once, we could cache and re-use the steps // object(s), rather than re-creating them in the arena repeatedly. void toLinearSrgb(constvoid* color) override;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.