[Qt] Replace use of QGLWidget/QGLContext with QOpenGLContext and QSurface for Qt 5
authorhausmann@webkit.org <hausmann@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 15 Feb 2012 15:42:30 +0000 (15:42 +0000)
committerhausmann@webkit.org <hausmann@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 15 Feb 2012 15:42:30 +0000 (15:42 +0000)
https://bugs.webkit.org/show_bug.cgi?id=78694

Reviewed by Noam Rosenthal.

Source/WebCore:

Typedef PlatformGraphicsContext3D and PlatformGraphicsSurface3D to QOpenGLContext
and QSurface for Qt 5. Use these APIs to change the current context and get the
procedure addresses. Removed QGraphicsObject inheritance remainder while we're at it,
because that code path is obsolete.

* platform/graphics/GraphicsContext3D.h:
* platform/graphics/cairo/OpenGLShims.cpp:
(WebCore::getProcAddress):
* platform/graphics/cairo/OpenGLShims.h:
* platform/graphics/qt/GraphicsContext3DQt.cpp:
(WebCore::GraphicsContext3DPrivate::~GraphicsContext3DPrivate):
(WebCore::GraphicsContext3DPrivate::blitMultisampleFramebufferAndRestoreContext):
(WebCore::GraphicsContext3DPrivate::makeCurrentIfNeeded):
(WebCore::GraphicsContext3D::~GraphicsContext3D):

Source/WebKit/qt:

* WebCoreSupport/PageClientQt.cpp:
(createPlatformGraphicsContext3DFromWidget): Return the QOpenGLContext and QSurface
from the QGLWidget when compiling with Qt 5, as that's what WebCore expects.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@107817 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/GraphicsContext3D.h
Source/WebCore/platform/graphics/cairo/OpenGLShims.cpp
Source/WebCore/platform/graphics/cairo/OpenGLShims.h
Source/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp
Source/WebKit/qt/ChangeLog
Source/WebKit/qt/WebCoreSupport/PageClientQt.cpp

index 4fdee4e..9e3b91c 100644 (file)
@@ -1,5 +1,27 @@
 2012-02-15  Simon Hausmann  <simon.hausmann@nokia.com>
 
+        [Qt] Replace use of QGLWidget/QGLContext with QOpenGLContext and QSurface for Qt 5
+        https://bugs.webkit.org/show_bug.cgi?id=78694
+
+        Reviewed by Noam Rosenthal.
+
+        Typedef PlatformGraphicsContext3D and PlatformGraphicsSurface3D to QOpenGLContext
+        and QSurface for Qt 5. Use these APIs to change the current context and get the
+        procedure addresses. Removed QGraphicsObject inheritance remainder while we're at it,
+        because that code path is obsolete.
+
+        * platform/graphics/GraphicsContext3D.h:
+        * platform/graphics/cairo/OpenGLShims.cpp:
+        (WebCore::getProcAddress):
+        * platform/graphics/cairo/OpenGLShims.h:
+        * platform/graphics/qt/GraphicsContext3DQt.cpp:
+        (WebCore::GraphicsContext3DPrivate::~GraphicsContext3DPrivate):
+        (WebCore::GraphicsContext3DPrivate::blitMultisampleFramebufferAndRestoreContext):
+        (WebCore::GraphicsContext3DPrivate::makeCurrentIfNeeded):
+        (WebCore::GraphicsContext3D::~GraphicsContext3D):
+
+2012-02-15  Simon Hausmann  <simon.hausmann@nokia.com>
+
         [Qt] Move Qt platform specific GL Context/Surface creation out of WebCore into WebKit
         https://bugs.webkit.org/show_bug.cgi?id=78692
 
index c809b79..cf32b59 100644 (file)
@@ -57,6 +57,8 @@ class QPainter;
 class QRect;
 class QGLWidget;
 class QGLContext;
+class QOpenGLContext;
+class QSurface;
 QT_END_NAMESPACE
 #elif PLATFORM(GTK) || PLATFORM(EFL)
 typedef unsigned int GLuint;
@@ -65,8 +67,13 @@ typedef unsigned int GLuint;
 #if PLATFORM(MAC)
 typedef CGLContextObj PlatformGraphicsContext3D;
 #elif PLATFORM(QT)
+#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
+typedef QOpenGLContext* PlatformGraphicsContext3D;
+typedef QSurface* PlatformGraphicsSurface3D;
+#else
 typedef QGLContext* PlatformGraphicsContext3D;
 typedef QGLWidget* PlatformGraphicsSurface3D;
+#endif
 #else
 typedef void* PlatformGraphicsContext3D;
 #endif
index 2994cd2..f59f26c 100644 (file)
@@ -42,7 +42,11 @@ OpenGLFunctionTable* openGLFunctionTable()
 #if PLATFORM(QT)
 static void* getProcAddress(const char* procName)
 {
+#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
+    return reinterpret_cast<void*>(QOpenGLContext::currentContext()->getProcAddress(procName));
+#else
     return reinterpret_cast<void*>(QGLContext::currentContext()->getProcAddress(QString::fromLatin1(procName)));
+#endif
 }
 #else
 typedef void* (*glGetProcAddressType) (const char* procName);
index a5c3c77..da50138 100644 (file)
  */
 
 #if PLATFORM(QT)
+#include <qglobal.h>
+#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
+#include <QOpenGLContext>
+#include <QSurface>
+#else
 #include <QGLContext>
