1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the QtGui module 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 The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/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 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file. Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QT_NO_QWS_INTEGRITYFB
43
44 #include <qscreenintegrityfb_qws.h>
45 #include <qwindowsystem_qws.h>
46 #include <qsocketnotifier.h>
47 #include <qapplication.h>
48 #include <qscreen_qws.h>
49 #include "qmouseintegrity_qws.h"
50 #include "qkbdintegrity_qws.h"
51 #include <qmousedriverfactory_qws.h>
52 #include <qkbddriverfactory_qws.h>
53 #include <qdebug.h>
54
55 #include <INTEGRITY.h>
56 #include <device/fbdriver.h>
57
58 QT_BEGIN_NAMESPACE
59
60 class QIntfbScreenPrivate
61 {
62 public:
63 QIntfbScreenPrivate();
64 ~QIntfbScreenPrivate();
65
66 FBHandle handle;
67 FBInfo fbinfo;
68 FBDriver *fbdrv;
69
70 QWSMouseHandler *mouse;
71 #ifndef QT_NO_QWS_KEYBOARD
72 QWSKeyboardHandler *keyboard;
73 #endif
74 };
75
QIntfbScreenPrivate()76 QIntfbScreenPrivate::QIntfbScreenPrivate()
77 : mouse(0)
78
79 {
80 #ifndef QT_NO_QWS_KEYBOARD
81 keyboard = 0;
82 #endif
83 }
84
~QIntfbScreenPrivate()85 QIntfbScreenPrivate::~QIntfbScreenPrivate()
86 {
87 delete mouse;
88 #ifndef QT_NO_QWS_KEYBOARD
89 delete keyboard;
90 #endif
91 }
92
93 /*!
94 \internal
95
96 \class QIntfbScreen
97 \ingroup qws
98
99 \brief The QIntfbScreen class implements a screen driver for the
100 INTEGRITY framebuffer drivers.
101
102 Note that this class is only available in \l{Qt for INTEGRITY}.
103 Custom screen drivers can be added by subclassing the
104 QScreenDriverPlugin class, using the QScreenDriverFactory class to
105 dynamically load the driver into the application, but there should
106 only be one screen object per application.
107
108 \sa QScreen, QScreenDriverPlugin, {Running Applications}
109 */
110
111 /*!
112 \fn bool QIntfbScreen::connect(const QString & displaySpec)
113 \reimp
114 */
115
116 /*!
117 \fn void QIntfbScreen::disconnect()
118 \reimp
119 */
120
121 /*!
122 \fn bool QIntfbScreen::initDevice()
123 \reimp
124 */
125
126 /*!
127 \fn void QIntfbScreen::restore()
128 \reimp
129 */
130
131 /*!
132 \fn void QIntfbScreen::save()
133 \reimp
134 */
135
136 /*!
137 \fn void QIntfbScreen::setDirty(const QRect & r)
138 \reimp
139 */
140
141 /*!
142 \fn void QIntfbScreen::setMode(int nw, int nh, int nd)
143 \reimp
144 */
145
146 /*!
147 \fn void QIntfbScreen::shutdownDevice()
148 \reimp
149 */
150
151 /*!
152 \fn QIntfbScreen::QIntfbScreen(int displayId)
153
154 Constructs a QVNCScreen object. The \a displayId argument
155 identifies the Qt for Embedded Linux server to connect to.
156 */
QIntfbScreen(int display_id)157 QIntfbScreen::QIntfbScreen(int display_id)
158 : QScreen(display_id, IntfbClass), d_ptr(new QIntfbScreenPrivate)
159 {
160 d_ptr->handle = 0;
161 data = 0;
162 }
163
164 /*!
165 Destroys this QIntfbScreen object.
166 */
~QIntfbScreen()167 QIntfbScreen::~QIntfbScreen()
168 {
169 delete d_ptr;
170 }
171
172 static QIntfbScreen *connected = 0;
173
connect(const QString & displaySpec)174 bool QIntfbScreen::connect(const QString &displaySpec)
175 {
176 CheckSuccess(gh_FB_get_driver(0, &d_ptr->fbdrv));
177 CheckSuccess(gh_FB_check_info(d_ptr->fbdrv, &d_ptr->fbinfo));
178 CheckSuccess(gh_FB_open(d_ptr->fbdrv, &d_ptr->fbinfo, &d_ptr->handle));
179 CheckSuccess(gh_FB_get_info(d_ptr->handle, &d_ptr->fbinfo));
180
181 data = (uchar *)d_ptr->fbinfo.Start;
182
183 d = d_ptr->fbinfo.BitsPerPixel;
184 switch (d) {
185 case 1:
186 setPixelFormat(QImage::Format_Mono);
187 break;
188 case 8:
189 setPixelFormat(QImage::Format_Indexed8);
190 break;
191 case 12:
192 setPixelFormat(QImage::Format_RGB444);
193 break;
194 case 15:
195 setPixelFormat(QImage::Format_RGB555);
196 break;
197 case 16:
198 setPixelFormat(QImage::Format_RGB16);
199 break;
200 case 18:
201 setPixelFormat(QImage::Format_RGB666);
202 break;
203 case 24:
204 setPixelFormat(QImage::Format_RGB888);
205 #ifdef QT_QWS_DEPTH_GENERIC
206 #if Q_BYTE_ORDER != Q_BIG_ENDIAN
207 qt_set_generic_blit(this, 24,
208 d_ptr->fbinfo.Red.Bits,
209 d_ptr->fbinfo.Green.Bits,
210 d_ptr->fbinfo.Blue.Bits,
211 d_ptr->fbinfo.Alpha.Bits,
212 d_ptr->fbinfo.Red.Offset,
213 d_ptr->fbinfo.Green.Offset,
214 d_ptr->fbinfo.Blue.Offset,
215 d_ptr->fbinfo.Alpha.Offset);
216 #else
217 qt_set_generic_blit(this, 24,
218 d_ptr->fbinfo.Red.Bits,
219 d_ptr->fbinfo.Green.Bits,
220 d_ptr->fbinfo.Blue.Bits,
221 d_ptr->fbinfo.Alpha.Bits,
222 16 - d_ptr->fbinfo.Red.Offset,
223 16 - d_ptr->fbinfo.Green.Offset,
224 16 - d_ptr->fbinfo.Blue.Offset,
225 16 - d_ptr->fbinfo.Alpha.Offset);
226 #endif
227 #endif
228 break;
229 case 32:
230 setPixelFormat(QImage::Format_ARGB32_Premultiplied);
231 #ifdef QT_QWS_DEPTH_GENERIC
232 #if Q_BYTE_ORDER != Q_BIG_ENDIAN
233 qt_set_generic_blit(this, 32,
234 d_ptr->fbinfo.Red.Bits,
235 d_ptr->fbinfo.Green.Bits,
236 d_ptr->fbinfo.Blue.Bits,
237 d_ptr->fbinfo.Alpha.Bits,
238 d_ptr->fbinfo.Red.Offset,
239 d_ptr->fbinfo.Green.Offset,
240 d_ptr->fbinfo.Blue.Offset,
241 d_ptr->fbinfo.Alpha.Offset);
242 #else
243 qt_set_generic_blit(this, 32,
244 d_ptr->fbinfo.Red.Bits,
245 d_ptr->fbinfo.Green.Bits,
246 d_ptr->fbinfo.Blue.Bits,
247 d_ptr->fbinfo.Alpha.Bits,
248 24 - d_ptr->fbinfo.Red.Offset,
249 24 - d_ptr->fbinfo.Green.Offset,
250 24 - d_ptr->fbinfo.Blue.Offset,
251 24 - d_ptr->fbinfo.Alpha.Offset);
252 #endif
253 #endif
254 break;
255 }
256
257 dw = w = d_ptr->fbinfo.Width;
258 dh = h = d_ptr->fbinfo.Height;
259
260 /* assumes no padding */
261 lstep = w * ((d + 7) >> 3);
262
263 mapsize = size = h * lstep;
264
265 /* default values */
266 int dpi = 72;
267 physWidth = qRound(dw * 25.4 / dpi);
268 physHeight = qRound(dh * 25.4 / dpi);
269
270 qDebug("Connected to INTEGRITYfb server: %d x %d x %d %dx%dmm (%dx%ddpi)",
271 w, h, d, physWidth, physHeight, qRound(dw*25.4/physWidth), qRound(dh*25.4/physHeight) );
272
273
274 QWSServer::setDefaultMouse("integrity");
275 QWSServer::setDefaultKeyboard("integrity");
276
277 connected = this;
278
279 return true;
280 }
281
disconnect()282 void QIntfbScreen::disconnect()
283 {
284 connected = 0;
285 }
286
initDevice()287 bool QIntfbScreen::initDevice()
288 {
289 #ifndef QT_NO_QWS_CURSOR
290 QScreenCursor::initSoftwareCursor();
291 #endif
292 return true;
293 }
294
shutdownDevice()295 void QIntfbScreen::shutdownDevice()
296 {
297 gh_FB_close(d_ptr->handle);
298 }
299
setMode(int,int,int)300 void QIntfbScreen::setMode(int ,int ,int)
301 {
302 }
303
304 // save the state of the graphics card
305 // This is needed so that e.g. we can restore the palette when switching
306 // between linux virtual consoles.
save()307 void QIntfbScreen::save()
308 {
309 // nothing to do.
310 }
311
312 // restore the state of the graphics card.
restore()313 void QIntfbScreen::restore()
314 {
315 }
setDirty(const QRect & rect)316 void QIntfbScreen::setDirty(const QRect& rect)
317 {
318 FBRect fbrect;
319 fbrect.dx = rect.x();
320 fbrect.dy = rect.y();
321 fbrect.Width = rect.width();
322 fbrect.Height = rect.height();
323 gh_FB_expose(d_ptr->handle, &fbrect, 0);
324 }
325
setBrightness(int b)326 void QIntfbScreen::setBrightness(int b)
327 {
328 if (connected) {
329 }
330 }
331
blank(bool on)332 void QIntfbScreen::blank(bool on)
333 {
334 }
335
336 #endif // QT_NO_QWS_INTEGRITYFB
337
338 QT_END_NAMESPACE
339
340