qtmobility/src/multimedia/qgraphicsvideoitem.cpp
changeset 4 90517678cc4f
parent 1 2b40d63a9c3d
child 5 453da2cfceef
equal deleted inserted replaced
1:2b40d63a9c3d 4:90517678cc4f
    37 **
    37 **
    38 ** $QT_END_LICENSE$
    38 ** $QT_END_LICENSE$
    39 **
    39 **
    40 ****************************************************************************/
    40 ****************************************************************************/
    41 
    41 
    42 #include <qgraphicsvideoitem.h>
    42 #include "qgraphicsvideoitem.h"
    43 
    43 
    44 #include <qmediaobject.h>
    44 #include "qmediaobject.h"
    45 #include <qmediaservice.h>
    45 #include "qmediaservice.h"
    46 #include <qpaintervideosurface_p.h>
    46 #include "qpaintervideosurface_p.h"
    47 #include <qvideooutputcontrol.h>
    47 #include "qvideooutputcontrol.h"
    48 #include <qvideorenderercontrol.h>
    48 #include "qvideorenderercontrol.h"
       
    49 
       
    50 #include <QtCore/qcoreevent.h>
    49 
    51 
    50 #include <QtMultimedia/qvideosurfaceformat.h>
    52 #include <QtMultimedia/qvideosurfaceformat.h>
    51 //#include <QtOpenGL/qgl.h>
    53 
    52 //#define QGRAPHICSVIDEOITEM_SHADERS
    54 #if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1)
       
    55 #include <QtOpenGL/qgl.h>
       
    56 #endif
    53 
    57 
    54 QTM_BEGIN_NAMESPACE
    58 QTM_BEGIN_NAMESPACE
    55 
    59 
    56 class QGraphicsVideoItemPrivate
    60 class QGraphicsVideoItemPrivate
    57 {
    61 {
   202 
   206 
   203     \sa QMediaObject, QMediaPlayer, QVideoWidget
   207     \sa QMediaObject, QMediaPlayer, QVideoWidget
   204 */
   208 */
   205 
   209 
   206 /*!
   210 /*!
   207     \enum QGraphicsVideoItem::FillMode
       
   208 
       
   209     Enumerates the methods of scaling a video to fit a graphics item.
       
   210 
       
   211     \value Stretch The video is stretched to fit the item's size.
       
   212     \value PreserveAspectFit The video is uniformly scaled to fix the item's
       
   213     size without cropping.
       
   214     \value PreserveAspectCrop The video is uniformly scaled to fill the item's
       
   215     size, cropping if necessary.
       
   216 */
       
   217 
       
   218 /*!
       
   219     Constructs a graphics item that displays video.
   211     Constructs a graphics item that displays video.
   220 
   212 
   221     The \a parent is passed to QGraphicsItem.
   213     The \a parent is passed to QGraphicsItem.
   222 */
   214 */
   223 QGraphicsVideoItem::QGraphicsVideoItem(QGraphicsItem *parent)
   215 QGraphicsVideoItem::QGraphicsVideoItem(QGraphicsItem *parent)
   280         connect(d->mediaObject, SIGNAL(destroyed()), this, SLOT(_q_mediaObjectDestroyed()));
   272         connect(d->mediaObject, SIGNAL(destroyed()), this, SLOT(_q_mediaObjectDestroyed()));
   281 
   273 
   282         d->service = d->mediaObject->service();
   274         d->service = d->mediaObject->service();
   283 
   275 
   284         if (d->service) {
   276         if (d->service) {
   285             connect(d->service, SIGNAL(destroyed()), this, SLOT(_q_serviceDestroyed()));            
   277             connect(d->service, SIGNAL(destroyed()), this, SLOT(_q_serviceDestroyed()));
   286 
   278 
   287             d->outputControl = qobject_cast<QVideoOutputControl *>(
   279             d->outputControl = qobject_cast<QVideoOutputControl *>(
   288                     d->service->control(QVideoOutputControl_iid));
   280                     d->service->control(QVideoOutputControl_iid));
   289             d->rendererControl = qobject_cast<QVideoRendererControl *>(
   281             d->rendererControl = qobject_cast<QVideoRendererControl *>(
   290                     d->service->control(QVideoRendererControl_iid));
   282                     d->service->control(QVideoRendererControl_iid));
   395     Q_UNUSED(widget);
   387     Q_UNUSED(widget);
   396 
   388 
   397     if (d->surface && d->surface->isActive()) {
   389     if (d->surface && d->surface->isActive()) {
   398         d->surface->paint(painter, d->boundingRect, d->sourceRect);
   390         d->surface->paint(painter, d->boundingRect, d->sourceRect);
   399         d->surface->setReady(true);
   391         d->surface->setReady(true);
   400 #ifndef QGRAPHICSVIDEOITEM_SHADERS    // Flickers
   392 #if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1)
   401     }
       
   402 #else
       
   403     } else if (d->updatePaintDevice && (painter->paintEngine()->type() == QPaintEngine::OpenGL
   393     } else if (d->updatePaintDevice && (painter->paintEngine()->type() == QPaintEngine::OpenGL
   404             || painter->paintEngine()->type() == QPaintEngine::OpenGL2)) {
   394             || painter->paintEngine()->type() == QPaintEngine::OpenGL2)) {
   405         d->updatePaintDevice = false;
   395         d->updatePaintDevice = false;
   406 
   396 
   407         d->surface->setGLContext(const_cast<QGLContext *>(QGLContext::currentContext()));
   397         d->surface->setGLContext(const_cast<QGLContext *>(QGLContext::currentContext()));
   408         if (d->surface->supportedShaderTypes() & QPainterVideoSurface::GlslShader) {
   398         if (d->surface->supportedShaderTypes() & QPainterVideoSurface::GlslShader) {
   409             d->surface->setShaderType(QPainterVideoSurface::GlslShader);
   399             d->surface->setShaderType(QPainterVideoSurface::GlslShader);
   410         } else {
   400         } else {
   411             d->surface->setShaderType(QPainterVideoSurface::FragmentProgramShader);
   401             d->surface->setShaderType(QPainterVideoSurface::FragmentProgramShader);
   412         }
   402         }
   413     }
       
   414 #endif
   403 #endif
       
   404     }
   415 }
   405 }
   416 
   406 
   417 /*!
   407 /*!
   418     \reimp
   408     \reimp
   419 
   409 
   420     \internal
   410     \internal
   421 */
   411 */
   422 QVariant QGraphicsVideoItem::itemChange(GraphicsItemChange change, const QVariant &value)
   412 QVariant QGraphicsVideoItem::itemChange(GraphicsItemChange change, const QVariant &value)
   423 {
   413 {
   424     Q_D(QGraphicsVideoItem);
   414     return QGraphicsItem::itemChange(change, value);
   425 
   415 }
   426     if (change == ItemVisibleChange && d->outputControl != 0 && d->rendererControl != 0) {
   416 
   427         if (value.toBool()) {
   417 void QGraphicsVideoItem::timerEvent(QTimerEvent *event)
   428             d->outputControl->setOutput(QVideoOutputControl::RendererOutput);
   418 {
   429 
   419     QGraphicsObject::timerEvent(event);
   430             return d->outputControl->output() == QVideoOutputControl::RendererOutput;
       
   431         } else {
       
   432             d->outputControl->setOutput(QVideoOutputControl::NoOutput);
       
   433 
       
   434             return value;
       
   435         }
       
   436     } else {
       
   437         return QGraphicsItem::itemChange(change, value);
       
   438     }
       
   439 }
   420 }
   440 
   421 
   441 #include "moc_qgraphicsvideoitem.cpp"
   422 #include "moc_qgraphicsvideoitem.cpp"
   442 QTM_END_NAMESPACE
   423 QTM_END_NAMESPACE