From f2215f3ff2b6c9eff1e3c4922d5a3a00ababefd5 Mon Sep 17 00:00:00 2001 From: Ove Brynestad Date: Tue, 8 Jul 2014 09:22:08 +0200 Subject: [PATCH] qv4l2: update common size variables at GL resize Ongoing work to move aspect/crop/scale calculations from individual render classes to the common capture-win class. Currently different renderers use slightly different code to calculate the various cropping/scaling/etc. data. This makes it hard to maintain. Signed-off-by: Ove Brynestad Signed-off-by: Hans Verkuil --- utils/qv4l2/capture-win-gl.cpp | 25 ++++++++++++++----------- utils/qv4l2/capture-win-gl.h | 2 +- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/utils/qv4l2/capture-win-gl.cpp b/utils/qv4l2/capture-win-gl.cpp index 7644094..ed9d87f 100644 --- a/utils/qv4l2/capture-win-gl.cpp +++ b/utils/qv4l2/capture-win-gl.cpp @@ -46,22 +46,26 @@ void CaptureWinGL::stop() void CaptureWinGL::resizeEvent(QResizeEvent *event) { #ifdef HAVE_QTGL + // Get size of frame viewport. Can't use size of m_videoSurface + // since it is a subwidget of this widget. QSize margins = getMargins(); - QSize frame = QSize(width() - margins.width(), height() - margins.height()); - QSize sizedFrame = CaptureWin::scaleFrameSize(QSize(frame.width(), frame.height()), - QSize(m_frameInfo.frameWidth, - m_frameInfo.frameHeight)); - m_videoSurface.setSize(sizedFrame.width(), sizedFrame.height()); + m_curWinWidth = width() - margins.width(); + m_curWinHeight = height() - margins.height(); + // Re-calculate + CaptureWin::resizeScaleCrop(); + // Lock viewport size to follow calculated size + m_videoSurface.lockSize(m_scaledSize); #endif event->accept(); } void CaptureWinGL::setRenderFrame() { - // Force a recalculation by setting this to 0. - m_cropInfo.bytes = 0; +#ifdef HAVE_QTGL m_curWinWidth = m_videoSurface.width(); m_curWinHeight = m_videoSurface.height(); +#endif + // No recalculation is performed if all parameters are unchanged CaptureWin::resizeScaleCrop(); // Get/copy (TODO: remove CaptureWinGLEngine and use direct or use pointer) @@ -240,11 +244,10 @@ void CaptureWinGLEngine::initializeGL() checkError("InitializeGL"); } -void CaptureWinGLEngine::setSize(int width, int height) +void CaptureWinGLEngine::lockSize(QSize size) { -// TODO: This just locks the aspect ratio, does not limit max size. Why? - if (width > 0 && height > 0) { - setMaximumSize(width, height); + if ((size.width() > 0) && (size.height() > 0)) { + setFixedSize(size); } } diff --git a/utils/qv4l2/capture-win-gl.h b/utils/qv4l2/capture-win-gl.h index 043620c..38884bd 100644 --- a/utils/qv4l2/capture-win-gl.h +++ b/utils/qv4l2/capture-win-gl.h @@ -45,7 +45,7 @@ public: void setFrame(int width, int height, int cropWidth, int cropHeight, __u32 format, unsigned char *data, unsigned char *data2); bool hasNativeFormat(__u32 format); - void setSize(int width, int height); + void lockSize(QSize size); void setColorspace(unsigned colorspace); void setDisplayColorspace(unsigned colorspace); void setField(unsigned field); -- 2.7.4