summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJørgen Lind <jorgen.lind@nokia.com>2009-11-16 11:33:26 +0100
committerJørgen Lind <jorgen.lind@nokia.com>2009-11-25 10:55:59 +0100
commit7dea84cd015538dc327e489113919d75c8e275bb (patch)
tree4255c5f05fb73ea17eb2a5fb2c078df190652256
parentefa0d024fc262b89189c0589a0ee81fe083635b1 (diff)
downloadqt4-tools-7dea84cd015538dc327e489113919d75c8e275bb.tar.gz
Added QBlittablePixmapData
Is going to be used by everyone that reimplements QBlittable
-rw-r--r--src/gui/image/image.pri2
-rw-r--r--src/gui/image/qimage.h1
-rw-r--r--src/gui/image/qpixmap_blitter.cpp65
-rw-r--r--src/gui/image/qpixmap_blitter_p.h60
-rw-r--r--src/gui/image/qpixmapdata_p.h2
-rw-r--r--src/gui/painting/qgraphicssystem_p.h2
-rw-r--r--src/gui/painting/qpaintengine_blitter.cpp31
-rw-r--r--src/gui/painting/qpaintengine_blitter_p.h9
8 files changed, 152 insertions, 20 deletions
diff --git a/src/gui/image/image.pri b/src/gui/image/image.pri
index 634c3f3090..b2328484ca 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 d8809ef114..f5c22bc384 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<QRgb> *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 0000000000..9730ecc7dc
--- /dev/null
+++ b/src/gui/image/qpixmap_blitter.cpp
@@ -0,0 +1,65 @@
+#include "qpixmap_blitter_p.h"
+
+#include <private/qapplication_p.h>
+#include <private/qgraphicssystem_p.h>
+
+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<QBlittablePixmapData *>(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 0000000000..5e93ef4e3a
--- /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 <private/qpixmapdata_p.h>
+#include <private/qpaintengine_blitter_p.h>
+
+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 &image;
+ }
+
+ 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 41e29230f1..292092f9ae 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 0b0dfb58fc..275afc0a77 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 <qdebug.h>
@@ -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 367a8b506c..b134d8440c 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 90493a433e..16b7b2c961 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;