From 946a4cb8acb742c3f196d0946cd09818f4684641 Mon Sep 17 00:00:00 2001 From: Brian Osman Date: Mon, 12 Jul 2021 17:02:21 -0400 Subject: [PATCH] First pass at a no-SkSL CPU build This just disables everything that depends on SkSL today: - Color filters: - HighContrast - Lerp - Luma - Overdraw - Skottie effects: - BlackAndWhite - BrightnessContrast - DisplacementMap - FractalNoise - Sphere - Threshold - GradientColorFilter (indirectly, this uses ColorFilters::Lerp) Cq-Include-Trybots: luci.skia.skia.primary:Canary-Android,Canary-Chromium,Canary-Flutter,Canary-G3 Bug: skia:12197 Change-Id: I26269bd4423897142b8f2fdcc4ab1b274e767cba Reviewed-on: https://skia-review.googlesource.com/c/skia/+/427376 Commit-Queue: Brian Osman Reviewed-by: Florin Malita --- BUILD.gn | 10 ++++++++-- gn/skia.gni | 4 ++++ include/core/SkTypes.h | 6 +++++- include/effects/SkRuntimeEffect.h | 6 +++++- modules/canvaskit/compile.sh | 2 +- modules/skottie/src/effects/BlackAndWhiteEffect.cpp | 8 ++++++++ .../skottie/src/effects/BrightnessContrastEffect.cpp | 9 +++++++++ modules/skottie/src/effects/DisplacementMapEffect.cpp | 9 +++++++++ modules/skottie/src/effects/FractalNoiseEffect.cpp | 10 ++++++++++ modules/skottie/src/effects/SphereEffect.cpp | 9 +++++++++ modules/skottie/src/effects/ThresholdEffect.cpp | 9 +++++++++ src/core/SkCanvas.cpp | 1 + src/core/SkColorFilter.cpp | 5 +++++ src/core/SkImageFilter_Base.h | 2 ++ src/core/SkRuntimeEffect.cpp | 4 ++++ src/core/SkRuntimeEffectPriv.h | 6 +++++- src/effects/SkBlenders.cpp | 6 ++++++ src/effects/SkHighContrastFilter.cpp | 5 +++++ src/effects/SkLumaColorFilter.cpp | 5 +++++ src/effects/SkOverdrawColorFilter.cpp | 5 +++++ src/effects/imagefilters/SkRuntimeImageFilter.cpp | 4 ++++ src/ports/SkGlobalInitialization_default.cpp | 9 ++++++++- 22 files changed, 127 insertions(+), 7 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 48f6fe598a..8c83e41993 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -41,6 +41,9 @@ config("skia_public") { if (!skia_enable_gpu) { defines += [ "SK_SUPPORT_GPU=0" ] } + if (skia_enable_sksl) { + defines += [ "SK_ENABLE_SKSL" ] + } if (is_fuchsia) { defines += fuchsia_defines } @@ -1217,7 +1220,6 @@ skia_component("skia") { ":armv7", ":avx", ":crc32", - ":dehydrate_sksl", ":fontmgr_factory", ":gif", ":heif", @@ -1251,7 +1253,6 @@ skia_component("skia") { sources += skia_utils_sources sources += skia_effects_sources sources += skia_effects_imagefilter_sources - sources += skia_sksl_sources sources += [ "src/android/SkAndroidFrameworkUtils.cpp", "src/android/SkAnimatedImage.cpp", @@ -1287,6 +1288,11 @@ skia_component("skia") { defines = [ "SK_HAS_ANDROID_CODEC" ] libs = [] + if (skia_enable_sksl) { + deps += [ ":dehydrate_sksl" ] + sources += skia_sksl_sources + } + if (is_win) { sources += [ "src/ports/SkDebug_win.cpp", diff --git a/gn/skia.gni b/gn/skia.gni index f7c65684a7..d98fdc19ee 100644 --- a/gn/skia.gni +++ b/gn/skia.gni @@ -24,6 +24,7 @@ declare_args() { skia_enable_pdf = true skia_enable_skottie = !(is_win && is_component_build) skia_enable_skrive = true + skia_enable_sksl = true skia_enable_skvm_jit_when_possible = is_skia_dev_build skia_enable_svg = !is_component_build skia_enable_tools = is_skia_dev_build @@ -147,6 +148,9 @@ declare_args() { # Our tools require static linking (they use non-exported symbols), and the GPU backend. skia_enable_tools = skia_enable_tools && !is_component_build && skia_enable_gpu +# The GPU build requires SkSL +skia_enable_sksl = skia_enable_sksl || skia_enable_gpu + # Skia's targets may be built inside other gn build systems. # Skia builds other project's build targets inside its build. # This is easier if the built-in target types remain generic. diff --git a/include/core/SkTypes.h b/include/core/SkTypes.h index 010057d1da..052fc66902 100644 --- a/include/core/SkTypes.h +++ b/include/core/SkTypes.h @@ -236,7 +236,11 @@ # define SK_SUPPORT_GPU 1 #endif -#if !SK_SUPPORT_GPU +#if SK_SUPPORT_GPU +# if !defined(SK_ENABLE_SKSL) +# define SK_ENABLE_SKSL +# endif +#else # undef SK_GL # undef SK_VULKAN # undef SK_METAL diff --git a/include/effects/SkRuntimeEffect.h b/include/effects/SkRuntimeEffect.h index 71073b66e5..6b0fa6f6fb 100644 --- a/include/effects/SkRuntimeEffect.h +++ b/include/effects/SkRuntimeEffect.h @@ -22,6 +22,8 @@ #include #include +#ifdef SK_ENABLE_SKSL + class GrRecordingContext; class SkFilterColorProgram; class SkImage; @@ -446,4 +448,6 @@ private: using INHERITED = SkRuntimeEffectBuilder>; }; -#endif +#endif // SK_ENABLE_SKSL + +#endif // SkRuntimeEffect_DEFINED diff --git a/modules/canvaskit/compile.sh b/modules/canvaskit/compile.sh index a45382e5a7..aae06c4b38 100755 --- a/modules/canvaskit/compile.sh +++ b/modules/canvaskit/compile.sh @@ -72,7 +72,7 @@ if [[ $@ == *cpu* ]]; then echo "Using the CPU backend instead of the GPU backend" GN_GPU="skia_enable_gpu=false" GN_GPU_FLAGS="" - WASM_GPU="-DSK_SUPPORT_GPU=0 --pre-js $BASE_DIR/cpu.js -s USE_WEBGL2=0" + WASM_GPU="-DSK_SUPPORT_GPU=0 -DSK_ENABLE_SKSL --pre-js $BASE_DIR/cpu.js -s USE_WEBGL2=0" fi SKP_JS="--pre-js $BASE_DIR/skp.js" diff --git a/modules/skottie/src/effects/BlackAndWhiteEffect.cpp b/modules/skottie/src/effects/BlackAndWhiteEffect.cpp index 17163b6e47..8423bc0d70 100644 --- a/modules/skottie/src/effects/BlackAndWhiteEffect.cpp +++ b/modules/skottie/src/effects/BlackAndWhiteEffect.cpp @@ -16,6 +16,8 @@ namespace skottie::internal { +#ifdef SK_ENABLE_SKSL + namespace { // The B&W effect allows controlling individual luminance contribution of @@ -125,12 +127,18 @@ private: } // namespace +#endif // SK_ENABLE_SKSL sk_sp EffectBuilder::attachBlackAndWhiteEffect( const skjson::ArrayValue& jprops, sk_sp layer) const { +#ifdef SK_ENABLE_SKSL return fBuilder->attachDiscardableAdapter(jprops, *fBuilder, std::move(layer)); +#else + // TODO(skia:12197) + return layer; +#endif } } // namespace skottie::internal diff --git a/modules/skottie/src/effects/BrightnessContrastEffect.cpp b/modules/skottie/src/effects/BrightnessContrastEffect.cpp index 5747849f5d..fcb9ed634e 100644 --- a/modules/skottie/src/effects/BrightnessContrastEffect.cpp +++ b/modules/skottie/src/effects/BrightnessContrastEffect.cpp @@ -17,6 +17,8 @@ namespace skottie::internal { +#ifdef SK_ENABLE_SKSL + namespace { // The contrast effect transfer function can be approximated with the following @@ -236,11 +238,18 @@ private: } // namespace +#endif // SK_ENABLE_SKSL + sk_sp EffectBuilder::attachBrightnessContrastEffect( const skjson::ArrayValue& jprops, sk_sp layer) const { +#ifdef SK_ENABLE_SKSL return fBuilder->attachDiscardableAdapter(jprops, *fBuilder, std::move(layer)); +#else + // TODO(skia:12197) + return layer; +#endif } } // namespace skottie::internal diff --git a/modules/skottie/src/effects/DisplacementMapEffect.cpp b/modules/skottie/src/effects/DisplacementMapEffect.cpp index 613e24dad6..3943a676f6 100644 --- a/modules/skottie/src/effects/DisplacementMapEffect.cpp +++ b/modules/skottie/src/effects/DisplacementMapEffect.cpp @@ -22,6 +22,8 @@ namespace skottie::internal { +#ifdef SK_ENABLE_SKSL + namespace { // AE's displacement map effect [1] is somewhat similar to SVG's feDisplacementMap [2]. Main @@ -375,8 +377,11 @@ private: } // namespace +#endif // SK_ENABLE_SKSL + sk_sp EffectBuilder::attachDisplacementMapEffect( const skjson::ArrayValue& jprops, sk_sp layer) const { +#ifdef SK_ENABLE_SKSL auto [ displ, displ_size ] = DisplacementMapAdapter::GetDisplacementSource(jprops, this); auto displ_node = DisplacementNode::Make(layer, fLayerSize, std::move(displ), displ_size); @@ -388,6 +393,10 @@ sk_sp EffectBuilder::attachDisplacementMapEffect( return fBuilder->attachDiscardableAdapter(jprops, fBuilder, std::move(displ_node)); +#else + // TODO(skia:12197) + return layer; +#endif } } // namespace skottie::internal diff --git a/modules/skottie/src/effects/FractalNoiseEffect.cpp b/modules/skottie/src/effects/FractalNoiseEffect.cpp index 71b43cc684..4608e54857 100644 --- a/modules/skottie/src/effects/FractalNoiseEffect.cpp +++ b/modules/skottie/src/effects/FractalNoiseEffect.cpp @@ -15,6 +15,9 @@ #include "modules/sksg/include/SkSGRenderNode.h" namespace skottie::internal { + +#ifdef SK_ENABLE_SKSL + namespace { // An implementation of the ADBE Fractal Noise effect: @@ -469,12 +472,19 @@ private: } // namespace +#endif // SK_ENABLE_SKSL + sk_sp EffectBuilder::attachFractalNoiseEffect( const skjson::ArrayValue& jprops, sk_sp layer) const { +#ifdef SK_ENABLE_SKSL auto fractal_noise = sk_make_sp(std::move(layer)); return fBuilder->attachDiscardableAdapter(jprops, fBuilder, std::move(fractal_noise)); +#else + // TODO(skia:12197) + return layer; +#endif } } // namespace skottie::internal diff --git a/modules/skottie/src/effects/SphereEffect.cpp b/modules/skottie/src/effects/SphereEffect.cpp index 75a90f27f0..f74564ac57 100644 --- a/modules/skottie/src/effects/SphereEffect.cpp +++ b/modules/skottie/src/effects/SphereEffect.cpp @@ -19,6 +19,8 @@ namespace skottie::internal { +#ifdef SK_ENABLE_SKSL + namespace { // This shader maps its child shader onto a sphere. To simplify things, we set it up such that: @@ -413,11 +415,18 @@ private: } // namespace +#endif // SK_ENABLE_SKSL + sk_sp EffectBuilder::attachSphereEffect( const skjson::ArrayValue& jprops, sk_sp layer) const { +#ifdef SK_ENABLE_SKSL auto sphere = sk_make_sp(std::move(layer), fLayerSize); return fBuilder->attachDiscardableAdapter(jprops, fBuilder, std::move(sphere)); +#else + // TODO(skia:12197) + return layer; +#endif } } // namespace skottie::internal diff --git a/modules/skottie/src/effects/ThresholdEffect.cpp b/modules/skottie/src/effects/ThresholdEffect.cpp index b41ee7777c..0231c10eda 100644 --- a/modules/skottie/src/effects/ThresholdEffect.cpp +++ b/modules/skottie/src/effects/ThresholdEffect.cpp @@ -15,6 +15,8 @@ namespace skottie::internal { +#ifdef SK_ENABLE_SKSL + namespace { // Convert to black & white, based on input luminance and a threshold uniform. @@ -69,11 +71,18 @@ private: } // namespace +#endif // SK_ENABLE_SKSL + sk_sp EffectBuilder::attachThresholdEffect(const skjson::ArrayValue& jprops, sk_sp layer) const { +#ifdef SK_ENABLE_SKSL return fBuilder->attachDiscardableAdapter(jprops, std::move(layer), *fBuilder); +#else + // TODO(skia:12197) + return layer; +#endif } } // namespace skottie::internal diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp index 32efdee1f0..61bbead270 100644 --- a/src/core/SkCanvas.cpp +++ b/src/core/SkCanvas.cpp @@ -7,6 +7,7 @@ #include "include/core/SkCanvas.h" +#include "include/core/SkBlender.h" #include "include/core/SkColorFilter.h" #include "include/core/SkImage.h" #include "include/core/SkImageFilter.h" diff --git a/src/core/SkColorFilter.cpp b/src/core/SkColorFilter.cpp index 108e0fe8ce..86089d624d 100644 --- a/src/core/SkColorFilter.cpp +++ b/src/core/SkColorFilter.cpp @@ -452,6 +452,7 @@ sk_sp SkColorFilters::WithWorkingFormat(sk_sp sk_sp SkColorFilters::Lerp(float weight, sk_sp cf0, sk_sp cf1) { +#ifdef SK_ENABLE_SKSL if (!cf0 && !cf1) { return nullptr; } @@ -484,6 +485,10 @@ sk_sp SkColorFilters::Lerp(float weight, sk_sp cf0 sk_sp inputs[] = {cf0,cf1}; return effect->makeColorFilter(SkData::MakeWithCopy(&weight, sizeof(weight)), inputs, SK_ARRAY_COUNT(inputs)); +#else + // TODO(skia:12197) + return nullptr; +#endif } /////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/core/SkImageFilter_Base.h b/src/core/SkImageFilter_Base.h index cba26a8659..3e155a6467 100644 --- a/src/core/SkImageFilter_Base.h +++ b/src/core/SkImageFilter_Base.h @@ -499,7 +499,9 @@ void SkRegisterMergeImageFilterFlattenable(); void SkRegisterMorphologyImageFilterFlattenables(); void SkRegisterOffsetImageFilterFlattenable(); void SkRegisterPictureImageFilterFlattenable(); +#ifdef SK_ENABLE_SKSL void SkRegisterRuntimeImageFilterFlattenable(); +#endif void SkRegisterShaderImageFilterFlattenable(); void SkRegisterTileImageFilterFlattenable(); diff --git a/src/core/SkRuntimeEffect.cpp b/src/core/SkRuntimeEffect.cpp index b08515f2d4..7e35ba7e59 100644 --- a/src/core/SkRuntimeEffect.cpp +++ b/src/core/SkRuntimeEffect.cpp @@ -44,6 +44,8 @@ #include +#ifdef SK_ENABLE_SKSL + namespace SkSL { class SharedCompiler { public: @@ -1327,3 +1329,5 @@ SkRuntimeBlendBuilder::~SkRuntimeBlendBuilder() = default; sk_sp SkRuntimeBlendBuilder::makeBlender() { return this->effect()->makeBlender(this->uniforms()); } + +#endif // SK_ENABLE_SKSL diff --git a/src/core/SkRuntimeEffectPriv.h b/src/core/SkRuntimeEffectPriv.h index 610410b137..3b3cd961b0 100644 --- a/src/core/SkRuntimeEffectPriv.h +++ b/src/core/SkRuntimeEffectPriv.h @@ -14,6 +14,8 @@ #include +#ifdef SK_ENABLE_SKSL + // These internal APIs for creating runtime effects vary from the public API in two ways: // // 1) they're used in contexts where it's not useful to receive an error message; @@ -136,4 +138,6 @@ public: } }; -#endif +#endif // SK_ENABLE_SKSL + +#endif // SkRuntimeEffectPriv_DEFINED diff --git a/src/effects/SkBlenders.cpp b/src/effects/SkBlenders.cpp index cfd23834da..90e098d1cd 100644 --- a/src/effects/SkBlenders.cpp +++ b/src/effects/SkBlenders.cpp @@ -5,11 +5,13 @@ * found in the LICENSE file. */ +#include "include/core/SkScalar.h" #include "include/effects/SkBlenders.h" #include "include/effects/SkRuntimeEffect.h" sk_sp SkBlenders::Arithmetic(float k1, float k2, float k3, float k4, bool enforcePremul) { +#ifdef SK_ENABLE_SKSL if (!SkScalarIsFinite(k1) || !SkScalarIsFinite(k2) || !SkScalarIsFinite(k3) || @@ -59,4 +61,8 @@ sk_sp SkBlenders::Arithmetic(float k1, float k2, float k3, float k4, enforcePremul ? 0.0f : 1.0f, }; return gArithmeticEffect->makeBlender(SkData::MakeWithCopy(array, sizeof(array))); +#else + // TODO(skia:12197) + return nullptr; +#endif } diff --git a/src/effects/SkHighContrastFilter.cpp b/src/effects/SkHighContrastFilter.cpp index 1414184657..6f2e9fe33a 100644 --- a/src/effects/SkHighContrastFilter.cpp +++ b/src/effects/SkHighContrastFilter.cpp @@ -12,6 +12,7 @@ #include "src/core/SkRuntimeEffectPriv.h" sk_sp SkHighContrastFilter::Make(const SkHighContrastConfig& config) { +#ifdef SK_ENABLE_SKSL if (!config.isValid()) { return nullptr; } @@ -62,5 +63,9 @@ sk_sp SkHighContrastFilter::Make(const SkHighContrastConfig& conf return SkColorFilters::WithWorkingFormat( effect->makeColorFilter(SkData::MakeWithCopy(&uniforms,sizeof(uniforms))), &linear, nullptr/*use dst gamut*/, &unpremul); +#else + // TODO(skia:12197) + return nullptr; +#endif } diff --git a/src/effects/SkLumaColorFilter.cpp b/src/effects/SkLumaColorFilter.cpp index 5ee0a96510..2db4ee5573 100644 --- a/src/effects/SkLumaColorFilter.cpp +++ b/src/effects/SkLumaColorFilter.cpp @@ -11,6 +11,7 @@ #include "src/core/SkRuntimeEffectPriv.h" sk_sp SkLumaColorFilter::Make() { +#ifdef SK_ENABLE_SKSL const char* code = "half4 main(half4 inColor) {" "return saturate(dot(half3(0.2126, 0.7152, 0.0722), inColor.rgb)).000r;" @@ -20,4 +21,8 @@ sk_sp SkLumaColorFilter::Make() { SkASSERT(effect); return effect->makeColorFilter(SkData::MakeEmpty()); +#else + // TODO(skia:12197) + return nullptr; +#endif } diff --git a/src/effects/SkOverdrawColorFilter.cpp b/src/effects/SkOverdrawColorFilter.cpp index 7d0f53a946..435b3bfa64 100644 --- a/src/effects/SkOverdrawColorFilter.cpp +++ b/src/effects/SkOverdrawColorFilter.cpp @@ -12,6 +12,7 @@ #include "src/core/SkRuntimeEffectPriv.h" sk_sp SkOverdrawColorFilter::MakeWithSkColors(const SkColor colors[kNumColors]) { +#ifdef SK_ENABLE_SKSL sk_sp effect = SkMakeCachedRuntimeEffect( SkRuntimeEffect::MakeForColorFilter, R"(uniform half4 color0; @@ -40,4 +41,8 @@ sk_sp SkOverdrawColorFilter::MakeWithSkColors(const SkColor color return effect->makeColorFilter(std::move(data)); } return nullptr; +#else + // TODO(skia:12197) + return nullptr; +#endif } diff --git a/src/effects/imagefilters/SkRuntimeImageFilter.cpp b/src/effects/imagefilters/SkRuntimeImageFilter.cpp index 55351fba5d..be79aaef9d 100644 --- a/src/effects/imagefilters/SkRuntimeImageFilter.cpp +++ b/src/effects/imagefilters/SkRuntimeImageFilter.cpp @@ -17,6 +17,8 @@ #include "src/core/SkWriteBuffer.h" #include "src/effects/imagefilters/SkRuntimeImageFilter.h" +#ifdef SK_ENABLE_SKSL + namespace { class SkRuntimeImageFilter final : public SkImageFilter_Base { @@ -137,3 +139,5 @@ sk_sp SkRuntimeImageFilter::onFilterImage(const Context& ctx, *offset = outputBounds.topLeft(); return surf->makeImageSnapshot(); } + +#endif // SK_ENABLE_SKSL diff --git a/src/ports/SkGlobalInitialization_default.cpp b/src/ports/SkGlobalInitialization_default.cpp index e1f721a504..c761b89c2a 100644 --- a/src/ports/SkGlobalInitialization_default.cpp +++ b/src/ports/SkGlobalInitialization_default.cpp @@ -24,7 +24,6 @@ #include "include/effects/SkGradientShader.h" #include "include/effects/SkOverdrawColorFilter.h" #include "include/effects/SkPerlinNoiseShader.h" - #include "include/effects/SkRuntimeEffect.h" #include "include/effects/SkShaderMaskFilter.h" #include "include/effects/SkTableColorFilter.h" #include "src/core/SkBlendModeBlender.h" @@ -49,6 +48,10 @@ #include "src/core/SkLocalMatrixImageFilter.h" #include "src/core/SkMatrixImageFilter.h" +#ifdef SK_ENABLE_SKSL + #include "include/effects/SkRuntimeEffect.h" +#endif + #ifdef SK_SUPPORT_LEGACY_DRAWLOOPER #include "include/effects/SkLayerDrawLooper.h" #endif @@ -81,8 +84,10 @@ // Blenders. SK_REGISTER_FLATTENABLE(SkBlendModeBlender); +#ifdef SK_ENABLE_SKSL // Runtime shaders, color filters, and blenders. SkRuntimeEffect::RegisterFlattenables(); +#endif // Mask filters. SK_REGISTER_FLATTENABLE(SkEmbossMaskFilter); @@ -134,7 +139,9 @@ SkRegisterMorphologyImageFilterFlattenables(); SkRegisterOffsetImageFilterFlattenable(); SkRegisterPictureImageFilterFlattenable(); +#ifdef SK_ENABLE_SKSL SkRegisterRuntimeImageFilterFlattenable(); +#endif SkRegisterShaderImageFilterFlattenable(); SkRegisterTileImageFilterFlattenable(); SK_REGISTER_FLATTENABLE(SkLocalMatrixImageFilter);