| 1 |
// Copyright (C) 2018 The Qt Company Ltd. |
| 2 |
// SPDX-License-Identifier: LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 |
|
| 4 |
#ifndef QX11PLATFORMPIXMAP_H |
| 5 |
#define QX11PLATFORMPIXMAP_H |
| 6 |
|
| 7 |
#include <QBitmap> |
| 8 |
#include <QPixmap> |
| 9 |
|
| 10 |
#include <qpa/qplatformpixmap.h> |
| 11 |
#include "qxcbnativepainting.h" |
| 12 |
|
| 13 |
typedef unsigned long XID; |
| 14 |
typedef XID Drawable; |
| 15 |
typedef XID Picture; |
| 16 |
typedef XID Pixmap; |
| 17 |
|
| 18 |
QT_BEGIN_NAMESPACE |
| 19 |
|
| 20 |
class QX11PaintEngine; |
| 21 |
struct QXImageWrapper; |
| 22 |
|
| 23 |
class QX11PlatformPixmap : public QPlatformPixmap |
| 24 |
{ |
| 25 |
public: |
| 26 |
QX11PlatformPixmap(PixelType pixelType); |
| 27 |
~QX11PlatformPixmap(); |
| 28 |
|
| 29 |
QPlatformPixmap *createCompatiblePlatformPixmap() const override; |
| 30 |
void resize(int width, int height) override; |
| 31 |
void fromImage(const QImage &img, Qt::ImageConversionFlags flags) override; |
| 32 |
void copy(const QPlatformPixmap *data, const QRect &rect) override; |
| 33 |
bool scroll(int dx, int dy, const QRect &rect) override; |
| 34 |
int metric(QPaintDevice::PaintDeviceMetric metric) const override; |
| 35 |
void fill(const QColor &fillColor) override; |
| 36 |
QBitmap mask() const override; |
| 37 |
void setMask(const QBitmap &mask) override; |
| 38 |
bool hasAlphaChannel() const override; |
| 39 |
QPixmap transformed(const QTransform &matrix, Qt::TransformationMode mode) const override; |
| 40 |
QImage toImage() const override; |
| 41 |
QImage toImage(const QRect &rect) const override; |
| 42 |
QPaintEngine *paintEngine() const override; |
| 43 |
qreal devicePixelRatio() const override; |
| 44 |
void setDevicePixelRatio(qreal scaleFactor) override; |
| 45 |
|
| 46 |
inline Drawable handle() const { return hd; } |
| 47 |
inline Picture x11PictureHandle() const { return picture; } |
| 48 |
inline const QXcbX11Info *x11_info() const { return &xinfo; } |
| 49 |
|
| 50 |
Pixmap x11ConvertToDefaultDepth(); |
| 51 |
static XID createBitmapFromImage(const QImage &image); |
| 52 |
|
| 53 |
#if QT_CONFIG(xrender) |
| 54 |
void convertToARGB32(bool preserveContents = true); |
| 55 |
#endif |
| 56 |
|
| 57 |
bool isBackingStore() const; |
| 58 |
void setIsBackingStore(bool on); |
| 59 |
private: |
| 60 |
friend class QX11PaintEngine; |
| 61 |
friend const QXcbX11Info &qt_x11Info(const QPixmap &pixmap); |
| 62 |
friend void qt_x11SetScreen(QPixmap &pixmap, int screen); |
| 63 |
|
| 64 |
void release(); |
| 65 |
QImage toImage(const QXImageWrapper &xi, const QRect &rect) const; |
| 66 |
QBitmap mask_to_bitmap(int screen) const; |
| 67 |
static Pixmap bitmap_to_mask(const QBitmap &, int screen); |
| 68 |
void bitmapFromImage(const QImage &image); |
| 69 |
bool canTakeQImageFromXImage(const QXImageWrapper &xi) const; |
| 70 |
QImage takeQImageFromXImage(const QXImageWrapper &xi) const; |
| 71 |
|
| 72 |
Pixmap hd = 0; |
| 73 |
|
| 74 |
enum Flag { |
| 75 |
NoFlags = 0x0, |
| 76 |
Uninitialized = 0x1, |
| 77 |
Readonly = 0x2, |
| 78 |
InvertedWhenBoundToTexture = 0x4, |
| 79 |
GlSurfaceCreatedWithAlpha = 0x8, |
| 80 |
IsBackingStore = 0x10 |
| 81 |
}; |
| 82 |
uint flags; |
| 83 |
|
| 84 |
QXcbX11Info xinfo; |
| 85 |
Pixmap x11_mask; |
| 86 |
Picture picture; |
| 87 |
Picture mask_picture; |
| 88 |
Pixmap hd2; // sorted in the default display depth |
| 89 |
//QPixmap::ShareMode share_mode; |
| 90 |
qreal dpr; |
| 91 |
|
| 92 |
QX11PaintEngine *pengine; |
| 93 |
}; |
| 94 |
|
| 95 |
inline QX11PlatformPixmap *qt_x11Pixmap(const QPixmap &pixmap) |
| 96 |
{ |
| 97 |
return (pixmap.handle() && pixmap.handle()->classId() == QPlatformPixmap::X11Class) |
| 98 |
? static_cast<QX11PlatformPixmap *>(pixmap.handle()) |
| 99 |
: nullptr; |
| 100 |
} |
| 101 |
|
| 102 |
inline Picture qt_x11PictureHandle(const QPixmap &pixmap) |
| 103 |
{ |
| 104 |
if (QX11PlatformPixmap *pm = qt_x11Pixmap(pixmap)) |
| 105 |
return pm->x11PictureHandle(); |
| 106 |
|
| 107 |
return 0; |
| 108 |
} |
| 109 |
|
| 110 |
inline Pixmap qt_x11PixmapHandle(const QPixmap &pixmap) |
| 111 |
{ |
| 112 |
if (QX11PlatformPixmap *pm = qt_x11Pixmap(pixmap)) |
| 113 |
return pm->handle(); |
| 114 |
|
| 115 |
return 0; |
| 116 |
} |
| 117 |
|
| 118 |
inline const QXcbX11Info &qt_x11Info(const QPixmap &pixmap) |
| 119 |
{ |
| 120 |
if (QX11PlatformPixmap *pm = qt_x11Pixmap(pixmap)) { |
| 121 |
return pm->xinfo; |
| 122 |
} else { |
| 123 |
static QXcbX11Info nullX11Info; |
| 124 |
return nullX11Info; |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
int qt_x11SetDefaultScreen(int screen); |
| 129 |
void qt_x11SetScreen(QPixmap &pixmap, int screen); |
| 130 |
|
| 131 |
QT_END_NAMESPACE |
| 132 |
|
| 133 |
#endif // QX11PLATFORMPIXMAP_H |