Remove dependencies on Android's forked decoder libraries

Disable SkImageDecoder's code which relies on Android's customized
libpng and libjpeg. Build standard versions of libpng and libjpeg-turbo
everywhere. The SkImageDecoder code has been replaced with SkCodec, which
can decode subsets using standard library APIs

BUG=skia:

Review URL: https://codereview.chromium.org/1406153015
diff --git a/DEPS b/DEPS
index 9a0c5cc..1fc09aa 100644
--- a/DEPS
+++ b/DEPS
@@ -28,8 +28,6 @@
   "third_party/externals/yasm/binaries"             : "https://chromium.googlesource.com/chromium/deps/yasm/binaries.git@52f9b3f4b0aa06da24ef8b123058bb61ee468881",
 
   "platform_tools/android/third_party/externals/expat" : "https://android.googlesource.com/platform/external/expat.git@android-5.1.0_r3",
-  "platform_tools/android/third_party/externals/jpeg" : "https://android.googlesource.com/platform/external/jpeg.git@android-5.1.0_r3",
-  "platform_tools/android/third_party/externals/png" : "https://android.googlesource.com/platform/external/libpng.git@android-4.2.2_r1.2",
 
   "platform_tools/chromeos/toolchain/src/third_party/chromite": "https://chromium.googlesource.com/chromiumos/chromite.git@d6a4c7e0ee4d53ddc5238dbddfc0417796a70e54",
   "platform_tools/chromeos/toolchain/src/third_party/pyelftools": "https://chromium.googlesource.com/chromiumos/third_party/pyelftools.git@bdc1d380acd88d4bfaf47265008091483b0d614e",
diff --git a/gyp/android_deps.gyp b/gyp/android_deps.gyp
index ceecb06..07188db 100644
--- a/gyp/android_deps.gyp
+++ b/gyp/android_deps.gyp
@@ -52,14 +52,14 @@
             },
           },
           {
-            'target_name': 'jpeg',
+            'target_name': 'libjpeg-turbo',
             'type': 'none',
             'direct_dependent_settings': {
               'libraries' : [
-                '-ljpeg',
+                '-ljpeg-turbo',
               ],
               'include_dirs': [
-                'external/jpeg',
+                'external/libjpeg-turbo',
               ],
             },
           },
diff --git a/gyp/codec.gyp b/gyp/codec.gyp
index 3888d4f..ace6e5a 100644
--- a/gyp/codec.gyp
+++ b/gyp/codec.gyp
@@ -18,6 +18,8 @@
       'dependencies': [
         'core.gyp:*',
         'giflib.gyp:giflib',
+        'libjpeg-turbo-selector.gyp:libjpeg-turbo-selector',
+        'libpng.gyp:libpng',
         'libwebp.gyp:libwebp',
       ],
       'cflags':[
@@ -58,37 +60,9 @@
           '../include/codec',
         ],
       },
-      'conditions': [
-        [ 'skia_android_framework == 1',
-          {
-            # TODO(djsollen): this is a temporary dependency until we can update
-            # the android framework to a more recent version of libpng.
-            'dependencies': [
-              'libpng.gyp:libpng',
-            ],
-            # TODO(msarett): Add libjpeg-turbo to Android so we can compile SkJpegCodec
-            # for the framework.
-            'sources!': [
-              '../src/codec/SkJpegCodec.cpp',
-              '../src/codec/SkJpegDecoderMgr.cpp',
-              '../src/codec/SkJpegUtility_codec.cpp',
-            ],
-          }, {  # !skia_android_framework
-            'dependencies': [
-              # TODO(msarett): Add libjpeg-turbo to Android so this can be a global
-              # dependency.
-              'libjpeg-turbo.gyp:libjpeg-turbo',
-              'libpng.gyp:libpng_static',
-            ],
-            'export_dependent_settings': [
-              'libjpeg-turbo.gyp:libjpeg-turbo',
-            ],
-            'defines': [
-              'TURBO_HAS_SKIP',
-            ],
-          }
-        ]
-      ]
+      'defines': [
+        'TURBO_HAS_SKIP',
+      ],
     },
   ],
 }
