📄 qscreen_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 "qscreen_qws.h"#include "qcolormap.h"#include "qscreendriverfactory_qws.h"#include "qwindowsystem_qws.h"#include "qwidget.h"#include "qcolor.h"#include "qpixmap.h"#include "qwsdisplay_qws.h"#include <private/qdrawhelper_p.h>#include <private/qpaintengine_raster_p.h>#include <private/qpainter_p.h>#include <private/qwindowsurface_qws_p.h>#include <private/qwidget_p.h>// #define QT_USE_MEMCPY_DUFF#ifndef QT_NO_QWS_CURSORbool qt_sw_cursor=false;Q_GUI_EXPORT QScreenCursor * qt_screencursor = 0;#endifQ_GUI_EXPORT QScreen * qt_screen = 0;ClearCacheFunc QScreen::clearCacheFunc = 0;#ifndef QT_NO_QWS_CURSOR/*! \class QScreenCursor \ingroup qws \brief The QScreenCursor class is a base class for screen cursors in Qtopia Core. Note that this class is non-portable, and that it is only available in \l {Qtopia Core}. QScreenCursor implements a software cursor, but can be subclassed to support hardware cursors as well. When deriving from the QScreenCursor class it is important to maintain the cursor's image, position, hot spot (the point within the cursor's image that will be the position of the associated mouse events) and visibility as well as informing whether it is hardware accelerated or not. Note that there may only be one screen cursor at a time. Use the static instance() function to retrieve a pointer to the current screen cursor. Typically, the cursor is constructed by the QScreen class or one of its descendants when it is initializing the device; the QScreenCursor class should never be instantiated explicitly. Use the move() function to change the position of the cursor, and the set() function to alter its image or its hot spot. In addition, you can find out whether the cursor is accelerated or not, using the isAccelerated() function, and the boundingRect() function returns the cursor's bounding rectangle. The cursor's appearance can be controlled using the isVisible(), hide() and show() functions; alternatively the QWSServer class provides some means of controlling the cursor's appearance using the QWSServer::isCursorVisible() and QWSServer::setCursorVisible() functions. \sa QScreen, QWSServer*//*! \fn static QScreenCursor* QScreenCursor::instance() \since 4.2 Returns a pointer to the application's unique screen cursor.*/extern bool qws_sw_cursor;/*! Constructs a screen cursor*/QScreenCursor::QScreenCursor(){ pos = QPoint(qt_screen->deviceWidth()/2, qt_screen->deviceHeight()/2); size = QSize(0,0); enable = true; hwaccel = false; supportsAlpha = true;}/*! Destroys the screen cursor.*/QScreenCursor::~QScreenCursor(){}/*! Hides the cursor from the screen. \sa show()*/void QScreenCursor::hide(){ if (enable) { enable = false; if (!hwaccel) qt_screen->exposeRegion(boundingRect(), 0); }}/*! Shows the mouse cursor. \sa hide()*/void QScreenCursor::show(){ if (!enable) { enable = true; if (!hwaccel) qt_screen->exposeRegion(boundingRect(), 0); }}/*! Sets the cursor's image to be the given \a image. The \a hotx and \a hoty parameters define the cursor's hot spot, i.e., the point within the cursor's image that will be the position of the associated mouse events. \sa move()*/void QScreenCursor::set(const QImage &image, int hotx, int hoty){ const QRect r = boundingRect(); hotspot = QPoint(hotx, hoty); cursor = image; size = image.size(); if (enable && !hwaccel) qt_screen->exposeRegion(r | boundingRect(), 0);}/*! Moves the mouse cursor to the given position, i.e., (\a x, \a y). Note that the given position defines the top-left corner of the cursor's image, i.e., not the cursor's hot spot (the position of the associated mouse events). \sa set()*/void QScreenCursor::move(int x, int y){ const QRegion r = boundingRect(); pos = QPoint(x,y); if (enable && !hwaccel) qt_screen->exposeRegion(r | boundingRect(), 0);}/*! \fn void QScreenCursor::initSoftwareCursor () Initializes the screen cursor. This function is typically called from the screen driver when initializing the device. Alternatively, the cursor can be set directly using the pointer returned by the static instance() function. \sa QScreen::initDevice()*/void QScreenCursor::initSoftwareCursor(){ qt_screencursor = new QScreenCursor;}#endif // QT_NO_QWS_CURSOR/*! \fn QRect QScreenCursor::boundingRect () const Returns the cursor's bounding rectangle.*//*! \internal \fn bool QScreenCursor::enabled ()*//*! \fn QImage QScreenCursor::image () const Returns the cursor's image.*//*! \fn bool QScreenCursor::isAccelerated () const Returns true if the cursor is accelerated; otherwise false.*//*! \fn bool QScreenCursor::isVisible () const Returns true if the cursor is visible; otherwise false.*//*! \internal \fn bool QScreenCursor::supportsAlphaCursor () const*//* \variable QScreenCursor::cursor \brief the cursor's image. \sa image()*//* \variable QScreenCursor::size \brief the cursor's size*//* \variable QScreenCursor::pos \brief the cursor's position, i.e., the position of the top-left corner of the crsor's image \sa set(), move()*//* \variable QScreenCursor::hotspot \brief the cursor's hotspot, i.e., the point within the cursor's image that will be the position of the associated mouse events. \sa set(), move()*//* \variable QScreenCursor::enable \brief whether the cursor is visible or not \sa isVisible()*//* \variable QScreenCursor::hwaccel \brief holds whether the cursor is accelerated or not If the cursor is not accelerated, its image will be included by the screen when it composites the window surfaces. \sa isAccelerated()*//* \variable QScreenCursor::supportsAlpha*//*! \internal \macro qt_screencursor \relates QScreenCursor A global pointer referring to the unique screen cursor. It is equivalent to the pointer returned by the QScreenCursor::instance() function.*/class QScreenPrivate{public: QScreenPrivate(QScreen *parent); inline QImage::Format preferredImageFormat() const; typedef void (*SolidFillFunc)(QScreen*, const QColor&, const QRegion&); typedef void (*BlitFunc)(QScreen*, const QImage&, const QPoint&, const QRegion&); SolidFillFunc solidFill; BlitFunc blit; QPoint offset; QList<QScreen*> subScreens; QImage::Format pixelFormat;#if Q_BYTE_ORDER == Q_BIG_ENDIAN bool fb_is_littleEndian;#endif QScreen *q_ptr;};template <typename T>static void solidFill_template(QScreen *screen, const QColor &color, const QRegion ®ion){ T *dest = reinterpret_cast<T*>(screen->base()); const T c = qt_colorConvert<T, quint32>(color.rgba(), 0); const int stride = screen->linestep(); const QVector<QRect> rects = region.rects(); for (int i = 0; i < rects.size(); ++i) { const QRect r = rects.at(i); qt_rectfill(dest, c, r.x(), r.y(), r.width(), r.height(), stride); }}#ifdef QT_QWS_DEPTH_GENERICstatic void solidFill_rgb_32bpp(QScreen *screen, const QColor &color, const QRegion ®ion){ quint32 *dest = reinterpret_cast<quint32*>(screen->base()); const quint32 c = qt_convertToRgb<quint32>(color.rgba()); const int stride = screen->linestep(); const QVector<QRect> rects = region.rects(); for (int i = 0; i < rects.size(); ++i) { const QRect r = rects.at(i); qt_rectfill(dest, c, r.x(), r.y(), r.width(), r.height(), stride); }}static void solidFill_rgb_16bpp(QScreen *screen, const QColor &color, const QRegion ®ion){ quint16 *dest = reinterpret_cast<quint16*>(screen->base()); const quint16 c = qt_convertToRgb<quint32>(color.rgba()); const int stride = screen->linestep(); const QVector<QRect> rects = region.rects(); for (int i = 0; i < rects.size(); ++i) { const QRect r = rects.at(i); qt_rectfill(dest, c, r.x(), r.y(), r.width(), r.height(), stride); }}#endif // QT_QWS_DEPTH_GENERIC#ifdef QT_QWS_DEPTH_4static inline void qt_rectfill_gray4(quint8 *dest, quint8 value, int x, int y, int width, int height, int stride){ const int pixelsPerByte = 2; dest += y * stride + x / pixelsPerByte; const int doAlign = x & 1; const int doTail = (width - doAlign) & 1; const int width8 = (width - doAlign) / pixelsPerByte; for (int j = 0; j < height; ++j) { if (doAlign) *dest = (*dest & 0xf0) | (value & 0x0f); if (width8) qt_memfill<quint8>(dest + doAlign, value, width8); if (doTail) { quint8 *d = dest + doAlign + width8; *d = (*d & 0x0f) | (value & 0xf0); } dest += stride; }}static void solidFill_gray4(QScreen *screen, const QColor &color, const QRegion ®ion){ quint8 *dest = reinterpret_cast<quint8*>(screen->base()); const quint8 c = qGray(color.rgba()) >> 4; const quint8 c8 = (c << 4) | c; const int stride = screen->linestep(); const QVector<QRect> rects = region.rects(); for (int i = 0; i < rects.size(); ++i) { const QRect r = rects.at(i); qt_rectfill_gray4(dest, c8, r.x(), r.y(), r.width(), r.height(), stride); }}#endif // QT_QWS_DEPTH_4#ifdef QT_QWS_DEPTH_1static inline void qt_rectfill_mono(quint8 *dest, quint8 value, int x, int y, int width, int height, int stride){ const int pixelsPerByte = 8; const int alignWidth = qMin(width, (8 - (x & 7)) & 7); const int doAlign = (alignWidth > 0 ? 1 : 0); const int alignStart = pixelsPerByte - 1 - (x & 7); const int alignStop = alignStart - (alignWidth - 1); const quint8 alignMask = ((1 << alignWidth) - 1) << alignStop; const int tailWidth = (width - alignWidth) & 7; const int doTail = (tailWidth > 0 ? 1 : 0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -