forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaint_op_reader.h
205 lines (182 loc) · 7.09 KB
/
paint_op_reader.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CC_PAINT_PAINT_OP_READER_H_
#define CC_PAINT_PAINT_OP_READER_H_
#include <vector>
#include "cc/paint/paint_export.h"
#include "cc/paint/paint_filter.h"
#include "cc/paint/paint_op_writer.h"
#include "cc/paint/transfer_cache_deserialize_helper.h"
namespace cc {
class PaintShader;
// PaintOpReader takes garbage |memory| and clobbers it with successive
// read functions.
class TransferCacheDeserializeHelper;
class CC_PAINT_EXPORT PaintOpReader {
public:
PaintOpReader(const volatile void* memory,
size_t size,
TransferCacheDeserializeHelper* transfer_cache,
bool enable_security_constraints = false)
: memory_(static_cast<const volatile char*>(memory) +
PaintOpWriter::HeaderBytes()),
remaining_bytes_(size - PaintOpWriter::HeaderBytes()),
transfer_cache_(transfer_cache),
enable_security_constraints_(enable_security_constraints) {
if (size < PaintOpWriter::HeaderBytes())
valid_ = false;
}
static void FixupMatrixPostSerialization(SkMatrix* matrix);
static bool ReadAndValidateOpHeader(const volatile void* input,
size_t input_size,
uint8_t* type,
uint32_t* skip);
bool valid() const { return valid_; }
size_t remaining_bytes() const { return remaining_bytes_; }
void ReadData(size_t bytes, void* data);
void ReadArray(size_t count, SkPoint* array);
void ReadSize(size_t* size);
void Read(SkScalar* data);
void Read(uint8_t* data);
void Read(uint32_t* data);
void Read(uint64_t* data);
void Read(int32_t* data);
void Read(SkRect* rect);
void Read(SkIRect* rect);
void Read(SkRRect* rect);
void Read(SkPath* path);
void Read(PaintFlags* flags);
void Read(PaintImage* image);
void Read(sk_sp<SkData>* data);
void Read(scoped_refptr<PaintTextBlob>* blob);
void Read(sk_sp<PaintFilter>* filter);
void Read(sk_sp<PaintShader>* shader);
void Read(SkMatrix* matrix);
void Read(SkColorType* color_type);
void Read(SkImageInfo* info);
void Read(sk_sp<SkColorSpace>* color_space);
void Read(SkClipOp* op) {
uint8_t value = 0u;
Read(&value);
*op = static_cast<SkClipOp>(value);
}
void Read(PaintCanvas::AnnotationType* type) {
uint8_t value = 0u;
Read(&value);
*type = static_cast<PaintCanvas::AnnotationType>(value);
}
void Read(PaintCanvas::SrcRectConstraint* constraint) {
uint8_t value = 0u;
Read(&value);
*constraint = static_cast<PaintCanvas::SrcRectConstraint>(value);
}
void Read(SkFilterQuality* quality) {
uint8_t value = 0u;
Read(&value);
if (value > static_cast<uint8_t>(kLast_SkFilterQuality)) {
SetInvalid();
return;
}
*quality = static_cast<SkFilterQuality>(value);
}
void Read(bool* data) {
uint8_t value = 0u;
Read(&value);
*data = !!value;
}
// Returns a pointer to the next block of memory of size |bytes|, and treats
// this memory as read (advancing the reader). Returns nullptr if |bytes|
// would exceed the available budfer.
const volatile void* ExtractReadableMemory(size_t bytes);
// Aligns the memory to the given alignment.
void AlignMemory(size_t alignment);
private:
template <typename T>
void ReadSimple(T* val);
template <typename T>
void ReadFlattenable(sk_sp<T>* val);
void SetInvalid();
// The main entry point is Read(sk_sp<PaintFilter>* filter) which calls one of
// the following functions depending on read type.
void ReadColorFilterPaintFilter(
sk_sp<PaintFilter>* filter,
const base::Optional<PaintFilter::CropRect>& crop_rect);
void ReadBlurPaintFilter(
sk_sp<PaintFilter>* filter,
const base::Optional<PaintFilter::CropRect>& crop_rect);
void ReadDropShadowPaintFilter(
sk_sp<PaintFilter>* filter,
const base::Optional<PaintFilter::CropRect>& crop_rect);
void ReadMagnifierPaintFilter(
sk_sp<PaintFilter>* filter,
const base::Optional<PaintFilter::CropRect>& crop_rect);
void ReadComposePaintFilter(
sk_sp<PaintFilter>* filter,
const base::Optional<PaintFilter::CropRect>& crop_rect);
void ReadAlphaThresholdPaintFilter(
sk_sp<PaintFilter>* filter,
const base::Optional<PaintFilter::CropRect>& crop_rect);
void ReadXfermodePaintFilter(
sk_sp<PaintFilter>* filter,
const base::Optional<PaintFilter::CropRect>& crop_rect);
void ReadArithmeticPaintFilter(
sk_sp<PaintFilter>* filter,
const base::Optional<PaintFilter::CropRect>& crop_rect);
void ReadMatrixConvolutionPaintFilter(
sk_sp<PaintFilter>* filter,
const base::Optional<PaintFilter::CropRect>& crop_rect);
void ReadDisplacementMapEffectPaintFilter(
sk_sp<PaintFilter>* filter,
const base::Optional<PaintFilter::CropRect>& crop_rect);
void ReadImagePaintFilter(
sk_sp<PaintFilter>* filter,
const base::Optional<PaintFilter::CropRect>& crop_rect);
void ReadRecordPaintFilter(
sk_sp<PaintFilter>* filter,
const base::Optional<PaintFilter::CropRect>& crop_rect);
void ReadMergePaintFilter(
sk_sp<PaintFilter>* filter,
const base::Optional<PaintFilter::CropRect>& crop_rect);
void ReadMorphologyPaintFilter(
sk_sp<PaintFilter>* filter,
const base::Optional<PaintFilter::CropRect>& crop_rect);
void ReadOffsetPaintFilter(
sk_sp<PaintFilter>* filter,
const base::Optional<PaintFilter::CropRect>& crop_rect);
void ReadTilePaintFilter(
sk_sp<PaintFilter>* filter,
const base::Optional<PaintFilter::CropRect>& crop_rect);
void ReadTurbulencePaintFilter(
sk_sp<PaintFilter>* filter,
const base::Optional<PaintFilter::CropRect>& crop_rect);
void ReadPaintFlagsPaintFilter(
sk_sp<PaintFilter>* filter,
const base::Optional<PaintFilter::CropRect>& crop_rect);
void ReadMatrixPaintFilter(
sk_sp<PaintFilter>* filter,
const base::Optional<PaintFilter::CropRect>& crop_rect);
void ReadLightingDistantPaintFilter(
sk_sp<PaintFilter>* filter,
const base::Optional<PaintFilter::CropRect>& crop_rect);
void ReadLightingPointPaintFilter(
sk_sp<PaintFilter>* filter,
const base::Optional<PaintFilter::CropRect>& crop_rect);
void ReadLightingSpotPaintFilter(
sk_sp<PaintFilter>* filter,
const base::Optional<PaintFilter::CropRect>& crop_rect);
void Read(sk_sp<PaintRecord>* record);
void Read(SkRegion* region);
const volatile char* memory_ = nullptr;
size_t remaining_bytes_ = 0u;
bool valid_ = true;
TransferCacheDeserializeHelper* transfer_cache_;
// Indicates that the data was serialized with the following constraints:
// 1) PaintRecords and SkDrawLoopers are ignored.
// 2) Images are decoded and only the bitmap is serialized.
// If set to true, the above constraints are validated during deserialization
// and the data types specified above are ignored.
const bool enable_security_constraints_;
};
} // namespace cc
#endif // CC_PAINT_PAINT_OP_READER_H_