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

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: re-upload 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
« no previous file with comments | « gyp/tests.gyp ('k') | src/core/SkScaledImageCache.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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* returnedBitmap);
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* returnedBitmap);
36 static ID* FindAndLockMip(const SkBitmap& original, SkMipMap const**); 41 static ID* FindAndLockMip(const SkBitmap& original,
42 SkMipMap const** returnedMipMap);
43
44
45 static ID* AddAndLock(uint32_t pixelGenerationID,
46 int32_t width,
47 int32_t height,
48 const SkBitmap& bitmap);
37 49
38 static ID* AddAndLock(const SkBitmap& original, SkScalar scaleX, 50 static ID* AddAndLock(const SkBitmap& original, SkScalar scaleX,
39 SkScalar scaleY, const SkBitmap& scaled); 51 SkScalar scaleY, const SkBitmap& bitmap);
40 static ID* AddAndLockMip(const SkBitmap& original, const SkMipMap*); 52 static ID* AddAndLockMip(const SkBitmap& original, const SkMipMap* mipMap);
41 53
42 static void Unlock(ID*); 54 static void Unlock(ID*);
43 55
44 static size_t GetBytesUsed(); 56 static size_t GetBytesUsed();
45 static size_t GetByteLimit(); 57 static size_t GetByteLimit();
46 static size_t SetByteLimit(size_t newLimit); 58 static size_t SetByteLimit(size_t newLimit);
47 59
48 /////////////////////////////////////////////////////////////////////////// 60 ///////////////////////////////////////////////////////////////////////////
49 61
50 SkScaledImageCache(size_t byteLimit); 62 SkScaledImageCache(size_t byteLimit);
51 ~SkScaledImageCache(); 63 ~SkScaledImageCache();
52 64
53 /** 65 /**
54 * Search the cache for a scaled version of original. If found, return it 66 * Search the cache for a matching bitmap (using generationID,
55 * in scaled, and return its ID pointer. Use the returned ptr to unlock 67 * width, and height as a search key). If found, return it in
56 * the cache when you are done using scaled. 68 * returnedBitmap, and return its ID pointer. Use the returned
69 * ptr to unlock the cache when you are done using
70 * returnedBitmap.
57 * 71 *
58 * If a match is not found, scaled will be unmodifed, and NULL will be 72 * If a match is not found, returnedBitmap will be unmodifed, and
59 * returned. 73 * NULL will be returned.
74 *
75 * This is used if there is no scaling or subsetting, for example
76 * by SkLazyPixelRef.
77 */
78 ID* findAndLock(uint32_t pixelGenerationID, int32_t width, int32_t height,
79 SkBitmap* returnedBitmap);
80
81 /**
82 * Search the cache for a scaled version of original. If found,
83 * return it in returnedBitmap, and return its ID pointer. Use
84 * the returned ptr to unlock the cache when you are done using
85 * returnedBitmap.
86 *
87 * If a match is not found, returnedBitmap will be unmodifed, and
88 * NULL will be returned.
60 */ 89 */
61 ID* findAndLock(const SkBitmap& original, SkScalar scaleX, 90 ID* findAndLock(const SkBitmap& original, SkScalar scaleX,
62 SkScalar scaleY, SkBitmap* scaled); 91 SkScalar scaleY, SkBitmap* returnedBitmap);
63 ID* findAndLockMip(const SkBitmap& original, SkMipMap const**); 92 ID* findAndLockMip(const SkBitmap& original,
93 SkMipMap const** returnedMipMap);
64 94
65 /** 95 /**
66 * To add a new (scaled) bitmap to the cache, call AddAndLock. Use the 96 * To add a new bitmap (or mipMap) to the cache, call
67 * returned ptr to unlock the cache when you are done using scaled. 97 * AddAndLock. Use the returned ptr to unlock the cache when you
98 * are done using scaled.
99 *
100 * Use (generationID, width, and height) or (original, scaleX,
101 * scaleY) or (original) as a search key
68 */ 102 */
103 ID* addAndLock(uint32_t pixelGenerationID, int32_t width, int32_t height,
104 const SkBitmap& bitmap);
69 ID* addAndLock(const SkBitmap& original, SkScalar scaleX, 105 ID* addAndLock(const SkBitmap& original, SkScalar scaleX,
70 SkScalar scaleY, const SkBitmap& scaled); 106 SkScalar scaleY, const SkBitmap& bitmap);
71 ID* addAndLockMip(const SkBitmap& original, const SkMipMap*); 107 ID* addAndLockMip(const SkBitmap& original, const SkMipMap* mipMap);
72 108
73 /** 109 /**
74 * Given a non-null ID ptr returned by either findAndLock or addAndLock, 110 * Given a non-null ID ptr returned by either findAndLock or addAndLock,
75 * this releases the associated resources to be available to be purged 111 * this releases the associated resources to be available to be purged
76 * if needed. After this, the cached bitmap should no longer be 112 * if needed. After this, the cached bitmap should no longer be
77 * referenced by the caller. 113 * referenced by the caller.
78 */ 114 */
79 void unlock(ID*); 115 void unlock(ID*);
80 116
81 size_t getBytesUsed() const { return fBytesUsed; } 117 size_t getBytesUsed() const { return fBytesUsed; }
(...skipping 12 matching lines...) Expand all
94 Rec* fHead; 130 Rec* fHead;
95 Rec* fTail; 131 Rec* fTail;
96 132
97 class Hash; 133 class Hash;
98 Hash* fHash; 134 Hash* fHash;
99 135
100 size_t fBytesUsed; 136 size_t fBytesUsed;
101 size_t fByteLimit; 137 size_t fByteLimit;
102 int fCount; 138 int fCount;
103 139
104 Rec* findAndLock(const SkBitmap& original, SkScalar sx, SkScalar sy); 140 Rec* findAndLock(uint32_t generationID, SkScalar sx, SkScalar sy,
141 const SkIRect& bounds);
142 void addAndLock(Rec* rec);
105 143
106 void purgeAsNeeded(); 144 void purgeAsNeeded();
107 145
108 // linklist management 146 // linklist management
109 void moveToHead(Rec*); 147 void moveToHead(Rec*);
110 void addToHead(Rec*); 148 void addToHead(Rec*);
111 void detach(Rec*); 149 void detach(Rec*);
112 #ifdef SK_DEBUG 150 #ifdef SK_DEBUG
113 void validate() const; 151 void validate() const;
114 #else 152 #else
115 void validate() const {} 153 void validate() const {}
116 #endif 154 #endif
117 }; 155 };
118
119 #endif 156 #endif
OLDNEW
« no previous file with comments | « gyp/tests.gyp ('k') | src/core/SkScaledImageCache.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698