Individually enable and disable SkCodecs
authormsarett <msarett@google.com>
Wed, 17 Feb 2016 16:26:31 +0000 (08:26 -0800)
committerCommit bot <commit-bot@chromium.org>
Wed, 17 Feb 2016 16:26:32 +0000 (08:26 -0800)
BUG=skia:4956
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1702533004
CQ_EXTRA_TRYBOTS=client.skia.compile:Build-Ubuntu-GCC-x86_64-Release-CMake-Trybot

Review URL: https://codereview.chromium.org/1702533004

cmake/CMakeLists.txt
gyp/codec.gyp
public.bzl
src/codec/SkAndroidCodec.cpp
src/codec/SkCodec.cpp
src/codec/SkGifCodec.cpp
src/codec/SkGifCodec.h
src/codec/SkJpegCodec.h
src/codec/SkJpegDecoderMgr.h

index 751361a..2f2a81c 100644 (file)
@@ -145,13 +145,6 @@ if (UNIX AND NOT APPLE)
     find_package (PNG)
 endif()
 
-# Decide whether to turn on SkCodec.
-# TODO (skbug.com/4956): We should be able to turn specific codecs on and off rather than
-#                        disabling all of them if one library is missing.
-if (NOT (GIF_FOUND AND JPEG_FOUND AND PNG_FOUND AND WEBP_INCLUDE_DIRS AND WEBP_LIBRARIES))
-    remove_srcs(../src/codec/* ../src/android/*)
-endif()
-
 # Do not compile SkRawCodec.
 remove_srcs(../src/codec/*Raw*.cpp)
 
@@ -167,15 +160,20 @@ endif()
 if (GIF_FOUND)
     list (APPEND private_includes ${GIF_INCLUDE_DIRS})
     list (APPEND libs             ${GIF_LIBRARIES})
+    add_definitions(-DSK_CODEC_DECODES_GIF)
 else()
     remove_srcs(../src/images/*gif*)
+    remove_srcs(../src/codec/*Gif*)
 endif()
 
 if (JPEG_FOUND)
     list (APPEND private_includes ${JPEG_INCLUDE_DIRS})
     list (APPEND libs             ${JPEG_LIBRARIES})
+    add_definitions(-DSK_CODEC_DECODES_JPEG)
 else()
     remove_srcs(../src/images/*jpeg*)
+    remove_srcs(../src/images/*Jpeg*)
+    remove_srcs(../src/codec/*Jpeg*)
 endif()
 
 if (LUA_FOUND)
@@ -190,8 +188,12 @@ if (PNG_FOUND)
     list (APPEND libs             ${PNG_LIBRARIES})
     add_definitions(-DPNG_SKIP_SETJMP_CHECK)
     add_definitions(-DPNG_SKIP_SKIA_OPTS)
+    add_definitions(-DSK_CODEC_DECODES_PNG)
 else()
     remove_srcs(../src/images/*png*)
+    remove_srcs(../src/images/*ico*)
+    remove_srcs(../src/codec/*Png*)
+    remove_srcs(../src/codec/*Ico*)
 endif()
 
 if (ZLIB_FOUND)
@@ -205,8 +207,10 @@ endif()
 if (WEBP_INCLUDE_DIRS AND WEBP_LIBRARIES)
     list (APPEND private_includes ${WEBP_INCLUDE_DIRS})
     list (APPEND libs             ${WEBP_LIBRARIES})
+    add_definitions(-DSK_CODEC_DECODES_WEBP)
 else()
     remove_srcs(../src/images/*webp*)
+    remove_srcs(../src/codec/*Webp*)
 endif()
 
 if (FREETYPE_FOUND)
index 9537f8a..d4904da 100644 (file)
         'libpng.gyp:libpng',
         'libwebp.gyp:libwebp',
       ],
-      'cflags':[
-        # FIXME: This gets around a longjmp warning. See
-        # http://build.chromium.org/p/client.skia.compile/builders/Build-Ubuntu-GCC-x86_64-Release-Trybot/builds/113/steps/build%20most/logs/stdio
-        '-Wno-clobbered -Wno-error',
+      'cflags':[   
+        # FIXME: This gets around a warning: "Argument might be clobbered by longjmp". 
+        '-Wno-clobbered -Wno-error',   
       ],
       'include_dirs': [
         '../include/codec',
         ],
       },
       'defines': [
+        # Turn on all of the codecs, since we know that we have all of the
+        # necessary dependencies.  Clients that are missing some of the
+        # required decoding libraries may choose to turn the codecs on or
+        # off individually.
+        'SK_CODEC_DECODES_GIF',
+        'SK_CODEC_DECODES_JPEG',
+        'SK_CODEC_DECODES_PNG',
+        'SK_CODEC_DECODES_WEBP',
+
+        # Turn on libjpeg-turbo optimizations since we know that the
+        # appropriate version of libjpeg-turbo is present.      
         'TURBO_HAS_SKIP',
         'TURBO_HAS_565',
       ],
index db92502..f687a42 100644 (file)
@@ -478,14 +478,20 @@ DEFINES_UNIX = [
     "SK_BUILD_FOR_UNIX",
     "SK_SAMPLES_FOR_X",
     "SK_SFNTLY_SUBSETTER",
+    "SK_CODEC_DECODES_GIF",
+    "SK_CODEC_DECODES_JPEG",
+    "SK_CODEC_DECODES_PNG",
     "SK_CODEC_DECODES_RAW",
+    "SK_CODEC_DECODES_WEBP",
 ]
 
 DEFINES_ANDROID = [
     "SK_BUILD_FOR_ANDROID",
-    # TODO(benjaminwagner): Try to get png library updated?
-    "SK_PNG_NO_INDEX_SUPPORTED",
+    "SK_CODEC_DECODES_GIF",
+    "SK_CODEC_DECODES_JPEG",
+    "SK_CODEC_DECODES_PNG",
     "SK_CODEC_DECODES_RAW",
+    "SK_CODEC_DECODES_WEBP",
 ]
 
 DEFINES_IOS = [
index 6c3113c..7dfd64d 100644 (file)
@@ -8,9 +8,7 @@
 #include "SkAndroidCodec.h"
 #include "SkCodec.h"
 #include "SkCodecPriv.h"
-#ifdef SK_CODEC_DECODES_RAW
 #include "SkRawAdapterCodec.h"
-#endif
 #include "SkSampledCodec.h"
 #include "SkWebpAdapterCodec.h"
 
@@ -31,15 +29,23 @@ SkAndroidCodec* SkAndroidCodec::NewFromStream(SkStream* stream, SkPngChunkReader
     }
 
     switch (codec->getEncodedFormat()) {
-        case kWEBP_SkEncodedFormat:
-            return new SkWebpAdapterCodec((SkWebpCodec*) codec.detach());
+#ifdef SK_CODEC_DECODES_PNG
         case kPNG_SkEncodedFormat:
+        case kICO_SkEncodedFormat:
+#endif
+#ifdef SK_CODEC_DECODES_JPEG
         case kJPEG_SkEncodedFormat:
-        case kWBMP_SkEncodedFormat:
-        case kBMP_SkEncodedFormat:
+#endif
+#ifdef SK_CODEC_DECODES_GIF
         case kGIF_SkEncodedFormat:
-        case kICO_SkEncodedFormat:
+#endif
+        case kBMP_SkEncodedFormat:
+        case kWBMP_SkEncodedFormat:
             return new SkSampledCodec(codec.detach());
+#ifdef SK_CODEC_DECODES_WEBP
+        case kWEBP_SkEncodedFormat:
+            return new SkWebpAdapterCodec((SkWebpCodec*) codec.detach());
+#endif
 #ifdef SK_CODEC_DECODES_RAW
         case kRAW_SkEncodedFormat:
             return new SkRawAdapterCodec((SkRawCodec*)codec.detach());
index bb7b265..c4f7498 100644 (file)
 #include "SkGifCodec.h"
 #include "SkIcoCodec.h"
 #include "SkJpegCodec.h"
+#ifdef SK_CODEC_DECODES_PNG
 #include "SkPngCodec.h"
-#ifdef SK_CODEC_DECODES_RAW
-#include "SkRawCodec.h"
 #endif
+#include "SkRawCodec.h"
 #include "SkStream.h"
 #include "SkWbmpCodec.h"
 #include "SkWebpCodec.h"
@@ -26,10 +26,18 @@ struct DecoderProc {
 };
 
 static const DecoderProc gDecoderProcs[] = {
+#ifdef SK_CODEC_DECODES_JPEG
     { SkJpegCodec::IsJpeg, SkJpegCodec::NewFromStream },
+#endif
+#ifdef SK_CODEC_DECODES_WEBP
     { SkWebpCodec::IsWebp, SkWebpCodec::NewFromStream },
+#endif
+#ifdef SK_CODEC_DECODES_GIF
     { SkGifCodec::IsGif, SkGifCodec::NewFromStream },
+#endif
+#ifdef SK_CODEC_DECODES_PNG
     { SkIcoCodec::IsIco, SkIcoCodec::NewFromStream },
+#endif
     { SkBmpCodec::IsBmp, SkBmpCodec::NewFromStream },
     { SkWbmpCodec::IsWbmp, SkWbmpCodec::NewFromStream }
 };
@@ -77,9 +85,12 @@ SkCodec* SkCodec::NewFromStream(SkStream* stream,
 
     // PNG is special, since we want to be able to supply an SkPngChunkReader.
     // But this code follows the same pattern as the loop.
+#ifdef SK_CODEC_DECODES_PNG
     if (SkPngCodec::IsPng(buffer, bytesRead)) {
         return SkPngCodec::NewFromStream(streamDeleter.detach(), chunkReader);
-    } else {
+    } else
+#endif
+    {
         for (DecoderProc proc : gDecoderProcs) {
             if (proc.IsFormat(buffer, bytesRead)) {
                 return proc.NewFromStream(streamDeleter.detach());
index 6995547..c7b15e7 100644 (file)
@@ -13,6 +13,8 @@
 #include "SkSwizzler.h"
 #include "SkUtils.h"
 
+#include "gif_lib.h"
+
 /*
  * Checks the start of the stream to see if the image is a gif
  */
index 010a344..a46667a 100644 (file)
@@ -10,7 +10,8 @@
 #include "SkImageInfo.h"
 #include "SkSwizzler.h"
 
-#include "gif_lib.h"
+struct GifFileType;
+struct SavedImage;
 
 /*
  *
index 283dd8f..06685cf 100644 (file)
 
 #include "SkCodec.h"
 #include "SkImageInfo.h"
-#include "SkJpegDecoderMgr.h"
-#include "SkJpegUtility_codec.h"
+#include "SkSwizzler.h"
 #include "SkStream.h"
 #include "SkTemplates.h"
 
-extern "C" {
-    #include "jpeglib.h"
-}
+class JpegDecoderMgr;
 
 /*
  *
index 8e938ad..7d34b67 100644 (file)
@@ -11,7 +11,6 @@
 #include "SkCodec.h"
 #include "SkCodecPriv.h"
 #include "SkJpegUtility_codec.h"
-#include "SkSwizzler.h"
 
 // stdio is needed for jpeglib
 #include <stdio.h>