diff options
author | msarett <msarett@google.com> | 2016-02-17 10:02:29 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-02-17 10:02:29 -0800 |
commit | 8715d47e247bf890ee78af0774ae7e8698146b67 (patch) | |
tree | aa8b25a8353ccd96e6eccb08f22457a1d89846e0 /src/ports | |
parent | feec878e850850cb0a092a765e3af0f5a3fa2a42 (diff) |
Make SkPicture/SkImageGenerator default to SkCodec
Remove reference to SkImageDecoder from SkPicture. Make the default
InstallPixelRefProc passed to CreateFromStream use
SkImageGenerator::NewFromEncoded instead.
Make SkImageGenerator::NewFromEncoded create an SkCodecImageGenerator.
Remove the old version that used SkImageDecoder.
Remove all versions of lazy_decode_bitmap/LazyDecodeBitmap. The default
now behaves lazily.
Update all clients to use the default.
Move SkImageDecoderGenerator into KtxTest.cpp, and use it directly.
This is a rebased version of:
https://codereview.chromium.org/1671193002/
TBR=reed@google.com
BUG=skia:4691
BUG=skia:4290
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1699183004
Review URL: https://codereview.chromium.org/1699183004
Diffstat (limited to 'src/ports')
-rw-r--r-- | src/ports/SkImageGenerator_skia.cpp | 96 |
1 files changed, 2 insertions, 94 deletions
diff --git a/src/ports/SkImageGenerator_skia.cpp b/src/ports/SkImageGenerator_skia.cpp index 8dbad555dd..b6ddee935a 100644 --- a/src/ports/SkImageGenerator_skia.cpp +++ b/src/ports/SkImageGenerator_skia.cpp @@ -6,100 +6,8 @@ */ #include "SkData.h" -#include "SkImageDecoder.h" -#include "SkImageGenerator.h" -#include "SkStream.h" - -class BareMemoryAllocator : public SkBitmap::Allocator { - const SkImageInfo fInfo; - void* const fMemory; - const size_t fRowBytes; - -public: - BareMemoryAllocator(const SkImageInfo& info, void* memory, size_t rowBytes) - : fInfo(info), fMemory(memory), fRowBytes(rowBytes) - {} - -protected: - bool allocPixelRef(SkBitmap* bm, SkColorTable* ctable) override { - const SkImageInfo bmi = bm->info(); - if (bmi.width() != fInfo.width() || bmi.height() != fInfo.height() || - bmi.colorType() != fInfo.colorType()) - { - return false; - } - return bm->installPixels(bmi, fMemory, fRowBytes, ctable, nullptr, nullptr); - } -}; - -class SkImageDecoderGenerator : public SkImageGenerator { - const SkImageInfo fInfo; - SkAutoTDelete<SkImageDecoder> fDecoder; - SkAutoTUnref<SkData> fData; - -public: - SkImageDecoderGenerator(const SkImageInfo& info, SkImageDecoder* decoder, SkData* data) - : INHERITED(info), fInfo(info), fDecoder(decoder), fData(SkRef(data)) - {} - -protected: - SkData* onRefEncodedData(SK_REFENCODEDDATA_CTXPARAM) override { - return SkRef(fData.get()); - } - bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, - SkPMColor ctableEntries[], int* ctableCount) override { - SkMemoryStream stream(fData->data(), fData->size(), false); - SkAutoTUnref<BareMemoryAllocator> allocator( - new BareMemoryAllocator(info, pixels, rowBytes)); - fDecoder->setAllocator(allocator); - fDecoder->setRequireUnpremultipliedColors(kUnpremul_SkAlphaType == info.alphaType()); - - SkBitmap bm; - const SkImageDecoder::Result result = fDecoder->decode(&stream, &bm, info.colorType(), - SkImageDecoder::kDecodePixels_Mode); - if (SkImageDecoder::kFailure == result) { - return false; - } - - SkASSERT(info.colorType() == bm.info().colorType()); - - if (kIndex_8_SkColorType == info.colorType()) { - SkASSERT(ctableEntries); - - SkColorTable* ctable = bm.getColorTable(); - if (nullptr == ctable) { - return false; - } - const int count = ctable->count(); - memcpy(ctableEntries, ctable->readColors(), count * sizeof(SkPMColor)); - *ctableCount = count; - } - return true; - } - - bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], - SkYUVColorSpace* colorSpace) override { - SkMemoryStream stream(fData->data(), fData->size(), false); - return fDecoder->decodeYUV8Planes(&stream, sizes, planes, rowBytes, colorSpace); - } - -private: - typedef SkImageGenerator INHERITED; -}; +#include "SkCodecImageGenerator.h" SkImageGenerator* SkImageGenerator::NewFromEncodedImpl(SkData* data) { - SkMemoryStream stream(data->data(), data->size(), false); - SkImageDecoder* decoder = SkImageDecoder::Factory(&stream); - if (nullptr == decoder) { - return nullptr; - } - - SkBitmap bm; - stream.rewind(); - if (!decoder->decode(&stream, &bm, kUnknown_SkColorType, SkImageDecoder::kDecodeBounds_Mode)) { - delete decoder; - return nullptr; - } - - return new SkImageDecoderGenerator(bm.info(), decoder, data); + return SkCodecImageGenerator::NewFromEncodedCodec(data); } |