Supply separate flags for onBuildTileIndex
Since png and jpeg's implementations of onBuildTileIndex rely on modifications to their underlying libraries, rather than whether we are running on Android, use separate flags that can be disabled independently. This will allow us to easily turn off the feature. It also is a step towards building and running on other platforms for testing (e.g. valgrind/ASAN to find memory leaks etc). Review URL: https://codereview.chromium.org/1401283003
This commit is contained in:
parent
94dd7a52d3
commit
8e48ed51ba
@ -54,6 +54,10 @@ SK_CONF_DECLARE(bool, c_suppressJPEGImageDecoderErrors,
|
|||||||
"Suppress most JPG error messages when decode "
|
"Suppress most JPG error messages when decode "
|
||||||
"function fails.");
|
"function fails.");
|
||||||
|
|
||||||
|
#if defined(SK_BUILD_FOR_ANDROID) && !defined(SK_JPEG_NO_INDEX_SUPPORTED)
|
||||||
|
#define SK_JPEG_INDEX_SUPPORTED
|
||||||
|
#endif
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@ -85,7 +89,7 @@ static void initialize_info(jpeg_decompress_struct* cinfo, skjpeg_source_mgr* sr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SK_BUILD_FOR_ANDROID
|
#ifdef SK_JPEG_INDEX_SUPPORTED
|
||||||
class SkJPEGImageIndex {
|
class SkJPEGImageIndex {
|
||||||
public:
|
public:
|
||||||
// Takes ownership of stream.
|
// Takes ownership of stream.
|
||||||
@ -203,7 +207,7 @@ private:
|
|||||||
|
|
||||||
class SkJPEGImageDecoder : public SkImageDecoder {
|
class SkJPEGImageDecoder : public SkImageDecoder {
|
||||||
public:
|
public:
|
||||||
#ifdef SK_BUILD_FOR_ANDROID
|
#ifdef SK_JPEG_INDEX_SUPPORTED
|
||||||
SkJPEGImageDecoder() {
|
SkJPEGImageDecoder() {
|
||||||
fImageIndex = nullptr;
|
fImageIndex = nullptr;
|
||||||
fImageWidth = 0;
|
fImageWidth = 0;
|
||||||
@ -218,7 +222,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
#ifdef SK_BUILD_FOR_ANDROID
|
#ifdef SK_JPEG_INDEX_SUPPORTED
|
||||||
bool onBuildTileIndex(SkStreamRewindable *stream, int *width, int *height) override;
|
bool onBuildTileIndex(SkStreamRewindable *stream, int *width, int *height) override;
|
||||||
bool onDecodeSubset(SkBitmap* bitmap, const SkIRect& rect) override;
|
bool onDecodeSubset(SkBitmap* bitmap, const SkIRect& rect) override;
|
||||||
#endif
|
#endif
|
||||||
@ -228,7 +232,7 @@ protected:
|
|||||||
SkYUVColorSpace* colorSpace) override;
|
SkYUVColorSpace* colorSpace) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#ifdef SK_BUILD_FOR_ANDROID
|
#ifdef SK_JPEG_INDEX_SUPPORTED
|
||||||
SkJPEGImageIndex* fImageIndex;
|
SkJPEGImageIndex* fImageIndex;
|
||||||
int fImageWidth;
|
int fImageWidth;
|
||||||
int fImageHeight;
|
int fImageHeight;
|
||||||
@ -295,7 +299,7 @@ static bool skip_src_rows(jpeg_decompress_struct* cinfo, void* buffer, int count
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SK_BUILD_FOR_ANDROID
|
#ifdef SK_JPEG_INDEX_SUPPORTED
|
||||||
static bool skip_src_rows_tile(jpeg_decompress_struct* cinfo,
|
static bool skip_src_rows_tile(jpeg_decompress_struct* cinfo,
|
||||||
huffman_index *index, void* buffer, int count) {
|
huffman_index *index, void* buffer, int count) {
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
@ -329,7 +333,7 @@ static bool return_false(const jpeg_decompress_struct& cinfo,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SK_BUILD_FOR_ANDROID
|
#ifdef SK_JPEG_INDEX_SUPPORTED
|
||||||
static bool return_false(const jpeg_decompress_struct& cinfo,
|
static bool return_false(const jpeg_decompress_struct& cinfo,
|
||||||
const SkBitmap& bm, const char caller[]) {
|
const SkBitmap& bm, const char caller[]) {
|
||||||
print_jpeg_decoder_errors(cinfo, bm.width(), bm.height(), caller);
|
print_jpeg_decoder_errors(cinfo, bm.width(), bm.height(), caller);
|
||||||
@ -939,7 +943,7 @@ bool SkJPEGImageDecoder::onDecodeYUV8Planes(SkStream* stream, SkISize componentS
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifdef SK_BUILD_FOR_ANDROID
|
#ifdef SK_JPEG_INDEX_SUPPORTED
|
||||||
bool SkJPEGImageDecoder::onBuildTileIndex(SkStreamRewindable* stream, int *width, int *height) {
|
bool SkJPEGImageDecoder::onBuildTileIndex(SkStreamRewindable* stream, int *width, int *height) {
|
||||||
SkAutoTDelete<SkJPEGImageIndex> imageIndex(new SkJPEGImageIndex(stream, this));
|
SkAutoTDelete<SkJPEGImageIndex> imageIndex(new SkJPEGImageIndex(stream, this));
|
||||||
|
|
||||||
|
@ -52,7 +52,9 @@ SK_CONF_DECLARE(bool, c_suppressPNGImageDecoderWarnings,
|
|||||||
"Suppress most PNG warnings when calling image decode "
|
"Suppress most PNG warnings when calling image decode "
|
||||||
"functions.");
|
"functions.");
|
||||||
|
|
||||||
|
#if defined(SK_BUILD_FOR_ANDROID) && !defined(SK_PNG_NO_INDEX_SUPPORTED)
|
||||||
|
#define SK_PNG_INDEX_SUPPORTED
|
||||||
|
#endif
|
||||||
|
|
||||||
class SkPNGImageIndex {
|
class SkPNGImageIndex {
|
||||||
public:
|
public:
|
||||||
@ -88,7 +90,7 @@ public:
|
|||||||
virtual ~SkPNGImageDecoder() { delete fImageIndex; }
|
virtual ~SkPNGImageDecoder() { delete fImageIndex; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
#ifdef SK_BUILD_FOR_ANDROID
|
#ifdef SK_PNG_INDEX_SUPPORTED
|
||||||
bool onBuildTileIndex(SkStreamRewindable *stream, int *width, int *height) override;
|
bool onBuildTileIndex(SkStreamRewindable *stream, int *width, int *height) override;
|
||||||
bool onDecodeSubset(SkBitmap* bitmap, const SkIRect& region) override;
|
bool onDecodeSubset(SkBitmap* bitmap, const SkIRect& region) override;
|
||||||
#endif
|
#endif
|
||||||
@ -132,7 +134,7 @@ static void sk_read_fn(png_structp png_ptr, png_bytep data, png_size_t length) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SK_BUILD_FOR_ANDROID
|
#ifdef SK_PNG_INDEX_SUPPORTED
|
||||||
static void sk_seek_fn(png_structp png_ptr, png_uint_32 offset) {
|
static void sk_seek_fn(png_structp png_ptr, png_uint_32 offset) {
|
||||||
SkStreamRewindable* sk_stream = (SkStreamRewindable*) png_get_io_ptr(png_ptr);
|
SkStreamRewindable* sk_stream = (SkStreamRewindable*) png_get_io_ptr(png_ptr);
|
||||||
if (!sk_stream->rewind()) {
|
if (!sk_stream->rewind()) {
|
||||||
@ -262,7 +264,7 @@ bool SkPNGImageDecoder::onDecodeInit(SkStream* sk_stream, png_structp *png_ptrp,
|
|||||||
* png_init_io() here you would call:
|
* png_init_io() here you would call:
|
||||||
*/
|
*/
|
||||||
png_set_read_fn(png_ptr, (void *)sk_stream, sk_read_fn);
|
png_set_read_fn(png_ptr, (void *)sk_stream, sk_read_fn);
|
||||||
#ifdef SK_BUILD_FOR_ANDROID
|
#ifdef SK_PNG_INDEX_SUPPORTED
|
||||||
png_set_seek_fn(png_ptr, sk_seek_fn);
|
png_set_seek_fn(png_ptr, sk_seek_fn);
|
||||||
#endif
|
#endif
|
||||||
/* where user_io_ptr is a structure you want available to the callbacks */
|
/* where user_io_ptr is a structure you want available to the callbacks */
|
||||||
@ -726,7 +728,7 @@ bool SkPNGImageDecoder::decodePalette(png_structp png_ptr, png_infop info_ptr,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SK_BUILD_FOR_ANDROID
|
#ifdef SK_PNG_INDEX_SUPPORTED
|
||||||
|
|
||||||
bool SkPNGImageDecoder::onBuildTileIndex(SkStreamRewindable* sk_stream, int *width, int *height) {
|
bool SkPNGImageDecoder::onBuildTileIndex(SkStreamRewindable* sk_stream, int *width, int *height) {
|
||||||
SkAutoTDelete<SkStreamRewindable> streamDeleter(sk_stream);
|
SkAutoTDelete<SkStreamRewindable> streamDeleter(sk_stream);
|
||||||
|
Loading…
Reference in New Issue
Block a user