From: scroggo@google.com Date: Wed, 1 May 2013 21:17:27 +0000 (+0000) Subject: Force linking with image decoders for images project. X-Git-Tag: accepted/tizen/5.0/unified/20181102.025319~12547 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c4ebdb03def1e9d03ccff05f32db0eec106cc361;p=platform%2Fupstream%2FlibSkiaSharp.git Force linking with image decoders for images project. Previously, each tool that wanted to use image decoders but did not specifically reference them had to create a dummy function that references them in order to ensure they are not stripped by the linker. Instead of making each tool reference each image decoder, do it once in SkImageDecoder.cpp. Now each tool will have image decoders linked in, assuming it includes the images project. This fixes a bug where SKPs with encoded data could not be read by bench_ or render_pictures. R=djsollen@google.com, robertphillips@google.com Review URL: https://codereview.chromium.org/14678003 git-svn-id: http://skia.googlecode.com/svn/trunk@8941 2bbb7eff-a529-9590-31e7-b0007b416f81 --- diff --git a/debugger/SkDebugger.cpp b/debugger/SkDebugger.cpp index 3a13579..1e39b8e 100644 --- a/debugger/SkDebugger.cpp +++ b/debugger/SkDebugger.cpp @@ -129,19 +129,3 @@ void SkDebugger::getOverviewText(const SkTDArray* typeTimes, overview->append("px"); } -#include "SkImageDecoder.h" - -void forceLinking(); -void forceLinking() { - // This function leaks, but that is okay because it is not intended - // to be called. It is only here so that the linker will include the - // decoders. - SkDEBUGCODE(SkImageDecoder *creator = ) CreateJPEGImageDecoder(); - SkASSERT(creator); - SkDEBUGCODE(creator = ) CreateWEBPImageDecoder(); - SkASSERT(creator); -#if defined(SK_BUILD_FOR_UNIX) && !defined(SK_BUILD_FOR_NACL) - SkDEBUGCODE(creator = ) CreateGIFImageDecoder(); - SkASSERT(creator); -#endif -} diff --git a/gm/cmykjpeg.cpp b/gm/cmykjpeg.cpp index 7ac4259..1d64d1c 100644 --- a/gm/cmykjpeg.cpp +++ b/gm/cmykjpeg.cpp @@ -64,13 +64,6 @@ private: typedef GM INHERITED; }; -void forceLinking(); - -void forceLinking() { - SkDEBUGCODE(SkImageDecoder *creator = ) CreateJPEGImageDecoder(); - SkASSERT(creator); -} - ////////////////////////////////////////////////////////////////////////////// static GM* MyFactory(void*) { return new CMYKJpegGM; } diff --git a/gyp/images.gyp b/gyp/images.gyp index bb1b92c..03bae3e 100644 --- a/gyp/images.gyp +++ b/gyp/images.gyp @@ -40,6 +40,9 @@ '../src/images/SkImageDecoder.cpp', '../src/images/SkImageDecoder_FactoryDefault.cpp', '../src/images/SkImageDecoder_FactoryRegistrar.cpp', + # If decoders are added/removed to/from (all/individual) + # platform(s), be sure to update SkImageDecoder.cpp:force_linking + # so the right decoders will be forced to link. '../src/images/SkImageDecoder_libbmp.cpp', '../src/images/SkImageDecoder_libgif.cpp', '../src/images/SkImageDecoder_libico.cpp', diff --git a/src/images/SkImageDecoder.cpp b/src/images/SkImageDecoder.cpp index 16cba64..2c3edc8 100644 --- a/src/images/SkImageDecoder.cpp +++ b/src/images/SkImageDecoder.cpp @@ -339,3 +339,28 @@ bool SkImageDecoder::DecodeStream(SkStream* stream, SkBitmap* bm, } return success; } + +namespace { + /** + * This function leaks, but that is okay because it is not intended + * to be called. It is only here so that the linker will include the + * decoders. + * Make sure to keep it in sync with images.gyp, so only the encoders + * which are created on a platform are linked. + */ + void force_linking() { + SkASSERT(false); + CreateJPEGImageDecoder(); + CreateWEBPImageDecoder(); + CreateBMPImageDecoder(); + CreateICOImageDecoder(); + CreateWBMPImageDecoder(); + // Only link GIF and PNG on platforms that build them. See images.gyp +#if !defined(SK_BUILD_FOR_MAC) && !defined(SK_BUILD_FOR_WIN) && !defined(SK_BUILD_FOR_NACL) + CreateGIFImageDecoder(); +#endif +#if !defined(SK_BUILD_FOR_MAC) && !defined(SK_BUILD_FOR_WIN) + CreatePNGImageDecoder(); +#endif + } +} diff --git a/tools/skimage_main.cpp b/tools/skimage_main.cpp index 188164f..7906386 100644 --- a/tools/skimage_main.cpp +++ b/tools/skimage_main.cpp @@ -292,22 +292,6 @@ int tool_main(int argc, char** argv) { return failed ? -1 : 0; } -void forceLinking(); - -void forceLinking() { - // This function leaks, but that is okay because it is not intended - // to be called. It is only here so that the linker will include the - // decoders. - SkDEBUGCODE(SkImageDecoder *creator = ) CreateJPEGImageDecoder(); - SkASSERT(creator); - SkDEBUGCODE(creator = ) CreateWEBPImageDecoder(); - SkASSERT(creator); -#ifdef SK_BUILD_FOR_UNIX - SkDEBUGCODE(creator = ) CreateGIFImageDecoder(); - SkASSERT(creator); -#endif -} - #if !defined SK_BUILD_FOR_IOS int main(int argc, char * const argv[]) { return tool_main(argc, (char**) argv);