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>
This commit is contained in:
Florin Malita 2017-01-27 16:41:22 -05:00 committed by Skia Commit-Bot
parent 22af73f2a5
commit 6d11ed2951
4 changed files with 40 additions and 4 deletions

View File

@ -503,9 +503,7 @@ protected:
virtual bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkArenaAlloc*,
const SkMatrix&, const SkPaint&,
const SkMatrix* /*local matrix*/) const {
return false;
}
const SkMatrix* /*local matrix*/) const;
private:
// This is essentially const, but not officially so it can be modified in

View File

@ -95,7 +95,8 @@
M(bicubic_n3y) M(bicubic_n1y) M(bicubic_p1y) M(bicubic_p3y) \
M(save_xy) M(accumulate) \
M(linear_gradient_2stops) \
M(byte_tables)
M(byte_tables) \
M(shader_adapter)
class SkRasterPipeline {
public:

View File

@ -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&) {

View File

@ -18,6 +18,7 @@
#include "SkPM4f.h"
#include "SkPM4fPriv.h"
#include "SkRasterPipeline.h"
#include "SkShader.h"
#include "SkSRGB.h"
namespace {
@ -1085,6 +1086,13 @@ STAGE_CTX(byte_tables, const void*) {
a = SkNf_from_byte(gather(tail, tables->a, SkNf_round(255.0f, a)));
}
STAGE_CTX(shader_adapter, SkShader::Context*) {
SkPM4f buf[N];
static_assert(sizeof(buf) == sizeof(r) + sizeof(g) + sizeof(b) + sizeof(a), "");
ctx->shadeSpan4f(x, (int)g[0], buf, N);
SkNf::Load4(buf, &r, &g, &b, &a);
}
SI Fn enum_to_Fn(SkRasterPipeline::StockStage st) {
switch (st) {
#define M(stage) case SkRasterPipeline::stage: return stage;