2019-12-19 20:44:56 +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.
|
|
|
|
*/
|
|
|
|
|
2020-01-02 16:55:24 +00:00
|
|
|
#include "include/effects/SkRuntimeEffect.h"
|
2019-12-19 20:44:56 +00:00
|
|
|
#include "tests/Test.h"
|
|
|
|
|
2019-12-30 18:44:01 +00:00
|
|
|
DEF_TEST(SkRuntimeEffectInvalidInputs, r) {
|
|
|
|
auto test = [r](const char* hdr, const char* expected) {
|
|
|
|
SkString src = SkStringPrintf("%s void main(float x, float y, inout half4 color) {}", hdr);
|
|
|
|
auto [effect, errorText] = SkRuntimeEffect::Make(src);
|
2019-12-19 20:44:56 +00:00
|
|
|
REPORTER_ASSERT(r, !effect);
|
|
|
|
REPORTER_ASSERT(r, errorText.contains(expected),
|
|
|
|
"Expected error message to contain \"%s\". Actual message: \"%s\"",
|
|
|
|
expected, errorText.c_str());
|
|
|
|
};
|
|
|
|
|
|
|
|
// Features that are only allowed in .fp files (key, in uniform, ctype, when, tracked).
|
|
|
|
// Ensure that these fail, and the error messages contain the relevant keyword.
|
2019-12-30 18:44:01 +00:00
|
|
|
test("layout(key) in bool Input;", "key");
|
|
|
|
test("in uniform float Input;", "in uniform");
|
|
|
|
test("layout(ctype=SkRect) float4 Input;", "ctype");
|
|
|
|
test("in bool Flag; layout(when=Flag) uniform float Input;", "when");
|
|
|
|
test("layout(tracked) uniform float Input;", "tracked");
|
2019-12-19 20:44:56 +00:00
|
|
|
|
2019-12-30 18:44:01 +00:00
|
|
|
// Runtime SkSL supports a limited set of uniform types. No samplers, for example:
|
|
|
|
test("uniform sampler2D s;", "sampler2D");
|
2019-12-19 20:44:56 +00:00
|
|
|
|
2019-12-30 18:44:01 +00:00
|
|
|
// 'in' variables can't be arrays
|
|
|
|
test("in int Input[2];", "array");
|
2020-01-06 16:13:45 +00:00
|
|
|
|
|
|
|
// Type specific restrictions:
|
|
|
|
|
|
|
|
// 'bool', 'int' can't be 'uniform'
|
|
|
|
test("uniform bool Input;", "'uniform'");
|
|
|
|
test("uniform int Input;", "'uniform'");
|
|
|
|
|
|
|
|
// vector and matrix types can't be 'in'
|
|
|
|
test("in float2 Input;", "'in'");
|
|
|
|
test("in half3x3 Input;", "'in'");
|
2019-12-19 20:44:56 +00:00
|
|
|
}
|