WIP: Added support for giflib, updated jpeg and png

BUG=skia:3257

Review URL: https://codereview.chromium.org/1038863003
diff --git a/DEPS b/DEPS
index 15917a9..0de145e 100644
--- a/DEPS
+++ b/DEPS
@@ -6,7 +6,6 @@
   "common": "https://skia.googlesource.com/common.git@d7c2e2b9464e70e0f3847a330b930d008dc8c8db",
 
   # There is some duplication here that might be worth cleaning up:
-  #   - both Android and ChromeOS pull the same giflib;
   #   - can use use our existing t_p/e/libjpeg instead of pulling it for Android?
 
   "third_party/externals/angle2"  : "https://chromium.googlesource.com/angle/angle.git@c415283b2bcd786e1a8c55c19ef3511eb2b3928c",
@@ -20,13 +19,12 @@
   "third_party/externals/zlib"    : "https://chromium.googlesource.com/chromium/src/third_party/zlib@4ba7cdd0e7bf49d671645264f839838fc56e1492",
   # NOTE: If we update libpng, we may need to update the generated file at third_party/libpng/pnglibconf.h
   "third_party/externals/libpng"  : "git://git.code.sf.net/p/libpng/code@070a616b8275277e18ef8ee91e2ca23f7bdc67d5",
+  "third_party/externals/giflib"  : "https://android.googlesource.com/platform/external/giflib.git@android-5.1.0_r3",
 
-  "platform_tools/android/third_party/externals/expat" : "https://android.googlesource.com/platform/external/expat.git@android-4.2.2_r1.2",
-  "platform_tools/android/third_party/externals/gif" : "https://android.googlesource.com/platform/external/giflib.git@android-4.2.2_r1.2",
-  "platform_tools/android/third_party/externals/jpeg" : "https://android.googlesource.com/platform/external/jpeg.git@ef1b83013e7814622a9d11579878d342e84580b7",
-  "platform_tools/android/third_party/externals/png" : "https://android.googlesource.com/platform/external/libpng.git@android-4.2.2_r1.2",
+  "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-5.1.0_r3",
 
-  "platform_tools/chromeos/third_party/externals/gif" : "https://android.googlesource.com/platform/external/giflib.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 2188150..ceecb06 100644
--- a/gyp/android_deps.gyp
+++ b/gyp/android_deps.gyp
@@ -2,6 +2,7 @@
 #
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
+
 # This GYP file stores the dependencies necessary to build Skia on the Android
 # platform. The OS doesn't provide many stable libraries as part of the
 # distribution so we have to build a few of them ourselves.
@@ -39,18 +40,6 @@
             },
           },
           {
-            'target_name': 'gif',
-            'type': 'none',
-            'direct_dependent_settings': {
-              'libraries' : [
-                'libgif.a',
-              ],
-              'include_dirs': [
-                'external/giflib',
-              ],
-            },
-          },
-          {
             'target_name': 'png',
             'type': 'none',
             'direct_dependent_settings': {
diff --git a/gyp/chromeos_deps.gyp b/gyp/chromeos_deps.gyp
deleted file mode 100644
index 63ab084..0000000
--- a/gyp/chromeos_deps.gyp
+++ /dev/null
@@ -1,13 +0,0 @@
-# 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 GYP file stores the dependencies necessary to build Skia on the Chrome OS
-# platform. The OS doesn't provide many stable libraries as part of the
-# distribution so we have to build a few of them ourselves.
-
-{
-  'includes': [
-    '../platform_tools/chromeos/gyp/dependencies.gypi',
-  ],
-}
diff --git a/gyp/common_variables.gypi b/gyp/common_variables.gypi
index 1031b52..1b9cf33 100644
--- a/gyp/common_variables.gypi
+++ b/gyp/common_variables.gypi
@@ -118,13 +118,6 @@
         ],
       ],
 
