diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt index 6c3a34a4e0..2d35214999 100644 --- a/RELEASE_NOTES.txt +++ b/RELEASE_NOTES.txt @@ -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 diff --git a/gm/runtimeimagefilter.cpp b/gm/runtimeimagefilter.cpp index 36e6af3435..f1b5bc0f12 100644 --- a/gm/runtimeimagefilter.cpp +++ b/gm/runtimeimagefilter.cpp @@ -34,7 +34,7 @@ static sk_sp 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) { diff --git a/include/effects/SkImageFilters.h b/include/effects/SkImageFilters.h index 7ed306c4c8..5665c60701 100644 --- a/include/effects/SkImageFilters.h +++ b/include/effects/SkImageFilters.h @@ -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 RuntimeShader(const SkRuntimeShaderBuilder& builder, - const char* childShaderName, + std::string_view childShaderName, sk_sp input); /** diff --git a/src/effects/imagefilters/SkRuntimeImageFilter.cpp b/src/effects/imagefilters/SkRuntimeImageFilter.cpp index b6a648e52d..0537e47395 100644 --- a/src/effects/imagefilters/SkRuntimeImageFilter.cpp +++ b/src/effects/imagefilters/SkRuntimeImageFilter.cpp @@ -224,22 +224,19 @@ static bool child_is_shader(const SkRuntimeEffect::Child* child) { } sk_sp SkImageFilters::RuntimeShader(const SkRuntimeShaderBuilder& builder, - const char* childShaderName, + std::string_view childShaderName, sk_sp 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 SkImageFilters::RuntimeShader(const SkRuntimeShaderBuilder& builder, diff --git a/tests/ShaderImageFilterTest.cpp b/tests/ShaderImageFilterTest.cpp index d413239368..d7d5be4bb3 100644 --- a/tests/ShaderImageFilterTest.cpp +++ b/tests/ShaderImageFilterTest.cpp @@ -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> 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) {