Addressed Windows compiler complaints

http://codereview.appspot.com/6462062/

This CL will require re-baselining of the imagemagnifier GM



git-svn-id: http://skia.googlecode.com/svn/trunk@5108 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gm/typeface.cpp b/gm/typeface.cpp
index af04725..9c73630 100644
--- a/gm/typeface.cpp
+++ b/gm/typeface.cpp
@@ -35,7 +35,7 @@
         for (size_t i = 0; i < SK_ARRAY_COUNT(gFaces); i++) {
             fFaces[i]->unref();
         }
-        delete fFaces;
+        delete [] fFaces;
     }
 
 protected:
diff --git a/src/core/SkPath.cpp b/src/core/SkPath.cpp
index a9937ab..4be1c98 100644
--- a/src/core/SkPath.cpp
+++ b/src/core/SkPath.cpp
@@ -1816,7 +1816,7 @@
         SkRect bounds;
 
         bool isFinite = compute_pt_bounds(&bounds, fPts);
-        SkASSERT(fIsFinite == isFinite);
+        SkASSERT(SkToBool(fIsFinite) == isFinite);
 
         if (fPts.count() <= 1) {
             // if we're empty, fBounds may be empty but translated, so we can't
diff --git a/src/effects/SkMagnifierImageFilter.cpp b/src/effects/SkMagnifierImageFilter.cpp
index 626de95..846fd28 100644
--- a/src/effects/SkMagnifierImageFilter.cpp
+++ b/src/effects/SkMagnifierImageFilter.cpp
@@ -192,15 +192,16 @@
     const int kMaxWidth = 200;
     const int kMaxHeight = 200;
     const int kMaxInset = 20;
-    SkScalar width = random->nextULessThan(kMaxWidth);
-    SkScalar height = random->nextULessThan(kMaxHeight);
-    SkScalar x = random->nextULessThan(kMaxWidth - width);
-    SkScalar y = random->nextULessThan(kMaxHeight - height);
-    SkScalar inset = random->nextULessThan(kMaxInset);
+    uint32_t width = random->nextULessThan(kMaxWidth);
+    uint32_t height = random->nextULessThan(kMaxHeight);
+    uint32_t x = random->nextULessThan(kMaxWidth - width);
+    uint32_t y = random->nextULessThan(kMaxHeight - height);
+    SkScalar inset = SkIntToScalar(random->nextULessThan(kMaxInset));
 
     SkAutoTUnref<SkImageFilter> filter(
             new SkMagnifierImageFilter(
-                SkRect::MakeXYWH(x, y, width, height),
+                SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y),
+                                 SkIntToScalar(width), SkIntToScalar(height)),
                 inset));
     GrSamplerState sampler;
     GrCustomStage* stage;
@@ -289,10 +290,10 @@
       return false;
     }
 
-    float inv_inset = fInset > 0 ? 1.0f / SkScalarToFloat(fInset) : 1.0f;
+    SkScalar inv_inset = fInset > 0 ? SkScalarInvert(fInset) : SK_Scalar1;
 
-    float inv_x_zoom = fSrcRect.width() / src.width();
-    float inv_y_zoom = fSrcRect.height() / src.height();
+    SkScalar inv_x_zoom = fSrcRect.width() / src.width();
+    SkScalar inv_y_zoom = fSrcRect.height() / src.height();
 
     dst->setConfig(src.config(), src.width(), src.height());
     dst->allocPixels();
