Constify the uniform value SkDatas in runtime effects

Bug: skia:12720
Change-Id: I7f74b4f88456bf5ddef1a648d2231d28034ed246
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/544237
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Brian Salomon 2022-05-26 10:16:51 -04:00 committed by SkCQ
parent 153bd188e6
commit 9676ef7302
6 changed files with 44 additions and 37 deletions

View File

@ -2,6 +2,12 @@ Skia Graphics Release Notes
This file includes a list of high level updates for each milestone release. This file includes a list of high level updates for each milestone release.
Milestone 104
-------------
* SkRuntimeEffect takes and returns a const SkData.
* * *
Milestone 103 Milestone 103
------------- -------------
* SkSamplingOptions now includes anisotropic filtering. Implemented on GPU only. * SkSamplingOptions now includes anisotropic filtering. Implemented on GPU only.

View File

@ -187,29 +187,30 @@ public:
sk_sp<SkFlattenable> fChild; sk_sp<SkFlattenable> fChild;
}; };
sk_sp<SkShader> makeShader(sk_sp<SkData> uniforms, sk_sp<SkShader> makeShader(sk_sp<const SkData> uniforms,
sk_sp<SkShader> children[], sk_sp<SkShader> children[],
size_t childCount, size_t childCount,
const SkMatrix* localMatrix = nullptr) const; const SkMatrix* localMatrix = nullptr) const;
sk_sp<SkShader> makeShader(sk_sp<SkData> uniforms, sk_sp<SkShader> makeShader(sk_sp<const SkData> uniforms,
SkSpan<ChildPtr> children, SkSpan<ChildPtr> children,
const SkMatrix* localMatrix = nullptr) const; const SkMatrix* localMatrix = nullptr) const;
sk_sp<SkImage> makeImage(GrRecordingContext*, sk_sp<SkImage> makeImage(GrRecordingContext*,
sk_sp<SkData> uniforms, sk_sp<const SkData> uniforms,
SkSpan<ChildPtr> children, SkSpan<ChildPtr> children,
const SkMatrix* localMatrix, const SkMatrix* localMatrix,
SkImageInfo resultInfo, SkImageInfo resultInfo,
bool mipmapped) const; bool mipmapped) const;
sk_sp<SkColorFilter> makeColorFilter(sk_sp<SkData> uniforms) const; sk_sp<SkColorFilter> makeColorFilter(sk_sp<const SkData> uniforms) const;
sk_sp<SkColorFilter> makeColorFilter(sk_sp<SkData> uniforms, sk_sp<SkColorFilter> makeColorFilter(sk_sp<const SkData> uniforms,
sk_sp<SkColorFilter> children[], sk_sp<SkColorFilter> children[],
size_t childCount) const; size_t childCount) const;
sk_sp<SkColorFilter> makeColorFilter(sk_sp<SkData> uniforms, sk_sp<SkColorFilter> makeColorFilter(sk_sp<const SkData> uniforms,
SkSpan<ChildPtr> children) const; SkSpan<ChildPtr> children) const;
sk_sp<SkBlender> makeBlender(sk_sp<SkData> uniforms, SkSpan<ChildPtr> children = {}) const; sk_sp<SkBlender> makeBlender(sk_sp<const SkData> uniforms,
SkSpan<ChildPtr> children = {}) const;
/** /**
* Creates a new Runtime Effect patterned after an already-existing one. The new shader behaves * Creates a new Runtime Effect patterned after an already-existing one. The new shader behaves
@ -419,7 +420,7 @@ protected:
SkRuntimeEffectBuilder& operator=(SkRuntimeEffectBuilder&&) = delete; SkRuntimeEffectBuilder& operator=(SkRuntimeEffectBuilder&&) = delete;
SkRuntimeEffectBuilder& operator=(const SkRuntimeEffectBuilder&) = delete; SkRuntimeEffectBuilder& operator=(const SkRuntimeEffectBuilder&) = delete;
sk_sp<SkData> uniforms() { return fUniforms; } sk_sp<const SkData> uniforms() { return fUniforms; }
SkRuntimeEffect::ChildPtr* children() { return fChildren.data(); } SkRuntimeEffect::ChildPtr* children() { return fChildren.data(); }
size_t numChildren() { return fChildren.size(); } size_t numChildren() { return fChildren.size(); }

View File

@ -779,8 +779,8 @@ const SkFilterColorProgram* SkRuntimeEffect::getFilterColorProgram() {
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
static sk_sp<SkData> get_xformed_uniforms(const SkRuntimeEffect* effect, static sk_sp<const SkData> get_xformed_uniforms(const SkRuntimeEffect* effect,
sk_sp<SkData> baseUniforms, sk_sp<const SkData> baseUniforms,
const SkColorSpace* dstCS) { const SkColorSpace* dstCS) {
using Flags = SkRuntimeEffect::Uniform::Flags; using Flags = SkRuntimeEffect::Uniform::Flags;
using Type = SkRuntimeEffect::Uniform::Type; using Type = SkRuntimeEffect::Uniform::Type;
@ -828,7 +828,7 @@ static sk_sp<SkData> get_xformed_uniforms(const SkRuntimeEffect* effect,
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
static GrFPResult make_effect_fp(sk_sp<SkRuntimeEffect> effect, static GrFPResult make_effect_fp(sk_sp<SkRuntimeEffect> effect,
const char* name, const char* name,
sk_sp<SkData> uniforms, sk_sp<const SkData> uniforms,
std::unique_ptr<GrFragmentProcessor> inputFP, std::unique_ptr<GrFragmentProcessor> inputFP,
std::unique_ptr<GrFragmentProcessor> destColorFP, std::unique_ptr<GrFragmentProcessor> destColorFP,
SkSpan<const SkRuntimeEffect::ChildPtr> children, SkSpan<const SkRuntimeEffect::ChildPtr> children,
@ -949,7 +949,7 @@ public:
class SkRuntimeColorFilter : public SkColorFilterBase { class SkRuntimeColorFilter : public SkColorFilterBase {
public: public:
SkRuntimeColorFilter(sk_sp<SkRuntimeEffect> effect, SkRuntimeColorFilter(sk_sp<SkRuntimeEffect> effect,
sk_sp<SkData> uniforms, sk_sp<const SkData> uniforms,
SkSpan<SkRuntimeEffect::ChildPtr> children) SkSpan<SkRuntimeEffect::ChildPtr> children)
: fEffect(std::move(effect)) : fEffect(std::move(effect))
, fUniforms(std::move(uniforms)) , fUniforms(std::move(uniforms))
@ -959,7 +959,7 @@ public:
GrFPResult asFragmentProcessor(std::unique_ptr<GrFragmentProcessor> inputFP, GrFPResult asFragmentProcessor(std::unique_ptr<GrFragmentProcessor> inputFP,
GrRecordingContext* context, GrRecordingContext* context,
const GrColorInfo& colorInfo) const override { const GrColorInfo& colorInfo) const override {
sk_sp<SkData> uniforms = sk_sp<const SkData> uniforms =
get_xformed_uniforms(fEffect.get(), fUniforms, colorInfo.colorSpace()); get_xformed_uniforms(fEffect.get(), fUniforms, colorInfo.colorSpace());
SkASSERT(uniforms); SkASSERT(uniforms);
@ -982,7 +982,7 @@ public:
skvm::Color onProgram(skvm::Builder* p, skvm::Color c, skvm::Color onProgram(skvm::Builder* p, skvm::Color c,
const SkColorInfo& colorInfo, const SkColorInfo& colorInfo,
skvm::Uniforms* uniforms, SkArenaAlloc* alloc) const override { skvm::Uniforms* uniforms, SkArenaAlloc* alloc) const override {
sk_sp<SkData> inputs = sk_sp<const SkData> inputs =
get_xformed_uniforms(fEffect.get(), fUniforms, colorInfo.colorSpace()); get_xformed_uniforms(fEffect.get(), fUniforms, colorInfo.colorSpace());
SkASSERT(inputs); SkASSERT(inputs);
@ -1008,7 +1008,7 @@ public:
} }
// Get our specific uniform values // Get our specific uniform values
sk_sp<SkData> inputs = get_xformed_uniforms(fEffect.get(), fUniforms, dstCS); sk_sp<const SkData> inputs = get_xformed_uniforms(fEffect.get(), fUniforms, dstCS);
SkASSERT(inputs); SkASSERT(inputs);
auto evalChild = [&](int index, SkPMColor4f inColor) { auto evalChild = [&](int index, SkPMColor4f inColor) {
@ -1043,7 +1043,7 @@ public:
private: private:
sk_sp<SkRuntimeEffect> fEffect; sk_sp<SkRuntimeEffect> fEffect;
sk_sp<SkData> fUniforms; sk_sp<const SkData> fUniforms;
std::vector<SkRuntimeEffect::ChildPtr> fChildren; std::vector<SkRuntimeEffect::ChildPtr> fChildren;
}; };
@ -1080,7 +1080,7 @@ class SkRTShader : public SkShaderBase {
public: public:
SkRTShader(sk_sp<SkRuntimeEffect> effect, SkRTShader(sk_sp<SkRuntimeEffect> effect,
sk_sp<SkSL::SkVMDebugTrace> debugTrace, sk_sp<SkSL::SkVMDebugTrace> debugTrace,
sk_sp<SkData> uniforms, sk_sp<const SkData> uniforms,
const SkMatrix* localMatrix, const SkMatrix* localMatrix,
SkSpan<SkRuntimeEffect::ChildPtr> children) SkSpan<SkRuntimeEffect::ChildPtr> children)
: SkShaderBase(localMatrix) : SkShaderBase(localMatrix)
@ -1107,7 +1107,7 @@ public:
return nullptr; return nullptr;
} }
sk_sp<SkData> uniforms = sk_sp<const SkData> uniforms =
get_xformed_uniforms(fEffect.get(), fUniforms, args.fDstColorInfo->colorSpace()); get_xformed_uniforms(fEffect.get(), fUniforms, args.fDstColorInfo->colorSpace());
SkASSERT(uniforms); SkASSERT(uniforms);
@ -1135,7 +1135,7 @@ public:
const SkMatrixProvider& matrices, const SkMatrix* localM, const SkMatrixProvider& matrices, const SkMatrix* localM,
const SkColorInfo& colorInfo, const SkColorInfo& colorInfo,
skvm::Uniforms* uniforms, SkArenaAlloc* alloc) const override { skvm::Uniforms* uniforms, SkArenaAlloc* alloc) const override {
sk_sp<SkData> inputs = sk_sp<const SkData> inputs =
get_xformed_uniforms(fEffect.get(), fUniforms, colorInfo.colorSpace()); get_xformed_uniforms(fEffect.get(), fUniforms, colorInfo.colorSpace());
SkASSERT(inputs); SkASSERT(inputs);
@ -1180,7 +1180,7 @@ private:
sk_sp<SkRuntimeEffect> fEffect; sk_sp<SkRuntimeEffect> fEffect;
sk_sp<SkSL::SkVMDebugTrace> fDebugTrace; sk_sp<SkSL::SkVMDebugTrace> fDebugTrace;
sk_sp<SkData> fUniforms; sk_sp<const SkData> fUniforms;
std::vector<SkRuntimeEffect::ChildPtr> fChildren; std::vector<SkRuntimeEffect::ChildPtr> fChildren;
}; };
@ -1232,7 +1232,7 @@ sk_sp<SkFlattenable> SkRTShader::CreateProc(SkReadBuffer& buffer) {
class SkRuntimeBlender : public SkBlenderBase { class SkRuntimeBlender : public SkBlenderBase {
public: public:
SkRuntimeBlender(sk_sp<SkRuntimeEffect> effect, SkRuntimeBlender(sk_sp<SkRuntimeEffect> effect,
sk_sp<SkData> uniforms, sk_sp<const SkData> uniforms,
SkSpan<SkRuntimeEffect::ChildPtr> children) SkSpan<SkRuntimeEffect::ChildPtr> children)
: fEffect(std::move(effect)) : fEffect(std::move(effect))
, fUniforms(std::move(uniforms)) , fUniforms(std::move(uniforms))
@ -1243,7 +1243,7 @@ public:
skvm::Color onProgram(skvm::Builder* p, skvm::Color src, skvm::Color dst, skvm::Color onProgram(skvm::Builder* p, skvm::Color src, skvm::Color dst,
const SkColorInfo& colorInfo, skvm::Uniforms* uniforms, const SkColorInfo& colorInfo, skvm::Uniforms* uniforms,
SkArenaAlloc* alloc) const override { SkArenaAlloc* alloc) const override {
sk_sp<SkData> inputs = get_xformed_uniforms(fEffect.get(), fUniforms, sk_sp<const SkData> inputs = get_xformed_uniforms(fEffect.get(), fUniforms,
colorInfo.colorSpace()); colorInfo.colorSpace());
SkASSERT(inputs); SkASSERT(inputs);
@ -1263,7 +1263,7 @@ public:
std::unique_ptr<GrFragmentProcessor> srcFP, std::unique_ptr<GrFragmentProcessor> srcFP,
std::unique_ptr<GrFragmentProcessor> dstFP, std::unique_ptr<GrFragmentProcessor> dstFP,
const GrFPArgs& args) const override { const GrFPArgs& args) const override {
sk_sp<SkData> uniforms = get_xformed_uniforms(fEffect.get(), fUniforms, sk_sp<const SkData> uniforms = get_xformed_uniforms(fEffect.get(), fUniforms,
args.fDstColorInfo->colorSpace()); args.fDstColorInfo->colorSpace());
SkASSERT(uniforms); SkASSERT(uniforms);
auto [success, fp] = make_effect_fp(fEffect, auto [success, fp] = make_effect_fp(fEffect,
@ -1290,7 +1290,7 @@ private:
using INHERITED = SkBlenderBase; using INHERITED = SkBlenderBase;
sk_sp<SkRuntimeEffect> fEffect; sk_sp<SkRuntimeEffect> fEffect;
sk_sp<SkData> fUniforms; sk_sp<const SkData> fUniforms;
std::vector<SkRuntimeEffect::ChildPtr> fChildren; std::vector<SkRuntimeEffect::ChildPtr> fChildren;
}; };
@ -1323,7 +1323,7 @@ sk_sp<SkFlattenable> SkRuntimeBlender::CreateProc(SkReadBuffer& buffer) {
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
sk_sp<SkShader> SkRuntimeEffect::makeShader(sk_sp<SkData> uniforms, sk_sp<SkShader> SkRuntimeEffect::makeShader(sk_sp<const SkData> uniforms,
sk_sp<SkShader> childShaders[], sk_sp<SkShader> childShaders[],
size_t childCount, size_t childCount,
const SkMatrix* localMatrix) const { const SkMatrix* localMatrix) const {
@ -1334,7 +1334,7 @@ sk_sp<SkShader> SkRuntimeEffect::makeShader(sk_sp<SkData> uniforms,
return this->makeShader(std::move(uniforms), SkMakeSpan(children), localMatrix); return this->makeShader(std::move(uniforms), SkMakeSpan(children), localMatrix);
} }
sk_sp<SkShader> SkRuntimeEffect::makeShader(sk_sp<SkData> uniforms, sk_sp<SkShader> SkRuntimeEffect::makeShader(sk_sp<const SkData> uniforms,
SkSpan<ChildPtr> children, SkSpan<ChildPtr> children,
const SkMatrix* localMatrix) const { const SkMatrix* localMatrix) const {
if (!this->allowShader()) { if (!this->allowShader()) {
@ -1354,7 +1354,7 @@ sk_sp<SkShader> SkRuntimeEffect::makeShader(sk_sp<SkData> uniforms,
} }
sk_sp<SkImage> SkRuntimeEffect::makeImage(GrRecordingContext* rContext, sk_sp<SkImage> SkRuntimeEffect::makeImage(GrRecordingContext* rContext,
sk_sp<SkData> uniforms, sk_sp<const SkData> uniforms,
SkSpan<ChildPtr> children, SkSpan<ChildPtr> children,
const SkMatrix* localMatrix, const SkMatrix* localMatrix,
SkImageInfo resultInfo, SkImageInfo resultInfo,
@ -1436,7 +1436,7 @@ sk_sp<SkImage> SkRuntimeEffect::makeImage(GrRecordingContext* rContext,
return surf->makeImageSnapshot(); return surf->makeImageSnapshot();
} }
sk_sp<SkColorFilter> SkRuntimeEffect::makeColorFilter(sk_sp<SkData> uniforms, sk_sp<SkColorFilter> SkRuntimeEffect::makeColorFilter(sk_sp<const SkData> uniforms,
sk_sp<SkColorFilter> childColorFilters[], sk_sp<SkColorFilter> childColorFilters[],
size_t childCount) const { size_t childCount) const {
SkSTArray<4, ChildPtr> children(childCount); SkSTArray<4, ChildPtr> children(childCount);
@ -1446,7 +1446,7 @@ sk_sp<SkColorFilter> SkRuntimeEffect::makeColorFilter(sk_sp<SkData> uniforms,
return this->makeColorFilter(std::move(uniforms), SkMakeSpan(children)); return this->makeColorFilter(std::move(uniforms), SkMakeSpan(children));
} }
sk_sp<SkColorFilter> SkRuntimeEffect::makeColorFilter(sk_sp<SkData> uniforms, sk_sp<SkColorFilter> SkRuntimeEffect::makeColorFilter(sk_sp<const SkData> uniforms,
SkSpan<ChildPtr> children) const { SkSpan<ChildPtr> children) const {
if (!this->allowColorFilter()) { if (!this->allowColorFilter()) {
return nullptr; return nullptr;
@ -1463,11 +1463,11 @@ sk_sp<SkColorFilter> SkRuntimeEffect::makeColorFilter(sk_sp<SkData> uniforms,
return sk_make_sp<SkRuntimeColorFilter>(sk_ref_sp(this), std::move(uniforms), children); return sk_make_sp<SkRuntimeColorFilter>(sk_ref_sp(this), std::move(uniforms), children);
} }
sk_sp<SkColorFilter> SkRuntimeEffect::makeColorFilter(sk_sp<SkData> uniforms) const { sk_sp<SkColorFilter> SkRuntimeEffect::makeColorFilter(sk_sp<const SkData> uniforms) const {
return this->makeColorFilter(std::move(uniforms), /*children=*/{}); return this->makeColorFilter(std::move(uniforms), /*children=*/{});
} }
sk_sp<SkBlender> SkRuntimeEffect::makeBlender(sk_sp<SkData> uniforms, sk_sp<SkBlender> SkRuntimeEffect::makeBlender(sk_sp<const SkData> uniforms,
SkSpan<ChildPtr> children) const { SkSpan<ChildPtr> children) const {
if (!this->allowBlender()) { if (!this->allowBlender()) {
return nullptr; return nullptr;

View File

@ -28,7 +28,7 @@ public:
virtual void writePad32(const void* buffer, size_t bytes) = 0; virtual void writePad32(const void* buffer, size_t bytes) = 0;
virtual void writeByteArray(const void* data, size_t size) = 0; virtual void writeByteArray(const void* data, size_t size) = 0;
void writeDataAsByteArray(SkData* data) { void writeDataAsByteArray(const SkData* data) {
if (!data) { if (!data) {
this->write32(0); this->write32(0);
} else { } else {

View File

@ -293,7 +293,7 @@ std::unique_ptr<GrSkSLFP> GrSkSLFP::MakeWithData(
sk_sp<SkColorSpace> dstColorSpace, sk_sp<SkColorSpace> dstColorSpace,
std::unique_ptr<GrFragmentProcessor> inputFP, std::unique_ptr<GrFragmentProcessor> inputFP,
std::unique_ptr<GrFragmentProcessor> destColorFP, std::unique_ptr<GrFragmentProcessor> destColorFP,
sk_sp<SkData> uniforms, sk_sp<const SkData> uniforms,
SkSpan<std::unique_ptr<GrFragmentProcessor>> childFPs) { SkSpan<std::unique_ptr<GrFragmentProcessor>> childFPs) {
if (uniforms->size() != effect->uniformSize()) { if (uniforms->size() != effect->uniformSize()) {
return nullptr; return nullptr;

View File

@ -106,7 +106,7 @@ public:
sk_sp<SkColorSpace> dstColorSpace, sk_sp<SkColorSpace> dstColorSpace,
std::unique_ptr<GrFragmentProcessor> inputFP, std::unique_ptr<GrFragmentProcessor> inputFP,
std::unique_ptr<GrFragmentProcessor> destColorFP, std::unique_ptr<GrFragmentProcessor> destColorFP,
sk_sp<SkData> uniforms, sk_sp<const SkData> uniforms,
SkSpan<std::unique_ptr<GrFragmentProcessor>> childFPs); SkSpan<std::unique_ptr<GrFragmentProcessor>> childFPs);
/* /*