Fix errors when compiling with -Wall -Werror on Android.

This CL also turns those features on by default on Android

Review URL: https://codereview.appspot.com/7313049

git-svn-id: http://skia.googlecode.com/svn/trunk@7645 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/bench/BlurRectBench.cpp b/bench/BlurRectBench.cpp
index b0b06e6..a3825be 100644
--- a/bench/BlurRectBench.cpp
+++ b/bench/BlurRectBench.cpp
@@ -19,12 +19,21 @@
 #define REALBIG SkFloatToScalar(30.5f)
 
 class BlurRectBench: public SkBenchmark {
+    int         fLoopCount;
     SkScalar    fRadius;
     SkString    fName;
 
 public:
     BlurRectBench(void *param, SkScalar rad) : INHERITED(param) {
         fRadius = rad;
+
+        if (fRadius > SkIntToScalar(25)) {
+            fLoopCount = 100;
+        } else if (fRadius > SkIntToScalar(5)) {
+            fLoopCount = 1000;
+        } else {
+            fLoopCount = 10000;
+        }
     }
 
 protected:
@@ -49,19 +58,9 @@
         SkScalar pad = fRadius*3/2 + SK_Scalar1;
         SkRect r = SkRect::MakeWH(2 * pad + SK_Scalar1, 2 * pad + SK_Scalar1);
 
-        int loop_count;
-
-        if (fRadius > SkIntToScalar(25)) {
-          loop_count = 100;
-        } else if (fRadius > SkIntToScalar(5)) {
-          loop_count = 1000;
-        } else {
-          loop_count = 10000;
-        }
-
         preBenchSetup(r);
 
-        for (int i = 0; i < SkBENCHLOOP(loop_count); i++) {
+        for (int i = 0; i < SkBENCHLOOP(fLoopCount); i++) {
             makeBlurryRect(r);
         }
     }
diff --git a/gyp/common_conditions.gypi b/gyp/common_conditions.gypi
index d61cc94..d1368dd 100644
--- a/gyp/common_conditions.gypi
+++ b/gyp/common_conditions.gypi
@@ -311,8 +311,10 @@
           '-llog',
         ],
         'cflags': [
+          '-Wall',
           '-fno-exceptions',
           '-fno-rtti',
+          '-fstrict-aliasing',
           '-fuse-ld=gold',
         ],
         'conditions': [
diff --git a/gyp/jsoncpp.gyp b/gyp/jsoncpp.gyp
index 1ee33fd..07507d4 100644
--- a/gyp/jsoncpp.gyp
+++ b/gyp/jsoncpp.gyp
@@ -61,6 +61,12 @@
             },
           },
         }],
+        [ 'skia_os == "android"', {
+          'cflags!': [
+            '-Wall',
+            '-Werror',
+          ],
+        }],
       ],
     },
   ],
diff --git a/gyp/libjpeg.gyp b/gyp/libjpeg.gyp
index 5780b27..a9d6aef 100644
--- a/gyp/libjpeg.gyp
+++ b/gyp/libjpeg.gyp
@@ -89,6 +89,8 @@
             ['OS=="android"', {
               'cflags!': [
                '-fno-rtti', # supresses warnings about invalid option of non-C++ code
+               '-Wall',
+               '-Werror',
               ],
             }],
           ],
diff --git a/gyp/utils.gyp b/gyp/utils.gyp
index c62657d..7c445d0 100644
--- a/gyp/utils.gyp
+++ b/gyp/utils.gyp
@@ -199,7 +199,7 @@
         }],
         [ 'skia_os == "android"', {
           'sources': [
-            '../src/utils/android/ashmem.c',
+            '../src/utils/android/ashmem.cpp',
           ],
         }],
       ],
@@ -242,6 +242,12 @@
             },
           },
         }],
+        [ 'skia_os == "android"', {
+          'cflags!': [
+            '-Wall',
+            '-Werror',
+          ],
+        }],
       ],
     },
   ],
diff --git a/include/core/SkFloatingPoint.h b/include/core/SkFloatingPoint.h
index 96270b0..02880f3 100644
--- a/include/core/SkFloatingPoint.h
+++ b/include/core/SkFloatingPoint.h
@@ -91,7 +91,7 @@
 extern const uint32_t gIEEEInfinity;
 extern const uint32_t gIEEENegativeInfinity;
 
