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

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

Issue 1744103002: move annotations to canvas virtual (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 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 "SkAnnotation.h"
9 #include "SkCanvas.h" 8 #include "SkCanvas.h"
10 #include "SkColorFilter.h" 9 #include "SkColorFilter.h"
11 #include "SkDrawLooper.h" 10 #include "SkDrawLooper.h"
12 #include "SkImage.h" 11 #include "SkImage.h"
13 #include "SkImageFilter.h" 12 #include "SkImageFilter.h"
14 #include "SkMaskFilter.h" 13 #include "SkMaskFilter.h"
15 #include "SkNinePatchIter.h" 14 #include "SkNinePatchIter.h"
16 #include "SkPath.h" 15 #include "SkPath.h"
17 #include "SkPathEffect.h" 16 #include "SkPathEffect.h"
18 #include "SkRasterizer.h" 17 #include "SkRasterizer.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 : fEncoder(encoder) { 119 : fEncoder(encoder) {
121 fIDs.misc = fEncoder->define(Misc::CreateFrom(paint)); 120 fIDs.misc = fEncoder->define(Misc::CreateFrom(paint));
122 fIDs.patheffect = fEncoder->define(paint.getPathEffect()); 121 fIDs.patheffect = fEncoder->define(paint.getPathEffect());
123 fIDs.shader = fEncoder->define(paint.getShader()); 122 fIDs.shader = fEncoder->define(paint.getShader());
124 fIDs.xfermode = fEncoder->define(paint.getXfermode()); 123 fIDs.xfermode = fEncoder->define(paint.getXfermode());
125 fIDs.maskfilter = fEncoder->define(paint.getMaskFilter()); 124 fIDs.maskfilter = fEncoder->define(paint.getMaskFilter());
126 fIDs.colorfilter = fEncoder->define(paint.getColorFilter()); 125 fIDs.colorfilter = fEncoder->define(paint.getColorFilter());
127 fIDs.rasterizer = fEncoder->define(paint.getRasterizer()); 126 fIDs.rasterizer = fEncoder->define(paint.getRasterizer());
128 fIDs.looper = fEncoder->define(paint.getLooper()); 127 fIDs.looper = fEncoder->define(paint.getLooper());
129 fIDs.imagefilter = fEncoder->define(paint.getImageFilter()); 128 fIDs.imagefilter = fEncoder->define(paint.getImageFilter());
130 fIDs.annotation = fEncoder->define(paint.getAnnotation());
131 } 129 }
132 ~AutoCommonIDs() { 130 ~AutoCommonIDs() {
133 if (fEncoder) { 131 if (fEncoder) {
134 fEncoder->undefine(fIDs.misc); 132 fEncoder->undefine(fIDs.misc);
135 fEncoder->undefine(fIDs.patheffect); 133 fEncoder->undefine(fIDs.patheffect);
136 fEncoder->undefine(fIDs.shader); 134 fEncoder->undefine(fIDs.shader);
137 fEncoder->undefine(fIDs.xfermode); 135 fEncoder->undefine(fIDs.xfermode);
138 fEncoder->undefine(fIDs.maskfilter); 136 fEncoder->undefine(fIDs.maskfilter);
139 fEncoder->undefine(fIDs.colorfilter); 137 fEncoder->undefine(fIDs.colorfilter);
140 fEncoder->undefine(fIDs.rasterizer); 138 fEncoder->undefine(fIDs.rasterizer);
141 fEncoder->undefine(fIDs.looper); 139 fEncoder->undefine(fIDs.looper);
142 fEncoder->undefine(fIDs.imagefilter); 140 fEncoder->undefine(fIDs.imagefilter);
143 fEncoder->undefine(fIDs.annotation);
144 } 141 }
145 } 142 }
146 143
147 AutoCommonIDs(AutoCommonIDs&& o) : fEncoder(o.fEncoder), fIDs(o.fIDs ) { 144 AutoCommonIDs(AutoCommonIDs&& o) : fEncoder(o.fEncoder), fIDs(o.fIDs ) {
148 o.fEncoder = nullptr; 145 o.fEncoder = nullptr;
149 } 146 }
150 AutoID& operator=(AutoID&&) = delete; 147 AutoID& operator=(AutoID&&) = delete;
151 148
152 operator Encoder::CommonIDs () const { return fIDs; } 149 operator Encoder::CommonIDs () const { return fIDs; }
153 150
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 ID define(const Stroke& v)O{return this->define(Type::kStroke, &fStroke, v);} 451 ID define(const Stroke& v)O{return this->define(Type::kStroke, &fStroke, v);}
455 ID define(const SkTextBlob* v)O{return this->define(Type::kTextBlob, &fTextBlob, v);} 452 ID define(const SkTextBlob* v)O{return this->define(Type::kTextBlob, &fTextBlob, v);}
456 ID define(SkPathEffect* v)O{return this->define(Type::kPathEffect, &fPathEffect, v);} 453 ID define(SkPathEffect* v)O{return this->define(Type::kPathEffect, &fPathEffect, v);}
457 ID define(SkShader* v)O{return this->define(Type::kShader, &fShader, v);} 454 ID define(SkShader* v)O{return this->define(Type::kShader, &fShader, v);}
458 ID define(SkXfermode* v)O{return this->define(Type::kXfermode, &fXfermode, v);} 455 ID define(SkXfermode* v)O{return this->define(Type::kXfermode, &fXfermode, v);}
459 ID define(SkMaskFilter* v)O{return this->define(Type::kMaskFilter, &fMaskFilter, v);} 456 ID define(SkMaskFilter* v)O{return this->define(Type::kMaskFilter, &fMaskFilter, v);}
460 ID define(SkColorFilter* v)O{return this->define(Type::kColorFilter, &fColorFilter, v);} 457 ID define(SkColorFilter* v)O{return this->define(Type::kColorFilter, &fColorFilter, v);}
461 ID define(SkRasterizer* v)O{return this->define(Type::kRasterizer, &fRasterizer, v);} 458 ID define(SkRasterizer* v)O{return this->define(Type::kRasterizer, &fRasterizer, v);}
462 ID define(SkDrawLooper* v)O{return this->define(Type::kDrawLooper, &fDrawLooper, v);} 459 ID define(SkDrawLooper* v)O{return this->define(Type::kDrawLooper, &fDrawLooper, v);}
463 ID define(SkImageFilter* v)O{return this->define(Type::kImageFilter, &fImageFilter, v);} 460 ID define(SkImageFilter* v)O{return this->define(Type::kImageFilter, &fImageFilter, v);}
464 ID define(SkAnnotation* v)O{return this->define(Type::kAnnotation, &fAnnotation, v);}
465 #undef O 461 #undef O
466 462
467 463
468 void undefine(ID id) override { 464 void undefine(ID id) override {
469 switch(id.type()) { 465 switch(id.type()) {
470 case Type::kMatrix: return fMatrix .remove(id); 466 case Type::kMatrix: return fMatrix .remove(id);
471 case Type::kMisc: return fMisc .remove(id); 467 case Type::kMisc: return fMisc .remove(id);
472 case Type::kPath: return fPath .remove(id); 468 case Type::kPath: return fPath .remove(id);
473 case Type::kStroke: return fStroke .remove(id); 469 case Type::kStroke: return fStroke .remove(id);
474 case Type::kTextBlob: return fTextBlob .remove(id); 470 case Type::kTextBlob: return fTextBlob .remove(id);
475 case Type::kPathEffect: return fPathEffect .remove(id); 471 case Type::kPathEffect: return fPathEffect .remove(id);
476 case Type::kShader: return fShader .remove(id); 472 case Type::kShader: return fShader .remove(id);
477 case Type::kXfermode: return fXfermode .remove(id); 473 case Type::kXfermode: return fXfermode .remove(id);
478 case Type::kMaskFilter: return fMaskFilter .remove(id); 474 case Type::kMaskFilter: return fMaskFilter .remove(id);
479 case Type::kColorFilter: return fColorFilter.remove(id); 475 case Type::kColorFilter: return fColorFilter.remove(id);
480 case Type::kRasterizer: return fRasterizer .remove(id); 476 case Type::kRasterizer: return fRasterizer .remove(id);
481 case Type::kDrawLooper: return fDrawLooper .remove(id); 477 case Type::kDrawLooper: return fDrawLooper .remove(id);
482 case Type::kImageFilter: return fImageFilter.remove(id); 478 case Type::kImageFilter: return fImageFilter.remove(id);
483 case Type::kAnnotation: return fAnnotation .remove(id);
484 }; 479 };
485 } 480 }
486 481
487 void applyCommon(const CommonIDs& common, SkPaint* paint) const { 482 void applyCommon(const CommonIDs& common, SkPaint* paint) const {
488 fMisc.find(common.misc).applyTo(paint); 483 fMisc.find(common.misc).applyTo(paint);
489 paint->setPathEffect (fPathEffect .find(common.patheffect)); 484 paint->setPathEffect (fPathEffect .find(common.patheffect));
490 paint->setShader (fShader .find(common.shader)); 485 paint->setShader (fShader .find(common.shader));
491 paint->setXfermode (fXfermode .find(common.xfermode)); 486 paint->setXfermode (fXfermode .find(common.xfermode));
492 paint->setMaskFilter (fMaskFilter .find(common.maskfilter)); 487 paint->setMaskFilter (fMaskFilter .find(common.maskfilter));
493 paint->setColorFilter(fColorFilter.find(common.colorfilter)); 488 paint->setColorFilter(fColorFilter.find(common.colorfilter));
494 paint->setRasterizer (fRasterizer .find(common.rasterizer)); 489 paint->setRasterizer (fRasterizer .find(common.rasterizer));
495 paint->setLooper (fDrawLooper .find(common.looper)); 490 paint->setLooper (fDrawLooper .find(common.looper));
496 paint->setImageFilter(fImageFilter.find(common.imagefilter)); 491 paint->setImageFilter(fImageFilter.find(common.imagefilter));
497 paint->setAnnotation (fAnnotation .find(common.annotation));
498 } 492 }
499 493
500 void save() override { fCanvas->save(); } 494 void save() override { fCanvas->save(); }
501 void restore() override { fCanvas->restore(); } 495 void restore() override { fCanvas->restore(); }
502 void saveLayer(ID bounds, CommonIDs common, SkCanvas::SaveLayerFlags fla gs) override { 496 void saveLayer(ID bounds, CommonIDs common, SkCanvas::SaveLayerFlags fla gs) override {
503 SkPaint paint; 497 SkPaint paint;
504 this->applyCommon(common, &paint); 498 this->applyCommon(common, &paint);
505 SkRect rect; 499 SkRect rect;
506 500
507 fCanvas->saveLayer({ fPath.find(bounds).isRect(&rect) ? &rect : null ptr, 501 fCanvas->saveLayer({ fPath.find(bounds).isRect(&rect) ? &rect : null ptr,
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 IDMap<Stroke , Type::kStroke > fStroke; 604 IDMap<Stroke , Type::kStroke > fStroke;
611 ReffedIDMap<const SkTextBlob, Type::kTextBlob > fTextBlob; 605 ReffedIDMap<const SkTextBlob, Type::kTextBlob > fTextBlob;
612 ReffedIDMap<SkPathEffect , Type::kPathEffect > fPathEffect; 606 ReffedIDMap<SkPathEffect , Type::kPathEffect > fPathEffect;
613 ReffedIDMap<SkShader , Type::kShader > fShader; 607 ReffedIDMap<SkShader , Type::kShader > fShader;
614 ReffedIDMap<SkXfermode , Type::kXfermode > fXfermode; 608 ReffedIDMap<SkXfermode , Type::kXfermode > fXfermode;
615 ReffedIDMap<SkMaskFilter , Type::kMaskFilter > fMaskFilter; 609 ReffedIDMap<SkMaskFilter , Type::kMaskFilter > fMaskFilter;
616 ReffedIDMap<SkColorFilter , Type::kColorFilter> fColorFilter; 610 ReffedIDMap<SkColorFilter , Type::kColorFilter> fColorFilter;
617 ReffedIDMap<SkRasterizer , Type::kRasterizer > fRasterizer; 611 ReffedIDMap<SkRasterizer , Type::kRasterizer > fRasterizer;
618 ReffedIDMap<SkDrawLooper , Type::kDrawLooper > fDrawLooper; 612 ReffedIDMap<SkDrawLooper , Type::kDrawLooper > fDrawLooper;
619 ReffedIDMap<SkImageFilter , Type::kImageFilter> fImageFilter; 613 ReffedIDMap<SkImageFilter , Type::kImageFilter> fImageFilter;
620 ReffedIDMap<SkAnnotation , Type::kAnnotation > fAnnotation;
621 614
622 SkCanvas* fCanvas; 615 SkCanvas* fCanvas;
623 uint64_t fNextID = 0; 616 uint64_t fNextID = 0;
624 }; 617 };
625 618
626 Encoder* NewDecoder(SkCanvas* canvas) { return new Decoder(canvas); } 619 Encoder* NewDecoder(SkCanvas* canvas) { return new Decoder(canvas); }
627 620
628 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // 621 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
629 622
630 class CachingEncoder final : public Encoder { 623 class CachingEncoder final : public Encoder {
(...skipping 15 matching lines...) Expand all
646 fStroke .foreach(undef); 639 fStroke .foreach(undef);
647 fTextBlob .foreach(undef); 640 fTextBlob .foreach(undef);
648 fPathEffect .foreach(undef); 641 fPathEffect .foreach(undef);
649 fShader .foreach(undef); 642 fShader .foreach(undef);
650 fXfermode .foreach(undef); 643 fXfermode .foreach(undef);
651 fMaskFilter .foreach(undef); 644 fMaskFilter .foreach(undef);
652 fColorFilter.foreach(undef); 645 fColorFilter.foreach(undef);
653 fRasterizer .foreach(undef); 646 fRasterizer .foreach(undef);
654 fDrawLooper .foreach(undef); 647 fDrawLooper .foreach(undef);
655 fImageFilter.foreach(undef); 648 fImageFilter.foreach(undef);
656 fAnnotation .foreach(undef);
657 } 649 }
658 650
659 template <typename Map, typename T> 651 template <typename Map, typename T>
660 ID define(Map* map, const T& v) { 652 ID define(Map* map, const T& v) {
661 if (const ID* id = map->find(v)) { 653 if (const ID* id = map->find(v)) {
662 return *id; 654 return *id;
663 } 655 }
664 ID id = fWrapped->define(v); 656 ID id = fWrapped->define(v);
665 map->set(v, id); 657 map->set(v, id);
666 return id; 658 return id;
667 } 659 }
668 660
669 ID define(const SkMatrix& v) override { return this->define(&fMatrix , v); } 661 ID define(const SkMatrix& v) override { return this->define(&fMatrix , v); }
670 ID define(const Misc& v) override { return this->define(&fMisc , v); } 662 ID define(const Misc& v) override { return this->define(&fMisc , v); }
671 ID define(const SkPath& v) override { return this->define(&fPath , v); } 663 ID define(const SkPath& v) override { return this->define(&fPath , v); }
672 ID define(const Stroke& v) override { return this->define(&fStroke , v); } 664 ID define(const Stroke& v) override { return this->define(&fStroke , v); }
673 ID define(const SkTextBlob* v) override { return this->define(&fTextBlob , v); } 665 ID define(const SkTextBlob* v) override { return this->define(&fTextBlob , v); }
674 ID define(SkPathEffect* v) override { return this->define(&fPathEffe ct , v); } 666 ID define(SkPathEffect* v) override { return this->define(&fPathEffe ct , v); }
675 ID define(SkShader* v) override { return this->define(&fShader , v); } 667 ID define(SkShader* v) override { return this->define(&fShader , v); }
676 ID define(SkXfermode* v) override { return this->define(&fXfermode , v); } 668 ID define(SkXfermode* v) override { return this->define(&fXfermode , v); }
677 ID define(SkMaskFilter* v) override { return this->define(&fMaskFilt er , v); } 669 ID define(SkMaskFilter* v) override { return this->define(&fMaskFilt er , v); }
678 ID define(SkColorFilter* v) override { return this->define(&fColorFil ter, v); } 670 ID define(SkColorFilter* v) override { return this->define(&fColorFil ter, v); }
679 ID define(SkRasterizer* v) override { return this->define(&fRasteriz er , v); } 671 ID define(SkRasterizer* v) override { return this->define(&fRasteriz er , v); }
680 ID define(SkDrawLooper* v) override { return this->define(&fDrawLoop er , v); } 672 ID define(SkDrawLooper* v) override { return this->define(&fDrawLoop er , v); }
681 ID define(SkImageFilter* v) override { return this->define(&fImageFil ter, v); } 673 ID define(SkImageFilter* v) override { return this->define(&fImageFil ter, v); }
682 ID define(SkAnnotation* v) override { return this->define(&fAnnotati on , v); }
683 674
684 void undefine(ID) override {} 675 void undefine(ID) override {}
685 676
686 void save() override { fWrapped-> save(); } 677 void save() override { fWrapped-> save(); }
687 void restore() override { fWrapped->restore(); } 678 void restore() override { fWrapped->restore(); }
688 void saveLayer(ID bounds, CommonIDs common, SkCanvas::SaveLayerFlags fla gs) override { 679 void saveLayer(ID bounds, CommonIDs common, SkCanvas::SaveLayerFlags fla gs) override {
689 fWrapped->saveLayer(bounds, common, flags); 680 fWrapped->saveLayer(bounds, common, flags);
690 } 681 }
691 682
692 void setMatrix(ID matrix) override { fWrapped->setMatrix(matrix); } 683 void setMatrix(ID matrix) override { fWrapped->setMatrix(matrix); }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 SkTHashMap<Stroke, ID> fStroke; 733 SkTHashMap<Stroke, ID> fStroke;
743 RefKeyMap<const SkTextBlob, Type::kTextBlob > fTextBlob; 734 RefKeyMap<const SkTextBlob, Type::kTextBlob > fTextBlob;
744 RefKeyMap<SkPathEffect , Type::kPathEffect > fPathEffect; 735 RefKeyMap<SkPathEffect , Type::kPathEffect > fPathEffect;
745 RefKeyMap<SkShader , Type::kShader > fShader; 736 RefKeyMap<SkShader , Type::kShader > fShader;
746 RefKeyMap<SkXfermode , Type::kXfermode > fXfermode; 737 RefKeyMap<SkXfermode , Type::kXfermode > fXfermode;
747 RefKeyMap<SkMaskFilter , Type::kMaskFilter > fMaskFilter; 738 RefKeyMap<SkMaskFilter , Type::kMaskFilter > fMaskFilter;
748 RefKeyMap<SkColorFilter , Type::kColorFilter> fColorFilter; 739 RefKeyMap<SkColorFilter , Type::kColorFilter> fColorFilter;
749 RefKeyMap<SkRasterizer , Type::kRasterizer > fRasterizer; 740 RefKeyMap<SkRasterizer , Type::kRasterizer > fRasterizer;
750 RefKeyMap<SkDrawLooper , Type::kDrawLooper > fDrawLooper; 741 RefKeyMap<SkDrawLooper , Type::kDrawLooper > fDrawLooper;
751 RefKeyMap<SkImageFilter , Type::kImageFilter> fImageFilter; 742 RefKeyMap<SkImageFilter , Type::kImageFilter> fImageFilter;
752 RefKeyMap<SkAnnotation , Type::kAnnotation > fAnnotation;
753 743
754 Encoder* fWrapped; 744 Encoder* fWrapped;
755 }; 745 };
756 746
757 Encoder* NewCachingEncoder(Encoder* wrapped) { return new CachingEncoder(wra pped); } 747 Encoder* NewCachingEncoder(Encoder* wrapped) { return new CachingEncoder(wra pped); }
758 748
759 } // namespace SkRemote 749 } // 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