@@ -301,31 +302,35 @@
     int width = src.width(), height = src.height();
     for (int y = 0; y < height; ++y) {
         for (int x = 0; x < width; ++x) {
-            float x_dist = SkMinScalar(x, width - x - 1) * inv_inset;
-            float y_dist = SkMinScalar(y, height - y - 1) * inv_inset;
-            float weight = 0;
+            SkScalar x_dist = SkMin32(x, width - x - 1) * inv_inset;
+            SkScalar y_dist = SkMin32(y, height - y - 1) * inv_inset;
+            SkScalar weight = 0;
+
+            static const SkScalar kScalar2 = SkScalar(2);
 
             // To create a smooth curve at the corners, we need to work on
             // a square twice the size of the inset.
-            if (x_dist < 2 && y_dist < 2) {
-                x_dist = 2 - x_dist;
-                y_dist = 2 - y_dist;
+            if (x_dist < kScalar2 && y_dist < kScalar2) {
+                x_dist = kScalar2 - x_dist;
+                y_dist = kScalar2 - y_dist;
 
-                float dist = sqrt(x_dist * x_dist + y_dist * y_dist);
-                dist = SkMaxScalar(2 - dist, 0.0f);
-                weight = SkMinScalar(dist * dist, 1.0f);
+                SkScalar dist = SkScalarSqrt(SkScalarSquare(x_dist) +
+                                             SkScalarSquare(y_dist));
+                dist = SkMaxScalar(kScalar2 - dist, 0);
+                weight = SkMinScalar(SkScalarSquare(dist), SK_Scalar1);
             } else {
-                float sq_dist = SkMinScalar(x_dist * x_dist, y_dist * y_dist);
-                weight = SkMinScalar(sq_dist, 1.0f);
+                SkScalar sqDist = SkMinScalar(SkScalarSquare(x_dist),
+                                              SkScalarSquare(y_dist));
+                weight = SkMinScalar(sqDist, SK_Scalar1);
             }
 
-            int x_val = weight * (fSrcRect.x() + x * inv_x_zoom) +
-                        (1 - weight) * x;
-            int y_val = weight * (fSrcRect.y() + y * inv_y_zoom) +
-                        (1 - weight) * y;
+            SkScalar x_interp = SkScalarMul(weight, (fSrcRect.x() + x * inv_x_zoom)) +
+                           (SK_Scalar1 - weight) * x;
+            SkScalar y_interp = SkScalarMul(weight, (fSrcRect.y() + y * inv_y_zoom)) +
+                           (SK_Scalar1 - weight) * y;
 
-            x_val = SkMin32(x_val, width - 1);
-            y_val = SkMin32(y_val, height - 1);
+            int x_val = SkMin32(SkScalarFloorToInt(x_interp), width - 1);
+            int y_val = SkMin32(SkScalarFloorToInt(y_interp), height - 1);
 
             *dptr = sptr[y_val * width + x_val];
             dptr++;
diff --git a/src/gpu/GrClipMaskManager.h b/src/gpu/GrClipMaskManager.h
index fed4205..1187a08 100644
--- a/src/gpu/GrClipMaskManager.h
+++ b/src/gpu/GrClipMaskManager.h
@@ -264,8 +264,8 @@
 public:
     GR_DECLARE_RESOURCE_CACHE_DOMAIN(GetAlphaMaskDomain)
 
-    GrClipMaskManager(GrGpu* gpu)
-        : fGpu(gpu)
+    GrClipMaskManager()
+        : fGpu(NULL)
         , fCurrClipMaskType(kNone_ClipMaskType) {
     }
 
@@ -299,6 +299,10 @@
         return fAACache.getContext();
     }
 
+    void setGpu(GrGpu* gpu) { 
+        fGpu = gpu;
+    }
+
 private:
     /**
      * Informs the helper function adjustStencilParams() about how the stencil
diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp
index a9306f4..c159f5e 100644
--- a/src/gpu/GrGpu.cpp
+++ b/src/gpu/GrGpu.cpp
@@ -29,8 +29,7 @@
 #define DEBUG_INVAL_START_IDX -1
 
 GrGpu::GrGpu()
-    : fClipMaskManager(this)
-    , fContext(NULL)
+    : fContext(NULL)
     , fResetTimestamp(kExpiredTimestamp+1)
     , fVertexPool(NULL)
     , fIndexPool(NULL)
@@ -41,10 +40,12 @@
     , fContextIsDirty(true)
     , fResourceHead(NULL) {
 
+    fClipMaskManager.setGpu(this);
+
 #if GR_DEBUG
     //gr_run_unittests();
 #endif
-        
+
     fGeomPoolStateStack.push_back();
 #if GR_DEBUG
     GeometryPoolState& poolState = fGeomPoolStateStack.back();
diff --git a/tools/PictureRenderer.cpp b/tools/PictureRenderer.cpp
index 6af1218..f0aba9f 100644
--- a/tools/PictureRenderer.cpp
+++ b/tools/PictureRenderer.cpp
@@ -76,10 +76,10 @@
     this->INHERITED::init(pict);
 
     if (fTileWidthPercentage > 0) {
-        fTileWidth = sk_float_ceil2int(fTileWidthPercentage * fPicture->width() / 100);
+        fTileWidth = sk_float_ceil2int(float(fTileWidthPercentage * fPicture->width() / 100));
     }
     if (fTileHeightPercentage > 0) {
-        fTileHeight = sk_float_ceil2int(fTileHeightPercentage * fPicture->height() / 100);
+        fTileHeight = sk_float_ceil2int(float(fTileHeightPercentage * fPicture->height() / 100));
     }
 
     this->setupTiles();