From 82065d667f64e232bcde2ad849756a6096fcbe6f Mon Sep 17 00:00:00 2001 From: "reed@google.com" Date: Mon, 7 Feb 2011 15:30:46 +0000 Subject: remove SkRefCnt safeRef() and safeUnref(), and replace the call-sites with SkSafeRef() and SkSafeUnref(). This is basically a bug waiting to happen. An optimizing compiler can remove checks for null on "this" if it chooses. However, SkRefCnt::safeRef() relies on precisely this check... void SkRefCnt::safeRef() { if (this) { this->ref(); } } Since a compiler might skip the if-clause, it breaks the intention of this method, hence its removal. static inline void SkSafeRef(SkRefCnt* obj) { if (obj) { obj->ref(); } } This form is not ignored by an optimizing compile, so we use it instead. git-svn-id: http://skia.googlecode.com/svn/trunk@762 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/core/SkBlitter_4444.cpp | 111 ++++++++++++++++++++++---------------------- 1 file changed, 56 insertions(+), 55 deletions(-) (limited to 'src/core/SkBlitter_4444.cpp') diff --git a/src/core/SkBlitter_4444.cpp b/src/core/SkBlitter_4444.cpp index 81bbc48cbb..e1c519a313 100644 --- a/src/core/SkBlitter_4444.cpp +++ b/src/core/SkBlitter_4444.cpp @@ -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. */ @@ -23,13 +23,13 @@ #include "SkUtils.h" #include "SkXfermode.h" -inline SkPMColor SkBlendARGB4444(SkPMColor16 src, SkPMColor16 dst, U8CPU aa) -{ +static inline SkPMColor SkBlendARGB4444(SkPMColor16 src, SkPMColor16 dst, + U8CPU aa) { SkASSERT((unsigned)aa <= 255); - + unsigned src_scale = SkAlpha255To256(aa) >> 4; unsigned dst_scale = SkAlpha15To16(15 - SkAlphaMul4(SkGetPackedA4444(src), src_scale)); - + uint32_t src32 = SkExpand_4444(src) * src_scale; uint32_t dst32 = SkExpand_4444(dst) * dst_scale; return SkCompact_4444((src32 + dst32) >> 4); @@ -46,16 +46,16 @@ public: virtual void blitRect(int x, int y, int width, int height); virtual void blitMask(const SkMask&, const SkIRect&); virtual const SkBitmap* justAnOpaqueColor(uint32_t*); - + protected: SkPMColor16 fPMColor16, fPMColor16Other; SkPMColor16 fRawColor16, fRawColor16Other; uint8_t fScale16; - + private: // illegal SkARGB4444_Blitter& operator=(const SkARGB4444_Blitter&); - + typedef SkRasterBlitter INHERITED; }; @@ -81,7 +81,7 @@ SkARGB4444_Blitter::SkARGB4444_Blitter(const SkBitmap& device, const SkPaint& pa } else { fRawColor16Other = fRawColor16; } - + #if 0 /// don't think this assertion is true, but need it be? // our dithered color will be the same or more opaque than the original @@ -146,19 +146,19 @@ static void src_over_4444x(SkPMColor16 dst[], uint32_t color, void SkARGB4444_Blitter::blitH(int x, int y, int width) { SkASSERT(x >= 0 && y >= 0 && x + width <= fDevice.width()); - + if (0 == fScale16) { return; } - + SkPMColor16* device = fDevice.getAddr16(x, y); SkPMColor16 color = fPMColor16; SkPMColor16 other = fPMColor16Other; - + if ((x ^ y) & 1) { SkTSwap(color, other); } - + if (16 == fScale16) { sk_dither_memset16(device, color, other, width); } @@ -174,12 +174,12 @@ void SkARGB4444_Blitter::blitV(int x, int y, int height, SkAlpha alpha) if (0 == alpha || 0 == fScale16) { return; } - + SkPMColor16* device = fDevice.getAddr16(x, y); SkPMColor16 color = fPMColor16; SkPMColor16 other = fPMColor16Other; unsigned rb = fDevice.rowBytes(); - + if ((x ^ y) & 1) { SkTSwap(color, other); } @@ -211,19 +211,19 @@ void SkARGB4444_Blitter::blitV(int x, int y, int height, SkAlpha alpha) void SkARGB4444_Blitter::blitRect(int x, int y, int width, int height) { SkASSERT(x >= 0 && y >= 0 && x + width <= fDevice.width() && y + height <= fDevice.height()); - + if (0 == fScale16) { return; } - + SkPMColor16* device = fDevice.getAddr16(x, y); SkPMColor16 color = fPMColor16; SkPMColor16 other = fPMColor16Other; - + if ((x ^ y) & 1) { SkTSwap(color, other); } - + if (16 == fScale16) { while (--height >= 0) { sk_dither_memset16(device, color, other, width); @@ -248,22 +248,22 @@ void SkARGB4444_Blitter::blitAntiH(int x, int y, const SkAlpha antialias[], cons if (0 == fScale16) { return; } - + SkPMColor16* device = fDevice.getAddr16(x, y); SkPMColor16 color = fPMColor16; SkPMColor16 other = fPMColor16Other; - + if ((x ^ y) & 1) { SkTSwap(color, other); } - + for (;;) { int count = runs[0]; SkASSERT(count >= 0); if (count <= 0) { return; } - + unsigned aa = antialias[0]; if (aa) { if (0xFF == aa) { @@ -338,11 +338,11 @@ if (mask & 0x01) { dst[7] = sc + SkAlphaMulQ4(dst[7], dst_scale); } \ void SkARGB4444_Blitter::blitMask(const SkMask& mask, const SkIRect& clip) { SkASSERT(mask.fBounds.contains(clip)); - + if (0 == fScale16) { return; } - + if (mask.fFormat == SkMask::kBW_Format) { if (16 == fScale16) { SkARGB4444_BlitBW(fDevice, mask, clip, fPMColor16); @@ -351,18 +351,18 @@ void SkARGB4444_Blitter::blitMask(const SkMask& mask, const SkIRect& clip) } return; } - + int x = clip.fLeft; int y = clip.fTop; int width = clip.width(); int height = clip.height(); - + SkPMColor16* device = fDevice.getAddr16(x, y); const uint8_t* alpha = mask.getAddr(x, y); SkPMColor16 srcColor = fPMColor16; unsigned devRB = fDevice.rowBytes() - (width << 1); unsigned maskRB = mask.fRowBytes - width; - + do { int w = width; do { @@ -384,15 +384,17 @@ class SkARGB4444_Shader_Blitter : public SkShaderBlitter { SkPMColor* fBuffer; uint8_t* fAAExpand; public: + SkARGB4444_Shader_Blitter(const SkBitmap& device, const SkPaint& paint) : INHERITED(device, paint) { const int width = device.width(); fBuffer = (SkPMColor*)sk_malloc_throw(width * sizeof(SkPMColor) + width); fAAExpand = (uint8_t*)(fBuffer + width); - - (fXfermode = paint.getXfermode())->safeRef(); - + + fXfermode = paint.getXfermode(); + SkSafeRef(fXfermode); + unsigned flags = 0; if (!(fShader->getFlags() & SkShader::kOpaqueAlpha_Flag)) { flags |= SkBlitRow::kSrcPixelAlpha_Flag; @@ -405,41 +407,39 @@ SkARGB4444_Shader_Blitter(const SkBitmap& device, const SkPaint& paint) SkBitmap::kARGB_4444_Config); } -virtual ~SkARGB4444_Shader_Blitter() -{ - fXfermode->safeUnref(); +virtual ~SkARGB4444_Shader_Blitter() { + SkSafeUnref(fXfermode); sk_free(fBuffer); } -virtual void blitH(int x, int y, int width) -{ +virtual void blitH(int x, int y, int width) { SkASSERT(x >= 0 && y >= 0 && x + width <= fDevice.width()); - - SkPMColor16* device = fDevice.getAddr16(x, y); + + SkPMColor16* device = fDevice.getAddr16(x, y); SkPMColor* span = fBuffer; - + fShader->shadeSpan(x, y, span, width); if (fXfermode) { fXfermode->xfer4444(device, span, width, NULL); - } - else { + } else { fOpaqueProc(device, span, width, 0xFF, x, y); } } -virtual void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]) -{ +virtual void blitAntiH(int x, int y, const SkAlpha antialias[], + const int16_t runs[]) { SkPMColor* SK_RESTRICT span = fBuffer; uint8_t* SK_RESTRICT aaExpand = fAAExpand; SkPMColor16* device = fDevice.getAddr16(x, y); SkShader* shader = fShader; SkXfermode* xfer = fXfermode; - + if (NULL != xfer) { for (;;) { int count = *runs; - if (count <= 0) + if (count <= 0) { break; + } int aa = *antialias; if (aa) { shader->shadeSpan(x, y, span, count); @@ -458,12 +458,13 @@ virtual void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t ru runs += count; antialias += count; x += count; - } + } } else { // no xfermode for (;;) { int count = *runs; - if (count <= 0) + if (count <= 0) { break; + } int aa = *antialias; if (aa) { fShader->shadeSpan(x, y, span, count); @@ -477,7 +478,7 @@ virtual void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t ru runs += count; antialias += count; x += count; - } + } } } -- cgit v1.2.3