commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +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 SkWriteBuffer_DEFINED |
| 10 | #define SkWriteBuffer_DEFINED |
| 11 | |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 12 | #include "SkData.h" |
msarett | e8597a4 | 2016-03-24 10:41:47 -0700 | [diff] [blame] | 13 | #include "SkImage.h" |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 14 | #include "SkPath.h" |
| 15 | #include "SkPicture.h" |
scroggo | 895c43b | 2014-12-11 10:53:58 -0800 | [diff] [blame] | 16 | #include "SkPixelSerializer.h" |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 17 | #include "SkRefCnt.h" |
| 18 | #include "SkWriter32.h" |
msarett | a3b3b23 | 2016-04-22 12:43:07 -0700 | [diff] [blame^] | 19 | #include "../private/SkTHash.h" |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 20 | |
| 21 | class SkBitmap; |
djsollen | 0b17d6c | 2014-11-13 12:52:35 -0800 | [diff] [blame] | 22 | class SkBitmapHeap; |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 23 | class SkFactorySet; |
| 24 | class SkFlattenable; |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 25 | class SkRefCntSet; |
| 26 | |
| 27 | class SkWriteBuffer { |
| 28 | public: |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 29 | enum Flags { |
| 30 | kCrossProcess_Flag = 1 << 0, |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 31 | }; |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 32 | |
commit-bot@chromium.org | a2bd2d1 | 2014-01-30 22:16:32 +0000 | [diff] [blame] | 33 | SkWriteBuffer(uint32_t flags = 0); |
| 34 | SkWriteBuffer(void* initialStorage, size_t storageSize, uint32_t flags = 0); |
| 35 | ~SkWriteBuffer(); |
| 36 | |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 37 | bool isCrossProcess() const { |
msarett | a3b3b23 | 2016-04-22 12:43:07 -0700 | [diff] [blame^] | 38 | return SkToBool(fFlags & kCrossProcess_Flag); |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | SkWriter32* getWriter32() { return &fWriter; } |
| 42 | void reset(void* storage = NULL, size_t storageSize = 0) { |
| 43 | fWriter.reset(storage, storageSize); |
| 44 | } |
| 45 | |
| 46 | uint32_t* reserve(size_t size) { return fWriter.reserve(size); } |
| 47 | |
| 48 | size_t bytesWritten() const { return fWriter.bytesWritten(); } |
| 49 | |
| 50 | void writeByteArray(const void* data, size_t size); |
| 51 | void writeDataAsByteArray(SkData* data) { this->writeByteArray(data->data(), data->size()); } |
| 52 | void writeBool(bool value); |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 53 | void writeScalar(SkScalar value); |
| 54 | void writeScalarArray(const SkScalar* value, uint32_t count); |
| 55 | void writeInt(int32_t value); |
| 56 | void writeIntArray(const int32_t* value, uint32_t count); |
| 57 | void writeUInt(uint32_t value); |
| 58 | void write32(int32_t value); |
| 59 | void writeString(const char* value); |
| 60 | void writeEncodedString(const void* value, size_t byteLength, SkPaint::TextEncoding encoding); |
commit-bot@chromium.org | 39426e2 | 2014-04-16 16:24:08 +0000 | [diff] [blame] | 61 | void writeFunctionPtr(void* ptr) { fWriter.writePtr(ptr); } |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 62 | |
| 63 | void writeFlattenable(const SkFlattenable* flattenable); |
| 64 | void writeColor(const SkColor& color); |
| 65 | void writeColorArray(const SkColor* color, uint32_t count); |
| 66 | void writePoint(const SkPoint& point); |
| 67 | void writePointArray(const SkPoint* point, uint32_t count); |
| 68 | void writeMatrix(const SkMatrix& matrix); |
| 69 | void writeIRect(const SkIRect& rect); |
| 70 | void writeRect(const SkRect& rect); |
| 71 | void writeRegion(const SkRegion& region); |
| 72 | void writePath(const SkPath& path); |
| 73 | size_t writeStream(SkStream* stream, size_t length); |
| 74 | void writeBitmap(const SkBitmap& bitmap); |
reed | 871872f | 2015-06-22 12:48:26 -0700 | [diff] [blame] | 75 | void writeImage(const SkImage*); |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 76 | void writeTypeface(SkTypeface* typeface); |
| 77 | void writePaint(const SkPaint& paint) { paint.flatten(*this); } |
| 78 | |
| 79 | bool writeToStream(SkWStream*); |
| 80 | void writeToMemory(void* dst) { fWriter.flatten(dst); } |
| 81 | |
| 82 | SkFactorySet* setFactoryRecorder(SkFactorySet*); |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 83 | |
| 84 | SkRefCntSet* getTypefaceRecorder() const { return fTFSet; } |
| 85 | SkRefCntSet* setTypefaceRecorder(SkRefCntSet*); |
| 86 | |
| 87 | /** |
| 88 | * Set an SkBitmapHeap to store bitmaps rather than flattening. |
| 89 | * |
scroggo | 895c43b | 2014-12-11 10:53:58 -0800 | [diff] [blame] | 90 | * Incompatible with an SkPixelSerializer. If an SkPixelSerializer is set, |
| 91 | * setting an SkBitmapHeap will set the SkPixelSerializer to NULL in release |
| 92 | * and crash in debug. |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 93 | */ |
| 94 | void setBitmapHeap(SkBitmapHeap*); |
| 95 | |
| 96 | /** |
scroggo | 895c43b | 2014-12-11 10:53:58 -0800 | [diff] [blame] | 97 | * Set an SkPixelSerializer to store an encoded representation of pixels, |
| 98 | * e.g. SkBitmaps. |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 99 | * |
scroggo | 895c43b | 2014-12-11 10:53:58 -0800 | [diff] [blame] | 100 | * Calls ref() on the serializer. |
| 101 | * |
| 102 | * TODO: Encode SkImage pixels as well. |
| 103 | * |
| 104 | * Incompatible with the SkBitmapHeap. If an encoder is set fBitmapHeap will |
| 105 | * be set to NULL in release and crash in debug. |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 106 | */ |
scroggo | 895c43b | 2014-12-11 10:53:58 -0800 | [diff] [blame] | 107 | void setPixelSerializer(SkPixelSerializer*); |
reed | 871872f | 2015-06-22 12:48:26 -0700 | [diff] [blame] | 108 | SkPixelSerializer* getPixelSerializer() const { return fPixelSerializer; } |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 109 | |
| 110 | private: |
commit-bot@chromium.org | a2bd2d1 | 2014-01-30 22:16:32 +0000 | [diff] [blame] | 111 | const uint32_t fFlags; |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 112 | SkFactorySet* fFactorySet; |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 113 | SkWriter32 fWriter; |
| 114 | |
| 115 | SkBitmapHeap* fBitmapHeap; |
| 116 | SkRefCntSet* fTFSet; |
| 117 | |
scroggo | 895c43b | 2014-12-11 10:53:58 -0800 | [diff] [blame] | 118 | SkAutoTUnref<SkPixelSerializer> fPixelSerializer; |
msarett | a3b3b23 | 2016-04-22 12:43:07 -0700 | [diff] [blame^] | 119 | |
| 120 | // Only used if we do not have an fFactorySet |
| 121 | SkTHashMap<SkString, uint32_t> fFlattenableDict; |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 122 | }; |
| 123 | |
| 124 | #endif // SkWriteBuffer_DEFINED |