42 #include <QtCore/qdebug.h> 44 #include <QtGui/private/qt_x11_p.h> 45 #include <QtGui/qx11info_x11.h> 46 #include <QtGui/private/qpixmapdata_p.h> 47 #include <QtGui/private/qpixmap_x11_p.h> 48 #include <QtGui/private/qimagepixmapcleanuphooks_p.h> 50 #include <QtGui/qpaintdevice.h> 51 #include <QtGui/qpixmap.h> 52 #include <QtGui/qwidget.h> 53 #include <QtGui/qcolormap.h> 55 #include "QtGui/private/qegl_p.h" 56 #include "QtGui/private/qeglcontext_p.h" 65 qWarning(
"QEglContext::getDisplay(): X11 display is not open");
97 Visual *visual = (Visual*)xinfo->
visual();
100 if (visual->c_class != TrueColor && visual->c_class != DirectColor)
106 EGLint alphaBits = 0;
107 #if !defined(QT_NO_XRENDER) 108 XRenderPictFormat *
format;
109 format = XRenderFindVisualFormat(xinfo->
display(), visual);
110 if (format && (format->type == PictTypeDirect) && format->direct.alphaMask) {
111 alphaBits =
countBits(format->direct.alphaMask);
112 qDebug(
"QEglProperties::setVisualFormat() - visual's alphaMask is %d", alphaBits);
115 setValue(EGL_ALPHA_SIZE, alphaBits);
135 VisualID visualId = 0;
138 EGLint configRedSize = 0;
139 eglGetConfigAttrib(
display(), config, EGL_RED_SIZE, &configRedSize);
141 EGLint configGreenSize = 0;
142 eglGetConfigAttrib(
display(), config, EGL_GREEN_SIZE, &configGreenSize);
144 EGLint configBlueSize = 0;
145 eglGetConfigAttrib(
display(), config, EGL_BLUE_SIZE, &configBlueSize);
147 EGLint configAlphaSize = 0;
148 eglGetConfigAttrib(
display(), config, EGL_ALPHA_SIZE, &configAlphaSize);
150 eglGetConfigAttrib(
display(), config, EGL_CONFIG_ID, &eglValue);
151 int configId = eglValue;
154 eglGetConfigAttrib(
display(), config, EGL_NATIVE_VISUAL_ID, &eglValue);
155 visualId = (VisualID)eglValue;
158 XVisualInfo visualInfoTemplate;
159 memset(&visualInfoTemplate, 0,
sizeof(XVisualInfo));
160 visualInfoTemplate.visualid = visualId;
162 XVisualInfo *chosenVisualInfo;
163 int matchingCount = 0;
164 chosenVisualInfo = XGetVisualInfo(
X11->display, VisualIDMask, &visualInfoTemplate, &matchingCount);
165 if (chosenVisualInfo) {
169 XFree(chosenVisualInfo);
173 int visualRedSize =
countBits(chosenVisualInfo->red_mask);
174 int visualGreenSize =
countBits(chosenVisualInfo->green_mask);
175 int visualBlueSize =
countBits(chosenVisualInfo->blue_mask);
176 int visualAlphaSize = -1;
178 #if !defined(QT_NO_XRENDER) 179 if (
X11->use_xrender) {
181 XRenderPictFormat *
format;
182 format = XRenderFindVisualFormat(
X11->display, chosenVisualInfo->visual);
183 if (format && (format->type == PictTypeDirect))
184 visualAlphaSize =
countBits(format->direct.alphaMask);
188 bool visualMatchesConfig =
false;
189 if ( visualRedSize == configRedSize &&
190 visualGreenSize == configGreenSize &&
191 visualBlueSize == configBlueSize )
195 if (visualAlphaSize >= 0)
196 visualMatchesConfig = visualAlphaSize == configAlphaSize;
198 visualMatchesConfig =
true;
201 if (!visualMatchesConfig) {
202 if (visualAlphaSize >= 0) {
203 qWarning(
"Warning: EGL suggested using X Visual ID %d (ARGB%d%d%d%d) for EGL config %d (ARGB%d%d%d%d), but this is incompatable",
204 (
int)visualId, visualAlphaSize, visualRedSize, visualGreenSize, visualBlueSize,
205 configId, configAlphaSize, configRedSize, configGreenSize, configBlueSize);
207 qWarning(
"Warning: EGL suggested using X Visual ID %d (RGB%d%d%d) for EGL config %d (RGB%d%d%d), but this is incompatable",
208 (
int)visualId, visualRedSize, visualGreenSize, visualBlueSize,
209 configId, configRedSize, configGreenSize, configBlueSize);
214 qWarning(
"Warning: EGL suggested using X Visual ID %d for EGL config %d, but that isn't a valid ID",
215 (
int)visualId, configId);
218 XFree(chosenVisualInfo);
220 #ifdef QT_DEBUG_X11_VISUAL_SELECTION 222 qDebug(
"EGL did not suggest a VisualID (EGL_NATIVE_VISUAL_ID was zero) for EGLConfig %d", configId);
226 #ifdef QT_DEBUG_X11_VISUAL_SELECTION 227 if (configAlphaSize > 0)
228 qDebug(
"Using ARGB Visual ID %d provided by EGL for config %d", (
int)visualId, configId);
230 qDebug(
"Using Opaque Visual ID %d provided by EGL for config %d", (
int)visualId, configId);
237 #if !defined(QT_NO_XRENDER) 238 if (!visualId &&
X11->use_xrender) {
239 XVisualInfo visualInfoTemplate;
240 memset(&visualInfoTemplate, 0,
sizeof(XVisualInfo));
242 visualInfoTemplate.c_class = TrueColor;
244 XVisualInfo *matchingVisuals;
245 int matchingCount = 0;
246 matchingVisuals = XGetVisualInfo(
X11->display,
251 for (
int i = 0; i < matchingCount; ++i) {
252 XRenderPictFormat *
format;
253 format = XRenderFindVisualFormat(
X11->display, matchingVisuals[i].visual);
256 if ( (
countBits(format->direct.redMask) == configRedSize) &&
257 (
countBits(format->direct.greenMask) == configGreenSize) &&
258 (
countBits(format->direct.blueMask) == configBlueSize) &&
259 (
countBits(format->direct.alphaMask) == configAlphaSize) )
261 visualId = matchingVisuals[i].visualid;
266 XFree(matchingVisuals);
270 # ifdef QT_DEBUG_X11_VISUAL_SELECTION 271 if (configAlphaSize > 0)
272 qDebug(
"Using ARGB Visual ID %d provided by XRender for EGL config %d", (
int)visualId, configId);
274 qDebug(
"Using Opaque Visual ID %d provided by XRender for EGL config %d", (
int)visualId, configId);
275 # endif // QT_DEBUG_X11_VISUAL_SELECTION 278 # ifdef QT_DEBUG_X11_VISUAL_SELECTION 280 qDebug(
"Failed to find an XVisual which matches EGL config %d using XRender", configId);
281 # endif // QT_DEBUG_X11_VISUAL_SELECTION 289 XVisualInfo visualInfoTemplate;
290 memset(&visualInfoTemplate, 0,
sizeof(XVisualInfo));
291 XVisualInfo *matchingVisuals;
292 int matchingCount = 0;
294 visualInfoTemplate.depth = configRedSize + configGreenSize + configBlueSize + configAlphaSize;
295 matchingVisuals = XGetVisualInfo(
X11->display,
299 if (!matchingVisuals) {
301 visualInfoTemplate.depth = configRedSize + configGreenSize + configBlueSize;
302 matchingVisuals = XGetVisualInfo(
X11->display,
308 if (matchingVisuals) {
309 visualId = matchingVisuals[0].visualid;
310 XFree(matchingVisuals);
315 #ifdef QT_DEBUG_X11_VISUAL_SELECTION 316 qDebug(
"Using Visual ID %d provided by XGetVisualInfo for EGL config %d", (
int)visualId, configId);
321 qWarning(
"Unable to find an X11 visual which matches EGL config %d", configId);
335 int devType = device->
devType();
339 return EGL_NO_SURFACE;
346 x11PixmapData = static_cast<QX11PixmapData*>(pmd);
349 qWarning(
"WARNING: Creating an EGL surface on a QPixmap is only supported for QX11PixmapData");
350 return EGL_NO_SURFACE;
353 qWarning(
"WARNING: Creating an EGLSurface for device type %d isn't supported", devType);
354 return EGL_NO_SURFACE;
359 eglGetConfigAttrib(
QEgl::display(), config, EGL_ALPHA_SIZE, &alphaSize);
364 VisualID currentVisualId = 0;
366 currentVisualId = XVisualIDFromVisual((Visual*)widget->
x11Info().
visual());
368 if (currentVisualId != visualId) {
376 XVisualInfo visualInfo;
377 visualInfo.visualid = visualId;
379 XVisualInfo *visualInfoPtr;
380 int matchingCount = 0;
381 visualInfoPtr = XGetVisualInfo(widget->
x11Info().
display(), VisualIDMask,
382 &visualInfo, &matchingCount);
384 visualInfo = *visualInfoPtr;
385 XFree(visualInfoPtr);
392 XSetWindowAttributes windowAttribs;
397 unsigned int valueMask = CWBackPixel|CWBorderPixel;
399 windowAttribs.colormap = XCreateColormap(widget->
x11Info().
display(), parentWindow,
400 visualInfo.visual, AllocNone);
401 valueMask |= CWColormap;
406 0, visualInfo.depth, InputOutput, visualInfo.visual,
407 valueMask, &windowAttribs);
424 if (surf == EGL_NO_SURFACE)
425 qWarning(
"QEglContext::createSurface(): Unable to create EGL surface, error = 0x%x", eglGetError());
432 eglGetConfigAttrib(
QEgl::display(), config, EGL_BUFFER_SIZE , &configDepth);
433 if (x11PixmapData->
depth() != configDepth) {
438 #ifndef QT_NO_XRENDER 439 if (configDepth == 32) {
440 qWarning(
"Warning: EGLConfig's depth (32) != pixmap's depth (%d), converting to ARGB32",
441 x11PixmapData->
depth());
446 qWarning(
"Warning: EGLConfig's depth (%d) != pixmap's depth (%d)",
447 configDepth, x11PixmapData->
depth());
454 surfaceAttribs.
setValue(EGL_TEXTURE_TARGET, EGL_TEXTURE_2D);
456 surfaceAttribs.setValue(EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGBA);
458 surfaceAttribs.setValue(EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGB);
460 EGLSurface surf = eglCreatePixmapSurface(
QEgl::display(), config,
462 surfaceAttribs.properties());
468 return EGL_NO_SURFACE;
static QColormap instance(int screen=-1)
#define QT_END_NAMESPACE
This macro expands to.
QPointer< QWidget > widget
NativePixmapType EGLNativePixmapType
const EGLint * properties() const
Qt::HANDLE handle() const
Returns the pixmap's handle to the device context.
static void enableCleanupHooks(const QImage &image)
void qt_set_winid_on_widget(QWidget *w, Qt::HANDLE id)
void setValue(int name, int value)
const QColor & color(ColorGroup cg, ColorRole cr) const
Returns the color in the specified color group, used for the given color role.
NativeWindowType EGLNativeWindowType
Q_GUI_EXPORT EGLNativePixmapType nativePixmap(QPixmap *)
virtual int devType() const
static int countBits(unsigned long mask)
Q_CORE_EXPORT void qDebug(const char *,...)
void setVisualFormat(const QX11Info *xinfo)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Q_GUI_EXPORT EGLDisplay display()
const QX11Info * qt_x11Info(const QPaintDevice *pd)
Qt::HANDLE handle() const
Q_CORE_EXPORT void qWarning(const char *,...)
void convertToARGB32(bool preserveContents=true)
void * visual() const
Returns the current visual.
uint pixel(const QColor &color) const
Q_GUI_EXPORT bool hasExtension(const char *extensionName)
The QX11Info class provides information about the X display configuration.
QVarLengthArray< EGLint > props
Q_GUI_EXPORT EGLSurface createSurface(QPaintDevice *device, EGLConfig cfg, const QEglProperties *surfaceAttribs=0)
Q_GUI_EXPORT EGLNativeDisplayType nativeDisplay()
void * data_ptr(const QTransform &t)
void setPaintDeviceFormat(QPaintDevice *dev)
The QPixmap class is an off-screen image representation that can be used as a paint device...
Q_GUI_EXPORT VisualID getCompatibleVisualId(EGLConfig config)
void setPixelFormat(QImage::Format pixelFormat)
NativeDisplayType EGLNativeDisplayType
Q_GUI_EXPORT EGLNativeWindowType nativeWindow(QWidget *)
static Display * display()
Returns the default display for the application.
int screen() const
Returns the number of the screen currently in use.