From 3868636fb8aa2c312b0139d2d9e775ad334669e7 Mon Sep 17 00:00:00 2001 From: Jorge Betancourt Date: Wed, 17 Nov 2021 10:10:40 -0500 Subject: [PATCH] discard SkRuntimeEffect builder in SkSLEffect to use lower level API Change-Id: I20bb5e6463e79bcdd56fd614d9936fdaf65aefcc Reviewed-on: https://skia-review.googlesource.com/c/skia/+/471776 Commit-Queue: Jorge Betancourt Reviewed-by: Florin Malita --- modules/skottie/src/effects/SkSLEffect.cpp | 30 ++++++++++++---------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/modules/skottie/src/effects/SkSLEffect.cpp b/modules/skottie/src/effects/SkSLEffect.cpp index cd6900a2b6..8e5acbf76d 100644 --- a/modules/skottie/src/effects/SkSLEffect.cpp +++ b/modules/skottie/src/effects/SkSLEffect.cpp @@ -8,6 +8,7 @@ #include "modules/skottie/src/effects/Effects.h" #include "include/effects/SkRuntimeEffect.h" +#include "include/private/SkMalloc.h" #include "modules/skottie/src/Adapter.h" #include "modules/skottie/src/SkottieJson.h" #include "modules/skottie/src/SkottieValue.h" @@ -99,28 +100,29 @@ public: private: void onSync() override { - this->node()->setShader(buildEffectShader()); + if (!fEffect) { + return; + } + sk_sp shader = fEffect->makeShader(buildUniformData(), {/* TODO: child support */}, &SkMatrix::I(), false); + this->node()->setShader(std::move(shader)); } - sk_sp buildEffectShader() const { - if (!fEffect) { - return nullptr; - } - // TODO: consider dumping builder and work with lower level API - SkRuntimeShaderBuilder builder = SkRuntimeShaderBuilder(fEffect); + sk_sp buildUniformData() const { + auto uniformData = SkData::MakeUninitialized(fEffect->uniformSize()); + SkASSERT(uniformData); + sk_bzero(uniformData->writable_data(), uniformData->size()); for (const auto& uniform : fUniforms) { const auto& name = std::get<0>(uniform); const auto& data = std::get<1>(uniform); auto metadata = fEffect->findUniform(name.c_str()); - // TODO: build SkData from SkRuntimeEffect::Uniform data - switch (metadata->type) { - case SkRuntimeEffect::Uniform::Type::kFloat: - builder.uniform(name.c_str()) = data->at(0); break; - default: - printf("!!! %s\n", "uniform data type not supported"); + if (metadata && metadata->count == static_cast(data->size())) { + auto dst = reinterpret_cast(uniformData->writable_data()) + metadata->offset; + memcpy(reinterpret_cast(dst), data->data(), data->size() * sizeof(float)); + } else { + SkDebugf("cannot set malformed uniform: %s", name.c_str()); } } - return builder.makeShader(&SkMatrix::I(), false); + return uniformData; } sk_sp fEffect; std::vector>> fUniforms;