author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Wed, 21 Apr 2010 12:15:23 +0300 | |
branch | RCL_3 |
changeset 12 | cc75c76972ee |
parent 7 | 3f74d0d4af4c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtGui module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
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 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
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 |
||
55 |
QT_BEGIN_NAMESPACE |
|
56 |
||
57 |
EGLSurface 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 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
96 |
EGLNativeDisplayType QEglContext::nativeDisplay() |
0 | 97 |
{ |
98 |
Display *xdpy = QX11Info::display(); |
|
99 |
if (!xdpy) { |
|
100 |
qWarning("QEglContext::getDisplay(): X11 display is not open"); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
101 |
return EGLNativeDisplayType(EGL_DEFAULT_DISPLAY); |
0 | 102 |
} |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
103 |
return EGLNativeDisplayType(xdpy); |
0 | 104 |
} |
105 |
||
106 |
static 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". |
|
118 |
void 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 |
||
143 |
extern const QX11Info *qt_x11Info(const QPaintDevice *pd); |
|
144 |
||
145 |
// Set pixel format and other properties based on a paint device. |
|
146 |
void 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 |
||
156 |
QT_END_NAMESPACE |