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