2019-03-18 20:20:55 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2019 Google, LLC
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrShaderCaps.h"
|
|
|
|
#include "src/sksl/SkSLCompiler.h"
|
2021-04-13 14:41:57 +00:00
|
|
|
#include "src/sksl/codegen/SkSLPipelineStageCodeGenerator.h"
|
2021-02-05 21:30:34 +00:00
|
|
|
#include "src/sksl/ir/SkSLVarDeclarations.h"
|
|
|
|
#include "src/sksl/ir/SkSLVariable.h"
|
2019-03-18 20:20:55 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "fuzz/Fuzz.h"
|
2019-03-18 20:20:55 +00:00
|
|
|
|
|
|
|
bool FuzzSKSL2Pipeline(sk_sp<SkData> bytes) {
|
|
|
|
sk_sp<GrShaderCaps> caps = SkSL::ShaderCapsFactory::Default();
|
2020-11-02 17:26:22 +00:00
|
|
|
SkSL::Compiler compiler(caps.get());
|
|
|
|
SkSL::Program::Settings settings;
|
2019-03-18 20:20:55 +00:00
|
|
|
std::unique_ptr<SkSL::Program> program = compiler.convertProgram(
|
2021-04-28 21:41:57 +00:00
|
|
|
SkSL::ProgramKind::kRuntimeShader,
|
2019-03-18 20:20:55 +00:00
|
|
|
SkSL::String((const char*) bytes->data(),
|
|
|
|
bytes->size()),
|
|
|
|
settings);
|
2021-02-05 17:15:29 +00:00
|
|
|
if (!program) {
|
2019-03-18 20:20:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
2021-02-05 17:15:29 +00:00
|
|
|
|
2021-02-05 21:30:34 +00:00
|
|
|
class Callbacks : public SkSL::PipelineStage::Callbacks {
|
|
|
|
using String = SkSL::String;
|
|
|
|
|
|
|
|
String declareUniform(const SkSL::VarDeclaration* decl) override {
|
|
|
|
return decl->var().name();
|
|
|
|
}
|
|
|
|
|
2021-02-09 21:52:53 +00:00
|
|
|
void defineFunction(const char* /*decl*/, const char* /*body*/, bool /*isMain*/) override {}
|
2021-02-10 15:19:27 +00:00
|
|
|
void defineStruct(const char* /*definition*/) override {}
|
2021-02-17 20:39:06 +00:00
|
|
|
void declareGlobal(const char* /*declaration*/) override {}
|
2021-02-05 21:30:34 +00:00
|
|
|
|
Reland "Better first-class shader & color filter support in runtime effects"
This is a reland of adadb95a9f1ef21ccc5264c7d0bdc83b56cf91e9
... adds a temporary workaround for some Android framework code.
Original change's description:
> Better first-class shader & color filter support in runtime effects
>
> This does a few things, because they're all intertwined:
>
> 1) SkRuntimeEffect's API now includes details about children (which Skia
> stage was declared, not just the name). The factories verify that the
> declared types in the SkSL match up with the C++ types being passed.
> Today, we still only support adding children of the same type, so the
> checks are simple. Once we allow mixing types, we'll be testing the
> declared type against the actual C++ type supplied for each slot.
> 2) Adds sample variants that supply the input color to the child. This
> is now the only way to invoke a colorFilter child. Internally, we
> support passing a color when invoking a child shader, but I'm not
> exposing that. It's not clearly part of the semantics of the Skia
> pipeline, and is almost never useful. It also exposes users to
> several inconsistencies (skbug.com/11942).
> 3) Because of #2, it's possible that we can't compute a reusable program
> to filter individual colors. In that case, we don't set the constant
> output for constant input optimization, and filterColor4f falls back
> to the slower base-class implementation.
>
> Bug: skia:11813 skia:11942
> Change-Id: I06c41e1b35056e486f3163a72acf6b9535d7fed4
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/401917
> Commit-Queue: Brian Osman <brianosman@google.com>
> Reviewed-by: Mike Klein <mtklein@google.com>
Bug: skia:11813 skia:11942
Change-Id: I2c31b147ed86fa8c4dddefb7066bc1d07fe0d285
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/404637
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2021-04-21 13:57:19 +00:00
|
|
|
String sampleChild(int index, String coords, String color) override {
|
|
|
|
String result = "sample(" + SkSL::to_string(index);
|
|
|
|
if (!coords.empty()) {
|
|
|
|
result += ", " + coords;
|
|
|
|
}
|
|
|
|
if (!color.empty()) {
|
|
|
|
result += ", " + color;
|
|
|
|
}
|
|
|
|
result += ")";
|
|
|
|
return result;
|
2021-02-05 21:30:34 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Callbacks callbacks;
|
2021-04-12 21:17:19 +00:00
|
|
|
SkSL::PipelineStage::ConvertProgram(*program, "coords", "inColor", &callbacks);
|
2019-03-18 20:20:55 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-09-14 12:37:35 +00:00
|
|
|
#if defined(SK_BUILD_FOR_LIBFUZZER)
|
2019-03-18 20:20:55 +00:00
|
|
|
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
2020-06-14 19:03:34 +00:00
|
|
|
if (size > 3000) {
|
|
|
|
return 0;
|
|
|
|
}
|
2019-03-18 20:20:55 +00:00
|
|
|
auto bytes = SkData::MakeWithoutCopy(data, size);
|
|
|
|
FuzzSKSL2Pipeline(bytes);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|