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 <brianosman@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
This commit is contained in:
Brian Osman 2021-07-12 17:02:21 -04:00 committed by Skia Commit-Bot
parent 59a00f062a
commit 946a4cb8ac
22 changed files with 127 additions and 7 deletions

View File

@ -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",

View File

@ -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.

View File

@ -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

View File

@ -22,6 +22,8 @@
#include <string>
#include <vector>
#ifdef SK_ENABLE_SKSL
class GrRecordingContext;
class SkFilterColorProgram;
class SkImage;
@ -446,4 +448,6 @@ private:
using INHERITED = SkRuntimeEffectBuilder<sk_sp<SkBlender>>;
};
#endif
#endif // SK_ENABLE_SKSL
#endif // SkRuntimeEffect_DEFINED

View File

@ -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"

View File

@ -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<sksg::RenderNode> EffectBuilder::attachBlackAndWhiteEffect(
const skjson::ArrayValue& jprops, sk_sp<sksg::RenderNode> layer) const {
#ifdef SK_ENABLE_SKSL
return fBuilder->attachDiscardableAdapter<BlackAndWhiteAdapter>(jprops,
*fBuilder,
std::move(layer));
#else
// TODO(skia:12197)
return layer;
#endif
}
} // namespace skottie::internal

View File

@ -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<sksg::RenderNode> EffectBuilder::attachBrightnessContrastEffect(
const skjson::ArrayValue& jprops, sk_sp<sksg::RenderNode> layer) const {
#ifdef SK_ENABLE_SKSL
return fBuilder->attachDiscardableAdapter<BrightnessContrastAdapter>(jprops,
*fBuilder,
std::move(layer));
#else
// TODO(skia:12197)
return layer;
#endif
}
} // namespace skottie::internal

View File

@ -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<sksg::RenderNode> EffectBuilder::attachDisplacementMapEffect(
const skjson::ArrayValue& jprops, sk_sp<sksg::RenderNode> 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<sksg::RenderNode> EffectBuilder::attachDisplacementMapEffect(
return fBuilder->attachDiscardableAdapter<DisplacementMapAdapter>(jprops,
fBuilder,
std::move(displ_node));
#else
// TODO(skia:12197)
return layer;
#endif
}
} // namespace skottie::internal

View File

@ -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<sksg::RenderNode> EffectBuilder::attachFractalNoiseEffect(
const skjson::ArrayValue& jprops, sk_sp<sksg::RenderNode> layer) const {
#ifdef SK_ENABLE_SKSL
auto fractal_noise = sk_make_sp<FractalNoiseNode>(std::move(layer));
return fBuilder->attachDiscardableAdapter<FractalNoiseAdapter>(jprops, fBuilder,
std::move(fractal_noise));
#else
// TODO(skia:12197)
return layer;
#endif
}
} // namespace skottie::internal

View File

@ -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<sksg::RenderNode> EffectBuilder::attachSphereEffect(
const skjson::ArrayValue& jprops, sk_sp<sksg::RenderNode> layer) const {
#ifdef SK_ENABLE_SKSL
auto sphere = sk_make_sp<SphereNode>(std::move(layer), fLayerSize);
return fBuilder->attachDiscardableAdapter<SphereAdapter>(jprops, fBuilder, std::move(sphere));
#else
// TODO(skia:12197)
return layer;
#endif
}
} // namespace skottie::internal

View File

@ -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<sksg::RenderNode> EffectBuilder::attachThresholdEffect(const skjson::ArrayValue& jprops,
sk_sp<sksg::RenderNode> layer) const {
#ifdef SK_ENABLE_SKSL
return fBuilder->attachDiscardableAdapter<ThresholdAdapter>(jprops,
std::move(layer),
*fBuilder);
#else
// TODO(skia:12197)
return layer;
#endif
}
} // namespace skottie::internal

View File

@ -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"

View File

@ -452,6 +452,7 @@ sk_sp<SkColorFilter> SkColorFilters::WithWorkingFormat(sk_sp<SkColorFilter>
sk_sp<SkColorFilter> SkColorFilters::Lerp(float weight, sk_sp<SkColorFilter> cf0,
sk_sp<SkColorFilter> cf1) {
#ifdef SK_ENABLE_SKSL
if (!cf0 && !cf1) {
return nullptr;
}
@ -484,6 +485,10 @@ sk_sp<SkColorFilter> SkColorFilters::Lerp(float weight, sk_sp<SkColorFilter> cf0
sk_sp<SkColorFilter> inputs[] = {cf0,cf1};
return effect->makeColorFilter(SkData::MakeWithCopy(&weight, sizeof(weight)),
inputs, SK_ARRAY_COUNT(inputs));
#else
// TODO(skia:12197)
return nullptr;
#endif
}
///////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -499,7 +499,9 @@ void SkRegisterMergeImageFilterFlattenable();
void SkRegisterMorphologyImageFilterFlattenables();
void SkRegisterOffsetImageFilterFlattenable();
void SkRegisterPictureImageFilterFlattenable();
#ifdef SK_ENABLE_SKSL
void SkRegisterRuntimeImageFilterFlattenable();
#endif
void SkRegisterShaderImageFilterFlattenable();
void SkRegisterTileImageFilterFlattenable();

View File

@ -44,6 +44,8 @@
#include <algorithm>
#ifdef SK_ENABLE_SKSL
namespace SkSL {
class SharedCompiler {
public:
@ -1327,3 +1329,5 @@ SkRuntimeBlendBuilder::~SkRuntimeBlendBuilder() = default;
sk_sp<SkBlender> SkRuntimeBlendBuilder::makeBlender() {
return this->effect()->makeBlender(this->uniforms());
}
#endif // SK_ENABLE_SKSL

View File

@ -14,6 +14,8 @@
#include <functional>
#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

View File

@ -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<SkBlender> 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<SkBlender> 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
}

View File

@ -12,6 +12,7 @@
#include "src/core/SkRuntimeEffectPriv.h"
sk_sp<SkColorFilter> SkHighContrastFilter::Make(const SkHighContrastConfig& config) {
#ifdef SK_ENABLE_SKSL
if (!config.isValid()) {
return nullptr;
}
@ -62,5 +63,9 @@ sk_sp<SkColorFilter> 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
}

View File

@ -11,6 +11,7 @@
#include "src/core/SkRuntimeEffectPriv.h"
sk_sp<SkColorFilter> 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<SkColorFilter> SkLumaColorFilter::Make() {
SkASSERT(effect);
return effect->makeColorFilter(SkData::MakeEmpty());
#else
// TODO(skia:12197)
return nullptr;
#endif
}

View File

@ -12,6 +12,7 @@
#include "src/core/SkRuntimeEffectPriv.h"
sk_sp<SkColorFilter> SkOverdrawColorFilter::MakeWithSkColors(const SkColor colors[kNumColors]) {
#ifdef SK_ENABLE_SKSL
sk_sp<SkRuntimeEffect> effect = SkMakeCachedRuntimeEffect(
SkRuntimeEffect::MakeForColorFilter,
R"(uniform half4 color0;
@ -40,4 +41,8 @@ sk_sp<SkColorFilter> SkOverdrawColorFilter::MakeWithSkColors(const SkColor color
return effect->makeColorFilter(std::move(data));
}
return nullptr;
#else
// TODO(skia:12197)
return nullptr;
#endif
}

View File

@ -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<SkSpecialImage> SkRuntimeImageFilter::onFilterImage(const Context& ctx,
*offset = outputBounds.topLeft();
return surf->makeImageSnapshot();
}
#endif // SK_ENABLE_SKSL

View File

@ -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);