Revert "Add SkRuntimeBlender class."
This reverts commit 6034941cc2
.
Reason for revert: breaking MSVC build
Original change's description:
> Add SkRuntimeBlender class.
>
> This class is returned by SkRuntimeEffect::makeBlender when a runtime
> blend is returned. SkRuntimeBlendBuilder is also added as a convenience
> class to simplify creation and uniform setup.
>
> Our ability to add tests is limited in this CL because the SkPaint does
> not contain an SkBlender yet. We do have one test which builds an
> SkBlender, but there's not much we can do with it. Testing will be
> bulked up in the next CL.
>
> Change-Id: Ib2d7d04186690ec0d2238fc990a19d9e6b786ce3
> Bug: skia:12080
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/417006
> Commit-Queue: John Stiles <johnstiles@google.com>
> Auto-Submit: John Stiles <johnstiles@google.com>
> Reviewed-by: Brian Osman <brianosman@google.com>
TBR=brianosman@google.com,johnstiles@google.com
Change-Id: Id916f7458b827cbfdbc951c8f02aed16e2f44935
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:12080
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/419159
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
This commit is contained in:
parent
6034941cc2
commit
c804b740b8
@ -249,7 +249,6 @@ private:
|
||||
#endif
|
||||
|
||||
friend class SkRTShader; // fBaseProgram, fMain
|
||||
friend class SkRuntimeBlender; //
|
||||
friend class SkRuntimeColorFilter; //
|
||||
|
||||
friend class SkFilterColorProgram;
|
||||
@ -420,18 +419,4 @@ private:
|
||||
using INHERITED = SkRuntimeEffectBuilder<sk_sp<SkShader>>;
|
||||
};
|
||||
|
||||
/**
|
||||
* SkRuntimeBlendBuilder is a utility to simplify creation and uniform setup of runtime blenders.
|
||||
*/
|
||||
class SK_API SkRuntimeBlendBuilder : public SkRuntimeEffectBuilder<sk_sp<SkBlender>> {
|
||||
public:
|
||||
explicit SkRuntimeBlendBuilder(sk_sp<SkRuntimeEffect>);
|
||||
~SkRuntimeBlendBuilder();
|
||||
|
||||
sk_sp<SkBlender> makeBlender();
|
||||
|
||||
private:
|
||||
using INHERITED = SkRuntimeEffectBuilder<sk_sp<SkBlender>>;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1003,64 +1003,6 @@ sk_sp<SkFlattenable> SkRTShader::CreateProc(SkReadBuffer& buffer) {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class SkRuntimeBlender : public SkBlenderBase {
|
||||
public:
|
||||
SkRuntimeBlender(sk_sp<SkRuntimeEffect> effect, sk_sp<SkData> uniforms)
|
||||
: fEffect(std::move(effect))
|
||||
, fUniforms(std::move(uniforms)) {}
|
||||
|
||||
skvm::Color onProgram(skvm::Builder* p, skvm::Color src, skvm::Color dst,
|
||||
const SkColorInfo& colorInfo, skvm::Uniforms* uniforms,
|
||||
SkArenaAlloc* alloc) const override {
|
||||
sk_sp<SkData> inputs = get_xformed_uniforms(fEffect.get(), fUniforms,
|
||||
colorInfo.colorSpace());
|
||||
SkASSERT(inputs);
|
||||
|
||||
const size_t uniformCount = fEffect->uniformSize() / 4;
|
||||
std::vector<skvm::Val> uniform;
|
||||
uniform.reserve(uniformCount);
|
||||
for (size_t i = 0; i < uniformCount; i++) {
|
||||
int bits;
|
||||
memcpy(&bits, (const char*)inputs->data() + 4*i, 4);
|
||||
uniform.push_back(p->uniform32(uniforms->push(bits)).id);
|
||||
}
|
||||
|
||||
// Emit the blend function as an SkVM program.
|
||||
skvm::Coord zeroCoord = {p->splat(0.0f), p->splat(0.0f)};
|
||||
return SkSL::ProgramToSkVM(*fEffect->fBaseProgram, fEffect->fMain, p, SkMakeSpan(uniform),
|
||||
/*device=*/zeroCoord, /*local=*/zeroCoord,
|
||||
src, dst, /*sampleChild=*/nullptr);
|
||||
}
|
||||
|
||||
void flatten(SkWriteBuffer& buffer) const override {
|
||||
buffer.writeString(fEffect->source().c_str());
|
||||
buffer.writeDataAsByteArray(fUniforms.get());
|
||||
}
|
||||
|
||||
SK_FLATTENABLE_HOOKS(SkRuntimeBlender)
|
||||
|
||||
private:
|
||||
using INHERITED = SkBlenderBase;
|
||||
|
||||
sk_sp<SkRuntimeEffect> fEffect;
|
||||
sk_sp<SkData> fUniforms;
|
||||
};
|
||||
|
||||
sk_sp<SkFlattenable> SkRuntimeBlender::CreateProc(SkReadBuffer& buffer) {
|
||||
SkString sksl;
|
||||
buffer.readString(&sksl);
|
||||
sk_sp<SkData> uniforms = buffer.readByteArrayAsData();
|
||||
|
||||
auto effect = SkMakeCachedRuntimeEffect(SkRuntimeEffect::MakeForBlender, std::move(sksl));
|
||||
if (!buffer.validate(effect != nullptr)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return effect->makeBlender(std::move(uniforms));
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
sk_sp<SkShader> SkRuntimeEffect::makeShader(sk_sp<SkData> uniforms,
|
||||
sk_sp<SkShader> childShaders[],
|
||||
size_t childCount,
|
||||
@ -1237,7 +1179,9 @@ sk_sp<SkBlender> SkRuntimeEffect::makeBlender(sk_sp<SkData> uniforms) const {
|
||||
if (uniforms->size() != this->uniformSize() || !fChildren.empty()) {
|
||||
return nullptr;
|
||||
}
|
||||
return sk_sp<SkBlender>(new SkRuntimeBlender(sk_ref_sp(this), std::move(uniforms)));
|
||||
// TODO(skia:12080): create a runtime blend class
|
||||
SkDEBUGFAIL("not yet implemented");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -1272,12 +1216,3 @@ sk_sp<SkShader> SkRuntimeShaderBuilder::makeShader(const SkMatrix* localMatrix,
|
||||
localMatrix,
|
||||
isOpaque);
|
||||
}
|
||||
|
||||
SkRuntimeBlendBuilder::SkRuntimeBlendBuilder(sk_sp<SkRuntimeEffect> effect)
|
||||
: INHERITED(std::move(effect)) {}
|
||||
|
||||
SkRuntimeBlendBuilder::~SkRuntimeBlendBuilder() = default;
|
||||
|
||||
sk_sp<SkBlender> SkRuntimeBlendBuilder::makeBlender() {
|
||||
return this->effect()->makeBlender(this->uniforms());
|
||||
}
|
||||
|
@ -6,7 +6,6 @@
|
||||
*/
|
||||
|
||||
#include "include/core/SkBitmap.h"
|
||||
#include "include/core/SkBlender.h"
|
||||
#include "include/core/SkCanvas.h"
|
||||
#include "include/core/SkColorFilter.h"
|
||||
#include "include/core/SkData.h"
|
||||
@ -330,7 +329,7 @@ public:
|
||||
|
||||
void test(GrColor TL, GrColor TR, GrColor BL, GrColor BR,
|
||||
PreTestFn preTestCallback = nullptr) {
|
||||
auto shader = fBuilder->makeShader(/*localMatrix=*/nullptr, /*isOpaque=*/false);
|
||||
auto shader = fBuilder->makeShader(nullptr, false);
|
||||
if (!shader) {
|
||||
REPORT_FAILURE(fReporter, "shader", SkString("Effect didn't produce a shader"));
|
||||
return;
|
||||
@ -500,27 +499,10 @@ DEF_TEST(SkRuntimeShaderBuilderReuse, r) {
|
||||
// Test passes if this sequence doesn't assert. skbug.com/10667
|
||||
SkRuntimeShaderBuilder b(std::move(effect));
|
||||
b.uniform("x") = 0.0f;
|
||||
auto shader_0 = b.makeShader(/*localMatrix=*/nullptr, /*isOpaque=*/false);
|
||||
auto shader_0 = b.makeShader(nullptr, false);
|
||||
|
||||
b.uniform("x") = 1.0f;
|
||||
auto shader_1 = b.makeShader(/*localMatrix=*/nullptr, /*isOpaque=*/true);
|
||||
}
|
||||
|
||||
DEF_TEST(SkRuntimeBlendBuilderReuse, r) {
|
||||
const char* kSource = R"(
|
||||
uniform half x;
|
||||
half4 main(half4 s, half4 d) { return half4(x); }
|
||||
)";
|
||||
|
||||
sk_sp<SkRuntimeEffect> effect = SkRuntimeEffect::MakeForBlender(SkString(kSource)).effect;
|
||||
REPORTER_ASSERT(r, effect);
|
||||
|
||||
// We should be able to construct multiple SkBlenders in a row without asserting.
|
||||
SkRuntimeBlendBuilder b(std::move(effect));
|
||||
for (float x = 0.0f; x <= 2.0f; x += 2.0f) {
|
||||
b.uniform("x") = x;
|
||||
sk_sp<SkBlender> blender = b.makeBlender();
|
||||
}
|
||||
auto shader_1 = b.makeShader(nullptr, true);
|
||||
}
|
||||
|
||||
DEF_TEST(SkRuntimeShaderBuilderSetUniforms, r) {
|
||||
@ -548,7 +530,8 @@ DEF_TEST(SkRuntimeShaderBuilderSetUniforms, r) {
|
||||
REPORTER_ASSERT(r, !b.uniform("offset").set<float>(origin, 3));
|
||||
#endif
|
||||
|
||||
auto shader = b.makeShader(/*localMatrix=*/nullptr, /*isOpaque=*/false);
|
||||
|
||||
auto shader = b.makeShader(nullptr, false);
|
||||
}
|
||||
|
||||
DEF_TEST(SkRuntimeEffectThreaded, r) {
|
||||
|
Loading…
Reference in New Issue
Block a user