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
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
-}
typedef GM INHERITED;
};
-void forceLinking();
-
-void forceLinking() {
- SkDEBUGCODE(SkImageDecoder *creator = ) CreateJPEGImageDecoder();
- SkASSERT(creator);
-}
-
//////////////////////////////////////////////////////////////////////////////
static GM* MyFactory(void*) { return new CMYKJpegGM; }
'../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',
}
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
+ }
+}
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);