~ubuntu-branches/ubuntu/oneiric/koffice/oneiric-updates

« back to all changes in this revision

Viewing changes to krita/image/tiles3/kis_tile_data_store.h

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2010-10-27 17:52:57 UTC
  • mfrom: (0.12.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20101027175257-s04zqqk5bs8ckm9o
Tags: 1:2.2.83-0ubuntu1
* Merge with Debian git remaining changes:
 - Add build-deps on librcps-dev, opengtl-dev, libqtgtl-dev, freetds-dev,
   create-resources, libspnav-dev
 - Remove needless build-dep on libwv2-dev
 - koffice-libs recommends create-resources
 - krita recommends pstoedit
 - Keep our patches
* New upstream release 2.3 beta 3
  - Remove debian/patches fixed by upstream
  - Update install files

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
#ifndef KIS_TILE_DATA_STORE_H_
19
19
#define KIS_TILE_DATA_STORE_H_
20
20
 
 
21
#include "krita_export.h"
21
22
 
22
23
#include <QReadWriteLock>
23
 
#include "kis_tile_data.h"
 
24
#include "kis_tile_data_interface.h"
24
25
 
25
26
#include "kis_tile_data_pooler.h"
 
27
#include "swap/kis_tile_data_swapper.h"
 
28
#include "swap/kis_swapped_data_store.h"
26
29
 
 
30
class KisTileDataStoreIterator;
 
31
class KisTileDataStoreReverseIterator;
 
32
class KisTileDataStoreClockIterator;
27
33
 
28
34
/**
29
35
 * Stores tileData objects. When needed compresses them and swaps.
30
36
 */
31
 
class KisTileDataStore
 
37
class KRITAIMAGE_EXPORT KisTileDataStore
32
38
{
 
39
private:
 
40
    KisTileDataStore();
 
41
 
33
42
public:
34
 
    KisTileDataStore();
 
43
    static KisTileDataStore* instance();
 
44
 
35
45
    ~KisTileDataStore();
36
46
 
37
47
    void debugPrintList();
38
48
 
39
 
    void ensureTileDataLoaded(const KisTileData *td);
40
 
    KisTileData *duplicateTileData(KisTileData *rhs);
41
 
 
42
 
 
43
 
    /**
44
 
     * Increments usersCount of a TD and refs shared pointer counter
45
 
     * Used by KisTile for COW
46
 
     */
47
 
    inline quint32 acquireTileData(const KisTileData *td) const {
48
 
        qint32 ref = refTileData(td);
49
 
        td->m_usersCount.ref();
50
 
        return ref;
51
 
    }
52
 
 
53
 
    /**
54
 
     * Decrements usersCount of a TD and derefs shared pointer counter
55
 
     * Used by KisTile for COW
56
 
     */
57
 
    inline quint32 releaseTileData(KisTileData *td) {
58
 
        td->m_usersCount.deref();
59
 
        qint32 ref = derefTileData(td);
60
 
        return ref;
61
 
    }
62
 
 
63
 
    /**
64
 
     * Only refs shared pointer counter.
65
 
     * Used only by KisMementoManager without
66
 
     * consideration of COW.
67
 
     */
68
 
    inline quint32 refTileData(const KisTileData *td) const {
69
 
        return td->m_refCount.ref();
70
 
    }
71
 
 
72
 
    /**
73
 
     * Only refs shared pointer counter.
74
 
     * Used only by KisMementoManager without
75
 
     * consideration of COW.
76
 
     */
77
 
    inline quint32 derefTileData(KisTileData *td) {
78
 
        if (!(td->m_refCount.deref())) {
79
 
            freeTileData(td);
80
 
            return 0;
81
 
        }
82
 
        return td->m_refCount;
83
 
    }
 
49
    /**
 
50
     * Returns total number of tiles present: in memory
 
51
     * or in a swap file
 
52
     */
 
53
    inline qint32 numTiles() const {
 
54
        return m_numTiles + m_swappedStore.numTiles();
 
55
    }
 
56
 
 
57
    /**
 
58
     * Returns the number of tiles present in memory only
 
59
     */
 
60
    inline qint32 numTilesInMemory() const {
 
61
        return m_numTiles;
 
62
    }
 
63
 
 
64
    inline void checkFreeMemory() {
 
65
        m_swapper.checkFreeMemory();
 
66
    }
 
67
 
 
68
    /**
 
69
     * \see m_memoryMetric
 
70
     */
 
71
    inline qint64 memoryMetric() const {
 
72
        return m_memoryMetric;
 
73
    }
 
74
 
 
75
    KisTileDataStoreIterator* beginIteration();
 
76
    void endIteration(KisTileDataStoreIterator* iterator);
 
77
 
 
78
    KisTileDataStoreReverseIterator* beginReverseIteration();
 
79
    void endIteration(KisTileDataStoreReverseIterator* iterator);
 
80
 
 
81
    KisTileDataStoreClockIterator* beginClockIteration();
 
82
    void endIteration(KisTileDataStoreClockIterator* iterator);
84
83
 
85
84
    inline KisTileData* createDefaultTileData(qint32 pixelSize, const quint8 *defPixel) {
86
85
        return allocTileData(pixelSize, defPixel);
89
88
    // Called by The Memento Manager after every commit
90
89
    inline void kickPooler() {
91
90
        m_pooler.kick();
 
91
 
 
92
        //FIXME: maybe, rename a function?
 
93
        m_swapper.kick();
92
94
    }
93
95
 
 
96
    /**
 
97
     * Try swap out the tile data.
 
98
     * It may fail in case the tile is being accessed
 
99
     * at the same moment of time.
 
100
     */
 
101
    bool trySwapTileData(KisTileData *td);
 
102
 
 
103
 
 
104
    /**
 
105
     * WARN: The following three method are only for usage
 
106
     * in KisTileData. Do not call them directly!
 
107
     */
 
108
 
 
109
    KisTileData *duplicateTileData(KisTileData *rhs);
 
110
 
 
111
    void freeTileData(KisTileData *td);
 
112
 
 
113
    /**
 
114
     * Ensures that the tile data is totally present in memory
 
115
     * and it's swapping is blocked by holding td->m_swapLock
 
116
     * in a read mode.
 
117
     * PRECONDITIONS: td->m_swapLock is *unlocked*
 
118
     *                m_listRWLock is *unlocked*
 
119
     * POSTCONDITIONS: td->m_data is in memory and
 
120
     *                 td->m_swapLock is locked
 
121
     *                 m_listRWLock is unlocked
 
122
     */
 
123
    void ensureTileDataLoaded(KisTileData *td);
 
124
 
94
125
private:
95
126
    KisTileData *allocTileData(qint32 pixelSize, const quint8 *defPixel);
96
 
    void freeTileData(KisTileData *td);
97
 
 
98
 
    void tileListAppend(KisTileData *td);
99
 
    void tileListDetach(KisTileData *td);
100
 
    void tileListClear();
101
 
 
 
127
 
 
128
    void registerTileData(KisTileData *td);
 
129
    void unregisterTileData(KisTileData *td);
 
130
    inline void registerTileDataImp(KisTileData *td);
 
131
    inline void unregisterTileDataImp(KisTileData *td);
 
132
    void freeRegisteredTiles();
 
133
 
 
134
    void debugSwapAll();
 
135
    void debugClear();
102
136
private:
103
 
    friend class KisTileDataPooler;
104
137
    KisTileDataPooler m_pooler;
105
 
 
106
 
    QReadWriteLock m_listRWLock;
107
 
    KisTileData *m_tileDataListHead;
 
138
    KisTileDataSwapper m_swapper;
 
139
 
 
140
    friend class KisTileDataStoreTest;
 
141
    KisSwappedDataStore m_swappedStore;
 
142
 
 
143
    KisTileDataListIterator m_clockIterator;
 
144
 
 
145
    QMutex m_listLock;
 
146
    KisTileDataList m_tileDataList;
 
147
    qint32 m_numTiles;
 
148
 
 
149
    /**
 
150
     * This metric is used for computing the volume
 
151
     * of memory occupied by tile data objects.
 
152
     * metric = num_bytes / (KisTileData::WIDTH * KisTileData::HEIGHT)
 
153
     */
 
154
    qint64 m_memoryMetric;
108
155
};
109
156
 
110
 
extern KisTileDataStore globalTileDataStore;
111
 
 
112
157
#endif /* KIS_TILE_DATA_STORE_H_ */
113
158