diff options
author | Mike Klein <mtklein@chromium.org> | 2016-11-29 15:33:39 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2016-11-29 21:36:32 +0000 |
commit | 7a14734d2cf20e99a24949e9513d823fdfa03b8d (patch) | |
tree | c9ea1280ca64907ddb8adbf06d326b9c7c1d38ac | |
parent | 5b1a7c21006175d313aad09ef40f9453a21480e2 (diff) |
support a8
Most of this is plumbing through the full paint to shaders instead of just the filter quality.
CQ_INCLUDE_TRYBOTS=skia.primary:Test-Ubuntu-GCC-GCE-CPU-AVX2-x86_64-Release-SKNX_NO_SIMD
Change-Id: I6afde07566afa3a4391c24dca7017a9a4f5ec700
Reviewed-on: https://skia-review.googlesource.com/5317
Commit-Queue: Mike Klein <mtklein@chromium.org>
Reviewed-by: Mike Reed <reed@google.com>
-rw-r--r-- | include/core/SkShader.h | 4 | ||||
-rw-r--r-- | src/core/SkColorShader.cpp | 4 | ||||
-rw-r--r-- | src/core/SkColorShader.h | 4 | ||||
-rw-r--r-- | src/core/SkPM4fPriv.h | 8 | ||||
-rw-r--r-- | src/core/SkRasterPipeline.h | 1 | ||||
-rw-r--r-- | src/core/SkRasterPipelineBlitter.cpp | 2 | ||||
-rw-r--r-- | src/core/SkShader.cpp | 4 | ||||
-rw-r--r-- | src/image/SkImageShader.cpp | 26 | ||||
-rw-r--r-- | src/image/SkImageShader.h | 2 | ||||
-rw-r--r-- | src/image/SkImageShaderContext.h | 2 | ||||
-rw-r--r-- | src/opts/SkRasterPipeline_opts.h | 15 |
11 files changed, 46 insertions, 26 deletions
diff --git a/include/core/SkShader.h b/include/core/SkShader.h index 0dcd11157d..9e05a38899 100644 --- a/include/core/SkShader.h +++ b/include/core/SkShader.h @@ -477,7 +477,7 @@ public: SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() bool appendStages(SkRasterPipeline*, SkColorSpace*, SkFallbackAlloc*, - const SkMatrix& ctm, SkFilterQuality) const; + const SkMatrix& ctm, const SkPaint&) const; protected: void flatten(SkWriteBuffer&) const override; @@ -511,7 +511,7 @@ protected: } virtual bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkFallbackAlloc*, - const SkMatrix&, SkFilterQuality) const { + const SkMatrix&, const SkPaint&) const { return false; } diff --git a/src/core/SkColorShader.cpp b/src/core/SkColorShader.cpp index a090621188..da87cdfe2c 100644 --- a/src/core/SkColorShader.cpp +++ b/src/core/SkColorShader.cpp @@ -313,7 +313,7 @@ bool SkColorShader::onAppendStages(SkRasterPipeline* p, SkColorSpace* dst, SkFallbackAlloc* scratch, const SkMatrix& ctm, - SkFilterQuality) const { + const SkPaint&) const { auto color = scratch->make<SkPM4f>(SkPM4f_from_SkColor(fColor, dst)); p->append(SkRasterPipeline::constant_color, color); return append_gamut_transform(p, scratch, @@ -324,7 +324,7 @@ bool SkColor4Shader::onAppendStages(SkRasterPipeline* p, SkColorSpace* dst, SkFallbackAlloc* scratch, const SkMatrix& ctm, - SkFilterQuality) const { + const SkPaint&) const { auto color = scratch->make<SkPM4f>(fColor4.premul()); p->append(SkRasterPipeline::constant_color, color); return append_gamut_transform(p, scratch, fColorSpace.get(), dst); diff --git a/src/core/SkColorShader.h b/src/core/SkColorShader.h index 3101fa3a9f..19c106ddfd 100644 --- a/src/core/SkColorShader.h +++ b/src/core/SkColorShader.h @@ -66,7 +66,7 @@ protected: return true; } bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkFallbackAlloc*, - const SkMatrix& ctm, SkFilterQuality) const override; + const SkMatrix& ctm, const SkPaint&) const override; private: SkColor fColor; @@ -122,7 +122,7 @@ protected: return true; } bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkFallbackAlloc*, - const SkMatrix& ctm, SkFilterQuality) const override; + const SkMatrix& ctm, const SkPaint&) const override; private: sk_sp<SkColorSpace> fColorSpace; diff --git a/src/core/SkPM4fPriv.h b/src/core/SkPM4fPriv.h index aedb0ad20f..13c1fd9ab7 100644 --- a/src/core/SkPM4fPriv.h +++ b/src/core/SkPM4fPriv.h @@ -111,7 +111,7 @@ static inline bool append_gamut_transform(SkRasterPipeline* p, SkFallbackAlloc* return append_gamut_transform(p, scratch->make<matrix_3x4>()->arr, src, dst); } -static inline SkPM4f SkPM4f_from_SkColor(SkColor color, SkColorSpace* dst) { +static inline SkColor4f SkColor4f_from_SkColor(SkColor color, SkColorSpace* dst) { SkColor4f color4f; if (dst) { // sRGB gamma, sRGB gamut. @@ -131,7 +131,11 @@ static inline SkPM4f SkPM4f_from_SkColor(SkColor color, SkColorSpace* dst) { // Linear gamma, dst gamut. swizzle_rb(SkNx_cast<float>(Sk4b::Load(&color)) * (1/255.0f)).store(&color4f); } - return color4f.premul(); + return color4f; +} + +static inline SkPM4f SkPM4f_from_SkColor(SkColor color, SkColorSpace* dst) { + return SkColor4f_from_SkColor(color, dst).premul(); } #endif diff --git a/src/core/SkRasterPipeline.h b/src/core/SkRasterPipeline.h index 96a93584c5..0495ebc3e7 100644 --- a/src/core/SkRasterPipeline.h +++ b/src/core/SkRasterPipeline.h @@ -59,6 +59,7 @@ M(move_src_dst) M(move_dst_src) M(swap_rb) M(swap_rb_d) \ M(clamp_0) M(clamp_a) M(clamp_1) \ M(unpremul) M(premul) \ + M(set_rgb) \ M(from_srgb) M(from_srgb_d) M(to_srgb) \ M(constant_color) M(store_f32) \ M(load_565) M(load_565_d) M(store_565) \ diff --git a/src/core/SkRasterPipelineBlitter.cpp b/src/core/SkRasterPipelineBlitter.cpp index 8f1a7ac751..d1796f5766 100644 --- a/src/core/SkRasterPipelineBlitter.cpp +++ b/src/core/SkRasterPipelineBlitter.cpp @@ -116,7 +116,7 @@ SkBlitter* SkRasterPipelineBlitter::Create(const SkPixmap& dst, if (shader) { if (!shader->appendStages(pipeline, dst.colorSpace(), &blitter->fScratchFallback, - ctm, paint.getFilterQuality())) { + ctm, paint)) { return earlyOut(); } if (!is_opaque) { diff --git a/src/core/SkShader.cpp b/src/core/SkShader.cpp index ca0eac4c8d..87b2cc3f30 100644 --- a/src/core/SkShader.cpp +++ b/src/core/SkShader.cpp @@ -261,8 +261,8 @@ bool SkShader::appendStages(SkRasterPipeline* pipeline, SkColorSpace* dst, SkFallbackAlloc* scratch, const SkMatrix& ctm, - SkFilterQuality quality) const { - return this->onAppendStages(pipeline, dst, scratch, ctm, quality); + const SkPaint& paint) const { + return this->onAppendStages(pipeline, dst, scratch, ctm, paint); } /////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/image/SkImageShader.cpp b/src/image/SkImageShader.cpp index 3def5ec345..4415521164 100644 --- a/src/image/SkImageShader.cpp +++ b/src/image/SkImageShader.cpp @@ -273,7 +273,7 @@ SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END bool SkImageShader::onAppendStages(SkRasterPipeline* p, SkColorSpace* dst, SkFallbackAlloc* scratch, - const SkMatrix& ctm, SkFilterQuality quality) const { + const SkMatrix& ctm, const SkPaint& paint) const { SkPixmap pm; if (!fImage->peekPixels(&pm)) { return false; @@ -286,12 +286,7 @@ bool SkImageShader::onAppendStages(SkRasterPipeline* p, SkColorSpace* dst, SkFal return false; } - // TODO: all formats - switch (info.colorType()) { - case kAlpha_8_SkColorType: - return false; - default: break; - } + auto quality = paint.getFilterQuality(); // When the matrix is just an integer translate, bilerp == nearest neighbor. if (matrix.getType() <= SkMatrix::kTranslate_Mask && @@ -318,11 +313,12 @@ bool SkImageShader::onAppendStages(SkRasterPipeline* p, SkColorSpace* dst, SkFal } auto ctx = scratch->make<SkImageShaderContext>(); - ctx->pixels = pm.addr(); - ctx->ctable = pm.ctable(); - ctx->stride = pm.rowBytesAsPixels(); - ctx->width = pm.width(); - ctx->height = pm.height(); + ctx->pixels = pm.addr(); + ctx->ctable = pm.ctable(); + ctx->color4f = SkColor4f_from_SkColor(paint.getColor(), dst); + ctx->stride = pm.rowBytesAsPixels(); + ctx->width = pm.width(); + ctx->height = pm.height(); if (matrix.asAffine(ctx->matrix)) { p->append(SkRasterPipeline::matrix_2x3, ctx->matrix); } else { @@ -342,6 +338,7 @@ bool SkImageShader::onAppendStages(SkRasterPipeline* p, SkColorSpace* dst, SkFal case kRepeat_TileMode: p->append(SkRasterPipeline::repeat_y, &ctx->height); break; } switch (info.colorType()) { + case kAlpha_8_SkColorType: p->append(SkRasterPipeline::gather_a8, ctx); break; case kIndex_8_SkColorType: p->append(SkRasterPipeline::gather_i8, ctx); break; case kGray_8_SkColorType: p->append(SkRasterPipeline::gather_g8, ctx); break; case kRGB_565_SkColorType: p->append(SkRasterPipeline::gather_565, ctx); break; @@ -386,7 +383,10 @@ bool SkImageShader::onAppendStages(SkRasterPipeline* p, SkColorSpace* dst, SkFal if (effective_color_type(info.colorType()) == kBGRA_8888_SkColorType) { p->append(SkRasterPipeline::swap_rb); } - if (info.alphaType() == kUnpremul_SkAlphaType) { + if (info.colorType() == kAlpha_8_SkColorType) { + p->append(SkRasterPipeline::set_rgb, &ctx->color4f); + } + if (info.colorType() == kAlpha_8_SkColorType || info.alphaType() == kUnpremul_SkAlphaType) { p->append(SkRasterPipeline::premul); } return append_gamut_transform(p, scratch, info.colorSpace(), dst); diff --git a/src/image/SkImageShader.h b/src/image/SkImageShader.h index e3bab5c924..074ecca3a7 100644 --- a/src/image/SkImageShader.h +++ b/src/image/SkImageShader.h @@ -38,7 +38,7 @@ protected: SkImage* onIsAImage(SkMatrix*, TileMode*) const override; bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkFallbackAlloc*, - const SkMatrix& ctm, SkFilterQuality) const override; + const SkMatrix& ctm, const SkPaint&) const override; sk_sp<SkImage> fImage; const TileMode fTileModeX; diff --git a/src/image/SkImageShaderContext.h b/src/image/SkImageShaderContext.h index cb562369a9..1b28bf61f4 100644 --- a/src/image/SkImageShaderContext.h +++ b/src/image/SkImageShaderContext.h @@ -8,6 +8,7 @@ #ifndef SkImageShaderContext_DEFINED #define SkImageShaderContext_DEFINED +#include "SkColor.h" class SkColorTable; // Definition used by SkImageShader.cpp and SkRasterPipeline_opts.h. @@ -16,6 +17,7 @@ class SkColorTable; struct SkImageShaderContext { const void* pixels; SkColorTable* ctable; + SkColor4f color4f; int stride; int width; int height; diff --git a/src/opts/SkRasterPipeline_opts.h b/src/opts/SkRasterPipeline_opts.h index 88a872cb1f..a40fe6c72e 100644 --- a/src/opts/SkRasterPipeline_opts.h +++ b/src/opts/SkRasterPipeline_opts.h @@ -288,6 +288,13 @@ STAGE(premul) { b *= a; } +STAGE(set_rgb) { + auto rgb = (const float*)ctx; + r = rgb[0]; + g = rgb[1]; + b = rgb[2]; +} + STAGE(move_src_dst) { dr = r; dg = g; @@ -777,7 +784,13 @@ SI SkNi offset_and_ptr(T** ptr, const void* ctx, const SkNf& x, const SkNf& y) { return offset; } -STAGE(gather_a8) {} // TODO +STAGE(gather_a8) { + const uint8_t* p; + SkNi offset = offset_and_ptr(&p, ctx, r, g); + + r = g = b = 0.0f; + a = SkNx_cast<float>(gather(tail, p, offset)) * (1/255.0f); +} STAGE(gather_i8) { auto sc = (const SkImageShaderContext*)ctx; const uint8_t* p; |