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

Unified Diff: src/core/SkRemote.cpp

Issue 1409273006: SkRemote: fix Misc hash function. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: illegal sizeof 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkRemote.cpp
diff --git a/src/core/SkRemote.cpp b/src/core/SkRemote.cpp
index 1e86044a544a42aae14ed8cbb287ba9b27b9cf6d..3966aaccc0318afba694f8775f00fdb6617d4eb4 100644
--- a/src/core/SkRemote.cpp
+++ b/src/core/SkRemote.cpp
@@ -35,6 +35,14 @@ namespace SkRemote {
&& a.fDither == b.fDither;
}
+ // Misc carries 10 bytes of data in a 12 byte struct, so we need a custom hash.
+ static_assert(sizeof(Misc) > offsetof(Misc, fDither) + sizeof(Misc().fDither), "");
+ struct MiscHash {
+ uint32_t operator()(const Misc& misc) {
+ return SkChecksum::Murmur3(&misc, offsetof(Misc, fDither) + sizeof(Misc().fDither));
+ }
+ };
+
Stroke Stroke::CreateFrom(const SkPaint& paint) {
Stroke stroke = {
paint.getStrokeWidth(),
@@ -59,6 +67,9 @@ namespace SkRemote {
&& a.fJoin == b.fJoin;
}
+ // The default SkGoodHash works fine for Stroke, as it's dense.
+ static_assert(sizeof(Stroke) == offsetof(Stroke, fJoin) + sizeof(Stroke().fJoin), "");
+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
class LookupScope {
@@ -162,10 +173,10 @@ namespace SkRemote {
return always_cache_helper(stroke, &fStroke, &fNextStroke, id);
}
- SkTHashMap<SkMatrix, ID> fMatrix;
- SkTHashMap<Misc, ID> fMisc;
- SkTHashMap<SkPath, ID> fPath;
- SkTHashMap<Stroke, ID> fStroke;
+ SkTHashMap<SkMatrix, ID> fMatrix;
+ SkTHashMap<Misc, ID, MiscHash> fMisc;
+ SkTHashMap<SkPath, ID> fPath;
+ SkTHashMap<Stroke, ID> fStroke;
ID fNextMatrix,
fNextMisc,
fNextPath,
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698