1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the QtOpenGL module of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** 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 are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #include <QtGui/qpaintdevice.h>
|
---|
43 | #include <QtGui/qpixmap.h>
|
---|
44 | #include <QtGui/qwidget.h>
|
---|
45 | #include "qegl_p.h"
|
---|
46 |
|
---|
47 | #if defined(QT_OPENGL_ES) || defined(QT_OPENVG)
|
---|
48 |
|
---|
49 | #if defined(Q_WS_X11)
|
---|
50 | #include <QtGui/qx11info_x11.h>
|
---|
51 | #include <X11/Xlib.h>
|
---|
52 | #include <X11/Xutil.h>
|
---|
53 | #endif
|
---|
54 |
|
---|
55 | QT_BEGIN_NAMESPACE
|
---|
56 |
|
---|
57 | bool QEglContext::createSurface(QPaintDevice *device)
|
---|
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 false;
|
---|
76 | }
|
---|
77 |
|
---|
78 | // Create the EGL surface to draw into, based on the native drawable.
|
---|
79 | if (devType == QInternal::Widget)
|
---|
80 | surf = eglCreateWindowSurface(dpy, cfg, windowDrawable, 0);
|
---|
81 | else
|
---|
82 | surf = eglCreatePixmapSurface(dpy, cfg, pixmapDrawable, 0);
|
---|
83 | if (surf == EGL_NO_SURFACE) {
|
---|
84 | qWarning("QEglContext::createSurface(): Unable to create EGL surface, error = 0x%x", eglGetError());
|
---|
85 | return false;
|
---|
86 | }
|
---|
87 | return true;
|
---|
88 | }
|
---|
89 |
|
---|
90 | EGLDisplay QEglContext::getDisplay(QPaintDevice *device)
|
---|
91 | {
|
---|
92 | Q_UNUSED(device);
|
---|
93 | Display *xdpy = QX11Info::display();
|
---|
94 | if (!xdpy) {
|
---|
95 | qWarning("QEglContext::getDisplay(): X11 display is not open");
|
---|
96 | return EGL_NO_DISPLAY;
|
---|
97 | }
|
---|
98 | return eglGetDisplay(EGLNativeDisplayType(xdpy));
|
---|
99 | }
|
---|
100 |
|
---|
101 | static int countBits(unsigned long mask)
|
---|
102 | {
|
---|
103 | int count = 0;
|
---|
104 | while (mask != 0) {
|
---|
105 | if (mask & 1)
|
---|
106 | ++count;
|
---|
107 | mask >>= 1;
|
---|
108 | }
|
---|
109 | return count;
|
---|
110 | }
|
---|
111 |
|
---|
112 | // Set the pixel format parameters from the visual in "xinfo".
|
---|
113 | void QEglProperties::setVisualFormat(const QX11Info *xinfo)
|
---|
114 | {
|
---|
115 | if (!xinfo)
|
---|
116 | return;
|
---|
117 | Visual *visual = (Visual*)xinfo->visual();
|
---|
118 | if (!visual)
|
---|
119 | return;
|
---|
120 | if (visual->c_class != TrueColor && visual->c_class != DirectColor)
|
---|
121 | return;
|
---|
122 | setValue(EGL_RED_SIZE, countBits(visual->red_mask));
|
---|
123 | setValue(EGL_GREEN_SIZE, countBits(visual->green_mask));
|
---|
124 | setValue(EGL_BLUE_SIZE, countBits(visual->blue_mask));
|
---|
125 | setValue(EGL_ALPHA_SIZE, 0); // XXX
|
---|
126 | }
|
---|
127 |
|
---|
128 | QT_END_NAMESPACE
|
---|
129 |
|
---|
130 | #endif // QT_OPENGL_ES || QT_OPENVG
|
---|