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
This commit is contained in:
scroggo@google.com 2013-05-01 21:17:27 +00:00
Родитель 22eb7944e0
Коммит c4ebdb03de
5 изменённых файлов: 28 добавлений и 39 удалений

Просмотреть файл

@ -129,19 +129,3 @@ void SkDebugger::getOverviewText(const SkTDArray<double>* typeTimes,
overview->append("px"); 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
}

Просмотреть файл

@ -64,13 +64,6 @@ private:
typedef GM INHERITED; typedef GM INHERITED;
}; };
void forceLinking();
void forceLinking() {
SkDEBUGCODE(SkImageDecoder *creator = ) CreateJPEGImageDecoder();
SkASSERT(creator);
}
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
static GM* MyFactory(void*) { return new CMYKJpegGM; } static GM* MyFactory(void*) { return new CMYKJpegGM; }

Просмотреть файл

@ -40,6 +40,9 @@
'../src/images/SkImageDecoder.cpp', '../src/images/SkImageDecoder.cpp',
'../src/images/SkImageDecoder_FactoryDefault.cpp', '../src/images/SkImageDecoder_FactoryDefault.cpp',
'../src/images/SkImageDecoder_FactoryRegistrar.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_libbmp.cpp',
'../src/images/SkImageDecoder_libgif.cpp', '../src/images/SkImageDecoder_libgif.cpp',
'../src/images/SkImageDecoder_libico.cpp', '../src/images/SkImageDecoder_libico.cpp',

Просмотреть файл

@ -339,3 +339,28 @@ bool SkImageDecoder::DecodeStream(SkStream* stream, SkBitmap* bm,
} }
return success; 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
}
}

Просмотреть файл

@ -292,22 +292,6 @@ int tool_main(int argc, char** argv) {
return failed ? -1 : 0; 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 #if !defined SK_BUILD_FOR_IOS
int main(int argc, char * const argv[]) { int main(int argc, char * const argv[]) {
return tool_main(argc, (char**) argv); return tool_main(argc, (char**) argv);