Update single-child RuntimeShader to use string_view.
This change has the potential to break existing clients if they pass nullptr as the childShaderName, which used to be supported. To fix this breakage, pass the empty string instead of null. Change-Id: I984ec0e12be5bb0a82ec5b719fec48ee7d577dc4 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/557898 Auto-Submit: John Stiles <johnstiles@google.com> Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: John Stiles <johnstiles@google.com>
This commit is contained in:
parent
c752f8490e
commit
8b2633215e
@ -15,7 +15,7 @@ Milestone 104
|
||||
* SkRuntimeEffect::Child now stores the child name as a string_view, rather than a SkString.
|
||||
Related methods SkRuntimeEffect::findChild and SkRuntimeEffectBuilder::child also take
|
||||
std::string_view instead of const char*. Also, SkImageFilters::RuntimeShader now takes the
|
||||
child-name array as a std::string_view[] instead of const char*[].
|
||||
child name(s) as std::string_view instead of const char*.
|
||||
* skcms.h has been relocated to //modules/skcms/skcms.h (was //include/third_party/skcms/skcms.h)
|
||||
* New functions SkCanvas::getBaseProps and SkCanvas::getTopProps; SkCanvas::getBaseProps is a
|
||||
direct replacement for the (now deprecated) SkCanvas::getProps function, while getTopProps is
|
||||
|
@ -34,7 +34,7 @@ static sk_sp<SkImageFilter> make_filter() {
|
||||
}
|
||||
)")).effect;
|
||||
SkRuntimeShaderBuilder builder(std::move(effect));
|
||||
return SkImageFilters::RuntimeShader(builder, /*childShaderName=*/nullptr, /*input=*/nullptr);
|
||||
return SkImageFilters::RuntimeShader(builder, /*childShaderName=*/"", /*input=*/nullptr);
|
||||
}
|
||||
|
||||
DEF_SIMPLE_GM_BG(rtif_distort, canvas, 500, 750, SK_ColorBLACK) {
|
||||
|
@ -345,13 +345,13 @@ public:
|
||||
* fill the result image
|
||||
* @param childShaderName The name of the child shader defined in the builder that will be
|
||||
* bound to the input param (or the source image if the input param
|
||||
* is null). If null, the builder can have exactly one child shader,
|
||||
* is null). If empty, the builder can have exactly one child shader,
|
||||
* which automatically binds the input param.
|
||||
* @param input The image filter that will be provided as input to the runtime
|
||||
* shader. If null the implicit source image is used instead
|
||||
*/
|
||||
static sk_sp<SkImageFilter> RuntimeShader(const SkRuntimeShaderBuilder& builder,
|
||||
const char* childShaderName,
|
||||
std::string_view childShaderName,
|
||||
sk_sp<SkImageFilter> input);
|
||||
|
||||
/**
|
||||
|
@ -224,22 +224,19 @@ static bool child_is_shader(const SkRuntimeEffect::Child* child) {
|
||||
}
|
||||
|
||||
sk_sp<SkImageFilter> SkImageFilters::RuntimeShader(const SkRuntimeShaderBuilder& builder,
|
||||
const char* childShaderName,
|
||||
std::string_view childShaderName,
|
||||
sk_sp<SkImageFilter> input) {
|
||||
// If no childShaderName is provided, check to see if we can implicitly assign it to the only
|
||||
// child in the effect.
|
||||
std::string_view childShaderNameView;
|
||||
if (childShaderName != nullptr) {
|
||||
childShaderNameView = childShaderName;
|
||||
} else {
|
||||
if (childShaderName.empty()) {
|
||||
auto children = builder.effect()->children();
|
||||
if (children.size() != 1) {
|
||||
return nullptr;
|
||||
}
|
||||
childShaderNameView = children.front().name;
|
||||
childShaderName = children.front().name;
|
||||
}
|
||||
|
||||
return SkImageFilters::RuntimeShader(builder, &childShaderNameView, &input, 1);
|
||||
return SkImageFilters::RuntimeShader(builder, &childShaderName, &input, 1);
|
||||
}
|
||||
|
||||
sk_sp<SkImageFilter> SkImageFilters::RuntimeShader(const SkRuntimeShaderBuilder& builder,
|
||||
|
@ -137,7 +137,7 @@ static void test_runtime_shader(skiatest::Reporter* r, SkSurface* surface) {
|
||||
// All 3 variations should produce the same pixel output
|
||||
std::vector<sk_sp<SkImageFilter>> filters = {
|
||||
SkMakeRuntimeImageFilter(effect, /*uniforms=*/nullptr, input),
|
||||
SkImageFilters::RuntimeShader(builder, /*childShaderName=*/nullptr, input),
|
||||
SkImageFilters::RuntimeShader(builder, /*childShaderName=*/"", input),
|
||||
SkImageFilters::RuntimeShader(builder, /*childShaderName=*/"child", input)};
|
||||
|
||||
for (auto&& filter : filters) {
|
||||
|
Loading…
Reference in New Issue
Block a user