2019-06-20 16:40:30 +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/SkColorFilter.h"
|
|
|
|
#include "include/core/SkData.h"
|
|
|
|
#include "include/core/SkImage.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "src/core/SkColorFilterPriv.h"
|
|
|
|
#include "src/core/SkReadBuffer.h"
|
|
|
|
#include "src/core/SkWriteBuffer.h"
|
|
|
|
#include "tools/Resources.h"
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
extern sk_sp<SkShader> SkRuntimeShaderMaker(SkString sksl, sk_sp<SkData> inputs,
|
|
|
|
const SkMatrix* localMatrix, bool isOpaque);
|
|
|
|
|
|
|
|
const char* gProg = R"(
|
2019-07-16 20:50:14 +00:00
|
|
|
layout(ctype=SkRect) in uniform half4 gColor;
|
2019-06-20 16:40:30 +00:00
|
|
|
|
2019-07-16 20:50:14 +00:00
|
|
|
void main(float x, float y, inout half4 color) {
|
|
|
|
color = half4(half(x)*(1.0/255), half(y)*(1.0/255), gColor.b, 1);
|
2019-06-20 16:40:30 +00:00
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
2019-07-16 20:50:14 +00:00
|
|
|
static sk_sp<SkShader> gShader;
|
|
|
|
|
2019-06-20 16:40:30 +00:00
|
|
|
class RuntimeShader : public skiagm::GM {
|
2019-07-18 17:35:49 +00:00
|
|
|
sk_sp<SkData> fData;
|
2019-06-20 16:40:30 +00:00
|
|
|
|
|
|
|
bool runAsBench() const override { return true; }
|
|
|
|
|
2019-07-18 17:35:49 +00:00
|
|
|
SkString onShortName() override { return SkString("runtime_shader"); }
|
2019-06-20 16:40:30 +00:00
|
|
|
|
2019-07-18 17:35:49 +00:00
|
|
|
SkISize onISize() override { return {512, 256}; }
|
2019-06-20 16:40:30 +00:00
|
|
|
|
|
|
|
void onOnceBeforeDraw() override {
|
2019-07-16 20:50:14 +00:00
|
|
|
// use global to pass gl persistent cache test in dm
|
|
|
|
if (!gShader) {
|
|
|
|
SkMatrix localM;
|
|
|
|
localM.setRotate(90, 128, 128);
|
2019-06-20 16:40:30 +00:00
|
|
|
|
2019-07-16 20:50:14 +00:00
|
|
|
fData = SkData::MakeUninitialized(sizeof(SkColor4f));
|
|
|
|
SkColor4f* c = (SkColor4f*)fData->writable_data();
|
|
|
|
*c = {1, 0, 0, 1};
|
|
|
|
gShader = SkRuntimeShaderMaker(SkString(gProg), fData, &localM, true);
|
|
|
|
}
|
2019-06-20 16:40:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void onDraw(SkCanvas* canvas) override {
|
|
|
|
SkPaint p;
|
2019-07-16 20:50:14 +00:00
|
|
|
p.setShader(gShader);
|
2019-06-20 16:40:30 +00:00
|
|
|
canvas->drawRect({0, 0, 256, 256}, p);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
DEF_GM(return new RuntimeShader;)
|