File indexing completed on 2024-12-22 04:10:30

0001 /*
0002  *  SPDX-FileCopyrightText: 2010 Dmitry Kazakov <dimula73@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 #ifndef KIS_TILE_DATA_SWAPPER_P_H_
0007 #define KIS_TILE_DATA_SWAPPER_P_H_
0008 
0009 #include "kis_image_config.h"
0010 #include "tiles3/kis_tile_data.h"
0011 
0012 
0013 /*
0014        Limits Diagram
0015   +------------------------+  <-- out of memory
0016   |                        |
0017   |                        |
0018   |                        |
0019   |## emergencyThreshold ##|  <-- new tiles are not created
0020   |                        |      until we free some memory
0021   |                        |
0022   |== hardLimitThreshold ==|  <-- the swapper thread starts
0023   |........................|      swapping out working (actually
0024   |........................|      needed) tiles until the level
0025   |........................|      reaches hardLimit level.
0026   |........................|
0027   |=====  hardLimit  ======|  <-- the swapper stops swapping
0028   |                        |      out needed tiles
0029   |                        |
0030   :                        :
0031   |                        |
0032   |                        |
0033   |== softLimitThreshold ==|  <-- the swapper starts swapping
0034   |........................|      out memento tiles (those, which
0035   |........................|      store undo information)
0036   |........................|
0037   |=====  softLimit  ======|  <-- the swapper stops swapping
0038   |                        |      out memento tiles
0039   |                        |
0040   :                        :
0041   |                        |
0042   +------------------------+  <-- 0 MiB
0043 
0044  */
0045 
0046 
0047 class KisStoreLimits
0048 {
0049 public:
0050     KisStoreLimits() {
0051         KisImageConfig config(true);
0052 
0053         m_emergencyThreshold = MiB_TO_METRIC(config.tilesHardLimit());
0054 
0055         m_hardLimitThreshold = m_emergencyThreshold - (m_emergencyThreshold / 8);
0056         m_hardLimit = m_hardLimitThreshold - (m_hardLimitThreshold / 8);
0057 
0058         m_softLimitThreshold = qBound(0, MiB_TO_METRIC(config.tilesSoftLimit()), m_hardLimitThreshold);
0059         m_softLimit = m_softLimitThreshold - m_softLimitThreshold / 8;
0060     }
0061 
0062     /**
0063      * These methods return the "metric" of the size
0064      */
0065 
0066     inline qint32 emergencyThreshold() {
0067         return m_emergencyThreshold;
0068     }
0069 
0070     inline qint32 hardLimitThreshold() {
0071         return m_hardLimitThreshold;
0072     }
0073 
0074     inline qint32 hardLimit() {
0075         return m_hardLimit;
0076     }
0077 
0078     inline qint32 softLimitThreshold() {
0079         return m_softLimitThreshold;
0080     }
0081 
0082     inline qint32 softLimit() {
0083         return m_softLimit;
0084     }
0085 
0086 private:
0087     qint32 m_emergencyThreshold;
0088     qint32 m_hardLimitThreshold;
0089     qint32 m_hardLimit;
0090     qint32 m_softLimitThreshold;
0091     qint32 m_softLimit;
0092 };
0093 
0094 
0095 
0096 
0097 #endif /* KIS_TILE_DATA_SWAPPER_P_H_ */
0098