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

Side by Side Diff: src/core/SkScaledImageCache.h

Issue 37343002: Allow SkLazyPixelRef to use SkScaledImageCache (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: lint Created 7 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 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 #ifndef SkScaledImageCache_DEFINED 8 #ifndef SkScaledImageCache_DEFINED
9 #define SkScaledImageCache_DEFINED 9 #define SkScaledImageCache_DEFINED
10 10
(...skipping 13 matching lines...) Expand all
24 */ 24 */
25 class SkScaledImageCache { 25 class SkScaledImageCache {
26 public: 26 public:
27 struct ID; 27 struct ID;
28 28
29 /* 29 /*
30 * The following static methods are thread-safe wrappers around a global 30 * The following static methods are thread-safe wrappers around a global
31 * instance of this cache. 31 * instance of this cache.
32 */ 32 */
33 33
34 static ID* FindAndLock(uint32_t pixelGenerationID,
35 int32_t width,
36 int32_t height,
37 SkBitmap* scaled);
reed1 2013/10/25 18:09:47 rename this last param? (since we're not scaling)
scroggo 2013/10/25 18:09:48 returnedBitmap?
hal.canary 2013/10/25 20:49:38 Done.
hal.canary 2013/10/25 20:49:38 Done.
38
34 static ID* FindAndLock(const SkBitmap& original, SkScalar scaleX, 39 static ID* FindAndLock(const SkBitmap& original, SkScalar scaleX,
35 SkScalar scaleY, SkBitmap* scaled); 40 SkScalar scaleY, SkBitmap* scaled);
36 static ID* FindAndLockMip(const SkBitmap& original, SkMipMap const**); 41 static ID* FindAndLockMip(const SkBitmap& original, SkMipMap const**);
37 42
43
44 static ID* AddAndLock(uint32_t pixelGenerationID,
45 int32_t width,
46 int32_t height,
47 const SkBitmap& scaled);
48
38 static ID* AddAndLock(const SkBitmap& original, SkScalar scaleX, 49 static ID* AddAndLock(const SkBitmap& original, SkScalar scaleX,
39 SkScalar scaleY, const SkBitmap& scaled); 50 SkScalar scaleY, const SkBitmap& scaled);
40 static ID* AddAndLockMip(const SkBitmap& original, const SkMipMap*); 51 static ID* AddAndLockMip(const SkBitmap& original, const SkMipMap*);
41 52
42 static void Unlock(ID*); 53 static void Unlock(ID*);
43 54
44 static size_t GetBytesUsed(); 55 static size_t GetBytesUsed();
45 static size_t GetByteLimit(); 56 static size_t GetByteLimit();
46 static size_t SetByteLimit(size_t newLimit); 57 static size_t SetByteLimit(size_t newLimit);
47 58
48 /////////////////////////////////////////////////////////////////////////// 59 ///////////////////////////////////////////////////////////////////////////
49 60
50 SkScaledImageCache(size_t byteLimit); 61 SkScaledImageCache(size_t byteLimit);
51 ~SkScaledImageCache(); 62 ~SkScaledImageCache();
52 63
53 /** 64 /**
54 * Search the cache for a scaled version of original. If found, return it 65 * Search the cache for a matching bitmap (using generationID,
55 * in scaled, and return its ID pointer. Use the returned ptr to unlock 66 * width, and height as a search key). If found, return it in
56 * the cache when you are done using scaled. 67 * returnedBitmap, and return its ID pointer. Use the returned
68 * ptr to unlock the cache when you are done using
69 * returnedBitmap.
57 * 70 *
58 * If a match is not found, scaled will be unmodifed, and NULL will be 71 * If a match is not found, returnedBitmap will be unmodifed, and
59 * returned. 72 * NULL will be returned.
73 *
74 * This is used if there is no scaling or subsetting, for example
75 * by SkLazyPixelRef.
76 */
77 ID* findAndLock(uint32_t pixelGenerationID, int32_t width, int32_t height,
78 SkBitmap* returnedBitmap);
79
80 /**
81 * Search the cache for a scaled version of original. If found,
82 * return it in returnedBitmap, and return its ID pointer. Use
83 * the returned ptr to unlock the cache when you are done using
84 * returnedBitmap.
85 *
86 * If a match is not found, returnedBitmap will be unmodifed, and
87 * NULL will be returned.
60 */ 88 */
61 ID* findAndLock(const SkBitmap& original, SkScalar scaleX, 89 ID* findAndLock(const SkBitmap& original, SkScalar scaleX,
62 SkScalar scaleY, SkBitmap* scaled); 90 SkScalar scaleY, SkBitmap* returnedBitmap);
63 ID* findAndLockMip(const SkBitmap& original, SkMipMap const**); 91 ID* findAndLockMip(const SkBitmap& original,
92 SkMipMap const** returnedMipMap);
64 93
65 /** 94 /**
66 * To add a new (scaled) bitmap to the cache, call AddAndLock. Use the 95 * To add a new bitmap (or mipMap) to the cache, call
67 * returned ptr to unlock the cache when you are done using scaled. 96 * AddAndLock. Use the returned ptr to unlock the cache when you
97 * are done using scaled.
98 *
99 * Use (generationID, width, and height) or (original, scaleX,
100 * scaleY) or (original) as a search key
68 */ 101 */
102 ID* addAndLock(uint32_t pixelGenerationID, int32_t width, int32_t height,
103 const SkBitmap& bitmap);
69 ID* addAndLock(const SkBitmap& original, SkScalar scaleX, 104 ID* addAndLock(const SkBitmap& original, SkScalar scaleX,
70 SkScalar scaleY, const SkBitmap& scaled); 105 SkScalar scaleY, const SkBitmap& bitmap);
71 ID* addAndLockMip(const SkBitmap& original, const SkMipMap*); 106 ID* addAndLockMip(const SkBitmap& original, const SkMipMap* mipMap);
72 107
73 /** 108 /**
74 * Given a non-null ID ptr returned by either findAndLock or addAndLock, 109 * Given a non-null ID ptr returned by either findAndLock or addAndLock,
75 * this releases the associated resources to be available to be purged 110 * this releases the associated resources to be available to be purged
76 * if needed. After this, the cached bitmap should no longer be 111 * if needed. After this, the cached bitmap should no longer be
77 * referenced by the caller. 112 * referenced by the caller.
78 */ 113 */
79 void unlock(ID*); 114 void unlock(ID*);
80 115
81 size_t getBytesUsed() const { return fBytesUsed; } 116 size_t getBytesUsed() const { return fBytesUsed; }
(...skipping 12 matching lines...) Expand all
94 Rec* fHead; 129 Rec* fHead;
95 Rec* fTail; 130 Rec* fTail;
96 131
97 class Hash; 132 class Hash;
98 Hash* fHash; 133 Hash* fHash;
99 134
100 size_t fBytesUsed; 135 size_t fBytesUsed;
101 size_t fByteLimit; 136 size_t fByteLimit;
102 int fCount; 137 int fCount;
103 138
104 Rec* findAndLock(const SkBitmap& original, SkScalar sx, SkScalar sy); 139 Rec* findAndLock(uint32_t generationID, SkScalar sx, SkScalar sy,
140 const SkIRect& bounds);
141 void addAndLock(Rec* rec);
105 142
106 void purgeAsNeeded(); 143 void purgeAsNeeded();
107 144
108 // linklist management 145 // linklist management
109 void moveToHead(Rec*); 146 void moveToHead(Rec*);
110 void addToHead(Rec*); 147 void addToHead(Rec*);
111 void detach(Rec*); 148 void detach(Rec*);
112 #ifdef SK_DEBUG 149 #ifdef SK_DEBUG
113 void validate() const; 150 void validate() const;
114 #else 151 #else
115 void validate() const {} 152 void validate() const {}
116 #endif 153 #endif
117 }; 154 };
118
119 #endif 155 #endif
OLDNEW
« no previous file with comments | « gyp/tests.gyp ('k') | src/core/SkScaledImageCache.cpp » ('j') | src/core/SkScaledImageCache.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698