File indexing completed on 2024-05-26 04:28:04
0001 /* 0002 * SPDX-FileCopyrightText: 2009 Dmitry Kazakov <dimula73@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 #ifndef KIS_TILE_DATA_H_ 0007 #define KIS_TILE_DATA_H_ 0008 0009 /** 0010 * Some methods of KisTileData have a cyclic dependency 0011 * to the KisTileDataStore, so we've moved the class 0012 * declaration to a separate file, that will be included 0013 * by the store. 0014 */ 0015 #include "kis_tile_data_interface.h" 0016 0017 0018 #include "kis_tile_data_store.h" 0019 0020 0021 inline quint8* KisTileData::data() const { 0022 // WARN: be careful - it can be null when swapped out! 0023 return m_data; 0024 } 0025 0026 void KisTileData::setData(const quint8 *data) { 0027 Q_ASSERT(m_data); 0028 memcpy(m_data, data, m_pixelSize*WIDTH*HEIGHT); 0029 } 0030 0031 inline quint32 KisTileData::pixelSize() const { 0032 return m_pixelSize; 0033 } 0034 0035 inline bool KisTileData::acquire() { 0036 /** 0037 * We need to ensure the clones in the stack are 0038 * consistent with the data. When we have a single 0039 * user, the most probably, the clone has already 0040 * started stinking. 0041 * So just clean it up. 0042 */ 0043 if(m_usersCount == 1) { 0044 KisTileData *clone = 0; 0045 while(m_clonesStack.pop(clone)) { 0046 delete clone; 0047 } 0048 } 0049 0050 bool _ref = ref(); 0051 m_usersCount.ref(); 0052 return _ref; 0053 } 0054 0055 inline bool KisTileData::release() { 0056 m_usersCount.deref(); 0057 bool _ref = deref(); 0058 return _ref; 0059 } 0060 0061 inline bool KisTileData::ref() const { 0062 return m_refCount.ref(); 0063 } 0064 0065 inline bool KisTileData::deref() { 0066 bool _ref; 0067 0068 if (!(_ref = m_refCount.deref())) { 0069 m_store->freeTileData(this); 0070 return 0; 0071 } 0072 return _ref; 0073 } 0074 0075 inline KisTileData* KisTileData::clone() { 0076 return m_store->duplicateTileData(this); 0077 } 0078 0079 inline void KisTileData::blockSwapping() { 0080 m_swapLock.lockForRead(); 0081 if(!m_data) { 0082 m_swapLock.unlock(); 0083 m_store->ensureTileDataLoaded(this); 0084 } 0085 resetAge(); 0086 } 0087 0088 inline void KisTileData::unblockSwapping() { 0089 m_swapLock.unlock(); 0090 } 0091 0092 inline KisChunk KisTileData::swapChunk() const { 0093 return m_swapChunk; 0094 } 0095 inline void KisTileData::setSwapChunk(KisChunk chunk) { 0096 m_swapChunk = chunk; 0097 } 0098 0099 inline bool KisTileData::mementoed() const { 0100 return m_mementoFlag; 0101 } 0102 inline void KisTileData::setMementoed(bool value) { 0103 m_mementoFlag += value ? 1 : -1; 0104 } 0105 0106 inline bool KisTileData::historical() const { 0107 return mementoed() && numUsers() <= 1; 0108 } 0109 0110 inline int KisTileData::age() const { 0111 return m_age; 0112 } 0113 inline void KisTileData::resetAge() { 0114 m_age = 0; 0115 } 0116 inline void KisTileData::markOld() { 0117 m_age++; 0118 } 0119 0120 inline qint32 KisTileData::numUsers() const { 0121 return m_usersCount; 0122 } 0123 0124 #endif /* KIS_TILE_DATA_H_ */ 0125