michael@0: /* michael@0: * Copyright 2013 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #ifndef SkImageGenerator_DEFINED michael@0: #define SkImageGenerator_DEFINED michael@0: michael@0: #include "SkDiscardableMemory.h" michael@0: #include "SkImageInfo.h" michael@0: michael@0: class SkBitmap; michael@0: class SkData; michael@0: class SkImageGenerator; michael@0: michael@0: /** michael@0: * Takes ownership of SkImageGenerator. If this method fails for michael@0: * whatever reason, it will return false and immediatetely delete michael@0: * the generator. If it succeeds, it will modify destination michael@0: * bitmap. michael@0: * michael@0: * If generator is NULL, will safely return false. michael@0: * michael@0: * If this fails or when the SkDiscardablePixelRef that is michael@0: * installed into destination is destroyed, it will call michael@0: * SkDELETE() on the generator. Therefore, generator should be michael@0: * allocated with SkNEW() or SkNEW_ARGS(). michael@0: * michael@0: * @param destination Upon success, this bitmap will be michael@0: * configured and have a pixelref installed. michael@0: * michael@0: * @param factory If not NULL, this object will be used as a michael@0: * source of discardable memory when decoding. If NULL, then michael@0: * SkDiscardableMemory::Create() will be called. michael@0: * michael@0: * @return true iff successful. michael@0: */ michael@0: SK_API bool SkInstallDiscardablePixelRef(SkImageGenerator* generator, michael@0: SkBitmap* destination, michael@0: SkDiscardableMemory::Factory* factory = NULL); michael@0: michael@0: michael@0: /** michael@0: * An interface that allows a purgeable PixelRef (such as a michael@0: * SkDiscardablePixelRef) to decode and re-decode an image as needed. michael@0: */ michael@0: class SK_API SkImageGenerator { michael@0: public: michael@0: /** michael@0: * The PixelRef which takes ownership of this SkImageGenerator michael@0: * will call the image generator's destructor. michael@0: */ michael@0: virtual ~SkImageGenerator() { } michael@0: michael@0: /** michael@0: * Return a ref to the encoded (i.e. compressed) representation, michael@0: * of this data. michael@0: * michael@0: * If non-NULL is returned, the caller is responsible for calling michael@0: * unref() on the data when it is finished. michael@0: */ michael@0: virtual SkData* refEncodedData() { return NULL; } michael@0: michael@0: /** michael@0: * Return some information about the image, allowing the owner of michael@0: * this object to allocate pixels. michael@0: * michael@0: * Repeated calls to this function should give the same results, michael@0: * allowing the PixelRef to be immutable. michael@0: * michael@0: * @return false if anything goes wrong. michael@0: */ michael@0: virtual bool getInfo(SkImageInfo* info) = 0; michael@0: michael@0: /** michael@0: * Decode into the given pixels, a block of memory of size at michael@0: * least (info.fHeight - 1) * rowBytes + (info.fWidth * michael@0: * bytesPerPixel) michael@0: * michael@0: * Repeated calls to this function should give the same results, michael@0: * allowing the PixelRef to be immutable. michael@0: * michael@0: * @param info A description of the format (config, size) michael@0: * expected by the caller. This can simply be identical michael@0: * to the info returned by getInfo(). michael@0: * michael@0: * This contract also allows the caller to specify michael@0: * different output-configs, which the implementation can michael@0: * decide to support or not. michael@0: * michael@0: * @return false if anything goes wrong or if the image info is michael@0: * unsupported. michael@0: */ michael@0: virtual bool getPixels(const SkImageInfo& info, michael@0: void* pixels, michael@0: size_t rowBytes) = 0; michael@0: }; michael@0: michael@0: #endif // SkImageGenerator_DEFINED