skia2/gm/runtimefunctions.cpp

59 lines
1.6 KiB
C++
Raw Normal View History

/*
* 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"
Reland "Remove (unused) gpuType from SkRuntimeEffect::Uniform" This reverts commit 0fdcaa5757a43b8b9c4fc9778c42592969dc8405. Reason for revert: Fix landed in Android Original change's description: > Revert "Remove (unused) gpuType from SkRuntimeEffect::Uniform" > > This reverts commit cc80a475662e573df8a4b625cd2a4f15ff4d31c2. > > Reason for revert: IWYU cleanup broke less IWYU-clean Android, > > frameworks/native/libs/renderengine/skia/filters/BlurFilter.cpp:180:17: error: variable has incomplete type 'SkRRect' > SkRRect roundedRect; > ^ > external/skia/include/core/SkCanvas.h:58:7: note: forward declaration of 'SkRRect' > class SkRRect; > > > Original change's description: > > Remove (unused) gpuType from SkRuntimeEffect::Uniform > > > > Also remove some unnecessary includes, then IWYU. > > > > Change-Id: I41e88f0e661c59e75cb26e28768801b811fe8ee8 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/371140 > > Commit-Queue: Brian Osman <brianosman@google.com> > > Reviewed-by: John Stiles <johnstiles@google.com> > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > TBR=bsalomon@google.com,brianosman@google.com,johnstiles@google.com > > Change-Id: Id655a6835ebffdb4f5f82474c287c09a69a737df > No-Tree-Checks: true > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/371941 > Reviewed-by: Mike Klein <mtklein@google.com> > Commit-Queue: Mike Klein <mtklein@google.com> # Not skipping CQ checks because this is a reland. Change-Id: I67deaee08f1dfea8d91121b3e665d2e6036b6139 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/372216 Commit-Queue: Brian Osman <brianosman@google.com> Reviewed-by: Brian Osman <brianosman@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com>
2021-02-18 20:51:20 +00:00
#include "include/core/SkShader.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 x / 255;
}
half4 blackAndWhite(half4 raw) {
half value = raw.r * 0.22 + raw.g * 0.67 + raw.b * 0.11;
return half4(value.xxx, 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 =
Reland "Remove deprecated form of SkRuntimeEffect::Make." This reverts commit e89b50ae054c08fc03ad5e7349d28c6a565e054b. Reason for revert: landed Android fix at http://ag/13544365 (master) and http://ag/13554983 (sc-dev) Original change's description: > Android roll broke with a compilation error: > frameworks/base/libs/hwui/jni/Shader.cpp:243:37: error: no matching function for call to 'get' > sk_sp<SkRuntimeEffect> effect = std::get<0>(result) > > Revert "Remove deprecated form of SkRuntimeEffect::Make." > > This reverts commit 1cda19436633c283561fe9a51f221ea9bf0ba2a3. > > Reason for revert: <INSERT REASONING HERE> > > Original change's description: > > Remove deprecated form of SkRuntimeEffect::Make. > > > > Chromium has migrated to the new API at https://crrev.com/c/2675855. > > > > Change-Id: Id4af77db2c462348e8031d28f56e543ad619c19c > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/367060 > > Reviewed-by: Brian Osman <brianosman@google.com> > > Commit-Queue: Brian Osman <brianosman@google.com> > > Commit-Queue: John Stiles <johnstiles@google.com> > > Auto-Submit: John Stiles <johnstiles@google.com> > > TBR=mtklein@google.com,brianosman@google.com,johnstiles@google.com > > Change-Id: Ie18f865f3b7f5b0263db1e52b19cf6faa0500fdd > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/368616 > Reviewed-by: Stan Iliev <stani@google.com> > Commit-Queue: Stan Iliev <stani@google.com> TBR=mtklein@google.com,brianosman@google.com,stani@google.com,johnstiles@google.com Change-Id: I9d679013cb275dc80aaaa977b7f1f4da31f36d1e No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://skia-review.googlesource.com/c/skia/+/369037 Reviewed-by: John Stiles <johnstiles@google.com> Reviewed-by: Derek Sollenberger <djsollen@google.com> Commit-Queue: John Stiles <johnstiles@google.com>
2021-02-11 22:40:03 +00:00
SkRuntimeEffect::Make(SkString(RUNTIME_FUNCTIONS_SRC)).effect;
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;)