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>
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;
}
virtual bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkFallbackAlloc*,
- const SkMatrix&, SkFilterQuality) const {
+ const SkMatrix&, const SkPaint&) const {
return false;
}
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,
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);
return true;
}
bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkFallbackAlloc*,
- const SkMatrix& ctm, SkFilterQuality) const override;
+ const SkMatrix& ctm, const SkPaint&) const override;
private:
SkColor fColor;
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;
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.
// 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
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) \
if (shader) {
if (!shader->appendStages(pipeline, dst.colorSpace(), &blitter->fScratchFallback,
- ctm, paint.getFilterQuality())) {
+ ctm, paint)) {
return earlyOut();
}
if (!is_opaque) {
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);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
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;
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 &&
}
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 {
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;
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);
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;
#ifndef SkImageShaderContext_DEFINED
#define SkImageShaderContext_DEFINED
+#include "SkColor.h"
class SkColorTable;
// Definition used by SkImageShader.cpp and SkRasterPipeline_opts.h.
struct SkImageShaderContext {
const void* pixels;
SkColorTable* ctable;
+ SkColor4f color4f;
int stride;
int width;
int height;
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;
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;