slant colorfilter away from filterSpan4f
rename to make it easy to delete any impl that also had onAppendStages... i.e. rename to make it clear that it is just an impl trick for rasterpipeline. Bug: skia: Change-Id: If3c3b2811eff12d399cdf7a77552c01e72c06996 Reviewed-on: https://skia-review.googlesource.com/18234 Reviewed-by: Mike Klein <mtklein@chromium.org> Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
parent
d696df74d4
commit
25f3805efa
@ -72,8 +72,6 @@ public:
|
||||
*/
|
||||
virtual void filterSpan(const SkPMColor src[], int count, SkPMColor result[]) const = 0;
|
||||
|
||||
virtual void filterSpan4f(const SkPM4f src[], int count, SkPM4f result[]) const = 0;
|
||||
|
||||
void appendStages(SkRasterPipeline*, SkColorSpace*, SkArenaAlloc*, bool shaderIsOpaque) const;
|
||||
|
||||
enum Flags {
|
||||
@ -189,6 +187,10 @@ private:
|
||||
bool shaderIsOpaque) const;
|
||||
|
||||
|
||||
virtual void onFilterStage(const SkPM4f[], int, SkPM4f[]) const {
|
||||
SkASSERT(false);
|
||||
}
|
||||
|
||||
friend class SkColorSpaceXformer;
|
||||
friend class SkComposeColorFilter;
|
||||
|
||||
|
@ -29,7 +29,6 @@ public:
|
||||
static sk_sp<SkColorFilter> Make();
|
||||
|
||||
void filterSpan(const SkPMColor src[], int count, SkPMColor[]) const override;
|
||||
void filterSpan4f(const SkPM4f src[], int count, SkPM4f result[]) const override;
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
sk_sp<GrFragmentProcessor> asFragmentProcessor(GrContext*, SkColorSpace*) const override;
|
||||
|
@ -61,7 +61,7 @@ void SkColorFilter::onAppendStages(SkRasterPipeline* p,
|
||||
ctx->fn = [](SkJumper_CallbackCtx* arg, int active_pixels) {
|
||||
auto ctx = (Ctx*)arg;
|
||||
auto buf = (SkPM4f*)ctx->rgba;
|
||||
ctx->cf->filterSpan4f(buf, active_pixels, buf);
|
||||
ctx->cf->onFilterStage(buf, active_pixels, buf);
|
||||
};
|
||||
p->append(SkRasterPipeline::callback, ctx);
|
||||
}
|
||||
@ -72,9 +72,19 @@ SkColor SkColorFilter::filterColor(SkColor c) const {
|
||||
return SkUnPreMultiply::PMColorToColor(dst);
|
||||
}
|
||||
|
||||
#include "SkRasterPipeline.h"
|
||||
SkColor4f SkColorFilter::filterColor4f(const SkColor4f& c) const {
|
||||
SkPM4f dst, src = c.premul();
|
||||
this->filterSpan4f(&src, 1, &dst);
|
||||
|
||||
SkSTArenaAlloc<128> alloc;
|
||||
SkRasterPipeline pipeline(&alloc);
|
||||
|
||||
pipeline.append(SkRasterPipeline::constant_color, &src);
|
||||
this->onAppendStages(&pipeline, nullptr, &alloc, c.fA == 1);
|
||||
SkPM4f* dstPtr = &dst;
|
||||
pipeline.append(SkRasterPipeline::store_f32, &dstPtr);
|
||||
pipeline.run(0,1);
|
||||
|
||||
return dst.unpremul();
|
||||
}
|
||||
|
||||
@ -102,11 +112,6 @@ public:
|
||||
fOuter->filterSpan(result, count, result);
|
||||
}
|
||||
|
||||
void filterSpan4f(const SkPM4f shader[], int count, SkPM4f result[]) const override {
|
||||
fInner->filterSpan4f(shader, count, result);
|
||||
fOuter->filterSpan4f(result, count, result);
|
||||
}
|
||||
|
||||
#ifndef SK_IGNORE_TO_STRING
|
||||
void toString(SkString* str) const override {
|
||||
SkString outerS, innerS;
|
||||
|
@ -137,24 +137,6 @@ void SkColorMatrixFilterRowMajor255::filterSpan(const SkPMColor src[], int count
|
||||
filter_span<SkPMColorAdaptor>(fTranspose, src, count, dst);
|
||||
}
|
||||
|
||||
struct SkPM4fAdaptor {
|
||||
enum {
|
||||
R = SkPM4f::R,
|
||||
G = SkPM4f::G,
|
||||
B = SkPM4f::B,
|
||||
A = SkPM4f::A,
|
||||
};
|
||||
static SkPM4f From4f(const Sk4f& c4) {
|
||||
return SkPM4f::From4f(c4);
|
||||
}
|
||||
static Sk4f To4f(const SkPM4f& c) {
|
||||
return c.to4f();
|
||||
}
|
||||
};
|
||||
void SkColorMatrixFilterRowMajor255::filterSpan4f(const SkPM4f src[], int count, SkPM4f dst[]) const {
|
||||
filter_span<SkPM4fAdaptor>(fTranspose, src, count, dst);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void SkColorMatrixFilterRowMajor255::flatten(SkWriteBuffer& buffer) const {
|
||||
|
@ -19,7 +19,6 @@ public:
|
||||
static sk_sp<SkColorFilter> MakeSingleChannelOutput(const SkScalar row[5]);
|
||||
|
||||
void filterSpan(const SkPMColor src[], int count, SkPMColor[]) const override;
|
||||
void filterSpan4f(const SkPM4f src[], int count, SkPM4f[]) const override;
|
||||
uint32_t getFlags() const override;
|
||||
bool asColorMatrix(SkScalar matrix[20]) const override;
|
||||
sk_sp<SkColorFilter> makeComposed(sk_sp<SkColorFilter>) const override;
|
||||
|
@ -64,14 +64,6 @@ void SkModeColorFilter::filterSpan(const SkPMColor shader[], int count, SkPMColo
|
||||
}
|
||||
}
|
||||
|
||||
void SkModeColorFilter::filterSpan4f(const SkPM4f shader[], int count, SkPM4f result[]) const {
|
||||
SkXfermodeProc4f proc = SkXfermode::GetProc4f(fMode);
|
||||
auto pm4f = fPMColor4f;
|
||||
for (int i = 0; i < count; i++) {
|
||||
result[i] = proc(pm4f, shader[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void SkModeColorFilter::flatten(SkWriteBuffer& buffer) const {
|
||||
buffer.writeColor(fColor);
|
||||
buffer.writeUInt((int)fMode);
|
||||
@ -167,21 +159,6 @@ private:
|
||||
typedef SkModeColorFilter INHERITED;
|
||||
};
|
||||
|
||||
class Modulate_SkModeColorFilter final : public SkModeColorFilter {
|
||||
public:
|
||||
Modulate_SkModeColorFilter(SkColor color) : INHERITED(color, SkBlendMode::kModulate) { }
|
||||
|
||||
void filterSpan4f(const SkPM4f shader[], int count, SkPM4f result[]) const override {
|
||||
auto pm4f = fPMColor4f.to4f();
|
||||
for (int i = 0; i < count; i++) {
|
||||
(pm4f * shader[i].to4f()).store(result[i].fVec);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
typedef SkModeColorFilter INHERITED;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
sk_sp<SkColorFilter> SkColorFilter::MakeModeFilter(SkColor color, SkBlendMode mode) {
|
||||
@ -222,8 +199,6 @@ sk_sp<SkColorFilter> SkColorFilter::MakeModeFilter(SkColor color, SkBlendMode mo
|
||||
return sk_make_sp<Src_SkModeColorFilter>(color);
|
||||
case SkBlendMode::kSrcOver:
|
||||
return sk_make_sp<SrcOver_SkModeColorFilter>(color);
|
||||
case SkBlendMode::kModulate:
|
||||
return sk_make_sp<Modulate_SkModeColorFilter>(color);
|
||||
default:
|
||||
return SkModeColorFilter::Make(color, mode);
|
||||
}
|
||||
|
@ -24,7 +24,6 @@ public:
|
||||
bool asColorMode(SkColor*, SkBlendMode*) const override;
|
||||
uint32_t getFlags() const override;
|
||||
void filterSpan(const SkPMColor shader[], int count, SkPMColor result[]) const override;
|
||||
void filterSpan4f(const SkPM4f shader[], int count, SkPM4f result[]) const override;
|
||||
|
||||
#ifndef SK_IGNORE_TO_STRING
|
||||
void toString(SkString* str) const override;
|
||||
|
@ -47,9 +47,6 @@ public:
|
||||
void filterSpan(const SkPMColor src[], int count, SkPMColor dst[]) const override {
|
||||
fMatrixFilter->filterSpan(src, count, dst);
|
||||
}
|
||||
void filterSpan4f(const SkPM4f src[], int count, SkPM4f dst[]) const override {
|
||||
fMatrixFilter->filterSpan4f(src, count, dst);
|
||||
}
|
||||
uint32_t getFlags() const override {
|
||||
return fMatrixFilter->getFlags();
|
||||
}
|
||||
|
@ -144,7 +144,6 @@ public:
|
||||
#endif
|
||||
|
||||
void filterSpan(const SkPMColor src[], int count, SkPMColor dst[]) const override;
|
||||
void filterSpan4f(const SkPM4f src[], int count, SkPM4f result[]) const override;
|
||||
void onAppendStages(SkRasterPipeline* p,
|
||||
SkColorSpace* dst,
|
||||
SkArenaAlloc* scratch,
|
||||
@ -179,12 +178,6 @@ void SkHighContrast_Filter::filterSpan(const SkPMColor src[], int count, SkPMCol
|
||||
}
|
||||
}
|
||||
|
||||
void SkHighContrast_Filter::filterSpan4f(const SkPM4f src[], int count, SkPM4f dst[]) const {
|
||||
for (int i = 0; i < count; ++i) {
|
||||
dst[i] = ApplyHighContrastFilter(fConfig, dst[i].unpremul()).premul();
|
||||
}
|
||||
}
|
||||
|
||||
void SkHighContrast_Filter::onAppendStages(SkRasterPipeline* p,
|
||||
SkColorSpace* dstCS,
|
||||
SkArenaAlloc* alloc,
|
||||
|
@ -36,25 +36,6 @@ void SkLumaColorFilter::filterSpan(const SkPMColor src[], int count, SkPMColor d
|
||||
}
|
||||
}
|
||||
|
||||
void SkLumaColorFilter::filterSpan4f(const SkPM4f src[], int count, SkPM4f dst[]) const {
|
||||
for (int i = 0; i < count; ++i) {
|
||||
/*
|
||||
* While LuminanceToAlpha is defined to operate on un-premultiplied
|
||||
* inputs, due to the final alpha scaling it can be computed based on
|
||||
* premultipled components:
|
||||
*
|
||||
* LumA = (k1 * r / a + k2 * g / a + k3 * b / a) * a
|
||||
* LumA = (k1 * r + k2 * g + k3 * b)
|
||||
*/
|
||||
dst[i].fVec[SkPM4f::R] = 0;
|
||||
dst[i].fVec[SkPM4f::G] = 0;
|
||||
dst[i].fVec[SkPM4f::B] = 0;
|
||||
dst[i].fVec[SkPM4f::A] = src[i].r() * SK_LUM_COEFF_R +
|
||||
src[i].g() * SK_LUM_COEFF_G +
|
||||
src[i].b() * SK_LUM_COEFF_B;
|
||||
}
|
||||
}
|
||||
|
||||
void SkLumaColorFilter::onAppendStages(SkRasterPipeline* p,
|
||||
SkColorSpace* dst,
|
||||
SkArenaAlloc* scratch,
|
||||
|
@ -20,7 +20,7 @@ void SkOverdrawColorFilter::filterSpan(const SkPMColor src[], int count, SkPMCol
|
||||
}
|
||||
}
|
||||
|
||||
void SkOverdrawColorFilter::filterSpan4f(const SkPM4f src[], int count, SkPM4f dst[]) const {
|
||||
void SkOverdrawColorFilter::onFilterStage(const SkPM4f src[], int count, SkPM4f dst[]) const {
|
||||
for (int i = 0; i < count; ++i) {
|
||||
uint8_t alpha = (int)(src[i].a() * 255);
|
||||
if (alpha >= kNumColors) {
|
||||
|
@ -32,7 +32,6 @@ public:
|
||||
#endif
|
||||
|
||||
void filterSpan(const SkPMColor src[], int count, SkPMColor dst[]) const override;
|
||||
void filterSpan4f(const SkPM4f src[], int count, SkPM4f result[]) const override;
|
||||
void toString(SkString* str) const override;
|
||||
|
||||
static sk_sp<SkFlattenable> CreateProc(SkReadBuffer& buffer);
|
||||
@ -47,6 +46,8 @@ private:
|
||||
memcpy(fColors, colors, kNumColors * sizeof(SkPMColor));
|
||||
}
|
||||
|
||||
void onFilterStage(const SkPM4f src[], int count, SkPM4f result[]) const override;
|
||||
|
||||
SkPMColor fColors[kNumColors];
|
||||
|
||||
typedef SkColorFilter INHERITED;
|
||||
|
@ -90,7 +90,6 @@ public:
|
||||
#endif
|
||||
|
||||
void filterSpan(const SkPMColor src[], int count, SkPMColor dst[]) const override;
|
||||
void filterSpan4f(const SkPM4f src[], int count, SkPM4f result[]) const override;
|
||||
|
||||
SK_TO_STRING_OVERRIDE()
|
||||
|
||||
@ -185,41 +184,6 @@ void SkTable_ColorFilter::filterSpan(const SkPMColor src[], int count, SkPMColor
|
||||
}
|
||||
}
|
||||
|
||||
void SkTable_ColorFilter::filterSpan4f(const SkPM4f src[], int count, SkPM4f dst[]) const {
|
||||
const uint8_t* table = fStorage;
|
||||
const uint8_t* tableA = gIdentityTable;
|
||||
const uint8_t* tableR = gIdentityTable;
|
||||
const uint8_t* tableG = gIdentityTable;
|
||||
const uint8_t* tableB = gIdentityTable;
|
||||
if (fFlags & kA_Flag) {
|
||||
tableA = table; table += 256;
|
||||
}
|
||||
if (fFlags & kR_Flag) {
|
||||
tableR = table; table += 256;
|
||||
}
|
||||
if (fFlags & kG_Flag) {
|
||||
tableG = table; table += 256;
|
||||
}
|
||||
if (fFlags & kB_Flag) {
|
||||
tableB = table;
|
||||
}
|
||||
|
||||
const float oneOver255 = 1.0f / 255;
|
||||
for (int i = 0; i < count; ++i) {
|
||||
SkColor4f c = src[i].unpremul();
|
||||
int r = (int)(c.fR * 255.999) & 0xFF;
|
||||
int g = (int)(c.fG * 255.999) & 0xFF;
|
||||
int b = (int)(c.fB * 255.999) & 0xFF;
|
||||
int a = (int)(c.fA * 255.999) & 0xFF;
|
||||
|
||||
SkColor4f d {
|
||||
tableR[r] * oneOver255, tableG[g] * oneOver255,
|
||||
tableB[b] * oneOver255, tableA[a] * oneOver255,
|
||||
};
|
||||
dst[i] = d.premul();
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef SK_IGNORE_TO_STRING
|
||||
void SkTable_ColorFilter::toString(SkString* str) const {
|
||||
const uint8_t* table = fStorage;
|
||||
|
@ -95,10 +95,8 @@ void SkColorFilterShader::FilterShaderContext::shadeSpan(int x, int y, SkPMColor
|
||||
|
||||
void SkColorFilterShader::FilterShaderContext::shadeSpan4f(int x, int y, SkPM4f result[],
|
||||
int count) {
|
||||
const SkColorFilterShader& filterShader = static_cast<const SkColorFilterShader&>(fShader);
|
||||
|
||||
fShaderContext->shadeSpan4f(x, y, result, count);
|
||||
filterShader.fFilter->filterSpan4f(result, count, result);
|
||||
// Should never get here, as shadeSpan4f should only be called if stages fails
|
||||
SkASSERT(false);
|
||||
}
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
|
@ -38,7 +38,6 @@ public:
|
||||
}
|
||||
|
||||
void filterSpan(const SkPMColor src[], int count, SkPMColor dst[]) const override;
|
||||
void filterSpan4f(const SkPM4f src[], int count, SkPM4f result[]) const override;
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
sk_sp<GrFragmentProcessor> asFragmentProcessor(GrContext*, SkColorSpace*) const override;
|
||||
@ -128,13 +127,6 @@ void SkGaussianColorFilter::filterSpan(const SkPMColor src[], int count, SkPMCol
|
||||
}
|
||||
}
|
||||
|
||||
void SkGaussianColorFilter::filterSpan4f(const SkPM4f src[], int count, SkPM4f dst[]) const {
|
||||
for (int i = 0; i < count; ++i) {
|
||||
float v = eval_gaussian(src[i].a());
|
||||
dst[i] = SkPM4f::FromPremulRGBA(v, v, v, v);
|
||||
}
|
||||
}
|
||||
|
||||
sk_sp<SkFlattenable> SkGaussianColorFilter::CreateProc(SkReadBuffer&) {
|
||||
return Make();
|
||||
}
|
||||
|
@ -40,9 +40,6 @@ public:
|
||||
void filterSpan(const SkPMColor src[], int count, SkPMColor dst[]) const override {
|
||||
SK_ABORT("SkSRGBColorFilter is only implemented for GPU");
|
||||
}
|
||||
void filterSpan4f(const SkPM4f src[], int count, SkPM4f dst[]) const override {
|
||||
SK_ABORT("SkSRGBColorFilter is only implemented for GPU");
|
||||
}
|
||||
Factory getFactory() const override { return nullptr; }
|
||||
|
||||
#ifndef SK_IGNORE_TO_STRING
|
||||
|
Loading…
Reference in New Issue
Block a user