Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(360)

Side by Side Diff: include/core/SkWriteBuffer.h

Issue 1920423002: Prototype code that turns any/every flattenable into JSON (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix copyright dates in new files Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/core/SkBitmap.h ('k') | src/core/SkFlattenableSerialization.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #ifndef SkWriteBuffer_DEFINED 9 #ifndef SkWriteBuffer_DEFINED
10 #define SkWriteBuffer_DEFINED 10 #define SkWriteBuffer_DEFINED
11 11
12 #include "SkData.h" 12 #include "SkData.h"
13 #include "SkImage.h" 13 #include "SkImage.h"
14 #include "SkPath.h" 14 #include "SkPath.h"
15 #include "SkPicture.h" 15 #include "SkPicture.h"
16 #include "SkPixelSerializer.h" 16 #include "SkPixelSerializer.h"
17 #include "SkRefCnt.h" 17 #include "SkRefCnt.h"
18 #include "SkWriter32.h" 18 #include "SkWriter32.h"
19 #include "../private/SkTHash.h" 19 #include "../private/SkTHash.h"
20 20
21 class SkBitmap; 21 class SkBitmap;
22 class SkFactorySet; 22 class SkFactorySet;
23 class SkFlattenable; 23 class SkFlattenable;
24 class SkRefCntSet; 24 class SkRefCntSet;
25 25
26 class SkWriteBuffer { 26 class SkWriteBuffer {
27 public: 27 public:
28 SkWriteBuffer() {}
29 virtual ~SkWriteBuffer() {}
30
31 virtual bool isCrossProcess() const = 0;
32
33 virtual void writeByteArray(const void* data, size_t size) = 0;
34 void writeDataAsByteArray(SkData* data) {
35 this->writeByteArray(data->data(), data->size());
36 }
37 virtual void writeBool(bool value) = 0;
38 virtual void writeScalar(SkScalar value) = 0;
39 virtual void writeScalarArray(const SkScalar* value, uint32_t count) = 0;
40 virtual void writeInt(int32_t value) = 0;
41 virtual void writeIntArray(const int32_t* value, uint32_t count) = 0;
42 virtual void writeUInt(uint32_t value) = 0;
43 void write32(int32_t value) {
44 this->writeInt(value);
45 }
46 virtual void writeString(const char* value) = 0;
47
48 virtual void writeFlattenable(const SkFlattenable* flattenable) = 0;
49 virtual void writeColor(SkColor color) = 0;
50 virtual void writeColorArray(const SkColor* color, uint32_t count) = 0;
51 virtual void writePoint(const SkPoint& point) = 0;
52 virtual void writePointArray(const SkPoint* point, uint32_t count) = 0;
53 virtual void writeMatrix(const SkMatrix& matrix) = 0;
54 virtual void writeIRect(const SkIRect& rect) = 0;
55 virtual void writeRect(const SkRect& rect) = 0;
56 virtual void writeRegion(const SkRegion& region) = 0;
57 virtual void writePath(const SkPath& path) = 0;
58 virtual size_t writeStream(SkStream* stream, size_t length) = 0;
59 virtual void writeBitmap(const SkBitmap& bitmap) = 0;
60 virtual void writeImage(const SkImage*) = 0;
61 virtual void writeTypeface(SkTypeface* typeface) = 0;
62 virtual void writePaint(const SkPaint& paint) = 0;
63 };
64
65 /**
66 * Concrete implementation that serializes to a flat binary blob.
67 */
68 class SkBinaryWriteBuffer final : public SkWriteBuffer {
69 public:
28 enum Flags { 70 enum Flags {
29 kCrossProcess_Flag = 1 << 0, 71 kCrossProcess_Flag = 1 << 0,
30 }; 72 };
31 73
32 SkWriteBuffer(uint32_t flags = 0); 74 SkBinaryWriteBuffer(uint32_t flags = 0);
33 SkWriteBuffer(void* initialStorage, size_t storageSize, uint32_t flags = 0); 75 SkBinaryWriteBuffer(void* initialStorage, size_t storageSize, uint32_t flags = 0);
34 ~SkWriteBuffer(); 76 ~SkBinaryWriteBuffer();
35 77
36 bool isCrossProcess() const { 78 bool isCrossProcess() const override {
37 return SkToBool(fFlags & kCrossProcess_Flag); 79 return SkToBool(fFlags & kCrossProcess_Flag);
38 } 80 }
39 81
40 void reset(void* storage = NULL, size_t storageSize = 0) { 82 void reset(void* storage = NULL, size_t storageSize = 0) {
41 fWriter.reset(storage, storageSize); 83 fWriter.reset(storage, storageSize);
42 } 84 }
43 85
44 size_t bytesWritten() const { return fWriter.bytesWritten(); } 86 size_t bytesWritten() const { return fWriter.bytesWritten(); }
45 87
46 void writeByteArray(const void* data, size_t size); 88 void writeByteArray(const void* data, size_t size) override;
47 void writeDataAsByteArray(SkData* data) { this->writeByteArray(data->data(), data->size()); } 89 void writeBool(bool value) override;
48 void writeBool(bool value); 90 void writeScalar(SkScalar value) override;
49 void writeScalar(SkScalar value); 91 void writeScalarArray(const SkScalar* value, uint32_t count) override;
50 void writeScalarArray(const SkScalar* value, uint32_t count); 92 void writeInt(int32_t value) override;
51 void writeInt(int32_t value); 93 void writeIntArray(const int32_t* value, uint32_t count) override;
52 void writeIntArray(const int32_t* value, uint32_t count); 94 void writeUInt(uint32_t value) override;
53 void writeUInt(uint32_t value); 95 void writeString(const char* value) override;
54 void write32(int32_t value);
55 void writeString(const char* value);
56 96
57 void writeFlattenable(const SkFlattenable* flattenable); 97 void writeFlattenable(const SkFlattenable* flattenable) override;
58 void writeColor(const SkColor& color); 98 void writeColor(SkColor color) override;
59 void writeColorArray(const SkColor* color, uint32_t count); 99 void writeColorArray(const SkColor* color, uint32_t count) override;
60 void writePoint(const SkPoint& point); 100 void writePoint(const SkPoint& point) override;
61 void writePointArray(const SkPoint* point, uint32_t count); 101 void writePointArray(const SkPoint* point, uint32_t count) override;
62 void writeMatrix(const SkMatrix& matrix); 102 void writeMatrix(const SkMatrix& matrix) override;
63 void writeIRect(const SkIRect& rect); 103 void writeIRect(const SkIRect& rect) override;
64 void writeRect(const SkRect& rect); 104 void writeRect(const SkRect& rect) override;
65 void writeRegion(const SkRegion& region); 105 void writeRegion(const SkRegion& region) override;
66 void writePath(const SkPath& path); 106 void writePath(const SkPath& path) override;
67 size_t writeStream(SkStream* stream, size_t length); 107 size_t writeStream(SkStream* stream, size_t length) override;
68 void writeBitmap(const SkBitmap& bitmap); 108 void writeBitmap(const SkBitmap& bitmap) override;
69 void writeImage(const SkImage*); 109 void writeImage(const SkImage*) override;
70 void writeTypeface(SkTypeface* typeface); 110 void writeTypeface(SkTypeface* typeface) override;
71 void writePaint(const SkPaint& paint) { paint.flatten(*this); } 111 void writePaint(const SkPaint& paint) override;
72 112
73 bool writeToStream(SkWStream*); 113 bool writeToStream(SkWStream*);
74 void writeToMemory(void* dst) { fWriter.flatten(dst); } 114 void writeToMemory(void* dst) { fWriter.flatten(dst); }
75 115
76 SkFactorySet* setFactoryRecorder(SkFactorySet*); 116 SkFactorySet* setFactoryRecorder(SkFactorySet*);
77
78 SkRefCntSet* getTypefaceRecorder() const { return fTFSet; }
79 SkRefCntSet* setTypefaceRecorder(SkRefCntSet*); 117 SkRefCntSet* setTypefaceRecorder(SkRefCntSet*);
80 118
81 /** 119 /**
82 * Set an SkPixelSerializer to store an encoded representation of pixels, 120 * Set an SkPixelSerializer to store an encoded representation of pixels,
83 * e.g. SkBitmaps. 121 * e.g. SkBitmaps.
84 * 122 *
85 * Calls ref() on the serializer. 123 * Calls ref() on the serializer.
86 * 124 *
87 * TODO: Encode SkImage pixels as well. 125 * TODO: Encode SkImage pixels as well.
88 */ 126 */
89 void setPixelSerializer(SkPixelSerializer*); 127 void setPixelSerializer(SkPixelSerializer*);
90 SkPixelSerializer* getPixelSerializer() const { return fPixelSerializer; } 128 SkPixelSerializer* getPixelSerializer() const { return fPixelSerializer; }
91 129
92 private: 130 private:
93 const uint32_t fFlags; 131 const uint32_t fFlags;
94 SkFactorySet* fFactorySet; 132 SkFactorySet* fFactorySet;
95 SkWriter32 fWriter; 133 SkWriter32 fWriter;
96 134
97 SkRefCntSet* fTFSet; 135 SkRefCntSet* fTFSet;
98 136
99 SkAutoTUnref<SkPixelSerializer> fPixelSerializer; 137 SkAutoTUnref<SkPixelSerializer> fPixelSerializer;
100 138
101 // Only used if we do not have an fFactorySet 139 // Only used if we do not have an fFactorySet
102 SkTHashMap<SkString, uint32_t> fFlattenableDict; 140 SkTHashMap<SkString, uint32_t> fFlattenableDict;
103 }; 141 };
104 142
105 #endif // SkWriteBuffer_DEFINED 143 #endif // SkWriteBuffer_DEFINED
OLDNEW
« no previous file with comments | « include/core/SkBitmap.h ('k') | src/core/SkFlattenableSerialization.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698