File indexing completed on 2024-12-22 04:12:33

0001 /*
0002  *  SPDX-FileCopyrightText: 2007 Boudewijn Rempt <boud@valdyas.org>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 #ifndef KIS_SHAPE_LAYER_CANVAS_H
0007 #define KIS_SHAPE_LAYER_CANVAS_H
0008 
0009 #include <QMutex>
0010 #include <QRegion>
0011 #include <KoCanvasBase.h>
0012 
0013 #include <kis_types.h>
0014 #include "kis_thread_safe_signal_compressor.h"
0015 #include <KoSelectedShapesProxy.h>
0016 #include <KoShapeManager.h>
0017 #include <KisSafeBlockingQueueConnectionProxy.h>
0018 #include <kis_signal_auto_connection.h>
0019 #include "kis_image_view_converter.h"
0020 #include "kis_default_bounds_base.h"
0021 #include "KoColorConversionTransformation.h"
0022 
0023 class KoColorProfile;
0024 class KoShapeManager;
0025 class KoToolProxy;
0026 class KoViewConverter;
0027 class KUndo2Command;
0028 class QWidget;
0029 class KoUnit;
0030 class KisImageViewConverter;
0031 class KoColorSpace;
0032 
0033 class KisShapeLayerCanvasBase : public KoCanvasBase
0034 {
0035     Q_OBJECT
0036 public:
0037     KisShapeLayerCanvasBase(KisShapeLayer *parent);
0038     KisShapeLayerCanvasBase(const KisShapeLayerCanvasBase &rhs, KisShapeLayer *parent);
0039 
0040     virtual void setImage(KisImageWSP image);
0041     void prepareForDestroying();
0042     virtual void forceRepaint() = 0;
0043     virtual bool hasPendingUpdates() const = 0;
0044     virtual KisPaintDeviceSP projection() const = 0;
0045 
0046     virtual void forceRepaintWithHiddenAreas() { forceRepaint(); }
0047 
0048     bool hasChangedWhileBeingInvisible();
0049     virtual void rerenderAfterBeingInvisible() = 0;
0050     virtual void resetCache() = 0;
0051 
0052     KoShapeManager *shapeManager() const override;
0053     const KoViewConverter *viewConverter() const override;
0054     KoViewConverter *viewConverter() override;
0055 
0056     void gridSize(QPointF *offset, QSizeF *spacing) const override;
0057     bool snapToGrid() const override;
0058     void addCommand(KUndo2Command *command) override;
0059     KoSelectedShapesProxy *selectedShapesProxy() const override;
0060     KoToolProxy * toolProxy() const override;
0061     QWidget* canvasWidget() override;
0062     const QWidget* canvasWidget() const override;
0063     KoUnit unit() const override;
0064     void setCursor(const QCursor &) override {}
0065 
0066 protected:
0067     QScopedPointer<KoShapeManager> m_shapeManager;
0068     QScopedPointer<KoSelectedShapesProxy> m_selectedShapesProxy;
0069     bool m_hasChangedWhileBeingInvisible {false};
0070     bool m_isDestroying {false};
0071 
0072     KisImageViewConverter m_viewConverter;
0073 };
0074 
0075 /**
0076  * KisShapeLayerCanvas is a special canvas implementation that Krita
0077  * uses for non-krita shapes to request updates on.
0078  *
0079  * Do NOT give this canvas to tools or to the KoCanvasController, it's
0080  * not made for that.
0081  */
0082 class KisShapeLayerCanvas : public KisShapeLayerCanvasBase
0083 {
0084     Q_OBJECT
0085 public:
0086 
0087     KisShapeLayerCanvas(const KoColorSpace *cs, KisDefaultBoundsBaseSP defaultBounds, KisShapeLayer *parent);
0088     KisShapeLayerCanvas(const KisShapeLayerCanvas &rhs, KisShapeLayer *parent);
0089     ~KisShapeLayerCanvas() override;
0090 
0091     /// This canvas won't render onto a widget, but a projection
0092     void setProjection(KisPaintDeviceSP projection);
0093     KisPaintDeviceSP projection() const override;
0094 
0095     void setImage(KisImageWSP image) override;
0096     void updateCanvas(const QRectF& rc) override;
0097     void updateCanvas(const QVector<QRectF> &region);
0098     void forceRepaint() override;
0099     bool hasPendingUpdates() const override;
0100 
0101     void forceRepaintWithHiddenAreas() override;
0102 
0103     void resetCache() override;
0104     void rerenderAfterBeingInvisible() override;
0105 
0106 
0107 private Q_SLOTS:
0108     friend class KisRepaintShapeLayerLayerJob;
0109     void repaint();
0110     void slotStartAsyncRepaint();
0111     void slotImageSizeChanged();
0112 
0113 private:
0114     KisPaintDeviceSP m_projection;
0115     KisShapeLayer *m_parentLayer {0};
0116 
0117     KisThreadSafeSignalCompressor m_asyncUpdateSignalCompressor;
0118     volatile bool m_hasUpdateInCompressor = false;
0119     bool m_hasUpdateOnSetImage = false;
0120     KisSafeBlockingQueueConnectionProxy<void> m_safeForcedConnection;
0121 
0122     bool m_forceUpdateHiddenAreasOnly = false;
0123     QRegion m_dirtyRegion;
0124     QMutex m_dirtyRegionMutex;
0125     KoShapeManager::PaintJobsOrder m_paintJobsOrder;
0126 
0127     QRect m_cachedImageRect;
0128 
0129     KisImageWSP m_image;
0130     KisSignalAutoConnectionsStore m_imageConnections;
0131 };
0132 
0133 #endif