767f444feb
There is no more 'inout half4 color'. Effects return their output color. If an effect wants the input color, it must use the (already existing) approach of sampling a nullptr input shader. The change is guarded for Chromium (so we can update their runtime color filters in skia_renderer.cc). For the GPU backend, FPs can now override usesExplicitReturn to indicate that their emitCode will generate a return statement. If that's true, then writeProcessorFunction doesn't inject the automatic return of the output color, and emitFragProc will *always* wrap that FP in a helper function, even as a top-level FP. GrSkSLFP opts in to this behavior, so that the user-supplied return becomes the actual return in the FP's emitCode. Adapting the skvm code to this wasn't too bad: It looks fragile (what happens if there are multiple returns?), but that's not really possible today, without varying control flow. Bug: skia:10613 Change-Id: I205b81fd87dd32bab30b6d6d5fc78853485da036 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/310756 Commit-Queue: Brian Osman <brianosman@google.com> Reviewed-by: Kevin Lubick <kjlubick@google.com> Reviewed-by: John Stiles <johnstiles@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com> Reviewed-by: Mike Klein <mtklein@google.com>
58 lines
1.6 KiB
C++
58 lines
1.6 KiB
C++
/*
|
|
* Copyright 2019 Google LLC
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include "gm/gm.h"
|
|
#include "include/core/SkCanvas.h"
|
|
#include "include/core/SkData.h"
|
|
#include "include/core/SkPaint.h"
|
|
#include "include/core/SkSize.h"
|
|
#include "include/core/SkString.h"
|
|
#include "include/effects/SkRuntimeEffect.h"
|
|
|
|
static const char* RUNTIME_FUNCTIONS_SRC = R"(
|
|
uniform half4 gColor;
|
|
|
|
half scale(float x) {
|
|
return half(x) / 255;
|
|
}
|
|
|
|
half4 blackAndWhite(half4 raw) {
|
|
half value = raw.r * 0.22 + raw.g * 0.67 + raw.b * 0.11;
|
|
return half4(half3(value), raw.a);
|
|
}
|
|
|
|
half4 main(float2 p) {
|
|
return blackAndWhite(half4(scale(p.x), scale(p.y), gColor.b, 1));
|
|
}
|
|
)";
|
|
|
|
class RuntimeFunctions : public skiagm::GM {
|
|
bool runAsBench() const override { return true; }
|
|
|
|
SkString onShortName() override { return SkString("runtimefunctions"); }
|
|
|
|
SkISize onISize() override { return {256, 256}; }
|
|
|
|
void onDraw(SkCanvas* canvas) override {
|
|
sk_sp<SkRuntimeEffect> gEffect =
|
|
std::get<0>(SkRuntimeEffect::Make(SkString(RUNTIME_FUNCTIONS_SRC)));
|
|
SkASSERT(gEffect);
|
|
|
|
SkMatrix localM;
|
|
localM.setRotate(90, 128, 128);
|
|
|
|
SkColor4f inputColor = { 1, 0, 0, 1 };
|
|
auto shader = gEffect->makeShader(SkData::MakeWithCopy(&inputColor, sizeof(inputColor)),
|
|
nullptr, 0, &localM, true);
|
|
SkPaint p;
|
|
p.setShader(std::move(shader));
|
|
canvas->drawRect({0, 0, 256, 256}, p);
|
|
}
|
|
};
|
|
|
|
DEF_GM(return new RuntimeFunctions;)
|