Mark all methods on SkXfermode as const, in preparation for declaring all

xfermodes as immutable/reentrant-safe
Review URL: https://codereview.appspot.com/6941065

git-svn-id: http://skia.googlecode.com/svn/trunk@6855 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@google.com 2012-12-17 19:55:24 +00:00
parent 82ec0b00f3
commit 30da745bbf
5 changed files with 64 additions and 79 deletions

View File

@ -28,13 +28,13 @@ public:
SkXfermode() {}
virtual void xfer32(SkPMColor dst[], const SkPMColor src[], int count,
const SkAlpha aa[]);
const SkAlpha aa[]) const;
virtual void xfer16(uint16_t dst[], const SkPMColor src[], int count,
const SkAlpha aa[]);
const SkAlpha aa[]) const;
virtual void xfer4444(uint16_t dst[], const SkPMColor src[], int count,
const SkAlpha aa[]);
const SkAlpha aa[]) const;
virtual void xferA8(SkAlpha dst[], const SkPMColor src[], int count,
const SkAlpha aa[]);
const SkAlpha aa[]) const;
/** Enum of possible coefficients to describe some xfermodes
*/
@ -68,13 +68,13 @@ public:
srcover one isa
dstover ida one
*/
virtual bool asCoeff(Coeff* src, Coeff* dst);
virtual bool asCoeff(Coeff* src, Coeff* dst) const;
/**
* The same as calling xfermode->asCoeff(..), except that this also checks
* if the xfermode is NULL, and if so, treats its as kSrcOver_Mode.
*/
static bool AsCoeff(SkXfermode*, Coeff* src, Coeff* dst);
static bool AsCoeff(const SkXfermode*, Coeff* src, Coeff* dst);
/** List of predefined xfermodes.
The algebra for the modes uses the following symbols:
@ -125,13 +125,13 @@ public:
* returns true and sets (if not null) mode accordingly. Otherwise it
* returns false and ignores the mode parameter.
*/
virtual bool asMode(Mode* mode);
virtual bool asMode(Mode* mode) const;
/**
* The same as calling xfermode->asMode(mode), except that this also checks
* if the xfermode is NULL, and if so, treats its as kSrcOver_Mode.
*/
static bool AsMode(SkXfermode*, Mode* mode);
static bool AsMode(const SkXfermode*, Mode* mode);
/**
* Returns true if the xfermode claims to be the specified Mode. This works
@ -143,7 +143,7 @@ public:
* ...
* }
*/
static bool IsMode(SkXfermode* xfer, Mode mode);
static bool IsMode(const SkXfermode* xfer, Mode mode);
/** Return an SkXfermode object for the specified mode.
*/
@ -170,7 +170,7 @@ public:
static bool ModeAsCoeff(Mode mode, Coeff* src, Coeff* dst);
// DEPRECATED: call AsMode(...)
static bool IsMode(SkXfermode* xfer, Mode* mode) {
static bool IsMode(const SkXfermode* xfer, Mode* mode) {
return AsMode(xfer, mode);
}
@ -186,7 +186,7 @@ protected:
This method will not be called directly by the client, so it need not
be implemented if your subclass has overridden xfer32/xfer16/xferA8
*/
virtual SkPMColor xferColor(SkPMColor src, SkPMColor dst);
virtual SkPMColor xferColor(SkPMColor src, SkPMColor dst) const;
private:
enum {
@ -208,13 +208,13 @@ public:
// overrides from SkXfermode
virtual void xfer32(SkPMColor dst[], const SkPMColor src[], int count,
const SkAlpha aa[]) SK_OVERRIDE;
const SkAlpha aa[]) const SK_OVERRIDE;
virtual void xfer16(uint16_t dst[], const SkPMColor src[], int count,
const SkAlpha aa[]) SK_OVERRIDE;
const SkAlpha aa[]) const SK_OVERRIDE;
virtual void xfer4444(uint16_t dst[], const SkPMColor src[], int count,
const SkAlpha aa[]) SK_OVERRIDE;
const SkAlpha aa[]) const SK_OVERRIDE;
virtual void xferA8(SkAlpha dst[], const SkPMColor src[], int count,
const SkAlpha aa[]) SK_OVERRIDE;
const SkAlpha aa[]) const SK_OVERRIDE;
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkProcXfermode)

View File

