Add missing flattenable registrations and CreateProc() functions;

fixes gm --serialize xfermode test case.



git-svn-id: http://skia.googlecode.com/svn/trunk@1199 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
tomhudson@google.com 2011-04-27 14:09:52 +00:00
parent 938d604026
commit 1447c6f7f4
10 changed files with 226 additions and 173 deletions

View File

@ -72,8 +72,8 @@ public:
* which is virtual.
*/
SkColor filterColor(SkColor);
/** Create a colorfilter that uses the specified color and mode.
If the Mode is DST, this function will return NULL (since that
mode will have no effect on the result).
@ -103,7 +103,7 @@ public:
protected:
SkColorFilter() {}
SkColorFilter(SkFlattenableReadBuffer& rb) : INHERITED(rb) {}
private:
typedef SkFlattenable INHERITED;
};
@ -123,17 +123,17 @@ public:
virtual void shadeSpan16(int x, int y, uint16_t result[], int count);
virtual void beginSession();
virtual void endSession();
protected:
SkFilterShader(SkFlattenableReadBuffer& );
virtual void flatten(SkFlattenableWriteBuffer& );
virtual Factory getFactory() { return CreateProc; }
private:
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(SkFilterShader, (buffer)); }
SkShader* fShader;
SkColorFilter* fFilter;
typedef SkShader INHERITED;
};

View File

@ -40,7 +40,7 @@ public:
const SkAlpha aa[]);
virtual void xferA8(SkAlpha dst[], const SkPMColor src[], int count,
const SkAlpha aa[]);
/** Enum of possible coefficients to describe some xfermodes
*/
enum Coeff {
@ -54,18 +54,18 @@ public:
kISA_Coeff, /** inverse src alpha (i.e. 1 - sa) */
kDA_Coeff, /** dst alpha */
kIDA_Coeff, /** inverse dst alpha (i.e. 1 - da) */
kCoeffCount
};
/** If the xfermode can be expressed as an equation using the coefficients
in Coeff, then asCoeff() returns true, and sets (if not null) src and
dst accordingly.
result = src_coeff * src_color + dst_coeff * dst_color;
As examples, here are some of the porterduff coefficients
MODE SRC_COEFF DST_COEFF
clear zero zero
src one zero
@ -80,7 +80,7 @@ public:
* if the xfermode is NULL, and if so, treats its as kSrcOver_Mode.
*/
static bool AsCoeff(SkXfermode*, Coeff* src, Coeff* dst);
/** List of predefined xfermodes.
The algebra for the modes uses the following symbols:
Sa, Sc - source alpha and color
@ -149,7 +149,7 @@ public:
16bit proc, and this will return NULL.
*/
static SkXfermodeProc16 GetProc16(Mode mode, SkColor srcColor);
/**
* If the specified mode can be represented by a pair of Coeff, then return
* true and set (if not NULL) the corresponding coeffs. If the mode is
@ -162,15 +162,15 @@ public:
static bool IsMode(SkXfermode* xfer, Mode* mode) {
return AsMode(xfer, mode);
}
protected:
SkXfermode(SkFlattenableReadBuffer& rb) : SkFlattenable(rb) {}
/** The default implementation of xfer32/xfer16/xferA8 in turn call this
method, 1 color at a time (upscaled to a SkPMColor). The default
implmentation of this method just returns dst. If performance is
important, your subclass should override xfer32/xfer16/xferA8 directly.
This method will not be called directly by the client, so it need not
be implemented if your subclass has overridden xfer32/xfer16/xferA8
*/
@ -213,7 +213,7 @@ protected:
private:
SkXfermodeProc fProc;
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(SkProcXfermode, (buffer)); }
@ -221,4 +221,3 @@ private:
};
#endif

View File

