diff options
author | mtklein <mtklein@chromium.org> | 2016-08-24 12:22:32 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-08-24 12:22:32 -0700 |
commit | 6dc5b9a9b79b9d71e772c47a4346fde31f3e7bfb (patch) | |
tree | 2903dd2744294f09f2609d76d75c0e6a857645ec | |
parent | 8c99eabdd92d4fbdbcb74e979b527cdbf066b138 (diff) |
SkPngCodec: voidp instead of forward-declares for png.h types.
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2277903002
Review-Url: https://codereview.chromium.org/2277903002
-rw-r--r-- | src/codec/SkPngCodec.cpp | 6 | ||||
-rw-r--r-- | src/codec/SkPngCodec.h | 27 |
2 files changed, 20 insertions, 13 deletions
diff --git a/src/codec/SkPngCodec.cpp b/src/codec/SkPngCodec.cpp index 7096933d57..a708f2a1a0 100644 --- a/src/codec/SkPngCodec.cpp +++ b/src/codec/SkPngCodec.cpp @@ -777,8 +777,8 @@ static bool read_header(SkStream* stream, SkPngChunkReader* chunkReader, SkCodec } SkPngCodec::SkPngCodec(const SkEncodedInfo& encodedInfo, const SkImageInfo& imageInfo, - SkStream* stream, SkPngChunkReader* chunkReader, png_structp png_ptr, - png_infop info_ptr, int bitDepth, int numberPasses) + SkStream* stream, SkPngChunkReader* chunkReader, void* png_ptr, + void* info_ptr, int bitDepth, int numberPasses) : INHERITED(encodedInfo, imageInfo, stream) , fPngChunkReader(SkSafeRef(chunkReader)) , fPng_ptr(png_ptr) @@ -798,7 +798,7 @@ void SkPngCodec::destroyReadStruct() { if (fPng_ptr) { // We will never have a nullptr fInfo_ptr with a non-nullptr fPng_ptr SkASSERT(fInfo_ptr); - png_destroy_read_struct(&fPng_ptr, &fInfo_ptr, nullptr); + png_destroy_read_struct((png_struct**)&fPng_ptr, (png_info**)&fInfo_ptr, nullptr); fPng_ptr = nullptr; fInfo_ptr = nullptr; } diff --git a/src/codec/SkPngCodec.h b/src/codec/SkPngCodec.h index 7bb833d10d..e4df823076 100644 --- a/src/codec/SkPngCodec.h +++ b/src/codec/SkPngCodec.h @@ -14,12 +14,6 @@ #include "SkRefCnt.h" #include "SkSwizzler.h" -// Instead of including png.h here, forward declare the few types we refer to. -struct png_struct_def; -struct png_info_def; -typedef png_struct_def png_struct; -typedef png_info_def png_info; - class SkStream; class SkPngCodec : public SkCodec { @@ -32,6 +26,19 @@ public: virtual ~SkPngCodec(); protected: + // We hold the png_ptr and info_ptr as voidp to avoid having to include png.h + // or forward declare their types here. voidp auto-casts to the real pointer types. + struct voidp { + voidp(void* ptr) : fPtr(ptr) {} + + template <typename T> + operator T*() const { return (T*)fPtr; } + + explicit operator bool() const { return fPtr != nullptr; } + + void* fPtr; + }; + Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, SkPMColor*, int*, int*) override; SkEncodedFormat onGetEncodedFormat() const override { return kPNG_SkEncodedFormat; } @@ -51,11 +58,11 @@ protected: int startRow) = 0; SkPngCodec(const SkEncodedInfo&, const SkImageInfo&, SkStream*, SkPngChunkReader*, - png_struct*, png_info*, int, int); + void* png_ptr, void* info_ptr, int, int); - SkAutoTUnref<SkPngChunkReader> fPngChunkReader; - png_struct* fPng_ptr; - png_info* fInfo_ptr; + SkAutoTUnref<SkPngChunkReader> fPngChunkReader; + voidp fPng_ptr; + voidp fInfo_ptr; // These are stored here so they can be used both by normal decoding and scanline decoding. SkAutoTUnref<SkColorTable> fColorTable; // May be unpremul. |