From 39b2d5a1ac4171aba0e92cb3f9882f62e5730e3e Mon Sep 17 00:00:00 2001 From: msarett Date: Wed, 17 Feb 2016 08:26:31 -0800 Subject: [PATCH] Individually enable and disable SkCodecs 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 | 18 +++++++++++------- gyp/codec.gyp | 18 ++++++++++++++---- public.bzl | 10 ++++++++-- src/codec/SkAndroidCodec.cpp | 20 +++++++++++++------- src/codec/SkCodec.cpp | 17 ++++++++++++++--- src/codec/SkGifCodec.cpp | 2 ++ src/codec/SkGifCodec.h | 3 ++- src/codec/SkJpegCodec.h | 7 ++----- src/codec/SkJpegDecoderMgr.h | 1 - 9 files changed, 66 insertions(+), 30 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 751361a..2f2a81c 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -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) diff --git a/gyp/codec.gyp b/gyp/codec.gyp index 9537f8a..d4904da 100644 --- a/gyp/codec.gyp +++ b/gyp/codec.gyp @@ -22,10 +22,9 @@ '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', @@ -65,6 +64,17 @@ ], }, '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', ], diff --git a/public.bzl b/public.bzl index db92502..f687a42 100644 --- a/public.bzl +++ b/public.bzl @@ -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 = [ diff --git a/src/codec/SkAndroidCodec.cpp b/src/codec/SkAndroidCodec.cpp index 6c3113c..7dfd64d 100644 --- a/src/codec/SkAndroidCodec.cpp +++ b/src/codec/SkAndroidCodec.cpp @@ -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()); diff --git a/src/codec/SkCodec.cpp b/src/codec/SkCodec.cpp index bb7b265..c4f7498 100644 --- a/src/codec/SkCodec.cpp +++ b/src/codec/SkCodec.cpp @@ -12,10 +12,10 @@ #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()); diff --git a/src/codec/SkGifCodec.cpp b/src/codec/SkGifCodec.cpp index 6995547..c7b15e7 100644 --- a/src/codec/SkGifCodec.cpp +++ b/src/codec/SkGifCodec.cpp @@ -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 */ diff --git a/src/codec/SkGifCodec.h b/src/codec/SkGifCodec.h index 010a344..a46667a 100644 --- a/src/codec/SkGifCodec.h +++ b/src/codec/SkGifCodec.h @@ -10,7 +10,8 @@ #include "SkImageInfo.h" #include "SkSwizzler.h" -#include "gif_lib.h" +struct GifFileType; +struct SavedImage; /* * diff --git a/src/codec/SkJpegCodec.h b/src/codec/SkJpegCodec.h index 283dd8f..06685cf 100644 --- a/src/codec/SkJpegCodec.h +++ b/src/codec/SkJpegCodec.h @@ -10,14 +10,11 @@ #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; /* * diff --git a/src/codec/SkJpegDecoderMgr.h b/src/codec/SkJpegDecoderMgr.h index 8e938ad..7d34b67 100644 --- a/src/codec/SkJpegDecoderMgr.h +++ b/src/codec/SkJpegDecoderMgr.h @@ -11,7 +11,6 @@ #include "SkCodec.h" #include "SkCodecPriv.h" #include "SkJpegUtility_codec.h" -#include "SkSwizzler.h" // stdio is needed for jpeglib #include -- 2.7.4