Index: include/core/SkPicture.h |
diff --git a/include/core/SkPicture.h b/include/core/SkPicture.h |
index f764d346cc4b9e8f4b828809372cd8305516265c..3628b06d23cfe29773bdec881287722ec2d5214f 100644 |
--- a/include/core/SkPicture.h |
+++ b/include/core/SkPicture.h |
@@ -35,6 +35,14 @@ namespace SkRecords { |
class CollectLayers; |
}; |
+//#define SK_LEGACY_ENCODE_BITMAP |
+ |
+#ifdef SK_LEGACY_ENCODE_BITMAP |
+#include "SkPixelSerializer.h" |
+#else |
+class SkPixelSerializer; |
+#endif |
+ |
/** \class SkPicture |
The SkPicture class records the drawing commands made to a canvas, to |
@@ -144,12 +152,19 @@ public: |
*/ |
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. |
*/ |
- void serialize(SkWStream*, EncodeBitmap encoder = NULL) const; |
+ void serialize(SkWStream* wStream, EncodeBitmap encoder) const { |
+ EncodeBitmapSerializer serializer(encoder); |
+ this->serialize(wStream, &serializer); |
+ } |
+#endif |
+ |
+ void serialize(SkWStream*, SkPixelSerializer* serializer = NULL) const; |
/** |
* Serialize to a buffer. |
@@ -295,6 +310,30 @@ private: |
int fNumAADFEligibleConcavePaths; |
} fAnalysis; |
+#ifdef SK_LEGACY_ENCODE_BITMAP |
+ // Helper to use the new API. |
+ class EncodeBitmapSerializer : public SkPixelSerializer { |
+ public: |
+ explicit EncodeBitmapSerializer(EncodeBitmap encoder) |
+ : fEncoder(encoder) |
+ { |
+ SkASSERT(fEncoder); |
+ } |
+ |
+ bool useEncodedData(SkData*) SK_OVERRIDE { return true; } |
+ |
+ SkData* encodePixels(const SkImageInfo& info, void* pixels, size_t rowBytes) SK_OVERRIDE { |
+ size_t unused; |
+ SkBitmap bm; |
+ bm.installPixels(info, pixels, rowBytes); |
+ return fEncoder(&unused, bm); |
+ } |
+ |
+ private: |
+ EncodeBitmap fEncoder; |
+ }; |
+#endif |
+ |
friend class SkPictureRecorder; // SkRecord-based constructor. |
friend class GrLayerHoister; // access to fRecord |
friend class ReplaceDraw; |