From e7541d9b0884e559b208f13a04ac1fb8a1a20c2f Mon Sep 17 00:00:00 2001 From: Mike Klein Date: Wed, 13 Jan 2021 13:53:05 -0600 Subject: [PATCH] make SkShaderBase::onProgram pure virtual This makes it easier to see which shaders do not have an SkVM implementation (tricolor for drawVertices, perlin noise) and lets us reserve the default onProgram() for other uses, like mutually recursive F32/Half onProgram(), just as we've done previously for color filters. I've marked both tricolor and perlin noise as "TODO?" rather than just a simple "TODO", mostly because they're both intriguing to handle in other ways, perhaps in externalizable SkSL. Change-Id: I6ccd14a85dee1519b10d53ecbfc1074916954eca Reviewed-on: https://skia-review.googlesource.com/c/skia/+/353319 Reviewed-by: Mike Reed Commit-Queue: Mike Klein --- src/core/SkDraw_vertices.cpp | 10 ++++++++++ src/shaders/SkPerlinNoiseShader.cpp | 10 ++++++++++ src/shaders/SkShader.cpp | 9 --------- src/shaders/SkShaderBase.h | 2 +- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/core/SkDraw_vertices.cpp b/src/core/SkDraw_vertices.cpp index c0161cd530..1b21424bad 100644 --- a/src/core/SkDraw_vertices.cpp +++ b/src/core/SkDraw_vertices.cpp @@ -16,6 +16,7 @@ #include "src/core/SkRasterClip.h" #include "src/core/SkRasterPipeline.h" #include "src/core/SkScan.h" +#include "src/core/SkVM.h" #include "src/core/SkVertState.h" #include "src/core/SkVerticesPriv.h" #include "src/shaders/SkComposeShader.h" @@ -147,6 +148,15 @@ protected: return true; } + skvm::Color onProgram(skvm::Builder*, + skvm::Coord, skvm::Coord, skvm::Color, + const SkMatrixProvider&, const SkMatrix*, + SkFilterQuality, const SkColorInfo&, + skvm::Uniforms*, SkArenaAlloc*) const override { + // TODO? + return {}; + } + private: bool isOpaque() const override { return fIsOpaque; } // For serialization. This will never be called. diff --git a/src/shaders/SkPerlinNoiseShader.cpp b/src/shaders/SkPerlinNoiseShader.cpp index 5260ff32bf..73f6d0a88d 100644 --- a/src/shaders/SkPerlinNoiseShader.cpp +++ b/src/shaders/SkPerlinNoiseShader.cpp @@ -16,6 +16,7 @@ #include "src/core/SkArenaAlloc.h" #include "src/core/SkMatrixProvider.h" #include "src/core/SkReadBuffer.h" +#include "src/core/SkVM.h" #include "src/core/SkWriteBuffer.h" #if SK_SUPPORT_GPU @@ -301,6 +302,15 @@ public: std::unique_ptr asFragmentProcessor(const GrFPArgs&) const override; #endif + skvm::Color onProgram(skvm::Builder*, + skvm::Coord, skvm::Coord, skvm::Color, + const SkMatrixProvider&, const SkMatrix*, + SkFilterQuality, const SkColorInfo&, + skvm::Uniforms*, SkArenaAlloc*) const override { + // TODO? + return {}; + } + protected: void flatten(SkWriteBuffer&) const override; #ifdef SK_ENABLE_LEGACY_SHADERCONTEXT diff --git a/src/shaders/SkShader.cpp b/src/shaders/SkShader.cpp index 4e8c79f178..0ee0913b4b 100644 --- a/src/shaders/SkShader.cpp +++ b/src/shaders/SkShader.cpp @@ -238,15 +238,6 @@ skvm::Color SkShaderBase::program(skvm::Builder* p, return {}; } -skvm::Color SkShaderBase::onProgram(skvm::Builder*, - skvm::Coord device, skvm::Coord local, skvm::Color paint, - const SkMatrixProvider&, const SkMatrix* localM, - SkFilterQuality quality, const SkColorInfo& dst, - skvm::Uniforms* uniforms, SkArenaAlloc* alloc) const { - // SkDebugf("cannot onProgram %s\n", this->getTypeName()); - return {}; -} - // need a cheap way to invert the alpha channel of a shader (i.e. 1 - a) sk_sp SkShaderBase::makeInvertAlpha() const { return this->makeWithColorFilter(SkColorFilters::Blend(0xFFFFFFFF, SkBlendMode::kSrcOut)); diff --git a/src/shaders/SkShaderBase.h b/src/shaders/SkShaderBase.h index 1e74f833e9..35a5beb9a8 100644 --- a/src/shaders/SkShaderBase.h +++ b/src/shaders/SkShaderBase.h @@ -252,7 +252,7 @@ private: skvm::Coord device, skvm::Coord local, skvm::Color paint, const SkMatrixProvider&, const SkMatrix* localM, SkFilterQuality quality, const SkColorInfo& dst, - skvm::Uniforms* uniforms, SkArenaAlloc* alloc) const; + skvm::Uniforms* uniforms, SkArenaAlloc* alloc) const = 0; using INHERITED = SkShader; };