summaryrefslogtreecommitdiffstats
path: root/src/multimedia
diff options
context:
space:
mode:
authorAndrew den Exter <andrew.den-exter@nokia.com>2010-02-03 01:01:11 (GMT)
committerAndrew den Exter <andrew.den-exter@nokia.com>2010-02-03 01:01:11 (GMT)
commit5a43e96062f7bd82ff9deb57e065b757d784607d (patch)
treed1964633956dd1717bb21c554c3d30a7d560b63f /src/multimedia
parent396d731af30048e3b98be14a7b97e5ba682a86f8 (diff)
downloadQt-5a43e96062f7bd82ff9deb57e065b757d784607d.zip
Qt-5a43e96062f7bd82ff9deb57e065b757d784607d.tar.gz
Qt-5a43e96062f7bd82ff9deb57e065b757d784607d.tar.bz2
Clip the paint region of QGraphicsVideoItem to it's bounding rect.
Diffstat (limited to 'src/multimedia')
-rw-r--r--src/multimedia/base/qgraphicsvideoitem.cpp50
-rw-r--r--src/multimedia/base/qpaintervideosurface.cpp54
-rw-r--r--src/multimedia/base/qpaintervideosurface_p.h2
3 files changed, 64 insertions, 42 deletions
diff --git a/src/multimedia/base/qgraphicsvideoitem.cpp b/src/multimedia/base/qgraphicsvideoitem.cpp
index 1a5ccd7..35baabe 100644
--- a/src/multimedia/base/qgraphicsvideoitem.cpp
+++ b/src/multimedia/base/qgraphicsvideoitem.cpp
@@ -64,6 +64,7 @@ public:
, rendererControl(0)
, aspectRatioMode(Qt::KeepAspectRatio)
, updatePaintDevice(true)
+ , rect(0.0, 0.0, 320, 240)
{
}
@@ -78,10 +79,11 @@ public:
bool updatePaintDevice;
QRectF rect;
QRectF boundingRect;
+ QRectF sourceRect;
QSizeF nativeSize;
void clearService();
- void updateBoundingRect();
+ void updateRects();
void _q_present();
void _q_formatChanged(const QVideoSurfaceFormat &format);
@@ -106,22 +108,32 @@ void QGraphicsVideoItemPrivate::clearService()
}
}
-void QGraphicsVideoItemPrivate::updateBoundingRect()
+void QGraphicsVideoItemPrivate::updateRects()
{
q_ptr->prepareGeometryChange();
if (nativeSize.isEmpty()) {
boundingRect = QRectF();
- } else {
- if (aspectRatioMode == Qt::IgnoreAspectRatio) {
- boundingRect = rect;
- } else {
- QSizeF size = nativeSize;
- size.scale(rect.size(), aspectRatioMode);
-
- boundingRect = QRectF(QPointF(), size);
- boundingRect.moveCenter(rect.center());
- }
+ } else if (aspectRatioMode == Qt::IgnoreAspectRatio) {
+ boundingRect = rect;
+ sourceRect = QRectF(0, 0, 1, 1);
+ } else if (aspectRatioMode == Qt::KeepAspectRatio) {
+ QSizeF size = nativeSize;
+ size.scale(rect.size(), Qt::KeepAspectRatio);
+
+ boundingRect = QRectF(0, 0, size.width(), size.height());
+ boundingRect.moveCenter(rect.center());
+
+ sourceRect = QRectF(0, 0, 1, 1);
+ } else if (aspectRatioMode == Qt::KeepAspectRatioByExpanding) {
+ boundingRect = rect;
+
+ QSizeF size = rect.size();
+ size.scale(nativeSize, Qt::KeepAspectRatio);
+
+ sourceRect = QRectF(
+ 0, 0, size.width() / nativeSize.width(), size.height() / nativeSize.height());
+ sourceRect.moveCenter(QPointF(0.5, 0.5));
}
}
@@ -139,7 +151,9 @@ void QGraphicsVideoItemPrivate::_q_formatChanged(const QVideoSurfaceFormat &form
{
nativeSize = format.sizeHint();
- updateBoundingRect();
+ updateRects();
+
+ emit q_ptr->nativeSizeChanged(nativeSize);
}
void QGraphicsVideoItemPrivate::_q_serviceDestroyed()
@@ -299,7 +313,7 @@ void QGraphicsVideoItem::setAspectRatioMode(Qt::AspectRatioMode mode)
Q_D(QGraphicsVideoItem);
d->aspectRatioMode = mode;
- d->updateBoundingRect();
+ d->updateRects();
}
/*!
@@ -320,7 +334,7 @@ void QGraphicsVideoItem::setOffset(const QPointF &offset)
Q_D(QGraphicsVideoItem);
d->rect.moveTo(offset);
- d->updateBoundingRect();
+ d->updateRects();
}
/*!
@@ -340,8 +354,8 @@ void QGraphicsVideoItem::setSize(const QSizeF &size)
{
Q_D(QGraphicsVideoItem);
- d->rect.setSize(size);
- d->updateBoundingRect();
+ d->rect.setSize(size.isValid() ? size : QSizeF(0, 0));
+ d->updateRects();
}
/*!
@@ -380,7 +394,7 @@ void QGraphicsVideoItem::paint(
Q_UNUSED(widget);
if (d->surface && d->surface->isActive()) {
- d->surface->paint(painter, d->boundingRect);
+ d->surface->paint(painter, d->boundingRect, d->sourceRect);
d->surface->setReady(true);
#ifndef QGRAPHICSVIDEOITEM_SHADERS // Flickers
}
diff --git a/src/multimedia/base/qpaintervideosurface.cpp b/src/multimedia/base/qpaintervideosurface.cpp
index 9953ae8..533ddee 100644
--- a/src/multimedia/base/qpaintervideosurface.cpp
+++ b/src/multimedia/base/qpaintervideosurface.cpp
@@ -73,7 +73,7 @@ public:
virtual QAbstractVideoSurface::Error setCurrentFrame(const QVideoFrame &frame) = 0;
virtual QAbstractVideoSurface::Error paint(
- const QRectF &target, QPainter *painter, const QRect &source) = 0;
+ const QRectF &target, QPainter *painter, const QRectF &source) = 0;
virtual void updateColors(int brightness, int contrast, int hue, int saturation) = 0;
};
@@ -99,7 +99,7 @@ public:
QAbstractVideoSurface::Error setCurrentFrame(const QVideoFrame &frame);
QAbstractVideoSurface::Error paint(
- const QRectF &target, QPainter *painter, const QRect &source);
+ const QRectF &target, QPainter *painter, const QRectF &source);
void updateColors(int brightness, int contrast, int hue, int saturation);
@@ -167,7 +167,7 @@ QAbstractVideoSurface::Error QVideoSurfaceRasterPainter::setCurrentFrame(const Q
}
QAbstractVideoSurface::Error QVideoSurfaceRasterPainter::paint(
- const QRectF &target, QPainter *painter, const QRect &source)
+ const QRectF &target, QPainter *painter, const QRectF &source)
{
if (m_frame.map(QAbstractVideoBuffer::ReadOnly)) {
QImage image(
@@ -183,7 +183,7 @@ QAbstractVideoSurface::Error QVideoSurfaceRasterPainter::paint(
painter->scale(1, -1);
painter->translate(0, -target.bottom());
painter->drawImage(
- QRect(target.x(), 0, target.width(), target.height()), image, source);
+ QRectF(target.x(), 0, target.width(), target.height()), image, source);
painter->setTransform(oldTransform);
} else {
painter->drawImage(target, image, source);
@@ -540,7 +540,8 @@ public:
QAbstractVideoSurface::Error start(const QVideoSurfaceFormat &format);
void stop();
- QAbstractVideoSurface::Error paint(const QRectF &target, QPainter *painter, const QRect &source);
+ QAbstractVideoSurface::Error paint(
+ const QRectF &target, QPainter *painter, const QRectF &source);
private:
typedef void (APIENTRY *_glProgramStringARB) (GLenum, GLenum, GLsizei, const GLvoid *);
@@ -700,19 +701,19 @@ void QVideoSurfaceArbFpPainter::stop()
}
QAbstractVideoSurface::Error QVideoSurfaceArbFpPainter::paint(
- const QRectF &target, QPainter *painter, const QRect &source)
+ const QRectF &target, QPainter *painter, const QRectF &source)
{
if (m_frame.isValid()) {
painter->beginNativePainting();
- const float txLeft = float(source.left()) / float(m_frameSize.width());
- const float txRight = float(source.right()) / float(m_frameSize.width());
+ const float txLeft = source.left() / m_frameSize.width();
+ const float txRight = source.right() / m_frameSize.width();
const float txTop = m_scanLineDirection == QVideoSurfaceFormat::TopToBottom
- ? float(source.top()) / float(m_frameSize.height())
- : float(source.bottom()) / float(m_frameSize.height());
+ ? source.top() / m_frameSize.height()
+ : source.bottom() / m_frameSize.height();
const float txBottom = m_scanLineDirection == QVideoSurfaceFormat::TopToBottom
- ? float(source.bottom()) / float(m_frameSize.height())
- : float(source.top()) / float(m_frameSize.height());
+ ? source.bottom() / m_frameSize.height()
+ : source.top() / m_frameSize.height();
const float tx_array[] =
@@ -857,7 +858,8 @@ public:
QAbstractVideoSurface::Error start(const QVideoSurfaceFormat &format);
void stop();
- QAbstractVideoSurface::Error paint(const QRectF &target, QPainter *painter, const QRect &source);
+ QAbstractVideoSurface::Error paint(
+ const QRectF &target, QPainter *painter, const QRectF &source);
private:
QGLShaderProgram m_program;
@@ -975,7 +977,7 @@ void QVideoSurfaceGlslPainter::stop()
}
QAbstractVideoSurface::Error QVideoSurfaceGlslPainter::paint(
- const QRectF &target, QPainter *painter, const QRect &source)
+ const QRectF &target, QPainter *painter, const QRectF &source)
{
if (m_frame.isValid()) {
painter->beginNativePainting();
@@ -1021,14 +1023,14 @@ QAbstractVideoSurface::Error QVideoSurfaceGlslPainter::paint(
target.right() + 1, target.top()
};
- const GLfloat txLeft = float(source.left()) / float(m_frameSize.width());
- const GLfloat txRight = float(source.right()) / float(m_frameSize.width());
+ const GLfloat txLeft = source.left() / m_frameSize.width();
+ const GLfloat txRight = source.right() / m_frameSize.width();
const GLfloat txTop = m_scanLineDirection == QVideoSurfaceFormat::TopToBottom
- ? float(source.top()) / float(m_frameSize.height())
- : float(source.bottom()) / float(m_frameSize.height());
+ ? source.top() / m_frameSize.height()
+ : source.bottom() / m_frameSize.height();
const GLfloat txBottom = m_scanLineDirection == QVideoSurfaceFormat::TopToBottom
- ? float(source.bottom()) / float(m_frameSize.height())
- : float(source.top()) / float(m_frameSize.height());
+ ? source.bottom() / m_frameSize.height()
+ : source.top() / m_frameSize.height();
const GLfloat textureCoordArray[] =
{
@@ -1289,17 +1291,23 @@ void QPainterVideoSurface::setReady(bool ready)
/*!
*/
-void QPainterVideoSurface::paint(QPainter *painter, const QRectF &rect)
+void QPainterVideoSurface::paint(QPainter *painter, const QRectF &target, const QRectF &source)
{
if (!isActive()) {
- painter->fillRect(rect, QBrush(Qt::black));
+ painter->fillRect(target, QBrush(Qt::black));
} else {
if (m_colorsDirty) {
m_painter->updateColors(m_brightness, m_contrast, m_hue, m_saturation);
m_colorsDirty = false;
}
- QAbstractVideoSurface::Error error = m_painter->paint(rect, painter, m_sourceRect);
+ const QRectF sourceRect(
+ m_sourceRect.x() + m_sourceRect.width() * source.x(),
+ m_sourceRect.y() + m_sourceRect.height() * source.y(),
+ m_sourceRect.width() * source.width(),
+ m_sourceRect.height() * source.height());
+
+ QAbstractVideoSurface::Error error = m_painter->paint(target, painter, sourceRect);
if (error != QAbstractVideoSurface::NoError) {
setError(error);
diff --git a/src/multimedia/base/qpaintervideosurface_p.h b/src/multimedia/base/qpaintervideosurface_p.h
index 5340956..d4b6740 100644
--- a/src/multimedia/base/qpaintervideosurface_p.h
+++ b/src/multimedia/base/qpaintervideosurface_p.h
@@ -102,7 +102,7 @@ public:
bool isReady() const;
void setReady(bool ready);
- void paint(QPainter *painter, const QRectF &rect);
+ void paint(QPainter *painter, const QRectF &target, const QRectF &source = QRectF(0, 0, 1, 1));
#if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1)
const QGLContext *glContext() const;