1 /****************************************************************************
3 ** Copyright (C) 2009 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 tools applications 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 ****************************************************************************/
50 #include <sys/types.h>
61 QMMapViewProtocol::QMMapViewProtocol(int displayid
, const QSize
&s
,
62 int d
, QObject
*parent
)
63 : QVFbViewProtocol(displayid
, parent
), hdr(0), dataCache(0), windowId(0)
77 qFatal("Unsupported bit depth %d\n", d
);
80 fileName
= QString("/tmp/.qtvfb_map-%1").arg(displayid
);
86 kh
= new QVFbKeyPipeProtocol(displayid
);
87 mh
= new QVFbMouseLinuxTP(displayid
);
91 bpl
= (w
* d
+ 7) / 8;
93 bpl
= w
* ((d
+ 7) / 8);
95 displaySize
= bpl
* h
;
98 uint data_offset_value
= sizeof(QVFbHeader
);
99 const int page_size
= getpagesize();
100 if (data_offset_value
% page_size
)
101 data_offset_value
+= page_size
- (data_offset_value
% page_size
);
103 dataSize
= bpl
* h
+ data_offset_value
;
105 unlink(fileName
.toLocal8Bit().data());
106 fd
= ::open( fileName
.toLocal8Bit().data(), O_CREAT
|O_RDWR
, 0666 );
107 ::lseek(fd
, dataSize
, SEEK_SET
);
108 ::write(fd
, "\0", 1);
110 data
= (unsigned char *)-1;
112 // might need to do something about size?
113 data
= (unsigned char *)mmap(NULL
, dataSize
, PROT_WRITE
| PROT_READ
,
115 if (data
== MAP_FAILED
)
116 data
= (unsigned char *)-1;
119 if ( (long)data
== -1 ){
122 qFatal( "Cannot attach to mapped file %s", fileName
.toLocal8Bit().data());
124 dataCache
= (unsigned char *)malloc(displaySize
);
125 memset(dataCache
, 0, displaySize
);
126 memset(data
+sizeof(QVFbHeader
), 0, displaySize
);
128 hdr
= (QVFbHeader
*)data
;
134 hdr
->dataoffset
= data_offset_value
;
135 hdr
->update
= QRect();
136 hdr
->brightness
= 255;
139 mRefreshTimer
= new QTimer(this);
140 connect(mRefreshTimer
, SIGNAL(timeout()), this, SLOT(flushChanges()));
143 QMMapViewProtocol::~QMMapViewProtocol()
145 munmap((char *)hdr
, dataSize
);
147 unlink(fileName
.toLocal8Bit().constData());
153 int QMMapViewProtocol::brightness() const
155 return hdr
->brightness
;
158 int QMMapViewProtocol::width() const
163 int QMMapViewProtocol::height() const
168 int QMMapViewProtocol::depth() const
173 int QMMapViewProtocol::linestep() const
175 return hdr
->linestep
;
178 int QMMapViewProtocol::numcols() const
183 QVector
<QRgb
> QMMapViewProtocol::clut() const
185 QVector
<QRgb
> vector(hdr
->numcols
);
186 for (int i
=0; i
< hdr
->numcols
; ++i
)
187 vector
[i
] = hdr
->clut
[i
];
192 unsigned char *QMMapViewProtocol::data() const
195 //return ((unsigned char *)hdr)+hdr->dataoffset;
198 void QMMapViewProtocol::flushChanges()
200 // based of dirty rect, copy changes from hdr to hdrcopy
201 memcpy(dataCache
, ((char *)hdr
) + hdr
->dataoffset
, displaySize
);
202 emit
displayDataChanged(QRect(0, 0, width(), height()));
205 void QMMapViewProtocol::setRate(int interval
)
208 return mRefreshTimer
->start(1000/interval
);
210 mRefreshTimer
->stop();
213 int QMMapViewProtocol::rate() const
215 int i
= mRefreshTimer
->interval();