qv4l2: update common size variables at GL resize
authorOve Brynestad <ovebryne@cisco.com>
Tue, 8 Jul 2014 07:22:08 +0000 (09:22 +0200)
committerHans Verkuil <hans.verkuil@cisco.com>
Fri, 11 Jul 2014 13:31:59 +0000 (15:31 +0200)
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 <ovebryne@cisco.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
utils/qv4l2/capture-win-gl.cpp
utils/qv4l2/capture-win-gl.h

index 7644094..ed9d87f 100644 (file)
@@ -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);
        }
 }
 
index 043620c..38884bd 100644 (file)
@@ -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);