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

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

Issue 1412223002: SkRemote: add xfermodes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 5 years, 2 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 | « no previous file | src/core/SkRemote.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 * 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
(...skipping 27 matching lines...) Expand all
38 }; 38 };
39 39
40 // TODO: document 40 // TODO: document
41 struct Encoder { 41 struct Encoder {
42 virtual ~Encoder() {} 42 virtual ~Encoder() {}
43 43
44 virtual void define(ID, const SkMatrix&) = 0; 44 virtual void define(ID, const SkMatrix&) = 0;
45 virtual void define(ID, const Misc&) = 0; 45 virtual void define(ID, const Misc&) = 0;
46 virtual void define(ID, const SkPath&) = 0; 46 virtual void define(ID, const SkPath&) = 0;
47 virtual void define(ID, const Stroke&) = 0; 47 virtual void define(ID, const Stroke&) = 0;
48 virtual void define(ID, SkXfermode*) = 0;
48 49
49 virtual void undefine(ID) = 0; 50 virtual void undefine(ID) = 0;
50 51
51 virtual void save() = 0; 52 virtual void save() = 0;
52 virtual void restore() = 0; 53 virtual void restore() = 0;
53 54
54 virtual void setMatrix(ID matrix) = 0; 55 virtual void setMatrix(ID matrix) = 0;
55 56
56 virtual void clipPath(ID path, SkRegion::Op, bool aa) = 0; 57 // TODO: struct CommonIDs { ID misc; ID xfermode; ... }
57 virtual void fillPath(ID path, ID misc) = 0; 58 // for IDs that affect both fill + stroke?
58 virtual void strokePath(ID path, ID misc, ID stroke) = 0; 59
60 virtual void clipPath(ID path, SkRegion::Op, bool aa) = 0;
61 virtual void fillPath(ID path, ID misc, ID xfermode) = 0;
62 virtual void strokePath(ID path, ID misc, ID xfermode, ID stroke) = 0;
59 }; 63 };
60 64
61 class LookupScope; 65 class LookupScope;
62 66
63 // TODO: document 67 // The Cache interface encapsulates the caching logic of the Client.
68 //
69 // Each lookup() method must always fill ID* with a valid value,
70 // but ID may be cached. If so, the lookup() method returns true;
71 // if not the lookup() method returns false and the Client must
72 // then define() this ID -> Thing mapping before using the ID.
73 //
74 // The Caches may also add IDs to the LookupScope's list of IDs to
75 // undefine() on destruction. This lets the Cache purge IDs.
64 struct Cache { 76 struct Cache {
65 virtual ~Cache() {} 77 virtual ~Cache() {}
66 78
67 static Cache* CreateNeverCache(); 79 static Cache* CreateNeverCache(); // Never caches anything.
68 static Cache* CreateAlwaysCache(); 80 static Cache* CreateAlwaysCache(); // Caches by value (not deep pointer equality).
81 // TODO: static Cache* CreateDeepCache(); // Caches by deep value.
69 82
70 virtual bool lookup(const SkMatrix&, ID*, LookupScope*) = 0; 83 virtual bool lookup(const SkMatrix&, ID*, LookupScope*) = 0;
71 virtual bool lookup(const Misc&, ID*, LookupScope*) = 0; 84 virtual bool lookup(const Misc&, ID*, LookupScope*) = 0;
72 virtual bool lookup(const SkPath&, ID*, LookupScope*) = 0; 85 virtual bool lookup(const SkPath&, ID*, LookupScope*) = 0;
73 virtual bool lookup(const Stroke&, ID*, LookupScope*) = 0; 86 virtual bool lookup(const Stroke&, ID*, LookupScope*) = 0;
87 virtual bool lookup(const SkXfermode*, ID*, LookupScope*) = 0;
74 88
75 virtual void cleanup(Encoder*) = 0; 89 virtual void cleanup(Encoder*) = 0;
76 }; 90 };
77 91
78 // TODO: document 92 // TODO: document
79 class Client final : public SkCanvas { 93 class Client final : public SkCanvas {
80 public: 94 public:
81 Client(Cache*, Encoder*); 95 Client(Cache*, Encoder*);
82 ~Client(); 96 ~Client();
83 97
(...skipping 29 matching lines...) Expand all
113 // TODO: document 127 // TODO: document
114 class Server final : public Encoder { 128 class Server final : public Encoder {
115 public: 129 public:
116 explicit Server(SkCanvas*); 130 explicit Server(SkCanvas*);
117 131
118 private: 132 private:
119 void define(ID, const SkMatrix&) override; 133 void define(ID, const SkMatrix&) override;
120 void define(ID, const Misc&) override; 134 void define(ID, const Misc&) override;
121 void define(ID, const SkPath&) override; 135 void define(ID, const SkPath&) override;
122 void define(ID, const Stroke&) override; 136 void define(ID, const Stroke&) override;
137 void define(ID, SkXfermode*) override;
123 138
124 void undefine(ID) override; 139 void undefine(ID) override;
125 140
126 void save() override; 141 void save() override;
127 void restore() override; 142 void restore() override;
128 143
129 void setMatrix(ID matrix) override; 144 void setMatrix(ID matrix) override;
130 145
131 void clipPath(ID path, SkRegion::Op, bool aa) override; 146 void clipPath(ID path, SkRegion::Op, bool aa) override;
132 void fillPath(ID path, ID misc) override; 147 void fillPath(ID path, ID misc, ID xfermode) override;
133 void strokePath(ID path, ID misc, ID stroke) override; 148 void strokePath(ID path, ID misc, ID xfermode, ID stroke) override;
134 149
150 // Maps ID -> T.
135 template <typename T, Type kType> 151 template <typename T, Type kType>
136 class IDMap { 152 class IDMap {
137 public: 153 public:
154 ~IDMap() {
155 // A well-behaved client always cleans up its definitions.
156 SkASSERT(fMap.count() == 0);
157 }
158
138 void set(const ID& id, const T& val) { 159 void set(const ID& id, const T& val) {
139 SkASSERT(id.type() == kType); 160 SkASSERT(id.type() == kType);
140 fMap.set(id, val); 161 fMap.set(id, val);
141 } 162 }
142 163
143 void remove(const ID& id) { 164 void remove(const ID& id) {
144 SkASSERT(id.type() == kType); 165 SkASSERT(id.type() == kType);
145 fMap.remove(id); 166 fMap.remove(id);
146 } 167 }
147 168
148 const T& find(const ID& id) const { 169 const T& find(const ID& id) const {
149 SkASSERT(id.type() == kType); 170 SkASSERT(id.type() == kType);
150 T* val = fMap.find(id); 171 T* val = fMap.find(id);
151 SkASSERT(val != nullptr); 172 SkASSERT(val != nullptr);
152 return *val; 173 return *val;
153 } 174 }
154 175
155 private: 176 private:
156 SkTHashMap<ID, T> fMap; 177 SkTHashMap<ID, T> fMap;
157 }; 178 };
158 179
159 IDMap<SkMatrix, Type::kMatrix> fMatrix; 180 // Maps ID -> T*, and keeps the T alive by reffing it.
160 IDMap<Misc , Type::kMisc > fMisc; 181 template <typename T, Type kType>
161 IDMap<SkPath , Type::kPath > fPath; 182 class ReffedIDMap {
162 IDMap<Stroke , Type::kStroke> fStroke; 183 public:
184 ReffedIDMap() {
185 // A null ID always maps to nullptr.
186 fMap.set(ID(kType), nullptr);
187 }
188 ~ReffedIDMap() {
189 // A well-behaved client always cleans up its definitions.
190 SkASSERT(fMap.count() == 1);
191 }
192
193 void set(const ID& id, T* val) {
194 SkASSERT(id.type() == kType && val);
195 fMap.set(id, SkRef(val));
196 }
197
198 void remove(const ID& id) {
199 SkASSERT(id.type() == kType);
200 T** val = fMap.find(id);
201 SkASSERT(val && *val);
202 (*val)->unref();
203 fMap.remove(id);
204 }
205
206 T* find(const ID& id) const {
207 SkASSERT(id.type() == kType);
208 T** val = fMap.find(id);
209 SkASSERT(val);
210 return *val;
211 }
212
213 private:
214 SkTHashMap<ID, T*> fMap;
215 };
216
217 IDMap<SkMatrix, Type::kMatrix> fMatrix;
218 IDMap<Misc , Type::kMisc > fMisc;
219 IDMap<SkPath , Type::kPath > fPath;
220 IDMap<Stroke , Type::kStroke> fStroke;
221 ReffedIDMap<SkXfermode, Type::kXfermode> fXfermode;
163 222
164 SkCanvas* fCanvas; 223 SkCanvas* fCanvas;
165 }; 224 };
166 225
167 } // namespace SkRemote 226 } // namespace SkRemote
168 227
169 #endif//SkRemote_DEFINED 228 #endif//SkRemote_DEFINED
OLDNEW
« no previous file with comments | « no previous file | src/core/SkRemote.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698