diff options
author | Mike Reed <reed@google.com> | 2009-06-22 22:53:17 -0400 |
---|---|---|
committer | Mike Reed <reed@google.com> | 2009-06-23 08:53:03 -0400 |
commit | 59f59bde0b05a6ac5ff28fdebc1942dbf0d43aab (patch) | |
tree | 5ce1159de2f8b6132da60919659b75b95f0a62cf /src/effects | |
parent | 9f0b433bdd1680cd1d371c19d7e0ffde8fb2c484 (diff) | |
download | external_skia-59f59bde0b05a6ac5ff28fdebc1942dbf0d43aab.zip external_skia-59f59bde0b05a6ac5ff28fdebc1942dbf0d43aab.tar.gz external_skia-59f59bde0b05a6ac5ff28fdebc1942dbf0d43aab.tar.bz2 |
remove deprecated uses of porterduff
Diffstat (limited to 'src/effects')
-rw-r--r-- | src/effects/SkColorFilters.cpp | 330 | ||||
-rw-r--r-- | src/effects/SkPorterDuff.cpp | 13 |
2 files changed, 151 insertions, 192 deletions
diff --git a/src/effects/SkColorFilters.cpp b/src/effects/SkColorFilters.cpp index 50be1ad..0bb3ae5 100644 --- a/src/effects/SkColorFilters.cpp +++ b/src/effects/SkColorFilters.cpp @@ -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)); } diff --git a/src/effects/SkPorterDuff.cpp b/src/effects/SkPorterDuff.cpp index 42f93b8..58447ad 100644 --- a/src/effects/SkPorterDuff.cpp +++ b/src/effects/SkPorterDuff.cpp @@ -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); @@ -67,9 +74,3 @@ SkXfermodeProc16 SkPorterDuff::GetXfermodeProc16(Mode mode, SkColor srcColor) { return SkXfermode::GetProc16(gPairs[mode].fXF, srcColor); } -// DEPRECATED -#include "SkPaint.h" -SkXfermode* SkPaint::setPorterDuffXfermode(SkPorterDuff::Mode mode) { - return this->setXfermode(SkPorterDuff::CreateXfermode(mode)); -} - |