diff --git a/src/plugins/platforms/cocoa/qcocoaglcontext.mm b/src/plugins/platforms/cocoa/qcocoaglcontext.mm
index d4673baaefe216b6a999be16eef326e71a67200a..3dee137038b5390b0abc44d4facf3c1de5cfbec4 100644
--- a/src/plugins/platforms/cocoa/qcocoaglcontext.mm
+++ b/src/plugins/platforms/cocoa/qcocoaglcontext.mm
@@ -133,18 +133,6 @@ void QCocoaGLContext::setActiveWindow(QWindow *window)
     cocoaWindow->setCurrentContext(this);
 
     [(QNSView *) cocoaWindow->contentView() setQCocoaGLContext:this];
-
-    // Enable high-dpi OpenGL for retina displays. Enabling has the side
-    // effect that Cooca will start calling glViewport(0, 0, width, height),
-    // overriding any glViewport calls in application code. This is usually not a
-    // problem, except if the applcation wants to have a "custom" viewport.
-    // (like the hellogl example)
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
-    if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_7) {
-        if (cocoaWindow->devicePixelRatio() > 1)
-            [cocoaWindow->contentView() setWantsBestResolutionOpenGLSurface:YES];
-    }
-#endif
 }
 
 void QCocoaGLContext::doneCurrent()
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm
index 999439d618b4e1f37b36fca16364ffd147c00304..ac30338c39dfc103e501a6487bb4d63ebaddb0ac 100644
--- a/src/plugins/platforms/cocoa/qcocoawindow.mm
+++ b/src/plugins/platforms/cocoa/qcocoawindow.mm
@@ -220,6 +220,16 @@ QCocoaWindow::QCocoaWindow(QWindow *tlw)
     } else {
         m_qtView = [[QNSView alloc] initWithQWindow:tlw platformWindow:this];
         m_contentView = m_qtView;
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
+        // Enable high-dpi OpenGL for retina displays. Enabling has the side
+        // effect that Cocoa will start calling glViewport(0, 0, width, height),
+        // overriding any glViewport calls in application code. This is usually not a
+        // problem, except if the appilcation wants to have a "custom" viewport.
+        // (like the hellogl example)
+        if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_7
+            && tlw->surfaceType() == QSurface::OpenGLSurface)
+            [m_contentView setWantsBestResolutionOpenGLSurface:YES];
+#endif
     }
     setGeometry(tlw->geometry());
     recreateWindow(parent());