File indexing completed on 2024-05-12 05:32:08

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 "scene/surfaceitem.h"
0010 
0011 #include <xcb/damage.h>
0012 #include <xcb/xfixes.h>
0013 
0014 namespace KWin
0015 {
0016 
0017 class X11Window;
0018 
0019 /**
0020  * The SurfaceItemX11 class represents an X11 surface in the scene.
0021  */
0022 class KWIN_EXPORT SurfaceItemX11 : public SurfaceItem
0023 {
0024     Q_OBJECT
0025 
0026 public:
0027     explicit SurfaceItemX11(X11Window *window, Scene *scene, Item *parent = nullptr);
0028     ~SurfaceItemX11() override;
0029 
0030     X11Window *window() const;
0031 
0032     void preprocess() override;
0033 
0034     void processDamage();
0035     bool fetchDamage();
0036     void waitForDamage();
0037     void forgetDamage();
0038     void destroyDamage();
0039 
0040     QList<QRectF> shape() const override;
0041     QRegion opaque() const override;
0042 
0043 private Q_SLOTS:
0044     void handleBufferGeometryChanged();
0045     void handleShapeChanged();
0046 
0047 protected:
0048     std::unique_ptr<SurfacePixmap> createPixmap() override;
0049 
0050 private:
0051     X11Window *m_window;
0052     xcb_damage_damage_t m_damageHandle = XCB_NONE;
0053     xcb_xfixes_fetch_region_cookie_t m_damageCookie;
0054     bool m_isDamaged = false;
0055     bool m_havePendingDamageRegion = false;
0056 };
0057 
0058 class KWIN_EXPORT SurfacePixmapX11 final : public SurfacePixmap
0059 {
0060     Q_OBJECT
0061 
0062 public:
0063     explicit SurfacePixmapX11(SurfaceItemX11 *item, QObject *parent = nullptr);
0064     ~SurfacePixmapX11() override;
0065 
0066     xcb_pixmap_t pixmap() const;
0067     xcb_visualid_t visual() const;
0068 
0069     void create() override;
0070     bool isValid() const override;
0071 
0072 private:
0073     SurfaceItemX11 *m_item;
0074     xcb_pixmap_t m_pixmap = XCB_PIXMAP_NONE;
0075 };
0076 
0077 } // namespace KWin