src/opengl/qgl_mac.mm
changeset 37 758a864f9613
parent 18 2f34d5167611
equal deleted inserted replaced
36:ef0373b55136 37:758a864f9613
   695     if (d->paintDevice->devType() == QInternal::Widget) {
   695     if (d->paintDevice->devType() == QInternal::Widget) {
   696         //get control information
   696         //get control information
   697         QWidget *w = (QWidget *)d->paintDevice;
   697         QWidget *w = (QWidget *)d->paintDevice;
   698         NSView *view = qt_mac_nativeview_for(w);
   698         NSView *view = qt_mac_nativeview_for(w);
   699 
   699 
   700         // ideally we would use QWidget::isVisible(), but we get "invalid drawable" errors
   700         // Trying to attach the GL context to the NSView will fail with
   701         if (![(NSWindow *)qt_mac_window_for(w) isVisible])
   701         // "invalid drawable" if done too soon, but we have to make sure
   702             return;
   702         // the connection is made before the first paint event. Using
       
   703         // the NSView do to this check fails as the NSView is visible
       
   704         // before it's safe to connect, and using the NSWindow fails as
       
   705         // the NSWindow will become visible after the first paint event.
       
   706         // This leaves us with the QWidget, who's visible state seems
       
   707         // to match the point in time when it's safe to connect.
       
   708         if (!w || !w->isVisible())
       
   709             return; // Not safe to attach GL context to view yet
       
   710 
   703         if ([static_cast<NSOpenGLContext *>(d->cx) view] != view && ![view isHidden])
   711         if ([static_cast<NSOpenGLContext *>(d->cx) view] != view && ![view isHidden])
   704             [static_cast<NSOpenGLContext *>(d->cx) setView:view];
   712             [static_cast<NSOpenGLContext *>(d->cx) setView:view];
   705     } else if (d->paintDevice->devType() == QInternal::Pixmap) {
   713     } else if (d->paintDevice->devType() == QInternal::Pixmap) {
   706         const QPixmap *pm = static_cast<const QPixmap *>(d->paintDevice);
   714         const QPixmap *pm = static_cast<const QPixmap *>(d->paintDevice);
   707         [static_cast<NSOpenGLContext *>(d->cx) setOffScreen:qt_mac_pixmap_get_base(pm)
   715         [static_cast<NSOpenGLContext *>(d->cx) setOffScreen:qt_mac_pixmap_get_base(pm)
   802 }
   810 }
   803 
   811 
   804 static CFBundleRef qt_getOpenGLBundle()
   812 static CFBundleRef qt_getOpenGLBundle()
   805 {
   813 {
   806     CFBundleRef bundle = 0;
   814     CFBundleRef bundle = 0;
       
   815     CFStringRef urlString = QCFString::toCFStringRef(QLatin1String("/System/Library/Frameworks/OpenGL.framework"));
   807     QCFType<CFURLRef> url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
   816     QCFType<CFURLRef> url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
   808                  QCFString::toCFStringRef(QLatin1String("/System/Library/Frameworks/OpenGL.framework")), kCFURLPOSIXPathStyle, false);
   817                  urlString, kCFURLPOSIXPathStyle, false);
   809     if (url)
   818     if (url)
   810         bundle = CFBundleCreate(kCFAllocatorDefault, url);
   819         bundle = CFBundleCreate(kCFAllocatorDefault, url);
       
   820     CFRelease(urlString);
   811     return bundle;
   821     return bundle;
   812 }
   822 }
   813 
   823 
   814 void *QGLContext::getProcAddress(const QString &proc) const
   824 void *QGLContext::getProcAddress(const QString &proc) const
   815 {
   825 {
   816     return CFBundleGetFunctionPointerForName(QCFType<CFBundleRef>(qt_getOpenGLBundle()),
   826     CFStringRef procName = QCFString(proc).toCFStringRef(proc);
   817                                              QCFString(proc));
   827     void *result = CFBundleGetFunctionPointerForName(QCFType<CFBundleRef>(qt_getOpenGLBundle()),
       
   828                                              procName);
       
   829     CFRelease(procName);
       
   830     return result;
   818 }
   831 }
   819 #ifndef QT_MAC_USE_COCOA
   832 #ifndef QT_MAC_USE_COCOA
   820 /*****************************************************************************
   833 /*****************************************************************************
   821   QGLWidget AGL-specific code
   834   QGLWidget AGL-specific code
   822  *****************************************************************************/
   835  *****************************************************************************/