aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Florin Malita <fmalita@chromium.org>2017-01-27 16:41:22 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-01-29 16:19:08 +0000
commit6d11ed2951fadc281433606a8edc6774bed39735 (patch)
treee610b91fb12603e63a2c32736e4a68d1c2ed99db
parent22af73f2a5fd40fd9f991e35f7a216e924464cd4 (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>
-rw-r--r--include/core/SkShader.h4
-rw-r--r--src/core/SkRasterPipeline.h3
-rw-r--r--src/core/SkShader.cpp29
-rw-r--r--src/opts/SkRasterPipeline_opts.h8
4 files changed, 40 insertions, 4 deletions
diff --git a/include/core/SkShader.h b/include/core/SkShader.h
index a885f0b982..30a10dcc9f 100644
--- a/include/core/SkShader.h
+++ b/include/core/SkShader.h
@@ -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
diff --git a/src/core/SkRasterPipeline.h b/src/core/SkRasterPipeline.h
index 5143d523e4..2dd2c32a99 100644
--- a/src/core/SkRasterPipeline.h
+++ b/src/core/SkRasterPipeline.h
@@ -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:
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&) {
diff --git a/src/opts/SkRasterPipeline_opts.h b/src/opts/SkRasterPipeline_opts.h
index 1b27fc25d4..dec81d990a 100644
--- a/src/opts/SkRasterPipeline_opts.h
+++ b/src/opts/SkRasterPipeline_opts.h
@@ -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;