Qt 4.8
qopenkodeintegration.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 "qopenkodeintegration.h"
43 #include "qopenkodewindow.h"
45 
46 #include <QtOpenGL/private/qpixmapdata_gl_p.h>
47 #include <QtOpenGL/private/qwindowsurface_gl_p.h>
48 
49 #include <QtGui/private/qpixmap_raster_p.h>
50 
51 #include <QtCore/qdebug.h>
52 #include <QtCore/qthread.h>
53 #include <QtCore/qfile.h>
54 
56 
57 #include <KD/kd.h>
58 #include <KD/NV_display.h>
59 #include <KD/NV_initialize.h>
60 
61 #include <EGL/egl.h>
62 
63 #include "GLES2/gl2ext.h"
64 
66 
67 QOpenKODEScreen::QOpenKODEScreen(KDDisplayNV *kdDisplay, KDDesktopNV *kdDesktop)
68  : mIsFullScreen(false)
69 {
70  qDebug() << "QOpenKODEScreen::QOpenKODEIntegrationScreen()";
71 
72  KDboolean enabled = KD_TRUE;
73  kdSetDisplayPropertybvNV(kdDisplay,
74  KD_DISPLAYPROPERTY_ENABLED_NV,
75  &enabled);
76  KDboolean power = KD_DISPLAY_POWER_ON;
77  kdSetDisplayPropertyivNV(kdDisplay,
78  KD_DISPLAYPROPERTY_POWER_NV,
79  &power);
80 
81  kdSetDisplayPropertycvNV(kdDisplay,
82  KD_DISPLAYPROPERTY_DESKTOP_NAME_NV,
83  KD_DEFAULT_DESKTOP_NV);
84 
85  KDDisplayModeNV mode;
86  if (kdGetDisplayModeNV(kdDisplay, &mode)) {
87  qErrnoWarning(kdGetError(), "Could not get display mode");
88  return;
89  }
90 
91  qDebug() << " - display mode " << mode.width << "x" << mode.height << " refresh " << mode.refresh;
92 
93  KDint desktopSize[] = { mode.width, mode.height };
94 
95  if (kdSetDesktopPropertyivNV(kdDesktop, KD_DESKTOPPROPERTY_SIZE_NV, desktopSize)) {
96  qErrnoWarning(kdGetError(), "Could not set desktop size");
97  return;
98  }
99 
100  // Once we've set up the desktop and display we don't need them anymore
101  kdReleaseDisplayNV(kdDisplay);
102  kdReleaseDesktopNV(kdDesktop);
103 
104  mEglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
105  if (mEglDisplay == EGL_NO_DISPLAY) {
106  qErrnoWarning("EGL failed to obtain display");
107  }
108 
109  /* Initialize EGL display */
110  EGLBoolean rvbool = eglInitialize(mEglDisplay, 0, 0);
111  if (!rvbool) {
112  qErrnoWarning("EGL failed to initialize display");
113  }
114 
115 // cursor = new QOpenKODECursor(this);
116 
117  mGeometry = QRect(0, 0, mode.width, mode.height);
118  mDepth = 24;
120 
121 
122 }
123 
125  : mEventLoopIntegration(0)
126  , mFontDb(new QGenericUnixFontDatabase())
127  , mMainGlContext(0)
128 {
129  if (kdInitializeNV() == KD_ENOTINITIALIZED) {
130  qFatal("Did not manage to initialize openkode");
131  }
132 
133  KDDisplaySystemNV *kdDisplaySystem = kdCreateDisplaySystemSnapshotNV(this);
134  KDint32 displayCount = 0;
135  kdGetDisplaySystemPropertyivNV(kdDisplaySystem, KD_DISPLAYPROPERTY_COUNT_NV, 0, &displayCount);
136 
137  for (int i = 0; i < displayCount; i++) {
138  KDchar *displayName = 0;
139  KDsize displayNameLength = 0;
140  kdGetDisplaySystemPropertycvNV(kdDisplaySystem,KD_DISPLAYPROPERTY_NAME_NV,i,0,&displayNameLength);
141  if (!displayNameLength)
142  continue;
143  displayName = new KDchar[displayNameLength];
144  kdGetDisplaySystemPropertycvNV(kdDisplaySystem,KD_DISPLAYPROPERTY_NAME_NV,i,displayName,&displayNameLength);
145 
146  KDDisplayNV *display = kdGetDisplayNV(displayName,this);
147  if (!display || display == (void*)-1) {
148  qErrnoWarning(kdGetError(), "Could not obtain KDDisplayNV pointer");
149  return;
150  }
151  if (displayNameLength)
152  delete displayName;
153 
154  KDchar *desktopName = 0;
155  KDsize desktopNameLength = 0;
156  bool openkodeImpDoesNotFail = false;
157  if (openkodeImpDoesNotFail) {
158  qDebug() << "printing desktopname";
159  kdGetDisplayPropertycvNV(display,KD_DISPLAYPROPERTY_DESKTOP_NAME_NV,desktopName,&desktopNameLength);
160  if (desktopNameLength) {
161  desktopName = new KDchar[desktopNameLength];
162  kdGetDisplayPropertycvNV(display,KD_DISPLAYPROPERTY_DESKTOP_NAME_NV,desktopName,&desktopNameLength);
163  } else {
164  desktopName = KD_DEFAULT_DESKTOP_NV;
165  }
166  } else {
167  desktopName = KD_DEFAULT_DESKTOP_NV;
168  }
169 
170  KDDesktopNV *desktop = kdGetDesktopNV(desktopName,this);
171  if (!desktop || desktop == (void*)-1) {
172  qErrnoWarning(kdGetError(), "Could not obtain KDDesktopNV pointer");
173  kdReleaseDisplayNV(display);
174  return;
175  }
176  if (desktopNameLength)
177  delete desktopName;
178 
179  QOpenKODEScreen *screen = new QOpenKODEScreen(display,desktop);
180  mScreens.append(screen);
181  }
182 }
183 
185 {
186  delete mEventLoopIntegration;
187  delete mFontDb;
188 }
189 
190 
192 {
193  switch (cap) {
194  case ThreadedPixmaps: return true;
195  case OpenGL: return true;
196  default: return QPlatformIntegration::hasCapability(cap);
197  }
198 }
199 
201 {
202  return new QGLPixmapData(type);
203 }
204 
206 {
207  return new QOpenKODEWindow(tlw);
208 }
209 
211 {
212  QWindowSurface *returnSurface = 0;
213  switch (widget->platformWindowFormat().windowApi()) {
214 
217  returnSurface = new QGLWindowSurface(widget);
218  break;
219 
221 // returnSurface = new QVGWindowSurface(widget);
222 // break;
223 
224  default:
225  returnSurface = new QGLWindowSurface(widget);
226  break;
227  }
228 
229  return returnSurface;
230 }
231 
233 {
234  if (!mEventLoopIntegration) {
235  QOpenKODEIntegration *that = const_cast<QOpenKODEIntegration *>(this);
237  }
238  return mEventLoopIntegration;
239 }
240 
242 {
243  return mFontDb;
244 }
245 
246 
unsigned long WId
Definition: qwindowdefs.h:119
int type
Definition: qmetatype.cpp:239
QPlatformWindow * createPlatformWindow(QWidget *widget, WId winId=0) const
Factory function for QPlatformWindow.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QImage::Format mFormat
QPointer< QWidget > widget
virtual bool hasCapability(Capability cap) const
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QOpenKODEScreen(KDDisplayNV *kdDisplay, KDDesktopNV *kdDesktop)
The QPlatformWindow class provides an abstraction for top-level windows.
QPixmapData * createPixmapData(QPixmapData::PixelType type) const
Factory function for QPixmapData.
Q_CORE_EXPORT void qDebug(const char *,...)
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
Q_GUI_EXPORT EGLDisplay display()
Definition: qegl.cpp:589
QOpenKODEEventLoopIntegration * mEventLoopIntegration
QList< QPlatformScreen * > mScreens
bool hasCapability(QPlatformIntegration::Capability cap) const
The QWindowSurface class provides the drawing area for top-level windows.
Q_CORE_EXPORT void qFatal(const char *,...)
QPlatformFontDatabase * fontDatabase() const
Accessor for the platform integrations fontdatabase.
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QPlatformEventLoopIntegration * createEventLoopIntegration() const
Factory function for the eventloop integration interface.
The QPlatformFontDatabase class makes it possible to customize how fonts are discovered and how they ...
QWindowSurface * createWindowSurface(QWidget *widget, WId winId) const
Factory function for QWindowSurface.
QPlatformFontDatabase * mFontDb
#define enabled
void qErrnoWarning(const char *msg,...)
Definition: qglobal.cpp:2954