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

Side by Side Diff: src/core/SkOrderedWriteBuffer.h

Issue 134163010: Refactor read and write buffers. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: original write flags were fine Created 6 years, 10 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
OLDNEW
(Empty)
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
12 #include "SkFlattenableBuffers.h"
13
14 #include "SkRefCnt.h"
15 #include "SkBitmapHeap.h"
16 #include "SkPath.h"
17 #include "SkPicture.h"
18 #include "SkWriter32.h"
19
20 class SkBitmap;
21 class SkFlattenable;
22 class SkFactorySet;
23 class SkNamedFactorySet;
24 class SkRefCntSet;
25
26 class SkOrderedWriteBuffer : public SkFlattenableWriteBuffer {
27 public:
28 SkOrderedWriteBuffer();
29 SkOrderedWriteBuffer(void* initialStorage, size_t storageSize);
30 virtual ~SkOrderedWriteBuffer();
31
32 virtual bool isOrderedBinaryBuffer() SK_OVERRIDE { return true; }
33 virtual SkOrderedWriteBuffer* getOrderedBinaryBuffer() SK_OVERRIDE { return this; }
34
35 SkWriter32* getWriter32() { return &fWriter; }
36 void reset(void* storage = NULL, size_t storageSize = 0) {
37 fWriter.reset(storage, storageSize);
38 }
39
40 void writeToMemory(void* dst) { fWriter.flatten(dst); }
41 uint32_t* reserve(size_t size) { return fWriter.reserve(size); }
42
43 size_t bytesWritten() const { return fWriter.bytesWritten(); }
44 // Deprecated. Please call bytesWritten instead. TODO(mtklein): clean up
45 size_t size() const { return this->bytesWritten(); }
46
47 virtual void writeByteArray(const void* data, size_t size) SK_OVERRIDE;
48 virtual void writeBool(bool value) SK_OVERRIDE;
49 virtual void writeFixed(SkFixed value) SK_OVERRIDE;
50 virtual void writeScalar(SkScalar value) SK_OVERRIDE;
51 virtual void writeScalarArray(const SkScalar* value, uint32_t count) SK_OVER RIDE;
52 virtual void writeInt(int32_t value) SK_OVERRIDE;
53 virtual void writeIntArray(const int32_t* value, uint32_t count) SK_OVERRIDE ;
54 virtual void writeUInt(uint32_t value) SK_OVERRIDE;
55 virtual void write32(int32_t value) SK_OVERRIDE;
56 virtual void writeString(const char* value) SK_OVERRIDE;
57 virtual void writeEncodedString(const void* value, size_t byteLength,
58 SkPaint::TextEncoding encoding) SK_OVERRIDE;
59
60 virtual void writeFlattenable(const SkFlattenable* flattenable) SK_OVERRIDE;
61 virtual void writeColor(const SkColor& color) SK_OVERRIDE;
62 virtual void writeColorArray(const SkColor* color, uint32_t count) SK_OVERRI DE;
63 virtual void writePoint(const SkPoint& point) SK_OVERRIDE;
64 virtual void writePointArray(const SkPoint* point, uint32_t count) SK_OVERRI DE;
65 virtual void writeMatrix(const SkMatrix& matrix) SK_OVERRIDE;
66 virtual void writeIRect(const SkIRect& rect)SK_OVERRIDE;
67 virtual void writeRect(const SkRect& rect) SK_OVERRIDE;
68 virtual void writeRegion(const SkRegion& region) SK_OVERRIDE;
69 virtual void writePath(const SkPath& path) SK_OVERRIDE;
70 virtual size_t writeStream(SkStream* stream, size_t length) SK_OVERRIDE;
71
72 virtual void writeBitmap(const SkBitmap& bitmap) SK_OVERRIDE;
73 virtual void writeTypeface(SkTypeface* typeface) SK_OVERRIDE;
74
75 virtual bool writeToStream(SkWStream*) SK_OVERRIDE;
76
77 SkFactorySet* setFactoryRecorder(SkFactorySet*);
78 SkNamedFactorySet* setNamedFactoryRecorder(SkNamedFactorySet*);
79
80 SkRefCntSet* getTypefaceRecorder() const { return fTFSet; }
81 SkRefCntSet* setTypefaceRecorder(SkRefCntSet*);
82
83 /**
84 * Set an SkBitmapHeap to store bitmaps rather than flattening.
85 *
86 * Incompatible with an EncodeBitmap function. If an EncodeBitmap function i s set, setting an
87 * SkBitmapHeap will set the function to NULL in release mode and crash in d ebug.
88 */
89 void setBitmapHeap(SkBitmapHeap*);
90
91 /**
92 * Provide a function to encode an SkBitmap to an SkData. writeBitmap will a ttempt to use
93 * bitmapEncoder to store the SkBitmap. If the reader does not provide a fun ction to decode, it
94 * will not be able to restore SkBitmaps, but will still be able to read the rest of the stream.
95 * bitmapEncoder will never be called with a NULL pixelRefOffset.
96 *
97 * Incompatible with the SkBitmapHeap. If an encoder is set fBitmapHeap will be set to NULL in
98 * release and crash in debug.
99 */
100 void setBitmapEncoder(SkPicture::EncodeBitmap bitmapEncoder);
101
102 private:
103 SkFactorySet* fFactorySet;
104 SkNamedFactorySet* fNamedFactorySet;
105 SkWriter32 fWriter;
106
107 SkBitmapHeap* fBitmapHeap;
108 SkRefCntSet* fTFSet;
109
110 SkPicture::EncodeBitmap fBitmapEncoder;
111
112 typedef SkFlattenableWriteBuffer INHERITED;
113 };
114
115 #endif // SkOrderedWriteBuffer_DEFINED
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698