From ad3a5c634d6d96874a8b5f13e96d05d62fd0d35d Mon Sep 17 00:00:00 2001 From: msarett Date: Fri, 6 May 2016 07:21:26 -0700 Subject: [PATCH] Compile SkForceLinking on CMake BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1956573002 CQ_EXTRA_TRYBOTS=client.skia.compile:Build-Ubuntu-GCC-x86_64-Release-CMake-Trybot,Build-Mac-Clang-x86_64-Release-CMake-Trybot Review-Url: https://codereview.chromium.org/1956573002 --- cmake/CMakeLists.txt | 10 ++++------ gyp/codec.gyp | 9 --------- gyp/common_conditions.gypi | 9 +++++++++ public.bzl | 16 ++++++++-------- src/codec/SkAndroidCodec.cpp | 8 ++++---- src/codec/SkCodec.cpp | 12 ++++++------ src/images/SkForceLinking.cpp | 7 ++++++- 7 files changed, 37 insertions(+), 34 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 67cdb1d719..f1a96a9818 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -43,8 +43,6 @@ endfunction() # This file is empty and is only used to trick GYP. remove_srcs (../src/core/SkForceCPlusPlusLinking.cpp) -# This file forces linking for all our supported image decoders. We're more fine-grained. -remove_srcs (../src/images/SkForceLinking.cpp) # Chrome only? remove_srcs (../src/ports/SkFontHost_fontconfig.cpp ../src/fonts/SkFontMgr_fontconfig.cpp @@ -166,7 +164,7 @@ endif() if (GIF_FOUND) list (APPEND private_includes ${GIF_INCLUDE_DIRS}) list (APPEND libs ${GIF_LIBRARIES}) - add_definitions(-DSK_CODEC_DECODES_GIF) + add_definitions(-DSK_HAS_GIF_LIBRARY) else() remove_srcs(../src/images/*GIF*) remove_srcs(../src/codec/*Gif*) @@ -175,7 +173,7 @@ endif() if (JPEG_FOUND) list (APPEND private_includes ${JPEG_INCLUDE_DIRS}) list (APPEND libs ${JPEG_LIBRARIES}) - add_definitions(-DSK_CODEC_DECODES_JPEG) + add_definitions(-DSK_HAS_JPEG_LIBRARY) else() remove_srcs(../src/images/*JPEG*) remove_srcs(../src/codec/*Jpeg*) @@ -193,7 +191,7 @@ 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) + add_definitions(-DSK_HAS_PNG_LIBRARY) else() remove_srcs(../src/images/*PNG*) remove_srcs(../src/codec/*Png*) @@ -212,7 +210,7 @@ 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) + add_definitions(-DSK_HAS_WEBP_LIBRARY) else() remove_srcs(../src/images/*WEBP*) remove_srcs(../src/codec/*Webp*) diff --git a/gyp/codec.gyp b/gyp/codec.gyp index bea740b9d1..c7393bb7ca 100644 --- a/gyp/codec.gyp +++ b/gyp/codec.gyp @@ -64,15 +64,6 @@ ], }, '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_CROP', diff --git a/gyp/common_conditions.gypi b/gyp/common_conditions.gypi index e784e51ceb..21f4c92398 100644 --- a/gyp/common_conditions.gypi +++ b/gyp/common_conditions.gypi @@ -10,6 +10,15 @@ 'SK_ALLOW_STATIC_GLOBAL_INITIALIZERS=<(skia_static_initializers)', 'SK_SUPPORT_GPU=<(skia_gpu)', 'SK_FORCE_DISTANCE_FIELD_TEXT=<(skia_force_distance_field_text)', + + # Indicate that all dependency libraries are present. Clients that + # are missing some of the required decoding libraries may choose + # not to define these. This will disable some decoder and encoder + # features. + 'SK_HAS_GIF_LIBRARY', + 'SK_HAS_JPEG_LIBRARY', + 'SK_HAS_PNG_LIBRARY', + 'SK_HAS_WEBP_LIBRARY', ], 'conditions' : [ [ 'skia_is_bot', { diff --git a/public.bzl b/public.bzl index 5546b24530..8eb4d855d9 100644 --- a/public.bzl +++ b/public.bzl @@ -551,20 +551,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", + "SK_HAS_GIF_LIBRARY", + "SK_HAS_JPEG_LIBRARY", + "SK_HAS_PNG_LIBRARY", + "SK_HAS_WEBP_LIBRARY", ] DEFINES_ANDROID = [ "SK_BUILD_FOR_ANDROID", - "SK_CODEC_DECODES_GIF", - "SK_CODEC_DECODES_JPEG", - "SK_CODEC_DECODES_PNG", "SK_CODEC_DECODES_RAW", - "SK_CODEC_DECODES_WEBP", + "SK_HAS_GIF_LIBRARY", + "SK_HAS_JPEG_LIBRARY", + "SK_HAS_PNG_LIBRARY", + "SK_HAS_WEBP_LIBRARY", ] DEFINES_IOS = [ diff --git a/src/codec/SkAndroidCodec.cpp b/src/codec/SkAndroidCodec.cpp index 6db0991c0d..db36564232 100644 --- a/src/codec/SkAndroidCodec.cpp +++ b/src/codec/SkAndroidCodec.cpp @@ -29,20 +29,20 @@ SkAndroidCodec* SkAndroidCodec::NewFromStream(SkStream* stream, SkPngChunkReader } switch (codec->getEncodedFormat()) { -#ifdef SK_CODEC_DECODES_PNG +#ifdef SK_HAS_PNG_LIBRARY case kPNG_SkEncodedFormat: case kICO_SkEncodedFormat: #endif -#ifdef SK_CODEC_DECODES_JPEG +#ifdef SK_HAS_JPEG_LIBRARY case kJPEG_SkEncodedFormat: #endif -#ifdef SK_CODEC_DECODES_GIF +#ifdef SK_HAS_GIF_LIBRARY case kGIF_SkEncodedFormat: #endif case kBMP_SkEncodedFormat: case kWBMP_SkEncodedFormat: return new SkSampledCodec(codec.release()); -#ifdef SK_CODEC_DECODES_WEBP +#ifdef SK_HAS_WEBP_LIBRARY case kWEBP_SkEncodedFormat: return new SkWebpAdapterCodec((SkWebpCodec*) codec.release()); #endif diff --git a/src/codec/SkCodec.cpp b/src/codec/SkCodec.cpp index 8468f8a099..955c86d609 100644 --- a/src/codec/SkCodec.cpp +++ b/src/codec/SkCodec.cpp @@ -13,7 +13,7 @@ #include "SkGifCodec.h" #include "SkIcoCodec.h" #include "SkJpegCodec.h" -#ifdef SK_CODEC_DECODES_PNG +#ifdef SK_HAS_PNG_LIBRARY #include "SkPngCodec.h" #endif #include "SkRawCodec.h" @@ -27,16 +27,16 @@ struct DecoderProc { }; static const DecoderProc gDecoderProcs[] = { -#ifdef SK_CODEC_DECODES_JPEG +#ifdef SK_HAS_JPEG_LIBRARY { SkJpegCodec::IsJpeg, SkJpegCodec::NewFromStream }, #endif -#ifdef SK_CODEC_DECODES_WEBP +#ifdef SK_HAS_WEBP_LIBRARY { SkWebpCodec::IsWebp, SkWebpCodec::NewFromStream }, #endif -#ifdef SK_CODEC_DECODES_GIF +#ifdef SK_HAS_GIF_LIBRARY { SkGifCodec::IsGif, SkGifCodec::NewFromStream }, #endif -#ifdef SK_CODEC_DECODES_PNG +#ifdef SK_HAS_PNG_LIBRARY { SkIcoCodec::IsIco, SkIcoCodec::NewFromStream }, #endif { SkBmpCodec::IsBmp, SkBmpCodec::NewFromStream }, @@ -86,7 +86,7 @@ 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 +#ifdef SK_HAS_PNG_LIBRARY if (SkPngCodec::IsPng(buffer, bytesRead)) { return SkPngCodec::NewFromStream(streamDeleter.release(), chunkReader); } else diff --git a/src/images/SkForceLinking.cpp b/src/images/SkForceLinking.cpp index 78e53f86d8..e97106fdf8 100644 --- a/src/images/SkForceLinking.cpp +++ b/src/images/SkForceLinking.cpp @@ -14,15 +14,20 @@ int SkForceLinking(bool doNotPassTrue) { if (doNotPassTrue) { SkASSERT(false); +#if defined(SK_HAS_JPEG_LIBRARY) CreateJPEGImageEncoder(); +#endif +#if defined(SK_HAS_WEBP_LIBRARY) CreateWEBPImageEncoder(); +#endif // Only link hardware texture codecs on platforms that build them. See images.gyp #ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK CreateKTXImageEncoder(); #endif -#if !defined(SK_BUILD_FOR_MAC) && !defined(SK_BUILD_FOR_WIN) && !defined(SK_BUILD_FOR_IOS) +#if !defined(SK_BUILD_FOR_MAC) && !defined(SK_BUILD_FOR_WIN) && !defined(SK_BUILD_FOR_IOS) && \ + defined(SK_HAS_PNG_LIBRARY) CreatePNGImageEncoder(); #endif #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)