⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qwindowsurface_qws.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/******************************************************************************** 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 "qwindowsurface_qws_p.h"#include <qwidget.h>#include <qscreen_qws.h>#include <qwsmanager_qws.h>#include <qapplication.h>#include <qwsdisplay_qws.h>#include <qrgb.h>#include <qpaintengine.h>#include <qdesktopwidget.h>#include <private/qapplication_p.h>#include <private/qwsdisplay_qws_p.h>#include <private/qwidget_p.h>#include <private/qwsmanager_p.h>#include <private/qwslock_p.h>#include <private/qbackingstore_p.h>#include <stdio.h>#ifdef Q_BACKINGSTORE_SUBSURFACEStypedef QMap<int, QWSWindowSurface*> SurfaceMap;Q_GLOBAL_STATIC(SurfaceMap, winIdToSurfaceMap);QWSWindowSurface* qt_findWindowSurface(int winId){    return winIdToSurfaceMap()->value(winId);}static void qt_insertWindowSurface(int winId, QWSWindowSurface *surface){    if (!surface)        winIdToSurfaceMap()->remove(winId);    else        winIdToSurfaceMap()->insert(winId, surface);}#endif // Q_BACKINGSTORE_SUBSURFACESinline bool isWidgetOpaque(const QWidget *w){    return w->d_func()->isOpaque();}static inline QScreen *getScreen(const QWidget *w){    const QList<QScreen*> subScreens = qt_screen->subScreens();    if (subScreens.isEmpty())        return qt_screen;    const int screen = QApplication::desktop()->screenNumber(w);    return qt_screen->subScreens().at(screen < 0 ? 0 : screen);}static inline void setImageMetrics(QImage &img, QWidget *window) {    QScreen *myScreen = getScreen(window);    if (myScreen) {        int dpmx = myScreen->width()*1000 / myScreen->physicalWidth();        int dpmy = myScreen->height()*1000 / myScreen->physicalHeight();        img.setDotsPerMeterX(dpmx);        img.setDotsPerMeterY(dpmy);    }}class QWSWindowSurfacePrivate{public:    QWSWindowSurfacePrivate() : flags(0), winId(0) {}    void setWinId(int id) { winId = id; }    QWSWindowSurface::SurfaceFlags flags;    QRegion dirty;    QRegion clip;    QRegion clippedDirty; // dirty, but currently outside the clip region    int winId;};// XXX: this should probably be handled in QWidgetPrivatevoid QWSWindowSurface::invalidateBuffer(){    d_ptr->dirty = QRegion();    d_ptr->clip = QRegion();    d_ptr->clippedDirty = QRegion();    QWidget *win = window();    if (win) {#ifdef Q_BACKINGSTORE_SUBSURFACES        const QPoint offset = -win->mapToGlobal(QPoint());#else        const QPoint offset = -win->geometry().topLeft();#endif        setDirty(geometry().translated(offset)); // XXX: clip with mask#ifndef QT_NO_QWS_MANAGER        QTLWExtra *topextra = win->d_func()->extra->topextra;        QWSManager *manager = topextra->qwsManager;        if (manager)            manager->d_func()->dirtyRegion(QDecoration::All,                                           QDecoration::Normal);#endif    }}int QWSWindowSurface::winId() const{    // XXX: the widget winId may change during the lifetime of the widget!!!    const QWidget *win = window();    if (win && win->isWindow())        return win->internalWinId();#ifdef Q_BACKINGSTORE_SUBSURFACES    if (!d_ptr->winId) {        QWSWindowSurface *that = const_cast<QWSWindowSurface*>(this);        QWSDisplay *display = QWSDisplay::instance();        const int id = display->takeId();        qt_insertWindowSurface(id, that);        that->d_ptr->winId = id;        if (win)            display->nameRegion(id, win->objectName(), win->windowTitle());        else            display->nameRegion(id, QString(), QString());        display->setAltitude(id, 1, true); // XXX    }#endif    return d_ptr->winId;}void QWSWindowSurface::setWinId(int id){    d_ptr->winId = id;}/*!    \class QWSWindowSurface    \since 4.2    \ingroup qws    \preliminary    \internal    \brief The QWSWindowSurface class provides the drawing area for top-level    windows in Qtopia Core.    Note that this class is only available in Qtopia Core.    In \l {Qtopia Core}, the default behavior is for each client to    render its widgets into memory while the server is responsible for    putting the contents of the memory onto the    screen. QWSWindowSurface is used by the window system to implement    the associated memory allocation.    When a screen update is required, the server runs through all the    top-level windows that intersect with the region that is about to    be updated, and ensures that the associated clients have updated    their memory buffer. Then the server uses the screen driver to    copy the content of the memory to the screen. To locate the    relevant parts of memory, the driver is provided with the list of    top-level windows that intersect with the given region. Associated    with each of the top-level windows there is a window surface    representing the drawing area of the window.    When deriving from the QWSWindowSurface class, e.g., when adding    an \l {Adding an Accelerated Graphics Driver in Qtopia    Core}{accelerated graphics driver}, there are several pure virtual    functions that must be implemented. In addition, QWSWindowSurface    provides several virtual functions that can be reimplemented to    customize the drawing process.    \tableofcontents    \section1 Pure Virtual Functions    There are in fact two window surface instances for each top-level    window; one used by the application when drawing a window, and    another used by the server application to perform window    compositioning. Implement the attach() to create the server-side    representation of the surface. The data() function must be    implemented to provide the required data.    Implement the key() function to uniquely identify the surface    class, and the isValid() function to determine is a surface    corresponds to a given widget.    The geometry() function must be implemented to let the window    system determine the area required by the window surface    (QWSWindowSurface also provides a corresponding virtual    setGeometry() function that is called whenever the area necessary    for the top-level window to be drawn, changes). The image()    function is called by the window system during window    compositioning, and must be implemented to return an image of the    top-level window.    Finally, the paintDevice() function must be implemented to return    the appropriate paint device, and the scroll() function must be    implemented to scroll the given region of the surface the given    number of pixels.    \section1 Virtual Functions    When painting onto the surface, the window system will always call    the beginPaint() function before any painting operations are    performed. Likewise the endPaint() function is automatically    called when the painting is done. Reimplement the painterOffset()    function to alter the offset that is applied when drawing.    The window system uses the flush() function to put a given region    of the widget onto the screen, and the release() function to    deallocate the screen region corresponding to this window surface.    \section1 Other Members    QWSWindowSurface provides the window() function returning a    pointer to the top-level window the surface is representing. The    currently visible region of the associated widget can be retrieved    and set using the clipRegion() and setClipRegion() functions,    respectively.    When the window system performs the window compositioning, it uses    the SurfaceFlag enum describing the surface content. The currently    set surface flags can be retrieved and altered using the    surfaceFlags() and setSurfaceFlags() functions. In addition,    QWSWindowSurface provides the isBuffered(), isOpaque() and    isRegionReserved() convenience functions.  Use the dirtyRegion()    function to retrieve the part of the widget that must be    repainted, and the setDirty() function to ensure that a region is    repainted.    \sa {Qtopia Core Architecture#Drawing on Screen}{Qtopia    Core Architecture}*//*!    \enum QWSWindowSurface::SurfaceFlag    This enum is used to describe the window surface's contents.  It    is used by the screen driver to handle region allocation and    composition.    \value RegionReserved The surface contains a reserved area. Once    allocated, a reserved area can not not be changed by the window    system, i.e., no other widgets can be drawn on top of this.    \value Buffered    The surface is in a memory area which is not part of a framebuffer.    (A top-level window with QWidget::windowOpacity() other than 1.0 must use    a buffered surface in order to making blending with the background work.)    \value Opaque    The surface contains only opaque pixels.    \sa surfaceFlags(), setSurfaceFlags()*//*!    \fn bool QWSWindowSurface::isValid() const    \since 4.3    Implement this function to return true if the surface is a valid    surface for the given top-level \a window; otherwise return    false.    \sa window(), key()*//*!    \fn QString QWSWindowSurface::key() const    Implement this function to return a string that uniquely    identifies the class of this surface.    \sa window(), isValid()*//*!    \fn QByteArray QWSWindowSurface::permanentState() const    \since 4.3    Implement this function to return the data required for creating a    server-side representation of the surface.    \sa attach()*//*!    \fn void QWSWindowSurface::setPermanentState(const QByteArray &data)    \since 4.3    Implement this function to attach a server-side surface instance    to the corresponding client side instance using the given \a    data. Return true if successful; otherwise return false.    \sa data()*//*!    \fn const QImage QWSWindowSurface::image() const    Implement this function to return an image of the top-level window.    \sa geometry()*//*!    \fn bool QWSWindowSurface::isRegionReserved() const    Returns true if the QWSWindowSurface::RegionReserved is set; otherwise    returns false.    \sa surfaceFlags()*//*!    \fn bool QWSWindowSurface::isBuffered() const    Returns true if the QWSWindowSurface::Buffered is set; otherwise returns false.    \sa surfaceFlags()*//*!    \fn bool QWSWindowSurface::isOpaque() const    Returns true if the QWSWindowSurface::Opaque is set; otherwise    returns false.    \sa surfaceFlags()*//*!    Constructs an empty surface.*/QWSWindowSurface::QWSWindowSurface()    : QWindowSurface(0), d_ptr(new QWSWindowSurfacePrivate){}/*!    Constructs an empty surface for the given top-level \a widget.*/QWSWindowSurface::QWSWindowSurface(QWidget *widget)    : QWindowSurface(widget), d_ptr(new QWSWindowSurfacePrivate){}QWSWindowSurface::~QWSWindowSurface(){    delete d_ptr;}/*!    Returns the offset to be used when painting.    \sa paintDevice()*/QPoint QWSWindowSurface::painterOffset() const{    const QWidget *w = window();    if (!w)        return QPoint();    return w->geometry().topLeft() - w->frameGeometry().topLeft();}void QWSWindowSurface::beginPaint(const QRegion &){    lock();}void QWSWindowSurface::endPaint(const QRegion &){    unlock();}// XXX: documentation!!!QByteArray QWSWindowSurface::transientState() const{    return QByteArray();}QByteArray QWSWindowSurface::permanentState() const{    return QByteArray();}void QWSWindowSurface::setTransientState(const QByteArray &state){    Q_UNUSED(state);}void QWSWindowSurface::setPermanentState(const QByteArray &state){    Q_UNUSED(state);}bool QWSWindowSurface::lock(int timeout){    Q_UNUSED(timeout);    return true;}void QWSWindowSurface::unlock(){}/*!

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -