kwin/src/surfaceitem.h

101 lines
2 KiB
C
Raw Normal View History

/*
SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include "item.h"
namespace KWin
{
class Deleted;
class SurfacePixmap;
2022-04-22 17:39:12 +00:00
class Window;
/**
* The SurfaceItem class represents a surface with some contents.
*/
class KWIN_EXPORT SurfaceItem : public Item
{
Q_OBJECT
public:
QMatrix4x4 surfaceToBufferMatrix() const;
void setSurfaceToBufferMatrix(const QMatrix4x4 &matrix);
2022-04-22 17:39:12 +00:00
Window *window() const;
void addDamage(const QRegion &region);
void resetDamage();
QRegion damage() const;
void discardPixmap();
void updatePixmap();
SurfacePixmap *pixmap() const;
SurfacePixmap *previousPixmap() const;
void referencePreviousPixmap();
void unreferencePreviousPixmap();
protected:
2022-04-22 17:39:12 +00:00
explicit SurfaceItem(Window *window, Item *parent = nullptr);
virtual SurfacePixmap *createPixmap() = 0;
void preprocess() override;
WindowQuadList buildQuads() const override;
2022-04-22 17:39:12 +00:00
void handleWindowClosed(Window *original, Deleted *deleted);
2022-04-22 17:39:12 +00:00
Window *m_window;
QRegion m_damage;
QScopedPointer<SurfacePixmap> m_pixmap;
QScopedPointer<SurfacePixmap> m_previousPixmap;
QMatrix4x4 m_surfaceToBufferMatrix;
int m_referencePixmapCounter = 0;
};
class KWIN_EXPORT SurfaceTexture
{
public:
virtual ~SurfaceTexture();
virtual bool isValid() const = 0;
};
class KWIN_EXPORT SurfacePixmap : public QObject
{
Q_OBJECT
public:
explicit SurfacePixmap(SurfaceTexture *texture, QObject *parent = nullptr);
SurfaceTexture *texture() const;
bool hasAlphaChannel() const;
QSize size() const;
QRect contentsRect() const;
bool isDiscarded() const;
void markAsDiscarded();
virtual void create() = 0;
virtual void update();
virtual bool isValid() const = 0;
protected:
QSize m_size;
QRect m_contentsRect;
bool m_hasAlphaChannel = false;
private:
QScopedPointer<SurfaceTexture> m_texture;
bool m_isDiscarded = false;
};
} // namespace KWin