diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/core/SkPicture.h | 20 | ||||
-rw-r--r-- | include/core/SkPixelSerializer.h | 52 | ||||
-rw-r--r-- | include/core/SkWriteBuffer.h | 24 |
3 files changed, 85 insertions, 11 deletions
diff --git a/include/core/SkPicture.h b/include/core/SkPicture.h index f764d346cc..88d8b05a4b 100644 --- a/include/core/SkPicture.h +++ b/include/core/SkPicture.h @@ -24,6 +24,7 @@ class SkBBoxHierarchy; class SkCanvas; class SkData; class SkPictureData; +class SkPixelSerializer; class SkStream; class SkWStream; @@ -35,6 +36,8 @@ namespace SkRecords { class CollectLayers; }; +//#define SK_LEGACY_ENCODE_BITMAP + /** \class SkPicture The SkPicture class records the drawing commands made to a canvas, to @@ -141,15 +144,30 @@ public: * @param pixelRefOffset DEPRECATED -- caller assumes it will return 0. * @return SkData If non-NULL, holds encoded data representing the passed * in bitmap. The caller is responsible for calling unref(). + * + * TODO: No longer used by SkPicture (except when SK_LEGACY_ENCODE_BITMAP + * is defined. Still used by PDF though. Move into PDF. */ typedef SkData* (*EncodeBitmap)(size_t* pixelRefOffset, const SkBitmap& bm); +#ifdef SK_LEGACY_ENCODE_BITMAP /** * Serialize to a stream. If non NULL, encoder will be used to encode * any bitmaps in the picture. * encoder will never be called with a NULL pixelRefOffset. + * DEPRECATED - use serialize(SkWStream*, SkPixelSerializer* serializer) + * instead. + */ + void serialize(SkWStream* wStream, EncodeBitmap encoder) const; +#endif + + /** + * Serialize to a stream. If non NULL, serializer will be used to serialize + * any bitmaps in the picture. + * + * TODO: Use serializer to serialize SkImages as well. */ - void serialize(SkWStream*, EncodeBitmap encoder = NULL) const; + void serialize(SkWStream*, SkPixelSerializer* serializer = NULL) const; /** * Serialize to a buffer. diff --git a/include/core/SkPixelSerializer.h b/include/core/SkPixelSerializer.h new file mode 100644 index 0000000000..8fc445c753 --- /dev/null +++ b/include/core/SkPixelSerializer.h @@ -0,0 +1,52 @@ +/* + * Copyright 2014 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkPixelSerializer_DEFINED +#define SkPixelSerializer_DEFINED + +#include "SkRefCnt.h" + +class SkData; +struct SkImageInfo; + +/** + * Interface for serializing pixels, e.g. SkBitmaps in an SkPicture. + */ +class SkPixelSerializer : public SkRefCnt { +public: + virtual ~SkPixelSerializer() {} + + /** + * Call to determine if the client wants to serialize the encoded data. If + * false, serialize another version (e.g. the result of encodePixels). + */ + bool useEncodedData(const void* data, size_t len) { + return this->onUseEncodedData(data, len); + } + + /** + * Call to get the client's version of encoding these pixels. If it + * returns NULL, serialize the raw pixels. + */ + SkData* encodePixels(const SkImageInfo& info, void* pixels, size_t rowBytes) { + return this->onEncodePixels(info, pixels, rowBytes); + } + +protected: + /** + * Return true if you want to serialize the encoded data, false if you want + * another version serialized (e.g. the result of encodePixels). + */ + virtual bool onUseEncodedData(const void* data, size_t len) = 0; + + /** + * If you want to encode these pixels, return the encoded data as an SkData + * Return null if you want to serialize the raw pixels. + */ + virtual SkData* onEncodePixels(const SkImageInfo&, void* pixels, size_t rowBytes) = 0; +}; +#endif // SkPixelSerializer_DEFINED diff --git a/include/core/SkWriteBuffer.h b/include/core/SkWriteBuffer.h index 4dbe17b0d9..39739f2c24 100644 --- a/include/core/SkWriteBuffer.h +++ b/include/core/SkWriteBuffer.h @@ -12,6 +12,7 @@ #include "SkData.h" #include "SkPath.h" #include "SkPicture.h" +#include "SkPixelSerializer.h" #include "SkRefCnt.h" #include "SkWriter32.h" @@ -87,21 +88,24 @@ public: /** * Set an SkBitmapHeap to store bitmaps rather than flattening. * - * Incompatible with an EncodeBitmap function. If an EncodeBitmap function is set, setting an - * SkBitmapHeap will set the function to NULL in release mode and crash in debug. + * Incompatible with an SkPixelSerializer. If an SkPixelSerializer is set, + * setting an SkBitmapHeap will set the SkPixelSerializer to NULL in release + * and crash in debug. */ void setBitmapHeap(SkBitmapHeap*); /** - * Provide a function to encode an SkBitmap to an SkData. writeBitmap will attempt to use - * bitmapEncoder to store the SkBitmap. If the reader does not provide a function to decode, it - * will not be able to restore SkBitmaps, but will still be able to read the rest of the stream. - * bitmapEncoder will never be called with a NULL pixelRefOffset. + * Set an SkPixelSerializer to store an encoded representation of pixels, + * e.g. SkBitmaps. * - * Incompatible with the SkBitmapHeap. If an encoder is set fBitmapHeap will be set to NULL in - * release and crash in debug. + * Calls ref() on the serializer. + * + * TODO: Encode SkImage pixels as well. + * + * Incompatible with the SkBitmapHeap. If an encoder is set fBitmapHeap will + * be set to NULL in release and crash in debug. */ - void setBitmapEncoder(SkPicture::EncodeBitmap bitmapEncoder); + void setPixelSerializer(SkPixelSerializer*); private: bool isValidating() const { return SkToBool(fFlags & kValidation_Flag); } @@ -114,7 +118,7 @@ private: SkBitmapHeap* fBitmapHeap; SkRefCntSet* fTFSet; - SkPicture::EncodeBitmap fBitmapEncoder; + SkAutoTUnref<SkPixelSerializer> fPixelSerializer; }; #endif // SkWriteBuffer_DEFINED |