qpixmapcache.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/image/qpixmapcache.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3static int cache_limit = 10240;-
4QPixmapCache::Key::Key() : d(0)-
5{-
6}
never executed: end of block
0
7-
8-
9-
10-
11-
12QPixmapCache::Key::Key(const Key &other)-
13{-
14 if (other.d
other.dDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
15 ++(
never executed: ++(other.d->ref);
other.d->ref);
never executed: ++(other.d->ref);
0
16 d = other.d;-
17}
never executed: end of block
0
18-
19-
20-
21-
22QPixmapCache::Key::~Key()-
23{-
24 if (d
dDescription
TRUEnever evaluated
FALSEnever evaluated
&& --(
--(d->ref) == 0Description
TRUEnever evaluated
FALSEnever evaluated
d->ref) == 0
--(d->ref) == 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
25 delete d;
never executed: delete d;
0
26}
never executed: end of block
0
27-
28-
29-
30-
31-
32-
33-
34bool QPixmapCache::Key::operator ==(const Key &key) const-
35{-
36 return
never executed: return (d == key.d);
(d == key.d);
never executed: return (d == key.d);
0
37}-
38QPixmapCache::Key &QPixmapCache::Key::operator =(const Key &other)-
39{-
40 if (d != other.d
d != other.dDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
41 if (other.d
other.dDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
42 ++(
never executed: ++(other.d->ref);
other.d->ref);
never executed: ++(other.d->ref);
0
43 if (d
dDescription
TRUEnever evaluated
FALSEnever evaluated
&& --(
--(d->ref) == 0Description
TRUEnever evaluated
FALSEnever evaluated
d->ref) == 0
--(d->ref) == 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
44 delete d;
never executed: delete d;
0
45 d = other.d;-
46 }
never executed: end of block
0
47 return
never executed: return *this;
*this;
never executed: return *this;
0
48}-
49-
50class QPMCache : public QObject, public QCache<QPixmapCache::Key, QPixmapCacheEntry>-
51{-
52 public: template <typename ThisObject> inline void qt_check_for_QOBJECT_macro(const ThisObject &_q_argument) const { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i + 1; }-
53#pragma GCC diagnostic push-
54 static const QMetaObject staticMetaObject; virtual const QMetaObject *metaObject() const; virtual void *qt_metacast(const char *); virtual int qt_metacall(QMetaObject::Call, int, void **); static inline QString tr(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } __attribute__ ((__deprecated__)) static inline QString trUtf8(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } private: __attribute__((visibility("hidden"))) static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **);-
55#pragma GCC diagnostic pop-
56 struct QPrivateSignal {};-
57public:-
58 QPMCache();-
59 ~QPMCache();-
60-
61 void timerEvent(QTimerEvent *) override;-
62 bool insert(const QString& key, const QPixmap &pixmap, int cost);-
63 QPixmapCache::Key insert(const QPixmap &pixmap, int cost);-
64 bool replace(const QPixmapCache::Key &key, const QPixmap &pixmap, int cost);-
65 bool remove(const QString &key);-
66 bool remove(const QPixmapCache::Key &key);-
67-
68 void resizeKeyArray(int size);-
69 QPixmapCache::Key createKey();-
70 void releaseKey(const QPixmapCache::Key &key);-
71 void clear();-
72-
73 QPixmap *object(const QString &key) const;-
74 QPixmap *object(const QPixmapCache::Key &key) const;-
75-
76 static inline QPixmapCache::KeyData *get(const QPixmapCache::Key &key)-
77 {return
never executed: return key.d;
key.d;
never executed: return key.d;
}
0
78-
79 static QPixmapCache::KeyData* getKeyData(QPixmapCache::Key *key);-
80-
81 bool flushDetachedPixmaps(bool nt);-
82-
83private:-
84 enum { soon_time = 10000, flush_time = 30000 };-
85 int *keyArray;-
86 int theid;-
87 int ps;-
88 int keyArraySize;-
89 int freeKey;-
90 QHash<QString, QPixmapCache::Key> cacheKeys;-
91 bool t;-
92};-
93-
94-
95-
96-
97uint qHash(const QPixmapCache::Key &k)-
98{-
99 return
never executed: return qHash(QPMCache::get(k)->key);
qHash(QPMCache::get(k)->key);
never executed: return qHash(QPMCache::get(k)->key);
0
100}-
101-
102QPMCache::QPMCache()-
103 : QObject(0),-
104 QCache<QPixmapCache::Key, QPixmapCacheEntry>(cache_limit * 1024),-
105 keyArray(0), theid(0), ps(0), keyArraySize(0), freeKey(0), t(false)-
106{-
107}
never executed: end of block
0
108QPMCache::~QPMCache()-
109{-
110 clear();-
111 free(keyArray);-
112}
never executed: end of block
0
113bool QPMCache::flushDetachedPixmaps(bool nt)-
114{-
115 int mc = maxCost();-
116 setMaxCost(nt ? totalCost() * 3 / 4 : totalCost() -1);-
117 setMaxCost(mc);-
118 ps = totalCost();-
119-
120 bool any = false;-
121 QHash<QString, QPixmapCache::Key>::iterator it = cacheKeys.begin();-
122 while (it != cacheKeys.end()
it != cacheKeys.end()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
123 if (!contains(it.value())
!contains(it.value())Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
124 releaseKey(it.value());-
125 it = cacheKeys.erase(it);-
126 any = true;-
127 }
never executed: end of block
else {
0
128 ++it;-
129 }
never executed: end of block
0
130 }-
131-
132 return
never executed: return any;
any;
never executed: return any;
0
133}-
134-
135void QPMCache::timerEvent(QTimerEvent *)-
136{-
137 bool nt = totalCost() == ps;-
138 if (!flushDetachedPixmaps(nt)
!flushDetachedPixmaps(nt)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
139 killTimer(theid);-
140 theid = 0;-
141 }
never executed: end of block
else if (nt != t
nt != tDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
142 killTimer(theid);-
143 theid = startTimer(nt ? soon_time : flush_time);-
144 t = nt;-
145 }
never executed: end of block
0
146}
never executed: end of block
0
147-
148-
149QPixmap *QPMCache::object(const QString &key) const-
150{-
151 QPixmapCache::Key cacheKey = cacheKeys.value(key);-
152 if (!cacheKey.d
!cacheKey.dDescription
TRUEnever evaluated
FALSEnever evaluated
|| !cacheKey.d->isValid
!cacheKey.d->isValidDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
153 const_cast<QPMCache *>(this)->cacheKeys.remove(key);-
154 return
never executed: return 0;
0;
never executed: return 0;
0
155 }-
156 QPixmap *ptr = QCache<QPixmapCache::Key, QPixmapCacheEntry>::object(cacheKey);-
157-
158 if (!ptr
!ptrDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
159 const_cast<QPMCache *>(this)->cacheKeys.remove(key);-
160 }
never executed: end of block
0
161 return
never executed: return ptr;
ptr;
never executed: return ptr;
0
162}-
163-
164QPixmap *QPMCache::object(const QPixmapCache::Key &key) const-
165{-
166 ((!(key.d->isValid)) ? qt_assert("key.d->isValid",__FILE__,301) : qt_noop());-
167 QPixmap *ptr = QCache<QPixmapCache::Key, QPixmapCacheEntry>::object(key);-
168-
169 if (!ptr
!ptrDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
170 const_cast<
never executed: const_cast<QPMCache *>(this)->releaseKey(key);
QPMCache *>(this)->releaseKey(key);
never executed: const_cast<QPMCache *>(this)->releaseKey(key);
0
171 return
never executed: return ptr;
ptr;
never executed: return ptr;
0
172}-
173-
174bool QPMCache::insert(const QString& key, const QPixmap &pixmap, int cost)-
175{-
176 QPixmapCache::Key cacheKey;-
177 QPixmapCache::Key oldCacheKey = cacheKeys.value(key);-
178-
179 if (oldCacheKey.d
oldCacheKey.dDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
180 QCache<QPixmapCache::Key, QPixmapCacheEntry>::remove(oldCacheKey);-
181 cacheKeys.remove(key);-
182 }
never executed: end of block
0
183-
184-
185 cacheKey = createKey();-
186-
187 bool success = QCache<QPixmapCache::Key, QPixmapCacheEntry>::insert(cacheKey, new QPixmapCacheEntry(cacheKey, pixmap), cost);-
188 if (success
successDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
189 cacheKeys.insert(key, cacheKey);-
190 if (!theid
!theidDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
191 theid = startTimer(flush_time);-
192 t = false;-
193 }
never executed: end of block
0
194 }
never executed: end of block
else {
0
195-
196 releaseKey(cacheKey);-
197 }
never executed: end of block
0
198 return
never executed: return success;
success;
never executed: return success;
0
199}-
200-
201QPixmapCache::Key QPMCache::insert(const QPixmap &pixmap, int cost)-
202{-
203 QPixmapCache::Key cacheKey = createKey();-
204 bool success = QCache<QPixmapCache::Key, QPixmapCacheEntry>::insert(cacheKey, new QPixmapCacheEntry(cacheKey, pixmap), cost);-
205 if (success
successDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
206 if (!theid
!theidDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
207 theid = startTimer(flush_time);-
208 t = false;-
209 }
never executed: end of block
0
210 }
never executed: end of block
else {
0
211-
212 releaseKey(cacheKey);-
213 }
never executed: end of block
0
214 return
never executed: return cacheKey;
cacheKey;
never executed: return cacheKey;
0
215}-
216-
217bool QPMCache::replace(const QPixmapCache::Key &key, const QPixmap &pixmap, int cost)-
218{-
219 ((!(key.d->isValid)) ? qt_assert("key.d->isValid",__FILE__,354) : qt_noop());-
220-
221 QCache<QPixmapCache::Key, QPixmapCacheEntry>::remove(key);-
222-
223 QPixmapCache::Key cacheKey = createKey();-
224-
225 bool success = QCache<QPixmapCache::Key, QPixmapCacheEntry>::insert(cacheKey, new QPixmapCacheEntry(cacheKey, pixmap), cost);-
226 if (success
successDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
227 if(!theid
!theidDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
228 theid = startTimer(flush_time);-
229 t = false;-
230 }
never executed: end of block
0
231 const_cast<QPixmapCache::Key&>(key) = cacheKey;-
232 }
never executed: end of block
else {
0
233-
234 releaseKey(cacheKey);-
235 }
never executed: end of block
0
236 return
never executed: return success;
success;
never executed: return success;
0
237}-
238-
239bool QPMCache::remove(const QString &key)-
240{-
241 QPixmapCache::Key cacheKey = cacheKeys.value(key);-
242-
243 if (!cacheKey.d
!cacheKey.dDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
244 return
never executed: return false;
false;
never executed: return false;
0
245 cacheKeys.remove(key);-
246 return
never executed: return QCache<QPixmapCache::Key, QPixmapCacheEntry>::remove(cacheKey);
QCache<QPixmapCache::Key, QPixmapCacheEntry>::remove(cacheKey);
never executed: return QCache<QPixmapCache::Key, QPixmapCacheEntry>::remove(cacheKey);
0
247}-
248-
249bool QPMCache::remove(const QPixmapCache::Key &key)-
250{-
251 return
never executed: return QCache<QPixmapCache::Key, QPixmapCacheEntry>::remove(key);
QCache<QPixmapCache::Key, QPixmapCacheEntry>::remove(key);
never executed: return QCache<QPixmapCache::Key, QPixmapCacheEntry>::remove(key);
0
252}-
253-
254void QPMCache::resizeKeyArray(int size)-
255{-
256 if (size <= keyArraySize
size <= keyArraySizeDescription
TRUEnever evaluated
FALSEnever evaluated
|| size == 0
size == 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
257 return;
never executed: return;
0
258 keyArray = q_check_ptr(reinterpret_cast<int *>(realloc(keyArray,-
259 size * sizeof(int))));-
260 for (int i = keyArraySize; i != size
i != sizeDescription
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
261 keyArray[i] = i + 1;
never executed: keyArray[i] = i + 1;
0
262 keyArraySize = size;-
263}
never executed: end of block
0
264-
265QPixmapCache::Key QPMCache::createKey()-
266{-
267 if (freeKey == keyArraySize
freeKey == keyArraySizeDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
268 resizeKeyArray(keyArraySize ? keyArraySize << 1 : 2);
never executed: resizeKeyArray(keyArraySize ? keyArraySize << 1 : 2);
0
269 int id = freeKey;-
270 freeKey = keyArray[id];-
271 QPixmapCache::Key key;-
272 QPixmapCache::KeyData *d = QPMCache::getKeyData(&key);-
273 d->key = ++id;-
274 return
never executed: return key;
key;
never executed: return key;
0
275}-
276-
277void QPMCache::releaseKey(const QPixmapCache::Key &key)-
278{-
279 if (key.d->key > keyArraySize
key.d->key > keyArraySizeDescription
TRUEnever evaluated
FALSEnever evaluated
|| key.d->key <= 0
key.d->key <= 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
280 return;
never executed: return;
0
281 key.d->key--;-
282 keyArray[key.d->key] = freeKey;-
283 freeKey = key.d->key;-
284 key.d->isValid = false;-
285 key.d->key = 0;-
286}
never executed: end of block
0
287-
288void QPMCache::clear()-
289{-
290 free(keyArray);-
291 keyArray = 0;-
292 freeKey = 0;-
293 keyArraySize = 0;-
294-
295 QList<QPixmapCache::Key> keys = QCache<QPixmapCache::Key, QPixmapCacheEntry>::keys();-
296 for (int i = 0; i < keys.size()
i < keys.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
297 keys.at(i).d->isValid = false;
never executed: keys.at(i).d->isValid = false;
0
298 QCache<QPixmapCache::Key, QPixmapCacheEntry>::clear();-
299}
never executed: end of block
0
300-
301QPixmapCache::KeyData* QPMCache::getKeyData(QPixmapCache::Key *key)-
302{-
303 if (!key->d
!key->dDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
304 key->d = new QPixmapCache::KeyData;
never executed: key->d = new QPixmapCache::KeyData;
0
305 return
never executed: return key->d;
key->d;
never executed: return key->d;
0
306}-
307-
308namespace { namespace Q_QGS_pm_cache { typedef QPMCache Type; QBasicAtomicInt guard = { QtGlobalStatic::Uninitialized }; __attribute__((visibility("hidden"))) inline Type *innerFunction() { struct HolderBase { ~HolderBase() noexcept { if (guard.load() == QtGlobalStatic::Initialized
guard.load() =...c::InitializedDescription
TRUEnever evaluated
FALSEnever evaluated
) guard.store(QtGlobalStatic::Destroyed);
never executed: guard.store(QtGlobalStatic::Destroyed);
}
never executed: end of block
}; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type ())) : value () { guard.store(QtGlobalStatic::Initialized); } } holder; return
never executed: return &holder.value;
&holder.value;
never executed: return &holder.value;
} } } static QGlobalStatic<QPMCache, Q_QGS_pm_cache::innerFunction, Q_QGS_pm_cache::guard> pm_cache;
0
309-
310int __attribute__((visibility("default"))) q_QPixmapCache_keyHashSize()-
311{-
312 return
never executed: return pm_cache()->size();
pm_cache()->size();
never executed: return pm_cache()->size();
0
313}-
314-
315QPixmapCacheEntry::~QPixmapCacheEntry()-
316{-
317 pm_cache()->releaseKey(key);-
318}
never executed: end of block
0
319QPixmap *QPixmapCache::find(const QString &key)-
320{-
321 return
never executed: return pm_cache()->object(key);
pm_cache()->object(key);
never executed: return pm_cache()->object(key);
0
322}-
323bool QPixmapCache::find(const QString &key, QPixmap& pixmap)-
324{-
325 return
never executed: return find(key, &pixmap);
find(key, &pixmap);
never executed: return find(key, &pixmap);
0
326}-
327bool QPixmapCache::find(const QString &key, QPixmap* pixmap)-
328{-
329 QPixmap *ptr = pm_cache()->object(key);-
330 if (ptr
ptrDescription
TRUEnever evaluated
FALSEnever evaluated
&& pixmap
pixmapDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
331 *
never executed: *pixmap = *ptr;
pixmap = *ptr;
never executed: *pixmap = *ptr;
0
332 return
never executed: return ptr != 0;
ptr != 0;
never executed: return ptr != 0;
0
333}-
334bool QPixmapCache::find(const Key &key, QPixmap* pixmap)-
335{-
336-
337 if (!key.d
!key.dDescription
TRUEnever evaluated
FALSEnever evaluated
|| !key.d->isValid
!key.d->isValidDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
338 return
never executed: return false;
false;
never executed: return false;
0
339 QPixmap *ptr = pm_cache()->object(key);-
340 if (ptr
ptrDescription
TRUEnever evaluated
FALSEnever evaluated
&& pixmap
pixmapDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
341 *
never executed: *pixmap = *ptr;
pixmap = *ptr;
never executed: *pixmap = *ptr;
0
342 return
never executed: return ptr != 0;
ptr != 0;
never executed: return ptr != 0;
0
343}-
344bool QPixmapCache::insert(const QString &key, const QPixmap &pixmap)-
345{-
346 return
never executed: return pm_cache()->insert(key, pixmap, pixmap.width() * pixmap.height() * pixmap.depth() / 8);
pm_cache()->insert(key, pixmap, pixmap.width() * pixmap.height() * pixmap.depth() / 8);
never executed: return pm_cache()->insert(key, pixmap, pixmap.width() * pixmap.height() * pixmap.depth() / 8);
0
347}-
348QPixmapCache::Key QPixmapCache::insert(const QPixmap &pixmap)-
349{-
350 return
never executed: return pm_cache()->insert(pixmap, pixmap.width() * pixmap.height() * pixmap.depth() / 8);
pm_cache()->insert(pixmap, pixmap.width() * pixmap.height() * pixmap.depth() / 8);
never executed: return pm_cache()->insert(pixmap, pixmap.width() * pixmap.height() * pixmap.depth() / 8);
0
351}-
352bool QPixmapCache::replace(const Key &key, const QPixmap &pixmap)-
353{-
354-
355 if (!key.d
!key.dDescription
TRUEnever evaluated
FALSEnever evaluated
|| !key.d->isValid
!key.d->isValidDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
356 return
never executed: return false;
false;
never executed: return false;
0
357 return
never executed: return pm_cache()->replace(key, pixmap, pixmap.width() * pixmap.height() * pixmap.depth() / 8);
pm_cache()->replace(key, pixmap, pixmap.width() * pixmap.height() * pixmap.depth() / 8);
never executed: return pm_cache()->replace(key, pixmap, pixmap.width() * pixmap.height() * pixmap.depth() / 8);
0
358}-
359int QPixmapCache::cacheLimit()-
360{-
361 return
never executed: return cache_limit;
cache_limit;
never executed: return cache_limit;
0
362}-
363void QPixmapCache::setCacheLimit(int n)-
364{-
365 cache_limit = n;-
366 pm_cache()->setMaxCost(1024 * cache_limit);-
367}
never executed: end of block
0
368-
369-
370-
371-
372void QPixmapCache::remove(const QString &key)-
373{-
374 pm_cache()->remove(key);-
375}
never executed: end of block
0
376-
377-
378-
379-
380-
381-
382-
383void QPixmapCache::remove(const Key &key)-
384{-
385-
386 if (!key.d
!key.dDescription
TRUEnever evaluated
FALSEnever evaluated
|| !key.d->isValid
!key.d->isValidDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
387 return;
never executed: return;
0
388 pm_cache()->remove(key);-
389}
never executed: end of block
0
390-
391-
392-
393-
394-
395void QPixmapCache::clear()-
396{-
397 if (true) {-
398 if (pm_cache.exists()
pm_cache.exists()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
399 pm_cache->clear();
never executed: pm_cache->clear();
0
400 }
never executed: end of block
else {
dead code: { }
-
401-
402-
403 }
dead code: { }
-
404}-
405-
406void QPixmapCache::flushDetachedPixmaps()-
407{-
408 pm_cache()->flushDetachedPixmaps(true);-
409}
never executed: end of block
0
410-
411int QPixmapCache::totalUsed()-
412{-
413 return
never executed: return (pm_cache()->totalCost()+1023) / 1024;
(pm_cache()->totalCost()+1023) / 1024;
never executed: return (pm_cache()->totalCost()+1023) / 1024;
0
414}-
415-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9