-      # skia_giflib_static - on OS variants that normally would link giflib
-      #     with '-lgif' and include the headers from '/usr/include/gif_lib.h',
-      #     don't do that; instead compile and staticlly link the version of
-      #     giflib in third_party/externals/giflib.
-      'skia_giflib_static%': '0',
-
-
       # skia_no_fontconfig - On POSIX systems that would normally use the
       #     SkFontHost_fontconfig interface; use the SkFontHost_linux
       #     version instead.
@@ -206,7 +199,6 @@
     'os_posix%': '<(os_posix)',
 
     'skia_freetype_static%': '<(skia_freetype_static)',
-    'skia_giflib_static%': '<(skia_giflib_static)',
     'skia_no_fontconfig%': '<(skia_no_fontconfig)',
     'skia_sanitizer%': '<(skia_sanitizer)',
     'skia_scalar%': '<(skia_scalar)',
diff --git a/gyp/giflib.gyp b/gyp/giflib.gyp
index 3a2c215..9263835 100644
--- a/gyp/giflib.gyp
+++ b/gyp/giflib.gyp
@@ -11,7 +11,7 @@
     {
       'target_name': 'giflib',
       'conditions': [
-        [ 'skia_giflib_static',
+        [ 'skia_android_framework == 0',
           {
             'type': 'static_library',
             'defines': [
@@ -35,17 +35,18 @@
               '../third_party/externals/giflib/gifalloc.c',
               '../third_party/externals/giflib/gif_err.c',
             ],
-          }, {  # not skia_giflib_static
+          }, { # skia_android_framework
             'type': 'none',
             'direct_dependent_settings': {
-              'link_settings': {
-                'libraries': [
-                  '-lgif',
-                ],
-              },
-            },
+              'libraries' : [
+                'libgif.a',
+              ],
+              'include_dirs': [
+                'external/giflib',
+              ]
+            }
           }
-        ],
+        ]
       ]
     }
   ]
