djsollen@google.com | 2b2ede3 | 2012-04-12 13:24:04 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
| 9 | #ifndef SkOrderedWriteBuffer_DEFINED |
| 10 | #define SkOrderedWriteBuffer_DEFINED |
| 11 | |
djsollen@google.com | c73dd5c | 2012-08-07 15:54:32 +0000 | [diff] [blame] | 12 | #include "SkFlattenableBuffers.h" |
| 13 | |
djsollen@google.com | 2b2ede3 | 2012-04-12 13:24:04 +0000 | [diff] [blame] | 14 | #include "SkRefCnt.h" |
djsollen@google.com | 21830d9 | 2012-08-07 19:49:41 +0000 | [diff] [blame] | 15 | #include "SkBitmapHeap.h" |
djsollen@google.com | 2b2ede3 | 2012-04-12 13:24:04 +0000 | [diff] [blame] | 16 | #include "SkPath.h" |
scroggo@google.com | 32ef131 | 2013-02-22 22:04:19 +0000 | [diff] [blame] | 17 | #include "SkPicture.h" |
djsollen@google.com | c73dd5c | 2012-08-07 15:54:32 +0000 | [diff] [blame] | 18 | #include "SkWriter32.h" |
| 19 | |
junov@chromium.org | ce65f38 | 2012-10-17 19:36:09 +0000 | [diff] [blame] | 20 | class SkBitmap; |
djsollen@google.com | c73dd5c | 2012-08-07 15:54:32 +0000 | [diff] [blame] | 21 | class SkFlattenable; |
mike@reedtribe.org | 227b516 | 2012-08-12 19:25:08 +0000 | [diff] [blame] | 22 | class SkFactorySet; |
| 23 | class SkNamedFactorySet; |
| 24 | class SkRefCntSet; |
djsollen@google.com | 2b2ede3 | 2012-04-12 13:24:04 +0000 | [diff] [blame] | 25 | |
| 26 | class SkOrderedWriteBuffer : public SkFlattenableWriteBuffer { |
| 27 | public: |
| 28 | SkOrderedWriteBuffer(size_t minSize); |
commit-bot@chromium.org | ff36a1d | 2013-07-24 20:37:30 +0000 | [diff] [blame] | 29 | SkOrderedWriteBuffer(size_t minSize, void* initialStorage, size_t storageSize); |
djsollen@google.com | c73dd5c | 2012-08-07 15:54:32 +0000 | [diff] [blame] | 30 | virtual ~SkOrderedWriteBuffer(); |
| 31 | |
| 32 | virtual bool isOrderedBinaryBuffer() SK_OVERRIDE { return true; } |
| 33 | virtual SkOrderedWriteBuffer* getOrderedBinaryBuffer() SK_OVERRIDE { return this; } |
djsollen@google.com | 2b2ede3 | 2012-04-12 13:24:04 +0000 | [diff] [blame] | 34 | |
djsollen@google.com | d2700ee | 2012-05-30 16:54:13 +0000 | [diff] [blame] | 35 | SkWriter32* getWriter32() { return &fWriter; } |
commit-bot@chromium.org | ff36a1d | 2013-07-24 20:37:30 +0000 | [diff] [blame] | 36 | void reset(void* storage, size_t storageSize) { fWriter.reset(storage, storageSize); } |
| 37 | |
| 38 | // Returns true if we've written only into the storage passed into constructor or reset. |
| 39 | // (You may be able to use this to avoid a call to writeToMemory.) |
| 40 | bool wroteOnlyToStorage() const { return fWriter.wroteOnlyToStorage(); } |
djsollen@google.com | d2700ee | 2012-05-30 16:54:13 +0000 | [diff] [blame] | 41 | |
djsollen@google.com | c73dd5c | 2012-08-07 15:54:32 +0000 | [diff] [blame] | 42 | void writeToMemory(void* dst) { fWriter.flatten(dst); } |
| 43 | uint32_t* reserve(size_t size) { return fWriter.reserve(size); } |
commit-bot@chromium.org | ff36a1d | 2013-07-24 20:37:30 +0000 | [diff] [blame] | 44 | |
robertphillips@google.com | adacc70 | 2013-10-14 21:53:24 +0000 | [diff] [blame] | 45 | size_t bytesWritten() const { return fWriter.bytesWritten(); } |
commit-bot@chromium.org | ff36a1d | 2013-07-24 20:37:30 +0000 | [diff] [blame] | 46 | // Deprecated. Please call bytesWritten instead. TODO(mtklein): clean up |
robertphillips@google.com | adacc70 | 2013-10-14 21:53:24 +0000 | [diff] [blame] | 47 | size_t size() const { return this->bytesWritten(); } |
djsollen@google.com | 2b2ede3 | 2012-04-12 13:24:04 +0000 | [diff] [blame] | 48 | |
djsollen@google.com | c73dd5c | 2012-08-07 15:54:32 +0000 | [diff] [blame] | 49 | virtual void writeByteArray(const void* data, size_t size) SK_OVERRIDE; |
| 50 | virtual void writeBool(bool value) SK_OVERRIDE; |
| 51 | virtual void writeFixed(SkFixed value) SK_OVERRIDE; |
| 52 | virtual void writeScalar(SkScalar value) SK_OVERRIDE; |
| 53 | virtual void writeScalarArray(const SkScalar* value, uint32_t count) SK_OVERRIDE; |
| 54 | virtual void writeInt(int32_t value) SK_OVERRIDE; |
| 55 | virtual void writeIntArray(const int32_t* value, uint32_t count) SK_OVERRIDE; |
| 56 | virtual void writeUInt(uint32_t value) SK_OVERRIDE; |
| 57 | virtual void write32(int32_t value) SK_OVERRIDE; |
| 58 | virtual void writeString(const char* value) SK_OVERRIDE; |
| 59 | virtual void writeEncodedString(const void* value, size_t byteLength, |
| 60 | SkPaint::TextEncoding encoding) SK_OVERRIDE; |
djsollen@google.com | 2b2ede3 | 2012-04-12 13:24:04 +0000 | [diff] [blame] | 61 | |
robertphillips@google.com | c2eae47 | 2013-10-21 12:26:10 +0000 | [diff] [blame] | 62 | virtual void writeFlattenable(const SkFlattenable* flattenable) SK_OVERRIDE; |
djsollen@google.com | c73dd5c | 2012-08-07 15:54:32 +0000 | [diff] [blame] | 63 | virtual void writeColor(const SkColor& color) SK_OVERRIDE; |
| 64 | virtual void writeColorArray(const SkColor* color, uint32_t count) SK_OVERRIDE; |
| 65 | virtual void writePoint(const SkPoint& point) SK_OVERRIDE; |
| 66 | virtual void writePointArray(const SkPoint* point, uint32_t count) SK_OVERRIDE; |
| 67 | virtual void writeMatrix(const SkMatrix& matrix) SK_OVERRIDE; |
| 68 | virtual void writeIRect(const SkIRect& rect)SK_OVERRIDE; |
| 69 | virtual void writeRect(const SkRect& rect) SK_OVERRIDE; |
| 70 | virtual void writeRegion(const SkRegion& region) SK_OVERRIDE; |
| 71 | virtual void writePath(const SkPath& path) SK_OVERRIDE; |
| 72 | virtual size_t writeStream(SkStream* stream, size_t length) SK_OVERRIDE; |
djsollen@google.com | 2b2ede3 | 2012-04-12 13:24:04 +0000 | [diff] [blame] | 73 | |
djsollen@google.com | c73dd5c | 2012-08-07 15:54:32 +0000 | [diff] [blame] | 74 | virtual void writeBitmap(const SkBitmap& bitmap) SK_OVERRIDE; |
| 75 | virtual void writeTypeface(SkTypeface* typeface) SK_OVERRIDE; |
| 76 | |
| 77 | virtual bool writeToStream(SkWStream*) SK_OVERRIDE; |
| 78 | |
| 79 | SkFactorySet* setFactoryRecorder(SkFactorySet*); |
| 80 | SkNamedFactorySet* setNamedFactoryRecorder(SkNamedFactorySet*); |
| 81 | |
| 82 | SkRefCntSet* getTypefaceRecorder() const { return fTFSet; } |
| 83 | SkRefCntSet* setTypefaceRecorder(SkRefCntSet*); |
| 84 | |
scroggo@google.com | 7c9d539 | 2012-12-10 15:40:55 +0000 | [diff] [blame] | 85 | /** |
| 86 | * Set an SkBitmapHeap to store bitmaps rather than flattening. |
| 87 | * |
| 88 | * Incompatible with an EncodeBitmap function. If an EncodeBitmap function is set, setting an |
| 89 | * SkBitmapHeap will set the function to NULL in release mode and crash in debug. |
| 90 | */ |
| 91 | void setBitmapHeap(SkBitmapHeap*); |
djsollen@google.com | 2b2ede3 | 2012-04-12 13:24:04 +0000 | [diff] [blame] | 92 | |
scroggo@google.com | 5a7c6be | 2012-10-04 21:46:08 +0000 | [diff] [blame] | 93 | /** |
scroggo@google.com | 1b1bcc3 | 2013-05-21 20:31:23 +0000 | [diff] [blame] | 94 | * Provide a function to encode an SkBitmap to an SkData. writeBitmap will attempt to use |
scroggo@google.com | 7c9d539 | 2012-12-10 15:40:55 +0000 | [diff] [blame] | 95 | * bitmapEncoder to store the SkBitmap. If the reader does not provide a function to decode, it |
| 96 | * will not be able to restore SkBitmaps, but will still be able to read the rest of the stream. |
scroggo@google.com | 1b1bcc3 | 2013-05-21 20:31:23 +0000 | [diff] [blame] | 97 | * bitmapEncoder will never be called with a NULL pixelRefOffset. |
scroggo@google.com | 7c9d539 | 2012-12-10 15:40:55 +0000 | [diff] [blame] | 98 | * |
| 99 | * Incompatible with the SkBitmapHeap. If an encoder is set fBitmapHeap will be set to NULL in |
| 100 | * release and crash in debug. |
scroggo@google.com | 5a7c6be | 2012-10-04 21:46:08 +0000 | [diff] [blame] | 101 | */ |
scroggo@google.com | 1b1bcc3 | 2013-05-21 20:31:23 +0000 | [diff] [blame] | 102 | void setBitmapEncoder(SkPicture::EncodeBitmap bitmapEncoder); |
scroggo@google.com | 5a7c6be | 2012-10-04 21:46:08 +0000 | [diff] [blame] | 103 | |
djsollen@google.com | 2b2ede3 | 2012-04-12 13:24:04 +0000 | [diff] [blame] | 104 | private: |
djsollen@google.com | c73dd5c | 2012-08-07 15:54:32 +0000 | [diff] [blame] | 105 | SkFactorySet* fFactorySet; |
| 106 | SkNamedFactorySet* fNamedFactorySet; |
djsollen@google.com | 2b2ede3 | 2012-04-12 13:24:04 +0000 | [diff] [blame] | 107 | SkWriter32 fWriter; |
djsollen@google.com | c73dd5c | 2012-08-07 15:54:32 +0000 | [diff] [blame] | 108 | |
djsollen@google.com | 21830d9 | 2012-08-07 19:49:41 +0000 | [diff] [blame] | 109 | SkBitmapHeap* fBitmapHeap; |
| 110 | SkRefCntSet* fTFSet; |
djsollen@google.com | c73dd5c | 2012-08-07 15:54:32 +0000 | [diff] [blame] | 111 | |
scroggo@google.com | 32ef131 | 2013-02-22 22:04:19 +0000 | [diff] [blame] | 112 | SkPicture::EncodeBitmap fBitmapEncoder; |
scroggo@google.com | 5a7c6be | 2012-10-04 21:46:08 +0000 | [diff] [blame] | 113 | |
djsollen@google.com | 2b2ede3 | 2012-04-12 13:24:04 +0000 | [diff] [blame] | 114 | typedef SkFlattenableWriteBuffer INHERITED; |
| 115 | }; |
| 116 | |
| 117 | #endif // SkOrderedWriteBuffer_DEFINED |