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

Unified Diff: src/core/SkScaledImageCache.h

Issue 472343002: make imagecache's Key more general purpose (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: remove Key::operator< (unused) Created 6 years, 4 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 | src/core/SkScaledImageCache.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkScaledImageCache.h
diff --git a/src/core/SkScaledImageCache.h b/src/core/SkScaledImageCache.h
index 817147e3b81e7bd75fc954fb029ca8854572d379..19da6717a56c6d51462e409339b39e088f0235cb 100644
--- a/src/core/SkScaledImageCache.h
+++ b/src/core/SkScaledImageCache.h
@@ -27,6 +27,41 @@ class SkScaledImageCache {
public:
struct ID;
+ struct Key {
+ // Call this to access your private contents. Must not use the address after calling init()
+ void* writableContents() { return this + 1; }
+
+ // must call this after your private data has been written.
+ // length must be a multiple of 4
+ void init(size_t length);
+
+ // This is only valid after having called init().
+ uint32_t hash() const { return fHash; }
+
+ bool operator==(const Key& other) const {
+ const uint32_t* a = this->as32();
+ const uint32_t* b = other.as32();
+ for (int i = 0; i < fCount32; ++i) {
+ if (a[i] != b[i]) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ // delete using sk_free
+ Key* clone() const;
+
+ private:
+ // store fCount32 first, so we don't consider it in operator<
+ int32_t fCount32; // 2 + user contents count32
+ uint32_t fHash;
+ /* uint32_t fContents32[] */
+
+ const uint32_t* as32() const { return (const uint32_t*)this; }
+ const uint32_t* as32SkipCount() const { return this->as32() + 1; }
+ };
+
/**
* Returns a locked/pinned SkDiscardableMemory instance for the specified
* number of bytes, or NULL on failure.
@@ -173,7 +208,6 @@ public:
public:
struct Rec;
- struct Key;
private:
Rec* fHead;
Rec* fTail;
« no previous file with comments | « no previous file | src/core/SkScaledImageCache.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698