skia2/src/images/SkDecodingImageGenerator.h

121 lines
4.3 KiB
C
Raw Normal View History

/*
* Copyright 2013 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkDecodingImageGenerator_DEFINED
#define SkDecodingImageGenerator_DEFINED
#include "SkDiscardableMemory.h"
#include "SkImageGenerator.h"
#include "SkImageInfo.h"
class SkBitmap;
class SkStreamRewindable;
/**
* Calls into SkImageDecoder::DecodeMemoryToTarget to implement a
* SkImageGenerator
*/
class SkDecodingImageGenerator : public SkImageGenerator {
public:
/*
* The constructor will take a reference to the SkData. The
* destructor will unref() it.
*/
explicit SkDecodingImageGenerator(SkData* data);
/*
* The SkData version of this constructor is preferred. If the
* stream has an underlying SkData (such as a SkMemoryStream)
* pass that in.
*
* This object will unref the stream when done. Since streams
* have internal state (position), the caller should not pass a
* shared stream in. Pass either a new duplicated stream in or
* transfer ownership of the stream. In the latter case, be sure
* that there are no other consumers of the stream who will
* modify the stream's position. This constructor asserts
* stream->unique().
*
* For example:
* SkStreamRewindable* stream;
* ...
* SkImageGenerator* gen
* = SkNEW_ARGS(SkDecodingImageGenerator,
* (stream->duplicate()));
* ...
* SkDELETE(gen);
*/
explicit SkDecodingImageGenerator(SkStreamRewindable* stream);
virtual ~SkDecodingImageGenerator();
virtual SkData* refEncodedData() SK_OVERRIDE;
virtual bool getInfo(SkImageInfo* info) SK_OVERRIDE;
virtual bool getPixels(const SkImageInfo& info,
void* pixels,
size_t rowBytes) SK_OVERRIDE;
/**
* Install the SkData into the destination bitmap, using a new
* SkDiscardablePixelRef and a new SkDecodingImageGenerator.
*
* @param data Contains the encoded image data that will be used
* by the SkDecodingImageGenerator. Will be ref()ed.
Big Cleanup: SkBitmapFactory, SkLazyPixelRef, SkImageCache Removed SkBitmapFactory since no clients were using it. New cache selection mechanism can simply pass a SkDiscardableMemory::Factory into the SkDiscardablePixelRef if non-default SkDiscardableMemory should be used. Removed BitmapFactoryTest. SkDiscardableMemory::Factory interface. Android will need this functionality in the future inside their BitmapFactory. Removed SkLazyPixelRef, since it's functionality is now subsumed into SkDiscardablePixelRef. Removed LazyPixelRef test. Modified SkDiscardablePixelRef to optionally allow it to use a SkDiscardableMemory::Factory. This tiny change makes it a replacement for SkLazyPixelRef. This functioanlity is also necessary for moving Android over to SkDiscardablePixelRef from SkImageRef in a later CL. Added a test for this. SkDecodingImageGenerator::Install can optionally pass a factory in to SkDiscardablePixelRef. Removed SkImageCache, SkLruImageCache, and SkPurgeableImageCache. This functionality can be handled much more cleanly by SkDiscardableMemory. New SkDiscardableMemoryPool class to replace SkLruImageCache. In a later CL, we will replace SkImageRef_GlobalPool (used by android) as well. This is a concrete implementation of SkDiscardableMemory::Factory. Added a test for this. modified gm/factory.cpp to remove dependnce on SkBitmapFactory + SkLruImageCache. Now uses SkDecodingImageGenerator + SkDiscardablePixelRef + SkDiscardableMemoryPool. SkImageDecoder::Target replaces SkBitmapFactory::Target. The DecodeMemoryToTarget function may disappear in the future. Moved SkLazyCachingPixelRef::DecodeProc replaces SkBitmapFactory::DecodeProc. This is a short term change, since another CL changes SkLazyCachingPixelRef to use SkImageGenerator instead of DecodeProc. Modified DrawBitmapRectTest to use SkDiscardablePixelRef instead of SkLazyPixelRef. tools/LazyDecodeBitmap.cpp now uses SkDecodingImageGenerator + SkDiscardablePixelRef instead of a SkBitmapFactory. bench_pictures uses the Global SkDiscardableMemoryPool instead of a global gLruImageCache. R=reed@google.com, scroggo@google.com Review URL: https://codereview.chromium.org/103033002 git-svn-id: http://skia.googlecode.com/svn/trunk@12515 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-12-05 18:31:42 +00:00
*
* @param destination Upon success, this bitmap will be
* configured and have a pixelref installed.
Big Cleanup: SkBitmapFactory, SkLazyPixelRef, SkImageCache Removed SkBitmapFactory since no clients were using it. New cache selection mechanism can simply pass a SkDiscardableMemory::Factory into the SkDiscardablePixelRef if non-default SkDiscardableMemory should be used. Removed BitmapFactoryTest. SkDiscardableMemory::Factory interface. Android will need this functionality in the future inside their BitmapFactory. Removed SkLazyPixelRef, since it's functionality is now subsumed into SkDiscardablePixelRef. Removed LazyPixelRef test. Modified SkDiscardablePixelRef to optionally allow it to use a SkDiscardableMemory::Factory. This tiny change makes it a replacement for SkLazyPixelRef. This functioanlity is also necessary for moving Android over to SkDiscardablePixelRef from SkImageRef in a later CL. Added a test for this. SkDecodingImageGenerator::Install can optionally pass a factory in to SkDiscardablePixelRef. Removed SkImageCache, SkLruImageCache, and SkPurgeableImageCache. This functionality can be handled much more cleanly by SkDiscardableMemory. New SkDiscardableMemoryPool class to replace SkLruImageCache. In a later CL, we will replace SkImageRef_GlobalPool (used by android) as well. This is a concrete implementation of SkDiscardableMemory::Factory. Added a test for this. modified gm/factory.cpp to remove dependnce on SkBitmapFactory + SkLruImageCache. Now uses SkDecodingImageGenerator + SkDiscardablePixelRef + SkDiscardableMemoryPool. SkImageDecoder::Target replaces SkBitmapFactory::Target. The DecodeMemoryToTarget function may disappear in the future. Moved SkLazyCachingPixelRef::DecodeProc replaces SkBitmapFactory::DecodeProc. This is a short term change, since another CL changes SkLazyCachingPixelRef to use SkImageGenerator instead of DecodeProc. Modified DrawBitmapRectTest to use SkDiscardablePixelRef instead of SkLazyPixelRef. tools/LazyDecodeBitmap.cpp now uses SkDecodingImageGenerator + SkDiscardablePixelRef instead of a SkBitmapFactory. bench_pictures uses the Global SkDiscardableMemoryPool instead of a global gLruImageCache. R=reed@google.com, scroggo@google.com Review URL: https://codereview.chromium.org/103033002 git-svn-id: http://skia.googlecode.com/svn/trunk@12515 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-12-05 18:31:42 +00:00
*
* @param factory If not NULL, this object will be used as a
* source of discardable memory when decoding. If NULL, then
* SkDiscardableMemory::Create() will be called.
Big Cleanup: SkBitmapFactory, SkLazyPixelRef, SkImageCache Removed SkBitmapFactory since no clients were using it. New cache selection mechanism can simply pass a SkDiscardableMemory::Factory into the SkDiscardablePixelRef if non-default SkDiscardableMemory should be used. Removed BitmapFactoryTest. SkDiscardableMemory::Factory interface. Android will need this functionality in the future inside their BitmapFactory. Removed SkLazyPixelRef, since it's functionality is now subsumed into SkDiscardablePixelRef. Removed LazyPixelRef test. Modified SkDiscardablePixelRef to optionally allow it to use a SkDiscardableMemory::Factory. This tiny change makes it a replacement for SkLazyPixelRef. This functioanlity is also necessary for moving Android over to SkDiscardablePixelRef from SkImageRef in a later CL. Added a test for this. SkDecodingImageGenerator::Install can optionally pass a factory in to SkDiscardablePixelRef. Removed SkImageCache, SkLruImageCache, and SkPurgeableImageCache. This functionality can be handled much more cleanly by SkDiscardableMemory. New SkDiscardableMemoryPool class to replace SkLruImageCache. In a later CL, we will replace SkImageRef_GlobalPool (used by android) as well. This is a concrete implementation of SkDiscardableMemory::Factory. Added a test for this. modified gm/factory.cpp to remove dependnce on SkBitmapFactory + SkLruImageCache. Now uses SkDecodingImageGenerator + SkDiscardablePixelRef + SkDiscardableMemoryPool. SkImageDecoder::Target replaces SkBitmapFactory::Target. The DecodeMemoryToTarget function may disappear in the future. Moved SkLazyCachingPixelRef::DecodeProc replaces SkBitmapFactory::DecodeProc. This is a short term change, since another CL changes SkLazyCachingPixelRef to use SkImageGenerator instead of DecodeProc. Modified DrawBitmapRectTest to use SkDiscardablePixelRef instead of SkLazyPixelRef. tools/LazyDecodeBitmap.cpp now uses SkDecodingImageGenerator + SkDiscardablePixelRef instead of a SkBitmapFactory. bench_pictures uses the Global SkDiscardableMemoryPool instead of a global gLruImageCache. R=reed@google.com, scroggo@google.com Review URL: https://codereview.chromium.org/103033002 git-svn-id: http://skia.googlecode.com/svn/trunk@12515 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-12-05 18:31:42 +00:00
*
* @return true iff successful.
*/
static bool Install(SkData* data, SkBitmap* destination,
SkDiscardableMemory::Factory* factory = NULL);
/**
* Install the stream into the destination bitmap, using a new
* SkDiscardablePixelRef and a new SkDecodingImageGenerator.
*
* The SkData version of this function is preferred. If the
* stream has an underlying SkData (such as a SkMemoryStream)
* pass that in.
*
* @param stream The source of encoded data that will be passed
* to the decoder. The installed SkDecodingImageGenerator will
* unref the stream when done. If false is returned, this
* function will perform the unref. Since streams have internal
* state (position), the caller should not pass a shared stream
* in. Pass either a new duplicated stream in or transfer
* ownership of the stream. In the latter case, be sure that
* there are no other consumers of the stream who will modify the
* stream's position. This function will fail if
* (!stream->unique()).
*
* @param destination Upon success, this bitmap will be
* configured and have a pixelref installed.
*
* @param factory If not NULL, this object will be used as a
* source of discardable memory when decoding. If NULL, then
* SkDiscardableMemory::Create() will be called.
*
* @return true iff successful.
*/
static bool Install(SkStreamRewindable* stream, SkBitmap* destination,
SkDiscardableMemory::Factory* factory = NULL);
private:
SkData* fData;
SkStreamRewindable* fStream;
SkImageInfo fInfo;
bool fHasInfo;
bool fDoCopyTo;
};
#endif // SkDecodingImageGenerator_DEFINED