Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/platformsupport/eglconvenience/qxlibeglintegration.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||
2 | ** | - | ||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||
5 | ** | - | ||||||||||||
6 | ** This file is part of the plugins of the Qt Toolkit. | - | ||||||||||||
7 | ** | - | ||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||
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 http://www.qt.io/terms-conditions. For further | - | ||||||||||||
15 | ** information use the contact form at http://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 2.1 or version 3 as published by the Free | - | ||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||
25 | ** | - | ||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||
29 | ** | - | ||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||
31 | ** | - | ||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||
33 | - | |||||||||||||
34 | #include <QLoggingCategory> | - | ||||||||||||
35 | #include "qxlibeglintegration_p.h" | - | ||||||||||||
36 | - | |||||||||||||
37 | Q_LOGGING_CATEGORY(lcXlibEglDebug, "qt.egl.xlib.debug") never executed: return category; | 0 | ||||||||||||
38 | - | |||||||||||||
39 | VisualID QXlibEglIntegration::getCompatibleVisualId(Display *display, EGLDisplay eglDisplay, EGLConfig config) | - | ||||||||||||
40 | { | - | ||||||||||||
41 | VisualID visualId = 0; | - | ||||||||||||
42 | EGLint eglValue = 0; | - | ||||||||||||
43 | - | |||||||||||||
44 | EGLint configRedSize = 0; | - | ||||||||||||
45 | eglGetConfigAttrib(eglDisplay, config, EGL_RED_SIZE, &configRedSize); | - | ||||||||||||
46 | - | |||||||||||||
47 | EGLint configGreenSize = 0; | - | ||||||||||||
48 | eglGetConfigAttrib(eglDisplay, config, EGL_GREEN_SIZE, &configGreenSize); | - | ||||||||||||
49 | - | |||||||||||||
50 | EGLint configBlueSize = 0; | - | ||||||||||||
51 | eglGetConfigAttrib(eglDisplay, config, EGL_BLUE_SIZE, &configBlueSize); | - | ||||||||||||
52 | - | |||||||||||||
53 | EGLint configAlphaSize = 0; | - | ||||||||||||
54 | eglGetConfigAttrib(eglDisplay, config, EGL_ALPHA_SIZE, &configAlphaSize); | - | ||||||||||||
55 | - | |||||||||||||
56 | eglGetConfigAttrib(eglDisplay, config, EGL_CONFIG_ID, &eglValue); | - | ||||||||||||
57 | int configId = eglValue; | - | ||||||||||||
58 | - | |||||||||||||
59 | // See if EGL provided a valid VisualID: | - | ||||||||||||
60 | eglGetConfigAttrib(eglDisplay, config, EGL_NATIVE_VISUAL_ID, &eglValue); | - | ||||||||||||
61 | visualId = (VisualID)eglValue; | - | ||||||||||||
62 | if (visualId) {
| 0 | ||||||||||||
63 | // EGL has suggested a visual id, so get the rest of the visual info for that id: | - | ||||||||||||
64 | XVisualInfo visualInfoTemplate; | - | ||||||||||||
65 | memset(&visualInfoTemplate, 0, sizeof(XVisualInfo)); | - | ||||||||||||
66 | visualInfoTemplate.visualid = visualId; | - | ||||||||||||
67 | - | |||||||||||||
68 | XVisualInfo *chosenVisualInfo; | - | ||||||||||||
69 | int matchingCount = 0; | - | ||||||||||||
70 | chosenVisualInfo = XGetVisualInfo(display, VisualIDMask, &visualInfoTemplate, &matchingCount); | - | ||||||||||||
71 | if (chosenVisualInfo) {
| 0 | ||||||||||||
72 | // Skip size checks if implementation supports non-matching visual | - | ||||||||||||
73 | // and config (QTBUG-9444). | - | ||||||||||||
74 | if (q_hasEglExtension(eglDisplay,"EGL_NV_post_convert_rounding")) {
| 0 | ||||||||||||
75 | XFree(chosenVisualInfo); | - | ||||||||||||
76 | return visualId; never executed: return visualId; | 0 | ||||||||||||
77 | } | - | ||||||||||||
78 | // Skip also for i.MX6 where 565 visuals are suggested for the default 444 configs and it works just fine. | - | ||||||||||||
79 | const char *vendor = eglQueryString(eglDisplay, EGL_VENDOR); | - | ||||||||||||
80 | if (vendor && strstr(vendor, "Vivante")) {
| 0 | ||||||||||||
81 | XFree(chosenVisualInfo); | - | ||||||||||||
82 | return visualId; never executed: return visualId; | 0 | ||||||||||||
83 | } | - | ||||||||||||
84 | - | |||||||||||||
85 | int visualRedSize = qPopulationCount(chosenVisualInfo->red_mask); | - | ||||||||||||
86 | int visualGreenSize = qPopulationCount(chosenVisualInfo->green_mask); | - | ||||||||||||
87 | int visualBlueSize = qPopulationCount(chosenVisualInfo->blue_mask); | - | ||||||||||||
88 | int visualAlphaSize = chosenVisualInfo->depth == 32 ? 8 : 0;
| 0 | ||||||||||||
89 | - | |||||||||||||
90 | const bool visualMatchesConfig = visualRedSize == configRedSize
| 0 | ||||||||||||
91 | && visualGreenSize == configGreenSize
| 0 | ||||||||||||
92 | && visualBlueSize == configBlueSize
| 0 | ||||||||||||
93 | && visualAlphaSize == configAlphaSize;
| 0 | ||||||||||||
94 | - | |||||||||||||
95 | // In some cases EGL tends to suggest a 24-bit visual for 8888 | - | ||||||||||||
96 | // configs. In such a case we have to fall back to XGetVisualInfo. | - | ||||||||||||
97 | if (!visualMatchesConfig) {
| 0 | ||||||||||||
98 | visualId = 0; | - | ||||||||||||
99 | qCDebug(lcXlibEglDebug, never executed: QMessageLogger( __FILE__ , 103 , __PRETTY_FUNCTION__, lcXlibEglDebug().categoryName()).debug("EGL suggested using X Visual ID %d (%d %d %d depth %d) for EGL config %d" "(%d %d %d %d), but this is incompatible", (int)visualId, visualRedSize, visualGreenSize, visualBlueSize, chosenVisualInfo->depth, configId, configRedSize, configGreenSize, configBlueSize, configAlphaSize) ;
| 0 | ||||||||||||
100 | "EGL suggested using X Visual ID %d (%d %d %d depth %d) for EGL config %d" never executed: QMessageLogger( __FILE__ , 103 , __PRETTY_FUNCTION__, lcXlibEglDebug().categoryName()).debug("EGL suggested using X Visual ID %d (%d %d %d depth %d) for EGL config %d" "(%d %d %d %d), but this is incompatible", (int)visualId, visualRedSize, visualGreenSize, visualBlueSize, chosenVisualInfo->depth, configId, configRedSize, configGreenSize, configBlueSize, configAlphaSize) ; | 0 | ||||||||||||
101 | "(%d %d %d %d), but this is incompatible", never executed: QMessageLogger( __FILE__ , 103 , __PRETTY_FUNCTION__, lcXlibEglDebug().categoryName()).debug("EGL suggested using X Visual ID %d (%d %d %d depth %d) for EGL config %d" "(%d %d %d %d), but this is incompatible", (int)visualId, visualRedSize, visualGreenSize, visualBlueSize, chosenVisualInfo->depth, configId, configRedSize, configGreenSize, configBlueSize, configAlphaSize) ; | 0 | ||||||||||||
102 | (int)visualId, visualRedSize, visualGreenSize, visualBlueSize, chosenVisualInfo->depth, never executed: QMessageLogger( __FILE__ , 103 , __PRETTY_FUNCTION__, lcXlibEglDebug().categoryName()).debug("EGL suggested using X Visual ID %d (%d %d %d depth %d) for EGL config %d" "(%d %d %d %d), but this is incompatible", (int)visualId, visualRedSize, visualGreenSize, visualBlueSize, chosenVisualInfo->depth, configId, configRedSize, configGreenSize, configBlueSize, configAlphaSize) ; | 0 | ||||||||||||
103 | configId, configRedSize, configGreenSize, configBlueSize, configAlphaSize); never executed: QMessageLogger( __FILE__ , 103 , __PRETTY_FUNCTION__, lcXlibEglDebug().categoryName()).debug("EGL suggested using X Visual ID %d (%d %d %d depth %d) for EGL config %d" "(%d %d %d %d), but this is incompatible", (int)visualId, visualRedSize, visualGreenSize, visualBlueSize, chosenVisualInfo->depth, configId, configRedSize, configGreenSize, configBlueSize, configAlphaSize) ; | 0 | ||||||||||||
104 | } never executed: end of block | 0 | ||||||||||||
105 | } else { never executed: end of block | 0 | ||||||||||||
106 | qCDebug(lcXlibEglDebug, "EGL suggested using X Visual ID %d for EGL config %d, but that isn't a valid ID", never executed: QMessageLogger( __FILE__ , 107 , __PRETTY_FUNCTION__, lcXlibEglDebug().categoryName()).debug("EGL suggested using X Visual ID %d for EGL config %d, but that isn't a valid ID", (int)visualId, configId) ;
| 0 | ||||||||||||
107 | (int)visualId, configId); never executed: QMessageLogger( __FILE__ , 107 , __PRETTY_FUNCTION__, lcXlibEglDebug().categoryName()).debug("EGL suggested using X Visual ID %d for EGL config %d, but that isn't a valid ID", (int)visualId, configId) ; | 0 | ||||||||||||
108 | visualId = 0; | - | ||||||||||||
109 | } never executed: end of block | 0 | ||||||||||||
110 | XFree(chosenVisualInfo); | - | ||||||||||||
111 | } never executed: end of block | 0 | ||||||||||||
112 | else | - | ||||||||||||
113 | qCDebug(lcXlibEglDebug, "EGL did not suggest a VisualID (EGL_NATIVE_VISUAL_ID was zero) for EGLConfig %d", configId); never executed: QMessageLogger(__FILE__, 113, __PRETTY_FUNCTION__, lcXlibEglDebug().categoryName()).debug("EGL did not suggest a VisualID (EGL_NATIVE_VISUAL_ID was zero) for EGLConfig %d", configId);
| 0 | ||||||||||||
114 | - | |||||||||||||
115 | if (visualId) {
| 0 | ||||||||||||
116 | qCDebug(lcXlibEglDebug, configAlphaSize > 0 never executed: QMessageLogger( __FILE__ , 118 , __PRETTY_FUNCTION__, lcXlibEglDebug().categoryName()).debug(configAlphaSize > 0 ? "Using ARGB Visual ID %d provided by EGL for config %d" : "Using Opaque Visual ID %d provided by EGL for config %d", (int)visualId, configId) ;
| 0 | ||||||||||||
117 | ? "Using ARGB Visual ID %d provided by EGL for config %d" never executed: QMessageLogger( __FILE__ , 118 , __PRETTY_FUNCTION__, lcXlibEglDebug().categoryName()).debug(configAlphaSize > 0 ? "Using ARGB Visual ID %d provided by EGL for config %d" : "Using Opaque Visual ID %d provided by EGL for config %d", (int)visualId, configId) ; | 0 | ||||||||||||
118 | : "Using Opaque Visual ID %d provided by EGL for config %d", (int)visualId, configId); never executed: QMessageLogger( __FILE__ , 118 , __PRETTY_FUNCTION__, lcXlibEglDebug().categoryName()).debug(configAlphaSize > 0 ? "Using ARGB Visual ID %d provided by EGL for config %d" : "Using Opaque Visual ID %d provided by EGL for config %d", (int)visualId, configId) ; | 0 | ||||||||||||
119 | return visualId; never executed: return visualId; | 0 | ||||||||||||
120 | } | - | ||||||||||||
121 | - | |||||||||||||
122 | // Finally, try to use XGetVisualInfo and only use the bit depths to match on: | - | ||||||||||||
123 | if (!visualId) {
| 0 | ||||||||||||
124 | XVisualInfo visualInfoTemplate; | - | ||||||||||||
125 | memset(&visualInfoTemplate, 0, sizeof(XVisualInfo)); | - | ||||||||||||
126 | XVisualInfo *matchingVisuals; | - | ||||||||||||
127 | int matchingCount = 0; | - | ||||||||||||
128 | - | |||||||||||||
129 | visualInfoTemplate.depth = configRedSize + configGreenSize + configBlueSize + configAlphaSize; | - | ||||||||||||
130 | matchingVisuals = XGetVisualInfo(display, | - | ||||||||||||
131 | VisualDepthMask, | - | ||||||||||||
132 | &visualInfoTemplate, | - | ||||||||||||
133 | &matchingCount); | - | ||||||||||||
134 | if (!matchingVisuals) {
| 0 | ||||||||||||
135 | // Try again without taking the alpha channel into account: | - | ||||||||||||
136 | visualInfoTemplate.depth = configRedSize + configGreenSize + configBlueSize; | - | ||||||||||||
137 | matchingVisuals = XGetVisualInfo(display, | - | ||||||||||||
138 | VisualDepthMask, | - | ||||||||||||
139 | &visualInfoTemplate, | - | ||||||||||||
140 | &matchingCount); | - | ||||||||||||
141 | } never executed: end of block | 0 | ||||||||||||
142 | - | |||||||||||||
143 | if (matchingVisuals) {
| 0 | ||||||||||||
144 | visualId = matchingVisuals[0].visualid; | - | ||||||||||||
145 | XFree(matchingVisuals); | - | ||||||||||||
146 | } never executed: end of block | 0 | ||||||||||||
147 | } never executed: end of block | 0 | ||||||||||||
148 | - | |||||||||||||
149 | if (visualId) {
| 0 | ||||||||||||
150 | qCDebug(lcXlibEglDebug, "Using Visual ID %d provided by XGetVisualInfo for EGL config %d", (int)visualId, configId); never executed: QMessageLogger(__FILE__, 150, __PRETTY_FUNCTION__, lcXlibEglDebug().categoryName()).debug("Using Visual ID %d provided by XGetVisualInfo for EGL config %d", (int)visualId, configId);
| 0 | ||||||||||||
151 | return visualId; never executed: return visualId; | 0 | ||||||||||||
152 | } | - | ||||||||||||
153 | - | |||||||||||||
154 | qWarning("Unable to find an X11 visual which matches EGL config %d", configId); | - | ||||||||||||
155 | return (VisualID)0; never executed: return (VisualID)0; | 0 | ||||||||||||
156 | } | - | ||||||||||||
Source code | Switch to Preprocessed file |