From 7dea84cd015538dc327e489113919d75c8e275bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lind?= Date: Mon, 16 Nov 2009 11:33:26 +0100 Subject: Added QBlittablePixmapData Is going to be used by everyone that reimplements QBlittable --- src/gui/image/image.pri | 2 + src/gui/image/qimage.h | 1 + src/gui/image/qpixmap_blitter.cpp | 65 +++++++++++++++++++++++++++++++ src/gui/image/qpixmap_blitter_p.h | 60 ++++++++++++++++++++++++++++ src/gui/image/qpixmapdata_p.h | 2 +- src/gui/painting/qgraphicssystem_p.h | 2 + src/gui/painting/qpaintengine_blitter.cpp | 31 ++++++++------- src/gui/painting/qpaintengine_blitter_p.h | 9 ++--- 8 files changed, 152 insertions(+), 20 deletions(-) create mode 100644 src/gui/image/qpixmap_blitter.cpp create mode 100644 src/gui/image/qpixmap_blitter_p.h diff --git a/src/gui/image/image.pri b/src/gui/image/image.pri index 634c3f3..b232848 100644 --- a/src/gui/image/image.pri +++ b/src/gui/image/image.pri @@ -23,6 +23,7 @@ HEADERS += \ image/qpictureformatplugin.h \ image/qpixmap.h \ image/qpixmap_raster_p.h \ + miage/qpixmap_blitter_p.h \ image/qpixmapcache.h \ image/qpixmapcache_p.h \ image/qpixmapdata_p.h \ @@ -51,6 +52,7 @@ SOURCES += \ image/qiconengineplugin.cpp \ image/qmovie.cpp \ image/qpixmap_raster.cpp \ + image/qpixmap_blitter.cpp \ image/qnativeimage.cpp \ image/qimagepixmapcleanuphooks.cpp \ diff --git a/src/gui/image/qimage.h b/src/gui/image/qimage.h index d8809ef..f5c22bc 100644 --- a/src/gui/image/qimage.h +++ b/src/gui/image/qimage.h @@ -317,6 +317,7 @@ private: QImageData *d; friend class QRasterPixmapData; + friend class QBlittablePixmapData; friend class QPixmapCacheEntry; friend Q_GUI_EXPORT qint64 qt_image_id(const QImage &image); friend const QVector *qt_image_colortable(const QImage &image); diff --git a/src/gui/image/qpixmap_blitter.cpp b/src/gui/image/qpixmap_blitter.cpp new file mode 100644 index 0000000..9730ecc --- /dev/null +++ b/src/gui/image/qpixmap_blitter.cpp @@ -0,0 +1,65 @@ +#include "qpixmap_blitter_p.h" + +#include +#include + +QBlittablePixmapData::QBlittablePixmapData(PixelType type) + : QPixmapData(type,BlitterClass), m_blittable(0), m_engine(0) +{ +} + +QBlittablePixmapData::~QBlittablePixmapData() +{ +} + +void QBlittablePixmapData::resize(int width, int height) +{ + delete m_blittable; + m_blittable = QApplicationPrivate::graphicsSystem()->createBlittable(QRect(0,0,width,height)); + m_engine = 0; +} + +int QBlittablePixmapData::metric(QPaintDevice::PaintDeviceMetric metric) const +{ + QImage *image = m_blittable->lock(); + return image->metric(metric); +} + +void QBlittablePixmapData::fill(const QColor &color) +{ + if (m_blittable->capabilities() & QBlittable::SolidRectCapability) + m_blittable->fillRect(m_blittable->rect(),color); + else + m_blittable->lock()->fill(color.rgb()); +} + +QImage *QBlittablePixmapData::buffer() +{ + return m_blittable->lock(); +} + +QImage QBlittablePixmapData::toImage() +{ + return m_blittable->lock()->copy(); +} + +bool QBlittablePixmapData::hasAlphaChannel() +{ + return m_blittable->lock()->hasAlphaChannel(); +} + +void QBlittablePixmapData::fromImage(const QImage &image, + Qt::ImageConversionFlags flags) +{ + m_blittable = new QImageBlitter(image); + m_engine = 0; +} + +QPaintEngine *QBlittablePixmapData::paintEngine() const +{ + if (!m_engine) { + QBlittablePixmapData *that = const_cast(this); + that->m_engine = new QBlitterPaintEngine(that); + } + return m_engine; +} diff --git a/src/gui/image/qpixmap_blitter_p.h b/src/gui/image/qpixmap_blitter_p.h new file mode 100644 index 0000000..5e93ef4 --- /dev/null +++ b/src/gui/image/qpixmap_blitter_p.h @@ -0,0 +1,60 @@ +#ifndef QPIXMAP_BLITTER_P_H +#define QPIXMAP_BLITTER_P_H + +#include +#include + +class QImageBlitter : public QBlittable +{ +public: + QImageBlitter(const QImage &img) + : QBlittable(img.rect(),0), image(img) + { + } + + void fillRect(const QRectF &, const QColor &) + { + //should never be called + } + void drawPixmap(const QRectF &, const QPixmap &, const QRectF &) + { + //should never be called + } + + QImage *lock() + { + return ℑ + } + + void unlock() + { + } + +private: + QImage image; +}; + +class QBlittablePixmapData : public QPixmapData +{ +public: + QBlittablePixmapData(PixelType type); + ~QBlittablePixmapData(); + + QBlittable *blittable() const { return m_blittable; } + + void resize(int width, int height); + int metric(QPaintDevice::PaintDeviceMetric metric) const; + void fill(const QColor &color); + QImage *buffer(); + QImage toImage(); + bool hasAlphaChannel(); + void fromImage(const QImage &image, Qt::ImageConversionFlags flags); + + QPaintEngine *paintEngine() const; + +protected: + QBlitterPaintEngine *m_engine; + QBlittable *m_blittable; +}; + +#endif // QPIXMAP_BLITTER_P_H diff --git a/src/gui/image/qpixmapdata_p.h b/src/gui/image/qpixmapdata_p.h index 41e2923..292092f 100644 --- a/src/gui/image/qpixmapdata_p.h +++ b/src/gui/image/qpixmapdata_p.h @@ -73,7 +73,7 @@ public: }; #endif enum ClassId { RasterClass, X11Class, MacClass, DirectFBClass, - OpenGLClass, OpenVGClass, CustomClass = 1024 }; + OpenGLClass, OpenVGClass, BlitterClass, CustomClass = 1024 }; QPixmapData(PixelType pixelType, int classId); virtual ~QPixmapData(); diff --git a/src/gui/painting/qgraphicssystem_p.h b/src/gui/painting/qgraphicssystem_p.h index 0b0dfb5..275afc0 100644 --- a/src/gui/painting/qgraphicssystem_p.h +++ b/src/gui/painting/qgraphicssystem_p.h @@ -55,6 +55,7 @@ #include "private/qpixmapdata_p.h" #include "private/qwindowsurface_p.h" +#include "private/qpaintengine_blitter_p.h" #include @@ -85,6 +86,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 &rect) { return 0; } virtual ~QGraphicsSystem() = 0; diff --git a/src/gui/painting/qpaintengine_blitter.cpp b/src/gui/painting/qpaintengine_blitter.cpp index 367a8b5..b134d84 100644 --- a/src/gui/painting/qpaintengine_blitter.cpp +++ b/src/gui/painting/qpaintengine_blitter.cpp @@ -147,9 +147,9 @@ public: class QBlitterPaintEnginePrivate : public QPaintEngineExPrivate { public: - QBlitterPaintEnginePrivate(QPaintDevice *p) - : QPaintEngineExPrivate(), - raster(new QRasterPaintEngine(p)), isBlitterLocked(false), + QBlitterPaintEnginePrivate(QPixmapData *p) + : QPaintEngineExPrivate(), pixmap(p), + raster(new QRasterPaintEngine(&pixmap)), isBlitterLocked(false), capabillities(0), hasXForm(false) { if (QGraphicsSystem *gs = QApplicationPrivate::graphicsSystem()) { @@ -235,6 +235,7 @@ public: raster->d_func()->systemStateChanged(); } + QPixmap pixmap; QRasterPaintEngine *raster; QRasterPaintEngineState *state; @@ -246,7 +247,7 @@ public: uint hasXForm; }; -QBlitterPaintEngine::QBlitterPaintEngine(QPaintDevice *p) +QBlitterPaintEngine::QBlitterPaintEngine(QPixmapData *p) : QPaintEngineEx(*(new QBlitterPaintEnginePrivate(p))) { } @@ -607,23 +608,19 @@ void QBlitterPaintEngine::setState(QPainterState *s) class QBlittablePrivate { public: + QBlittablePrivate(const QRect &rect, QBlittable::Capabilities caps) + : m_rect(rect), caps(caps) + {} QBlittable::Capabilities caps; + QRect m_rect; }; -QBlittable::QBlittable(Capabilities caps) - : d_ptr(new QBlittablePrivate) +QBlittable::QBlittable(const QRect &rect, Capabilities caps) + : d_ptr(new QBlittablePrivate(rect,caps)) { - d_ptr->caps = caps; } -QBlittable::QBlittable(QBlittablePrivate &d, Capabilities caps) - : d_ptr(&d) -{ - d_ptr->caps = caps; -} - - QBlittable::~QBlittable() { delete d_ptr; @@ -636,3 +633,9 @@ QBlittable::Capabilities QBlittable::capabilities() const return d->caps; } +QRect QBlittable::rect() const +{ + Q_D(const QBlittable); + return d->m_rect; +} + diff --git a/src/gui/painting/qpaintengine_blitter_p.h b/src/gui/painting/qpaintengine_blitter_p.h index 90493a4..16b7b2c 100644 --- a/src/gui/painting/qpaintengine_blitter_p.h +++ b/src/gui/painting/qpaintengine_blitter_p.h @@ -22,12 +22,13 @@ public: // Internal ones OutlineCapability = 0x0001000, }; - Q_DECLARE_FLAGS(Capabilities, Capability); + Q_DECLARE_FLAGS (Capabilities, Capability); - QBlittable(Capabilities caps); + 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; @@ -37,8 +38,6 @@ public: protected: QBlittablePrivate *d_ptr; - - QBlittable(QBlittablePrivate &d, Capabilities caps); }; @@ -46,7 +45,7 @@ class Q_GUI_EXPORT QBlitterPaintEngine : public QPaintEngineEx { Q_DECLARE_PRIVATE(QBlitterPaintEngine); public: - QBlitterPaintEngine(QPaintDevice *p); + QBlitterPaintEngine(QPixmapData *p); ~QBlitterPaintEngine(); virtual QPainterState *createState(QPainterState *orig) const; -- cgit v0.12