Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2015 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 #ifndef SkRemote_DEFINED | |
| 9 #define SkRemote_DEFINED | |
| 10 | |
| 11 #include "SkCanvas.h" | |
| 12 #include "SkPaint.h" | |
| 13 #include "SkRemote_protocol.h" | |
| 14 #include "SkTHash.h" | |
| 15 #include "SkTypes.h" | |
| 16 | |
| 17 namespace SkRemote { | |
| 18 | |
| 19 struct Encoder { | |
|
hal.canary
2015/10/16 16:57:54
/** describe class */
mtklein
2015/10/16 17:20:33
Left myself some TODOs. Not _quite_ confident eno
| |
| 20 virtual ~Encoder() {} | |
| 21 | |
| 22 struct Misc { | |
|
hal.canary
2015/10/16 16:57:55
Should this be SkRemote::Misc rather than SkRemote
mtklein
2015/10/16 17:21:36
Whoops, I seem to have clicked Cancel instead of S
| |
| 23 SkColor fColor; | |
| 24 SkFilterQuality fFilterQuality; | |
| 25 bool fAntiAlias, fDither; | |
| 26 | |
| 27 static Misc CreateFrom(const SkPaint&); | |
| 28 void applyTo(SkPaint*) const; | |
| 29 }; | |
| 30 | |
| 31 struct Stroke { | |
| 32 SkScalar fWidth, fMiter; | |
| 33 SkPaint::Cap fCap; | |
| 34 SkPaint::Join fJoin; | |
| 35 | |
| 36 static Stroke CreateFrom(const SkPaint&); | |
| 37 void applyTo(SkPaint*) const; | |
| 38 }; | |
| 39 | |
| 40 /* | |
| 41 struct Text { | |
| 42 SkScalar fSize, fScaleX, fSkewX; | |
| 43 SkPaint::Align fAlign; | |
| 44 SkPaint::Hinting fHinting; | |
| 45 SkPaint::TextEncoding fEncoding; | |
| 46 bool fAutoHinted, fDevKern, fEmbeddedBitmap, fFakeBold, fLcdRender, | |
| 47 fLinear, fStrikeThru, fSubpixel, fUnderline, fVertical; | |
| 48 | |
| 49 static Text CreateFrom(const SkPaint&); | |
| 50 void applyTo(SkPaint*) const; | |
| 51 }; | |
| 52 */ | |
| 53 | |
| 54 virtual void define(ID, const SkMatrix&) = 0; | |
| 55 virtual void define(ID, const Misc&) = 0; | |
| 56 virtual void define(ID, const SkPath&) = 0; | |
| 57 virtual void define(ID, const Stroke&) = 0; | |
| 58 | |
| 59 virtual void undefine(ID) = 0; | |
| 60 | |
| 61 virtual void save() = 0; | |
| 62 virtual void restore() = 0; | |
| 63 | |
| 64 virtual void setMatrix(ID matrix) = 0; | |
| 65 | |
| 66 virtual void clipPath(ID path, SkRegion::Op, bool aa) = 0; | |
| 67 virtual void fillPath(ID path, ID misc) = 0; | |
| 68 virtual void strokePath(ID path, ID misc, ID stroke) = 0; | |
| 69 }; | |
| 70 | |
| 71 struct Cache; | |
| 72 | |
| 73 class LookupScope { | |
|
hal.canary
2015/10/16 16:57:54
/** comments explaining what this class does. */
| |
| 74 public: | |
| 75 LookupScope(Cache* cache, Encoder* encoder) : fCache(cache), fEncoder(en coder) {} | |
| 76 ~LookupScope() { for (ID id : fToUndefine) { fEncoder->undefine(id); } } | |
| 77 void undefineWhenDone(ID id) { fToUndefine.push_back(id); } | |
| 78 | |
| 79 template <typename T> | |
| 80 ID lookup(const T&); | |
| 81 private: | |
| 82 Cache* fCache; | |
| 83 Encoder* fEncoder; | |
| 84 SkSTArray<4, ID> fToUndefine; | |
| 85 }; | |
| 86 | |
| 87 struct Cache { | |
|
hal.canary
2015/10/16 16:57:54
/** describe class */
| |
| 88 virtual ~Cache() {} | |
| 89 | |
| 90 static Cache* CreateNeverCache(); | |
| 91 static Cache* CreateAlwaysCache(); | |
| 92 | |
| 93 virtual bool lookup(const SkMatrix&, ID*, LookupScope*) = 0; | |
| 94 virtual bool lookup(const Encoder::Misc&, ID*, LookupScope*) = 0; | |
| 95 virtual bool lookup(const SkPath&, ID*, LookupScope*) = 0; | |
| 96 virtual bool lookup(const Encoder::Stroke&, ID*, LookupScope*) = 0; | |
| 97 | |
| 98 virtual void cleanup(Encoder*) = 0; | |
| 99 }; | |
| 100 | |
| 101 class Client final : public SkCanvas { | |
|
hal.canary
2015/10/16 16:57:54
/** describe class */
| |
| 102 public: | |
| 103 Client(Cache*, Encoder*); | |
| 104 ~Client(); | |
| 105 | |
| 106 private: | |
| 107 void willSave() override; | |
| 108 void didRestore() override; | |
| 109 | |
| 110 void didConcat(const SkMatrix&) override; | |
| 111 void didSetMatrix(const SkMatrix&) override; | |
| 112 | |
| 113 void onClipPath (const SkPath&, SkRegion::Op, ClipEdgeStyle) override; | |
| 114 void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) override; | |
| 115 void onClipRect (const SkRect&, SkRegion::Op, ClipEdgeStyle) override; | |
| 116 | |
| 117 void onDrawOval(const SkRect&, const SkPaint&) override; | |
| 118 void onDrawPath(const SkPath&, const SkPaint&) override; | |
| 119 void onDrawRect(const SkRect&, const SkPaint&) override; | |
| 120 | |
| 121 Cache* fCache; | |
| 122 Encoder* fEncoder; | |
| 123 }; | |
| 124 | |
| 125 class Server final : public Encoder { | |
| 126 public: | |
| 127 explicit Server(SkCanvas*); | |
| 128 | |
| 129 private: | |
| 130 void define(ID, const SkMatrix&) override; | |
| 131 void define(ID, const Misc&) override; | |
| 132 void define(ID, const SkPath&) override; | |
| 133 void define(ID, const Stroke&) override; | |
| 134 | |
| 135 void undefine(ID) override; | |
| 136 | |
| 137 void save() override; | |
| 138 void restore() override; | |
| 139 | |
| 140 void setMatrix(ID matrix) override; | |
| 141 | |
| 142 void clipPath(ID path, SkRegion::Op, bool aa) override; | |
| 143 void fillPath(ID path, ID misc) override; | |
| 144 void strokePath(ID path, ID misc, ID stroke) override; | |
| 145 | |
| 146 template <typename T, Type kType> | |
| 147 class IDMap { | |
| 148 public: | |
| 149 void set(const ID& id, const T& val) { | |
| 150 SkASSERT(id.type() == kType); | |
| 151 fMap.set(id, val); | |
| 152 } | |
| 153 | |
| 154 void remove(const ID& id) { | |
| 155 SkASSERT(id.type() == kType); | |
| 156 fMap.remove(id); | |
| 157 } | |
| 158 | |
| 159 const T& find(const ID& id) const { | |
| 160 SkASSERT(id.type() == kType); | |
| 161 T* val = fMap.find(id); | |
| 162 SkASSERT(val != nullptr); | |
| 163 return *val; | |
| 164 } | |
| 165 | |
| 166 private: | |
| 167 SkTHashMap<ID, T> fMap; | |
| 168 }; | |
| 169 | |
| 170 IDMap<SkMatrix, Type::kMatrix> fMatrix; | |
| 171 IDMap<Misc , Type::kMisc > fMisc; | |
| 172 IDMap<SkPath , Type::kPath > fPath; | |
| 173 IDMap<Stroke , Type::kStroke> fStroke; | |
| 174 | |
| 175 SkCanvas* fCanvas; | |
| 176 }; | |
| 177 | |
| 178 } // namespace SkRemote | |
| 179 | |
| 180 #endif//SkRemote_DEFINED | |
| OLD | NEW |