-#define SK_FloatNaN                 (*reinterpret_cast<const float*>(&gIEEENotANumber))
-#define SK_FloatInfinity            (*reinterpret_cast<const float*>(&gIEEEInfinity))
-#define SK_FloatNegativeInfinity    (*reinterpret_cast<const float*>(&gIEEENegativeInfinity))
+#define SK_FloatNaN                 (*SkTCast<const float*>(&gIEEENotANumber))
+#define SK_FloatInfinity            (*SkTCast<const float*>(&gIEEEInfinity))
+#define SK_FloatNegativeInfinity    (*SkTCast<const float*>(&gIEEENegativeInfinity))
 #endif
diff --git a/include/utils/SkRandom.h b/include/utils/SkRandom.h
index 150384d..6ab1cd1 100644
--- a/include/utils/SkRandom.h
+++ b/include/utils/SkRandom.h
@@ -197,7 +197,7 @@
      */
     float nextF() {
         unsigned int floatint = 0x3f800000 | (this->nextU() >> 9);
-        float f = *(float*)(&floatint) - 1.0f;
+        float f = *SkTCast<float*>(&floatint) - 1.0f;
         return f;
     }
 
diff --git a/samplecode/SamplePolyToPoly.cpp b/samplecode/SamplePolyToPoly.cpp
index 93a5351..a0401f6 100644
--- a/samplecode/SamplePolyToPoly.cpp
+++ b/samplecode/SamplePolyToPoly.cpp
@@ -27,9 +27,8 @@
                               { 2*SK_Scalar1, 0 },
                               { 0, 2*SK_Scalar1 } };
             SkMatrix m1, m2;
-            bool success;
 
-            success = m1.setPolyToPoly(src, dst, 3);
+            (void) m1.setPolyToPoly(src, dst, 3);
 
             m2.reset();
             m2.set(SkMatrix::kMScaleX, dst[1].fX - dst[0].fX);
@@ -49,7 +48,7 @@
                 SkFloatToScalar(158), SkFloatToScalar(604.5f), SkFloatToScalar(158), SkFloatToScalar(-177.5f)
             };
 
-            success = m2.setPolyToPoly((const SkPoint*)src1, (SkPoint*)dst1, 4);
+            (void) m2.setPolyToPoly((const SkPoint*)src1, (SkPoint*)dst1, 4);
 
             {
                 const SkPoint src[] = {
diff --git a/src/core/SkAdvancedTypefaceMetrics.cpp b/src/core/SkAdvancedTypefaceMetrics.cpp
index b647ada..e41bb81 100644
--- a/src/core/SkAdvancedTypefaceMetrics.cpp
+++ b/src/core/SkAdvancedTypefaceMetrics.cpp
@@ -153,7 +153,6 @@
     Data lastAdvance = kInvalidAdvance;
     int repeatedAdvances = 0;
     int wildCardsInRun = 0;
-    int leadingWildCards = 0;
     int trailingWildCards = 0;
     uint32_t subsetIndex = 0;
 
@@ -200,7 +199,6 @@
             }
             repeatedAdvances = 0;
             wildCardsInRun = trailingWildCards;
-            leadingWildCards = trailingWildCards;
             trailingWildCards = 0;
         } else {
             if (lastAdvance == 0 &&
@@ -236,7 +234,6 @@
             }
             repeatedAdvances = 0;
             wildCardsInRun = trailingWildCards;
-            leadingWildCards = trailingWildCards;
             trailingWildCards = 0;
         }
         curRange->fAdvance.append(1, &advance);
diff --git a/src/core/SkPictureFlat.h b/src/core/SkPictureFlat.h
index 6354e9f..e577f79 100644
--- a/src/core/SkPictureFlat.h
+++ b/src/core/SkPictureFlat.h
@@ -362,7 +362,7 @@
 
     // marks fTopBot[] as unrecorded
     void setTopBotUnwritten() {
-        this->fTopBot[0] = this->fTopBot[1] = SK_ScalarNaN; // initial to sentinel values
+        this->fTopBot[0] = SK_ScalarNaN; // initial to sentinel values
     }
 
     // From here down is the data we look at in the search/sort. We always begin
