Qt 4.8
eglnullwsscreen.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 "eglnullwsscreen.h"
43 #include "eglnullwswindowsurface.h"
44 #include "eglnullwsscreenplugin.h"
45 
46 #include <QHash>
47 #include <QDebug>
48 
49 namespace
50 {
51  class EGLNullWSScreenSurfaceFunctions : public QGLScreenSurfaceFunctions
52  {
53  public:
54  virtual bool createNativeWindow(QWidget *, EGLNativeWindowType *native)
55  { *native = 0; return true; }
56  };
57 }
58 
59 EGLNullWSScreen::EGLNullWSScreen(int displayId) : QGLScreen(displayId) {}
60 
62 
64 {
65  setSurfaceFunctions(new EGLNullWSScreenSurfaceFunctions);
66  return true;
67 }
68 
70 {
72  dictionary["rgb32"] = QImage::Format_RGB32;
73  dictionary["argb32"] = QImage::Format_ARGB32;
74  dictionary["rgb16"] = QImage::Format_RGB16;
75  dictionary["rgb666"] = QImage::Format_RGB666;
76  dictionary["rgb555"] = QImage::Format_RGB555;
77  dictionary["rgb888"] = QImage::Format_RGB888;
78  dictionary["rgb444"] = QImage::Format_RGB444;
79  return dictionary;
80 }
81 
83 {
84  switch (format) {
85  case QImage::Format_RGB32: return 32;
86  case QImage::Format_ARGB32: return 32;
87  case QImage::Format_RGB16: return 16;
88  case QImage::Format_RGB666: return 24;
89  case QImage::Format_RGB555: return 16;
90  case QImage::Format_RGB888: return 24;
91  case QImage::Format_RGB444: return 16;
92  default:
93  Q_ASSERT_X(false, "EGLNullWSScreen", "Unknown format");
94  return -1;
95  }
96 }
97 
99 {
100  QByteArray formatsBuf;
101  QTextStream(&formatsBuf) << QStringList(formatDictionary.keys()).join(", ");
102  qWarning(
103  "%s: Valid options are:\n"
104  "size=WIDTHxHEIGHT Screen size reported by this driver\n"
105  "format=FORMAT Screen format, where FORMAT is one of the following:\n"
106  " %s\n",
107  PluginName,
108  formatsBuf.constData());
109 }
110 
111 bool EGLNullWSScreen::connect(const QString &displaySpec)
112 {
113  const QStringList args = displaySpec.section(':', 1).split(':', QString::SkipEmptyParts);
115  Q_FOREACH(const QString arg, args) {
116  const QString optionName = arg.section('=', 0, 0);
117  const QString optionArg = arg.section('=', 1);
118  if (optionName == QLatin1String("size")) {
119  w = optionArg.section('x', 0, 0).toInt();
120  h = optionArg.section('x', 1, 1).toInt();
121  } else if (optionName == QLatin1String("format")) {
122  if (formatDict.contains(optionArg))
123  setPixelFormat(formatDict.value(optionArg));
124  else
125  printHelp(formatDict);
126  } else {
127  printHelp(formatDict);
128  }
129  }
130 
131  if (w == 0 || h == 0) {
132  w = 640;
133  h = 480;
134  qWarning("%s: Using default screen size %dx%d", PluginName, w, h);
135  }
136  dw = w;
137  dh = h;
138 
140  qWarning("%s: Using default screen format argb32", PluginName);
142  }
144 
145  static const int Dpi = 120;
146  static const qreal ScalingFactor = static_cast<qreal>(25.4) / Dpi;
147  physWidth = qRound(dw * ScalingFactor);
148  physHeight = qRound(dh * ScalingFactor);
149 
150  return true;
151 }
152 
154 
156 
157 void EGLNullWSScreen::setMode(int /*width*/, int /*height*/, int /*depth*/) {}
158 
159 void EGLNullWSScreen::blank(bool /*on*/) {}
160 
161 void EGLNullWSScreen::exposeRegion(QRegion /*r*/, int /*changing*/) {}
162 
164 {
165  if (qobject_cast<QGLWidget*>(widget)) {
166  return new EGLNullWSWindowSurface(widget);
167  } else {
168  qWarning("%s: Creating non-GL surface", PluginName);
169  return QScreen::createSurface(widget);
170  }
171 }
172 
174 {
175  if (key == QLatin1String("eglnullws")) {
176  return new EGLNullWSWindowSurface;
177  } else {
178  qWarning("%s: Creating non-GL surface", PluginName);
179  return QScreen::createSurface(key);
180  }
181 }
QString section(QChar sep, int start, int end=-1, SectionFlags flags=SectionDefault) const
This function returns a section of the string.
Definition: qstring.h:781
The QWSWindowSurface class provides the drawing area for top-level windows in Qt for Embedded Linux...
Format
The following image formats are available in Qt.
Definition: qimage.h:91
void blank(bool on)
Prevents the screen driver form displaying any content on the screen.
double qreal
Definition: qglobal.h:1193
QPointer< QWidget > widget
void disconnect()
This function is called by every Qt for Embedded Linux application before exiting, and must be implemented to unmap the framebuffer.
bool initDevice()
This function is called by the Qt for Embedded Linux server to initialize the framebuffer.
int d
the pixel depth
Definition: qscreen_qws.h:327
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
void setMode(int width, int height, int depth)
Implement this function to reset the framebuffer&#39;s resolution (width and height) and bit depth...
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
const char *const PluginName
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int physHeight
the physical height of the screen in millimeters.
Definition: qscreen_qws.h:340
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
NativeWindowType EGLNativeWindowType
Definition: qegl_p.h:116
static void printHelp(const QHash< QString, QImage::Format > &formatDictionary)
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
Definition: qhash.h:872
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
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.
QWSWindowSurface * createSurface(QWidget *widget) const
Creates and returns a new window surface for the given widget.
virtual bool createNativeWindow(QWidget *widget, EGLNativeWindowType *native)
Creates a native OpenGLES drawable for the surface of widget and returns it in native.
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
Q_CORE_EXPORT void qWarning(const char *,...)
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
static int depthForFormat(QImage::Format format)
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
void shutdownDevice()
This function is called by the Qt for Embedded Linux server before it calls the disconnect() function...
int dw
the device width
Definition: qscreen_qws.h:331
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
int dh
the device height
Definition: qscreen_qws.h:332
EGLNullWSScreen(int displayId)
QImage::Format pixelFormat() const
Returns the pixel format of the screen, or QImage::Format_Invalid if the pixel format is not a suppor...
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73
int key
The QGLScreenSurfaceFunctions class encapsulates the functions for creating native windows and pixmap...
Definition: qglscreen_qws.h:81
#define Q_FOREACH(variable, container)
Same as foreach(variable, container).
Definition: qglobal.h:2435
void exposeRegion(QRegion r, int changing)
This function is called by the Qt for Embedded Linux server whenever a screen update is required...
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.
int h
the logical height of the screen.
Definition: qscreen_qws.h:326
static const QHash< QString, QImage::Format > formatDictionary()
This class encapsulates an OpenGL screen driver.
Definition: qglscreen_qws.h:89
QList< Key > keys() const
Returns a list containing all the keys in the hash, in an arbitrary order.
Definition: qhash.h:648
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
bool connect(const QString &displaySpec)
This function is called by every Qt for Embedded Linux application on startup, and must be implemente...