@ -41,13 +41,13 @@ public:
// overrides from SkXfermode
virtual void xfer32(SkPMColor dst[], const SkPMColor src[], int count,
const SkAlpha aa[]) SK_OVERRIDE;
const SkAlpha aa[]) const SK_OVERRIDE;
virtual void xfer16(uint16_t dst[], const SkPMColor src[], int count,
const SkAlpha aa[]) SK_OVERRIDE;
const SkAlpha aa[]) const SK_OVERRIDE;
virtual void xfer4444(uint16_t dst[], const SkPMColor src[], int count,
const SkAlpha aa[]) SK_OVERRIDE;
const SkAlpha aa[]) const SK_OVERRIDE;
virtual void xferA8(SkAlpha dst[], const SkPMColor src[], int count,
const SkAlpha aa[]) SK_OVERRIDE;
const SkAlpha aa[]) const SK_OVERRIDE;
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkAvoidXfermode)

View File

@ -450,22 +450,22 @@ static const ProcCoeff gProcCoeffs[] = {
///////////////////////////////////////////////////////////////////////////////
bool SkXfermode::asCoeff(Coeff* src, Coeff* dst) {
bool SkXfermode::asCoeff(Coeff* src, Coeff* dst) const {
return false;
}
bool SkXfermode::asMode(Mode* mode) {
bool SkXfermode::asMode(Mode* mode) const {
return false;
}
SkPMColor SkXfermode::xferColor(SkPMColor src, SkPMColor dst) {
SkPMColor SkXfermode::xferColor(SkPMColor src, SkPMColor dst) const{
// no-op. subclasses should override this
return dst;
}
void SkXfermode::xfer32(SkPMColor* SK_RESTRICT dst,
const SkPMColor* SK_RESTRICT src, int count,
const SkAlpha* SK_RESTRICT aa) {
const SkAlpha* SK_RESTRICT aa) const {
SkASSERT(dst && src && count >= 0);
if (NULL == aa) {
@ -489,7 +489,7 @@ void SkXfermode::xfer32(SkPMColor* SK_RESTRICT dst,
void SkXfermode::xfer16(uint16_t* dst,
const SkPMColor* SK_RESTRICT src, int count,
const SkAlpha* SK_RESTRICT aa) {
const SkAlpha* SK_RESTRICT aa) const {
SkASSERT(dst && src && count >= 0);
if (NULL == aa) {
@ -514,8 +514,7 @@ void SkXfermode::xfer16(uint16_t* dst,
void SkXfermode::xfer4444(SkPMColor16* SK_RESTRICT dst,
const SkPMColor* SK_RESTRICT src, int count,
const SkAlpha* SK_RESTRICT aa)
{
const SkAlpha* SK_RESTRICT aa) const {
SkASSERT(dst && src && count >= 0);
if (NULL == aa) {
@ -540,8 +539,7 @@ void SkXfermode::xfer4444(SkPMColor16* SK_RESTRICT dst,
void SkXfermode::xferA8(SkAlpha* SK_RESTRICT dst,
const SkPMColor src[], int count,
const SkAlpha* SK_RESTRICT aa)
{
const SkAlpha* SK_RESTRICT aa) const {
SkASSERT(dst && src && count >= 0);
if (NULL == aa) {
@ -569,7 +567,7 @@ void SkXfermode::xferA8(SkAlpha* SK_RESTRICT dst,
void SkProcXfermode::xfer32(SkPMColor* SK_RESTRICT dst,
const SkPMColor* SK_RESTRICT src, int count,
const SkAlpha* SK_RESTRICT aa) {
const SkAlpha* SK_RESTRICT aa) const {
SkASSERT(dst && src && count >= 0);
SkXfermodeProc proc = fProc;
@ -597,7 +595,7 @@ void SkProcXfermode::xfer32(SkPMColor* SK_RESTRICT dst,
void SkProcXfermode::xfer16(uint16_t* SK_RESTRICT dst,
const SkPMColor* SK_RESTRICT src, int count,
const SkAlpha* SK_RESTRICT aa) {
const SkAlpha* SK_RESTRICT aa) const {
SkASSERT(dst && src && count >= 0);
SkXfermodeProc proc = fProc;
@ -626,7 +624,7 @@ void SkProcXfermode::xfer16(uint16_t* SK_RESTRICT dst,
void SkProcXfermode::xfer4444(SkPMColor16* SK_RESTRICT dst,
const SkPMColor* SK_RESTRICT src, int count,
const SkAlpha* SK_RESTRICT aa) {
const SkAlpha* SK_RESTRICT aa) const {
SkASSERT(dst && src && count >= 0);
SkXfermodeProc proc = fProc;
@ -655,7 +653,7 @@ void SkProcXfermode::xfer4444(SkPMColor16* SK_RESTRICT dst,
void SkProcXfermode::xferA8(SkAlpha* SK_RESTRICT dst,
const SkPMColor* SK_RESTRICT src, int count,
const SkAlpha* SK_RESTRICT aa) {
const SkAlpha* SK_RESTRICT aa) const {
SkASSERT(dst && src && count >= 0);
SkXfermodeProc proc = fProc;
@ -711,14 +709,14 @@ public:
fDstCoeff = rec.fDC;
}
virtual bool asMode(Mode* mode) {
virtual bool asMode(Mode* mode) const SK_OVERRIDE {
if (mode) {
*mode = fMode;
}
return true;
}
virtual bool asCoeff(Coeff* sc, Coeff* dc) {
virtual bool asCoeff(Coeff* sc, Coeff* dc) const SK_OVERRIDE {
if (CANNOT_USE_COEFF == fSrcCoeff) {
return false;
}
@ -765,8 +763,8 @@ class SkClearXfermode : public SkProcCoeffXfermode {
public:
SkClearXfermode(const ProcCoeff& rec) : SkProcCoeffXfermode(rec, kClear_Mode) {}
virtual void xfer32(SkPMColor*, const SkPMColor*, int, const SkAlpha*) SK_OVERRIDE;
virtual void xferA8(SkAlpha*, const SkPMColor*, int, const SkAlpha*) SK_OVERRIDE;
virtual void xfer32(SkPMColor*, const SkPMColor*, int, const SkAlpha*) const SK_OVERRIDE;
virtual void xferA8(SkAlpha*, const SkPMColor*, int, const SkAlpha*) const SK_OVERRIDE;
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkClearXfermode)
@ -778,7 +776,7 @@ private:
void SkClearXfermode::xfer32(SkPMColor* SK_RESTRICT dst,
const SkPMColor* SK_RESTRICT, int count,
const SkAlpha* SK_RESTRICT aa) {
const SkAlpha* SK_RESTRICT aa) const {
SkASSERT(dst && count >= 0);
if (NULL == aa) {
@ -796,7 +794,7 @@ void SkClearXfermode::xfer32(SkPMColor* SK_RESTRICT dst,
}
void SkClearXfermode::xferA8(SkAlpha* SK_RESTRICT dst,
const SkPMColor* SK_RESTRICT, int count,
const SkAlpha* SK_RESTRICT aa) {
const SkAlpha* SK_RESTRICT aa) const {
SkASSERT(dst && count >= 0);
if (NULL == aa) {
@ -819,8 +817,8 @@ class SkSrcXfermode : public SkProcCoeffXfermode {
public:
SkSrcXfermode(const ProcCoeff& rec) : SkProcCoeffXfermode(rec, kSrc_Mode) {}
virtual void xfer32(SkPMColor*, const SkPMColor*, int, const SkAlpha*) SK_OVERRIDE;
virtual void xferA8(SkAlpha*, const SkPMColor*, int, const SkAlpha*) SK_OVERRIDE;
virtual void xfer32(SkPMColor*, const SkPMColor*, int, const SkAlpha*) const SK_OVERRIDE;
virtual void xferA8(SkAlpha*, const SkPMColor*, int, const SkAlpha*) const SK_OVERRIDE;
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSrcXfermode)
@ -832,7 +830,7 @@ private:
void SkSrcXfermode::xfer32(SkPMColor* SK_RESTRICT dst,
const SkPMColor* SK_RESTRICT src, int count,
const SkAlpha* SK_RESTRICT aa) {
const SkAlpha* SK_RESTRICT aa) const {
SkASSERT(dst && src && count >= 0);
if (NULL == aa) {
@ -851,7 +849,7 @@ void SkSrcXfermode::xfer32(SkPMColor* SK_RESTRICT dst,
void SkSrcXfermode::xferA8(SkAlpha* SK_RESTRICT dst,
const SkPMColor* SK_RESTRICT src, int count,
const SkAlpha* SK_RESTRICT aa) {
const SkAlpha* SK_RESTRICT aa) const {
SkASSERT(dst && src && count >= 0);
if (NULL == aa) {
@ -873,13 +871,13 @@ void SkSrcXfermode::xferA8(SkAlpha* SK_RESTRICT dst,
}
}
////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
class SkDstInXfermode : public SkProcCoeffXfermode {
public:
SkDstInXfermode(const ProcCoeff& rec) : SkProcCoeffXfermode(rec, kDstIn_Mode) {}
virtual void xfer32(SkPMColor*, const SkPMColor*, int, const SkAlpha*) SK_OVERRIDE;
virtual void xfer32(SkPMColor*, const SkPMColor*, int, const SkAlpha*) const SK_OVERRIDE;
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDstInXfermode)
@ -891,7 +889,7 @@ private:
void SkDstInXfermode::xfer32(SkPMColor* SK_RESTRICT dst,
const SkPMColor* SK_RESTRICT src, int count,
const SkAlpha* SK_RESTRICT aa) {
const SkAlpha* SK_RESTRICT aa) const {
SkASSERT(dst && src);
if (count <= 0) {
@ -909,13 +907,13 @@ void SkDstInXfermode::xfer32(SkPMColor* SK_RESTRICT dst,
} while (--count != 0);
}
/////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
class SkDstOutXfermode : public SkProcCoeffXfermode {
public:
SkDstOutXfermode(const ProcCoeff& rec) : SkProcCoeffXfermode(rec, kDstOut_Mode) {}
virtual void xfer32(SkPMColor*, const SkPMColor*, int, const SkAlpha*) SK_OVERRIDE;
virtual void xfer32(SkPMColor*, const SkPMColor*, int, const SkAlpha*) const SK_OVERRIDE;
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDstOutXfermode)
@ -928,7 +926,7 @@ private:
void SkDstOutXfermode::xfer32(SkPMColor* SK_RESTRICT dst,
const SkPMColor* SK_RESTRICT src, int count,
const SkAlpha* SK_RESTRICT aa) {
const SkAlpha* SK_RESTRICT aa) const {
SkASSERT(dst && src);
if (count <= 0) {
@ -1002,7 +1000,7 @@ bool SkXfermode::ModeAsCoeff(Mode mode, Coeff* src, Coeff* dst) {
return true;
}
bool SkXfermode::AsMode(SkXfermode* xfer, Mode* mode) {
bool SkXfermode::AsMode(const SkXfermode* xfer, Mode* mode) {
if (NULL == xfer) {
if (mode) {
*mode = kSrcOver_Mode;
@ -1012,14 +1010,14 @@ bool SkXfermode::AsMode(SkXfermode* xfer, Mode* mode) {
return xfer->asMode(mode);
}
bool SkXfermode::AsCoeff(SkXfermode* xfer, Coeff* src, Coeff* dst) {
bool SkXfermode::AsCoeff(const SkXfermode* xfer, Coeff* src, Coeff* dst) {
if (NULL == xfer) {
return ModeAsCoeff(kSrcOver_Mode, src, dst);
}
return xfer->asCoeff(src, dst);
}
bool SkXfermode::IsMode(SkXfermode* xfer, Mode mode) {
bool SkXfermode::IsMode(const SkXfermode* xfer, Mode mode) {
// if xfer==null then the mode is srcover
Mode m = kSrcOver_Mode;
if (xfer && !xfer->asMode(&m)) {

View File

@ -12,7 +12,7 @@ public:
}
virtual void xfer32(SkPMColor dst[], const SkPMColor src[], int count,
const SkAlpha aa[]) SK_OVERRIDE;
const SkAlpha aa[]) const SK_OVERRIDE;
SK_DECLARE_UNFLATTENABLE_OBJECT()
@ -48,7 +48,7 @@ static bool needsUnpremul(int alpha) {
}
void SkArithmeticMode_scalar::xfer32(SkPMColor dst[], const SkPMColor src[],
int count, const SkAlpha aaCoverage[]) {
int count, const SkAlpha aaCoverage[]) const {
SkScalar k1 = fK[0] / 255;
SkScalar k2 = fK[1];
SkScalar k3 = fK[2];

View File

@ -1,4 +1,3 @@
/*
* Copyright 2006 The Android Open Source Project
*
@ -6,13 +5,11 @@
* found in the LICENSE file.
*/
#include "SkAvoidXfermode.h"
#include "SkColorPriv.h"
#include "SkFlattenableBuffers.h"
SkAvoidXfermode::SkAvoidXfermode(SkColor opColor, U8CPU tolerance, Mode mode)
{
SkAvoidXfermode::SkAvoidXfermode(SkColor opColor, U8CPU tolerance, Mode mode) {
if (tolerance > 255) {
tolerance = 255;
}
@ -23,15 +20,13 @@ SkAvoidXfermode::SkAvoidXfermode(SkColor opColor, U8CPU tolerance, Mode mode)
}
SkAvoidXfermode::SkAvoidXfermode(SkFlattenableReadBuffer& buffer)
: INHERITED(buffer)
{
: INHERITED(buffer) {
fOpColor = buffer.readColor();
fDistMul = buffer.readUInt();
fMode = (Mode)buffer.readUInt();
}
void SkAvoidXfermode::flatten(SkFlattenableWriteBuffer& buffer) const
{
void SkAvoidXfermode::flatten(SkFlattenableWriteBuffer& buffer) const {
this->INHERITED::flatten(buffer);
buffer.writeColor(fOpColor);
@ -40,8 +35,7 @@ void SkAvoidXfermode::flatten(SkFlattenableWriteBuffer& buffer) const
}
// returns 0..31
static unsigned color_dist16(uint16_t c, unsigned r, unsigned g, unsigned b)
{
static unsigned color_dist16(uint16_t c, unsigned r, unsigned g, unsigned b) {
SkASSERT(r <= SK_R16_MASK);
SkASSERT(g <= SK_G16_MASK);
SkASSERT(b <= SK_B16_MASK);
@ -54,8 +48,7 @@ static unsigned color_dist16(uint16_t c, unsigned r, unsigned g, unsigned b)
}
// returns 0..15
static unsigned color_dist4444(uint16_t c, unsigned r, unsigned g, unsigned b)
{
static unsigned color_dist4444(uint16_t c, unsigned r, unsigned g, unsigned b) {
SkASSERT(r <= 0xF);
SkASSERT(g <= 0xF);
SkASSERT(b <= 0xF);
@ -68,8 +61,7 @@ static unsigned color_dist4444(uint16_t c, unsigned r, unsigned g, unsigned b)
}
// returns 0..255
static unsigned color_dist32(SkPMColor c, U8CPU r, U8CPU g, U8CPU b)
{
static unsigned color_dist32(SkPMColor c, U8CPU r, U8CPU g, U8CPU b) {
SkASSERT(r <= 0xFF);
SkASSERT(g <= 0xFF);
SkASSERT(b <= 0xFF);
@ -81,8 +73,7 @@ static unsigned color_dist32(SkPMColor c, U8CPU r, U8CPU g, U8CPU b)
return SkMax32(dr, SkMax32(dg, db));
}
static int scale_dist_14(int dist, uint32_t mul, uint32_t sub)
{
static int scale_dist_14(int dist, uint32_t mul, uint32_t sub) {
int tmp = dist * mul - sub;
int result = (tmp + (1 << 13)) >> 14;
@ -94,8 +85,7 @@ static inline unsigned Accurate255To256(unsigned x) {
}
void SkAvoidXfermode::xfer32(SkPMColor dst[], const SkPMColor src[], int count,
const SkAlpha aa[])
{
const SkAlpha aa[]) const {
unsigned opR = SkColorGetR(fOpColor);
unsigned opG = SkColorGetG(fOpColor);
unsigned opB = SkColorGetB(fOpColor);
@ -134,8 +124,7 @@ void SkAvoidXfermode::xfer32(SkPMColor dst[], const SkPMColor src[], int count,
}
}
static inline U16CPU SkBlend3216(SkPMColor src, U16CPU dst, unsigned scale)
{
static inline U16CPU SkBlend3216(SkPMColor src, U16CPU dst, unsigned scale) {
SkASSERT(scale <= 32);
scale <<= 3;
@ -145,8 +134,7 @@ static inline U16CPU SkBlend3216(SkPMColor src, U16CPU dst, unsigned scale)
}
void SkAvoidXfermode::xfer16(uint16_t dst[], const SkPMColor src[], int count,
const SkAlpha aa[])
{
const SkAlpha aa[]) const {
unsigned opR = SkColorGetR(fOpColor) >> (8 - SK_R16_BITS);
unsigned opG = SkColorGetG(fOpColor) >> (8 - SK_G16_BITS);
unsigned opB = SkColorGetB(fOpColor) >> (8 - SK_R16_BITS);
@ -186,8 +174,7 @@ void SkAvoidXfermode::xfer16(uint16_t dst[], const SkPMColor src[], int count,
}
void SkAvoidXfermode::xfer4444(uint16_t dst[], const SkPMColor src[], int count,
const SkAlpha aa[])
{
const SkAlpha aa[]) const {
unsigned opR = SkColorGetR(fOpColor) >> 4;
unsigned opG = SkColorGetG(fOpColor) >> 4;
unsigned opB = SkColorGetB(fOpColor) >> 4;
@ -226,7 +213,7 @@ void SkAvoidXfermode::xfer4444(uint16_t dst[], const SkPMColor src[], int count,
}
}
void SkAvoidXfermode::xferA8(SkAlpha dst[], const SkPMColor src[], int count, const SkAlpha aa[])
{
void SkAvoidXfermode::xferA8(SkAlpha dst[], const SkPMColor src[], int count,
const SkAlpha aa[]) const {
// override in subclass
}