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

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: Share lots more code with SkDrawCommand 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 SkBitmapHeap; 22 class SkBitmapHeap;
23 class SkFactorySet; 23 class SkFactorySet;
24 class SkFlattenable; 24 class SkFlattenable;
25 class SkRefCntSet; 25 class SkRefCntSet;
26 26
mtklein 2016/05/02 13:55:15 We might try moving this whole file to include/pri
27 class SkWriteBuffer { 27 class SkWriteBuffer {
28 public: 28 public:
29 SkWriteBuffer() {}
30 virtual ~SkWriteBuffer() {}
31
32 virtual bool isCrossProcess() const = 0;
reed1 2016/05/02 12:44:39 Can/should we consider making this non-virtual, an
mtklein 2016/05/02 13:55:15 If it's at all possible I'd prefer an interface he
reed1 2016/05/02 14:04:42 What are the advantages? I was motivated to just s
33
34 virtual void writeByteArray(const void* data, size_t size) = 0;
35 virtual void writeDataAsByteArray(SkData* data) = 0;
reed1 2016/05/02 12:44:39 does the "SkData" version need to be virtual?
mtklein 2016/05/02 13:55:15 Making these virtual gives us finer type informati
reed1 2016/05/02 14:04:42 Yea, I thought about that too, but thinking furthe
Brian Osman 2016/05/02 14:49:12 As discussed - I had split it off to capture the e
mtklein 2016/05/02 15:04:43 My preference for an interface here is mostly beca
36 virtual void writeBool(bool value) = 0;;
mtklein 2016/05/02 13:55:14 Stray ;.
37 virtual void writeScalar(SkScalar value) = 0;
38 virtual void writeScalarArray(const SkScalar* value, uint32_t count) = 0;
39 virtual void writeInt(int32_t value) = 0;
40 virtual void writeIntArray(const int32_t* value, uint32_t count) = 0;
41 virtual void writeUInt(uint32_t value) = 0;
42 virtual void write32(int32_t value) = 0;
reed1 2016/05/02 12:44:39 How is this different from writeInt? Lets either s
Brian Osman 2016/05/02 14:49:12 They appear to be totally interchangeable in their
mtklein 2016/05/02 15:04:43 Seems like another fine candidate to alias on the
43 virtual void writeString(const char* value) = 0;
44 virtual void writeEncodedString(const void* value, size_t byteLength,
reed1 2016/05/02 12:44:39 Do we use writeEncodedString?
mtklein 2016/05/02 13:55:15 No.
45 SkPaint::TextEncoding encoding) = 0;
46 virtual void writeFunctionPtr(void* ptr) = 0;
reed1 2016/05/02 12:44:39 do we still need writeFunctionPtr?
mtklein 2016/05/02 13:55:14 No. Its one use, in tests/ImageFilterTest.cpp, is
47
48 virtual void writeFlattenable(const SkFlattenable* flattenable) = 0;
49 virtual void writeColor(const SkColor& color) = 0;
reed1 2016/05/02 12:44:39 take param by value?
Brian Osman 2016/05/02 14:49:12 Sure.
mtklein 2016/05/02 15:04:43 I suspect points and rects are also faster to pass
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;
reed1 2016/05/02 12:44:39 doe writeStream need to be virtual? Doesn't it jus
mtklein 2016/05/02 13:55:15 Yes; no. If we devolve into writeByteArray(), tha
reed1 2016/05/02 14:04:42 Good point about efficiency. I wonder if that coul
mtklein 2016/05/02 15:04:42 We've got more streams than write buffers, so I th
59 virtual void writeBitmap(const SkBitmap& bitmap) = 0;
reed1 2016/05/02 12:44:39 Does writeBitmap need to be virtual? i.e. does it
mtklein 2016/05/02 13:55:15 Yes, today writeBitmap() serializes some formats a
reed1 2016/05/02 14:04:42 Yea, but that distinction seems more historical th
mtklein 2016/05/02 15:04:42 Agreed. Generally I want to always do SkImage::Ma
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:
29 enum Flags { 70 enum Flags {
30 kCrossProcess_Flag = 1 << 0, 71 kCrossProcess_Flag = 1 << 0,
31 }; 72 };
32 73
33 SkWriteBuffer(uint32_t flags = 0); 74 SkBinaryWriteBuffer(uint32_t flags = 0);
34 SkWriteBuffer(void* initialStorage, size_t storageSize, uint32_t flags = 0); 75 SkBinaryWriteBuffer(void* initialStorage, size_t storageSize, uint32_t flags = 0);
35 ~SkWriteBuffer(); 76 ~SkBinaryWriteBuffer();
36 77
37 bool isCrossProcess() const { 78 bool isCrossProcess() const override {
38 return SkToBool(fFlags & kCrossProcess_Flag); 79 return SkToBool(fFlags & kCrossProcess_Flag);
39 } 80 }
40 81
41 SkWriter32* getWriter32() { return &fWriter; } 82 SkWriter32* getWriter32() { return &fWriter; }
42 void reset(void* storage = NULL, size_t storageSize = 0) { 83 void reset(void* storage = NULL, size_t storageSize = 0) {
43 fWriter.reset(storage, storageSize); 84 fWriter.reset(storage, storageSize);
44 } 85 }
45 86
46 size_t bytesWritten() const { return fWriter.bytesWritten(); } 87 size_t bytesWritten() const { return fWriter.bytesWritten(); }
47 88
48 void writeByteArray(const void* data, size_t size); 89 void writeByteArray(const void* data, size_t size) override;
49 void writeDataAsByteArray(SkData* data) { this->writeByteArray(data->data(), data->size()); } 90 void writeDataAsByteArray(SkData* data) override;
50 void writeBool(bool value); 91 void writeBool(bool value) override;
51 void writeScalar(SkScalar value); 92 void writeScalar(SkScalar value) override;
52 void writeScalarArray(const SkScalar* value, uint32_t count); 93 void writeScalarArray(const SkScalar* value, uint32_t count) override;
53 void writeInt(int32_t value); 94 void writeInt(int32_t value) override;
54 void writeIntArray(const int32_t* value, uint32_t count); 95 void writeIntArray(const int32_t* value, uint32_t count) override;
55 void writeUInt(uint32_t value); 96 void writeUInt(uint32_t value) override;
56 void write32(int32_t value); 97 void write32(int32_t value) override;
57 void writeString(const char* value); 98 void writeString(const char* value) override;
58 void writeEncodedString(const void* value, size_t byteLength, SkPaint::TextE ncoding encoding); 99 void writeEncodedString(const void* value, size_t byteLength,
59 void writeFunctionPtr(void* ptr) { fWriter.writePtr(ptr); } 100 SkPaint::TextEncoding encoding) override;
101 void writeFunctionPtr(void* ptr) override;
60 102
61 void writeFlattenable(const SkFlattenable* flattenable); 103 void writeFlattenable(const SkFlattenable* flattenable) override;
62 void writeColor(const SkColor& color); 104 void writeColor(const SkColor& color) override;
63 void writeColorArray(const SkColor* color, uint32_t count); 105 void writeColorArray(const SkColor* color, uint32_t count) override;
64 void writePoint(const SkPoint& point); 106 void writePoint(const SkPoint& point) override;
65 void writePointArray(const SkPoint* point, uint32_t count); 107 void writePointArray(const SkPoint* point, uint32_t count) override;
66 void writeMatrix(const SkMatrix& matrix); 108 void writeMatrix(const SkMatrix& matrix) override;
67 void writeIRect(const SkIRect& rect); 109 void writeIRect(const SkIRect& rect) override;
68 void writeRect(const SkRect& rect); 110 void writeRect(const SkRect& rect) override;
69 void writeRegion(const SkRegion& region); 111 void writeRegion(const SkRegion& region) override;
70 void writePath(const SkPath& path); 112 void writePath(const SkPath& path) override;
71 size_t writeStream(SkStream* stream, size_t length); 113 size_t writeStream(SkStream* stream, size_t length) override;
72 void writeBitmap(const SkBitmap& bitmap); 114 void writeBitmap(const SkBitmap& bitmap) override;
73 void writeImage(const SkImage*); 115 void writeImage(const SkImage*) override;
74 void writeTypeface(SkTypeface* typeface); 116 void writeTypeface(SkTypeface* typeface) override;
75 void writePaint(const SkPaint& paint) { paint.flatten(*this); } 117 void writePaint(const SkPaint& paint) override;
76 118
77 bool writeToStream(SkWStream*); 119 bool writeToStream(SkWStream*);
78 void writeToMemory(void* dst) { fWriter.flatten(dst); } 120 void writeToMemory(void* dst) { fWriter.flatten(dst); }
79 121
80 SkFactorySet* setFactoryRecorder(SkFactorySet*); 122 SkFactorySet* setFactoryRecorder(SkFactorySet*);
81
82 SkRefCntSet* getTypefaceRecorder() const { return fTFSet; }
83 SkRefCntSet* setTypefaceRecorder(SkRefCntSet*); 123 SkRefCntSet* setTypefaceRecorder(SkRefCntSet*);
84 124
85 /** 125 /**
86 * Set an SkBitmapHeap to store bitmaps rather than flattening. 126 * Set an SkBitmapHeap to store bitmaps rather than flattening.
87 * 127 *
88 * Incompatible with an SkPixelSerializer. If an SkPixelSerializer is set, 128 * Incompatible with an SkPixelSerializer. If an SkPixelSerializer is set,
89 * setting an SkBitmapHeap will set the SkPixelSerializer to NULL in release 129 * setting an SkBitmapHeap will set the SkPixelSerializer to NULL in release
90 * and crash in debug. 130 * and crash in debug.
91 */ 131 */
92 void setBitmapHeap(SkBitmapHeap*); 132 void setBitmapHeap(SkBitmapHeap*);
(...skipping 20 matching lines...) Expand all
113 SkBitmapHeap* fBitmapHeap; 153 SkBitmapHeap* fBitmapHeap;
114 SkRefCntSet* fTFSet; 154 SkRefCntSet* fTFSet;
115 155
116 SkAutoTUnref<SkPixelSerializer> fPixelSerializer; 156 SkAutoTUnref<SkPixelSerializer> fPixelSerializer;
117 157
118 // Only used if we do not have an fFactorySet 158 // Only used if we do not have an fFactorySet
119 SkTHashMap<SkString, uint32_t> fFlattenableDict; 159 SkTHashMap<SkString, uint32_t> fFlattenableDict;
120 }; 160 };
121 161
122 #endif // SkWriteBuffer_DEFINED 162 #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