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 <jmbetancourt@google.com> Reviewed-by: Florin Malita <fmalita@google.com>
This commit is contained in:
parent
3a295f293c
commit
3868636fb8
@ -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<SkShader> shader = fEffect->makeShader(buildUniformData(), {/* TODO: child support */}, &SkMatrix::I(), false);
|
||||
this->node()->setShader(std::move(shader));
|
||||
}
|
||||
|
||||
sk_sp<SkShader> buildEffectShader() const {
|
||||
if (!fEffect) {
|
||||
return nullptr;
|
||||
}
|
||||
// TODO: consider dumping builder and work with lower level API
|
||||
SkRuntimeShaderBuilder builder = SkRuntimeShaderBuilder(fEffect);
|
||||
sk_sp<SkData> 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<int>(data->size())) {
|
||||
auto dst = reinterpret_cast<uint8_t*>(uniformData->writable_data()) + metadata->offset;
|
||||
memcpy(reinterpret_cast<void*>(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<SkRuntimeEffect> fEffect;
|
||||
std::vector<std::tuple<SkString, std::unique_ptr<VectorValue>>> fUniforms;
|
||||
|
Loading…
Reference in New Issue
Block a user