diff --git a/src/images/SkMovie_gif.cpp b/src/images/SkMovie_gif.cpp
index cda1525..cda53d8 100644
--- a/src/images/SkMovie_gif.cpp
+++ b/src/images/SkMovie_gif.cpp
@@ -188,9 +188,6 @@
         copyHeight = height - frame->ImageDesc.Top;
     }
 
-    int srcPad, dstPad;
-    dstPad = width - copyWidth;
-    srcPad = frame->ImageDesc.Width - copyWidth;
     for (; copyHeight > 0; copyHeight--) {
         copyLine(dst, src, cmap, transparent, copyWidth);
         src += frame->ImageDesc.Width;
diff --git a/src/opts/SkBitmapProcState_matrixProcs_neon.cpp b/src/opts/SkBitmapProcState_matrixProcs_neon.cpp
index e9684e2..7d75143 100644
--- a/src/opts/SkBitmapProcState_matrixProcs_neon.cpp
+++ b/src/opts/SkBitmapProcState_matrixProcs_neon.cpp
@@ -47,7 +47,6 @@
 
         /* now build fx/fx+dx/fx+2dx/fx+3dx */
         SkFixed fx1, fx2, fx3;
-        int32x2_t lower, upper;
         int32x4_t lbase, hbase;
         uint16_t *dst16 = (uint16_t *)dst;
 
diff --git a/src/opts/SkBitmapProcState_matrix_clamp_neon.h b/src/opts/SkBitmapProcState_matrix_clamp_neon.h
index 4f47d47..5af7a52 100644
--- a/src/opts/SkBitmapProcState_matrix_clamp_neon.h
+++ b/src/opts/SkBitmapProcState_matrix_clamp_neon.h
@@ -106,7 +106,6 @@
 
         /* now build fx/fx+dx/fx+2dx/fx+3dx */
         SkFixed fx1, fx2, fx3;
-        int32x2_t lower, upper;
         int32x4_t lbase, hbase;
         int16_t *dst16 = (int16_t *)xy;
 
@@ -324,8 +323,8 @@
          */
 
             do {
-                int16x4_t xlo, xhi, ylo, yhi;
-                int16x4_t x2lo, x2hi, y2lo, y2hi;
+                int16x4_t xhi, yhi;
+                int16x4_t x2hi, y2hi;
 
                 /* vld4 does the de-interleaving for us */
         {
@@ -338,9 +337,7 @@
                         : "=w" (t_xlo), "=w" (t_xhi), "=w" (t_ylo), "=w" (t_yhi)
                         : "r" (mysrc)
                     );
-            xlo = t_xlo;
             xhi = t_xhi;
-            ylo = t_ylo;
             yhi = t_yhi;
         }
 
@@ -364,9 +361,7 @@
                         : "=w" (t_xlo), "=w" (t_xhi), "=w" (t_ylo), "=w" (t_yhi)
                         : "r" (mysrc+16)
                     );
-            x2lo = t_xlo;
             x2hi = t_xhi;
-            y2lo = t_ylo;
             y2hi = t_yhi;
         }
 