diff --git a/gyp/dm.gypi b/gyp/dm.gypi
index ad73072..8896673 100644
--- a/gyp/dm.gypi
+++ b/gyp/dm.gypi
@@ -22,7 +22,7 @@
     'etc1.gyp:libetc1',
     'flags.gyp:flags',
     'jsoncpp.gyp:jsoncpp',
-    'libpng.gyp:libpng_static_when_possible',
+    'libpng.gyp:libpng',
     'skia_lib.gyp:skia_lib',
     'svg.gyp:svg',
     'tools.gyp:bitmap_region_decoder',
diff --git a/gyp/images.gyp b/gyp/images.gyp
index 3c46ec1..6f11514 100644
--- a/gyp/images.gyp
+++ b/gyp/images.gyp
@@ -14,7 +14,7 @@
       'dependencies': [
         'core.gyp:*',
         'giflib.gyp:giflib',
-        'libjpeg.gyp:*',
+        'libjpeg-turbo-selector.gyp:libjpeg-turbo-selector',
         'etc1.gyp:libetc1',
         'ktx.gyp:libSkKTX',
         'libwebp.gyp:libwebp',
@@ -116,9 +116,6 @@
           ],
         }],
         [ 'skia_os in ["linux", "freebsd", "openbsd", "solaris"]', {
-          'export_dependent_settings': [
-            'libpng.gyp:libpng',
-          ],
           'dependencies': [
             'libpng.gyp:libpng',
           ],
@@ -128,9 +125,6 @@
           'include_dirs': [
              '../src/utils',
           ],
-          'dependencies': [
-             'android_deps.gyp:png',
-          ],
           'cflags' : [
             # SkImageDecoder_libpng includes png.h.
             # In the version of libpng that we use on Android (1.2.46),
@@ -138,13 +132,11 @@
             # in png.h, triggering a warning in C++11.
             '-Wno-literal-suffix',
           ],
+          'dependencies': [
+            'libpng.gyp:libpng',
+          ],
           'conditions': [
-            [ 'skia_android_framework == 0', {
-              'export_dependent_settings': [
-                'android_deps.gyp:png',
-                'libjpeg.gyp:*'
-              ],
-            }, {
+            [ 'skia_android_framework == 1', {
               # The android framework disables these decoders as they are of little use to
               # Java applications that can't take advantage of the compressed formats.
               'sources!': [
diff --git a/gyp/libjpeg-turbo-selector.gyp b/gyp/libjpeg-turbo-selector.gyp
new file mode 100644
index 0000000..7b75109
--- /dev/null
+++ b/gyp/libjpeg-turbo-selector.gyp
@@ -0,0 +1,27 @@
+# Copyright 2015 Google Inc.
+#
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+# This arguably should go in libjpeg-turbo.gyp.  But if we put it there, gyp
+# gets overeager and starts trying to parse all of the targets in that file.
+# And it will fail to parse a target it doesn't need anyway when we are
+# building for the android framework.  So we will add this file as another
+# layer of indirection.
+{
+  'targets': [
+    {
+      'target_name': 'libjpeg-turbo-selector',
+      'type': 'none',
+      'conditions': [
+        [ 'skia_android_framework', {
+            'dependencies':              [ 'android_deps.gyp:libjpeg-turbo' ],
+            'export_dependent_settings': [ 'android_deps.gyp:libjpeg-turbo' ],
+        },{
+            'dependencies':              [ 'libjpeg-turbo.gyp:libjpeg-turbo' ],
+            'export_dependent_settings': [ 'libjpeg-turbo.gyp:libjpeg-turbo' ],
+        }]
+      ]
+    },
+  ]
+}
diff --git a/gyp/libjpeg.gyp b/gyp/libjpeg.gyp
deleted file mode 100644
index 76052bf..0000000
--- a/gyp/libjpeg.gyp
+++ /dev/null
@@ -1,45 +0,0 @@
-# Copyright 2012 The Chromium Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-# This is a copy of ../third_party/externals/libjpeg/libjpeg.gyp , modified
-# such that all source paths point into that directory.
-# See http://code.google.com/p/skia/issues/detail?id=543 ('wrap libjpeg.gyp
-# from Chrome's libjpeg port, rather than making our own copy') for a better
-# long-term solution.
-
-{
-  'variables': {
-    'use_system_libjpeg%': 0,
-    'skia_warnings_as_errors': 0,
-  },
-  'conditions': [
-    ['skia_os == "android"', {
-      'targets': [
-        {
-          'target_name': 'libjpeg',
-          'type': 'none',
-          'dependencies': [
-            'android_deps.gyp:jpeg',
-          ],
-          'export_dependent_settings': [
-            'android_deps.gyp:jpeg',
-          ],
-        },
-      ],
-    }, { # skia_os != android
-      'targets': [
-        {
-          'target_name': 'libjpeg',
-          'type': 'none',
-          'dependencies': [
-            'libjpeg-turbo.gyp:libjpeg-turbo',
-          ],
-          'export_dependent_settings': [
-            'libjpeg-turbo.gyp:libjpeg-turbo',
-          ],
-        },
-      ],
-    }],
-  ],
-}
diff --git a/gyp/libpng.gyp b/gyp/libpng.gyp
index 45be5f7..c6014bb 100644
--- a/gyp/libpng.gyp
+++ b/gyp/libpng.gyp
@@ -12,19 +12,6 @@
       'target_name': 'libpng',
       'type': 'none',
       'conditions': [
-        [ 'skia_os == "android"', {
-            'dependencies':              [ 'android_deps.gyp:png' ],
-            'export_dependent_settings': [ 'android_deps.gyp:png' ],
-        },{
-            'dependencies':              [ 'libpng.gyp:libpng_static' ],
-            'export_dependent_settings': [ 'libpng.gyp:libpng_static' ],
-        }]
-      ]
-    },
-    {
-      'target_name': 'libpng_static_when_possible',
-      'type': 'none',
-      'conditions': [
         [ 'skia_android_framework', {
             'dependencies':              [ 'android_deps.gyp:png' ],
             'export_dependent_settings': [ 'android_deps.gyp:png' ],
diff --git a/platform_tools/android/gyp/dependencies.gypi b/platform_tools/android/gyp/dependencies.gypi
index f6298c1..3be8542 100644
--- a/platform_tools/android/gyp/dependencies.gypi
+++ b/platform_tools/android/gyp/dependencies.gypi
@@ -89,158 +89,6 @@
       }
     },
     {
-      'target_name': 'png',
-      'type': 'static_library',
-      'sources': [
-        '../third_party/externals/png/png.c',
-        '../third_party/externals/png/pngerror.c',
-        '../third_party/externals/png/pnggccrd.c',
-        '../third_party/externals/png/pngget.c',
-        '../third_party/externals/png/pngmem.c',
-        '../third_party/externals/png/pngpread.c',
-        '../third_party/externals/png/pngread.c',
-        '../third_party/externals/png/pngrio.c',
-        '../third_party/externals/png/pngrtran.c',
-        '../third_party/externals/png/pngrutil.c',
-        '../third_party/externals/png/pngset.c',
-        '../third_party/externals/png/pngtrans.c',
-        '../third_party/externals/png/pngvcrd.c',
-        '../third_party/externals/png/pngwio.c',
-        '../third_party/externals/png/pngwrite.c',
-        '../third_party/externals/png/pngwtran.c',
-        '../third_party/externals/png/pngwutil.c',
-      ],
-      'include_dirs': [
-        '../third_party/externals/png',
-      ],
-      'cflags': [
-        '-w',
-        '-fvisibility=hidden',
-      ],
-      'link_settings': {
-        'libraries': [
-          '-lz',
-        ],
-      },
-      'direct_dependent_settings': {
-        'include_dirs': [
-          '../third_party/externals/png',
-        ],
-      }
-    },
-    {
-      'target_name': 'jpeg',
-      'type': 'static_library',
-      'dependencies': [
-        'ashmem'
-      ],
-      'sources': [
-        '../third_party/externals/jpeg/jcapimin.c',
-        '../third_party/externals/jpeg/jcapistd.c',
-        '../third_party/externals/jpeg/jccoefct.c',
-        '../third_party/externals/jpeg/jccolor.c',
-        '../third_party/externals/jpeg/jcdctmgr.c',
-        '../third_party/externals/jpeg/jchuff.c',
-        '../third_party/externals/jpeg/jcinit.c',
-        '../third_party/externals/jpeg/jcmainct.c',
-        '../third_party/externals/jpeg/jcmarker.c',
-        '../third_party/externals/jpeg/jcmaster.c',
-        '../third_party/externals/jpeg/jcomapi.c',
-        '../third_party/externals/jpeg/jcparam.c',
-        '../third_party/externals/jpeg/jcphuff.c',
-        '../third_party/externals/jpeg/jcprepct.c',
-        '../third_party/externals/jpeg/jcsample.c',
-        '../third_party/externals/jpeg/jctrans.c',
-        '../third_party/externals/jpeg/jdapimin.c',
-        '../third_party/externals/jpeg/jdapistd.c',
-        '../third_party/externals/jpeg/jdatadst.c',
-        '../third_party/externals/jpeg/jdatasrc.c',
-        '../third_party/externals/jpeg/jdcoefct.c',
-        '../third_party/externals/jpeg/jdcolor.c',
-        '../third_party/externals/jpeg/jddctmgr.c',
-        '../third_party/externals/jpeg/jdhuff.c',
-        '../third_party/externals/jpeg/jdinput.c',
-        '../third_party/externals/jpeg/jdmainct.c',
-        '../third_party/externals/jpeg/jdmarker.c',
-        '../third_party/externals/jpeg/jdmaster.c',
-        '../third_party/externals/jpeg/jdmerge.c',
-        '../third_party/externals/jpeg/jdphuff.c',
-        '../third_party/externals/jpeg/jdpostct.c',
-        '../third_party/externals/jpeg/jdsample.c',
-        '../third_party/externals/jpeg/jdtrans.c',
-        '../third_party/externals/jpeg/jerror.c',
-        '../third_party/externals/jpeg/jfdctflt.c',
-        '../third_party/externals/jpeg/jfdctfst.c',
-        '../third_party/externals/jpeg/jfdctint.c',
-        '../third_party/externals/jpeg/jidctflt.c',
-        '../third_party/externals/jpeg/jidctfst.c',
-        '../third_party/externals/jpeg/jidctint.c',
-        '../third_party/externals/jpeg/jidctred.c',
-        '../third_party/externals/jpeg/jmem-ashmem.c',
-        '../third_party/externals/jpeg/jmemmgr.c',
-        '../third_party/externals/jpeg/jquant1.c',
-        '../third_party/externals/jpeg/jquant2.c',
-        '../third_party/externals/jpeg/jutils.c',
-      ],
-      'conditions': [
-        # FIXME (msarett):
-        # Turn off Arm NEON optimizations to avoid namespace conflicts when
-        # compiling libjpeg and libjpeg-turbo.  This is a temporary step in the
-        # plan to replace libjpeg with libjpeg-turbo.
-        #[ 'arm_neon == 1 and skia_clang_build == 0',
-        #  {
-        #    'sources' : [
-        #      '../third_party/externals/jpeg/armv6_idct.S',
-        #      '../third_party/externals/jpeg/jsimd_arm_neon.S',
-        #      '../third_party/externals/jpeg/jsimd_neon.c',
-        #    ],
-        #    'defines' : [
-        #      'NV_ARM_NEON',
-        #    ],
-        #  },
-        #],
-        [ '"mips" in skia_arch_type and mips_dsp == 2',
-          {
-            'sources' : [
-              '../third_party/externals/jpeg/mips_jidctfst.c',
-              '../third_party/externals/jpeg/mips_idct_le.S',
-            ],
-            'defines' : [
-              'ANDROID_MIPS_IDCT',
-            ],
-          },
-        ],
-        [ '"x86" in skia_arch_type',
-          {
-            'sources' : [
-              '../third_party/externals/jpeg/jidctintelsse.c',
-            ],
-            'defines' : [
-              'ANDROID_INTELSSE2_IDCT',
-            ],
-          },
-        ],
-      ],
-      'include_dirs': [
-        '../third_party/externals/jpeg',
-      ],
-      'cflags': [
-        '-w',
-        '-fvisibility=hidden',
-        '-DAVOID_TABLES',
-        '-DUSE_ANDROID_ASHMEM',
-        '-O3',
-        '-fstrict-aliasing',
-        '-fprefetch-loop-arrays',
-        '-DANDROID_TILE_BASED_DECODE',
-      ],
-      'direct_dependent_settings': {
-        'include_dirs': [
-          '../third_party/externals/jpeg',
-        ],
-      }
-    },
-    {
       # This target is a dependency for all console-type Skia applications which
       # will run on Android.  Since Android requires us to load native code in
       # shared libraries, we need a common entry point to wrap around main().
diff --git a/src/codec/SkCodec.cpp b/src/codec/SkCodec.cpp
index 0c6c95a..071a4b8 100644
--- a/src/codec/SkCodec.cpp
+++ b/src/codec/SkCodec.cpp
@@ -13,7 +13,7 @@
 #include "SkCodec_libpng.h"
 #include "SkCodec_wbmp.h"
 #include "SkCodecPriv.h"
-#if !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && !defined(GOOGLE3)
+#if !defined(GOOGLE3)
 #include "SkJpegCodec.h"
 #endif
 #include "SkStream.h"
@@ -26,7 +26,7 @@
 
 static const DecoderProc gDecoderProcs[] = {
     { SkPngCodec::IsPng, SkPngCodec::NewFromStream },
-#if !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && !defined(GOOGLE3)
+#if !defined(GOOGLE3)
     { SkJpegCodec::IsJpeg, SkJpegCodec::NewFromStream },
 #endif
     { SkWebpCodec::IsWebp, SkWebpCodec::NewFromStream },
diff --git a/src/images/SkImageDecoder_libjpeg.cpp b/src/images/SkImageDecoder_libjpeg.cpp
index 9de1733..f270cae 100644
--- a/src/images/SkImageDecoder_libjpeg.cpp
+++ b/src/images/SkImageDecoder_libjpeg.cpp
@@ -54,10 +54,6 @@
                 "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
-
 //////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////
 
diff --git a/src/images/SkImageDecoder_libpng.cpp b/src/images/SkImageDecoder_libpng.cpp
index aded29c..ab1affa 100644
--- a/src/images/SkImageDecoder_libpng.cpp
+++ b/src/images/SkImageDecoder_libpng.cpp
@@ -52,10 +52,6 @@
                 "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:
     // Takes ownership of stream.
diff --git a/src/images/SkJpegUtility.cpp b/src/images/SkJpegUtility.cpp
index b6b8fe8..f1a32ca 100644
--- a/src/images/SkJpegUtility.cpp
+++ b/src/images/SkJpegUtility.cpp
@@ -8,10 +8,6 @@
 
 #include "SkJpegUtility.h"
 
-#if defined(SK_BUILD_FOR_ANDROID) && !defined(SK_JPEG_NO_INDEX_SUPPORTED)
-#define SK_JPEG_INDEX_SUPPORTED
-#endif
-
 /////////////////////////////////////////////////////////////////////
 static void sk_init_source(j_decompress_ptr cinfo) {
     skjpeg_source_mgr*  src = (skjpeg_source_mgr*)cinfo->src;