1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
|
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qscreentransformed_qws.h"
#ifndef QT_NO_QWS_TRANSFORMED
#include <qscreendriverfactory_qws.h>
#include <qvector.h>
#include <private/qpainter_p.h>
#include <private/qmemrotate_p.h>
#include <qmatrix.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <errno.h>
#include <qwindowsystem_qws.h>
#include <qwsdisplay_qws.h>
QT_BEGIN_NAMESPACE
//#define QT_REGION_DEBUG
#ifdef QT_REGION_DEBUG
#include <QDebug>
#endif
class QTransformedScreenPrivate
{
public:
QTransformedScreenPrivate(QTransformedScreen *parent);
void configure();
QTransformedScreen::Transformation transformation;
#ifdef QT_QWS_DEPTH_GENERIC
bool doGenericColors;
#endif
QTransformedScreen *q;
};
QTransformedScreenPrivate::QTransformedScreenPrivate(QTransformedScreen *parent)
: transformation(QTransformedScreen::None),
#ifdef QT_QWS_DEPTH_GENERIC
doGenericColors(false),
#endif
q(parent)
{
}
extern "C"
#ifndef QT_BUILD_GUI_LIB
Q_DECL_EXPORT
#endif
void qws_setScreenTransformation(QScreen *that, int t)
{
QTransformedScreen *tscreen = static_cast<QTransformedScreen*>(that);
tscreen->setTransformation((QTransformedScreen::Transformation)t);
}
// ---------------------------------------------------------------------------
// Transformed Screen
// ---------------------------------------------------------------------------
/*!
\internal
\class QTransformedScreen
\ingroup qws
\brief The QTransformedScreen class implements a screen driver for
a transformed screen.
Note that this class is only available in \l{Qt for Embedded Linux}.
Custom screen drivers can be added by subclassing the
QScreenDriverPlugin class, using the QScreenDriverFactory class to
dynamically load the driver into the application, but there should
only be one screen object per application.
Use the QScreen::isTransformed() function to determine if a screen
is transformed. The QTransformedScreen class itself provides means
of rotating the screen with its setTransformation() function; the
transformation() function returns the currently set rotation in
terms of the \l Transformation enum (which describes the various
available rotation settings). Alternatively, QTransformedScreen
provides an implementation of the QScreen::transformOrientation()
function, returning the current rotation as an integer value.
\sa QScreen, QScreenDriverPlugin, {Running Applications}
*/
/*!
\enum QTransformedScreen::Transformation
This enum describes the various rotations a transformed screen can
have.
\value None No rotation
\value Rot90 90 degrees rotation
\value Rot180 180 degrees rotation
\value Rot270 270 degrees rotation
*/
/*!
\fn bool QTransformedScreen::isTransformed() const
\reimp
*/
/*!
Constructs a QTransformedScreen object. The \a displayId argument
identifies the Qt for Embedded Linux server to connect to.
*/
QTransformedScreen::QTransformedScreen(int displayId)
: QProxyScreen(displayId, QScreen::TransformedClass)
{
d_ptr = new QTransformedScreenPrivate(this);
d_ptr->transformation = None;
#ifdef QT_REGION_DEBUG
qDebug() << "QTransformedScreen::QTransformedScreen";
#endif
}
void QTransformedScreenPrivate::configure()
{
// ###: works because setTransformation recalculates unconditionally
q->setTransformation(transformation);
}
/*!
Destroys the QTransformedScreen object.
*/
QTransformedScreen::~QTransformedScreen()
{
delete d_ptr;
}
static int getDisplayId(const QString &spec)
{
QRegExp regexp(QLatin1String(":(\\d+)\\b"));
if (regexp.lastIndexIn(spec) != -1) {
const QString capture = regexp.cap(1);
return capture.toInt();
}
return 0;
}
static QTransformedScreen::Transformation filterTransformation(QString &spec)
{
QRegExp regexp(QLatin1String("\\bRot(\\d+):?\\b"), Qt::CaseInsensitive);
if (regexp.indexIn(spec) == -1)
return QTransformedScreen::None;
const int degrees = regexp.cap(1).toInt();
spec.remove(regexp.pos(0), regexp.matchedLength());
return static_cast<QTransformedScreen::Transformation>(degrees / 90);
}
/*!
\reimp
*/
bool QTransformedScreen::connect(const QString &displaySpec)
{
QString dspec = displaySpec.trimmed();
if (dspec.startsWith(QLatin1String("Transformed:"), Qt::CaseInsensitive))
dspec = dspec.mid(QString::fromLatin1("Transformed:").size());
else if (!dspec.compare(QLatin1String("Transformed"), Qt::CaseInsensitive))
dspec = QString();
const QString displayIdSpec = QString::fromLatin1(" :%1").arg(displayId);
if (dspec.endsWith(displayIdSpec))
dspec = dspec.left(dspec.size() - displayIdSpec.size());
d_ptr->transformation = filterTransformation(dspec);
QString driver = dspec;
int colon = driver.indexOf(QLatin1Char(':'));
if (colon >= 0)
driver.truncate(colon);
if (!QScreenDriverFactory::keys().contains(driver, Qt::CaseInsensitive))
if (!dspec.isEmpty())
dspec.prepend(QLatin1Char(':'));
const int id = getDisplayId(dspec);
QScreen *s = qt_get_screen(id, dspec.toLatin1().constData());
setScreen(s);
#ifdef QT_QWS_DEPTH_GENERIC
d_ptr->doGenericColors = dspec.contains(QLatin1String("genericcolors"));
#endif
d_ptr->configure();
// XXX
qt_screen = this;
return true;
}
/*!
Returns the currently set rotation.
\sa setTransformation(), QScreen::transformOrientation()
*/
QTransformedScreen::Transformation QTransformedScreen::transformation() const
{
return d_ptr->transformation;
}
/*!
\reimp
*/
int QTransformedScreen::transformOrientation() const
{
return (int)d_ptr->transformation;
}
/*!
\reimp
*/
void QTransformedScreen::exposeRegion(QRegion region, int changing)
{
if (!data || d_ptr->transformation == None) {
QProxyScreen::exposeRegion(region, changing);
return;
}
QScreen::exposeRegion(region, changing);
}
/*!
Rotates this screen object according to the specified \a transformation.
\sa transformation()
*/
void QTransformedScreen::setTransformation(Transformation transformation)
{
d_ptr->transformation = transformation;
QSize size = mapFromDevice(QSize(dw, dh));
w = size.width();
h = size.height();
const QScreen *s = screen();
size = mapFromDevice(QSize(s->physicalWidth(), s->physicalHeight()));
physWidth = size.width();
physHeight = size.height();
#ifdef QT_REGION_DEBUG
qDebug() << "QTransformedScreen::setTransformation" << transformation
<< "size" << w << h << "dev size" << dw << dh;
#endif
}
static inline QRect correctNormalized(const QRect &r) {
const int x1 = qMin(r.left(), r.right());
const int x2 = qMax(r.left(), r.right());
const int y1 = qMin(r.top(), r.bottom());
const int y2 = qMax(r.top(), r.bottom());
return QRect( QPoint(x1,y1), QPoint(x2,y2) );
}
template <class DST, class SRC>
static inline void blit90(QScreen *screen, const QImage &image,
const QRect &rect, const QPoint &topLeft)
{
const SRC *src = (const SRC*)(image.scanLine(rect.top())) + rect.left();
DST *dest = (DST*)(screen->base() + topLeft.y() * screen->linestep())
+ topLeft.x();
qt_memrotate90(src, rect.width(), rect.height(), image.bytesPerLine(),
dest, screen->linestep());
}
template <class DST, class SRC>
static inline void blit180(QScreen *screen, const QImage &image,
const QRect &rect, const QPoint &topLeft)
{
const SRC *src = (const SRC*)(image.scanLine(rect.top())) + rect.left();
DST *dest = (DST*)(screen->base() + topLeft.y() * screen->linestep())
+ topLeft.x();
qt_memrotate180(src, rect.width(), rect.height(), image.bytesPerLine(),
dest, screen->linestep());
}
template <class DST, class SRC>
static inline void blit270(QScreen *screen, const QImage &image,
const QRect &rect, const QPoint &topLeft)
{
const SRC *src = (const SRC *)(image.scanLine(rect.top())) + rect.left();
DST *dest = (DST*)(screen->base() + topLeft.y() * screen->linestep())
+ topLeft.x();
qt_memrotate270(src, rect.width(), rect.height(), image.bytesPerLine(),
dest, screen->linestep());
}
typedef void (*BlitFunc)(QScreen *, const QImage &, const QRect &, const QPoint &);
#define SET_BLIT_FUNC(dst, src, rotation, func) \
do { \
switch (rotation) { \
case Rot90: \
func = blit90<dst, src>; \
break; \
case Rot180: \
func = blit180<dst, src>; \
break; \
case Rot270: \
func = blit270<dst, src>; \
break; \
default: \
break; \
} \
} while (0)
/*!
\reimp
*/
void QTransformedScreen::blit(const QImage &image, const QPoint &topLeft,
const QRegion ®ion)
{
const Transformation trans = d_ptr->transformation;
if (trans == None) {
QProxyScreen::blit(image, topLeft, region);
return;
}
const QVector<QRect> rects = region.rects();
const QRect bound = QRect(0, 0, QScreen::w, QScreen::h)
& QRect(topLeft, image.size());
BlitFunc func = 0;
#ifdef QT_QWS_DEPTH_GENERIC
if (d_ptr->doGenericColors && depth() == 16) {
if (image.depth() == 16)
SET_BLIT_FUNC(qrgb_generic16, quint16, trans, func);
else
SET_BLIT_FUNC(qrgb_generic16, quint32, trans, func);
} else
#endif
switch (depth()) {
#ifdef QT_QWS_DEPTH_32
case 32:
#ifdef QT_QWS_DEPTH_16
if (image.depth() == 16)
SET_BLIT_FUNC(quint32, quint16, trans, func);
else
#endif
SET_BLIT_FUNC(quint32, quint32, trans, func);
break;
#endif
#if defined(QT_QWS_DEPTH_24) || defined(QT_QWS_DEPTH18)
case 24:
case 18:
SET_BLIT_FUNC(quint24, quint24, trans, func);
break;
#endif
#if defined(QT_QWS_DEPTH_16) || defined(QT_QWS_DEPTH_15) || defined(QT_QWS_DEPTH_12)
case 16:
#if defined QT_QWS_ROTATE_BGR
if (pixelType() == BGRPixel && image.depth() == 16) {
SET_BLIT_FUNC(qbgr565, quint16, trans, func);
break;
} //fall-through here!!!
#endif
case 15:
#if defined QT_QWS_ROTATE_BGR
if (pixelType() == BGRPixel && image.format() == QImage::Format_RGB555) {
SET_BLIT_FUNC(qbgr555, qrgb555, trans, func);
break;
} //fall-through here!!!
#endif
case 12:
if (image.depth() == 16)
SET_BLIT_FUNC(quint16, quint16, trans, func);
else
SET_BLIT_FUNC(quint16, quint32, trans, func);
break;
#endif
#ifdef QT_QWS_DEPTH_8
case 8:
if (image.format() == QImage::Format_RGB444)
SET_BLIT_FUNC(quint8, qrgb444, trans, func);
else if (image.depth() == 16)
SET_BLIT_FUNC(quint8, quint16, trans, func);
else
SET_BLIT_FUNC(quint8, quint32, trans, func);
break;
#endif
default:
return;
}
if (!func)
return;
QWSDisplay::grab();
for (int i = 0; i < rects.size(); ++i) {
const QRect r = rects.at(i) & bound;
QPoint dst;
switch (trans) {
case Rot90:
dst = mapToDevice(r.topRight(), QSize(w, h));
break;
case Rot180:
dst = mapToDevice(r.bottomRight(), QSize(w, h));
break;
case Rot270:
dst = mapToDevice(r.bottomLeft(), QSize(w, h));
break;
default:
break;
}
func(this, image, r.translated(-topLeft), dst);
}
QWSDisplay::ungrab();
}
/*!
\reimp
*/
void QTransformedScreen::solidFill(const QColor &color, const QRegion ®ion)
{
const QRegion tr = mapToDevice(region, QSize(w,h));
Q_ASSERT(tr.boundingRect() == mapToDevice(region.boundingRect(), QSize(w,h)));
#ifdef QT_REGION_DEBUG
qDebug() << "QTransformedScreen::solidFill region" << region << "transformed" << tr;
#endif
QProxyScreen::solidFill(color, tr);
}
/*!
\reimp
*/
QSize QTransformedScreen::mapToDevice(const QSize &s) const
{
switch (d_ptr->transformation) {
case None:
case Rot180:
break;
case Rot90:
case Rot270:
return QSize(s.height(), s.width());
break;
}
return s;
}
/*!
\reimp
*/
QSize QTransformedScreen::mapFromDevice(const QSize &s) const
{
switch (d_ptr->transformation) {
case None:
case Rot180:
break;
case Rot90:
case Rot270:
return QSize(s.height(), s.width());
break;
}
return s;
}
/*!
\reimp
*/
QPoint QTransformedScreen::mapToDevice(const QPoint &p, const QSize &s) const
{
QPoint rp(p);
switch (d_ptr->transformation) {
case None:
break;
case Rot90:
rp.setX(p.y());
rp.setY(s.width() - p.x() - 1);
break;
case Rot180:
rp.setX(s.width() - p.x() - 1);
rp.setY(s.height() - p.y() - 1);
break;
case Rot270:
rp.setX(s.height() - p.y() - 1);
rp.setY(p.x());
break;
}
return rp;
}
/*!
\reimp
*/
QPoint QTransformedScreen::mapFromDevice(const QPoint &p, const QSize &s) const
{
QPoint rp(p);
switch (d_ptr->transformation) {
case None:
break;
case Rot90:
rp.setX(s.height() - p.y() - 1);
rp.setY(p.x());
break;
case Rot180:
rp.setX(s.width() - p.x() - 1);
rp.setY(s.height() - p.y() - 1);
break;
case Rot270:
rp.setX(p.y());
rp.setY(s.width() - p.x() - 1);
break;
}
return rp;
}
/*!
\reimp
*/
QRect QTransformedScreen::mapToDevice(const QRect &r, const QSize &s) const
{
if (r.isNull())
return QRect();
QRect tr;
switch (d_ptr->transformation) {
case None:
tr = r;
break;
case Rot90:
tr.setCoords(r.y(), s.width() - r.x() - 1,
r.bottom(), s.width() - r.right() - 1);
break;
case Rot180:
tr.setCoords(s.width() - r.x() - 1, s.height() - r.y() - 1,
s.width() - r.right() - 1, s.height() - r.bottom() - 1);
break;
case Rot270:
tr.setCoords(s.height() - r.y() - 1, r.x(),
s.height() - r.bottom() - 1, r.right());
break;
}
return correctNormalized(tr);
}
/*!
\reimp
*/
QRect QTransformedScreen::mapFromDevice(const QRect &r, const QSize &s) const
{
if (r.isNull())
return QRect();
QRect tr;
switch (d_ptr->transformation) {
case None:
tr = r;
break;
case Rot90:
tr.setCoords(s.height() - r.y() - 1, r.x(),
s.height() - r.bottom() - 1, r.right());
break;
case Rot180:
tr.setCoords(s.width() - r.x() - 1, s.height() - r.y() - 1,
s.width() - r.right() - 1, s.height() - r.bottom() - 1);
break;
case Rot270:
tr.setCoords(r.y(), s.width() - r.x() - 1,
r.bottom(), s.width() - r.right() - 1);
break;
}
return correctNormalized(tr);
}
/*!
\reimp
*/
QRegion QTransformedScreen::mapToDevice(const QRegion &rgn, const QSize &s) const
{
if (d_ptr->transformation == None)
return QProxyScreen::mapToDevice(rgn, s);
#ifdef QT_REGION_DEBUG
qDebug() << "mapToDevice size" << s << "rgn: " << rgn;
#endif
QRect tr;
QRegion trgn;
QVector<QRect> a = rgn.rects();
const QRect *r = a.data();
int w = s.width();
int h = s.height();
int size = a.size();
switch (d_ptr->transformation) {
case None:
break;
case Rot90:
for (int i = 0; i < size; i++, r++) {
tr.setCoords(r->y(), w - r->x() - 1,
r->bottom(), w - r->right() - 1);
trgn |= correctNormalized(tr);
}
break;
case Rot180:
for (int i = 0; i < size; i++, r++) {
tr.setCoords(w - r->x() - 1, h - r->y() - 1,
w - r->right() - 1, h - r->bottom() - 1);
trgn |= correctNormalized(tr);
}
break;
case Rot270:
for (int i = 0; i < size; i++, r++) {
tr.setCoords(h - r->y() - 1, r->x(),
h - r->bottom() - 1, r->right());
trgn |= correctNormalized(tr);
}
break;
}
#ifdef QT_REGION_DEBUG
qDebug() << "mapToDevice trgn: " << trgn;
#endif
return trgn;
}
/*!
\reimp
*/
QRegion QTransformedScreen::mapFromDevice(const QRegion &rgn, const QSize &s) const
{
if (d_ptr->transformation == None)
return QProxyScreen::mapFromDevice(rgn, s);
#ifdef QT_REGION_DEBUG
qDebug() << "fromDevice: realRegion count: " << rgn.rects().size() << " isEmpty? " << rgn.isEmpty() << " bounds:" << rgn.boundingRect();
#endif
QRect tr;
QRegion trgn;
QVector<QRect> a = rgn.rects();
const QRect *r = a.data();
int w = s.width();
int h = s.height();
int size = a.size();
switch (d_ptr->transformation) {
case None:
break;
case Rot90:
for (int i = 0; i < size; i++, r++) {
tr.setCoords(h - r->y() - 1, r->x(),
h - r->bottom() - 1, r->right());
trgn |= correctNormalized(tr);
}
break;
case Rot180:
for (int i = 0; i < size; i++, r++) {
tr.setCoords(w - r->x() - 1, h - r->y() - 1,
w - r->right() - 1, h - r->bottom() - 1);
trgn |= correctNormalized(tr);
}
break;
case Rot270:
for (int i = 0; i < size; i++, r++) {
tr.setCoords(r->y(), w - r->x() - 1,
r->bottom(), w - r->right() - 1);
trgn |= correctNormalized(tr);
}
break;
}
#ifdef QT_REGION_DEBUG
qDebug() << "fromDevice: transRegion count: " << trgn.rects().size() << " isEmpty? " << trgn.isEmpty() << " bounds:" << trgn.boundingRect();
#endif
return trgn;
}
/*!
\reimp
*/
void QTransformedScreen::setDirty(const QRect& rect)
{
const QRect r = mapToDevice(rect, QSize(width(), height()));
QProxyScreen::setDirty(r);
}
/*!
\reimp
*/
QRegion QTransformedScreen::region() const
{
QRegion deviceRegion = QProxyScreen::region();
return mapFromDevice(deviceRegion, QSize(deviceWidth(), deviceHeight()));
}
QT_END_NAMESPACE
#endif // QT_NO_QWS_TRANSFORMED
|