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

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

Issue 1409273002: LookupScope does not need to be in SkRemote.h (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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 | « src/core/SkRemote.h ('k') | no next file » | 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 #include "SkPath.h" 8 #include "SkPath.h"
9 #include "SkRect.h" 9 #include "SkRect.h"
10 #include "SkRemote.h" 10 #include "SkRemote.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 54
55 static bool operator==(const Stroke& a, const Stroke& b) { 55 static bool operator==(const Stroke& a, const Stroke& b) {
56 return a.fWidth == b.fWidth 56 return a.fWidth == b.fWidth
57 && a.fMiter == b.fMiter 57 && a.fMiter == b.fMiter
58 && a.fCap == b.fCap 58 && a.fCap == b.fCap
59 && a.fJoin == b.fJoin; 59 && a.fJoin == b.fJoin;
60 } 60 }
61 61
62 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // 62 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
63 63
64 class LookupScope {
65 public:
66 LookupScope(Cache* cache, Encoder* encoder) : fCache(cache), fEncoder(en coder) {}
67 ~LookupScope() { for (ID id : fToUndefine) { fEncoder->undefine(id); } }
68 void undefineWhenDone(ID id) { fToUndefine.push_back(id); }
69
70 template <typename T>
71 ID lookup(const T& val) {
72 ID id;
73 if (!fCache->lookup(val, &id, this)) {
74 fEncoder->define(id, val);
75 }
76 return id;
77 }
78
79 private:
80 Cache* fCache;
81 Encoder* fEncoder;
82 SkSTArray<4, ID> fToUndefine;
83 };
84
85
64 Cache* Cache::CreateNeverCache() { 86 Cache* Cache::CreateNeverCache() {
65 struct NeverCache final : public Cache { 87 struct NeverCache final : public Cache {
66 NeverCache() 88 NeverCache()
67 : fNextMatrix(Type::kMatrix) 89 : fNextMatrix(Type::kMatrix)
68 , fNextMisc (Type::kMisc) 90 , fNextMisc (Type::kMisc)
69 , fNextPath (Type::kPath) 91 , fNextPath (Type::kPath)
70 , fNextStroke(Type::kStroke) 92 , fNextStroke(Type::kStroke)
71 {} 93 {}
72 void cleanup(Encoder*) override {} 94 void cleanup(Encoder*) override {}
73 95
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 Client::Client(Cache* cache, Encoder* encoder) 179 Client::Client(Cache* cache, Encoder* encoder)
158 : SkCanvas(1,1) 180 : SkCanvas(1,1)
159 , fCache(cache) 181 , fCache(cache)
160 , fEncoder(encoder) 182 , fEncoder(encoder)
161 {} 183 {}
162 184
163 Client::~Client() { 185 Client::~Client() {
164 fCache->cleanup(fEncoder); 186 fCache->cleanup(fEncoder);
165 } 187 }
166 188
167 template <typename T>
168 ID LookupScope::lookup(const T& val) {
169 ID id;
170 if (!fCache->lookup(val, &id, this)) {
171 fEncoder->define(id, val);
172 }
173 return id;
174 }
175
176 void Client::willSave() { fEncoder->save(); } 189 void Client::willSave() { fEncoder->save(); }
177 void Client::didRestore() { fEncoder->restore(); } 190 void Client::didRestore() { fEncoder->restore(); }
178 191
179 void Client::didConcat (const SkMatrix&) { this->didSetMatrix(this->getTot alMatrix()); } 192 void Client::didConcat (const SkMatrix&) { this->didSetMatrix(this->getTot alMatrix()); }
180 void Client::didSetMatrix(const SkMatrix& matrix) { 193 void Client::didSetMatrix(const SkMatrix& matrix) {
181 LookupScope ls(fCache, fEncoder); 194 LookupScope ls(fCache, fEncoder);
182 fEncoder->setMatrix(ls.lookup(matrix)); 195 fEncoder->setMatrix(ls.lookup(matrix));
183 } 196 }
184 197
185 void Client::onDrawOval(const SkRect& oval, const SkPaint& paint) { 198 void Client::onDrawOval(const SkRect& oval, const SkPaint& paint) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 } 273 }
261 void Server::strokePath(ID path, ID misc, ID stroke) { 274 void Server::strokePath(ID path, ID misc, ID stroke) {
262 SkPaint paint; 275 SkPaint paint;
263 paint.setStyle(SkPaint::kStroke_Style); 276 paint.setStyle(SkPaint::kStroke_Style);
264 fMisc .find(misc ).applyTo(&paint); 277 fMisc .find(misc ).applyTo(&paint);
265 fStroke.find(stroke).applyTo(&paint); 278 fStroke.find(stroke).applyTo(&paint);
266 fCanvas->drawPath(fPath.find(path), paint); 279 fCanvas->drawPath(fPath.find(path), paint);
267 } 280 }
268 281
269 } // namespace SkRemote 282 } // namespace SkRemote
OLDNEW
« no previous file with comments | « src/core/SkRemote.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698