@@ -517,8 +512,7 @@
 #endif
 
     if (count >= 4) {
-        int32x4_t wide_dx, wide_one;
-        int32x4_t wide_fx, wide_fx1, wide_i, wide_lo;
+        int32x4_t wide_one, wide_fx, wide_fx1, wide_i, wide_lo;
     #if 0
         /* verification hooks -- see below */
         SkFixed debug_fx = fx;
@@ -530,7 +524,6 @@
         wide_fx = vsetq_lane_s32(fx+dx+dx, wide_fx, 2);
         wide_fx = vsetq_lane_s32(fx+dx+dx+dx, wide_fx, 3);
 
-        wide_dx = vdupq_n_s32(dx);
         wide_one = vdupq_n_s32(one);
 
         while (count >= 4) {
@@ -617,9 +610,9 @@
     unsigned maxY = s.fBitmap->height() - 1;
 
     if (count >= 4) {
-        int32x4_t wide_one, wide_i, wide_lo;
-        int32x4_t wide_dx, wide_fx, wide_onex, wide_fx1;
-        int32x4_t wide_dy, wide_fy, wide_oney, wide_fy1;
+        int32x4_t wide_i, wide_lo;
+        int32x4_t wide_fx, wide_onex, wide_fx1;
+        int32x4_t wide_fy, wide_oney, wide_fy1;
 
     #undef    AFFINE_DEBUG
     #if    defined(AFFINE_DEBUG)
@@ -633,13 +626,11 @@
         wide_fx = vsetq_lane_s32(fx+dx, wide_fx, 1);
         wide_fx = vsetq_lane_s32(fx+dx+dx, wide_fx, 2);
         wide_fx = vsetq_lane_s32(fx+dx+dx+dx, wide_fx, 3);
-        wide_dx = vdupq_n_s32(dx);
 
         wide_fy = vdupq_n_s32(fy);
         wide_fy = vsetq_lane_s32(fy+dy, wide_fy, 1);
         wide_fy = vsetq_lane_s32(fy+dy+dy, wide_fy, 2);
         wide_fy = vsetq_lane_s32(fy+dy+dy+dy, wide_fy, 3);
-        wide_dy = vdupq_n_s32(dy);
 
         wide_onex = vdupq_n_s32(oneX);
         wide_oney = vdupq_n_s32(oneY);
@@ -774,7 +765,7 @@
         const SkFixed* SK_RESTRICT srcXY = iter.getXY();
 
         if (count >= 4) {
-            int32x4_t wide_one, wide_i, wide_lo;
+            int32x4_t wide_i, wide_lo;
             int32x4_t wide_fx1;
             int32x4_t wide_fy1;
             int32x4_t wide_x, wide_y;
diff --git a/src/opts/SkBitmapProcState_matrix_repeat_neon.h b/src/opts/SkBitmapProcState_matrix_repeat_neon.h
index 615f3ff..a0eb0a9 100644
--- a/src/opts/SkBitmapProcState_matrix_repeat_neon.h
+++ b/src/opts/SkBitmapProcState_matrix_repeat_neon.h
@@ -103,7 +103,6 @@
 
         /* now build fx/fx+dx/fx+2dx/fx+3dx */
         SkFixed fx1, fx2, fx3;
-        int32x2_t lower, upper;
         int32x4_t lbase, hbase;
         int16_t *dst16 = (int16_t *)xy;
 
@@ -179,7 +178,7 @@
     int maxX = s.fBitmap->width() - 1;
     int maxY = s.fBitmap->height() - 1;
 
-#if 1
+#if 0
     int ocount = count;
     uint32_t *oxy = xy;
     SkFixed bfx = fx, bfy=fy, bdx=dx, bdy=dy;
@@ -199,7 +198,6 @@
         SkFixed dy4 = dy*4;
 
         /* now build fx/fx+dx/fx+2dx/fx+3dx */
-        int32x2_t lower, upper;
         int32x4_t xbase, ybase;
         int16_t *dst16 = (int16_t *)xy;
 
diff --git a/src/opts/SkBlitRow_opts_arm_neon.cpp b/src/opts/SkBlitRow_opts_arm_neon.cpp
index 14d5968..22785be 100644
--- a/src/opts/SkBlitRow_opts_arm_neon.cpp
+++ b/src/opts/SkBlitRow_opts_arm_neon.cpp
@@ -24,7 +24,7 @@
     SkASSERT(255 == alpha);
 
     if (count >= 8) {
-        uint16_t* SK_RESTRICT keep_dst;
+        uint16_t* SK_RESTRICT keep_dst = 0;
 
         asm volatile (
                       "ands       ip, %[count], #7            \n\t"
@@ -104,7 +104,7 @@
     }
     else
     {   // handle count < 8
-        uint16_t* SK_RESTRICT keep_dst;
+        uint16_t* SK_RESTRICT keep_dst = 0;
 
         asm volatile (
                       "vmov.u8    d31, #1<<7                  \n\t"
@@ -889,8 +889,8 @@
     d = vld1_u8(dstart);
 
     while (count >= UNROLL) {
-        uint8x8_t sr, sg, sb, sa;
-        uint16x8_t dr, dg, db, da;
+        uint8x8_t sr, sg, sb;
+        uint16x8_t dr, dg, db;
         uint16x8_t dst8;
 
         /* source is in ABGR ordering (R == lsb) */
@@ -904,7 +904,7 @@
             : "=w" (d0), "=w" (d1), "=w" (d2), "=w" (d3)
             : "r" (src)
                     );
-            sr = d0; sg = d1; sb = d2; sa = d3;
+            sr = d0; sg = d1; sb = d2;
         }
         /* XXX: if we want to prefetch, hide it in the above asm()
          * using the gcc __builtin_prefetch(), the prefetch will
diff --git a/src/ports/FontHostConfiguration_android.cpp b/src/ports/FontHostConfiguration_android.cpp
index 6d03414..ef5a742 100644
--- a/src/ports/FontHostConfiguration_android.cpp
+++ b/src/ports/FontHostConfiguration_android.cpp
@@ -82,7 +82,6 @@
         // The Family tag has an optional "order" attribute with an integer value >= 0
         // If this attribute does not exist, the default value is -1
         for (int i = 0; atts[i] != NULL; i += 2) {
-            const char* attribute = atts[i];
             const char* valueString = atts[i+1];
             int value;
             int len = sscanf(valueString, "%d", &value);
diff --git a/src/ports/SkFontHost_android.cpp b/src/ports/SkFontHost_android.cpp
index 12357f1..bbde313 100644
--- a/src/ports/SkFontHost_android.cpp
+++ b/src/ports/SkFontHost_android.cpp
@@ -451,6 +451,7 @@
 static char** gDefaultNames = NULL;
 static uint32_t *gFallbackFonts;
 
+#if SK_DEBUG_FONTS
 static void dump_globals() {
     SkDebugf("gDefaultNormal=%p id=%u refCnt=%d", gDefaultNormal,
              gDefaultNormal ? gDefaultNormal->uniqueID() : 0,
@@ -506,6 +507,7 @@
     }
 
 }
+#endif
 
 
 /*  Load info from a configuration file that populates the system/fallback font structures
@@ -519,10 +521,8 @@
     }
 
     SkTDArray<FontInitRec> fontInfo;
-    bool firstInFamily = false;
     for (int i = 0; i < fontFamilies.count(); ++i) {
         FontFamily *family = fontFamilies[i];
-        firstInFamily = true;
         for (int j = 0; j < family->fFileNames.count(); ++j) {
             FontInitRec fontInfoRecord;
             fontInfoRecord.fFileName = family->fFileNames[j];
@@ -672,7 +672,9 @@
     // now terminate our fallback list with the sentinel value
     gFallbackFonts[fallbackCount] = 0;
 
-//    SkDEBUGCODE(dump_globals());
+#if SK_DEBUG_FONTS
+    SkDEBUGCODE(dump_globals());
+#endif
 }
 
 static size_t find_uniqueID(const char* filename) {
diff --git a/src/utils/android/ashmem.c b/src/utils/android/ashmem.cpp
similarity index 100%
rename from src/utils/android/ashmem.c
rename to src/utils/android/ashmem.cpp
diff --git a/tests/PaintTest.cpp b/tests/PaintTest.cpp
index 2a84e4c..ed79076 100644
--- a/tests/PaintTest.cpp
+++ b/tests/PaintTest.cpp
@@ -29,8 +29,8 @@
 
 #ifdef SK_BUILD_FOR_ANDROID
     // the copy constructor should preserve the Generation ID
-    int32_t paintGenID = paint.getGenerationID();
-    int32_t copiedPaintGenID = copiedPaint.getGenerationID();
+    uint32_t paintGenID = paint.getGenerationID();
+    uint32_t copiedPaintGenID = copiedPaint.getGenerationID();
     REPORTER_ASSERT(reporter, paintGenID == copiedPaintGenID);
     REPORTER_ASSERT(reporter, !memcmp(&paint, &copiedPaint, sizeof(paint)));
 #endif
diff --git a/tests/ReadWriteAlphaTest.cpp b/tests/ReadWriteAlphaTest.cpp
index a3bf5de..7830669 100644
--- a/tests/ReadWriteAlphaTest.cpp
+++ b/tests/ReadWriteAlphaTest.cpp
@@ -7,7 +7,7 @@
  */
 
 // This test is specific to the GPU backend.
-#if SK_SUPPORT_GPU
+#if SK_SUPPORT_GPU && !defined(SK_BUILD_FOR_ANDROID)
 
 #include "Test.h"
 #include "SkGpuDevice.h"
@@ -110,9 +110,7 @@
     }
 }
 
-#ifndef SK_BUILD_FOR_ANDROID
 #include "TestClassDef.h"
 DEFINE_GPUTESTCLASS("ReadWriteAlpha", ReadWriteAlphaTestClass, ReadWriteAlphaTest)
 
 #endif
-#endif