OpenCoverage

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

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