diff options
author | scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-10-04 21:46:08 +0000 |
---|---|---|
committer | scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-10-04 21:46:08 +0000 |
commit | 5a7c6be72b940dde8ff6ad2485a09aecd56a2660 (patch) | |
tree | dae271d0e09ac6fcbb50dbc4509755055f20fc9c /include/core | |
parent | 94bc60f9864094edbfb787b09c963d8818c8962f (diff) |
Add the ability to provide function pointers to SkPicture serialization
and deserialization for encoding and decoding bitmaps.
Remove kForceFlattenBitmapPixels_Flag, which is no longer used.
When an SkOrderedReadBuffer needs to read a bitmap, if it does not
have an image decoder, use a dummy bitmap.
In GM, add a tolerance option for color differences, used when
testing picture serialization, so it can assume two images are the
same even though PNG encoding/decoding may have resulted in small
differences.
Create dummy implementations for SkImageDecoder and SkImageEncoder
functions in SkImageDecoder_empty so that a project that does not
want to include the images project it can still build.
Allow ports to build without images project.
In Mac's image encoder, copy 4444 to 8888 before encoding.
Add SkWriter32::reservePad, to provide a pointer to write non 4 byte
aligned data, padded with zeroes.
In bench_ and render_ pictures, pass decode function to SkPicture
creation from a stream.
BUG=https://code.google.com/p/skia/issues/detail?id=842
Review URL: https://codereview.appspot.com/6551071
git-svn-id: http://skia.googlecode.com/svn/trunk@5818 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include/core')
-rw-r--r-- | include/core/SkFlattenableBuffers.h | 9 | ||||
-rw-r--r-- | include/core/SkPicture.h | 11 | ||||
-rw-r--r-- | include/core/SkSerializationHelpers.h | 35 | ||||
-rw-r--r-- | include/core/SkWriter32.h | 9 |
4 files changed, 53 insertions, 11 deletions
diff --git a/include/core/SkFlattenableBuffers.h b/include/core/SkFlattenableBuffers.h index 763460b12f..f5b853c5ac 100644 --- a/include/core/SkFlattenableBuffers.h +++ b/include/core/SkFlattenableBuffers.h @@ -154,11 +154,6 @@ public: enum Flags { kCrossProcess_Flag = 0x01, - - /** - * Instructs the writer to always serialize bitmap pixel data. - */ - kForceFlattenBitmapPixels_Flag = 0x04, }; uint32_t getFlags() const { return fFlags; } @@ -168,10 +163,6 @@ public: return SkToBool(fFlags & kCrossProcess_Flag); } - bool persistBitmapPixels() const { - return (fFlags & (kCrossProcess_Flag | kForceFlattenBitmapPixels_Flag)) != 0; - } - bool persistTypeface() const { return (fFlags & kCrossProcess_Flag) != 0; } protected: diff --git a/include/core/SkPicture.h b/include/core/SkPicture.h index 00eadb83a6..203efde916 100644 --- a/include/core/SkPicture.h +++ b/include/core/SkPicture.h @@ -11,6 +11,7 @@ #define SkPicture_DEFINED #include "SkRefCnt.h" +#include "SkSerializationHelpers.h" class SkBitmap; class SkCanvas; @@ -40,8 +41,10 @@ public: /** * Recreate a picture that was serialized into a stream. *success is set to * true if the picture was deserialized successfully and false otherwise. + * decoder is used to decode any SkBitmaps that were encoded into the stream. */ - explicit SkPicture(SkStream*, bool* success = NULL); + explicit SkPicture(SkStream*, bool* success = NULL, + SkSerializationHelpers::DecodeBitmap decoder = NULL); virtual ~SkPicture(); /** @@ -132,7 +135,11 @@ public: */ int height() const { return fHeight; } - void serialize(SkWStream*) const; + /** + * Serialize to a stream. If non NULL, encoder will be used to encode + * any bitmaps in the picture. + */ + void serialize(SkWStream*, SkSerializationHelpers::EncodeBitmap encoder = NULL) const; /** Signals that the caller is prematurely done replaying the drawing commands. This can be called from a canvas virtual while the picture diff --git a/include/core/SkSerializationHelpers.h b/include/core/SkSerializationHelpers.h new file mode 100644 index 0000000000..8bb2a41d95 --- /dev/null +++ b/include/core/SkSerializationHelpers.h @@ -0,0 +1,35 @@ + +/* + * Copyright 2012 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkSerializationHelpers_DEFINED +#define SkSerializationHelpers_DEFINED + +class SkBitmap; +class SkStream; +class SkWStream; + +namespace SkSerializationHelpers { + /** + * Function to encode an SkBitmap to an SkWStream. A function with this signature can be passed + * to SkPicture::serialize() and SkOrderedWriteBuffer. The function should return true if it + * succeeds. Otherwise it should return false so that SkOrderedWriteBuffer can switch to + * another method of storing SkBitmaps. + */ + typedef bool (*EncodeBitmap)(SkWStream*, const SkBitmap&); + + /** + * Function to decode an SkBitmap from an SkStream. A function with this signature can be + * passed to the SkStream constructor for SkPicture and SkOrderedReadBuffer to decode SkBitmaps + * which were previously encoded. The function should return true if it succeeds. Otherwise it + * should return false so that SkOrderedReadBuffer can skip the data and provide a dummy + * SkBitmap. + */ + typedef bool (*DecodeBitmap)(SkStream*, SkBitmap*); +} + +#endif // SkSerializationHelpers_DEFINED diff --git a/include/core/SkWriter32.h b/include/core/SkWriter32.h index fa30f0f8eb..9354d6d16d 100644 --- a/include/core/SkWriter32.h +++ b/include/core/SkWriter32.h @@ -143,6 +143,15 @@ public: memcpy(this->reserve(size), values, size); } + /** + * Reserve size bytes. Does not need to be 4 byte aligned. The remaining space (if any) will be + * filled in with zeroes. + */ + uint32_t* reservePad(size_t size); + + /** + * Write size bytes from src, and pad to 4 byte alignment with zeroes. + */ void writePad(const void* src, size_t size); /** |