File indexing completed on 2024-05-12 15:58:52

0001 /*
0002  *  SPDX-FileCopyrightText: 2019 Dmitry Kazakov <dimula73@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #ifndef KISSAFENODEPROJECTIONSTORE_H
0008 #define KISSAFENODEPROJECTIONSTORE_H
0009 
0010 #include <QObject>
0011 
0012 #include <QMutex>
0013 #include <QScopedPointer>
0014 
0015 #include "kritaimage_export.h"
0016 #include "kis_shared.h"
0017 #include "kis_types.h"
0018 #include "kis_image_interfaces.h"
0019 
0020 struct StoreImplementaionInterface;
0021 
0022 class KRITAIMAGE_EXPORT KisSafeNodeProjectionStoreBase : public QObject, public KisShared
0023 {
0024     Q_OBJECT
0025 
0026 public:
0027     KisSafeNodeProjectionStoreBase(const KisSafeNodeProjectionStoreBase &rhs);
0028     ~KisSafeNodeProjectionStoreBase();
0029 
0030     /**
0031      * Notify the store that current projection device can be
0032      * safely dropped. The store will try to recycle the device
0033      * (taking ABA problem into account).
0034      */
0035     void releaseDevice();
0036 
0037     void setImage(KisImageWSP image);
0038 
0039 Q_SIGNALS:
0040     void internalInitiateProjectionsCleanup();
0041 
0042 private Q_SLOTS:
0043     void slotInitiateProjectionsCleanup();
0044 
0045 protected:
0046     KisSafeNodeProjectionStoreBase(StoreImplementaionInterface *storeImpl);
0047 
0048 private:
0049     void discardCaches();
0050 
0051     friend class KisRecycleProjectionsJob;
0052     void recycleProjectionsInSafety();
0053 
0054 protected:
0055     struct Private;
0056     QScopedPointer<Private> m_d;
0057 };
0058 
0059 class KRITAIMAGE_EXPORT KisSafeNodeProjectionStore : public KisSafeNodeProjectionStoreBase
0060 {
0061 public:
0062     KisSafeNodeProjectionStore();
0063     KisSafeNodeProjectionStore(const KisSafeNodeProjectionStore &rhs);
0064 
0065     /**
0066      * Safely fetch the current node projection device. If projection
0067      * already exists, the existing device is returned. Otherwise a new
0068      * device is created as a full copy of \p prototype.
0069      */
0070     KisPaintDeviceSP getDeviceLazy(KisPaintDeviceSP prototype);
0071 };
0072 
0073 class KRITAIMAGE_EXPORT KisSafeSelectionNodeProjectionStore : public KisSafeNodeProjectionStoreBase
0074 {
0075 public:
0076     KisSafeSelectionNodeProjectionStore();
0077     KisSafeSelectionNodeProjectionStore(const KisSafeSelectionNodeProjectionStore &rhs);
0078 
0079     /**
0080      * Safely fetch the current node projection device. If projection
0081      * already exists, the existing device is returned. Otherwise a new
0082      * device is created as a full copy of \p prototype.
0083      */
0084     KisSelectionSP getDeviceLazy(KisSelectionSP prototype);
0085 };
0086 
0087 
0088 typedef KisSharedPtr<KisSafeNodeProjectionStoreBase> KisSafeNodeProjectionStoreBaseSP;
0089 typedef KisWeakSharedPtr<KisSafeNodeProjectionStoreBase> KisSafeNodeProjectionStoreBaseWSP;
0090 
0091 typedef KisSharedPtr<KisSafeNodeProjectionStore> KisSafeNodeProjectionStoreSP;
0092 typedef KisWeakSharedPtr<KisSafeNodeProjectionStore> KisSafeNodeProjectionStoreWSP;
0093 
0094 typedef KisSharedPtr<KisSafeSelectionNodeProjectionStore> KisSafeSelectionNodeProjectionStoreSP;
0095 typedef KisWeakSharedPtr<KisSafeSelectionNodeProjectionStore> KisSafeSelectionNodeProjectionStoreWSP;
0096 
0097 #endif // KISSAFENODEPROJECTIONSTORE_H