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

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

Issue 1417703003: SkRemote: shaders (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') | src/core/SkRemote_protocol.h » ('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 #include "SkPath.h" 8 #include "SkPath.h"
9 #include "SkRect.h" 9 #include "SkRect.h"
10 #include "SkRemote.h" 10 #include "SkRemote.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 }; 94 };
95 95
96 96
97 Cache* Cache::CreateNeverCache() { 97 Cache* Cache::CreateNeverCache() {
98 struct NeverCache final : public Cache { 98 struct NeverCache final : public Cache {
99 NeverCache() 99 NeverCache()
100 : fNextMatrix (Type::kMatrix) 100 : fNextMatrix (Type::kMatrix)
101 , fNextMisc (Type::kMisc) 101 , fNextMisc (Type::kMisc)
102 , fNextPath (Type::kPath) 102 , fNextPath (Type::kPath)
103 , fNextStroke (Type::kStroke) 103 , fNextStroke (Type::kStroke)
104 , fNextShader (Type::kShader)
104 , fNextXfermode(Type::kXfermode) 105 , fNextXfermode(Type::kXfermode)
105 {} 106 {}
106 void cleanup(Encoder*) override {} 107 void cleanup(Encoder*) override {}
107 108
108 static bool Helper(ID* next, ID* id, LookupScope* ls) { 109 static bool Helper(ID* next, ID* id, LookupScope* ls) {
109 *id = ++(*next); 110 *id = ++(*next);
110 ls->undefineWhenDone(*id); 111 ls->undefineWhenDone(*id);
111 return false; 112 return false;
112 } 113 }
113 114
114 bool lookup(const SkMatrix&, ID* id, LookupScope* ls) override { 115 bool lookup(const SkMatrix&, ID* id, LookupScope* ls) override {
115 return Helper(&fNextMatrix, id, ls); 116 return Helper(&fNextMatrix, id, ls);
116 } 117 }
117 bool lookup(const Misc&, ID* id, LookupScope* ls) override { 118 bool lookup(const Misc&, ID* id, LookupScope* ls) override {
118 return Helper(&fNextMisc, id, ls); 119 return Helper(&fNextMisc, id, ls);
119 } 120 }
120 bool lookup(const SkPath&, ID* id, LookupScope* ls) override { 121 bool lookup(const SkPath&, ID* id, LookupScope* ls) override {
121 return Helper(&fNextPath, id, ls); 122 return Helper(&fNextPath, id, ls);
122 } 123 }
123 bool lookup(const Stroke&, ID* id, LookupScope* ls) override { 124 bool lookup(const Stroke&, ID* id, LookupScope* ls) override {
124 return Helper(&fNextStroke, id, ls); 125 return Helper(&fNextStroke, id, ls);
125 } 126 }
127 bool lookup(const SkShader* shader, ID* id, LookupScope* ls) overrid e {
128 if (!shader) {
129 *id = ID(Type::kShader);
130 return true; // Null IDs are always defined.
131 }
132 return Helper(&fNextShader, id, ls);
133 }
126 bool lookup(const SkXfermode* xfermode, ID* id, LookupScope* ls) ove rride { 134 bool lookup(const SkXfermode* xfermode, ID* id, LookupScope* ls) ove rride {
127 if (!xfermode) { 135 if (!xfermode) {
128 *id = ID(Type::kXfermode); 136 *id = ID(Type::kXfermode);
129 return true; // Null IDs are always defined. 137 return true; // Null IDs are always defined.
130 } 138 }
131 return Helper(&fNextXfermode, id, ls); 139 return Helper(&fNextXfermode, id, ls);
132 } 140 }
133 141
134 ID fNextMatrix, 142 ID fNextMatrix,
135 fNextMisc, 143 fNextMisc,
136 fNextPath, 144 fNextPath,
137 fNextStroke, 145 fNextStroke,
146 fNextShader,
138 fNextXfermode; 147 fNextXfermode;
139 }; 148 };
140 return new NeverCache; 149 return new NeverCache;
141 } 150 }
142 151
143 // These can't be declared locally inside AlwaysCache because of the templat ing. :( 152 // These can't be declared locally inside AlwaysCache because of the templat ing. :(
144 namespace { 153 namespace {
145 template <typename T, typename Map> 154 template <typename T, typename Map>
146 static bool always_cache_lookup(const T& val, Map* map, ID* next, ID* id ) { 155 static bool always_cache_lookup(const T& val, Map* map, ID* next, ID* id ) {
147 if (const ID* found = map->find(val)) { 156 if (const ID* found = map->find(val)) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 }; 199 };
191 } // namespace 200 } // namespace
192 201
193 Cache* Cache::CreateAlwaysCache() { 202 Cache* Cache::CreateAlwaysCache() {
194 struct AlwaysCache final : public Cache { 203 struct AlwaysCache final : public Cache {
195 AlwaysCache() 204 AlwaysCache()
196 : fNextMatrix (Type::kMatrix) 205 : fNextMatrix (Type::kMatrix)
197 , fNextMisc (Type::kMisc) 206 , fNextMisc (Type::kMisc)
198 , fNextPath (Type::kPath) 207 , fNextPath (Type::kPath)
199 , fNextStroke (Type::kStroke) 208 , fNextStroke (Type::kStroke)
209 , fNextShader (Type::kShader)
200 , fNextXfermode(Type::kXfermode) 210 , fNextXfermode(Type::kXfermode)
201 {} 211 {}
202 212
203 void cleanup(Encoder* encoder) override { 213 void cleanup(Encoder* encoder) override {
204 Undefiner undef{encoder}; 214 Undefiner undef{encoder};
205 fMatrix .foreach(undef); 215 fMatrix .foreach(undef);
206 fMisc .foreach(undef); 216 fMisc .foreach(undef);
207 fPath .foreach(undef); 217 fPath .foreach(undef);
208 fStroke .foreach(undef); 218 fStroke .foreach(undef);
219 fShader .foreach(undef);
209 fXfermode.foreach(undef); 220 fXfermode.foreach(undef);
210 } 221 }
211 222
212 223
213 bool lookup(const SkMatrix& matrix, ID* id, LookupScope*) override { 224 bool lookup(const SkMatrix& matrix, ID* id, LookupScope*) override {
214 return always_cache_lookup(matrix, &fMatrix, &fNextMatrix, id); 225 return always_cache_lookup(matrix, &fMatrix, &fNextMatrix, id);
215 } 226 }
216 bool lookup(const Misc& misc, ID* id, LookupScope*) override { 227 bool lookup(const Misc& misc, ID* id, LookupScope*) override {
217 return always_cache_lookup(misc, &fMisc, &fNextMisc, id); 228 return always_cache_lookup(misc, &fMisc, &fNextMisc, id);
218 } 229 }
219 bool lookup(const SkPath& path, ID* id, LookupScope*) override { 230 bool lookup(const SkPath& path, ID* id, LookupScope*) override {
220 return always_cache_lookup(path, &fPath, &fNextPath, id); 231 return always_cache_lookup(path, &fPath, &fNextPath, id);
221 } 232 }
222 bool lookup(const Stroke& stroke, ID* id, LookupScope*) override { 233 bool lookup(const Stroke& stroke, ID* id, LookupScope*) override {
223 return always_cache_lookup(stroke, &fStroke, &fNextStroke, id); 234 return always_cache_lookup(stroke, &fStroke, &fNextStroke, id);
224 } 235 }
236 bool lookup(const SkShader* shader, ID* id, LookupScope*) override {
237 return always_cache_lookup(shader, &fShader, &fNextShader, id);
238 }
225 bool lookup(const SkXfermode* xfermode, ID* id, LookupScope*) overri de { 239 bool lookup(const SkXfermode* xfermode, ID* id, LookupScope*) overri de {
226 return always_cache_lookup(xfermode, &fXfermode, &fNextXfermode, id); 240 return always_cache_lookup(xfermode, &fXfermode, &fNextXfermode, id);
227 } 241 }
228 242
229 SkTHashMap<SkMatrix, ID> fMatrix; 243 SkTHashMap<SkMatrix, ID> fMatrix;
230 SkTHashMap<Misc, ID, MiscHash> fMisc; 244 SkTHashMap<Misc, ID, MiscHash> fMisc;
231 SkTHashMap<SkPath, ID> fPath; 245 SkTHashMap<SkPath, ID> fPath;
232 SkTHashMap<Stroke, ID> fStroke; 246 SkTHashMap<Stroke, ID> fStroke;
247 RefKeyMap<SkShader, Type::kShader> fShader;
233 RefKeyMap<SkXfermode, Type::kXfermode> fXfermode; 248 RefKeyMap<SkXfermode, Type::kXfermode> fXfermode;
234 249
235 ID fNextMatrix, 250 ID fNextMatrix,
236 fNextMisc, 251 fNextMisc,
237 fNextPath, 252 fNextPath,
238 fNextStroke, 253 fNextStroke,
254 fNextShader,
239 fNextXfermode; 255 fNextXfermode;
240 }; 256 };
241 return new AlwaysCache; 257 return new AlwaysCache;
242 } 258 }
243 259
244 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // 260 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
245 261
246 Client::Client(Cache* cache, Encoder* encoder) 262 Client::Client(Cache* cache, Encoder* encoder)
247 : SkCanvas(1,1) 263 : SkCanvas(1,1)
248 , fCache(cache) 264 , fCache(cache)
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 SkPath path; 302 SkPath path;
287 path.addRRect(outside); 303 path.addRRect(outside);
288 path.addRRect(inside, SkPath::kCCW_Direction); 304 path.addRRect(inside, SkPath::kCCW_Direction);
289 this->onDrawPath(path, paint); 305 this->onDrawPath(path, paint);
290 } 306 }
291 307
292 void Client::onDrawPath(const SkPath& path, const SkPaint& paint) { 308 void Client::onDrawPath(const SkPath& path, const SkPaint& paint) {
293 LookupScope ls(fCache, fEncoder); 309 LookupScope ls(fCache, fEncoder);
294 ID p = ls.lookup(path), 310 ID p = ls.lookup(path),
295 m = ls.lookup(Misc::CreateFrom(paint)), 311 m = ls.lookup(Misc::CreateFrom(paint)),
312 s = ls.lookup(paint.getShader()),
296 x = ls.lookup(paint.getXfermode()); 313 x = ls.lookup(paint.getXfermode());
297 314
298 if (paint.getStyle() == SkPaint::kFill_Style) { 315 if (paint.getStyle() == SkPaint::kFill_Style) {
299 fEncoder->fillPath(p, m, x); 316 fEncoder->fillPath(p, m, s, x);
300 } else { 317 } else {
301 // TODO: handle kStrokeAndFill_Style 318 // TODO: handle kStrokeAndFill_Style
302 fEncoder->strokePath(p, m, x, ls.lookup(Stroke::CreateFrom(paint))); 319 fEncoder->strokePath(p, m, s, x, ls.lookup(Stroke::CreateFrom(paint) ));
303 } 320 }
304 } 321 }
305 322
306 void Client::onDrawPaint(const SkPaint& paint) { 323 void Client::onDrawPaint(const SkPaint& paint) {
307 SkPath path; 324 SkPath path;
308 path.setFillType(SkPath::kInverseWinding_FillType); // Either inverse F illType works fine. 325 path.setFillType(SkPath::kInverseWinding_FillType); // Either inverse F illType works fine.
309 this->onDrawPath(path, paint); 326 this->onDrawPath(path, paint);
310 } 327 }
311 328
312 void Client::onDrawText(const void* text, size_t byteLength, SkScalar x, 329 void Client::onDrawText(const void* text, size_t byteLength, SkScalar x,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 } 373 }
357 374
358 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // 375 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
359 376
360 Server::Server(SkCanvas* canvas) : fCanvas(canvas) {} 377 Server::Server(SkCanvas* canvas) : fCanvas(canvas) {}
361 378
362 void Server::define(ID id, const SkMatrix& v) { fMatrix .set(id, v); } 379 void Server::define(ID id, const SkMatrix& v) { fMatrix .set(id, v); }
363 void Server::define(ID id, const Misc& v) { fMisc .set(id, v); } 380 void Server::define(ID id, const Misc& v) { fMisc .set(id, v); }
364 void Server::define(ID id, const SkPath& v) { fPath .set(id, v); } 381 void Server::define(ID id, const SkPath& v) { fPath .set(id, v); }
365 void Server::define(ID id, const Stroke& v) { fStroke .set(id, v); } 382 void Server::define(ID id, const Stroke& v) { fStroke .set(id, v); }
383 void Server::define(ID id, SkShader* v) { fShader .set(id, v); }
366 void Server::define(ID id, SkXfermode* v) { fXfermode.set(id, v); } 384 void Server::define(ID id, SkXfermode* v) { fXfermode.set(id, v); }
367 385
368 void Server::undefine(ID id) { 386 void Server::undefine(ID id) {
369 switch(id.type()) { 387 switch(id.type()) {
370 case Type::kMatrix: return fMatrix .remove(id); 388 case Type::kMatrix: return fMatrix .remove(id);
371 case Type::kMisc: return fMisc .remove(id); 389 case Type::kMisc: return fMisc .remove(id);
372 case Type::kPath: return fPath .remove(id); 390 case Type::kPath: return fPath .remove(id);
373 case Type::kStroke: return fStroke .remove(id); 391 case Type::kStroke: return fStroke .remove(id);
392 case Type::kShader: return fShader .remove(id);
374 case Type::kXfermode: return fXfermode.remove(id); 393 case Type::kXfermode: return fXfermode.remove(id);
375 394
376 case Type::kNone: SkASSERT(false); 395 case Type::kNone: SkASSERT(false);
377 }; 396 };
378 } 397 }
379 398
380 void Server:: save() { fCanvas->save(); } 399 void Server:: save() { fCanvas->save(); }
381 void Server::restore() { fCanvas->restore(); } 400 void Server::restore() { fCanvas->restore(); }
382 401
383 void Server::setMatrix(ID matrix) { fCanvas->setMatrix(fMatrix.find(matrix)) ; } 402 void Server::setMatrix(ID matrix) { fCanvas->setMatrix(fMatrix.find(matrix)) ; }
384 403
385 void Server::clipPath(ID path, SkRegion::Op op, bool aa) { 404 void Server::clipPath(ID path, SkRegion::Op op, bool aa) {
386 fCanvas->clipPath(fPath.find(path), op, aa); 405 fCanvas->clipPath(fPath.find(path), op, aa);
387 } 406 }
388 void Server::fillPath(ID path, ID misc, ID xfermode) { 407 void Server::fillPath(ID path, ID misc, ID shader, ID xfermode) {
389 SkPaint paint; 408 SkPaint paint;
390 paint.setStyle(SkPaint::kFill_Style); 409 paint.setStyle(SkPaint::kFill_Style);
391 fMisc.find(misc).applyTo(&paint); 410 fMisc.find(misc).applyTo(&paint);
411 paint.setShader (fShader .find(shader));
392 paint.setXfermode(fXfermode.find(xfermode)); 412 paint.setXfermode(fXfermode.find(xfermode));
393 fCanvas->drawPath(fPath.find(path), paint); 413 fCanvas->drawPath(fPath.find(path), paint);
394 } 414 }
395 void Server::strokePath(ID path, ID misc, ID xfermode, ID stroke) { 415 void Server::strokePath(ID path, ID misc, ID shader, ID xfermode, ID stroke) {
396 SkPaint paint; 416 SkPaint paint;
397 paint.setStyle(SkPaint::kStroke_Style); 417 paint.setStyle(SkPaint::kStroke_Style);
398 fMisc .find(misc ).applyTo(&paint); 418 fMisc .find(misc ).applyTo(&paint);
399 fStroke.find(stroke).applyTo(&paint); 419 fStroke.find(stroke).applyTo(&paint);
420 paint.setShader (fShader .find(shader));
400 paint.setXfermode(fXfermode.find(xfermode)); 421 paint.setXfermode(fXfermode.find(xfermode));
401 fCanvas->drawPath(fPath.find(path), paint); 422 fCanvas->drawPath(fPath.find(path), paint);
402 } 423 }
403 424
404 } // namespace SkRemote 425 } // namespace SkRemote
OLDNEW
« no previous file with comments | « src/core/SkRemote.h ('k') | src/core/SkRemote_protocol.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698