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
diff --git a/src/effects/SkLayerRasterizer.cpp b/src/effects/SkLayerRasterizer.cpp
index 5aa883d..168fbe9 100644
--- a/src/effects/SkLayerRasterizer.cpp
+++ b/src/effects/SkLayerRasterizer.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.
 */
 
@@ -59,7 +59,7 @@
     SkLayerRasterizer_Rec*  rec;
 
     bounds->set(SK_MaxS32, SK_MaxS32, SK_MinS32, SK_MinS32);
-    
+
     while ((rec = (SkLayerRasterizer_Rec*)iter.next()) != NULL)
     {
         const SkPaint&  paint = rec->fPaint;
@@ -117,13 +117,13 @@
     }
 
     if (SkMask::kJustComputeBounds_CreateMode != mode)
-    {    
+    {
         SkBitmap device;
         SkDraw   draw;
         SkMatrix translatedMatrix;  // this translates us to our local pixels
         SkMatrix drawMatrix;        // this translates the path by each layer's offset
         SkRegion rectClip;
-        
+
         rectClip.setRect(0, 0, mask->fBounds.width(), mask->fBounds.height());
 
         translatedMatrix = matrix;
@@ -138,7 +138,7 @@
         draw.fClip      = &rectClip;
         // we set the matrixproc in the loop, as the matrix changes each time (potentially)
         draw.fBounder   = NULL;
-        
+
         SkDeque::Iter           iter(fLayers);
         SkLayerRasterizer_Rec*  rec;
 
@@ -158,7 +158,7 @@
     paint->setAntiAlias(buffer.readBool());
     paint->setStyle((SkPaint::Style)buffer.readU8());
     paint->setAlpha(buffer.readU8());
-    
+
     if (paint->getStyle() != SkPaint::kFill_Style)
     {
         paint->setStrokeWidth(buffer.readScalar());
@@ -167,10 +167,10 @@
         paint->setStrokeJoin((SkPaint::Join)buffer.readU8());
     }
 
-    paint->setMaskFilter((SkMaskFilter*)buffer.readFlattenable())->safeUnref();
-    paint->setPathEffect((SkPathEffect*)buffer.readFlattenable())->safeUnref();
-    paint->setRasterizer((SkRasterizer*)buffer.readFlattenable())->safeUnref();
-    paint->setXfermode((SkXfermode*)buffer.readFlattenable())->safeUnref();
+    SkSafeUnref(paint->setMaskFilter((SkMaskFilter*)buffer.readFlattenable()));
+    SkSafeUnref(paint->setPathEffect((SkPathEffect*)buffer.readFlattenable()));
+    SkSafeUnref(paint->setRasterizer((SkRasterizer*)buffer.readFlattenable()));
+    SkSafeUnref(paint->setXfermode((SkXfermode*)buffer.readFlattenable()));
 }
 
 static void paint_write(const SkPaint& paint, SkFlattenableWriteBuffer& buffer)
@@ -178,7 +178,7 @@
     buffer.writeBool(paint.isAntiAlias());
     buffer.write8(paint.getStyle());
     buffer.write8(paint.getAlpha());
-    
+
     if (paint.getStyle() != SkPaint::kFill_Style)
     {
         buffer.writeScalar(paint.getStrokeWidth());
@@ -186,7 +186,7 @@
         buffer.write8(paint.getStrokeCap());
         buffer.write8(paint.getStrokeJoin());
     }
-    
+
     buffer.writeFlattenable(paint.getMaskFilter());
     buffer.writeFlattenable(paint.getPathEffect());
     buffer.writeFlattenable(paint.getRasterizer());
@@ -197,11 +197,11 @@
     : SkRasterizer(buffer), fLayers(sizeof(SkLayerRasterizer_Rec))
 {
     int count = buffer.readS32();
-    
+
     for (int i = 0; i < count; i++)
     {
         SkLayerRasterizer_Rec* rec = (SkLayerRasterizer_Rec*)fLayers.push_back();
-    
+
 #if 0
         new (&rec->fPaint) SkPaint(buffer);
 #else