Qt 4.8
qxcbnativeinterface.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the plugins of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qxcbnativeinterface.h"
43 
44 #include "qxcbscreen.h"
45 
46 #include <QtGui/private/qapplication_p.h>
47 #include <QtCore/QMap>
48 
49 #include <QtCore/QDebug>
50 
51 #if defined(XCB_USE_EGL)
52 #include "../eglconvenience/qeglplatformcontext.h"
53 #elif defined (XCB_USE_DRI2)
54 #include "qdri2context.h"
55 #endif
56 
57 class QXcbResourceMap : public QMap<QByteArray, QXcbNativeInterface::ResourceType>
58 {
59 public:
61  :QMap<QByteArray, QXcbNativeInterface::ResourceType>()
62  {
69  }
70 };
71 
72 Q_GLOBAL_STATIC(QXcbResourceMap, qXcbResourceMap)
73 
74 void *QXcbNativeInterface::nativeResourceForWidget(const QByteArray &resourceString, QWidget *widget)
75 {
76  QByteArray lowerCaseResource = resourceString.toLower();
77  ResourceType resource = qXcbResourceMap()->value(lowerCaseResource);
78  void *result = 0;
79  switch(resource) {
80  case Display:
81  result = displayForWidget(widget);
82  break;
83  case EglDisplay:
84  result = eglDisplayForWidget(widget);
85  break;
86  case Connection:
87  result = connectionForWidget(widget);
88  break;
89  case Screen:
90  result = qPlatformScreenForWidget(widget);
91  break;
92  case GraphicsDevice:
93  result = graphicsDeviceForWidget(widget);
94  break;
95  case EglContext:
96  result = eglContextForWidget(widget);
97  break;
98  default:
99  result = 0;
100  }
101  return result;
102 }
103 
105 {
106  QXcbScreen *screen;
107  if (widget) {
108  screen = static_cast<QXcbScreen *>(QPlatformScreen::platformScreenForWidget(widget));
109  }else {
110  screen = static_cast<QXcbScreen *>(QApplicationPrivate::platformIntegration()->screens()[0]);
111  }
112  return screen;
113 }
114 
116 {
117 #if defined(XCB_USE_XLIB)
118  QXcbScreen *screen = qPlatformScreenForWidget(widget);
119  return screen->connection()->xlib_display();
120 #else
121  Q_UNUSED(widget);
122  return 0;
123 #endif
124 }
125 
127 {
128 #if defined(XCB_USE_DRI2) || defined(XCB_USE_EGL)
129  QXcbScreen *screen = qPlatformScreenForWidget(widget);
130  return screen->connection()->egl_display();
131 #else
132  Q_UNUSED(widget)
133  return 0;
134 #endif
135 }
136 
138 {
139  QXcbScreen *screen = qPlatformScreenForWidget(widget);
140  return screen->xcb_connection();
141 }
142 
144 {
145  QXcbScreen *screen = qPlatformScreenForWidget(widget);
146  return screen->screen();
147 }
148 
150 {
151 #if defined(XCB_USE_DRI2)
152  QXcbScreen *screen = qPlatformScreenForWidget(widget);
153  QByteArray deviceName = screen->connection()->dri2DeviceName();
154  return deviceName.data();
155 #else
156  Q_UNUSED(widget);
157  return 0;
158 #endif
159 
160 }
161 
163 {
164  Q_ASSERT(widget);
165  if (!widget->platformWindow()) {
166  qDebug() << "QPlatformWindow does not exist for widget" << widget
167  << "cannot return EGLContext";
168  return 0;
169  }
170  QPlatformGLContext *platformContext = widget->platformWindow()->glContext();
171  if (!platformContext) {
172  qDebug() << "QPlatformWindow" << widget->platformWindow() << "does not have a glContext"
173  << "cannot return EGLContext";
174  return 0;
175  }
176 #if defined(XCB_USE_EGL)
177  QEGLPlatformContext *eglPlatformContext = static_cast<QEGLPlatformContext *>(platformContext);
178  return eglPlatformContext->eglContext();
179 #elif defined (XCB_USE_DRI2)
180  QDri2Context *dri2Context = static_cast<QDri2Context *>(platformContext);
181  return dri2Context->eglContext();
182 #else
183  return 0;
184 #endif
185 }
QPointer< QWidget > widget
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
static QXcbScreen * qPlatformScreenForWidget(QWidget *widget)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
xcb_connection_t * xcb_connection() const
Definition: qxcbobject.h:56
EGLContext eglContext() const
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QByteArray toLower() const
Returns a lowercase copy of the byte array.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QXcbConnection * connection() const
Definition: qxcbobject.h:53
Q_CORE_EXPORT void qDebug(const char *,...)
#define Q_GLOBAL_STATIC(TYPE, NAME)
Declares a global static variable with the given type and name.
Definition: qglobal.h:1968
void * connectionForWidget(QWidget *widget)
void * eglContext() const
static QPlatformScreen * platformScreenForWidget(const QWidget *widget)
void * eglContextForWidget(QWidget *widget)
struct _XDisplay Display
Definition: qwindowdefs.h:115
The QPlatformGLContext class provides an abstraction for native GL contexts.
iterator insert(const QByteArray &key, const QXcbNativeInterface::ResourceType &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:559
void * graphicsDeviceForWidget(QWidget *widget)
void * screenForWidget(QWidget *widget)
void * displayForWidget(QWidget *widget)
void * eglDisplayForWidget(QWidget *widget)
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
The QMap class is a template class that provides a skip-list-based dictionary.
Definition: qdatastream.h:67
xcb_screen_t * screen() const
Definition: qxcbscreen.h:67