File indexing completed on 2024-06-09 04:22:25
0001 /* 0002 * SPDX-FileCopyrightText: 2017 Dmitry Kazakov <dimula73@gmail.com> 0003 * SPDX-FileCopyrightText: 2018 Andrey Kamakin <a.kamakin@icloud.com> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #ifndef KISTILEDEXTENTMANAGER_H 0009 #define KISTILEDEXTENTMANAGER_H 0010 0011 #include <QMutex> 0012 #include <QReadWriteLock> 0013 #include <QMap> 0014 #include <QRect> 0015 #include "kritaimage_export.h" 0016 0017 0018 class KRITAIMAGE_EXPORT KisTiledExtentManager 0019 { 0020 static const qint32 InitialBufferSize = 256; 0021 0022 class KRITAIMAGE_EXPORT Data 0023 { 0024 public: 0025 Data(); 0026 ~Data(); 0027 0028 bool add(qint32 index); 0029 bool remove(qint32 index); 0030 void replace(const QVector<qint32> &indexes); 0031 void clear(); 0032 bool isEmpty(); 0033 qint32 min(); 0034 qint32 max(); 0035 0036 public: 0037 QReadWriteLock m_extentLock; 0038 0039 private: 0040 inline void unsafeAdd(qint32 index); 0041 inline void unsafeMigrate(qint32 index); 0042 inline void migrate(qint32 index); 0043 inline void updateMin(); 0044 inline void updateMax(); 0045 0046 private: 0047 qint32 m_min; 0048 qint32 m_max; 0049 qint32 m_offset; 0050 qint32 m_capacity; 0051 qint32 m_count; 0052 QAtomicInt *m_buffer; 0053 QReadWriteLock m_migrationLock; 0054 }; 0055 0056 public: 0057 KisTiledExtentManager(); 0058 0059 void notifyTileAdded(qint32 col, qint32 row); 0060 void notifyTileRemoved(qint32 col, qint32 row); 0061 void replaceTileStats(const QVector<QPoint> &indexes); 0062 void clear(); 0063 QRect extent() const; 0064 0065 private: 0066 void updateExtent(); 0067 friend class KisTiledDataManagerTest; 0068 0069 private: 0070 mutable QReadWriteLock m_extentLock; 0071 QRect m_currentExtent; 0072 Data m_colsData; 0073 Data m_rowsData; 0074 }; 0075 0076 #endif // KISTILEDEXTENTMANAGER_H