File indexing completed on 2024-05-19 16:34:47

0001 /*
0002     SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "core/output.h"
0010 #include "scene/item.h"
0011 
0012 namespace KWin
0013 {
0014 
0015 class SurfacePixmap;
0016 class Window;
0017 
0018 /**
0019  * The SurfaceItem class represents a surface with some contents.
0020  */
0021 class KWIN_EXPORT SurfaceItem : public Item
0022 {
0023     Q_OBJECT
0024 
0025 public:
0026     QMatrix4x4 surfaceToBufferMatrix() const;
0027     void setSurfaceToBufferMatrix(const QMatrix4x4 &matrix);
0028 
0029     void addDamage(const QRegion &region);
0030     void resetDamage();
0031     QRegion damage() const;
0032 
0033     void discardPixmap();
0034     void updatePixmap();
0035     void destroyPixmap();
0036 
0037     SurfacePixmap *pixmap() const;
0038     SurfacePixmap *previousPixmap() const;
0039 
0040     void referencePreviousPixmap();
0041     void unreferencePreviousPixmap();
0042 
0043     virtual ContentType contentType() const;
0044 
0045 Q_SIGNALS:
0046     void damaged();
0047 
0048 protected:
0049     explicit SurfaceItem(Scene *scene, Item *parent = nullptr);
0050 
0051     virtual std::unique_ptr<SurfacePixmap> createPixmap() = 0;
0052     void preprocess() override;
0053     WindowQuadList buildQuads() const override;
0054 
0055     QRegion m_damage;
0056     std::unique_ptr<SurfacePixmap> m_pixmap;
0057     std::unique_ptr<SurfacePixmap> m_previousPixmap;
0058     QMatrix4x4 m_surfaceToBufferMatrix;
0059     int m_referencePixmapCounter = 0;
0060 };
0061 
0062 class KWIN_EXPORT SurfaceTexture
0063 {
0064 public:
0065     virtual ~SurfaceTexture();
0066 
0067     virtual bool isValid() const = 0;
0068 };
0069 
0070 class KWIN_EXPORT SurfacePixmap : public QObject
0071 {
0072     Q_OBJECT
0073 
0074 public:
0075     explicit SurfacePixmap(std::unique_ptr<SurfaceTexture> &&texture, QObject *parent = nullptr);
0076 
0077     SurfaceTexture *texture() const;
0078 
0079     bool hasAlphaChannel() const;
0080     QSize size() const;
0081 
0082     bool isDiscarded() const;
0083     void markAsDiscarded();
0084 
0085     virtual void create() = 0;
0086     virtual void update();
0087 
0088     virtual bool isValid() const = 0;
0089 
0090 protected:
0091     QSize m_size;
0092     bool m_hasAlphaChannel = false;
0093 
0094 private:
0095     std::unique_ptr<SurfaceTexture> m_texture;
0096     bool m_isDiscarded = false;
0097 };
0098 
0099 } // namespace KWin