@ -33,14 +33,14 @@ public:
/** This xfermode draws, or doesn't draw, based on the destination's
distance from an op-color.
There are two modes, and each mode interprets a tolerance value.
Avoid: In this mode, drawing is allowed only on destination pixels that
are different from the op-color.
Tolerance near 0: avoid any colors even remotely similar to the op-color
Tolerance near 255: avoid only colors nearly identical to the op-color
Target: In this mode, drawing only occurs on destination pixels that
are similar to the op-color
Tolerance near 0: draw only on colors that are nearly identical to the op-color
@ -62,6 +62,10 @@ public:
virtual Factory getFactory();
virtual void flatten(SkFlattenableWriteBuffer&);
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(SkAvoidXfermode, (buffer));
}
protected:
SkAvoidXfermode(SkFlattenableReadBuffer&);
@ -69,9 +73,9 @@ private:
SkColor fOpColor;
uint32_t fDistMul; // x.14
Mode fMode;
static SkFlattenable* Create(SkFlattenableReadBuffer&);
typedef SkXfermode INHERITED;
};

View File

@ -25,15 +25,15 @@ public:
SkColorMatrixFilter();
explicit SkColorMatrixFilter(const SkColorMatrix&);
SkColorMatrixFilter(const SkScalar array[20]);
void setMatrix(const SkColorMatrix&);
void setArray(const SkScalar array[20]);
// overrides from SkColorFilter
virtual void filterSpan(const SkPMColor src[], int count, SkPMColor[]);
virtual void filterSpan16(const uint16_t src[], int count, uint16_t[]);
virtual uint32_t getFlags();
// overrides for SkFlattenable
virtual void flatten(SkFlattenableWriteBuffer& buffer);
@ -43,14 +43,15 @@ public:
int32_t fResult[4];
};
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer);
protected:
// overrides for SkFlattenable
virtual Factory getFactory();
SkColorMatrixFilter(SkFlattenableReadBuffer& buffer);
private:
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer);
typedef void (*Proc)(State*, unsigned r, unsigned g, unsigned b,
unsigned a);
@ -58,9 +59,9 @@ private:
Proc fProc;
State fState;
uint32_t fFlags;
void setup(const SkScalar array[20]);
typedef SkColorFilter INHERITED;
};

View File

@ -32,6 +32,10 @@ public:
virtual Factory getFactory();
virtual void flatten(SkFlattenableWriteBuffer&);
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(SkPixelXorXfermode, (buffer));
}
protected:
// override from SkXfermode
virtual SkPMColor xferColor(SkPMColor src, SkPMColor dst);
@ -47,4 +51,3 @@ private:
};
#endif

View File

@ -98,7 +98,7 @@ static SkPMColor dst_modeproc(SkPMColor src, SkPMColor dst) {
return dst;
}
// kSrcOver_Mode, //!< [Sa + Da - Sa*Da, Sc + (1 - Sa)*Dc]
// kSrcOver_Mode, //!< [Sa + Da - Sa*Da, Sc + (1 - Sa)*Dc]
static SkPMColor srcover_modeproc(SkPMColor src, SkPMColor dst) {
#if 0
// this is the old, more-correct way, but it doesn't guarantee that dst==255
@ -335,7 +335,7 @@ static SkPMColor colorburn_modeproc(SkPMColor src, SkPMColor dst) {
if (0 == dst) {
return src;
}
int sa = SkGetPackedA32(src);
int da = SkGetPackedA32(dst);
int a = srcover_byte(sa, da);
@ -531,7 +531,7 @@ void SkXfermode::xfer4444(SK_RESTRICT SkPMColor16 dst[],
const SK_RESTRICT SkAlpha aa[])
{
SkASSERT(dst && src && count >= 0);
if (NULL == aa) {
for (int i = count - 1; i >= 0; --i) {
SkPMColor dstC = SkPixel4444ToPixel32(dst[i]);
@ -642,7 +642,7 @@ void SkProcXfermode::xfer4444(SK_RESTRICT SkPMColor16 dst[],
const SK_RESTRICT SkPMColor src[], int count,
const SK_RESTRICT SkAlpha aa[]) {
SkASSERT(dst && src && count >= 0);
SkXfermodeProc proc = fProc;
if (NULL != proc) {
@ -739,7 +739,7 @@ public:
}
return true;
}
virtual Factory getFactory() { return CreateProc; }
virtual void flatten(SkFlattenableWriteBuffer& buffer) {
this->INHERITED::flatten(buffer);
@ -748,6 +748,10 @@ public:
buffer.write32(fDstCoeff);
}
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(SkProcCoeffXfermode, (buffer));
}
protected:
SkProcCoeffXfermode(SkFlattenableReadBuffer& buffer)
: INHERITED(buffer) {
@ -755,13 +759,11 @@ protected:
fSrcCoeff = (Coeff)buffer.readU32();
fDstCoeff = (Coeff)buffer.readU32();
}
private:
Mode fMode;
Coeff fSrcCoeff, fDstCoeff;
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(SkProcCoeffXfermode, (buffer)); }
typedef SkProcXfermode INHERITED;
};
@ -808,16 +810,17 @@ public:
}
}
}
virtual Factory getFactory() { return CreateProc; }
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(SkClearXfermode, (buffer));
}
private:
SkClearXfermode(SkFlattenableReadBuffer& buffer)
: SkProcCoeffXfermode(buffer) {}
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(SkClearXfermode, (buffer));
}
};
///////////////////////////////////////////////////////////////////////////////
@ -868,34 +871,35 @@ public:
}
}
}
virtual Factory getFactory() { return CreateProc; }
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(SkSrcXfermode, (buffer));
}
private:
SkSrcXfermode(SkFlattenableReadBuffer& buffer)
: SkProcCoeffXfermode(buffer) {}
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(SkSrcXfermode, (buffer));
}
};
class SkDstInXfermode : public SkProcCoeffXfermode {
public:
SkDstInXfermode(const ProcCoeff& rec) : SkProcCoeffXfermode(rec, kDstIn_Mode) {}
virtual void xfer32(SK_RESTRICT SkPMColor dst[],
const SK_RESTRICT SkPMColor src[], int count,
const SK_RESTRICT SkAlpha aa[]) {
SkASSERT(dst && src);
if (count <= 0) {
return;
}
if (NULL != aa) {
return this->INHERITED::xfer32(dst, src, count, aa);
}
do {
unsigned a = SkGetPackedA32(*src);
*dst = SkAlphaMulQ(*dst, SkAlpha255To256(a));
@ -903,35 +907,35 @@ public:
src++;
} while (--count != 0);
}
virtual Factory getFactory() { return CreateProc; }
private:
SkDstInXfermode(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {}
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(SkDstInXfermode, (buffer));
}
private:
SkDstInXfermode(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {}
typedef SkProcCoeffXfermode INHERITED;
};
class SkDstOutXfermode : public SkProcCoeffXfermode {
public:
SkDstOutXfermode(const ProcCoeff& rec) : SkProcCoeffXfermode(rec, kDstOut_Mode) {}
virtual void xfer32(SK_RESTRICT SkPMColor dst[],
const SK_RESTRICT SkPMColor src[], int count,
const SK_RESTRICT SkAlpha aa[]) {
SkASSERT(dst && src);
if (count <= 0) {
return;
}
if (NULL != aa) {
return this->INHERITED::xfer32(dst, src, count, aa);
}
do {
unsigned a = SkGetPackedA32(*src);
*dst = SkAlphaMulQ(*dst, SkAlpha255To256(255 - a));
@ -939,17 +943,17 @@ public:
src++;
} while (--count != 0);
}
virtual Factory getFactory() { return CreateProc; }
private:
SkDstOutXfermode(SkFlattenableReadBuffer& buffer)
: INHERITED(buffer) {}
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(SkDstOutXfermode, (buffer));
}
private:
SkDstOutXfermode(SkFlattenableReadBuffer& buffer)
: INHERITED(buffer) {}
typedef SkProcCoeffXfermode INHERITED;
};
@ -987,18 +991,18 @@ SkXfermodeProc SkXfermode::GetProc(Mode mode) {
bool SkXfermode::ModeAsCoeff(Mode mode, Coeff* src, Coeff* dst) {
SkASSERT(SK_ARRAY_COUNT(gProcCoeffs) == kModeCount);
if ((unsigned)mode >= (unsigned)kModeCount) {
// illegal mode parameter
return false;
}
const ProcCoeff& rec = gProcCoeffs[mode];
if (CANNOT_USE_COEFF == rec.fSC) {
return false;
}
SkASSERT(CANNOT_USE_COEFF != rec.fDC);
if (src) {
*src = rec.fSC;
@ -1080,7 +1084,7 @@ static uint16_t dstout_modeproc16_0(SkPMColor src, uint16_t dst) {
static uint16_t srcatop_modeproc16(SkPMColor src, uint16_t dst) {
unsigned isa = 255 - SkGetPackedA32(src);
return SkPackRGB16(
SkPacked32ToR16(src) + SkAlphaMulAlpha(SkGetPackedR16(dst), isa),
SkPacked32ToG16(src) + SkAlphaMulAlpha(SkGetPackedG16(dst), isa),
@ -1194,3 +1198,18 @@ SkXfermodeProc16 SkXfermode::GetProc16(Mode mode, SkColor srcColor) {
return proc16;
}
static SkFlattenable::Registrar
gSkProcCoeffXfermodeReg("SkProcCoeffXfermode",
SkProcCoeffXfermode::CreateProc);
static SkFlattenable::Registrar
gSkClearXfermodeReg("SkClearXfermode", SkClearXfermode::CreateProc);
static SkFlattenable::Registrar
gSkSrcXfermodeReg("SkSrcXfermode", SkSrcXfermode::CreateProc);
static SkFlattenable::Registrar
gSkDstInXfermodeReg("SkDstInXfermode", SkDstInXfermode::CreateProc);
static SkFlattenable::Registrar
gSkDstOutXfermodeReg("SkDstOutXfermode", SkDstOutXfermode::CreateProc);

View File

@ -2,16 +2,16 @@
**
** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
@ -19,7 +19,7 @@
#include "SkColorPriv.h"
SkAvoidXfermode::SkAvoidXfermode(SkColor opColor, U8CPU tolerance, Mode mode)
{
{
if (tolerance > 255) {
tolerance = 255;
}
@ -66,7 +66,7 @@ static unsigned color_dist16(uint16_t c, unsigned r, unsigned g, unsigned b)
unsigned dr = SkAbs32(SkGetPackedR16(c) - r);
unsigned dg = SkAbs32(SkGetPackedG16(c) - g) >> (SK_G16_BITS - SK_R16_BITS);
unsigned db = SkAbs32(SkGetPackedB16(c) - b);
return SkMax32(dr, SkMax32(dg, db));
}
@ -76,11 +76,11 @@ static unsigned color_dist4444(uint16_t c, unsigned r, unsigned g, unsigned b)
SkASSERT(r <= 0xF);
SkASSERT(g <= 0xF);
SkASSERT(b <= 0xF);
unsigned dr = SkAbs32(SkGetPackedR4444(c) - r);
unsigned dg = SkAbs32(SkGetPackedG4444(c) - g);
unsigned db = SkAbs32(SkGetPackedB4444(c) - b);
return SkMax32(dr, SkMax32(dg, db));
}
@ -94,7 +94,7 @@ static unsigned color_dist32(SkPMColor c, U8CPU r, U8CPU g, U8CPU b)
unsigned dr = SkAbs32(SkGetPackedR32(c) - r);
unsigned dg = SkAbs32(SkGetPackedG32(c) - g);
unsigned db = SkAbs32(SkGetPackedB32(c) - b);
return SkMax32(dr, SkMax32(dg, db));
}
@ -128,9 +128,9 @@ void SkAvoidXfermode::xfer32(SkPMColor dst[], const SkPMColor src[], int count,
unsigned opB = SkColorGetB(fOpColor);
uint32_t mul = fDistMul;
uint32_t sub = (fDistMul - (1 << 14)) << 8;
int MAX, mask;
if (kTargetColor_Mode == fMode) {
mask = -1;
MAX = 255;
@ -138,17 +138,17 @@ void SkAvoidXfermode::xfer32(SkPMColor dst[], const SkPMColor src[], int count,
mask = 0;
MAX = 0;
}
for (int i = 0; i < count; i++) {
int d = color_dist32(dst[i], opR, opG, opB);
// now reverse d if we need to
d = MAX + (d ^ mask) - mask;
SkASSERT((unsigned)d <= 255);
d = Accurate255To256(d);
d = scale_dist_14(d, mul, sub);
SkASSERT(d <= 256);
if (d > 0) {
if (NULL != aa) {
d = SkAlphaMul(d, Accurate255To256(*aa++));
@ -181,7 +181,7 @@ void SkAvoidXfermode::xfer16(uint16_t dst[], const SkPMColor src[], int count,
uint32_t sub = (fDistMul - (1 << 14)) << SK_R16_BITS;
int MAX, mask;
if (kTargetColor_Mode == fMode) {
mask = -1;
MAX = 31;
@ -220,9 +220,9 @@ void SkAvoidXfermode::xfer4444(uint16_t dst[], const SkPMColor src[], int count,
unsigned opB = SkColorGetB(fOpColor) >> 4;
uint32_t mul = fDistMul;
uint32_t sub = (fDistMul - (1 << 14)) << 4;
int MAX, mask;
if (kTargetColor_Mode == fMode) {
mask = -1;
MAX = 15;
@ -230,7 +230,7 @@ void SkAvoidXfermode::xfer4444(uint16_t dst[], const SkPMColor src[], int count,
mask = 0;
MAX = 0;
}
for (int i = 0; i < count; i++) {
int d = color_dist4444(dst[i], opR, opG, opB);
// now reverse d if we need to
@ -240,7 +240,7 @@ void SkAvoidXfermode::xfer4444(uint16_t dst[], const SkPMColor src[], int count,
d += d >> 3;
d = scale_dist_14(d, mul, sub);
SkASSERT(d <= 16);
if (d > 0) {
if (NULL != aa) {
d = SkAlphaMul(d, Accurate255To256(*aa++));
@ -258,3 +258,5 @@ void SkAvoidXfermode::xferA8(SkAlpha dst[], const SkPMColor src[], int count, co
// override in subclass
}
static SkFlattenable::Registrar
gSkAvoidXfermodeReg("SkAvoidXfermode", SkAvoidXfermode::CreateProc);

View File

@ -37,7 +37,7 @@ public:
fPMColor = SkPreMultiplyColor(fColor);
};
virtual bool asColorMode(SkColor* color, SkXfermode::Mode* mode) {
if (ILLEGAL_XFERMODE_MODE == fMode) {
return false;
@ -58,10 +58,11 @@ public:
protected:
virtual void flatten(SkFlattenableWriteBuffer& buffer) {
this->INHERITED::flatten(buffer);
buffer.write32(fColor);
buffer.write32(fMode);
}
SkModeColorFilter(SkFlattenableReadBuffer& buffer) {
fColor = buffer.readU32();
fMode = (SkXfermode::Mode)buffer.readU32();
@ -75,6 +76,8 @@ protected:
private:
SkColor fColor;
SkXfermode::Mode fMode;
typedef SkColorFilter INHERITED;
};
class Src_SkModeColorFilter : public SkModeColorFilter {
@ -100,17 +103,17 @@ public:
sk_memset16(result, SkPixel32ToPixel16(fPMColor), count);
}
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(Src_SkModeColorFilter, (buffer));
}
protected:
virtual Factory getFactory() { return CreateProc; }
Src_SkModeColorFilter(SkFlattenableReadBuffer& buffer)
: INHERITED(buffer) {}
private:
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(Src_SkModeColorFilter, (buffer));
}
private:
typedef SkModeColorFilter INHERITED;
};
@ -128,7 +131,7 @@ public:
return 0;
}
}
virtual void filterSpan(const SkPMColor shader[], int count,
SkPMColor result[]) {
if (NULL == fColor32Proc) {
@ -142,18 +145,19 @@ public:
SkASSERT(this->getFlags() & kHasFilter16_Flag);
sk_memset16(result, SkPixel32ToPixel16(fPMColor), count);
}
protected:
virtual Factory getFactory() { return CreateProc; }
SrcOver_SkModeColorFilter(SkFlattenableReadBuffer& buffer)
: INHERITED(buffer), fColor32Proc(NULL) {}
private:
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(SrcOver_SkModeColorFilter, (buffer));
}
protected:
virtual Factory getFactory() { return CreateProc; }
SrcOver_SkModeColorFilter(SkFlattenableReadBuffer& buffer)
: INHERITED(buffer), fColor32Proc(NULL) {}
private:
SkBlitRow::ColorProc fColor32Proc;
typedef SkModeColorFilter INHERITED;
@ -167,14 +171,14 @@ public:
fProc = SkXfermode::GetProc(mode);
fProc16 = SkXfermode::GetProc16(mode, color);
}
Proc_SkModeColorFilter(SkColor color,
SkXfermodeProc proc, SkXfermodeProc16 proc16)
: INHERITED(color, ILLEGAL_XFERMODE_MODE) {
fProc = proc;
fProc16 = proc16;
}
virtual uint32_t getFlags() {
return fProc16 ? (kAlphaUnchanged_Flag | kHasFilter16_Flag) : 0;
}
@ -188,27 +192,31 @@ public:
result[i] = proc(color, shader[i]);
}
}
virtual void filterSpan16(const uint16_t shader[], int count,
uint16_t result[]) {
SkASSERT(this->getFlags() & kHasFilter16_Flag);
SkPMColor color = fPMColor;
SkXfermodeProc16 proc16 = fProc16;
for (int i = 0; i < count; i++) {
result[i] = proc16(color, shader[i]);
}
}
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(Proc_SkModeColorFilter, (buffer));
}
protected:
virtual void flatten(SkFlattenableWriteBuffer& buffer) {
this->INHERITED::flatten(buffer);
buffer.writeFunctionPtr((void*)fProc);
buffer.writeFunctionPtr((void*)fProc16);
}
virtual Factory getFactory() {
virtual Factory getFactory() {
return CreateProc;
}
@ -218,13 +226,9 @@ protected:
}
private:
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(Proc_SkModeColorFilter, (buffer));
}
SkXfermodeProc fProc;
SkXfermodeProc16 fProc16;
typedef SkModeColorFilter INHERITED;
};
@ -267,7 +271,7 @@ SkColorFilter* SkColorFilter::CreateModeFilter(SkColor color,
(0xFF == alpha && SkXfermode::kDstIn_Mode == mode)) {
return NULL;
}
switch (mode) {
case SkXfermode::kSrc_Mode:
return SkNEW_ARGS(Src_SkModeColorFilter, (color));
@ -307,7 +311,7 @@ public:
unsigned scaleR = SkAlpha255To256(SkColorGetR(fMul));
unsigned scaleG = SkAlpha255To256(SkColorGetG(fMul));
unsigned scaleB = SkAlpha255To256(SkColorGetB(fMul));
unsigned addR = SkColorGetR(fAdd);
unsigned addG = SkColorGetG(fAdd);
unsigned addB = SkColorGetB(fAdd);
@ -316,7 +320,7 @@ public:
SkPMColor c = shader[i];
if (c) {
unsigned a = SkGetPackedA32(c);
unsigned scaleA = SkAlpha255To256(a);
unsigned scaleA = SkAlpha255To256(a);
unsigned r = pin(SkAlphaMul(SkGetPackedR32(c), scaleR) + SkAlphaMul(addR, scaleA), a);
unsigned g = pin(SkAlphaMul(SkGetPackedG32(c), scaleG) + SkAlphaMul(addG, scaleA), a);
unsigned b = pin(SkAlphaMul(SkGetPackedB32(c), scaleB) + SkAlphaMul(addB, scaleA), a);
@ -328,10 +332,11 @@ public:
protected:
virtual void flatten(SkFlattenableWriteBuffer& buffer) {
this->INHERITED::flatten(buffer);
buffer.write32(fMul);
buffer.write32(fAdd);
}
virtual Factory getFactory() {
return CreateProc;
}
@ -340,13 +345,15 @@ protected:
fMul = buffer.readU32();
fAdd = buffer.readU32();
}
SkColor fMul, fAdd;
private:
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(SkLightingColorFilter, (buffer));
}
typedef SkColorFilter INHERITED;
};
class SkLightingColorFilter_JustAdd : public SkLightingColorFilter {
@ -364,7 +371,7 @@ public:
SkPMColor c = shader[i];
if (c) {
unsigned a = SkGetPackedA32(c);
unsigned scaleA = SkAlpha255To256(a);
unsigned scaleA = SkAlpha255To256(a);
unsigned r = pin(SkGetPackedR32(c) + SkAlphaMul(addR, scaleA), a);
unsigned g = pin(SkGetPackedG32(c) + SkAlphaMul(addG, scaleA), a);
unsigned b = pin(SkGetPackedB32(c) + SkAlphaMul(addB, scaleA), a);
@ -384,6 +391,7 @@ private:
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(SkLightingColorFilter_JustAdd, (buffer));
}
typedef SkLightingColorFilter INHERITED;
};
@ -397,7 +405,7 @@ public:
unsigned scaleR = SkAlpha255To256(SkColorGetR(fMul));
unsigned scaleG = SkAlpha255To256(SkColorGetG(fMul));
unsigned scaleB = SkAlpha255To256(SkColorGetB(fMul));
for (int i = 0; i < count; i++) {
SkPMColor c = shader[i];
if (c) {
@ -416,7 +424,7 @@ protected:
SkLightingColorFilter_JustMul(SkFlattenableReadBuffer& buffer)
: INHERITED(buffer) {}
private:
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(SkLightingColorFilter_JustMul, (buffer));
@ -435,7 +443,7 @@ public:
SkASSERT(SkColorGetR(mul) == SkColorGetG(mul));
SkASSERT(SkColorGetR(mul) == SkColorGetB(mul));
}
virtual uint32_t getFlags() {
return this->INHERITED::getFlags() | (kAlphaUnchanged_Flag | kHasFilter16_Flag);
}
@ -462,7 +470,7 @@ private:
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(SkLightingColorFilter_SingleMul, (buffer));
}
typedef SkLightingColorFilter INHERITED;
};
@ -470,22 +478,22 @@ class SkLightingColorFilter_NoPin : public SkLightingColorFilter {
public:
SkLightingColorFilter_NoPin(SkColor mul, SkColor add)
: INHERITED(mul, add) {}
virtual void filterSpan(const SkPMColor shader[], int count,
SkPMColor result[]) {
unsigned scaleR = SkAlpha255To256(SkColorGetR(fMul));
unsigned scaleG = SkAlpha255To256(SkColorGetG(fMul));
unsigned scaleB = SkAlpha255To256(SkColorGetB(fMul));
unsigned addR = SkColorGetR(fAdd);
unsigned addG = SkColorGetG(fAdd);
unsigned addB = SkColorGetB(fAdd);
for (int i = 0; i < count; i++) {
SkPMColor c = shader[i];
if (c) {
unsigned a = SkGetPackedA32(c);
unsigned scaleA = SkAlpha255To256(a);
unsigned scaleA = SkAlpha255To256(a);
unsigned r = SkAlphaMul(SkGetPackedR32(c), scaleR) + SkAlphaMul(addR, scaleA);
unsigned g = SkAlphaMul(SkGetPackedG32(c), scaleG) + SkAlphaMul(addG, scaleA);
unsigned b = SkAlphaMul(SkGetPackedB32(c), scaleB) + SkAlphaMul(addB, scaleA);
@ -494,18 +502,18 @@ public:
result[i] = c;
}
}
protected:
virtual Factory getFactory() { return CreateProc; }
SkLightingColorFilter_NoPin(SkFlattenableReadBuffer& buffer)
: INHERITED(buffer) {}
private:
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(SkLightingColorFilter_NoPin, (buffer));
}
typedef SkLightingColorFilter INHERITED;
};
@ -520,7 +528,7 @@ protected:
}
virtual void flatten(SkFlattenableWriteBuffer& buffer) {}
virtual Factory getFactory() {
return CreateProc;
}
@ -560,3 +568,14 @@ SkColorFilter* SkColorFilter::CreateLightingFilter(SkColor mul, SkColor add) {
return SkNEW_ARGS(SkLightingColorFilter, (mul, add));
}
static SkFlattenable::Registrar
gSrcColorFilterReg("Src_SkModeColorFilterReg",
Src_SkModeColorFilter::CreateProc);
static SkFlattenable::Registrar
gSrcOverColorFilterReg("SrcOver_SkModeColorFilterReg",
SrcOver_SkModeColorFilter::CreateProc);
static SkFlattenable::Registrar
gProcColorFilterReg("Proc_SkModeColorFilterReg",
Proc_SkModeColorFilter::CreateProc);

View File

@ -18,7 +18,7 @@ static void General(SkColorMatrixFilter::State* state,
const int32_t* SK_RESTRICT array = state->fArray;
const int shift = state->fShift;
int32_t* SK_RESTRICT result = state->fResult;
result[0] = rowmul4(&array[0], r, g, b, a) >> shift;
result[1] = rowmul4(&array[5], r, g, b, a) >> shift;
result[2] = rowmul4(&array[10], r, g, b, a) >> shift;
@ -29,7 +29,7 @@ static void General16(SkColorMatrixFilter::State* state,
unsigned r, unsigned g, unsigned b, unsigned a) {
const int32_t* SK_RESTRICT array = state->fArray;
int32_t* SK_RESTRICT result = state->fResult;
result[0] = rowmul4(&array[0], r, g, b, a) >> 16;
result[1] = rowmul4(&array[5], r, g, b, a) >> 16;
result[2] = rowmul4(&array[10], r, g, b, a) >> 16;
@ -41,7 +41,7 @@ static void AffineAdd(SkColorMatrixFilter::State* state,
const int32_t* SK_RESTRICT array = state->fArray;
const int shift = state->fShift;
int32_t* SK_RESTRICT result = state->fResult;
result[0] = rowmul3(&array[0], r, g, b) >> shift;
result[1] = rowmul3(&array[5], r, g, b) >> shift;
result[2] = rowmul3(&array[10], r, g, b) >> shift;
@ -52,7 +52,7 @@ static void AffineAdd16(SkColorMatrixFilter::State* state,
unsigned r, unsigned g, unsigned b, unsigned a) {
const int32_t* SK_RESTRICT array = state->fArray;
int32_t* SK_RESTRICT result = state->fResult;
result[0] = rowmul3(&array[0], r, g, b) >> 16;
result[1] = rowmul3(&array[5], r, g, b) >> 16;
result[2] = rowmul3(&array[10], r, g, b) >> 16;
@ -64,7 +64,7 @@ static void ScaleAdd(SkColorMatrixFilter::State* state,
const int32_t* SK_RESTRICT array = state->fArray;
const int shift = state->fShift;
int32_t* SK_RESTRICT result = state->fResult;
// cast to (int) to keep the expression signed for the shift
result[0] = (array[0] * (int)r + array[4]) >> shift;
result[1] = (array[6] * (int)g + array[9]) >> shift;
@ -76,7 +76,7 @@ static void ScaleAdd16(SkColorMatrixFilter::State* state,
unsigned r, unsigned g, unsigned b, unsigned a) {
const int32_t* SK_RESTRICT array = state->fArray;
int32_t* SK_RESTRICT result = state->fResult;
// cast to (int) to keep the expression signed for the shift
result[0] = (array[0] * (int)r + array[4]) >> 16;
result[1] = (array[6] * (int)g + array[9]) >> 16;
@ -89,7 +89,7 @@ static void Add(SkColorMatrixFilter::State* state,
const int32_t* SK_RESTRICT array = state->fArray;
const int shift = state->fShift;
int32_t* SK_RESTRICT result = state->fResult;
result[0] = r + (array[4] >> shift);
result[1] = g + (array[9] >> shift);
result[2] = b + (array[14] >> shift);
@ -100,7 +100,7 @@ static void Add16(SkColorMatrixFilter::State* state,
unsigned r, unsigned g, unsigned b, unsigned a) {
const int32_t* SK_RESTRICT array = state->fArray;
int32_t* SK_RESTRICT result = state->fResult;
result[0] = r + (array[4] >> 16);
result[1] = g + (array[9] >> 16);
result[2] = b + (array[14] >> 16);
@ -117,7 +117,7 @@ void SkColorMatrixFilter::setup(const SkScalar SK_RESTRICT src[20]) {
// fState is undefined, but that is OK, since we shouldn't look at it
return;
}
int32_t* SK_RESTRICT array = fState.fArray;
int i;
@ -129,7 +129,7 @@ void SkColorMatrixFilter::setup(const SkScalar SK_RESTRICT src[20]) {
value = SkAbs32(value);
max = SkMax32(max, value);
}
/* All of fArray[] values must fit in 23 bits, to safely allow me to
multiply them by 8bit unsigned values, and get a signed answer without
overflow. This means clz needs to be 9 or bigger
@ -146,7 +146,7 @@ void SkColorMatrixFilter::setup(const SkScalar SK_RESTRICT src[20]) {
}
one >>= bits;
}
// check if we have to munge Alpha
int32_t changesAlpha = (array[15] | array[16] | array[17] |
(array[18] - one) | array[19]);
@ -224,36 +224,36 @@ void SkColorMatrixFilter::filterSpan(const SkPMColor src[], int count,
Proc proc = fProc;
State* state = &fState;
int32_t* SK_RESTRICT result = state->fResult;
if (NULL == proc) {
if (src != dst) {
memcpy(dst, src, count * sizeof(SkPMColor));
}
return;
}
const SkUnPreMultiply::Scale* table = SkUnPreMultiply::GetScaleTable();
for (int i = 0; i < count; i++) {
SkPMColor c = src[i];
unsigned r = SkGetPackedR32(c);
unsigned g = SkGetPackedG32(c);
unsigned b = SkGetPackedB32(c);
unsigned a = SkGetPackedA32(c);
// need our components to be un-premultiplied
if (255 != a) {
SkUnPreMultiply::Scale scale = table[a];
r = SkUnPreMultiply::ApplyScale(scale, r);
g = SkUnPreMultiply::ApplyScale(scale, g);
b = SkUnPreMultiply::ApplyScale(scale, b);
SkASSERT(r <= 255);
SkASSERT(g <= 255);
SkASSERT(b <= 255);
}
proc(state, r, g, b, a);
r = pin(result[0], SK_R32_MASK);
@ -278,7 +278,7 @@ void SkColorMatrixFilter::filterSpan16(const uint16_t src[], int count,
Proc proc = fProc;
State* state = &fState;
int32_t* SK_RESTRICT result = state->fResult;
if (NULL == proc) {
if (src != dst) {
memcpy(dst, src, count * sizeof(uint16_t));
@ -288,18 +288,18 @@ void SkColorMatrixFilter::filterSpan16(const uint16_t src[], int count,
for (int i = 0; i < count; i++) {
uint16_t c = src[i];
// expand to 8bit components (since our matrix translate is 8bit biased
unsigned r = SkPacked16ToR32(c);
unsigned g = SkPacked16ToG32(c);
unsigned b = SkPacked16ToB32(c);
proc(state, r, g, b, 0);
r = pin(result[0], SK_R32_MASK);
g = pin(result[1], SK_G32_MASK);
b = pin(result[2], SK_B32_MASK);
// now packed it back down to 16bits (hmmm, could dither...)
dst[i] = SkPack888ToRGB16(r, g, b);
}
@ -314,17 +314,20 @@ void SkColorMatrixFilter::flatten(SkFlattenableWriteBuffer& buffer) {
buffer.writeMul4(&fState, sizeof(fState));
buffer.write32(fFlags);
}
SkFlattenable::Factory SkColorMatrixFilter::getFactory() { return CreateProc; }
SkColorMatrixFilter::SkColorMatrixFilter(SkFlattenableReadBuffer& buffer)
: INHERITED(buffer) {
fProc = (Proc)buffer.readFunctionPtr();
buffer.read(&fState, sizeof(fState));
fFlags = buffer.readU32();
}
SkFlattenable* SkColorMatrixFilter::CreateProc(SkFlattenableReadBuffer& buf) {
return SkNEW_ARGS(SkColorMatrixFilter, (buf));
}
static SkFlattenable::Registrar
gSkColorMatrixFilterReg("SkColorMatrixFilter",
SkColorMatrixFilter::CreateProc);

View File

@ -43,3 +43,6 @@ SkFlattenable* SkPixelXorXfermode::Create(SkFlattenableReadBuffer& rb) {
return SkNEW_ARGS(SkPixelXorXfermode, (rb));
}
static SkFlattenable::Registrar
gSkPixelXorXfermodeReg("SkPixelXorXfermode",
SkPixelXorXfermode::CreateProc);