qtmobility/src/multimedia/qpaintervideosurface.cpp
changeset 14 6fbed849b4f4
parent 11 06b8e2af4411
equal deleted inserted replaced
11:06b8e2af4411 14:6fbed849b4f4
    37 **
    37 **
    38 ** $QT_END_LICENSE$
    38 ** $QT_END_LICENSE$
    39 **
    39 **
    40 ****************************************************************************/
    40 ****************************************************************************/
    41 
    41 
    42 #include "qpaintervideosurface_p.h"
    42 #include <qpaintervideosurface_p.h>
       
    43 #include <qpaintervideosurface_mac_p.h>
    43 
    44 
    44 #include <qmath.h>
    45 #include <qmath.h>
    45 
    46 
    46 #include <qpainter.h>
    47 #include <qpainter.h>
    47 #include <qvariant.h>
    48 #include <qvariant.h>
    48 #include <QtMultimedia/qvideosurfaceformat.h>
    49 #include <qvideosurfaceformat.h>
    49 
    50 
    50 #if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1)
    51 #if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1)
    51 #include <qglshaderprogram.h>
    52 #include <qglshaderprogram.h>
    52 #endif
    53 #endif
    53 
    54 
    54 #include <QtDebug>
    55 #include <QtDebug>
    55 QT_BEGIN_NAMESPACE
    56 QT_BEGIN_NAMESPACE
    56 
       
    57 class QVideoSurfacePainter
       
    58 {
       
    59 public:
       
    60     virtual ~QVideoSurfacePainter();
       
    61 
       
    62     virtual QList<QVideoFrame::PixelFormat> supportedPixelFormats(
       
    63             QAbstractVideoBuffer::HandleType handleType) const = 0;
       
    64 
       
    65     virtual bool isFormatSupported(
       
    66             const QVideoSurfaceFormat &format, QVideoSurfaceFormat *similar) const = 0;
       
    67 
       
    68     virtual QAbstractVideoSurface::Error start(const QVideoSurfaceFormat &format) = 0;
       
    69     virtual void stop() = 0;
       
    70 
       
    71     virtual QAbstractVideoSurface::Error setCurrentFrame(const QVideoFrame &frame) = 0;
       
    72 
       
    73     virtual QAbstractVideoSurface::Error paint(
       
    74             const QRectF &target, QPainter *painter, const QRectF &source) = 0;
       
    75 
       
    76     virtual void updateColors(int brightness, int contrast, int hue, int saturation) = 0;
       
    77 };
       
    78 
    57 
    79 QVideoSurfacePainter::~QVideoSurfacePainter()
    58 QVideoSurfacePainter::~QVideoSurfacePainter()
    80 {
    59 {
    81 }
    60 }
    82 
    61 
   748 
   727 
   749 QAbstractVideoSurface::Error QVideoSurfaceArbFpPainter::paint(
   728 QAbstractVideoSurface::Error QVideoSurfaceArbFpPainter::paint(
   750         const QRectF &target, QPainter *painter, const QRectF &source)
   729         const QRectF &target, QPainter *painter, const QRectF &source)
   751 {
   730 {
   752     if (m_frame.isValid()) {
   731     if (m_frame.isValid()) {
       
   732         bool stencilTestEnabled = glIsEnabled(GL_STENCIL_TEST);
       
   733         bool scissorTestEnabled = glIsEnabled(GL_SCISSOR_TEST);
       
   734 
   753         painter->beginNativePainting();
   735         painter->beginNativePainting();
   754 
   736 
   755         glEnable(GL_STENCIL_TEST);
   737         if (stencilTestEnabled)
   756         glEnable(GL_SCISSOR_TEST);
   738             glEnable(GL_STENCIL_TEST);
       
   739         if (scissorTestEnabled)
       
   740             glEnable(GL_SCISSOR_TEST);
   757 
   741 
   758         const float txLeft = source.left() / m_frameSize.width();
   742         const float txLeft = source.left() / m_frameSize.width();
   759         const float txRight = source.right() / m_frameSize.width();
   743         const float txRight = source.right() / m_frameSize.width();
   760         const float txTop = m_scanLineDirection == QVideoSurfaceFormat::TopToBottom
   744         const float txTop = m_scanLineDirection == QVideoSurfaceFormat::TopToBottom
   761                 ? source.top() / m_frameSize.height()
   745                 ? source.top() / m_frameSize.height()
   833 
   817 
   834         glDisableClientState(GL_TEXTURE_COORD_ARRAY);
   818         glDisableClientState(GL_TEXTURE_COORD_ARRAY);
   835         glDisableClientState(GL_VERTEX_ARRAY);
   819         glDisableClientState(GL_VERTEX_ARRAY);
   836         glDisable(GL_FRAGMENT_PROGRAM_ARB);
   820         glDisable(GL_FRAGMENT_PROGRAM_ARB);
   837 
   821 
   838         glDisable(GL_STENCIL_TEST);
       
   839         glDisable(GL_SCISSOR_TEST);
       
   840 
       
   841         painter->endNativePainting();
   822         painter->endNativePainting();
   842     }
   823     }
   843     return QAbstractVideoSurface::NoError;
   824     return QAbstractVideoSurface::NoError;
   844 }
   825 }
   845 
   826 
  1081 
  1062 
  1082 QAbstractVideoSurface::Error QVideoSurfaceGlslPainter::paint(
  1063 QAbstractVideoSurface::Error QVideoSurfaceGlslPainter::paint(
  1083         const QRectF &target, QPainter *painter, const QRectF &source)
  1064         const QRectF &target, QPainter *painter, const QRectF &source)
  1084 {
  1065 {
  1085     if (m_frame.isValid()) {
  1066     if (m_frame.isValid()) {
       
  1067         bool stencilTestEnabled = glIsEnabled(GL_STENCIL_TEST);
       
  1068         bool scissorTestEnabled = glIsEnabled(GL_SCISSOR_TEST);
       
  1069 
  1086         painter->beginNativePainting();
  1070         painter->beginNativePainting();
  1087 
  1071 
  1088         glEnable(GL_STENCIL_TEST);
  1072         if (stencilTestEnabled)
  1089         glEnable(GL_SCISSOR_TEST);
  1073             glEnable(GL_STENCIL_TEST);
       
  1074         if (scissorTestEnabled)
       
  1075             glEnable(GL_SCISSOR_TEST);
  1090 
  1076 
  1091         const int width = QGLContext::currentContext()->device()->width();
  1077         const int width = QGLContext::currentContext()->device()->width();
  1092         const int height = QGLContext::currentContext()->device()->height();
  1078         const int height = QGLContext::currentContext()->device()->height();
  1093 
  1079 
  1094         const QTransform transform = painter->deviceTransform();
  1080         const QTransform transform = painter->deviceTransform();
  1184 
  1170 
  1185         glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
  1171         glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
  1186 
  1172 
  1187         m_program.release();
  1173         m_program.release();
  1188 
  1174 
  1189 
       
  1190         glDisable(GL_SCISSOR_TEST);
       
  1191         glDisable(GL_STENCIL_TEST);
       
  1192         painter->endNativePainting();
  1175         painter->endNativePainting();
  1193     }
  1176     }
  1194     return QAbstractVideoSurface::NoError;
  1177     return QAbstractVideoSurface::NoError;
  1195 }
  1178 }
  1196 
  1179 
  1549 
  1532 
  1550 void QPainterVideoSurface::createPainter()
  1533 void QPainterVideoSurface::createPainter()
  1551 {
  1534 {
  1552     Q_ASSERT(!m_painter);
  1535     Q_ASSERT(!m_painter);
  1553 
  1536 
       
  1537 #ifdef Q_WS_MAC
       
  1538     if (m_glContext)
       
  1539         m_glContext->makeCurrent();
       
  1540 
       
  1541     m_painter = new QVideoSurfaceCoreGraphicsPainter(m_glContext != 0);
       
  1542     return;
       
  1543 #endif
       
  1544 
  1554 #if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1)
  1545 #if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1)
  1555     switch (m_shaderType) {
  1546     switch (m_shaderType) {
  1556 #ifndef QT_OPENGL_ES
  1547 #ifndef QT_OPENGL_ES
  1557     case FragmentProgramShader:
  1548     case FragmentProgramShader:
  1558         Q_ASSERT(m_glContext);
  1549         Q_ASSERT(m_glContext);