2019-09-20 16:19:11 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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"
|
2020-01-02 16:55:24 +00:00
|
|
|
#include "include/effects/SkRuntimeEffect.h"
|
2019-09-20 16:19:11 +00:00
|
|
|
|
|
|
|
static const char* RUNTIME_FUNCTIONS_SRC = R"(
|
2019-12-13 21:31:40 +00:00
|
|
|
uniform half4 gColor;
|
2019-09-20 16:19:11 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void main(float x, float y, inout half4 color) {
|
|
|
|
color = blackAndWhite(half4(scale(x), scale(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}; }
|
|
|
|
|
2019-12-26 13:43:05 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
|
|
|
// static to pass gl persistent cache test in dm
|
|
|
|
static sk_sp<SkRuntimeEffect> gEffect =
|
|
|
|
std::get<0>(SkRuntimeEffect::Make(SkString(RUNTIME_FUNCTIONS_SRC)));
|
|
|
|
SkASSERT(gEffect);
|
2019-09-20 16:19:11 +00:00
|
|
|
|
2019-12-26 13:43:05 +00:00
|
|
|
SkMatrix localM;
|
|
|
|
localM.setRotate(90, 128, 128);
|
2019-09-20 16:19:11 +00:00
|
|
|
|
2019-12-26 13:43:05 +00:00
|
|
|
SkColor4f inputColor = { 1, 0, 0, 1 };
|
|
|
|
auto shader = gEffect->makeShader(SkData::MakeWithCopy(&inputColor, sizeof(inputColor)),
|
|
|
|
nullptr, 0, &localM, true);
|
2019-09-20 16:19:11 +00:00
|
|
|
SkPaint p;
|
2019-12-26 13:43:05 +00:00
|
|
|
p.setShader(std::move(shader));
|
2019-09-20 16:19:11 +00:00
|
|
|
canvas->drawRect({0, 0, 256, 256}, p);
|
|
|
|
}
|
|
|
|
};
|
2019-12-26 13:43:05 +00:00
|
|
|
|
2019-09-20 16:19:11 +00:00
|
|
|
DEF_GM(return new RuntimeFunctions;)
|