diff options
author | Florin Malita <fmalita@chromium.org> | 2017-01-27 16:41:22 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-01-29 16:19:08 +0000 |
commit | 6d11ed2951fadc281433606a8edc6774bed39735 (patch) | |
tree | e610b91fb12603e63a2c32736e4a68d1c2ed99db /src/core/SkShader.cpp | |
parent | 22af73f2a5fd40fd9f991e35f7a216e924464cd4 (diff) |
SkRasterPipeline shader adapter
(lifted from https://skia-review.googlesource.com/c/7088/)
R=mtklein@google.com,herb@google.com,reed@google.com
CQ_INCLUDE_TRYBOTS=skia.primary:Test-Ubuntu-GCC-GCE-CPU-AVX2-x86_64-Release-SKNX_NO_SIMD
Change-Id: Idddb84069423c5fc535bea0a65a5b21a4d07084d
Reviewed-on: https://skia-review.googlesource.com/7615
Commit-Queue: Florin Malita <fmalita@chromium.org>
Reviewed-by: Mike Klein <mtklein@chromium.org>
Reviewed-by: Mike Reed <reed@google.com>
Diffstat (limited to 'src/core/SkShader.cpp')
-rw-r--r-- | src/core/SkShader.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/core/SkShader.cpp b/src/core/SkShader.cpp index 0e03fb7112..7c93394b12 100644 --- a/src/core/SkShader.cpp +++ b/src/core/SkShader.cpp @@ -5,6 +5,7 @@ * found in the LICENSE file. */ +#include "SkArenaAlloc.h" #include "SkAtomics.h" #include "SkBitmapProcShader.h" #include "SkColorShader.h" @@ -13,9 +14,12 @@ #include "SkPaint.h" #include "SkPicture.h" #include "SkPictureShader.h" +#include "SkPM4fPriv.h" +#include "SkRasterPipeline.h" #include "SkReadBuffer.h" #include "SkScalar.h" #include "SkShader.h" +#include "SkTLazy.h" #include "SkWriteBuffer.h" #if SK_SUPPORT_GPU @@ -262,6 +266,31 @@ bool SkShader::appendStages(SkRasterPipeline* pipeline, return this->onAppendStages(pipeline, dst, scratch, ctm, paint, nullptr); } +bool SkShader::onAppendStages(SkRasterPipeline* p, + SkColorSpace* cs, + SkArenaAlloc* alloc, + const SkMatrix& ctm, + const SkPaint& paint, + const SkMatrix* localM) const { + // Legacy shaders handle the paint opacity internally, + // but RP applies it as a separate stage. + SkTCopyOnFirstWrite<SkPaint> opaquePaint(paint); + if (paint.getAlpha() != SK_AlphaOPAQUE) { + opaquePaint.writable()->setAlpha(SK_AlphaOPAQUE); + } + + ContextRec rec(*opaquePaint, ctm, localM, ContextRec::kPM4f_DstType, cs); + if (auto* ctx = this->createContext(rec, + alloc->makeArrayDefault<char>(this->contextSize(rec)))) { + p->append(SkRasterPipeline::shader_adapter, ctx); + // Legacy shaders aren't aware of color spaces. We can pretty + // safely assume they're in sRGB gamut. + return append_gamut_transform(p, alloc, + SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named).get(), cs); + } + return false; +} + /////////////////////////////////////////////////////////////////////////////////////////////////// sk_sp<SkFlattenable> SkEmptyShader::CreateProc(SkReadBuffer&) { |