| OLD | NEW |
| 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 17 matching lines...) Expand all Loading... |
| 28 paint->setDither (fDither); | 28 paint->setDither (fDither); |
| 29 } | 29 } |
| 30 | 30 |
| 31 static bool operator==(const Misc& a, const Misc& b) { | 31 static bool operator==(const Misc& a, const Misc& b) { |
| 32 return a.fColor == b.fColor | 32 return a.fColor == b.fColor |
| 33 && a.fFilterQuality == b.fFilterQuality | 33 && a.fFilterQuality == b.fFilterQuality |
| 34 && a.fAntiAlias == b.fAntiAlias | 34 && a.fAntiAlias == b.fAntiAlias |
| 35 && a.fDither == b.fDither; | 35 && a.fDither == b.fDither; |
| 36 } | 36 } |
| 37 | 37 |
| 38 // Misc carries 10 bytes of data in a 12 byte struct, so we need a custom ha
sh. |
| 39 static_assert(sizeof(Misc) > offsetof(Misc, fDither) + sizeof(Misc().fDither
), ""); |
| 40 struct MiscHash { |
| 41 uint32_t operator()(const Misc& misc) { |
| 42 return SkChecksum::Murmur3(&misc, offsetof(Misc, fDither) + sizeof(M
isc().fDither)); |
| 43 } |
| 44 }; |
| 45 |
| 38 Stroke Stroke::CreateFrom(const SkPaint& paint) { | 46 Stroke Stroke::CreateFrom(const SkPaint& paint) { |
| 39 Stroke stroke = { | 47 Stroke stroke = { |
| 40 paint.getStrokeWidth(), | 48 paint.getStrokeWidth(), |
| 41 paint.getStrokeMiter(), | 49 paint.getStrokeMiter(), |
| 42 paint.getStrokeCap(), | 50 paint.getStrokeCap(), |
| 43 paint.getStrokeJoin(), | 51 paint.getStrokeJoin(), |
| 44 }; | 52 }; |
| 45 return stroke; | 53 return stroke; |
| 46 } | 54 } |
| 47 | 55 |
| 48 void Stroke::applyTo(SkPaint* paint) const { | 56 void Stroke::applyTo(SkPaint* paint) const { |
| 49 paint->setStrokeWidth(fWidth); | 57 paint->setStrokeWidth(fWidth); |
| 50 paint->setStrokeMiter(fMiter); | 58 paint->setStrokeMiter(fMiter); |
| 51 paint->setStrokeCap (fCap); | 59 paint->setStrokeCap (fCap); |
| 52 paint->setStrokeJoin (fJoin); | 60 paint->setStrokeJoin (fJoin); |
| 53 } | 61 } |
| 54 | 62 |
| 55 static bool operator==(const Stroke& a, const Stroke& b) { | 63 static bool operator==(const Stroke& a, const Stroke& b) { |
| 56 return a.fWidth == b.fWidth | 64 return a.fWidth == b.fWidth |
| 57 && a.fMiter == b.fMiter | 65 && a.fMiter == b.fMiter |
| 58 && a.fCap == b.fCap | 66 && a.fCap == b.fCap |
| 59 && a.fJoin == b.fJoin; | 67 && a.fJoin == b.fJoin; |
| 60 } | 68 } |
| 61 | 69 |
| 70 // The default SkGoodHash works fine for Stroke, as it's dense. |
| 71 static_assert(sizeof(Stroke) == offsetof(Stroke, fJoin) + sizeof(Stroke().fJ
oin), ""); |
| 72 |
| 62 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // | 73 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // |
| 63 | 74 |
| 64 class LookupScope { | 75 class LookupScope { |
| 65 public: | 76 public: |
| 66 LookupScope(Cache* cache, Encoder* encoder) : fCache(cache), fEncoder(en
coder) {} | 77 LookupScope(Cache* cache, Encoder* encoder) : fCache(cache), fEncoder(en
coder) {} |
| 67 ~LookupScope() { for (ID id : fToUndefine) { fEncoder->undefine(id); } } | 78 ~LookupScope() { for (ID id : fToUndefine) { fEncoder->undefine(id); } } |
| 68 void undefineWhenDone(ID id) { fToUndefine.push_back(id); } | 79 void undefineWhenDone(ID id) { fToUndefine.push_back(id); } |
| 69 | 80 |
| 70 template <typename T> | 81 template <typename T> |
| 71 ID lookup(const T& val) { | 82 ID lookup(const T& val) { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 bool lookup(const Misc& misc, ID* id, LookupScope*) override { | 166 bool lookup(const Misc& misc, ID* id, LookupScope*) override { |
| 156 return always_cache_helper(misc, &fMisc, &fNextMisc, id); | 167 return always_cache_helper(misc, &fMisc, &fNextMisc, id); |
| 157 } | 168 } |
| 158 bool lookup(const SkPath& path, ID* id, LookupScope*) override { | 169 bool lookup(const SkPath& path, ID* id, LookupScope*) override { |
| 159 return always_cache_helper(path, &fPath, &fNextPath, id); | 170 return always_cache_helper(path, &fPath, &fNextPath, id); |
| 160 } | 171 } |
| 161 bool lookup(const Stroke& stroke, ID* id, LookupScope*) override { | 172 bool lookup(const Stroke& stroke, ID* id, LookupScope*) override { |
| 162 return always_cache_helper(stroke, &fStroke, &fNextStroke, id); | 173 return always_cache_helper(stroke, &fStroke, &fNextStroke, id); |
| 163 } | 174 } |
| 164 | 175 |
| 165 SkTHashMap<SkMatrix, ID> fMatrix; | 176 SkTHashMap<SkMatrix, ID> fMatrix; |
| 166 SkTHashMap<Misc, ID> fMisc; | 177 SkTHashMap<Misc, ID, MiscHash> fMisc; |
| 167 SkTHashMap<SkPath, ID> fPath; | 178 SkTHashMap<SkPath, ID> fPath; |
| 168 SkTHashMap<Stroke, ID> fStroke; | 179 SkTHashMap<Stroke, ID> fStroke; |
| 169 ID fNextMatrix, | 180 ID fNextMatrix, |
| 170 fNextMisc, | 181 fNextMisc, |
| 171 fNextPath, | 182 fNextPath, |
| 172 fNextStroke; | 183 fNextStroke; |
| 173 }; | 184 }; |
| 174 return new AlwaysCache; | 185 return new AlwaysCache; |
| 175 } | 186 } |
| 176 | 187 |
| 177 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // | 188 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // |
| 178 | 189 |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 } | 334 } |
| 324 void Server::strokePath(ID path, ID misc, ID stroke) { | 335 void Server::strokePath(ID path, ID misc, ID stroke) { |
| 325 SkPaint paint; | 336 SkPaint paint; |
| 326 paint.setStyle(SkPaint::kStroke_Style); | 337 paint.setStyle(SkPaint::kStroke_Style); |
| 327 fMisc .find(misc ).applyTo(&paint); | 338 fMisc .find(misc ).applyTo(&paint); |
| 328 fStroke.find(stroke).applyTo(&paint); | 339 fStroke.find(stroke).applyTo(&paint); |
| 329 fCanvas->drawPath(fPath.find(path), paint); | 340 fCanvas->drawPath(fPath.find(path), paint); |
| 330 } | 341 } |
| 331 | 342 |
| 332 } // namespace SkRemote | 343 } // namespace SkRemote |
| OLD | NEW |