remove deprecated use of porterduff enum

git-svn-id: http://skia.googlecode.com/svn/trunk@235 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@android.com 2009-06-23 03:01:32 +00:00
Родитель c9c6422903
Коммит 845fdaca17
11 изменённых файлов: 204 добавлений и 239 удалений

Просмотреть файл

@ -22,10 +22,10 @@
#include "SkDeque.h"
#include "SkPaint.h"
#include "SkRefCnt.h"
#include "SkPorterDuff.h"
#include "SkPath.h"
#include "SkRegion.h"
#include "SkScalarCompare.h"
#include "SkXfermode.h"
class SkBounder;
class SkDevice;
@ -315,7 +315,7 @@ public:
bool getClipBounds(SkRect* bounds, EdgeType et = kAA_EdgeType) const;
/** Fill the entire canvas' bitmap (restricted to the current clip) with the
specified ARGB color, using the specified PorterDuff mode.
specified ARGB color, using the specified mode.
@param a the alpha component (0..255) of the color to fill the canvas
@param r the red component (0..255) of the color to fill the canvas
@param g the green component (0..255) of the color to fill the canvas
@ -323,15 +323,15 @@ public:
@param mode the mode to apply the color in (defaults to SrcOver)
*/
void drawARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b,
SkPorterDuff::Mode mode = SkPorterDuff::kSrcOver_Mode);
SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode);
/** Fill the entire canvas' bitmap (restricted to the current clip) with the
specified color and porter-duff xfermode.
specified color and mode.
@param color the color to draw with
@param mode the mode to apply the color in (defaults to SrcOver)
*/
void drawColor(SkColor color,
SkPorterDuff::Mode mode = SkPorterDuff::kSrcOver_Mode);
SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode);
/** Fill the entire canvas' bitmap (restricted to the current clip) with the
specified paint.
@ -614,7 +614,7 @@ public:
@param xmode Used if both texs and colors are present. In this
case the colors are combined with the texture using mode,
before being drawn using the paint. If mode is null, then
the porter-duff MULTIPLY mode is used.
kMultiply_Mode is used.
@param indices If not null, array of indices to reference into the
vertex (texs, colors) array.
@param indexCount number of entries in the indices array (if not null)

Просмотреть файл

@ -19,7 +19,7 @@
#include "SkColor.h"
#include "SkFlattenable.h"
#include "SkPorterDuff.h"
#include "SkXfermode.h"
class SkColorFilter : public SkFlattenable {
public:
@ -58,25 +58,24 @@ public:
*/
virtual uint32_t getFlags() { return 0; }
/** Create a colorfilter that uses the specified color and porter-duff mode.
If porterDuffMode is DST, this function will return NULL (since that
/** 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).
@param srcColor The source color used with the specified mode
@param mode The porter-duff mode that is applied to each color in
@param c The source color used with the specified mode
@param mode The xfermode mode that is applied to each color in
the colorfilter's filterSpan[16,32] methods
@return colorfilter object that applies the src color and porter-duff
mode, or NULL if the mode will have no effect.
@return colorfilter object that applies the src color and mode,
or NULL if the mode will have no effect.
*/
static SkColorFilter* CreatePorterDuffFilter(SkColor srcColor,
SkPorterDuff::Mode mode);
static SkColorFilter* CreateModeFilter(SkColor c, SkXfermode::Mode mode);
/** Create a colorfilter that calls through to the specified procs to
filter the colors. The SkXfermodeProc parameter must be non-null, but
the SkXfermodeProc16 is optional, and may be null.
*/
static SkColorFilter* CreatXfermodeProcFilter(SkColor srcColor,
SkXfermodeProc proc,
SkXfermodeProc16 proc16 = NULL);
static SkColorFilter* CreateProcFilter(SkColor srcColor,
SkXfermodeProc proc,
SkXfermodeProc16 proc16 = NULL);
/** Create a colorfilter that multiplies the RGB channels by one color, and
then adds a second color, pinning the result for each component to

Просмотреть файл

@ -18,6 +18,7 @@
#define SkPorterDuff_DEFINED
#include "SkColor.h"
#include "SkXfermode.h"
class SkXfermode;
@ -54,6 +55,7 @@ public:
kModeCount
};
/** Return an SkXfermode object for the specified mode.
*/
static SkXfermode* CreateXfermode(Mode mode);
@ -76,6 +78,10 @@ public:
return false and ignore the mode parameter.
*/
static bool IsMode(SkXfermode*, Mode* mode);
/** Return the corersponding SkXfermode::Mode
*/
static SkXfermode::Mode ToXfermodeMode(Mode);
};
#endif

