1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the plugins of the Qt Toolkit.
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
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.
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.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
42 #include "eglnullwsscreen.h"
43 #include "eglnullwswindowsurface.h"
44 #include "eglnullwsscreenplugin.h"
51 class EGLNullWSScreenSurfaceFunctions : public QGLScreenSurfaceFunctions
54 virtual bool createNativeWindow(QWidget *, EGLNativeWindowType *native)
55 { *native = 0; return true; }
59 EGLNullWSScreen::EGLNullWSScreen(int displayId) : QGLScreen(displayId) {}
61 EGLNullWSScreen::~EGLNullWSScreen() {}
63 bool EGLNullWSScreen::initDevice()
65 setSurfaceFunctions(new EGLNullWSScreenSurfaceFunctions);
69 static const QHash<QString, QImage::Format> formatDictionary()
71 QHash<QString, QImage::Format> dictionary;
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;
82 static int depthForFormat(QImage::Format 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;
93 Q_ASSERT_X(false, "EGLNullWSScreen", "Unknown format");
98 static void printHelp(const QHash<QString, QImage::Format> &formatDictionary)
100 QByteArray formatsBuf;
101 QTextStream(&formatsBuf) << QStringList(formatDictionary.keys()).join(", ");
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"
108 formatsBuf.constData());
111 bool EGLNullWSScreen::connect(const QString &displaySpec)
113 const QStringList args = displaySpec.section(':', 1).split(':', QString::SkipEmptyParts);
114 const QHash<QString, QImage::Format> formatDict = formatDictionary();
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));
125 printHelp(formatDict);
127 printHelp(formatDict);
131 if (w == 0 || h == 0) {
134 qWarning("%s: Using default screen size %dx%d", PluginName, w, h);
139 if (pixelFormat() == QImage::Format_Invalid) {
140 qWarning("%s: Using default screen format argb32", PluginName);
141 setPixelFormat(QImage::Format_ARGB32);
143 d = depthForFormat(pixelFormat());
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);
153 void EGLNullWSScreen::disconnect() {}
155 void EGLNullWSScreen::shutdownDevice() {}
157 void EGLNullWSScreen::setMode(int /*width*/, int /*height*/, int /*depth*/) {}
159 void EGLNullWSScreen::blank(bool /*on*/) {}
161 void EGLNullWSScreen::exposeRegion(QRegion /*r*/, int /*changing*/) {}
163 QWSWindowSurface* EGLNullWSScreen::createSurface(QWidget *widget) const
165 if (qobject_cast<QGLWidget*>(widget)) {
166 return new EGLNullWSWindowSurface(widget);
168 qWarning("%s: Creating non-GL surface", PluginName);
169 return QScreen::createSurface(widget);
173 QWSWindowSurface* EGLNullWSScreen::createSurface(const QString &key) const
175 if (key == QLatin1String("eglnullws")) {
176 return new EGLNullWSWindowSurface;
178 qWarning("%s: Creating non-GL surface", PluginName);
179 return QScreen::createSurface(key);