qtmobility/src/multimedia/qpaintervideosurface.cpp
changeset 14 6fbed849b4f4
parent 11 06b8e2af4411
--- a/qtmobility/src/multimedia/qpaintervideosurface.cpp	Fri Jun 11 14:26:25 2010 +0300
+++ b/qtmobility/src/multimedia/qpaintervideosurface.cpp	Wed Jun 23 19:08:38 2010 +0300
@@ -39,13 +39,14 @@
 **
 ****************************************************************************/
 
-#include "qpaintervideosurface_p.h"
+#include <qpaintervideosurface_p.h>
+#include <qpaintervideosurface_mac_p.h>
 
 #include <qmath.h>
 
 #include <qpainter.h>
 #include <qvariant.h>
-#include <QtMultimedia/qvideosurfaceformat.h>
+#include <qvideosurfaceformat.h>
 
 #if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1)
 #include <qglshaderprogram.h>
@@ -54,28 +55,6 @@
 #include <QtDebug>
 QT_BEGIN_NAMESPACE
 
-class QVideoSurfacePainter
-{
-public:
-    virtual ~QVideoSurfacePainter();
-
-    virtual QList<QVideoFrame::PixelFormat> supportedPixelFormats(
-            QAbstractVideoBuffer::HandleType handleType) const = 0;
-
-    virtual bool isFormatSupported(
-            const QVideoSurfaceFormat &format, QVideoSurfaceFormat *similar) const = 0;
-
-    virtual QAbstractVideoSurface::Error start(const QVideoSurfaceFormat &format) = 0;
-    virtual void stop() = 0;
-
-    virtual QAbstractVideoSurface::Error setCurrentFrame(const QVideoFrame &frame) = 0;
-
-    virtual QAbstractVideoSurface::Error paint(
-            const QRectF &target, QPainter *painter, const QRectF &source) = 0;
-
-    virtual void updateColors(int brightness, int contrast, int hue, int saturation) = 0;
-};
-
 QVideoSurfacePainter::~QVideoSurfacePainter()
 {
 }
@@ -750,10 +729,15 @@
         const QRectF &target, QPainter *painter, const QRectF &source)
 {
     if (m_frame.isValid()) {
+        bool stencilTestEnabled = glIsEnabled(GL_STENCIL_TEST);
+        bool scissorTestEnabled = glIsEnabled(GL_SCISSOR_TEST);
+
         painter->beginNativePainting();
 
-        glEnable(GL_STENCIL_TEST);
-        glEnable(GL_SCISSOR_TEST);
+        if (stencilTestEnabled)
+            glEnable(GL_STENCIL_TEST);
+        if (scissorTestEnabled)
+            glEnable(GL_SCISSOR_TEST);
 
         const float txLeft = source.left() / m_frameSize.width();
         const float txRight = source.right() / m_frameSize.width();
@@ -835,9 +819,6 @@
         glDisableClientState(GL_VERTEX_ARRAY);
         glDisable(GL_FRAGMENT_PROGRAM_ARB);
 
-        glDisable(GL_STENCIL_TEST);
-        glDisable(GL_SCISSOR_TEST);
-
         painter->endNativePainting();
     }
     return QAbstractVideoSurface::NoError;
@@ -1083,10 +1064,15 @@
         const QRectF &target, QPainter *painter, const QRectF &source)
 {
     if (m_frame.isValid()) {
+        bool stencilTestEnabled = glIsEnabled(GL_STENCIL_TEST);
+        bool scissorTestEnabled = glIsEnabled(GL_SCISSOR_TEST);
+
         painter->beginNativePainting();
 
-        glEnable(GL_STENCIL_TEST);
-        glEnable(GL_SCISSOR_TEST);
+        if (stencilTestEnabled)
+            glEnable(GL_STENCIL_TEST);
+        if (scissorTestEnabled)
+            glEnable(GL_SCISSOR_TEST);
 
         const int width = QGLContext::currentContext()->device()->width();
         const int height = QGLContext::currentContext()->device()->height();
@@ -1186,9 +1172,6 @@
 
         m_program.release();
 
-
-        glDisable(GL_SCISSOR_TEST);
-        glDisable(GL_STENCIL_TEST);
         painter->endNativePainting();
     }
     return QAbstractVideoSurface::NoError;
@@ -1551,6 +1534,14 @@
 {
     Q_ASSERT(!m_painter);
 
+#ifdef Q_WS_MAC
+    if (m_glContext)
+        m_glContext->makeCurrent();
+
+    m_painter = new QVideoSurfaceCoreGraphicsPainter(m_glContext != 0);
+    return;
+#endif
+
 #if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1)
     switch (m_shaderType) {
 #ifndef QT_OPENGL_ES