From cb1a2df616f54a0d26cc276cc485e994824bf3dc Mon Sep 17 00:00:00 2001 From: Mike Reed Date: Sat, 21 Mar 2020 18:02:58 -0400 Subject: [PATCH] skvm for picture-shader After this, it appears that the only remaining shaders w/o skvm are: - perlinnoise - lighting - runtime (sksl) EmptyShader doesn't, but it is supposed to return failure. Change-Id: Iab2393e1846b92089de837614ba1fb5543a76432 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/278419 Reviewed-by: Mike Klein Commit-Queue: Mike Klein --- src/shaders/SkPictureShader.cpp | 18 ++++++++++++++++++ src/shaders/SkPictureShader.h | 5 +++++ 2 files changed, 23 insertions(+) diff --git a/src/shaders/SkPictureShader.cpp b/src/shaders/SkPictureShader.cpp index 5f3c95c387..b39730467c 100644 --- a/src/shaders/SkPictureShader.cpp +++ b/src/shaders/SkPictureShader.cpp @@ -15,6 +15,7 @@ #include "src/core/SkPicturePriv.h" #include "src/core/SkReadBuffer.h" #include "src/core/SkResourceCache.h" +#include "src/core/SkVM.h" #include "src/shaders/SkBitmapProcShader.h" #include "src/shaders/SkImageShader.h" #include @@ -271,6 +272,23 @@ bool SkPictureShader::onAppendStages(const SkStageRec& rec) const { return as_SB(bitmapShader)->appendStages(localRec); } +skvm::Color SkPictureShader::onProgram(skvm::Builder* p, + skvm::F32 x, skvm::F32 y, skvm::Color paint, + const SkMatrix& ctm, const SkMatrix* localM, + SkFilterQuality quality, const SkColorInfo& dst, + skvm::Uniforms* uniforms, SkArenaAlloc* alloc) const { + auto lm = this->totalLocalMatrix(localM); + + // Keep bitmapShader alive by using alloc instead of stack memory + auto& bitmapShader = *alloc->make>(); + bitmapShader = this->refBitmapShader(ctm, &lm, dst.colorType(), dst.colorSpace()); + if (!bitmapShader) { + return {}; + } + + return as_SB(bitmapShader)->program(p, x,y, paint, ctm, lm, quality, dst, uniforms, alloc); +} + ///////////////////////////////////////////////////////////////////////////////////////// #ifdef SK_ENABLE_LEGACY_SHADERCONTEXT diff --git a/src/shaders/SkPictureShader.h b/src/shaders/SkPictureShader.h index 69a3530b16..0bdc9cd9e0 100644 --- a/src/shaders/SkPictureShader.h +++ b/src/shaders/SkPictureShader.h @@ -37,6 +37,11 @@ protected: SkPictureShader(SkReadBuffer&); void flatten(SkWriteBuffer&) const override; bool onAppendStages(const SkStageRec&) const override; + skvm::Color onProgram(skvm::Builder*, skvm::F32 x, skvm::F32 y, skvm::Color paint, + const SkMatrix& ctm, const SkMatrix* localM, + SkFilterQuality quality, const SkColorInfo& dst, + skvm::Uniforms* uniforms, SkArenaAlloc* alloc) const override; + #ifdef SK_ENABLE_LEGACY_SHADERCONTEXT Context* onMakeContext(const ContextRec&, SkArenaAlloc*) const override; #endif