qtmobility/plugins/multimedia/qt7/qt7movievideowidget.mm
changeset 14 6fbed849b4f4
parent 11 06b8e2af4411
equal deleted inserted replaced
11:06b8e2af4411 14:6fbed849b4f4
    78         setAutoFillBackground(false);        
    78         setAutoFillBackground(false);        
    79     }
    79     }
    80 
    80 
    81     void initializeGL()
    81     void initializeGL()
    82     {
    82     {
    83         glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    83         QColor bgColor = palette().color(QPalette::Background);
       
    84         glClearColor(bgColor.redF(), bgColor.greenF(), bgColor.blueF(), bgColor.alphaF());
    84     }
    85     }
    85 
    86 
    86     void resizeGL(int w, int h)
    87     void resizeGL(int w, int h)
    87     {
    88     {
    88         glMatrixMode(GL_MODELVIEW);
    89         glMatrixMode(GL_MODELVIEW);
   204     if (!createVisualContext()) {
   205     if (!createVisualContext()) {
   205         qWarning() << "QT7MovieVideoWidget: failed to create visual context";
   206         qWarning() << "QT7MovieVideoWidget: failed to create visual context";
   206     }
   207     }
   207 }
   208 }
   208 
   209 
   209 
       
   210 bool QT7MovieVideoWidget::createVisualContext()
   210 bool QT7MovieVideoWidget::createVisualContext()
   211 {
   211 {
   212 #ifdef QUICKTIME_C_API_AVAILABLE
   212 #ifdef QUICKTIME_C_API_AVAILABLE
   213     m_videoWidget->makeCurrent();
   213     m_videoWidget->makeCurrent();
   214 
   214 
   216     CGLContextObj cglContext = CGLGetCurrentContext();
   216     CGLContextObj cglContext = CGLGetCurrentContext();
   217     NSOpenGLPixelFormat *nsglPixelFormat = [NSOpenGLView defaultPixelFormat];
   217     NSOpenGLPixelFormat *nsglPixelFormat = [NSOpenGLView defaultPixelFormat];
   218     CGLPixelFormatObj cglPixelFormat = static_cast<CGLPixelFormatObj>([nsglPixelFormat CGLPixelFormatObj]);
   218     CGLPixelFormatObj cglPixelFormat = static_cast<CGLPixelFormatObj>([nsglPixelFormat CGLPixelFormatObj]);
   219 
   219 
   220     CFTypeRef keys[] = { kQTVisualContextOutputColorSpaceKey };
   220     CFTypeRef keys[] = { kQTVisualContextOutputColorSpaceKey };
   221     CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
   221     CGColorSpaceRef colorSpace = NULL;
       
   222     CMProfileRef sysprof = NULL;
       
   223 
       
   224     // Get the Systems Profile for the main display
       
   225     if (CMGetSystemProfile(&sysprof) == noErr) {
       
   226         // Create a colorspace with the systems profile
       
   227         colorSpace = CGColorSpaceCreateWithPlatformColorSpace(sysprof);
       
   228         CMCloseProfile(sysprof);
       
   229     }
       
   230 
       
   231     if (!colorSpace)
       
   232         colorSpace = CGColorSpaceCreateDeviceRGB();
       
   233 
   222     CFDictionaryRef textureContextAttributes = CFDictionaryCreate(kCFAllocatorDefault,
   234     CFDictionaryRef textureContextAttributes = CFDictionaryCreate(kCFAllocatorDefault,
   223                                                                   (const void **)keys,
   235                                                                   (const void **)keys,
   224                                                                   (const void **)&colorSpace, 1,
   236                                                                   (const void **)&colorSpace, 1,
   225                                                                   &kCFTypeDictionaryKeyCallBacks,
   237                                                                   &kCFTypeDictionaryKeyCallBacks,
   226                                                                   &kCFTypeDictionaryValueCallBacks);
   238                                                                   &kCFTypeDictionaryValueCallBacks);
   261     if (m_movie == 0) {
   273     if (m_movie == 0) {
   262         m_displayLink->stop();
   274         m_displayLink->stop();
   263         return;
   275         return;
   264     }
   276     }
   265 
   277 
   266     NSSize size = [[(QTMovie*)m_movie attributeForKey:@"QTMovieCurrentSizeAttribute"] sizeValue];
   278     NSSize size = [[(QTMovie*)m_movie attributeForKey:@"QTMovieNaturalSizeAttribute"] sizeValue];
   267     m_nativeSize = QSize(size.width, size.height);
   279     m_nativeSize = QSize(size.width, size.height);
   268     m_videoWidget->setNativeSize(m_nativeSize);
   280     m_videoWidget->setNativeSize(m_nativeSize);
   269 
   281 
   270 #ifdef QUICKTIME_C_API_AVAILABLE
   282 #ifdef QUICKTIME_C_API_AVAILABLE
   271     // targets a Movie to render into a visual context
   283     // targets a Movie to render into a visual context
   272     SetMovieVisualContext([(QTMovie*)m_movie quickTimeMovie], m_visualContext);
   284     SetMovieVisualContext([(QTMovie*)m_movie quickTimeMovie], m_visualContext);
   273 #endif
   285 #endif
   274 
   286 
   275     m_displayLink->start();
   287     m_displayLink->start();
   276 }
       
   277 
       
   278 void QT7MovieVideoWidget::setEnabled(bool)
       
   279 {
       
   280 }
   288 }
   281 
   289 
   282 void QT7MovieVideoWidget::setMovie(void *movie)
   290 void QT7MovieVideoWidget::setMovie(void *movie)
   283 {
   291 {
   284     if (m_movie == movie)
   292     if (m_movie == movie)
   293 
   301 
   294     m_movie = movie;
   302     m_movie = movie;
   295     [(QTMovie*)m_movie retain];
   303     [(QTMovie*)m_movie retain];
   296 
   304 
   297     setupVideoOutput();
   305     setupVideoOutput();
       
   306 }
       
   307 
       
   308 void QT7MovieVideoWidget::updateNaturalSize(const QSize &newSize)
       
   309 {
       
   310     if (m_nativeSize != newSize) {
       
   311         m_nativeSize = newSize;
       
   312         setupVideoOutput();
       
   313     }
   298 }
   314 }
   299 
   315 
   300 bool QT7MovieVideoWidget::isFullScreen() const
   316 bool QT7MovieVideoWidget::isFullScreen() const
   301 {
   317 {
   302     return m_fullscreen;
   318     return m_fullscreen;