summaryrefslogtreecommitdiffstats
path: root/src/gui/image/qpixmap_blitter.cpp
diff options
context:
space:
mode:
authorJørgen Lind <jorgen.lind@nokia.com>2010-02-05 11:45:09 (GMT)
committerJørgen Lind <jorgen.lind@nokia.com>2010-02-09 09:54:10 (GMT)
commitece7ebb01c65ff0930881bff869b99c1f6889fa4 (patch)
treeb2ad0e8c21c0a2afa1a0bd7f27e91cdb4380516c /src/gui/image/qpixmap_blitter.cpp
parent99ce03ef6c33a670d86706a8a7d701ac25e2e2b5 (diff)
downloadQt-ece7ebb01c65ff0930881bff869b99c1f6889fa4.zip
Qt-ece7ebb01c65ff0930881bff869b99c1f6889fa4.tar.gz
Qt-ece7ebb01c65ff0930881bff869b99c1f6889fa4.tar.bz2
Second attemt on rasteroverlay in blitterpaintengine
Diffstat (limited to 'src/gui/image/qpixmap_blitter.cpp')
-rw-r--r--src/gui/image/qpixmap_blitter.cpp106
1 files changed, 100 insertions, 6 deletions
diff --git a/src/gui/image/qpixmap_blitter.cpp b/src/gui/image/qpixmap_blitter.cpp
index 6e34fbd..f82a67d 100644
--- a/src/gui/image/qpixmap_blitter.cpp
+++ b/src/gui/image/qpixmap_blitter.cpp
@@ -1,6 +1,7 @@
#include "qpixmap_blitter_p.h"
#include <qpainter.h>
+#include <qimage.h>
#include <private/qapplication_p.h>
#include <private/qgraphicssystem_p.h>
@@ -11,6 +12,9 @@ static int global_ser_no = 0;
QBlittablePixmapData::QBlittablePixmapData(QPixmapData::PixelType type)
: QPixmapData(type,BlitterClass), m_engine(0), m_blittable(0)
+#ifdef QT_BLITTER_RASTEROVERLAY
+ ,m_rasterOverlay(0), m_unmergedCopy(0)
+#endif //QT_BLITTER_RASTEROVERLAY
{
setSerialNumber(++global_ser_no);
}
@@ -19,6 +23,10 @@ QBlittablePixmapData::~QBlittablePixmapData()
{
delete m_blittable;
delete m_engine;
+#ifdef QT_BLITTER_RASTEROVERLAY
+ delete m_rasterOverlay;
+ delete m_unmergedCopy;
+#endif //QT_BLITTER_RASTEROVERLAY
}
QBlittable *QBlittablePixmapData::blittable() const
@@ -132,18 +140,13 @@ void QBlittablePixmapData::fromImage(const QImage &image,
Qt::ImageConversionFlags flags)
{
resize(image.width(),image.height());
+ markRasterOverlay(QRect(0,0,w,h));
QImage *thisImg = buffer();
QImage correctFormatPic = image;
if (correctFormatPic.format() != thisImg->format())
correctFormatPic = correctFormatPic.convertToFormat(thisImg->format(), flags);
- //jl: This does not ALWAYS work as expected :(
-// QPainter p(thisImg);
-// p.setCompositionMode(QPainter::CompositionMode_Source);
-// p.drawImage(0,0,image,flags);
-
- //So just copy strides by hand
uchar *mem = thisImg->bits();
const uchar *bits = correctFormatPic.bits();
int bytesCopied = 0;
@@ -163,3 +166,94 @@ QPaintEngine *QBlittablePixmapData::paintEngine() const
}
return m_engine;
}
+
+#ifdef QT_BLITTER_RASTEROVERLAY
+
+static bool showRasterOverlay = !qgetenv("QT_BLITTER_RASTEROVERLAY").isEmpty();
+
+void QBlittablePixmapData::mergeOverlay()
+{
+ if (m_unmergedCopy || !showRasterOverlay)
+ return;
+ m_unmergedCopy = new QImage(buffer()->copy());
+ QPainter p(buffer());
+ p.setCompositionMode(QPainter::CompositionMode_SourceOver);
+ p.drawImage(0,0,*overlay());
+ p.end();
+}
+
+void QBlittablePixmapData::unmergeOverlay()
+{
+ if (!m_unmergedCopy || !showRasterOverlay)
+ return;
+ QPainter p(buffer());
+ p.setCompositionMode(QPainter::CompositionMode_Source);
+ p.drawImage(0,0,*m_unmergedCopy);
+ p.end();
+
+ delete m_unmergedCopy;
+ m_unmergedCopy = 0;
+}
+
+QImage *QBlittablePixmapData::overlay()
+{
+ if (!m_rasterOverlay||
+ m_rasterOverlay->size() != QSize(w,h)){
+ m_rasterOverlay = new QImage(w,h,QImage::Format_ARGB32_Premultiplied);
+ m_rasterOverlay->fill(0x00000000);
+ uint color = (qrand() % 11)+7;
+ m_overlayColor = QColor(Qt::GlobalColor(color));
+ m_overlayColor.setAlpha(0x88);
+
+ }
+ return m_rasterOverlay;
+}
+
+void QBlittablePixmapData::markRasterOverlayImpl(const QRectF &rect)
+{
+ if (!showRasterOverlay)
+ return;
+ QRectF transformationRect = clipAndTransformRect(rect);
+ if(!transformationRect.isEmpty()) {
+ QPainter p(overlay());
+ p.setBrush(m_overlayColor);
+ p.setCompositionMode(QPainter::CompositionMode_Source);
+ p.fillRect(transformationRect,QBrush(m_overlayColor));
+ }
+}
+
+void QBlittablePixmapData::unmarkRasterOverlayImpl(const QRectF &rect)
+{
+ if (!showRasterOverlay)
+ return;
+ QRectF transformationRect = clipAndTransformRect(rect);
+ if (!transformationRect.isEmpty()) {
+ QPainter p(overlay());
+ QColor color(0x00,0x00,0x00,0x00);
+ p.setBrush(color);
+ p.setCompositionMode(QPainter::CompositionMode_Source);
+ p.fillRect(transformationRect,QBrush(color));
+ }
+}
+
+QRectF QBlittablePixmapData::clipAndTransformRect(const QRectF &rect) const
+{
+ QRectF transformationRect = rect;
+ paintEngine();
+ if (m_engine->state()) {
+ transformationRect = m_engine->state()->matrix.mapRect(rect);
+ const QClipData *clipData = m_engine->clip();
+ if (clipData) {
+ if (clipData->hasRectClip) {
+ transformationRect &= clipData->clipRect;
+ } else if (clipData->hasRegionClip) {
+ const QVector<QRect> rects = clipData->clipRegion.rects();
+ for (int i = 0; i < rects.size(); i++) {
+ transformationRect &= rects.at(i);
+ }
+ }
+ }
+ }
+ return transformationRect;
+}
+#endif //QT_BLITTER_RASTEROVERLAY