Skip to content

Commit

Permalink
qml: compute display rect correctly and less times
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Apr 25, 2014
1 parent 27db52a commit d757ff6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
32 changes: 19 additions & 13 deletions qml/QQuickItemRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ bool QQuickItemRenderer::isSupported(VideoFormat::PixelFormat pixfmt) const
return VideoFormat::isRGB(pixfmt);
}

void QQuickItemRenderer::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
{
Q_UNUSED(oldGeometry);
DPTR_D(QQuickItemRenderer);
resizeRenderer(newGeometry.size().toSize());
if (d.fill_mode == PreserveAspectCrop) {
QSizeF scaled = d.out_rect.size();
scaled.scale(boundingRect().size(), Qt::KeepAspectRatioByExpanding);
d.out_rect = QRect(QPoint(), scaled.toSize());
d.out_rect.moveCenter(boundingRect().center().toPoint());
}
}

bool QQuickItemRenderer::receiveFrame(const VideoFrame &frame)
{
DPTR_D(QQuickItemRenderer);
Expand Down Expand Up @@ -96,6 +109,11 @@ void QQuickItemRenderer::setFillMode(FillMode mode)
if (d.fill_mode == mode)
return;
d_func().fill_mode = mode;
if (d.fill_mode == Stretch) {
setOutAspectRatioMode(RendererAspectRatio);
} else {//compute out_rect fits video aspect ratio then compute again if crop
setOutAspectRatioMode(VideoAspectRatio);
}
//m_geometryDirty = true;
//update();
emit fillModeChanged(mode);
Expand All @@ -121,19 +139,7 @@ void QQuickItemRenderer::drawFrame()
d.image = QImage(rendererSize(), QImage::Format_RGB32);
d.image.fill(Qt::black);
}
if (d.fill_mode == Stretch) {
static_cast<QSGSimpleTextureNode*>(d.node)->setRect(boundingRect());
} else if (d.fill_mode == PreserveAspectFit || d.fill_mode == PreserveAspectCrop) {
//TODO: optimize by updating content rect only when fill mode changed
QSizeF scaled = d.out_rect.size();
scaled.scale(boundingRect().size(), d.fill_mode == PreserveAspectFit ?
Qt::KeepAspectRatio : Qt::KeepAspectRatioByExpanding);
QRectF rect(QPointF(), scaled);
rect.moveCenter(boundingRect().center());
//d.out_rect = rect;
//rect &= boundingRect(); //FIXME: why QtMultiMedia does not have it?
static_cast<QSGSimpleTextureNode*>(d.node)->setRect(rect);
}
static_cast<QSGSimpleTextureNode*>(d.node)->setRect(d.out_rect);

if (d.texture)
delete d.texture;
Expand Down
2 changes: 2 additions & 0 deletions qml/QmlAV/QQuickItemRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class QMLAV_EXPORT QQuickItemRenderer : public QQuickItem, public VideoRenderer
void regionOfInterestChanged();

protected:
virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);

virtual bool receiveFrame(const VideoFrame &frame);
virtual bool needUpdateBackground() const;
virtual bool needDrawFrame() const;
Expand Down

0 comments on commit d757ff6

Please sign in to comment.