Просмотреть файл

@ -64,7 +64,7 @@ static void* draw_proc(void* context) {
// SkDebugf("----- dirty [%d %d %d %d]\n", dirty.getBounds().fLeft, dirty.getBounds().fTop, dirty.getBounds().width(), dirty.getBounds().height());
canvas.clipRegion(update.dirty());
canvas.drawColor(0, SkPorterDuff::kClear_Mode);
canvas.drawColor(0, SkXfermode::kClear_Mode);
canvas.drawOval(oval, paint);
}
bounce(&x, &dx, WIDTH-OVALW);

Просмотреть файл

@ -251,8 +251,8 @@ protected:
paint.setAntiAlias(true);
paint.setAlpha(0x80);
paint.setColorFilter(
SkColorFilter::CreatePorterDuffFilter(
SkColorSetARGB(0x44, 0, 0xFF, 0), SkPorterDuff::kSrcATop_Mode))->unref();
SkColorFilter::CreateModeFilter(
SkColorSetARGB(0x44, 0, 0xFF, 0), SkXfermode::kSrcATop_Mode))->unref();
bounds.set(SkIntToScalar(10), SkIntToScalar(10), SkIntToScalar(150), SkIntToScalar(70));
canvas->saveLayer(&bounds, &paint,

Просмотреть файл

@ -81,7 +81,7 @@ SkDrawPaint::SkDrawPaint() : antiAlias(-1), color(NULL), fakeBold(-1), filterBit
strokeWidth(SK_ScalarNaN), style((SkPaint::Style) -1),
textAlign((SkPaint::Align) -1), textScaleX(SK_ScalarNaN), textSize(SK_ScalarNaN),
textSkewX(SK_ScalarNaN), typeface((SkDrawTypeface*) -1),
underline(-1), xfermode((SkPorterDuff::Mode) -1), fOwnsColor(false), fOwnsMaskFilter(false),
underline(-1), xfermode((SkXfermode::Mode) -1), fOwnsColor(false), fOwnsMaskFilter(false),
fOwnsPathEffect(false), fOwnsShader(false), fOwnsTypeface(false) {
}
@ -272,6 +272,6 @@ void SkDrawPaint::setupPaint(SkPaint* paint) const {
paint->setTypeface(typeface->getTypeface())->safeUnref();
if (underline != -1)
paint->setUnderlineText(SkToBool(underline));
if (xfermode != (SkPorterDuff::Mode) -1)
paint->setPorterDuffXfermode((SkPorterDuff::Mode) xfermode);
if (xfermode != (SkXfermode::Mode) -1)
paint->setXfermode((SkXfermode::Mode) xfermode);
}

Просмотреть файл

@ -25,9 +25,7 @@
#include "SkUtils.h"
#include "SkXfermode.h"
SkBlitter::~SkBlitter()
{
}
SkBlitter::~SkBlitter() {}
const SkBitmap* SkBlitter::justAnOpaqueColor(uint32_t* value)
{
@ -806,31 +804,31 @@ enum XferInterp {
static XferInterp interpret_xfermode(const SkPaint& paint, SkXfermode* xfer,
SkBitmap::Config deviceConfig) {
SkPorterDuff::Mode mode;
SkXfermode::Mode mode;
if (SkPorterDuff::IsMode(xfer, &mode)) {
if (SkXfermode::IsMode(xfer, &mode)) {
switch (mode) {
case SkPorterDuff::kSrc_Mode:
case SkXfermode::kSrc_Mode:
if (just_solid_color(paint)) {
return kSrcOver_XferInterp;
}
break;
case SkPorterDuff::kDst_Mode:
case SkXfermode::kDst_Mode:
return kSkipDrawing_XferInterp;
case SkPorterDuff::kSrcOver_Mode:
case SkXfermode::kSrcOver_Mode:
return kSrcOver_XferInterp;
case SkPorterDuff::kDstOver_Mode:
case SkXfermode::kDstOver_Mode:
if (SkBitmap::kRGB_565_Config == deviceConfig) {
return kSkipDrawing_XferInterp;
}
break;
case SkPorterDuff::kSrcIn_Mode:
case SkXfermode::kSrcIn_Mode:
if (SkBitmap::kRGB_565_Config == deviceConfig &&
just_solid_color(paint)) {
return kSrcOver_XferInterp;
}
break;
case SkPorterDuff::kDstIn_Mode:
case SkXfermode::kDstIn_Mode:
if (just_solid_color(paint)) {
return kSkipDrawing_XferInterp;
}

Просмотреть файл

@ -1229,22 +1229,22 @@ void SkCanvas::drawVertices(VertexMode vmode, int vertexCount,
//////////////////////////////////////////////////////////////////////////////
void SkCanvas::drawARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b,
SkPorterDuff::Mode mode) {
SkXfermode::Mode mode) {
SkPaint paint;
paint.setARGB(a, r, g, b);
if (SkPorterDuff::kSrcOver_Mode != mode) {
paint.setPorterDuffXfermode(mode);
if (SkXfermode::kSrcOver_Mode != mode) {
paint.setXfermode(mode);
}
this->drawPaint(paint);
}
void SkCanvas::drawColor(SkColor c, SkPorterDuff::Mode mode) {
void SkCanvas::drawColor(SkColor c, SkXfermode::Mode mode) {
SkPaint paint;
paint.setColor(c);
if (SkPorterDuff::kSrcOver_Mode != mode) {
paint.setPorterDuffXfermode(mode);
if (SkXfermode::kSrcOver_Mode != mode) {
paint.setXfermode(mode);
}
this->drawPaint(paint);
}

Просмотреть файл

@ -177,31 +177,31 @@ static BitmapXferProc ChooseBitmapXferProc(const SkBitmap& bitmap,
return NULL;
}
SkPorterDuff::Mode mode;
if (!SkPorterDuff::IsMode(paint.getXfermode(), &mode)) {
SkXfermode::Mode mode;
if (!SkXfermode::IsMode(paint.getXfermode(), &mode)) {
return NULL;
}
SkColor color = paint.getColor();
// collaps modes based on color...
if (SkPorterDuff::kSrcOver_Mode == mode) {
if (SkXfermode::kSrcOver_Mode == mode) {
unsigned alpha = SkColorGetA(color);
if (0 == alpha) {
mode = SkPorterDuff::kDst_Mode;
mode = SkXfermode::kDst_Mode;
} else if (0xFF == alpha) {
mode = SkPorterDuff::kSrc_Mode;
mode = SkXfermode::kSrc_Mode;
}
}
switch (mode) {
case SkPorterDuff::kClear_Mode:
case SkXfermode::kClear_Mode:
// SkDebugf("--- D_Clear_BitmapXferProc\n");
return D_Clear_BitmapXferProc; // ignore data
case SkPorterDuff::kDst_Mode:
case SkXfermode::kDst_Mode:
// SkDebugf("--- D_Dst_BitmapXferProc\n");
return D_Dst_BitmapXferProc; // ignore data
case SkPorterDuff::kSrc_Mode: {
case SkXfermode::kSrc_Mode: {
/*
should I worry about dithering for the lower depths?
*/
@ -2002,9 +2002,7 @@ bool SkTriColorShader::setup(const SkPoint pts[], const SkColor colors[],
}
#include "SkColorPriv.h"
#include "SkPorterDuff.h"
#include "SkComposeShader.h"
#include "SkXfermode.h"
static int ScalarTo256(SkScalar v) {
int scale = SkScalarToFixed(v) >> 8;
@ -2102,8 +2100,7 @@ void SkDraw::drawVertices(SkCanvas::VertexMode vmode, int count,
SkASSERT(shader);
bool releaseMode = false;
if (NULL == xmode) {
xmode = SkPorterDuff::CreateXfermode(
SkPorterDuff::kMultiply_Mode);
xmode = SkXfermode::Create(SkXfermode::kMultiply_Mode);
releaseMode = true;
}
SkShader* compose = SkNEW_ARGS(SkComposeShader,

Просмотреть файл

@ -1,80 +1,74 @@
/* libs/graphics/effects/SkColorFilters.cpp
**
** 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
**
** 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
** limitations under the License.
*/
/*
* Copyright (C) 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
*
* 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
* limitations under the License.
*/
#include "SkColorFilter.h"
#include "SkColorPriv.h"
#include "SkPorterDuff.h"
#include "SkUtils.h"
//#define TRACE_CreatePorterDuffFilter
// common baseclass
class Sk_XfermodeColorFilter : public SkColorFilter {
protected:
Sk_XfermodeColorFilter(SkColor color) : fColor(SkPreMultiplyColor(color)) {}
Sk_XfermodeColorFilter(SkColor color)
: fPMColor(SkPreMultiplyColor(color)) {}
virtual void flatten(SkFlattenableWriteBuffer& buffer)
{
buffer.write32(fColor);
virtual void flatten(SkFlattenableWriteBuffer& buffer) {
buffer.write32(fPMColor);
}
Sk_XfermodeColorFilter(SkFlattenableReadBuffer& buffer)
{
fColor = buffer.readU32();
Sk_XfermodeColorFilter(SkFlattenableReadBuffer& buffer) {
fPMColor = buffer.readU32();
}
SkPMColor fColor;
SkPMColor fPMColor;
};
class SkSrc_XfermodeColorFilter : public Sk_XfermodeColorFilter {
public:
SkSrc_XfermodeColorFilter(SkColor color) : INHERITED(color) {}
virtual uint32_t getFlags()
{
if (SkGetPackedA32(fColor) == 0xFF)
virtual uint32_t getFlags() {
if (SkGetPackedA32(fPMColor) == 0xFF) {
return kAlphaUnchanged_Flag | kHasFilter16_Flag;
else
} else {
return 0;
}
}
virtual void filterSpan(const SkPMColor shader[], int count, SkPMColor result[])
{
sk_memset32(result, fColor, count);
virtual void filterSpan(const SkPMColor shader[], int count,
SkPMColor result[]) {
sk_memset32(result, fPMColor, count);
}
virtual void filterSpan16(const uint16_t shader[], int count, uint16_t result[])
{
virtual void filterSpan16(const uint16_t shader[], int count,
uint16_t result[]) {
SkASSERT(this->getFlags() & kHasFilter16_Flag);
sk_memset16(result, SkPixel32ToPixel16(fColor), count);
sk_memset16(result, SkPixel32ToPixel16(fPMColor), count);
}
protected:
virtual Factory getFactory() { return CreateProc; }
SkSrc_XfermodeColorFilter(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {}
SkSrc_XfermodeColorFilter(SkFlattenableReadBuffer& buffer)
: INHERITED(buffer) {}
private:
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer)
{
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(SkSrc_XfermodeColorFilter, (buffer));
}
typedef Sk_XfermodeColorFilter INHERITED;
};
@ -82,38 +76,38 @@ class SkSrcOver_XfermodeColorFilter : public Sk_XfermodeColorFilter {
public:
SkSrcOver_XfermodeColorFilter(SkColor color) : INHERITED(color) {}
virtual uint32_t getFlags()
{
if (SkGetPackedA32(fColor) == 0xFF)
virtual uint32_t getFlags() {
if (SkGetPackedA32(fPMColor) == 0xFF) {
return kAlphaUnchanged_Flag | kHasFilter16_Flag;
else
} else {
return 0;
}
}
virtual void filterSpan(const SkPMColor shader[], int count, SkPMColor result[])
{
SkPMColor src = fColor;
virtual void filterSpan(const SkPMColor shader[], int count,
SkPMColor result[]) {
SkPMColor src = fPMColor;
unsigned scale = SkAlpha255To256(255 - SkGetPackedA32(src));
for (int i = 0; i < count; i++)
for (int i = 0; i < count; i++) {
result[i] = src + SkAlphaMulQ(shader[i], scale);
}
}
virtual void filterSpan16(const uint16_t shader[], int count, uint16_t result[])
{
virtual void filterSpan16(const uint16_t shader[], int count,
uint16_t result[]) {
SkASSERT(this->getFlags() & kHasFilter16_Flag);
sk_memset16(result, SkPixel32ToPixel16(fColor), count);
sk_memset16(result, SkPixel32ToPixel16(fPMColor), count);
}
protected:
virtual Factory getFactory() { return CreateProc; }
SkSrcOver_XfermodeColorFilter(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {}
SkSrcOver_XfermodeColorFilter(SkFlattenableReadBuffer& buffer)
: INHERITED(buffer) {}
private:
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer)
{
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(SkSrcOver_XfermodeColorFilter, (buffer));
}
@ -125,35 +119,35 @@ private:
class SkXfermodeColorFilter : public Sk_XfermodeColorFilter {
public:
SkXfermodeColorFilter(SkColor color, SkXfermodeProc proc,
SkXfermodeProc16 proc16) : INHERITED(color)
{
SkXfermodeProc16 proc16) : INHERITED(color) {
fProc = proc;
fProc16 = proc16;
}
virtual uint32_t getFlags()
{
virtual uint32_t getFlags() {
return fProc16 ? (kAlphaUnchanged_Flag | kHasFilter16_Flag) : 0;
}
virtual void filterSpan(const SkPMColor shader[], int count, SkPMColor result[])
{
SkPMColor color = fColor;
virtual void filterSpan(const SkPMColor shader[], int count,
SkPMColor result[]) {
SkPMColor color = fPMColor;
SkXfermodeProc proc = fProc;
for (int i = 0; i < count; i++)
for (int i = 0; i < count; i++) {
result[i] = proc(color, shader[i]);
}
}
virtual void filterSpan16(const uint16_t shader[], int count, uint16_t result[])
{
virtual void filterSpan16(const uint16_t shader[], int count,
uint16_t result[]) {
SkASSERT(this->getFlags() & kHasFilter16_Flag);
SkPMColor color = fColor;
SkPMColor color = fPMColor;
SkXfermodeProc16 proc16 = fProc16;
for (int i = 0; i < count; i++)
for (int i = 0; i < count; i++) {
result[i] = proc16(color, shader[i]);
}
}
protected:
@ -182,10 +176,9 @@ private:
typedef Sk_XfermodeColorFilter INHERITED;
};
SkColorFilter* SkColorFilter::CreatXfermodeProcFilter(SkColor color,
SkXfermodeProc proc,
SkXfermodeProc16 proc16)
{
SkColorFilter* SkColorFilter::CreateProcFilter(SkColor color,
SkXfermodeProc proc,
SkXfermodeProc16 proc16) {
return proc ?
SkNEW_ARGS(SkXfermodeColorFilter, (color, proc, proc16)) :
NULL;
@ -193,67 +186,57 @@ SkColorFilter* SkColorFilter::CreatXfermodeProcFilter(SkColor color,
///////////////////////////////////////////////////////////////////////////////
SkColorFilter* SkColorFilter::CreatePorterDuffFilter(SkColor color,
SkPorterDuff::Mode mode)
{
SkColorFilter* SkColorFilter::CreateModeFilter(SkColor color,
SkXfermode::Mode mode) {
unsigned alpha = SkColorGetA(color);
// first collaps some modes if possible
if (SkPorterDuff::kClear_Mode == mode)
{
if (SkXfermode::kClear_Mode == mode) {
color = 0;
mode = SkPorterDuff::kSrc_Mode;
}
else if (SkPorterDuff::kSrcOver_Mode == mode)
{
if (0 == alpha)
{
mode = SkPorterDuff::kDst_Mode;
}
else if (255 == alpha)
{
mode = SkPorterDuff::kSrc_Mode;
mode = SkXfermode::kSrc_Mode;
} else if (SkXfermode::kSrcOver_Mode == mode) {
if (0 == alpha) {
mode = SkXfermode::kDst_Mode;
} else if (255 == alpha) {
mode = SkXfermode::kSrc_Mode;
}
// else just stay srcover
}
// weed out combinations that are noops, and just return null
if (SkPorterDuff::kDst_Mode == mode ||
(0 == alpha && (SkPorterDuff::kSrcOver_Mode == mode ||
SkPorterDuff::kDstOver_Mode == mode ||
SkPorterDuff::kDstOut_Mode == mode ||
SkPorterDuff::kSrcATop_Mode == mode ||
SkPorterDuff::kXor_Mode == mode ||
SkPorterDuff::kDarken_Mode == mode)) ||
(0xFF == alpha && SkPorterDuff::kDstIn_Mode == mode))
{
if (SkXfermode::kDst_Mode == mode ||
(0 == alpha && (SkXfermode::kSrcOver_Mode == mode ||
SkXfermode::kDstOver_Mode == mode ||
SkXfermode::kDstOut_Mode == mode ||
SkXfermode::kSrcATop_Mode == mode ||
SkXfermode::kXor_Mode == mode ||
SkXfermode::kDarken_Mode == mode)) ||
(0xFF == alpha && SkXfermode::kDstIn_Mode == mode)) {
return NULL;
}
switch (mode) {
case SkPorterDuff::kSrc_Mode:
case SkXfermode::kSrc_Mode:
return SkNEW_ARGS(SkSrc_XfermodeColorFilter, (color));
case SkPorterDuff::kSrcOver_Mode:
case SkXfermode::kSrcOver_Mode:
return SkNEW_ARGS(SkSrcOver_XfermodeColorFilter, (color));
default:
return SkColorFilter::CreatXfermodeProcFilter(color,
SkPorterDuff::GetXfermodeProc(mode),
SkPorterDuff::GetXfermodeProc16(mode, color));
return SkColorFilter::CreateProcFilter(color, SkXfermode::GetProc(mode),
SkXfermode::GetProc16(mode, color));
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
static inline unsigned pin(unsigned value, unsigned max)
{
if (value > max)
static inline unsigned pin(unsigned value, unsigned max) {
if (value > max) {
value = max;
}
return value;
}
static inline unsigned SkUClampMax(unsigned value, unsigned max)
{
static inline unsigned SkUClampMax(unsigned value, unsigned max) {
SkASSERT((int32_t)value >= 0);
SkASSERT((int32_t)max >= 0);
@ -268,8 +251,8 @@ class SkLightingColorFilter : public SkColorFilter {
public:
SkLightingColorFilter(SkColor mul, SkColor add) : fMul(mul), fAdd(add) {}
virtual void filterSpan(const SkPMColor shader[], int count, SkPMColor result[])
{
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));
@ -278,11 +261,9 @@ public:
unsigned addG = SkColorGetG(fAdd);
unsigned addB = SkColorGetB(fAdd);
for (int i = 0; i < count; i++)
{
for (int i = 0; i < count; i++) {
SkPMColor c = shader[i];
if (c)
{
if (c) {
unsigned a = SkGetPackedA32(c);
unsigned scaleA = SkAlpha255To256(a);
unsigned r = pin(SkAlphaMul(SkGetPackedR32(c), scaleR) + SkAlphaMul(addR, scaleA), a);
@ -295,19 +276,16 @@ public:
}
protected:
virtual void flatten(SkFlattenableWriteBuffer& buffer)
{
virtual void flatten(SkFlattenableWriteBuffer& buffer) {
buffer.write32(fMul);
buffer.write32(fAdd);
}
virtual Factory getFactory()
{
virtual Factory getFactory() {
return CreateProc;
}
SkLightingColorFilter(SkFlattenableReadBuffer& buffer)
{
SkLightingColorFilter(SkFlattenableReadBuffer& buffer) {
fMul = buffer.readU32();
fAdd = buffer.readU32();
}
@ -315,8 +293,7 @@ protected:
SkColor fMul, fAdd;
private:
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer)
{
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(SkLightingColorFilter, (buffer));
}
};
@ -326,17 +303,15 @@ public:
SkLightingColorFilter_JustAdd(SkColor mul, SkColor add)
: INHERITED(mul, add) {}
virtual void filterSpan(const SkPMColor shader[], int count, SkPMColor result[])
{
virtual void filterSpan(const SkPMColor shader[], int count,
SkPMColor result[]) {
unsigned addR = SkColorGetR(fAdd);
unsigned addG = SkColorGetG(fAdd);
unsigned addB = SkColorGetB(fAdd);
for (int i = 0; i < count; i++)
{
for (int i = 0; i < count; i++) {
SkPMColor c = shader[i];
if (c)
{
if (c) {
unsigned a = SkGetPackedA32(c);
unsigned scaleA = SkAlpha255To256(a);
unsigned r = pin(SkGetPackedR32(c) + SkAlphaMul(addR, scaleA), a);
@ -355,8 +330,7 @@ protected:
: INHERITED(buffer) {}
private:
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer)
{
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(SkLightingColorFilter_JustAdd, (buffer));
}
typedef SkLightingColorFilter INHERITED;
@ -367,17 +341,15 @@ public:
SkLightingColorFilter_JustMul(SkColor mul, SkColor add)
: INHERITED(mul, add) {}
virtual void filterSpan(const SkPMColor shader[], int count, SkPMColor result[])
{
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));
for (int i = 0; i < count; i++)
{
for (int i = 0; i < count; i++) {
SkPMColor c = shader[i];
if (c)
{
if (c) {
unsigned a = SkGetPackedA32(c);
unsigned r = SkAlphaMul(SkGetPackedR32(c), scaleR);
unsigned g = SkAlphaMul(SkGetPackedG32(c), scaleG);
@ -395,8 +367,7 @@ protected:
: INHERITED(buffer) {}
private:
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer)
{
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(SkLightingColorFilter_JustMul, (buffer));
}
@ -406,8 +377,7 @@ private:
class SkLightingColorFilter_SingleMul : public SkLightingColorFilter {
public:
SkLightingColorFilter_SingleMul(SkColor mul, SkColor add)
: INHERITED(mul, add)
{
: INHERITED(mul, add) {
SkASSERT(SkColorGetR(add) == 0);
SkASSERT(SkColorGetG(add) == 0);
SkASSERT(SkColorGetB(add) == 0);
@ -415,20 +385,20 @@ public:
SkASSERT(SkColorGetR(mul) == SkColorGetB(mul));
}
virtual uint32_t getFlags()
{
virtual uint32_t getFlags() {
return this->INHERITED::getFlags() | (kAlphaUnchanged_Flag | kHasFilter16_Flag);
}
virtual void filterSpan16(const uint16_t shader[], int count, uint16_t result[])
{
virtual void filterSpan16(const uint16_t shader[], int count,
uint16_t result[]) {
// all mul components are the same
unsigned scale = SkAlpha255To256(SkColorGetR(fMul));
if (count > 0)
if (count > 0) {
do {
*result++ = SkAlphaMulRGB16(*shader++, scale);
} while (--count > 0);
}
}
protected:
@ -438,8 +408,7 @@ protected:
: INHERITED(buffer) {}
private:
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer)
{
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(SkLightingColorFilter_SingleMul, (buffer));
}
@ -451,8 +420,8 @@ public:
SkLightingColorFilter_NoPin(SkColor mul, SkColor add)
: INHERITED(mul, add) {}
virtual void filterSpan(const SkPMColor shader[], int count, SkPMColor result[])
{
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));
@ -461,11 +430,9 @@ public:
unsigned addG = SkColorGetG(fAdd);
unsigned addB = SkColorGetB(fAdd);
for (int i = 0; i < count; i++)
{
for (int i = 0; i < count; i++) {
SkPMColor c = shader[i];
if (c)
{
if (c) {
unsigned a = SkGetPackedA32(c);
unsigned scaleA = SkAlpha255To256(a);
unsigned r = SkAlphaMul(SkGetPackedR32(c), scaleR) + SkAlphaMul(addR, scaleA);
@ -484,69 +451,60 @@ protected:
: INHERITED(buffer) {}
private:
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer)
{
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(SkLightingColorFilter_NoPin, (buffer));
}
typedef SkLightingColorFilter INHERITED;
};
//////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
class SkSimpleColorFilter : public SkColorFilter {
protected:
void filterSpan(const SkPMColor src[], int count, SkPMColor result[])
{
if (result != src)
void filterSpan(const SkPMColor src[], int count, SkPMColor result[]) {
if (result != src) {
memcpy(result, src, count * sizeof(SkPMColor));
}
}
virtual void flatten(SkFlattenableWriteBuffer& buffer)
{
}
virtual void flatten(SkFlattenableWriteBuffer& buffer) {}
virtual Factory getFactory()
{
virtual Factory getFactory() {
return CreateProc;
}
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer)
{
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW(SkSimpleColorFilter);
}
};
SkColorFilter* SkColorFilter::CreateLightingFilter(SkColor mul, SkColor add)
{
SkColorFilter* SkColorFilter::CreateLightingFilter(SkColor mul, SkColor add) {
mul &= 0x00FFFFFF;
add &= 0x00FFFFFF;
if (0xFFFFFF == mul)
{
if (0 == add)
if (0xFFFFFF == mul) {
if (0 == add) {
return SkNEW(SkSimpleColorFilter); // no change to the colors
else
} else {
return SkNEW_ARGS(SkLightingColorFilter_JustAdd, (mul, add));
}
}
if (0 == add)
{
if (0 == add) {
if (SkColorGetR(mul) == SkColorGetG(mul) &&
SkColorGetR(mul) == SkColorGetB(mul))
{
SkColorGetR(mul) == SkColorGetB(mul)) {
return SkNEW_ARGS(SkLightingColorFilter_SingleMul, (mul, add));
}
else
{
} else {
return SkNEW_ARGS(SkLightingColorFilter_JustMul, (mul, add));
}
}
if (SkColorGetR(mul) + SkColorGetR(add) <= 255 &&
SkColorGetG(mul) + SkColorGetG(add) <= 255 &&
SkColorGetB(mul) + SkColorGetB(add) <= 255)
return SkNEW_ARGS(SkLightingColorFilter_NoPin, (mul, add));
SkColorGetB(mul) + SkColorGetB(add) <= 255) {
return SkNEW_ARGS(SkLightingColorFilter_NoPin, (mul, add));
}
return SkNEW_ARGS(SkLightingColorFilter, (mul, add));
}

Просмотреть файл

@ -45,6 +45,13 @@ static bool find_pdmode(SkXfermode::Mode src, SkPorterDuff::Mode* dst) {
return false;
}
SkXfermode::Mode SkPorterDuff::ToXfermodeMode(Mode mode) {
SkASSERT((unsigned)mode < SkPorterDuff::kModeCount);
const Pair& pair = gPairs[mode];
SkASSERT(pair.fPD == mode);
return pair.fXF;
}
SkXfermode* SkPorterDuff::CreateXfermode(SkPorterDuff::Mode mode) {
const Pair& pair = gPairs[mode];
SkASSERT(pair.fPD == mode);