Supply separate flags for onBuildTileIndex

Since png and jpeg's implementations of onBuildTileIndex rely on
modifications to their underlying libraries, rather than whether we are
running on Android, use separate flags that can be disabled
independently.

This will allow us to easily turn off the feature. It also is a step
towards building and running on other platforms for testing (e.g.
valgrind/ASAN to find memory leaks etc).

Review URL: https://codereview.chromium.org/1401283003
diff --git a/src/images/SkImageDecoder_libjpeg.cpp b/src/images/SkImageDecoder_libjpeg.cpp
index 4b0d18b..7216239 100644
--- a/src/images/SkImageDecoder_libjpeg.cpp
+++ b/src/images/SkImageDecoder_libjpeg.cpp
@@ -54,6 +54,10 @@
                 "Suppress most JPG error messages when decode "
                 "function fails.");
 
+#if defined(SK_BUILD_FOR_ANDROID) && !defined(SK_JPEG_NO_INDEX_SUPPORTED)
+#define SK_JPEG_INDEX_SUPPORTED
+#endif
+
 //////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////
 
@@ -85,7 +89,7 @@
     }
 }
 
-#ifdef SK_BUILD_FOR_ANDROID
+#ifdef SK_JPEG_INDEX_SUPPORTED
 class SkJPEGImageIndex {
 public:
     // Takes ownership of stream.
@@ -203,7 +207,7 @@
 
 class SkJPEGImageDecoder : public SkImageDecoder {
 public:
-#ifdef SK_BUILD_FOR_ANDROID
+#ifdef SK_JPEG_INDEX_SUPPORTED
     SkJPEGImageDecoder() {
         fImageIndex = nullptr;
         fImageWidth = 0;
@@ -218,7 +222,7 @@
     }
 
 protected:
-#ifdef SK_BUILD_FOR_ANDROID
+#ifdef SK_JPEG_INDEX_SUPPORTED
     bool onBuildTileIndex(SkStreamRewindable *stream, int *width, int *height) override;
     bool onDecodeSubset(SkBitmap* bitmap, const SkIRect& rect) override;
 #endif
@@ -228,7 +232,7 @@
                             SkYUVColorSpace* colorSpace) override;
 
 private:
-#ifdef SK_BUILD_FOR_ANDROID
+#ifdef SK_JPEG_INDEX_SUPPORTED
     SkJPEGImageIndex* fImageIndex;
     int fImageWidth;
     int fImageHeight;
@@ -295,7 +299,7 @@
     return true;
 }
 
-#ifdef SK_BUILD_FOR_ANDROID
+#ifdef SK_JPEG_INDEX_SUPPORTED
 static bool skip_src_rows_tile(jpeg_decompress_struct* cinfo,
                                huffman_index *index, void* buffer, int count) {
     for (int i = 0; i < count; i++) {
@@ -329,7 +333,7 @@
     return false;
 }
 
-#ifdef SK_BUILD_FOR_ANDROID
+#ifdef SK_JPEG_INDEX_SUPPORTED
 static bool return_false(const jpeg_decompress_struct& cinfo,
                          const SkBitmap& bm, const char caller[]) {
     print_jpeg_decoder_errors(cinfo, bm.width(), bm.height(), caller);
@@ -939,7 +943,7 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
-#ifdef SK_BUILD_FOR_ANDROID
+#ifdef SK_JPEG_INDEX_SUPPORTED
 bool SkJPEGImageDecoder::onBuildTileIndex(SkStreamRewindable* stream, int *width, int *height) {
     SkAutoTDelete<SkJPEGImageIndex> imageIndex(new SkJPEGImageIndex(stream, this));
 
diff --git a/src/images/SkImageDecoder_libpng.cpp b/src/images/SkImageDecoder_libpng.cpp
index 31ec4dd..aded29c 100644
--- a/src/images/SkImageDecoder_libpng.cpp
+++ b/src/images/SkImageDecoder_libpng.cpp
@@ -52,7 +52,9 @@
                 "Suppress most PNG warnings when calling image decode "
                 "functions.");
 
-
+#if defined(SK_BUILD_FOR_ANDROID) && !defined(SK_PNG_NO_INDEX_SUPPORTED)
+#define SK_PNG_INDEX_SUPPORTED
+#endif
 
 class SkPNGImageIndex {
 public:
@@ -88,7 +90,7 @@
     virtual ~SkPNGImageDecoder() { delete fImageIndex; }
 
 protected:
-#ifdef SK_BUILD_FOR_ANDROID
+#ifdef SK_PNG_INDEX_SUPPORTED
     bool onBuildTileIndex(SkStreamRewindable *stream, int *width, int *height) override;
     bool onDecodeSubset(SkBitmap* bitmap, const SkIRect& region) override;
 #endif
@@ -132,7 +134,7 @@
     }
 }
 
-#ifdef SK_BUILD_FOR_ANDROID
+#ifdef SK_PNG_INDEX_SUPPORTED
 static void sk_seek_fn(png_structp png_ptr, png_uint_32 offset) {
     SkStreamRewindable* sk_stream = (SkStreamRewindable*) png_get_io_ptr(png_ptr);
     if (!sk_stream->rewind()) {
@@ -262,7 +264,7 @@
     * png_init_io() here you would call:
     */
     png_set_read_fn(png_ptr, (void *)sk_stream, sk_read_fn);
-#ifdef SK_BUILD_FOR_ANDROID
+#ifdef SK_PNG_INDEX_SUPPORTED
     png_set_seek_fn(png_ptr, sk_seek_fn);
 #endif
     /* where user_io_ptr is a structure you want available to the callbacks */
@@ -726,7 +728,7 @@
     return true;
 }
 
-#ifdef SK_BUILD_FOR_ANDROID
+#ifdef SK_PNG_INDEX_SUPPORTED
 
 bool SkPNGImageDecoder::onBuildTileIndex(SkStreamRewindable* sk_stream, int *width, int *height) {
     SkAutoTDelete<SkStreamRewindable> streamDeleter(sk_stream);