File indexing completed on 2024-11-10 04:56:34
0001 /* 0002 KWin - the KDE window manager 0003 This file is part of the KDE project. 0004 0005 SPDX-FileCopyrightText: 2008 Lubos Lunak <l.lunak@kde.org> 0006 SPDX-FileCopyrightText: 2022 MBition GmbH 0007 SPDX-FileContributor: Kai Uwe Broulik <kai_uwe.broulik@mbition.io> 0008 0009 SPDX-License-Identifier: GPL-2.0-or-later 0010 */ 0011 0012 #pragma once 0013 0014 // KWin 0015 #include <kwin_export.h> 0016 // Qt 0017 #include <QExplicitlySharedDataPointer> 0018 // XCB 0019 #include <xcb/render.h> 0020 0021 #include <memory> 0022 0023 class QImage; 0024 0025 /** @addtogroup kwineffects */ 0026 /** @{ */ 0027 0028 namespace KWin 0029 { 0030 0031 /** @internal */ 0032 class KWIN_EXPORT XRenderPictureData 0033 : public QSharedData 0034 { 0035 public: 0036 explicit XRenderPictureData(xcb_render_picture_t pic = XCB_RENDER_PICTURE_NONE); 0037 ~XRenderPictureData(); 0038 xcb_render_picture_t value(); 0039 0040 private: 0041 xcb_render_picture_t picture; 0042 Q_DISABLE_COPY(XRenderPictureData) 0043 }; 0044 0045 /** 0046 * @short Wrapper around XRender Picture. 0047 * 0048 * This class wraps XRender's Picture, providing proper initialization, 0049 * convenience constructors and freeing of resources. 0050 * It should otherwise act exactly like the Picture type. 0051 */ 0052 class KWIN_EXPORT XRenderPicture 0053 { 0054 public: 0055 explicit XRenderPicture(xcb_render_picture_t pic = XCB_RENDER_PICTURE_NONE); 0056 explicit XRenderPicture(const QImage &img); 0057 XRenderPicture(xcb_pixmap_t pix, int depth); 0058 operator xcb_render_picture_t(); 0059 0060 private: 0061 void fromImage(const QImage &img); 0062 std::unique_ptr<XRenderPictureData> d; 0063 }; 0064 0065 inline XRenderPictureData::XRenderPictureData(xcb_render_picture_t pic) 0066 : picture(pic) 0067 { 0068 } 0069 0070 inline xcb_render_picture_t XRenderPictureData::value() 0071 { 0072 return picture; 0073 } 0074 0075 inline XRenderPicture::XRenderPicture(xcb_render_picture_t pic) 0076 : d(std::make_unique<XRenderPictureData>(pic)) 0077 { 0078 } 0079 0080 inline XRenderPicture::operator xcb_render_picture_t() 0081 { 0082 return d->value(); 0083 } 0084 0085 namespace XRenderUtils 0086 { 0087 /** 0088 * @internal 0089 */ 0090 KWIN_EXPORT void init(xcb_connection_t *connection, xcb_window_t rootWindow); 0091 0092 /** 0093 * Returns the Xrender format that corresponds to the given visual ID. 0094 */ 0095 KWIN_EXPORT xcb_render_pictformat_t findPictFormat(xcb_visualid_t visual); 0096 0097 /** 0098 * Returns the xcb_render_directformat_t for the given Xrender format. 0099 */ 0100 KWIN_EXPORT const xcb_render_directformat_t *findPictFormatInfo(xcb_render_pictformat_t format); 0101 0102 /** 0103 * @internal 0104 */ 0105 KWIN_EXPORT void cleanup(); 0106 0107 } // namespace XRenderUtils 0108 0109 } // namespace KWin 0110 0111 /** @} */