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
qxcbnativepainting.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
4#include <QtCore/qrandom.h>
5
6#include "qxcbconnection.h"
7#include "qcolormap_x11_p.h"
9#include "qt_x11_p.h"
10
12
14
16{
18 X11->display = static_cast<Display *>(conn->xlib_display());
19 X11->defaultScreen = DefaultScreen(X11->display);
20 X11->screenCount = ScreenCount(X11->display);
21
22 X11->screens = new QX11InfoData[X11->screenCount];
23 X11->argbVisuals = new Visual *[X11->screenCount];
24 X11->argbColormaps = new Colormap[X11->screenCount];
25
26 for (int s = 0; s < X11->screenCount; s++) {
27 QX11InfoData *screen = X11->screens + s;
28 //screen->ref = 1; // ensures it doesn't get deleted
29 screen->screen = s;
30
31 int widthMM = DisplayWidthMM(X11->display, s);
32 if (widthMM != 0) {
33 screen->dpiX = (DisplayWidth(X11->display, s) * 254 + widthMM * 5) / (widthMM * 10);
34 } else {
35 screen->dpiX = 72;
36 }
37
38 int heightMM = DisplayHeightMM(X11->display, s);
39 if (heightMM != 0) {
40 screen->dpiY = (DisplayHeight(X11->display, s) * 254 + heightMM * 5) / (heightMM * 10);
41 } else {
42 screen->dpiY = 72;
43 }
44
45 X11->argbVisuals[s] = 0;
46 X11->argbColormaps[s] = 0;
47 }
48
49 X11->use_xrender = conn->hasXRender() && !qEnvironmentVariableIsSet("QT_XCB_NATIVE_PAINTING_NO_XRENDER");
50
51#if QT_CONFIG(xrender)
52 memset(X11->solid_fills, 0, sizeof(X11->solid_fills));
53 for (int i = 0; i < X11->solid_fill_count; ++i)
54 X11->solid_fills[i].screen = -1;
55 memset(X11->pattern_fills, 0, sizeof(X11->pattern_fills));
56 for (int i = 0; i < X11->pattern_fill_count; ++i)
57 X11->pattern_fills[i].screen = -1;
58#endif
59
61
62#if QT_CONFIG(xrender)
63 if (X11->use_xrender) {
64 // XRender is supported, let's see if we have a PictFormat for the
65 // default visual
66 XRenderPictFormat *format =
67 XRenderFindVisualFormat(X11->display,
68 (Visual *) QXcbX11Info::appVisual(X11->defaultScreen));
69
70 if (!format) {
71 X11->use_xrender = false;
72 }
73 }
74#endif // QT_CONFIG(xrender)
75}
76
77QList<XRectangle> qt_region_to_xrectangles(const QRegion &r)
78{
79 const int numRects = r.rectCount();
80 const auto input = r.begin();
81 QList<XRectangle> output(numRects);
82 for (int i = 0; i < numRects; ++i) {
83 const QRect &in = input[i];
84 XRectangle &out = output[i];
85 out.x = qMax(SHRT_MIN, in.x());
86 out.y = qMax(SHRT_MIN, in.y());
87 out.width = qMin((int)USHRT_MAX, in.width());
88 out.height = qMin((int)USHRT_MAX, in.height());
89 }
90 return output;
91}
92
94{};
95
99
102
106
108{
109 d = other.d;
110 return *this;
111}
112
114{
116 xd->screen = screen;
117 xd->depth = QXcbX11Info::appDepth(screen);
118 xd->cells = QXcbX11Info::appCells(screen);
119 xd->colormap = QXcbX11Info::appColormap(screen);
120 xd->defaultColormap = QXcbX11Info::appDefaultColormap(screen);
121 xd->visual = (Visual *)QXcbX11Info::appVisual(screen);
122 xd->defaultVisual = QXcbX11Info::appDefaultVisual(screen);
123
125 info.d = xd;
126 return info;
127}
128
130{
131 if (!d)
132 *this = fromScreen(appScreen());
133
134 d->depth = depth;
135}
136
138{
139 return X11 ? X11->display : 0;
140}
141
143{
144 return d ? d->screen : QXcbX11Info::appScreen();
145}
146
148{
149 return d ? d->depth : QXcbX11Info::appDepth();
150}
151
153{
154 return d ? d->colormap : QXcbX11Info::appColormap();
155}
156
158{
159 return d ? d->visual : QXcbX11Info::appVisual();
160}
161
162void QXcbX11Info::setVisual(void *visual)
163{
164 if (!d)
165 *this = fromScreen(appScreen());
166
167 d->visual = (Visual *) visual;
168}
169
171{
172 return X11 ? X11->defaultScreen : 0;
173}
174
176{
177 return X11 ? X11->screens[screen == -1 ? X11->defaultScreen : screen].depth : 32;
178}
179
181{
182 return X11 ? X11->screens[screen == -1 ? X11->defaultScreen : screen].cells : 0;
183}
184
186{
187 return X11 ? X11->screens[screen == -1 ? X11->defaultScreen : screen].colormap : 0;
188}
189
191{
192 return X11 ? X11->screens[screen == -1 ? X11->defaultScreen : screen].visual : 0;
193}
194
196{
197 return X11 ? RootWindow(X11->display, screen == -1 ? X11->defaultScreen : screen) : 0;
198}
199
201{
202 return X11 ? X11->screens[screen == -1 ? X11->defaultScreen : screen].defaultColormap : true;
203}
204
206{
207 return X11 ? X11->screens[screen == -1 ? X11->defaultScreen : screen].defaultVisual : true;
208}
209
211{
212 if (!X11)
213 return 75;
214 if (screen < 0)
215 screen = X11->defaultScreen;
216 if (screen > X11->screenCount)
217 return 0;
218 return X11->screens[screen].dpiX;
219}
220
222{
223 if (!X11)
224 return 75;
225 if (screen < 0)
226 screen = X11->defaultScreen;
227 if (screen > X11->screenCount)
228 return 0;
229 return X11->screens[screen].dpiY;
230}
231
232#if QT_CONFIG(xrender)
233Picture QXcbX11Data::getSolidFill(int screen, const QColor &c)
234{
235 if (!X11->use_xrender)
236 return XNone;
237
238 XRenderColor color = preMultiply(c);
239 for (int i = 0; i < X11->solid_fill_count; ++i) {
240 if (X11->solid_fills[i].screen == screen
241 && X11->solid_fills[i].color.alpha == color.alpha
242 && X11->solid_fills[i].color.red == color.red
243 && X11->solid_fills[i].color.green == color.green
244 && X11->solid_fills[i].color.blue == color.blue)
245 return X11->solid_fills[i].picture;
246 }
247 // none found, replace one
248 int i = QRandomGenerator::global()->generate() % 16;
249
250 if (X11->solid_fills[i].screen != screen && X11->solid_fills[i].picture) {
251 XRenderFreePicture (X11->display, X11->solid_fills[i].picture);
252 X11->solid_fills[i].picture = 0;
253 }
254
255 if (!X11->solid_fills[i].picture) {
256 Pixmap pixmap = XCreatePixmap (X11->display, RootWindow (X11->display, screen), 1, 1, 32);
257 XRenderPictureAttributes attrs;
258 attrs.repeat = True;
259 X11->solid_fills[i].picture = XRenderCreatePicture (X11->display, pixmap,
260 XRenderFindStandardFormat(X11->display, PictStandardARGB32),
261 CPRepeat, &attrs);
262 XFreePixmap (X11->display, pixmap);
263 }
264
265 X11->solid_fills[i].color = color;
266 X11->solid_fills[i].screen = screen;
267 XRenderFillRectangle (X11->display, PictOpSrc, X11->solid_fills[i].picture, &color, 0, 0, 1, 1);
268 return X11->solid_fills[i].picture;
269}
270
271XRenderColor QXcbX11Data::preMultiply(const QColor &c)
272{
273 XRenderColor color;
274 const uint A = c.alpha(),
275 R = c.red(),
276 G = c.green(),
277 B = c.blue();
278 color.alpha = (A | A << 8);
279 color.red = (R | R << 8) * color.alpha / 0x10000;
280 color.green = (G | G << 8) * color.alpha / 0x10000;
281 color.blue = (B | B << 8) * color.alpha / 0x10000;
282 return color;
283}
284#endif // QT_CONFIG(xrender)
285
286
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
static Q_DECL_CONST_FUNCTION QRandomGenerator * global()
\threadsafe
Definition qrandom.h:275
\inmodule QtCore\reentrant
Definition qrect.h:30
The QRegion class specifies a clip region for a painter.
Definition qregion.h:27
\inmodule QtCore
Definition qshareddata.h:19
bool hasXRender(int major=-1, int minor=-1) const
static void initialize()
void setDepth(int depth)
static bool appDefaultVisual(int screen=-1)
static int appScreen()
static QXcbX11Info fromScreen(int screen)
static Colormap appColormap(int screen=-1)
static Window appRootWindow(int screen=-1)
static bool appDefaultColormap(int screen=-1)
static int appDepth(int screen=-1)
void setVisual(void *visual)
void * visual() const
static Display * display()
Colormap colormap() const
static int appDpiY(int screen=-1)
QXcbX11Info & operator=(const QXcbX11Info &other)
static int appCells(int screen=-1)
static void * appVisual(int screen=-1)
static int appDpiX(int screen=-1)
Combined button and popup list for selecting options.
static struct AttrInfo attrs[]
constexpr const T & qMin(const T &a, const T &b)
Definition qminmax.h:40
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42
n varying highp vec2 A
GLint GLenum GLsizei GLsizei GLsizei depth
GLboolean r
[2]
GLuint color
[2]
GLint GLsizei GLsizei GLenum format
GLdouble s
[6]
Definition qopenglext.h:235
const GLubyte * c
GLuint in
GLenum GLenum GLenum input
#define X11
XID Picture
XID Pixmap
#define X11
Definition qt_x11_p.h:141
@ XNone
Definition qt_x11_p.h:54
QScreen * screen
[1]
Definition main.cpp:29
Q_CORE_EXPORT bool qEnvironmentVariableIsSet(const char *varName) noexcept
struct _XDisplay Display
unsigned int uint
Definition qtypes.h:34
QT_BEGIN_NAMESPACE typedef uchar * output
QT_BEGIN_NAMESPACE QXcbX11Data * qt_x11Data
QList< XRectangle > qt_region_to_xrectangles(const QRegion &r)
void qt_xcb_native_x11_info_init(QXcbConnection *conn)
XID Colormap
struct _XDisplay Display
XID Window
QTextStream out(stdout)
[7]
QObject::connect nullptr
QSharedPointer< T > other(t)
[5]
widget render & pixmap
QHostInfo info
[0]
Visual * visual
Definition qt_x11_p.h:150
Colormap colormap
Definition qt_x11_p.h:149