Qt 4.8
qdirectpainter_qws.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 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 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 "qdirectpainter_qws.h"
43 
44 #include "qscreen_qws.h"
45 #include "private/qobject_p.h"
46 #include "private/qapplication_p.h"
47 #include "qwsdisplay_qws.h"
48 #include "qwidget.h"
49 #include "qimage.h"
50 #include <qwsevent_qws.h>
51 #include <private/qwindowsurface_qws_p.h>
52 #include <private/qwsdisplay_qws_p.h>
53 
55 
56 #ifdef Q_WS_QWS
57 #ifndef QT_NO_DIRECTPAINTER
58 
170 static inline QScreen *getPrimaryScreen()
171 {
172  QScreen *screen = QScreen::instance();
173  if (!screen->base()) {
174  QList<QScreen*> subScreens = screen->subScreens();
175  if (subScreens.size() < 1)
176  return 0;
177  screen = subScreens.at(0);
178  }
179  return screen;
180 }
181 
182 static inline QSize screenS()
183 {
184  QScreen *screen = getPrimaryScreen();
185  if (!screen)
186  return QSize();
187  return QSize(screen->width(), screen->height());
188 }
189 
190 static inline QSize devS()
191 {
192  QScreen *screen = getPrimaryScreen();
193  if (!screen)
194  return QSize();
195  return QSize(screen->deviceWidth(), screen->deviceHeight());
196 }
197 
198 
200 {
202 public:
203 
205 
207  if (QPaintDevice::qwsDisplay()) { // make sure not in QApplication destructor
208  qApp->d_func()->directPainters->remove(surface->windowId());
210  }
211  delete surface;
212  }
213 
216 
219 };
220 
222 
224 {
225  QDirectPainterPrivate *d = dp->d_func();
226 
227  QRegion r = alloc;
228  QScreen *screen = d->surface->screen();
229  if (screen->isTransformed()) {
230  const QSize screenSize(screen->width(), screen->height());
231  r = screen->mapToDevice(r, screenSize);
232  }
233  if (type == QWSRegionEvent::Allocation) {
234  d->surface->setClipRegion(alloc);
235  d->seenRegion = true;
236  if (dp != QDirectPainterPrivate::staticPainter) {
237  if (!d->surface->flushingRegionEvents) // recursion guard
238  dp->regionChanged(r);
239  }
240  }
241 }
242 
243 #ifndef QT_NO_QWSEMBEDWIDGET
245 {
246  if (event->type | QWSEmbedEvent::Region) {
247  QScreen *screen = dp->d_func()->surface->screen();
248  QRegion r = event->region;
249  if (screen->isTransformed()) {
250  const QSize screenSize(screen->width(), screen->height());
251  r = screen->mapToDevice(r, screenSize);
252  }
253  dp->setRegion(r);
254  }
255 }
256 #endif
257 
263  :QObject(*new QDirectPainterPrivate, parent)
264 {
266  d->surface = new QWSDirectPainterSurface(true, flag);
267 
268  if (flag != NonReserved)
269  d->surface->setReserved();
270 
271  QApplicationPrivate *ad = qApp->d_func();
272  if (!ad->directPainters)
274  ad->directPainters->insert(d->surface->windowId(), this);
275 }
276 
283 {
284  /* should not be necessary
285  if (this == QDirectPainterPrivate::staticPainter)
286  QDirectPainterPrivate::staticPainter = 0;
287  */
288 }
289 
306 {
307  setRegion(rect);
308 }
309 
321 {
322  Q_D(const QDirectPainter);
323  return d->requested_region.boundingRect();
324 }
325 
341 {
343  d->requested_region = region;
344 
345  const QScreen *screen = d->surface->screen();
346  if (screen->isTransformed()) {
347  const QSize devSize(screen->deviceWidth(), screen->deviceHeight());
348  const QRegion r = screen->mapFromDevice(region, devSize);
349  d->surface->setRegion(r);
350  } else {
351  d->surface->setRegion(region);
352  }
353 }
354 
371 {
372  Q_D(const QDirectPainter);
373  return d->requested_region;
374 }
375 
392 {
393  Q_D(const QDirectPainter);
394  const QScreen *screen = d->surface->screen();
395  if (screen->isTransformed()) {
396  const QSize screenSize(screen->width(), screen->height());
397  return screen->mapToDevice(d->surface->region(), screenSize);
398  } else {
399  return d->surface->region();
400  }
401 }
402 
412 {
413  Q_D(const QDirectPainter);
414  return d->surface->windowId();
415 }
416 
437 {
438  Q_UNUSED(region);
439 }
440 
464 void QDirectPainter::startPainting(bool lockDisplay)
465 {
467  d->surface->setLocking(lockDisplay);
468 
469  const QScreen *screen = d->surface->screen();
470  if (screen->isTransformed()) {
471  const QSize devSize(screen->deviceWidth(), screen->deviceHeight());
472  const QRegion r = screen->mapFromDevice(d->surface->region(), devSize);
473  d->surface->beginPaint(r);
474  } else {
475  d->surface->beginPaint(d->surface->region());
476  }
477 }
478 
490 {
492 
493  const QScreen *screen = d->surface->screen();
494  if (screen->isTransformed()) {
495  const QSize devSize(screen->deviceWidth(), screen->deviceHeight());
496  const QRegion r = screen->mapFromDevice(d->surface->region(), devSize);
497  d->surface->endPaint(r);
498  } else {
499  d->surface->endPaint(d->surface->region());
500  }
501 }
502 
515 {
516  endPainting();
517  flush(region);
518 }
519 
529 {
531 
532  const QScreen *screen = d->surface->screen();
533  if (screen->isTransformed()) {
534  const QSize devSize(screen->deviceWidth(), screen->deviceHeight());
535  const QRegion r = screen->mapFromDevice(region, devSize);
536  d->surface->flush(0, r, QPoint());
537  } else {
538  d->surface->flush(0, region, QPoint());
539  }
540 }
541 
556 {
558 }
559 
574 {
576 }
577 
578 
599 {
600  if (!QDirectPainterPrivate::staticPainter)
601  QDirectPainterPrivate::staticPainter = new QDirectPainter(qApp, ReservedSynchronous);
602 
604  dp->setRegion(reg);
605 
606  return dp->allocatedRegion();
607 }
608 
625 {
626  QScreen *screen = getPrimaryScreen();
627  if (!screen)
628  return 0;
629  return screen->base();
630 }
631 
647 {
648  return QDirectPainterPrivate::staticPainter
649  ? QDirectPainterPrivate::staticPainter->allocatedRegion() : QRegion();
650 }
651 
658 {
659  QScreen *screen = getPrimaryScreen();
660  if (!screen)
661  return 0;
662  return screen->depth();
663 }
664 
671 {
672  QScreen *screen = getPrimaryScreen();
673  if (!screen)
674  return 0;
675  return screen->deviceWidth();
676 }
677 
684 {
685  QScreen *screen = getPrimaryScreen();
686  if (!screen)
687  return 0;
688  return screen->deviceHeight();
689 }
690 
697 {
698  QScreen *screen = getPrimaryScreen();
699  if (!screen)
700  return 0;
701  return screen->linestep();
702 }
703 
704 
714 {
715  QWSDisplay::grab(true);
716 }
724 {
726 }
727 
728 #endif //QT_NO_DIRECTPAINTER
729 
730 #endif
731 
QWSDirectPainterSurface * surface
double d
Definition: qnumeric_p.h:62
~QDirectPainter()
Destroys this QDirectPainter object, releasing the reserved region.
QRegion requestedRegion() const
Returns the region requested by this QDirectPainter.
unsigned long WId
Definition: qwindowdefs.h:119
static int linestep()
Returns the length (in bytes) of each scanline of the framebuffer.
int type
Definition: qmetatype.cpp:239
int height() const
Returns the logical height of the framebuffer in pixels.
Definition: qscreen_qws.h:228
QRegion allocatedRegion() const
Returns the currently reserved region.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
static QSize screenS()
EventRef event
void setAltitude(int winId, int altitude, bool fixed=false)
WId winId() const
Returns the window system identifier of the widget.
static QWSDisplay * qwsDisplay()
void raise()
Raises the reserved region to the top of the widget stack.
void qt_directpainter_region(QDirectPainter *dp, const QRegion &alloc, int type)
static int screenWidth()
Returns the width of the display in pixels.
int deviceWidth() const
Returns the physical width of the framebuffer device in pixels.
Definition: qscreen_qws.h:233
virtual QSize mapFromDevice(const QSize &) const
Maps the given size from the framebuffer coordinate system to the coordinate space used by the applic...
static int screenHeight()
Returns the height of the display in pixels.
The QDirectPainter class provides direct access to the underlying hardware in Qt for Embedded Linux...
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_D(Class)
Definition: qglobal.h:2482
static QScreen * getPrimaryScreen()
virtual QSize mapToDevice(const QSize &) const
Maps the given size from the coordinate space used by the application to the framebuffer coordinate s...
unsigned char uchar
Definition: qglobal.h:994
int width() const
Returns the logical width of the framebuffer in pixels.
Definition: qscreen_qws.h:227
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
static int screenDepth()
Returns the bit depth of the display.
int linestep() const
Returns the length of each scanline of the framebuffer in bytes.
Definition: qscreen_qws.h:232
void startPainting(bool lockDisplay=true)
Call this function before you start updating the pixels in the allocated region.
static QRegion reservedRegion()
Returns the reserved region.
#define qApp
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
void setGeometry(const QRect &)
Request to reserve the given rectangle of the framebuffer.
QDirectPainter(QObject *parentObject=0, SurfaceFlag flag=NonReserved)
Constructs a QDirectPainter object with the given parent and surface flag.
static QScreen * instance()
Returns a pointer to the application&#39;s QScreen instance.
Definition: qscreen_qws.h:201
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
static void grab()
void endPainting()
Call this function when you are done updating the screen.
virtual void regionChanged(const QRegion &exposedRegion)
This function is called when the allocated region changes.
void qt_directpainter_embedevent(QDirectPainter *dp, const QWSEmbedEvent *event)
static void unlock()
Unlocks the lock on the framebuffer (set using the lock() function), allowing other applications to a...
static QSize devS()
uchar * base() const
Returns a pointer to the beginning of the framebuffer.
Definition: qscreen_qws.h:235
Q_DECLARE_PUBLIC(QDirectPainter)
int deviceHeight() const
Returns the full height of the framebuffer device in pixels.
Definition: qscreen_qws.h:234
void setClipRegion(const QRegion &)
Sets the region currently visible on the screen to be the given clip region.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:559
void lower()
Lowers the reserved region to the bottom of the widget stack.
virtual QList< QScreen * > subScreens() const
Definition: qscreen_qws.h:283
virtual bool isTransformed() const
Returns true if the screen is transformed (for instance, rotated 90 degrees); otherwise returns false...
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
static QRegion reserveRegion(const QRegion &)
Attempts to reserve the region and returns the region that is actually reserved.
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
static QRegion region()
Use QDirectPainter::allocatedRegion() instead.
SurfaceFlag
This enum describes the behavior of the region reserved by this QDirectPainter object.
The QScreen class is a base class for screen drivers in Qt for Embedded Linux.
Definition: qscreen_qws.h:191
void setRegion(const QRegion &)
Requests to reserve the given region of the framebuffer.
QObject * parent
Definition: qobject.h:92
QMap< WId, QDirectPainter * > * directPainters
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
QRect geometry() const
Returns the bounding rectangle of the requested region.
static void ungrab()
static uchar * frameBuffer()
Returns a pointer to the beginning of the display memory.
static QDirectPainter * staticPainter
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
static void lock()
Locks access to the framebuffer.
void setGeometry(const QRect &rect)
Sets the currently allocated area to be the given rect.
void flush(const QRegion &region)
Flushes the region onto the screen.
The QMap class is a template class that provides a skip-list-based dictionary.
Definition: qdatastream.h:67
int depth() const
Returns the depth of the framebuffer, in bits per pixel.
Definition: qscreen_qws.h:229
The QList class is a template class that provides lists.
Definition: qdatastream.h:62