Force linking with image decoders for images project.
authorscroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Wed, 1 May 2013 21:17:27 +0000 (21:17 +0000)
committerscroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Wed, 1 May 2013 21:17:27 +0000 (21:17 +0000)
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

debugger/SkDebugger.cpp
gm/cmykjpeg.cpp
gyp/images.gyp
src/images/SkImageDecoder.cpp
tools/skimage_main.cpp

index 3a13579..1e39b8e 100644 (file)
@@ -129,19 +129,3 @@ void SkDebugger::getOverviewText(const SkTDArray<double>* 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
-}
index 7ac4259..1d64d1c 100644 (file)
@@ -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; }
index bb1b92c..03bae3e 100644 (file)
@@ -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',
index 16cba64..2c3edc8 100644 (file)
@@ -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
+    }
+}
index 188164f..7906386 100644 (file)
@@ -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);