+#endif
 #else
 #include <GL/gl.h>
 #endif
index e7aac60..b86dbbb 100644 (file)
@@ -36,9 +36,6 @@
 #include "NotImplemented.h"
 #include "QWebPageClient.h"
 #include "SharedBuffer.h"
-#include <QAbstractScrollArea>
-#include <QGraphicsObject>
-#include <QGLContext>
 #include <wtf/UnusedParam.h>
 #include <wtf/text/CString.h>
 
@@ -59,12 +56,8 @@ typedef char GLchar;
 #endif
 
 class GraphicsContext3DPrivate
-#if USE(ACCELERATED_COMPOSITING)
-#if USE(TEXTURE_MAPPER)
+#if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER)
         : public TextureMapperPlatformLayer
-#else
-        : public QGraphicsObject
-#endif
 #endif
 {
 public:
@@ -114,7 +107,7 @@ GraphicsContext3DPrivate::~GraphicsContext3DPrivate()
 {
     delete m_surface;
     m_surface = 0;
-    // ### Delete context?
+    // Platform context is assumed to be owned by surface.
     m_platformContext = 0;
 }
 
@@ -199,6 +192,17 @@ void GraphicsContext3DPrivate::blitMultisampleFramebufferAndRestoreContext() con
     if (!m_context->m_attrs.antialias)
         return;
 
+#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
+    const QOpenGLContext* currentContext = QOpenGLContext::currentContext();
+    QSurface* currentSurface = 0;
+    if (currentContext != m_platformContext) {
+        currentSurface = currentContext->surface();
+        m_platformContext->makeCurrent(m_surface);
+    }
+    blitMultisampleFramebuffer();
+    if (currentSurface)
+        const_cast<QOpenGLContext*>(currentContext)->makeCurrent(currentSurface);
+#else
     const QGLContext* currentContext = QGLContext::currentContext();
     const QGLContext* widgetContext = m_surface->context();
     if (currentContext != widgetContext)
@@ -209,16 +213,24 @@ void GraphicsContext3DPrivate::blitMultisampleFramebufferAndRestoreContext() con
             const_cast<QGLContext*>(currentContext)->makeCurrent();
     } else
         m_surface->doneCurrent();
+#endif
 }
 
 bool GraphicsContext3DPrivate::makeCurrentIfNeeded() const
 {
+#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
+    const QOpenGLContext* currentContext = QOpenGLContext::currentContext();
+    if (currentContext == m_platformContext)
+        return true;
+    return m_platformContext->makeCurrent(m_surface);
+#else
     const QGLContext* currentContext = QGLContext::currentContext();
     const QGLContext* widgetContext = m_surface->context();
     if (currentContext != widgetContext)
         m_surface->makeCurrent();
 
     return QGLContext::currentContext() == widgetContext;
+#endif
 }
 
 PassRefPtr<GraphicsContext3D> GraphicsContext3D::create(GraphicsContext3D::Attributes attrs, HostWindow* hostWindow, GraphicsContext3D::RenderStyle renderStyle)
@@ -335,8 +347,6 @@ GraphicsContext3D::GraphicsContext3D(GraphicsContext3D::Attributes attrs, HostWi
 GraphicsContext3D::~GraphicsContext3D()
 {
     makeContextCurrent();
-    if (!m_private->m_surface->isValid())
-        return;
     glDeleteTextures(1, &m_texture);
     glDeleteFramebuffers(1, &m_fbo);
     if (m_attrs.antialias) {
index dca2b69..02546ea 100644 (file)
@@ -1,5 +1,16 @@
 2012-02-15  Simon Hausmann  <simon.hausmann@nokia.com>
 
+        [Qt] Replace use of QGLWidget/QGLContext with QOpenGLContext and QSurface for Qt 5
+        https://bugs.webkit.org/show_bug.cgi?id=78694
+
+        Reviewed by Noam Rosenthal.
+
+        * WebCoreSupport/PageClientQt.cpp:
+        (createPlatformGraphicsContext3DFromWidget): Return the QOpenGLContext and QSurface
+        from the QGLWidget when compiling with Qt 5, as that's what WebCore expects.
+
+2012-02-15  Simon Hausmann  <simon.hausmann@nokia.com>
+
         [Qt] Move Qt platform specific GL Context/Surface creation out of WebCore into WebKit
         https://bugs.webkit.org/show_bug.cgi?id=78692
 
index 4f43e1f..bb376b7 100644 (file)
 #if ENABLE(WEBGL)
 #include <QGLWidget>
 
+#if QT_VERSION_CHECK(5, 0, 0)
+#include <QWindow>
+#endif
+
 static void createPlatformGraphicsContext3DFromWidget(QWidget* widget, PlatformGraphicsContext3D* context,
                                                       PlatformGraphicsSurface3D* surface)
 {
@@ -46,8 +50,13 @@ static void createPlatformGraphicsContext3DFromWidget(QWidget* widget, PlatformG
     if (glWidget->isValid()) {
         // Geometry can be set to zero because m_glWidget is used only for its QGLContext.
         glWidget->setGeometry(0, 0, 0, 0);
+#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
+        *surface = glWidget->windowHandle();
+        *context = glWidget->context()->contextHandle();
+#else
         *surface = glWidget;
         *context = const_cast<QGLContext*>(glWidget->context());
+#endif
     } else {
         delete glWidget;
         glWidget = 0;