Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qbackingstore_x11.cpp
Go to the documentation of this file.
1// Copyright (C) 2018 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5#include "qxcbwindow.h"
6#include "qpixmap_x11_p.h"
7
8#include <private/qhighdpiscaling_p.h>
9#include <QPainter>
10
11#if QT_CONFIG(xrender)
12# include <X11/extensions/Xrender.h>
13#endif
14
15#define register /* C++17 deprecated register */
16#include <X11/Xlib.h>
17#undef register
18
20
23 , m_translucentBackground(false)
24{
25 if (QXcbWindow *w = static_cast<QXcbWindow *>(window->handle())) {
26 m_translucentBackground = w->connection()->hasXRender() &&
27 QImage::toPixelFormat(w->imageFormat()).alphaUsage() == QPixelFormat::UsesAlpha;
28 }
29}
30
33
35{
36 return &m_pixmap;
37}
38
40{
41 if (m_pixmap.isNull())
42 return;
43
44 QSize pixmapSize = m_pixmap.size();
45
46 QRegion clipped = region;
48 clipped &= QRect(0, 0, pixmapSize.width(), pixmapSize.height()).translated(-offset);
49
50 QRect br = clipped.boundingRect();
51 if (br.isNull())
52 return;
53
54 QXcbWindow *platformWindow = static_cast<QXcbWindow *>(window->handle());
55 if (!platformWindow) {
56 qWarning("QXcbBackingStore::flush: QWindow has no platform window (QTBUG-32681)");
57 return;
58 }
59
60 Window wid = platformWindow->xcb_window();
61 Pixmap pid = qt_x11PixmapHandle(m_pixmap);
62
63 QList<XRectangle> clipRects = qt_region_to_xrectangles(clipped);
64
65#if QT_CONFIG(xrender)
66 if (m_translucentBackground)
67 {
68 XWindowAttributes attrib;
69 XGetWindowAttributes(display(), wid, &attrib);
70 XRenderPictFormat *format = XRenderFindVisualFormat(display(), attrib.visual);
71
72 Picture srcPic = qt_x11PictureHandle(m_pixmap);
73 Picture dstPic = XRenderCreatePicture(display(), wid, format, 0, 0);
74
75 XRenderSetPictureClipRectangles(display(), dstPic, 0, 0, clipRects.constData(), clipRects.size());
76
77 XRenderComposite(display(), PictOpSrc, srcPic, 0L /*None*/, dstPic, br.x() + offset.x(),
78 br.y() + offset.y(), 0, 0, br.x(), br.y(), br.width(), br.height());
79
80 XRenderFreePicture(display(), dstPic);
81 }
82 else
83#endif
84 {
85 GC gc = XCreateGC(display(), wid, 0, nullptr);
86
87 if (clipRects.size() != 1)
88 XSetClipRectangles(display(), gc, 0, 0, clipRects.data(), clipRects.size(), YXBanded);
89
90 XCopyArea(display(), pid, wid, gc, br.x() + offset.x(), br.y() + offset.y(), br.width(), br.height(), br.x(), br.y());
91 XFreeGC(display(), gc);
92 }
93
94
95 if (platformWindow->needsSync()) {
96 platformWindow->updateSyncRequestCounter();
97 } else {
98 XFlush(display());
99 }
100}
101
103{
104 return m_pixmap.toImage();
105}
106
107void QXcbNativeBackingStore::resize(const QSize &size, const QRegion &staticContents)
108{
109 if (size == m_pixmap.size())
110 return;
111
112 QPixmap newPixmap(size);
113
114#if QT_CONFIG(xrender)
115 if (m_translucentBackground && newPixmap.depth() != 32)
116 qt_x11Pixmap(newPixmap)->convertToARGB32();
117#endif
118
119 if (!m_pixmap.isNull()) {
120 Pixmap from = qt_x11PixmapHandle(m_pixmap);
121 Pixmap to = qt_x11PixmapHandle(newPixmap);
122 QRect br = staticContents.boundingRect().intersected(QRect(QPoint(0, 0), size));
123
124 if (!br.isEmpty()) {
125 GC gc = XCreateGC(display(), to, 0, nullptr);
126 XCopyArea(display(), from, to, gc, br.x(), br.y(), br.width(), br.height(), br.x(), br.y());
127 XFreeGC(display(), gc);
128 }
129 }
130
131 m_pixmap = newPixmap;
132}
133
134bool QXcbNativeBackingStore::scroll(const QRegion &area, int dx, int dy)
135{
136 if (m_pixmap.isNull())
137 return false;
138
139 QRect rect = area.boundingRect();
140 Pixmap pix = qt_x11PixmapHandle(m_pixmap);
141
142 GC gc = XCreateGC(display(), pix, 0, nullptr);
143 XCopyArea(display(), pix, pix, gc,
144 rect.x(), rect.y(), rect.width(), rect.height(),
145 rect.x()+dx, rect.y()+dy);
146 XFreeGC(display(), gc);
147 return true;
148}
149
151{
152 QX11PlatformPixmap *x11pm = qt_x11Pixmap(m_pixmap);
153 if (x11pm)
154 x11pm->setIsBackingStore(true);
155
156#if QT_CONFIG(xrender)
157 if (m_translucentBackground) {
158 const QList<XRectangle> xrects = qt_region_to_xrectangles(region);
159 const XRenderColor color = { 0, 0, 0, 0 };
160 XRenderFillRectangles(display(), PictOpSrc,
161 qt_x11PictureHandle(m_pixmap), &color,
162 xrects.constData(), xrects.size());
163 }
164#else
165 Q_UNUSED(region);
166#endif
167}
168
169Display *QXcbNativeBackingStore::display() const
170{
171 return static_cast<Display *>(static_cast<QXcbWindow *>(window()->handle())->connection()->xlib_display());
172}
173
\inmodule QtGui
Definition qimage.h:37
static QPixelFormat toPixelFormat(QImage::Format format) noexcept
Converts format into a QPixelFormat.
Definition qimage.cpp:6392
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
QImage toImage() const
Converts the pixmap to a QImage.
Definition qpixmap.cpp:408
QSize size() const
Returns the size of the pixmap.
Definition qpixmap.cpp:493
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition qpixmap.cpp:456
int width() const
Returns the width of the pixmap.
Definition qpixmap.cpp:468
The QPlatformBackingStore class provides the drawing area for top-level windows.
QWindow * window() const
Returns a pointer to the top-level window associated with this surface.
\inmodule QtCore\reentrant
Definition qpoint.h:25
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr bool isEmpty() const noexcept
Returns true if the rectangle is empty, otherwise returns false.
Definition qrect.h:167
constexpr int height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:239
constexpr bool isNull() const noexcept
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition qrect.h:164
QRect intersected(const QRect &other) const noexcept
Definition qrect.h:415
constexpr int x() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:185
constexpr int width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:236
constexpr QRect translated(int dx, int dy) const noexcept
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis,...
Definition qrect.h:261
constexpr int y() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:188
The QRegion class specifies a clip region for a painter.
Definition qregion.h:27
QRect boundingRect() const noexcept
Returns the bounding rectangle of this region.
\inmodule QtCore
Definition qsize.h:25
\inmodule QtGui
Definition qwindow.h:63
QSize size() const override
Returns the size of the window excluding any window frame.
Definition qwindow.h:210
void beginPaint(const QRegion &region) override
This function is called before painting onto the surface begins, with the region in which the paintin...
QXcbNativeBackingStore(QWindow *window)
void flush(QWindow *window, const QRegion &region, const QPoint &offset) override
Flushes the given region from the specified window.
QImage toImage() const override
Implemented in subclasses to return the content of the backingstore as a QImage.
QPaintDevice * paintDevice() override
Implement this function to return the appropriate paint device.
void resize(const QSize &size, const QRegion &staticContents) override
bool scroll(const QRegion &area, int dx, int dy) override
Scrolls the given area dx pixels to the right and dy downward; both dx and dy may be negative.
xcb_window_t xcb_window() const
Definition qxcbwindow.h:94
void updateSyncRequestCounter()
bool needsSync() const
[Window class with invokable method]
Definition window.h:11
rect
[4]
QPixmap pix
struct wl_display * display
Definition linuxdmabuf.h:41
T toNativePixels(const T &value, const C *context)
Combined button and popup list for selecting options.
DBusConnection * connection
static int area(const QSize &s)
Definition qicon.cpp:153
#define qWarning
Definition qlogging.h:166
GLfloat GLfloat GLfloat w
[0]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint color
[2]
GLenum GLuint GLintptr offset
GLint GLsizei GLsizei GLenum format
struct _XGC * GC
XID Picture
XID Pixmap
Pixmap qt_x11PixmapHandle(const QPixmap &pixmap)
Picture qt_x11PictureHandle(const QPixmap &pixmap)
QX11PlatformPixmap * qt_x11Pixmap(const QPixmap &pixmap)
void gc(QV4::ExecutionEngine &engine, GCFlags flags)
Definition qmlutils.cpp:118
#define Q_UNUSED(x)
struct _XDisplay Display
QList< XRectangle > qt_region_to_xrectangles(const QRegion &r)
aWidget window() -> setWindowTitle("New Window Title")
[2]