diff --git a/gyp/images.gyp b/gyp/images.gyp
index 4cce08e..34cc8a8 100644
--- a/gyp/images.gyp
+++ b/gyp/images.gyp
@@ -2,6 +2,7 @@
 #
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
+
 # GYP file for images project.
 {
   'targets': [
@@ -12,6 +13,7 @@
       'standalone_static_library': 1,
       'dependencies': [
         'core.gyp:*',
+        'giflib.gyp:giflib',
         'libjpeg.gyp:*',
         'etc1.gyp:libetc1',
         'ktx.gyp:libSkKTX',
@@ -87,6 +89,9 @@
             '../src/images/SkImageDecoder_libpng.cpp',
             '../src/images/SkMovie_gif.cpp',
           ],
+          'dependencies!': [
+            'giflib.gyp:giflib'
+          ],
           'link_settings': {
             'libraries': [
               '-lwindowscodecs.lib',
@@ -112,13 +117,11 @@
         [ 'skia_os in ["linux", "freebsd", "openbsd", "solaris"]', {
           'export_dependent_settings': [
             'libpng.gyp:libpng',
-            'giflib.gyp:giflib'
           ],
           'dependencies': [
             'libpng.gyp:libpng',
-            'giflib.gyp:giflib'
           ],
-          # end libpng/libgif stuff
+          # end libpng stuff
         }],
         # FIXME: NaCl should be just like linux, etc, above, but it currently is separated out
         # to remove gif. Once gif is supported by naclports, this can be merged into the above
@@ -128,13 +131,15 @@
             '../src/images/SkImageDecoder_libgif.cpp',
             '../src/images/SkMovie_gif.cpp',
           ],
+          'dependencies!': [
+            'giflib.gyp:giflib'
+          ],
         }],
         [ 'skia_os == "android"', {
           'include_dirs': [
              '../src/utils',
           ],
           'dependencies': [
-             'android_deps.gyp:gif',
              'android_deps.gyp:png',
           ],
           'conditions': [
@@ -156,8 +161,7 @@
         }],
         [ 'skia_os == "chromeos"', {
           'dependencies': [
-             'chromeos_deps.gyp:gif',
-             'libpng.gyp:libpng',
+            'libpng.gyp:libpng',
           ],
         }],
         [ 'skia_os == "ios"', {
diff --git a/platform_tools/android/gyp/dependencies.gypi b/platform_tools/android/gyp/dependencies.gypi
index 6507ee4..4f23759 100644
--- a/platform_tools/android/gyp/dependencies.gypi
+++ b/platform_tools/android/gyp/dependencies.gypi
@@ -1,3 +1,8 @@
+# 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 GYP file stores the dependencies necessary to build Skia on the Android
 # platform. The OS doesn't provide many stable libraries as part of the
 # distribution so we have to build a few of them ourselves.
@@ -55,33 +60,11 @@
       }
     },
     {
-      'target_name': 'gif',
-      'type': 'static_library',
-      'sources': [
-        '../third_party/externals/gif/dgif_lib.c',
-        '../third_party/externals/gif/gifalloc.c',
-        '../third_party/externals/gif/gif_err.c',
-      ],
-      'include_dirs': [
-        '../third_party/externals/gif',
-      ],
-      'cflags': [
-        '-w',
-        '-DHAVE_CONFIG_H',
-      ],
-      'direct_dependent_settings': {
-        'include_dirs': [
-          '../third_party/externals/gif',
-        ],
-      }
-    },
-    {
       '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',
@@ -91,12 +74,25 @@
         '../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',
       ],
+      'conditions': [
+        [ 'arm_neon == 1',
+          {
+            'sources' : [
+              '../third_party/externals/png/arm/arm_init.c',
+              '../third_party/externals/png/arm/filter_neon.S',
+              '../third_party/externals/png/arm/filter_neon_intrinsics.c',
+            ],
+            'defines' : [
+              'PNG_ARM_NEON_OPT=2',
+            ],
+          },
+        ],
+      ],
       'include_dirs': [
         '../third_party/externals/png',
       ],
@@ -160,11 +156,46 @@
         '../third_party/externals/jpeg/jidctfst.c',
         '../third_party/externals/jpeg/jidctint.c',
         '../third_party/externals/jpeg/jidctred.c',
+        '../third_party/externals/jpeg/jmem-android.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',
-        '../third_party/externals/jpeg/jmemmgr.c',
-        '../third_party/externals/jpeg/jmem-android.c', # ashmem is also available
+      ],
+      'conditions': [
+        [ 'arm_neon == 1',
+          {
+            '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',
+            ],
+          },
+        ],
+        [ 'skia_arch_type == "mips" 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',
diff --git a/platform_tools/chromeos/gyp/dependencies.gypi b/platform_tools/chromeos/gyp/dependencies.gypi
deleted file mode 100644
index 38e3c53..0000000
--- a/platform_tools/chromeos/gyp/dependencies.gypi
+++ /dev/null
@@ -1,35 +0,0 @@
-# This GYP file stores the dependencies necessary to build Skia on the Chrome OS
-# platform. The OS doesn't provide many stable libraries as part of the
-# distribution so we have to build a few of them ourselves.
-
-{
-  'variables': {
-    'skia_warnings_as_errors': 0,
-  },
-  'targets': [
-    {
-      'target_name': 'gif',
-      'type': 'static_library',
-      'sources': [
-        '../third_party/externals/gif/dgif_lib.c',
-        '../third_party/externals/gif/gifalloc.c',
-        '../third_party/externals/gif/gif_err.c',
-      ],
-      'include_dirs': [
-        '../third_party/externals/gif',
-      ],
-      'cflags': [
-        '-Wno-format',
-        '-DHAVE_CONFIG_H',
-      ],
-      'cflags!': [
-        '-Wall',
-      ],
-      'direct_dependent_settings': {
-        'include_dirs': [
-          '../third_party/externals/gif',
-        ],
-      }
-    },
-  ]
-}