Qt 4.8
pvreglscreen.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 "pvreglscreen.h"
43 #include "pvreglwindowsurface.h"
44 #include "pvrqwsdrawable_p.h"
45 #include <QRegExp>
46 #include <qwindowsystem_qws.h>
47 #ifndef QT_NO_QWS_TRANSFORMED
48 #include <qscreentransformed_qws.h>
49 #endif
50 #include <sys/stat.h>
51 #include <sys/ioctl.h>
52 #include <sys/kd.h>
53 #include <fcntl.h>
54 #include <unistd.h>
55 
58  : QGLScreen(displayId)
59 {
61  setSupportsBlitInClients(true);
64  fd = -1;
65  ttyfd = -1;
66  doGraphicsMode = true;
67  oldKdMode = KD_TEXT;
68  parent = 0;
69 
70  // Make sure that the EGL layer is initialized and the drivers loaded.
71  EGLDisplay dpy = eglGetDisplay((EGLNativeDisplayType)EGL_DEFAULT_DISPLAY);
72  if (!eglInitialize(dpy, 0, 0))
73  qWarning("Could not initialize EGL display - are the drivers loaded?");
74 
75  // Make sure that screen 0 is initialized.
77 }
78 
80 {
81  if (fd >= 0)
82  ::close(fd);
83 }
84 
86 {
87  openTty();
88  return true;
89 }
90 
91 bool PvrEglScreen::connect(const QString &displaySpec)
92 {
93  if (!pvrQwsDisplayOpen())
94  return false;
95 
96  // Initialize the QScreen properties.
101  dw = w;
102  dh = h;
103  size = h * lstep;
104  mapsize = size;
105  switch (pvrQwsDisplay.screens[0].pixelFormat) {
106  case PVR2D_RGB565:
107  d = 16;
109  break;
110  case PVR2D_ARGB4444:
111  d = 16;
113  break;
114  case PVR2D_ARGB8888:
115  d = 32;
117  break;
118  default:
120  qWarning("PvrEglScreen::connect: unsupported pixel format %d", (int)(pvrQwsDisplay.screens[0].pixelFormat));
121  return false;
122  }
123 
124  // Handle display physical size spec.
125  QStringList displayArgs = displaySpec.split(QLatin1Char(':'));
126  QRegExp mmWidthRx(QLatin1String("mmWidth=?(\\d+)"));
127  int dimIdxW = displayArgs.indexOf(mmWidthRx);
128  QRegExp mmHeightRx(QLatin1String("mmHeight=?(\\d+)"));
129  int dimIdxH = displayArgs.indexOf(mmHeightRx);
130  if (dimIdxW >= 0) {
131  mmWidthRx.exactMatch(displayArgs.at(dimIdxW));
132  physWidth = mmWidthRx.cap(1).toInt();
133  if (dimIdxH < 0)
135  }
136  if (dimIdxH >= 0) {
137  mmHeightRx.exactMatch(displayArgs.at(dimIdxH));
138  physHeight = mmHeightRx.cap(1).toInt();
139  if (dimIdxW < 0)
141  }
142  if (dimIdxW < 0 && dimIdxH < 0) {
143  const int dpi = 72;
144  physWidth = qRound(dw * 25.4 / dpi);
145  physHeight = qRound(dh * 25.4 / dpi);
146  }
147 
148  // Find the name of the tty device to use.
149  QRegExp ttyRegExp(QLatin1String("tty=(.*)"));
150  if (displayArgs.indexOf(ttyRegExp) != -1)
151  ttyDevice = ttyRegExp.cap(1);
152  if (displayArgs.contains(QLatin1String("nographicsmodeswitch")))
153  doGraphicsMode = false;
154 
155  // The screen is ready.
156  return true;
157 }
158 
160 {
162 }
163 
165 {
166  closeTty();
167 }
168 
169 void PvrEglScreen::blit(const QImage &img, const QPoint &topLeft, const QRegion &region)
170 {
171  QGLScreen::blit(img, topLeft, region);
172  sync();
173 }
174 
175 void PvrEglScreen::solidFill(const QColor &color, const QRegion &region)
176 {
177  QGLScreen::solidFill(color, region);
178  sync();
179 }
180 
182  (QGLContext *context, const QGLContext *shareContext)
183 {
184  // We use PvrEglScreenSurfaceFunctions instead.
185  Q_UNUSED(context);
186  Q_UNUSED(shareContext);
187  return false;
188 }
189 
191 {
192  return true;
193 }
194 
197 {
198  if (qobject_cast<QGLWidget*>(widget))
199  return new PvrEglWindowSurface(widget, (PvrEglScreen *)this, displayId);
200 
201  return QScreen::createSurface(widget);
202 }
203 
205 {
206  if (key == QLatin1String("PvrEgl"))
207  return new PvrEglWindowSurface();
208 
209  return QScreen::createSurface(key);
210 }
212 
213 #ifndef QT_NO_QWS_TRANSFORMED
214 
215 static const QScreen *parentScreen
216  (const QScreen *current, const QScreen *lookingFor)
217 {
218  if (!current)
219  return 0;
220  switch (current->classId()) {
221  case QScreen::ProxyClass:
223  const QScreen *child =
224  static_cast<const QProxyScreen *>(current)->screen();
225  if (child == lookingFor)
226  return current;
227  else
228  return parentScreen(child, lookingFor);
229  }
230  // Not reached.
231 
232  case QScreen::MultiClass: {
233  QList<QScreen *> screens = current->subScreens();
234  foreach (QScreen *screen, screens) {
235  if (screen == lookingFor)
236  return current;
237  const QScreen *parent = parentScreen(screen, lookingFor);
238  if (parent)
239  return parent;
240  }
241  }
242  break;
243 
244  default: break;
245  }
246  return 0;
247 }
248 
250 {
251  // We need to search for our parent screen, which is assumed to be
252  // "Transformed". If it isn't, then there is no transformation.
253  // There is no direct method to get the parent screen so we need
254  // to search every screen until we find ourselves.
255  if (!parent && qt_screen != this)
256  parent = parentScreen(qt_screen, this);
257  if (!parent)
258  return 0;
260  return 0;
261  return 90 * static_cast<const QTransformedScreen *>(parent)
263 }
264 
265 #else
266 
268 {
269  return 0;
270 }
271 
272 #endif
273 
275 {
276  // Put code here to synchronize 2D and 3D operations if necessary.
277 }
278 
280 {
281  const char *const devs[] = {"/dev/tty0", "/dev/tty", "/dev/console", 0};
282 
283  if (ttyDevice.isEmpty()) {
284  for (const char * const *dev = devs; *dev; ++dev) {
285  ttyfd = ::open(*dev, O_RDWR);
286  if (ttyfd != -1)
287  break;
288  }
289  } else {
291  }
292 
293  if (ttyfd == -1)
294  return;
295 
296  ::fcntl(ttyfd, F_SETFD, FD_CLOEXEC);
297 
298  if (doGraphicsMode) {
299  ioctl(ttyfd, KDGETMODE, &oldKdMode);
300  if (oldKdMode != KD_GRAPHICS) {
301  int ret = ioctl(ttyfd, KDSETMODE, KD_GRAPHICS);
302  if (ret == -1)
303  doGraphicsMode = false;
304  }
305  }
306 
307  // No blankin' screen, no blinkin' cursor!, no cursor!
308  const char termctl[] = "\033[9;0]\033[?33l\033[?25l\033[?1c";
309  ::write(ttyfd, termctl, sizeof(termctl));
310 }
311 
313 {
314  if (ttyfd == -1)
315  return;
316 
317  if (doGraphicsMode)
318  ioctl(ttyfd, KDSETMODE, oldKdMode);
319 
320  // Blankin' screen, blinkin' cursor!
321  const char termctl[] = "\033[9;15]\033[?33h\033[?25h\033[?0c";
322  ::write(ttyfd, termctl, sizeof(termctl));
323 
324  ::close(ttyfd);
325  ttyfd = -1;
326 }
327 
330 {
332  QWSWindowSurface *surface =
333  static_cast<QWSWindowSurface *>(widget->windowSurface());
334  if (!surface) {
335  // The widget does not have a surface yet, so give it one.
336  surface = new PvrEglWindowSurface(widget, screen, displayId);
337  widget->setWindowSurface(surface);
338  } else if (surface->key() != QLatin1String("PvrEgl")) {
339  // The application has attached a QGLContext to an ordinary QWidget.
340  // Replace the widget's window surface with a new one that can do GL.
341  QRect geometry = widget->frameGeometry();
342  geometry.moveTo(widget->mapToGlobal(QPoint(0, 0)));
343  surface = new PvrEglWindowSurface(widget, screen, displayId);
344  surface->setGeometry(geometry);
345  widget->setWindowSurface(surface);
347  }
348  PvrEglWindowSurface *nsurface = static_cast<PvrEglWindowSurface*>(surface);
349  *native = (EGLNativeWindowType)(nsurface->nativeDrawable());
350  return true;
351 }
Q_GUI_EXPORT QScreen * qt_screen
Definition: qscreen_qws.cpp:69
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
void setWindowSurface(QWindowSurface *surface)
Sets the window surface to be the surface specified.
Definition: qwidget.cpp:12774
The QWSWindowSurface class provides the drawing area for top-level windows in Qt for Embedded Linux...
The QProxyScreen class provides a generic interface to QScreen implementations.
void solidFill(const QColor &color, const QRegion &region)
Fills the given region of the screen with the specified color.
QString cap(int nth=0) const
Returns the text captured by the nth subexpression.
Definition: qregexp.cpp:4310
QPointer< QWidget > widget
bool doGraphicsMode
Definition: pvreglscreen.h:95
int d
the pixel depth
Definition: qscreen_qws.h:327
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
int toInt(bool *ok=0, int base=10) const
Returns the string converted to an int using base base, which is 10 by default and must be between 2 ...
Definition: qstring.cpp:6090
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
void blit(const QImage &img, const QPoint &topLeft, const QRegion &region)
Copies the given region in the given image to the point specified by topLeft using device coordinates...
QRect frameGeometry
geometry of the widget relative to its parent including any window frame
Definition: qwidget.h:159
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
PvrQwsDisplay pvrQwsDisplay
bool connect(const QString &displaySpec)
This function is called by every Qt for Embedded Linux application on startup, and must be implemente...
PvrQwsRect screenRect
void moveTo(int x, int t)
Moves the rectangle, leaving the top-left corner at the given position (x, y).
Definition: qrect.h:334
int physHeight
the physical height of the screen in millimeters.
Definition: qscreen_qws.h:340
const QScreen * parent
Definition: pvreglscreen.h:96
The QString class provides a Unicode character string.
Definition: qstring.h:83
int size
the number of bytes in the visible region of the frame buffer
Definition: qscreen_qws.h:334
bool initDevice()
This function is called by the Qt for Embedded Linux server to initialize the framebuffer.
int pvrQwsDisplayOpen(void)
NativeWindowType EGLNativeWindowType
Definition: qegl_p.h:116
PvrEglScreen(int displayId)
[0]
int physWidth
the physical width of the screen in millimeters.
Definition: qscreen_qws.h:339
void setPixelFormat(QImage::Format format)
Sets the screen&#39;s pixel format to format.
void setOptions(QGLScreen::Options value)
Sets the options associated with this QGLScreen to value.
virtual void blit(const QImage &img, const QPoint &topLeft, const QRegion &region)
Copies the given region in the given image to the point specified by topLeft using device coordinates...
QWSWindowSurface * createSurface(QWidget *widget) const
[1]
virtual QRegion region() const
Returns the region covered by this screen driver.
Definition: qscreen_qws.h:284
unsigned char uchar
Definition: qglobal.h:994
uchar * data
points to the first visible pixel in the frame buffer.
Definition: qscreen_qws.h:311
int transformation() const
int indexOf(const QRegExp &rx, int from=0) const
Returns the index position of the first exact match of rx in the list, searching forward from index p...
Definition: qstringlist.h:195
QString ttyDevice
Definition: pvreglscreen.h:94
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
int w
the logical width of the screen.
Definition: qscreen_qws.h:324
void disconnect()
This function is called by every Qt for Embedded Linux application before exiting, and must be implemented to unmap the framebuffer.
Q_CORE_EXPORT void qWarning(const char *,...)
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QWindowSurface * windowSurface() const
Returns the QWindowSurface this widget will be drawn into.
Definition: qwidget.cpp:12819
QBool contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the list contains the string str; otherwise returns false.
Definition: qstringlist.h:172
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
int displayId
Definition: qscreen_qws.h:337
bool createNativeWindow(QWidget *widget, EGLNativeWindowType *native)
[2]
static const QScreen * parentScreen(const QScreen *current, const QScreen *lookingFor)
[1]
virtual QWSWindowSurface * createSurface(QWidget *widget) const
Creates and returns a new window surface for the given widget.
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
int dw
the device width
Definition: qscreen_qws.h:331
int fcntl(int, int,...)
int dh
the device height
Definition: qscreen_qws.h:332
virtual QString key() const =0
Implement this function to return a string that uniquely identifies the class of this surface...
void shutdownDevice()
This function is called by the Qt for Embedded Linux server before it calls the disconnect() function...
virtual QList< QScreen * > subScreens() const
Definition: qscreen_qws.h:283
int key
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
QByteArray toAscii() const Q_REQUIRED_RESULT
Returns an 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4014
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
The QScreen class is a base class for screen drivers in Qt for Embedded Linux.
Definition: qscreen_qws.h:191
PVR2DFORMAT pixelFormat
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
Definition: qwidget.cpp:11087
virtual int transformOrientation() const
Returns the current rotation as an integer value.
bool exactMatch(const QString &str) const
Returns true if str is matched exactly by this regular expression; otherwise returns false...
Definition: qregexp.cpp:4094
int lstep
the number of bytes representing a line in the frame buffer.
Definition: qscreen_qws.h:325
NativeDisplayType EGLNativeDisplayType
Definition: qegl_p.h:118
ClassId classId() const
Returns the class identifier for the screen object.
PvrQwsDrawable * pvrQwsScreenWindow(int screen)
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
Definition: qstring.cpp:6526
void setSurfaceFunctions(QGLScreenSurfaceFunctions *functions)
Sets the surface functions object for this QGLScreen to functions.
PvrQwsScreenInfo screens[PVRQWS_MAX_SCREENS]
int h
the logical height of the screen.
Definition: qscreen_qws.h:326
int mapsize
the total number of bytes in the frame buffer
Definition: qscreen_qws.h:335
This class encapsulates an OpenGL screen driver.
Definition: qglscreen_qws.h:89
#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
#define O_RDWR
QPoint mapToGlobal(const QPoint &) const
Translates the widget coordinate pos to global screen coordinates.
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
virtual void solidFill(const QColor &color, const QRegion &region)
Fills the given region of the screen with the specified color.
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
bool chooseContext(QGLContext *context, const QGLContext *shareContext)
Initializes the context and sets up the QGLWindowSurface of the QWidget of context based on the param...
virtual void setGeometry(const QRect &rect)
Sets the currently allocated area to be the given rect.
int open(const char *, int,...)
void pvrQwsDisplayClose(void)
The QTransformedScreen class implements a screen driver for a transformed screen. ...
The QList class is a template class that provides lists.
Definition: qdatastream.h:62