📄 qdirectpainter_qws.cpp
字号:
/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the QtGui module of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.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 GNU** General Public Licensing requirements will be met:** http://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include "qdirectpainter_qws.h"#include "qscreen_qws.h"#include "private/qobject_p.h"#include "private/qapplication_p.h"#include "qwsdisplay_qws.h"#include "qwidget.h"#include "qimage.h"#include <qwsevent_qws.h>#include <private/qwindowsurface_qws_p.h>#include <private/qwsdisplay_qws_p.h>#ifdef Q_WS_QWS#ifndef QT_NO_DIRECTPAINTER/*! \class QDirectPainter \ingroup multimedia \ingroup qws \brief The QDirectPainter class provides direct access to the underlying hardware in Qtopia Core. \preliminary Note that this class is only available in \l {Qtopia Core}. QDirectPainter allows a client application to reserve a region of the framebuffer and render directly onto the screen. There are two ways of using the QDirectPainter class: You can either reserve a region using the provided static functions, or you can instantiate an object and make use of its more dynamic API. \tableofcontents \section1 Dynamic Allocation By instantiating a QDirectPainter object using the default QDirectPainter::NonReserved surface flag, the client application only gets some control over the reserved region, i.e., it can still render directly onto the screen but the allocated region may change (for example, if a window with a higher focus requests parts of the same region). The currently allocated region can be retrieved using the allocatedRegion() function, while the requestedRegion() function returns the originally reserved region. \section1 Static Allocation Using the static approach, the client application gets complete control over the reserved region, i.e., the affected region will never be modified by the screen driver. To create a static region, pass the QDirectPainter::Reserved surface flag to the constructor. After the reserved region is reported through regionChanged(), the allocated region will not change, unless setRegion() is called. If QDirectPainter::ReservedSynchronous is passed to the constructor, calls to setRegion() will block until the region is reserved, meaning that allocatedRegion() will be available immediately. Note that in the current version setRegion() will cause the application event loop to be entered, potentially causing reentrancy issues. \section1 Rendering To draw on a given region, the application must first get hold of a pointer to the framebuffer. In most cases, this pointer can be retrieved using the QDirectPainter::frameBuffer() function. But note that if the current screen has subscreens, you must query the screen driver instead to identify the correct subscreen. A pointer to the current screen driver can always be retrieved using the static QScreen::instance() function. Then use QScreen's \l {QScreen::}{subScreenIndexAt()} and \l {QScreen::}{subScreens()} functions to access the correct subscreen, and the subscreen's \l {QScreen::}{base()} function to retrieve a pointer to the framebuffer. Depending on the hardware, it might be necessary to lock the framebuffer for exclusive use while writing to it. This is possible using the lock() and unlock() functions. Note that calling lock() will prevent all other applications from working until unlock() is called. In addition, QDirectPainter provides several functions returning information about the framebuffer: the linestep() function returns the length (in bytes) of each scanline of the framebuffer while the screenDepth(), screenWidth() and screenHeight() function return the screen metrics. \sa QScreen, QWSEmbedWidget, {Qtopia Core Architecture}*//*! \enum QDirectPainter::SurfaceFlag This enum describes the behavior of the region reserved by this QDirectPainter object. \value NonReserved The allocated region may change, e.g., if a window with a higher focus requests parts of the same region. See also \l {Dynamic Allocation}. \value Reserved The allocated region will never change. See also \l {Static Allocation}. \value ReservedSynchronous The allocated region will never change and each function that changes the allocated region will be blocking. \sa reservedRegion(), allocatedRegion()*//*! \fn QRegion QDirectPainter::region() \obsolete Use QDirectPainter::reservedRegion() instead.*/static inline QScreen *getPrimaryScreen(){ QScreen *screen = QScreen::instance(); if (!screen->base()) { QList<QScreen*> subScreens = screen->subScreens(); if (subScreens.size() < 1) return 0; screen = subScreens.at(0); } return screen;}static inline QSize screenS(){ QScreen *screen = getPrimaryScreen(); if (!screen) return QSize(); return QSize(screen->width(), screen->height());}static inline QSize devS(){ QScreen *screen = getPrimaryScreen(); if (!screen) return QSize(); return QSize(screen->deviceWidth(), screen->deviceHeight());}class QDirectPainterPrivate : public QObjectPrivate{ Q_DECLARE_PUBLIC(QDirectPainter);public: QDirectPainterPrivate() : surface(0), seenRegion(false) {} ~QDirectPainterPrivate() { if (QPaintDevice::qwsDisplay()) { // make sure not in QApplication destructor qApp->d_func()->directPainters->remove(surface->windowId()); surface->setGeometry(QRect()); } delete surface; } QWSDirectPainterSurface *surface; QRegion requested_region; static QDirectPainter *staticPainter; bool seenRegion;};QDirectPainter *QDirectPainterPrivate::staticPainter = 0;void qt_directpainter_region(QDirectPainter *dp, const QRegion &alloc, int type){ QDirectPainterPrivate *d = dp->d_func(); QRegion r = alloc; QScreen *screen = d->surface->screen(); if (screen->isTransformed()) { const QSize screenSize(screen->width(), screen->height()); r = screen->mapToDevice(r, screenSize); } if (type == QWSRegionEvent::Allocation) { d->surface->setClipRegion(r); d->seenRegion = true; if (dp != QDirectPainterPrivate::staticPainter) { if (!d->surface->flushingRegionEvents) // recursion guard dp->regionChanged(r); } }}#ifndef QT_NO_QWSEMBEDWIDGETvoid qt_directpainter_embedevent(QDirectPainter *dp, const QWSEmbedEvent *event){ if (event->type | QWSEmbedEvent::Region) dp->setRegion(event->region);}#endif/*! Constructs a QDirectPainter object with the given \a parent and surface \a flag.*/QDirectPainter::QDirectPainter(QObject *parent, SurfaceFlag flag) :QObject(*new QDirectPainterPrivate, parent){ Q_D(QDirectPainter); d->surface = new QWSDirectPainterSurface(true, flag); if (flag != NonReserved) d->surface->setReserved(); QApplicationPrivate *ad = qApp->d_func(); if (!ad->directPainters) ad->directPainters = new QMap<WId, QDirectPainter*>; ad->directPainters->insert(d->surface->windowId(), this);}/*! Destroys this QDirectPainter object, releasing the reserved region. \sa allocatedRegion()*/QDirectPainter::~QDirectPainter(){ /* should not be necessary if (this == QDirectPainterPrivate::staticPainter) QDirectPainterPrivate::staticPainter = 0; */}/*! \fn void QDirectPainter::setGeometry(const QRect &rectangle) \since 4.2 Request to reserve the given \a rectangle of the framebuffer. Note that the actually allocated region might differ from the requested one, e.g., if the given region overlaps with the region of another QDirectPainter object. \sa geometry(), allocatedRegion(), setRegion()*/void QDirectPainter::setGeometry(const QRect &rect){ setRegion(rect);}/*! \since 4.2 Returns the bounding rectangle of the requested region. \sa setGeometry(), requestedRegion()*/QRect QDirectPainter::geometry() const{ Q_D(const QDirectPainter); return d->requested_region.boundingRect();}/*! \since 4.2 Requests to reserve the given \a region of the framebuffer. Note that the actually allocated region might differ from the requested one, e.g., if the given region overlaps with the region of another QDirectPainter object. \sa requestedRegion(), allocatedRegion(), {Dynamic Allocation}*/void QDirectPainter::setRegion(const QRegion ®ion){ Q_D(QDirectPainter); d->requested_region = region; d->surface->setRegion(region);}/*! \since 4.2
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -