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
|
/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkRemote_DEFINED
#define SkRemote_DEFINED
#include "SkCanvas.h"
#include "SkPaint.h"
#include "SkRemote_protocol.h"
#include "SkTHash.h"
#include "SkTypes.h"
// TODO: document
namespace SkRemote {
// TODO: document
struct Misc {
SkColor fColor;
SkFilterQuality fFilterQuality;
bool fAntiAlias, fDither;
static Misc CreateFrom(const SkPaint&);
void applyTo(SkPaint*) const;
};
// TODO: document
struct Stroke {
SkScalar fWidth, fMiter;
SkPaint::Cap fCap;
SkPaint::Join fJoin;
static Stroke CreateFrom(const SkPaint&);
void applyTo(SkPaint*) const;
};
// TODO: document
struct Encoder {
virtual ~Encoder() {}
virtual void define(ID, const SkMatrix&) = 0;
virtual void define(ID, const Misc&) = 0;
virtual void define(ID, const SkPath&) = 0;
virtual void define(ID, const Stroke&) = 0;
virtual void undefine(ID) = 0;
virtual void save() = 0;
virtual void restore() = 0;
virtual void setMatrix(ID matrix) = 0;
virtual void clipPath(ID path, SkRegion::Op, bool aa) = 0;
virtual void fillPath(ID path, ID misc) = 0;
virtual void strokePath(ID path, ID misc, ID stroke) = 0;
};
struct Cache;
// TODO: document
class LookupScope {
public:
LookupScope(Cache* cache, Encoder* encoder) : fCache(cache), fEncoder(encoder) {}
~LookupScope() { for (ID id : fToUndefine) { fEncoder->undefine(id); } }
void undefineWhenDone(ID id) { fToUndefine.push_back(id); }
template <typename T>
ID lookup(const T&);
private:
Cache* fCache;
Encoder* fEncoder;
SkSTArray<4, ID> fToUndefine;
};
// TODO: document
struct Cache {
virtual ~Cache() {}
static Cache* CreateNeverCache();
static Cache* CreateAlwaysCache();
virtual bool lookup(const SkMatrix&, ID*, LookupScope*) = 0;
virtual bool lookup(const Misc&, ID*, LookupScope*) = 0;
virtual bool lookup(const SkPath&, ID*, LookupScope*) = 0;
virtual bool lookup(const Stroke&, ID*, LookupScope*) = 0;
virtual void cleanup(Encoder*) = 0;
};
// TODO: document
class Client final : public SkCanvas {
public:
Client(Cache*, Encoder*);
~Client();
private:
void willSave() override;
void didRestore() override;
void didConcat(const SkMatrix&) override;
void didSetMatrix(const SkMatrix&) override;
void onClipPath (const SkPath&, SkRegion::Op, ClipEdgeStyle) override;
void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) override;
void onClipRect (const SkRect&, SkRegion::Op, ClipEdgeStyle) override;
void onDrawOval(const SkRect&, const SkPaint&) override;
void onDrawPath(const SkPath&, const SkPaint&) override;
void onDrawRect(const SkRect&, const SkPaint&) override;
Cache* fCache;
Encoder* fEncoder;
};
// TODO: document
class Server final : public Encoder {
public:
explicit Server(SkCanvas*);
private:
void define(ID, const SkMatrix&) override;
void define(ID, const Misc&) override;
void define(ID, const SkPath&) override;
void define(ID, const Stroke&) override;
void undefine(ID) override;
void save() override;
void restore() override;
void setMatrix(ID matrix) override;
void clipPath(ID path, SkRegion::Op, bool aa) override;
void fillPath(ID path, ID misc) override;
void strokePath(ID path, ID misc, ID stroke) override;
template <typename T, Type kType>
class IDMap {
public:
void set(const ID& id, const T& val) {
SkASSERT(id.type() == kType);
fMap.set(id, val);
}
void remove(const ID& id) {
SkASSERT(id.type() == kType);
fMap.remove(id);
}
const T& find(const ID& id) const {
SkASSERT(id.type() == kType);
T* val = fMap.find(id);
SkASSERT(val != nullptr);
return *val;
}
private:
SkTHashMap<ID, T> fMap;
};
IDMap<SkMatrix, Type::kMatrix> fMatrix;
IDMap<Misc , Type::kMisc > fMisc;
IDMap<SkPath , Type::kPath > fPath;
IDMap<Stroke , Type::kStroke> fStroke;
SkCanvas* fCanvas;
};
} // namespace SkRemote
#endif//SkRemote_DEFINED
|