diff options
author | Jørgen Lind <jorgen.lind@nokia.com> | 2010-03-29 08:06:52 (GMT) |
---|---|---|
committer | Jørgen Lind <jorgen.lind@nokia.com> | 2010-03-29 08:06:52 (GMT) |
commit | a5e1442d8960d3a9f363a8101d02e6fae804b6f8 (patch) | |
tree | e4ccac01df0d33b79dfd06e3f335766e25a34831 | |
parent | 9e12625b31e1d95f023fe67deb50e8bf97903994 (diff) | |
download | Qt-a5e1442d8960d3a9f363a8101d02e6fae804b6f8.zip Qt-a5e1442d8960d3a9f363a8101d02e6fae804b6f8.tar.gz Qt-a5e1442d8960d3a9f363a8101d02e6fae804b6f8.tar.bz2 |
Make sure the blitter api works with Raster GS(x11 and win) and QWS
21 files changed, 623 insertions, 97 deletions
diff --git a/src/gui/image/qpixmap_blitter.cpp b/src/gui/image/qpixmap_blitter.cpp index a22bd8f..6dcf7c7 100644 --- a/src/gui/image/qpixmap_blitter.cpp +++ b/src/gui/image/qpixmap_blitter.cpp @@ -5,10 +5,13 @@ #include <private/qapplication_p.h> #include <private/qgraphicssystem_p.h> +#include <private/qblittable_p.h> #include <private/qdrawhelper_p.h> #ifndef QT_NO_BLITTABLE +QT_BEGIN_NAMESPACE + static int global_ser_no = 0; QBlittablePixmapData::QBlittablePixmapData(QPixmapData::PixelType type) @@ -34,7 +37,7 @@ QBlittable *QBlittablePixmapData::blittable() const { if (!m_blittable) { QBlittablePixmapData *that = const_cast<QBlittablePixmapData *>(this); - that->m_blittable = QApplicationPrivate::graphicsSystem()->createBlittable(QRect(0,0,w,h)); + that->m_blittable = QApplicationPrivate::graphicsSystem()->createBlittable(QSize(w,h)); } return m_blittable; @@ -42,7 +45,7 @@ QBlittable *QBlittablePixmapData::blittable() const void QBlittablePixmapData::setBlittable(QBlittable *blittable) { - resize(blittable->rect().width(),blittable->rect().height()); + resize(blittable->size().width(),blittable->size().height()); m_blittable = blittable; } @@ -259,6 +262,8 @@ QRectF QBlittablePixmapData::clipAndTransformRect(const QRectF &rect) const } return transformationRect; } + +QT_END_NAMESPACE #endif //QT_BLITTER_RASTEROVERLAY #endif //QT_NO_BLITTABLE diff --git a/src/gui/image/qpixmap_blitter_p.h b/src/gui/image/qpixmap_blitter_p.h index 1d85cd3..b9f7630 100644 --- a/src/gui/image/qpixmap_blitter_p.h +++ b/src/gui/image/qpixmap_blitter_p.h @@ -5,6 +5,8 @@ #include <private/qpaintengine_blitter_p.h> #ifndef QT_NO_BLITTABLE +QT_BEGIN_NAMESPACE + class Q_GUI_EXPORT QBlittablePixmapData : public QPixmapData { // Q_DECLARE_PRIVATE(QBlittablePixmapData); @@ -117,5 +119,6 @@ inline void QBlittablePixmapData::unmarkRasterOverlay(const QRectF &rect) #endif } +QT_END_NAMESPACE #endif // QT_NO_BLITTABLE #endif // QPIXMAP_BLITTER_P_H diff --git a/src/gui/painting/painting.pri b/src/gui/painting/painting.pri index 8e7bba7..a3fe2e1 100644 --- a/src/gui/painting/painting.pri +++ b/src/gui/painting/painting.pri @@ -89,12 +89,16 @@ SOURCES += \ painting/qpaintengine_raster.cpp \ painting/qdrawhelper.cpp \ painting/qimagescale.cpp \ - painting/qgrayraster.c + painting/qgrayraster.c \ + painting/qpaintengine_blitter.cpp \ + painting/qblittable.cpp \ HEADERS += \ painting/qpaintengine_raster_p.h \ painting/qrasterdefs_p.h \ - painting/qgrayraster_p.h + painting/qgrayraster_p.h \ + painting/qpaintengine_blitter_p.h \ + painting/qblittable_p.h \ win32 { HEADERS += painting/qprintengine_win_p.h @@ -121,12 +125,14 @@ embedded { painting/qgraphicssystemfactory_p.h \ painting/qgraphicssystemplugin_p.h \ painting/qwindowsurface_raster_p.h \ + painting/qwindowsurface_rasterblittable_p.h \ SOURCES += \ painting/qgraphicssystem_raster.cpp \ painting/qgraphicssystemfactory.cpp \ painting/qgraphicssystemplugin.cpp \ painting/qwindowsurface_raster.cpp \ + painting/qwindowsurface_rasterblittable.cpp \ } unix:x11 { diff --git a/src/gui/painting/qblittable.cpp b/src/gui/painting/qblittable.cpp new file mode 100644 index 0000000..0b2bd64 --- /dev/null +++ b/src/gui/painting/qblittable.cpp @@ -0,0 +1,64 @@ +#include "qblittable_p.h" + +#ifndef QT_NO_BLITTABLE +QT_BEGIN_NAMESPACE + +class QBlittablePrivate +{ +public: + QBlittablePrivate(const QSize &size, QBlittable::Capabilities caps) + : caps(caps), m_size(size), locked(false), cachedImg(0) + {} + QBlittable::Capabilities caps; + QSize m_size; + bool locked; + QImage *cachedImg; +}; + + +QBlittable::QBlittable(const QSize &size, Capabilities caps) + : d_ptr(new QBlittablePrivate(size,caps)) +{ +} + +QBlittable::~QBlittable() +{ + delete d_ptr; +} + + +QBlittable::Capabilities QBlittable::capabilities() const +{ + Q_D(const QBlittable); + return d->caps; +} + +QSize QBlittable::size() const +{ + Q_D(const QBlittable); + return d->m_size; +} + +QImage *QBlittable::lock() +{ + Q_D(QBlittable); + if (!d->locked) { + d->cachedImg = doLock(); + d->locked = true; + } + + return d->cachedImg; +} + +void QBlittable::unlock() +{ + Q_D(QBlittable); + if (d->locked) { + doUnlock(); + d->locked = false; + } +} + +QT_END_NAMESPACE +#endif //QT_NO_BLITTABLE + diff --git a/src/gui/painting/qblittable_p.h b/src/gui/painting/qblittable_p.h new file mode 100644 index 0000000..98caab7d --- /dev/null +++ b/src/gui/painting/qblittable_p.h @@ -0,0 +1,48 @@ +#ifndef QBLITTABLE_P_H +#define QBLITTABLE_P_H + +#include <QtCore/qsize.h> + +#ifndef QT_NO_BLITTABLE +QT_BEGIN_NAMESPACE + +class QImage; +class QBlittablePrivate; + +class Q_GUI_EXPORT QBlittable +{ + Q_DECLARE_PRIVATE(QBlittable); +public: + enum Capability { + + SolidRectCapability = 0x0001, + SourcePixmapCapability = 0x0002, + SourceOverPixmapCapability = 0x0004, + SourceOverScaledPixmapCapability = 0x0008, + + // Internal ones + OutlineCapability = 0x0001000, + }; + Q_DECLARE_FLAGS (Capabilities, Capability); + + QBlittable(const QSize &size, Capabilities caps); + virtual ~QBlittable(); + + Capabilities capabilities() const; + QSize size() const; + + virtual void fillRect(const QRectF &rect, const QColor &color) = 0; + virtual void drawPixmap(const QRectF &rect, const QPixmap &pixmap, const QRectF &subrect) = 0; + + QImage *lock(); + void unlock(); + +protected: + virtual QImage *doLock() = 0; + virtual void doUnlock() = 0; + QBlittablePrivate *d_ptr; +}; + +QT_END_NAMESPACE +#endif //QT_NO_BLITTABLE +#endif //QBLITTABLE_P_H diff --git a/src/gui/painting/qgraphicssystem_p.h b/src/gui/painting/qgraphicssystem_p.h index 8e35f9f..03b0f48 100644 --- a/src/gui/painting/qgraphicssystem_p.h +++ b/src/gui/painting/qgraphicssystem_p.h @@ -62,6 +62,7 @@ QT_BEGIN_NAMESPACE class QPixmapFilter; +class QBlittable; #ifdef Q_WS_LITE class Q_GUI_EXPORT QGraphicsSystemScreen : public QObject @@ -86,7 +87,7 @@ class Q_GUI_EXPORT QGraphicsSystem public: virtual QPixmapData *createPixmapData(QPixmapData::PixelType type) const = 0; virtual QWindowSurface *createWindowSurface(QWidget *widget) const = 0; - virtual QBlittable *createBlittable(const QRect &) const { return 0; } + virtual QBlittable *createBlittable(const QSize &) const { return 0; } virtual ~QGraphicsSystem() = 0; @@ -94,6 +95,7 @@ public: virtual QList<QGraphicsSystemScreen *> screens() const; virtual QPixmap grabWindow(WId window, int x, int y, int width, int height) const; #endif + //### Remove this & change qpixmap.cpp & qbitmap.cpp once every platform is gaurenteed // to have a graphics system. static QPixmapData *createDefaultPixmapData(QPixmapData::PixelType type); diff --git a/src/gui/painting/qpaintengine_blitter.cpp b/src/gui/painting/qpaintengine_blitter.cpp index 1032852..0b74a4d 100644 --- a/src/gui/painting/qpaintengine_blitter.cpp +++ b/src/gui/painting/qpaintengine_blitter.cpp @@ -1,10 +1,13 @@ #include "private/qpaintengine_blitter_p.h" + +#include "private/qblittable_p.h" #include "private/qpaintengine_raster_p.h" #include "private/qpainter_p.h" #include "private/qapplication_p.h" #include "private/qpixmap_blitter_p.h" #ifndef QT_NO_BLITTABLE +QT_BEGIN_NAMESPACE #define STATE_XFORM_SCALE 0x00000001 #define STATE_XFORM_COMPLEX 0x00000002 @@ -617,60 +620,6 @@ inline QRasterPaintEngine *QBlitterPaintEngine::raster() const return d->raster; } -class QBlittablePrivate -{ -public: - QBlittablePrivate(const QRect &rect, QBlittable::Capabilities caps) - : caps(caps), m_rect(rect), locked(false), cachedImg(0) - {} - QBlittable::Capabilities caps; - QRect m_rect; - bool locked; - QImage *cachedImg; -}; - - -QBlittable::QBlittable(const QRect &rect, Capabilities caps) - : d_ptr(new QBlittablePrivate(rect,caps)) -{ -} - -QBlittable::~QBlittable() -{ - delete d_ptr; -} - - -QBlittable::Capabilities QBlittable::capabilities() const -{ - Q_D(const QBlittable); - return d->caps; -} - -QRect QBlittable::rect() const -{ - Q_D(const QBlittable); - return d->m_rect; -} - -QImage *QBlittable::lock() -{ - Q_D(QBlittable); - if (!d->locked) { - d->cachedImg = doLock(); - d->locked = true; - } - - return d->cachedImg; -} - -void QBlittable::unlock() -{ - Q_D(QBlittable); - if (d->locked) { - doUnlock(); - d->locked = false; - } -} - +QT_END_NAMESPACE #endif //QT_NO_BLITTABLE + diff --git a/src/gui/painting/qpaintengine_blitter_p.h b/src/gui/painting/qpaintengine_blitter_p.h index 1a2ad9e..d436993 100644 --- a/src/gui/painting/qpaintengine_blitter_p.h +++ b/src/gui/painting/qpaintengine_blitter_p.h @@ -5,45 +5,11 @@ #include "private/qpaintengine_raster_p.h" #ifndef QT_NO_BLITTABLE +QT_BEGIN_NAMESPACE -class QBlittablePrivate; class QBlitterPaintEnginePrivate; class QBlittablePixmapData; - -class Q_GUI_EXPORT QBlittable -{ - Q_DECLARE_PRIVATE(QBlittable); -public: - enum Capability { - - SolidRectCapability = 0x0001, - SourcePixmapCapability = 0x0002, - SourceOverPixmapCapability = 0x0004, - SourceOverScaledPixmapCapability = 0x0008, - - // Internal ones - OutlineCapability = 0x0001000, - }; - Q_DECLARE_FLAGS (Capabilities, Capability); - - QBlittable(const QRect &rect, Capabilities caps); - virtual ~QBlittable(); - - Capabilities capabilities() const; - QRect rect() const; - - virtual void fillRect(const QRectF &rect, const QColor &color) = 0; - virtual void drawPixmap(const QRectF &rect, const QPixmap &pixmap, const QRectF &subrect) = 0; - - QImage *lock(); - void unlock(); - -protected: - virtual QImage *doLock() = 0; - virtual void doUnlock() = 0; - QBlittablePrivate *d_ptr; -}; - +class QBlittable; class Q_GUI_EXPORT QBlitterPaintEngine : public QPaintEngineEx { @@ -101,5 +67,7 @@ private: }; +QT_END_NAMESPACE #endif //QT_NO_BLITTABLE #endif // QPAINTENGINE_BLITTER_P_H + diff --git a/src/gui/painting/qwindowsurface_rasterblittable.cpp b/src/gui/painting/qwindowsurface_rasterblittable.cpp new file mode 100644 index 0000000..56a79ba --- /dev/null +++ b/src/gui/painting/qwindowsurface_rasterblittable.cpp @@ -0,0 +1,26 @@ +#include "qwindowsurface_rasterblittable_p.h" + +#include <private/qpaintengine_blitter_p.h> +#include <private/qpixmap_blitter_p.h> + +QRasterBlittableWindowSurface::QRasterBlittableWindowSurface(QWidget *widget) + : QRasterWindowSurface(widget), + m_currentImage(0), + m_blittable(0), + m_pmData(new QBlittablePixmapData(QPixmapData::PixmapType)), + m_pixmap(new QPixmap(m_pmData)) +{ +} + +QPaintDevice *QRasterBlittableWindowSurface::paintDevice() +{ + QPaintDevice *device = QRasterWindowSurface::paintDevice(); + if (m_currentImage != device) { + if (device->devType() == QInternal::Image) { + m_currentImage = static_cast<QImage *>(device); + m_blittable = createBlittable(m_currentImage); + m_pmData->setBlittable(m_blittable); + } + } + return m_pixmap; +} diff --git a/src/gui/painting/qwindowsurface_rasterblittable_p.h b/src/gui/painting/qwindowsurface_rasterblittable_p.h new file mode 100644 index 0000000..1e697c7 --- /dev/null +++ b/src/gui/painting/qwindowsurface_rasterblittable_p.h @@ -0,0 +1,21 @@ +#include <private/qwindowsurface_raster_p.h> +#include <private/qpixmapdata_p.h> + +class QBlittable; +class QBlittablePixmapData; + +class Q_GUI_EXPORT QRasterBlittableWindowSurface : public QRasterWindowSurface +{ +public: + QRasterBlittableWindowSurface(QWidget *widget); + + virtual QBlittable *createBlittable(QImage *rasterSurface) = 0; + + QPaintDevice *paintDevice(); + +private: + QImage *m_currentImage; + QBlittable *m_blittable; + QBlittablePixmapData *m_pmData; + QPixmap *m_pixmap; +}; diff --git a/src/plugins/gfxdrivers/blittableqvfb/blittableqvfb.pro b/src/plugins/gfxdrivers/blittableqvfb/blittableqvfb.pro new file mode 100644 index 0000000..d6a2018 --- /dev/null +++ b/src/plugins/gfxdrivers/blittableqvfb/blittableqvfb.pro @@ -0,0 +1,28 @@ +TARGET = qscreenblittablevfb +include(../../qpluginbase.pri) + +DEFINES += QT_QWS_QVFB QT_QWS_MOUSE_QVFB QT_QWS_KBD_QVFB + +QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/gfxdrivers + +HEADERS = qgraphicssystem_blittableqvfb.h \ + qscreen_blittableqvfb.h \ + qwindowsurface_qwsblittable.h \ + qblittable_image.h + +SOURCES = main.cpp \ + qwindowsurface_qwsblittable.cpp + +#include qvfb sources +HEADERS += \ + $$QT_SOURCE_TREE/src/gui/embedded/qscreenvfb_qws.h \ + $$QT_SOURCE_TREE/src/gui/embedded/qkbdvfb_qws.h \ + $$QT_SOURCE_TREE/src/gui/embedded/qmousevfb_qws.h + +SOURCES += \ + $$QT_SOURCE_TREE/src/gui/embedded/qscreenvfb_qws.cpp \ + $$QT_SOURCE_TREE/src/gui/embedded/qkbdvfb_qws.cpp \ + $$QT_SOURCE_TREE/src/gui/embedded/qmousevfb_qws.cpp + +target.path += $$[QT_INSTALL_PLUGINS]/gfxdrivers +INSTALLS += target diff --git a/src/plugins/gfxdrivers/blittableqvfb/main.cpp b/src/plugins/gfxdrivers/blittableqvfb/main.cpp new file mode 100644 index 0000000..b6d2603 --- /dev/null +++ b/src/plugins/gfxdrivers/blittableqvfb/main.cpp @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <qscreendriverplugin_qws.h> +#include <qstringlist.h> +#include "qscreen_blittableqvfb.h" + +#ifndef QT_NO_LIBRARY +QT_BEGIN_NAMESPACE + +class ScreenBlittableVfbDriver : public QScreenDriverPlugin +{ +public: + ScreenBlittableVfbDriver(); + + QStringList keys() const; + QScreen *create(const QString&, int displayId); +}; + +ScreenBlittableVfbDriver::ScreenBlittableVfbDriver() +: QScreenDriverPlugin() +{ +} + +QStringList ScreenBlittableVfbDriver::keys() const +{ + QStringList list; + list << "BlittableQVFb"; + return list; +} + +QScreen* ScreenBlittableVfbDriver::create(const QString& driver, int displayId) +{ + if (driver.toLower() == "blittableqvfb") + return new QBlittableVFbScreen(displayId); + + return 0; +} + +Q_EXPORT_PLUGIN2(qscreenblittablevfb, ScreenBlittableVfbDriver) + +QT_END_NAMESPACE +#endif //QT_NO_LIBRARY diff --git a/src/plugins/gfxdrivers/blittableqvfb/qblittable_image.h b/src/plugins/gfxdrivers/blittableqvfb/qblittable_image.h new file mode 100644 index 0000000..3f8dc69 --- /dev/null +++ b/src/plugins/gfxdrivers/blittableqvfb/qblittable_image.h @@ -0,0 +1,48 @@ +#include <qimage.h> + +#include <private/qblittable_p.h> + + +class QImageBlittable : public QBlittable +{ +public: + QImageBlittable(QImage *image, bool deleteImage) + : QBlittable(image->size(), QBlittable::Capabilities(QBlittable::SolidRectCapability + |QBlittable::SourcePixmapCapability + |QBlittable::SourceOverPixmapCapability + |QBlittable::SourceOverScaledPixmapCapability)), + m_image(image), m_deleteImage(deleteImage) + { + + } + + ~QImageBlittable() { + if (m_deleteImage) + delete m_image; + } + + void fillRect(const QRectF &rect, const QColor &color) + { + QPainter p(lock()); + p.fillRect(rect,color); + } + void drawPixmap(const QRectF &rect, const QPixmap &pixmap, const QRectF &source) + { + //here it is possible to do a pixmap.pixmapData()->buffer() + //but is like this to show how to get the the blitter + QPixmapData *data = pixmap.pixmapData(); + Q_ASSERT(data->width() && data->height()); + Q_ASSERT(data->classId() == QPixmapData::BlitterClass); + QBlittablePixmapData *blittableData = static_cast<QBlittablePixmapData*>(data); + + QPainter p(lock()); + p.drawImage(rect, *blittableData->blittable()->lock(),source); + } + +protected: + QImage *doLock() { return m_image; } + void doUnlock() { } +private: + QImage *m_image; + bool m_deleteImage; +}; diff --git a/src/plugins/gfxdrivers/blittableqvfb/qgraphicssystem_blittableqvfb.h b/src/plugins/gfxdrivers/blittableqvfb/qgraphicssystem_blittableqvfb.h new file mode 100644 index 0000000..89940d0 --- /dev/null +++ b/src/plugins/gfxdrivers/blittableqvfb/qgraphicssystem_blittableqvfb.h @@ -0,0 +1,47 @@ +#include <private/qgraphicssystem_p.h> +#include <private/qpixmap_blitter_p.h> +#include <private/qpixmap_raster_p.h> +#include <QScreen> + +#include "qwindowsurface_qwsblittable.h" +#include "qblittable_image.h" +#include <qapplication.h> + +class QBlittableVFbGraphicsSystem : public QGraphicsSystem +{ +public: + QPixmapData *createPixmapData(QPixmapData::PixelType type) const + { + if (type == QPixmapData::PixmapType) { + return new QBlittablePixmapData(type); + } else { + return new QRasterPixmapData(type); + } + } + + QWindowSurface *createWindowSurface(QWidget *widget) const + { + if (QApplication::type() == QApplication::GuiServer) + return new QWSBlittableMemSurface(widget); + else + return QScreen::instance()->createSurface(widget); + } + + QBlittable *createBlittable(const QSize &size) const + { + QImage *image = new QImage(size,QImage::Format_ARGB32); + return new QImageBlittable(image,true); + } + + static QGraphicsSystem *instance() + { + static QGraphicsSystem *system = 0; + if (!system) { + system = new QBlittableVFbGraphicsSystem; + } + return system; + } + +private: + QBlittableVFbGraphicsSystem() { } +}; diff --git a/src/plugins/gfxdrivers/blittableqvfb/qscreen_blittableqvfb.h b/src/plugins/gfxdrivers/blittableqvfb/qscreen_blittableqvfb.h new file mode 100644 index 0000000..645aeec --- /dev/null +++ b/src/plugins/gfxdrivers/blittableqvfb/qscreen_blittableqvfb.h @@ -0,0 +1,14 @@ +#include <qscreenvfb_qws.h> +#include "qgraphicssystem_blittableqvfb.h" + +class QBlittableVFbScreen : public QVFbScreen +{ +public: + explicit QBlittableVFbScreen(int display_id) + : QVFbScreen(display_id) + { + setGraphicsSystem(QBlittableVFbGraphicsSystem::instance()); + + } + +}; diff --git a/src/plugins/gfxdrivers/blittableqvfb/qwindowsurface_qwsblittable.cpp b/src/plugins/gfxdrivers/blittableqvfb/qwindowsurface_qwsblittable.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/plugins/gfxdrivers/blittableqvfb/qwindowsurface_qwsblittable.cpp diff --git a/src/plugins/gfxdrivers/blittableqvfb/qwindowsurface_qwsblittable.h b/src/plugins/gfxdrivers/blittableqvfb/qwindowsurface_qwsblittable.h new file mode 100644 index 0000000..b955322 --- /dev/null +++ b/src/plugins/gfxdrivers/blittableqvfb/qwindowsurface_qwsblittable.h @@ -0,0 +1,36 @@ +#include "qblittable_image.h" + +#include <private/qpixmap_blitter_p.h> +#include <private/qwindowsurface_qws_p.h> + +class QBlittablePixmapData; + +class Q_GUI_EXPORT QWSBlittableMemSurface : public QWSLocalMemSurface +{ +public: + QWSBlittableMemSurface( QWidget *window ) + : QWSLocalMemSurface(window), + m_currentPaintDevice(0), + pmData(new QBlittablePixmapData(QPixmapData::PixmapType)), + pm(pmData) + { + } + + QPaintDevice *paintDevice() + { + if (QWSLocalMemSurface::paintDevice() != m_currentPaintDevice) { + QPaintDevice *device = QWSLocalMemSurface::paintDevice(); + if (device->devType() == QInternal::Image) { + img = *static_cast<QImage *>(device); + pmData->setBlittable(new QImageBlittable(&img,false)); + } + } + return ± + } + +private: + QPaintDevice *m_currentPaintDevice; + QBlittablePixmapData *pmData; + QPixmap pm; +}; + diff --git a/src/plugins/graphicssystems/blittable/blittable.pro b/src/plugins/graphicssystems/blittable/blittable.pro new file mode 100644 index 0000000..596e92f --- /dev/null +++ b/src/plugins/graphicssystems/blittable/blittable.pro @@ -0,0 +1,12 @@ +TARGET = qblittablegraphicssystem +include(../../qpluginbase.pri) + +QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/graphicssystems + +SOURCES = main.cpp +HEADERS = qblittable_image.h \ + qgraphicssystem_blittable.h \ + qwindowsurface_imageblittable.h + +target.path += $$[QT_INSTALL_PLUGINS]/graphicssystems +INSTALLS += target diff --git a/src/plugins/graphicssystems/blittable/main.cpp b/src/plugins/graphicssystems/blittable/main.cpp new file mode 100644 index 0000000..06c3189 --- /dev/null +++ b/src/plugins/graphicssystems/blittable/main.cpp @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <private/qgraphicssystemplugin_p.h> + +#include "qgraphicssystem_blittable.h" + +QT_BEGIN_NAMESPACE + +class QBlittableGraphicsSystemPlugin : public QGraphicsSystemPlugin +{ +public: + QStringList keys() const; + QGraphicsSystem *create(const QString&); +}; + +QStringList QBlittableGraphicsSystemPlugin::keys() const +{ + QStringList list; + list << QLatin1String("Blittable"); + return list; +} + +QGraphicsSystem* QBlittableGraphicsSystemPlugin::create(const QString& system) +{ + if (system.toLower() == QLatin1String("blittable")) { + return new QBlittableGraphicsSystem; + } + + return 0; +} + +Q_EXPORT_PLUGIN2(blittable, QBlittableGraphicsSystemPlugin) + +QT_END_NAMESPACE diff --git a/src/plugins/graphicssystems/blittable/qblittable_image.h b/src/plugins/graphicssystems/blittable/qblittable_image.h new file mode 100644 index 0000000..8ca86b7 --- /dev/null +++ b/src/plugins/graphicssystems/blittable/qblittable_image.h @@ -0,0 +1,48 @@ +#include <qimage.h> + +#include <private/qpaintengine_blitter_p.h> + + +class QImageBlittable : public QBlittable +{ +public: + QImageBlittable(QImage *image, bool deleteImage) + : QBlittable(image->size(), QBlittable::Capabilities(QBlittable::SolidRectCapability + |QBlittable::SourcePixmapCapability + |QBlittable::SourceOverPixmapCapability + |QBlittable::SourceOverScaledPixmapCapability)), + m_image(image), m_deleteImage(deleteImage) + { + + } + + ~QImageBlittable() { + if (m_deleteImage) + delete m_image; + } + + void fillRect(const QRectF &rect, const QColor &color) + { + QPainter p(lock()); + p.fillRect(rect,color); + } + void drawPixmap(const QRectF &rect, const QPixmap &pixmap, const QRectF &source) + { + //here it is possible to do a pixmap.pixmapData()->buffer() + //but is like this to show how to get the the blitter + QPixmapData *data = pixmap.pixmapData(); + Q_ASSERT(data->width() && data->height()); + Q_ASSERT(data->classId() == QPixmapData::BlitterClass); + QBlittablePixmapData *blittableData = static_cast<QBlittablePixmapData*>(data); + + QPainter p(lock()); + p.drawImage(rect, *blittableData->blittable()->lock(),source); + } + +protected: + QImage *doLock() { return m_image; } + void doUnlock() { } +private: + QImage *m_image; + bool m_deleteImage; +}; diff --git a/src/plugins/graphicssystems/blittable/qgraphicssystem_blittable.h b/src/plugins/graphicssystems/blittable/qgraphicssystem_blittable.h new file mode 100644 index 0000000..b42021e --- /dev/null +++ b/src/plugins/graphicssystems/blittable/qgraphicssystem_blittable.h @@ -0,0 +1,47 @@ +#include <private/qgraphicssystem_p.h> +#include <private/qblittable_p.h> +#include <private/qpixmap_blitter_p.h> +#include <private/qpixmap_raster_p.h> +#include <private/qwindowsurface_rasterblittable_p.h> + +#include "qblittable_image.h" + +class QImageBlittableWindowSurface : public QRasterBlittableWindowSurface +{ +public: + QImageBlittableWindowSurface(QWidget *widget) + : QRasterBlittableWindowSurface(widget) + {} + + QBlittable *createBlittable(QImage *rasterSurface) + { + return new QImageBlittable(rasterSurface,false); + } + +}; + +class QBlittableGraphicsSystem : public QGraphicsSystem +{ +public: + ~QBlittableGraphicsSystem() { } + + QPixmapData *createPixmapData(QPixmapData::PixelType type) const + { + if (type == QPixmapData::PixmapType) + return new QBlittablePixmapData(type); + else + return new QRasterPixmapData(type); + } + + QWindowSurface *createWindowSurface(QWidget *widget) const + { + return new QImageBlittableWindowSurface(widget); + } + + QBlittable *createBlittable(const QSize &size) const + { + QImage *image = new QImage(size, QImage::Format_ARGB32_Premultiplied); + return new QImageBlittable(image,true); + } +}; + |