source: trunk/src/gui/egl/qegl_x11.cpp@ 769

Last change on this file since 769 was 769, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.3 sources from branches/vendor/nokia/qt.

  • Property svn:eol-style set to native
File size: 5.3 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtGui module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include <QtCore/qdebug.h>
43
44#include <private/qt_x11_p.h>
45#include <QtGui/qx11info_x11.h>
46#include <private/qpixmapdata_p.h>
47#include <private/qpixmap_x11_p.h>
48
49#include <QtGui/qpaintdevice.h>
50#include <QtGui/qpixmap.h>
51#include <QtGui/qwidget.h>
52#include "qegl_p.h"
53
54
55QT_BEGIN_NAMESPACE
56
57EGLSurface QEglContext::createSurface(QPaintDevice *device, const QEglProperties *properties)
58{
59 // Create the native drawable for the paint device.
60 int devType = device->devType();
61 EGLNativePixmapType pixmapDrawable = 0;
62 EGLNativeWindowType windowDrawable = 0;
63 bool ok;
64 if (devType == QInternal::Pixmap) {
65 pixmapDrawable = (EGLNativePixmapType)(static_cast<QPixmap *>(device))->handle();
66 ok = (pixmapDrawable != 0);
67 } else if (devType == QInternal::Widget) {
68 windowDrawable = (EGLNativeWindowType)(static_cast<QWidget *>(device))->winId();
69 ok = (windowDrawable != 0);
70 } else {
71 ok = false;
72 }
73 if (!ok) {
74 qWarning("QEglContext::createSurface(): Cannot create the native EGL drawable");
75 return EGL_NO_SURFACE;
76 }
77
78 // Create the EGL surface to draw into, based on the native drawable.
79 const int *props;
80 if (properties)
81 props = properties->properties();
82 else
83 props = 0;
84 EGLSurface surf;
85 if (devType == QInternal::Widget)
86 surf = eglCreateWindowSurface(dpy, cfg, windowDrawable, props);
87 else
88 surf = eglCreatePixmapSurface(dpy, cfg, pixmapDrawable, props);
89 if (surf == EGL_NO_SURFACE) {
90 qWarning() << "QEglContext::createSurface(): Unable to create EGL surface:"
91 << errorString(eglGetError());
92 }
93 return surf;
94}
95
96EGLNativeDisplayType QEglContext::nativeDisplay()
97{
98 Display *xdpy = QX11Info::display();
99 if (!xdpy) {
100 qWarning("QEglContext::getDisplay(): X11 display is not open");
101 return EGLNativeDisplayType(EGL_DEFAULT_DISPLAY);
102 }
103 return EGLNativeDisplayType(xdpy);
104}
105
106static int countBits(unsigned long mask)
107{
108 int count = 0;
109 while (mask != 0) {
110 if (mask & 1)
111 ++count;
112 mask >>= 1;
113 }
114 return count;
115}
116
117// Set the pixel format parameters from the visual in "xinfo".
118void QEglProperties::setVisualFormat(const QX11Info *xinfo)
119{
120 if (!xinfo)
121 return;
122 Visual *visual = (Visual*)xinfo->visual();
123 if (!visual)
124 return;
125 if (visual->c_class != TrueColor && visual->c_class != DirectColor)
126 return;
127 setValue(EGL_RED_SIZE, countBits(visual->red_mask));
128 setValue(EGL_GREEN_SIZE, countBits(visual->green_mask));
129 setValue(EGL_BLUE_SIZE, countBits(visual->blue_mask));
130
131 EGLint alphaBits = 0;
132#if !defined(QT_NO_XRENDER)
133 XRenderPictFormat *format;
134 format = XRenderFindVisualFormat(xinfo->display(), visual);
135 if (format && (format->type == PictTypeDirect) && format->direct.alphaMask) {
136 alphaBits = countBits(format->direct.alphaMask);
137 qDebug("QEglProperties::setVisualFormat() - visual's alphaMask is %d", alphaBits);
138 }
139#endif
140 setValue(EGL_ALPHA_SIZE, alphaBits);
141}
142
143extern const QX11Info *qt_x11Info(const QPaintDevice *pd);
144
145// Set pixel format and other properties based on a paint device.
146void QEglProperties::setPaintDeviceFormat(QPaintDevice *dev)
147{
148 if (!dev)
149 return;
150 if (dev->devType() == QInternal::Image)
151 setPixelFormat(static_cast<QImage *>(dev)->format());
152 else
153 setVisualFormat(qt_x11Info(dev));
154}
155
156QT_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.