1 /****************************************************************************
2 **
3 ** Copyright (C) 2018 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the plugins of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #ifndef QX11PLATFORMPIXMAP_H
41 #define QX11PLATFORMPIXMAP_H
42 
43 #include <QBitmap>
44 #include <QPixmap>
45 
46 #include <qpa/qplatformpixmap.h>
47 #include "qxcbnativepainting.h"
48 
49 typedef unsigned long XID;
50 typedef XID Drawable;
51 typedef XID Picture;
52 typedef XID Pixmap;
53 
54 QT_BEGIN_NAMESPACE
55 
56 class QX11PaintEngine;
57 struct QXImageWrapper;
58 
59 class QX11PlatformPixmap : public QPlatformPixmap
60 {
61 public:
62     QX11PlatformPixmap(PixelType pixelType);
63     ~QX11PlatformPixmap();
64 
65     QPlatformPixmap *createCompatiblePlatformPixmap() const override;
66     void resize(int width, int height) override;
67     void fromImage(const QImage &img, Qt::ImageConversionFlags flags) override;
68     void copy(const QPlatformPixmap *data, const QRect &rect) override;
69     bool scroll(int dx, int dy, const QRect &rect) override;
70     int metric(QPaintDevice::PaintDeviceMetric metric) const override;
71     void fill(const QColor &fillColor) override;
72     QBitmap mask() const override;
73     void setMask(const QBitmap &mask) override;
74     bool hasAlphaChannel() const override;
75     QPixmap transformed(const QTransform &matrix, Qt::TransformationMode mode) const override;
76     QImage toImage() const override;
77     QImage toImage(const QRect &rect) const override;
78     QPaintEngine *paintEngine() const override;
79     qreal devicePixelRatio() const override;
80     void setDevicePixelRatio(qreal scaleFactor) override;
81 
handle()82     inline Drawable handle() const { return hd; }
x11PictureHandle()83     inline Picture x11PictureHandle() const { return picture; }
x11_info()84     inline const QXcbX11Info *x11_info() const { return &xinfo; }
85 
86     Pixmap x11ConvertToDefaultDepth();
87     static XID createBitmapFromImage(const QImage &image);
88 
89 #if QT_CONFIG(xrender)
90     void convertToARGB32(bool preserveContents = true);
91 #endif
92 
93     bool isBackingStore() const;
94     void setIsBackingStore(bool on);
95 private:
96     friend class QX11PaintEngine;
97     friend const QXcbX11Info &qt_x11Info(const QPixmap &pixmap);
98     friend void qt_x11SetScreen(QPixmap &pixmap, int screen);
99 
100     void release();
101     QImage toImage(const QXImageWrapper &xi, const QRect &rect) const;
102     QBitmap mask_to_bitmap(int screen) const;
103     static Pixmap bitmap_to_mask(const QBitmap &, int screen);
104     void bitmapFromImage(const QImage &image);
105     bool canTakeQImageFromXImage(const QXImageWrapper &xi) const;
106     QImage takeQImageFromXImage(const QXImageWrapper &xi) const;
107 
108     Pixmap hd = 0;
109 
110     enum Flag {
111         NoFlags = 0x0,
112         Uninitialized = 0x1,
113         Readonly = 0x2,
114         InvertedWhenBoundToTexture = 0x4,
115         GlSurfaceCreatedWithAlpha = 0x8,
116         IsBackingStore = 0x10
117     };
118     uint flags;
119 
120     QXcbX11Info xinfo;
121     Pixmap x11_mask;
122     Picture picture;
123     Picture mask_picture;
124     Pixmap hd2; // sorted in the default display depth
125     //QPixmap::ShareMode share_mode;
126     qreal dpr;
127 
128     QX11PaintEngine *pengine;
129 };
130 
qt_x11Pixmap(const QPixmap & pixmap)131 inline QX11PlatformPixmap *qt_x11Pixmap(const QPixmap &pixmap)
132 {
133     return (pixmap.handle() && pixmap.handle()->classId() == QPlatformPixmap::X11Class)
134             ? static_cast<QX11PlatformPixmap *>(pixmap.handle())
135             : nullptr;
136 }
137 
qt_x11PictureHandle(const QPixmap & pixmap)138 inline Picture qt_x11PictureHandle(const QPixmap &pixmap)
139 {
140     if (QX11PlatformPixmap *pm = qt_x11Pixmap(pixmap))
141         return pm->x11PictureHandle();
142 
143     return 0;
144 }
145 
qt_x11PixmapHandle(const QPixmap & pixmap)146 inline Pixmap qt_x11PixmapHandle(const QPixmap &pixmap)
147 {
148     if (QX11PlatformPixmap *pm = qt_x11Pixmap(pixmap))
149         return pm->handle();
150 
151     return 0;
152 }
153 
qt_x11Info(const QPixmap & pixmap)154 inline const QXcbX11Info &qt_x11Info(const QPixmap &pixmap)
155 {
156     if (QX11PlatformPixmap *pm = qt_x11Pixmap(pixmap)) {
157         return pm->xinfo;
158     } else {
159         static QXcbX11Info nullX11Info;
160         return nullX11Info;
161     }
162 }
163 
164 int qt_x11SetDefaultScreen(int screen);
165 void qt_x11SetScreen(QPixmap &pixmap, int screen);
166 
167 QT_END_NAMESPACE
168 
169 #endif // QX11PLATFORMPIXMAP_H
170