OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkRemote_DEFINED | 8 #ifndef SkRemote_DEFINED |
9 #define SkRemote_DEFINED | 9 #define SkRemote_DEFINED |
10 | 10 |
11 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
12 #include "SkPaint.h" | 12 #include "SkPaint.h" |
13 #include "SkRemote_protocol.h" | 13 #include "SkRemote_protocol.h" |
| 14 #include "SkShader.h" |
14 #include "SkTHash.h" | 15 #include "SkTHash.h" |
15 #include "SkTypes.h" | 16 #include "SkTypes.h" |
16 | 17 |
17 // TODO: document | 18 // TODO: document |
18 | 19 |
19 namespace SkRemote { | 20 namespace SkRemote { |
20 // TODO: document | 21 // TODO: document |
21 struct Misc { | 22 struct Misc { |
22 SkColor fColor; | 23 SkColor fColor; |
23 SkFilterQuality fFilterQuality; | 24 SkFilterQuality fFilterQuality; |
(...skipping 14 matching lines...) Expand all Loading... |
38 }; | 39 }; |
39 | 40 |
40 // TODO: document | 41 // TODO: document |
41 struct Encoder { | 42 struct Encoder { |
42 virtual ~Encoder() {} | 43 virtual ~Encoder() {} |
43 | 44 |
44 virtual void define(ID, const SkMatrix&) = 0; | 45 virtual void define(ID, const SkMatrix&) = 0; |
45 virtual void define(ID, const Misc&) = 0; | 46 virtual void define(ID, const Misc&) = 0; |
46 virtual void define(ID, const SkPath&) = 0; | 47 virtual void define(ID, const SkPath&) = 0; |
47 virtual void define(ID, const Stroke&) = 0; | 48 virtual void define(ID, const Stroke&) = 0; |
| 49 virtual void define(ID, SkShader*) = 0; |
48 virtual void define(ID, SkXfermode*) = 0; | 50 virtual void define(ID, SkXfermode*) = 0; |
49 | 51 |
50 virtual void undefine(ID) = 0; | 52 virtual void undefine(ID) = 0; |
51 | 53 |
52 virtual void save() = 0; | 54 virtual void save() = 0; |
53 virtual void restore() = 0; | 55 virtual void restore() = 0; |
54 | 56 |
55 virtual void setMatrix(ID matrix) = 0; | 57 virtual void setMatrix(ID matrix) = 0; |
56 | 58 |
57 // TODO: struct CommonIDs { ID misc; ID xfermode; ... } | 59 // TODO: struct CommonIDs { ID misc, shader, xfermode; ... } |
58 // for IDs that affect both fill + stroke? | 60 // for IDs that affect both fill + stroke? |
59 | 61 |
60 virtual void clipPath(ID path, SkRegion::Op, bool aa) = 0; | 62 virtual void clipPath(ID path, SkRegion::Op, bool aa)
= 0; |
61 virtual void fillPath(ID path, ID misc, ID xfermode) = 0; | 63 virtual void fillPath(ID path, ID misc, ID shader, ID xfermode)
= 0; |
62 virtual void strokePath(ID path, ID misc, ID xfermode, ID stroke) = 0; | 64 virtual void strokePath(ID path, ID misc, ID shader, ID xfermode, ID str
oke) = 0; |
63 }; | 65 }; |
64 | 66 |
65 class LookupScope; | 67 class LookupScope; |
66 | 68 |
67 // The Cache interface encapsulates the caching logic of the Client. | 69 // The Cache interface encapsulates the caching logic of the Client. |
68 // | 70 // |
69 // Each lookup() method must always fill ID* with a valid value, | 71 // Each lookup() method must always fill ID* with a valid value, |
70 // but ID may be cached. If so, the lookup() method returns true; | 72 // but ID may be cached. If so, the lookup() method returns true; |
71 // if not the lookup() method returns false and the Client must | 73 // if not the lookup() method returns false and the Client must |
72 // then define() this ID -> Thing mapping before using the ID. | 74 // then define() this ID -> Thing mapping before using the ID. |
73 // | 75 // |
74 // The Caches may also add IDs to the LookupScope's list of IDs to | 76 // The Caches may also add IDs to the LookupScope's list of IDs to |
75 // undefine() on destruction. This lets the Cache purge IDs. | 77 // undefine() on destruction. This lets the Cache purge IDs. |
76 struct Cache { | 78 struct Cache { |
77 virtual ~Cache() {} | 79 virtual ~Cache() {} |
78 | 80 |
79 static Cache* CreateNeverCache(); // Never caches anything. | 81 static Cache* CreateNeverCache(); // Never caches anything. |
80 static Cache* CreateAlwaysCache(); // Caches by value (not deep pointer
equality). | 82 static Cache* CreateAlwaysCache(); // Caches by value (not deep pointer
equality). |
81 // TODO: static Cache* CreateDeepCache(); // Caches by deep value. | 83 // TODO: static Cache* CreateDeepCache(); // Caches by deep value. |
82 | 84 |
83 virtual bool lookup(const SkMatrix&, ID*, LookupScope*) = 0; | 85 virtual bool lookup(const SkMatrix&, ID*, LookupScope*) = 0; |
84 virtual bool lookup(const Misc&, ID*, LookupScope*) = 0; | 86 virtual bool lookup(const Misc&, ID*, LookupScope*) = 0; |
85 virtual bool lookup(const SkPath&, ID*, LookupScope*) = 0; | 87 virtual bool lookup(const SkPath&, ID*, LookupScope*) = 0; |
86 virtual bool lookup(const Stroke&, ID*, LookupScope*) = 0; | 88 virtual bool lookup(const Stroke&, ID*, LookupScope*) = 0; |
| 89 virtual bool lookup(const SkShader*, ID*, LookupScope*) = 0; |
87 virtual bool lookup(const SkXfermode*, ID*, LookupScope*) = 0; | 90 virtual bool lookup(const SkXfermode*, ID*, LookupScope*) = 0; |
88 | 91 |
89 virtual void cleanup(Encoder*) = 0; | 92 virtual void cleanup(Encoder*) = 0; |
90 }; | 93 }; |
91 | 94 |
92 // TODO: document | 95 // TODO: document |
93 class Client final : public SkCanvas { | 96 class Client final : public SkCanvas { |
94 public: | 97 public: |
95 Client(Cache*, Encoder*); | 98 Client(Cache*, Encoder*); |
96 ~Client(); | 99 ~Client(); |
(...skipping 30 matching lines...) Expand all Loading... |
127 // TODO: document | 130 // TODO: document |
128 class Server final : public Encoder { | 131 class Server final : public Encoder { |
129 public: | 132 public: |
130 explicit Server(SkCanvas*); | 133 explicit Server(SkCanvas*); |
131 | 134 |
132 private: | 135 private: |
133 void define(ID, const SkMatrix&) override; | 136 void define(ID, const SkMatrix&) override; |
134 void define(ID, const Misc&) override; | 137 void define(ID, const Misc&) override; |
135 void define(ID, const SkPath&) override; | 138 void define(ID, const SkPath&) override; |
136 void define(ID, const Stroke&) override; | 139 void define(ID, const Stroke&) override; |
| 140 void define(ID, SkShader*) override; |
137 void define(ID, SkXfermode*) override; | 141 void define(ID, SkXfermode*) override; |
138 | 142 |
139 void undefine(ID) override; | 143 void undefine(ID) override; |
140 | 144 |
141 void save() override; | 145 void save() override; |
142 void restore() override; | 146 void restore() override; |
143 | 147 |
144 void setMatrix(ID matrix) override; | 148 void setMatrix(ID matrix) override; |
145 | 149 |
146 void clipPath(ID path, SkRegion::Op, bool aa) override; | 150 void clipPath(ID path, SkRegion::Op, bool aa) ove
rride; |
147 void fillPath(ID path, ID misc, ID xfermode) override; | 151 void fillPath(ID path, ID misc, ID shader, ID xfermode) ove
rride; |
148 void strokePath(ID path, ID misc, ID xfermode, ID stroke) override; | 152 void strokePath(ID path, ID misc, ID shader, ID xfermode, ID stroke) ove
rride; |
149 | 153 |
150 // Maps ID -> T. | 154 // Maps ID -> T. |
151 template <typename T, Type kType> | 155 template <typename T, Type kType> |
152 class IDMap { | 156 class IDMap { |
153 public: | 157 public: |
154 ~IDMap() { | 158 ~IDMap() { |
155 // A well-behaved client always cleans up its definitions. | 159 // A well-behaved client always cleans up its definitions. |
156 SkASSERT(fMap.count() == 0); | 160 SkASSERT(fMap.count() == 0); |
157 } | 161 } |
158 | 162 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 } | 215 } |
212 | 216 |
213 private: | 217 private: |
214 SkTHashMap<ID, T*> fMap; | 218 SkTHashMap<ID, T*> fMap; |
215 }; | 219 }; |
216 | 220 |
217 IDMap<SkMatrix, Type::kMatrix> fMatrix; | 221 IDMap<SkMatrix, Type::kMatrix> fMatrix; |
218 IDMap<Misc , Type::kMisc > fMisc; | 222 IDMap<Misc , Type::kMisc > fMisc; |
219 IDMap<SkPath , Type::kPath > fPath; | 223 IDMap<SkPath , Type::kPath > fPath; |
220 IDMap<Stroke , Type::kStroke> fStroke; | 224 IDMap<Stroke , Type::kStroke> fStroke; |
| 225 ReffedIDMap<SkShader, Type::kShader> fShader; |
221 ReffedIDMap<SkXfermode, Type::kXfermode> fXfermode; | 226 ReffedIDMap<SkXfermode, Type::kXfermode> fXfermode; |
222 | 227 |
223 SkCanvas* fCanvas; | 228 SkCanvas* fCanvas; |
224 }; | 229 }; |
225 | 230 |
226 } // namespace SkRemote | 231 } // namespace SkRemote |
227 | 232 |
228 #endif//SkRemote_DEFINED | 233 #endif//SkRemote_DEFINED |
OLD | NEW |