Get rid of QOpenGLContext dependency in WaylandCompositor constructor.
authorSamuel Rødal <samuel.rodal@nokia.com>
Tue, 1 Nov 2011 07:56:47 +0000 (08:56 +0100)
committerJørgen Lind <jorgen.lind@nokia.com>
Tue, 1 Nov 2011 08:19:39 +0000 (09:19 +0100)
Now WaylandSurface::texture() takes a QOpenGLContext * instead. This
prevents a crash in qml-compositor against wayland_egl, since the
context was 0 (it's created behind the scenes by scene graph at a
later point).

Change-Id: Ia02f596922ad0edea602dfe12b411ec827d47669
Reviewed-by: Jørgen Lind <jorgen.lind@nokia.com>
22 files changed:
examples/qml-compositor/main.cpp
examples/qwidget-compositor/main.cpp
examples/qwidget-compositor/qwidget-compositor.pro
examples/qwindow-compositor/qwindowcompositor.cpp
src/qt-compositor/compositor_api/compositor_api.pri
src/qt-compositor/compositor_api/waylandcompositor.cpp
src/qt-compositor/compositor_api/waylandcompositor.h
src/qt-compositor/compositor_api/waylandsurface.cpp
src/qt-compositor/compositor_api/waylandsurface.h
src/qt-compositor/compositor_api/waylandsurfaceitem.cpp
src/qt-compositor/hardware_integration/dri2_xcb/dri2xcbhwintegration.cpp
src/qt-compositor/hardware_integration/dri2_xcb/dri2xcbhwintegration.h
src/qt-compositor/hardware_integration/graphicshardwareintegration.h
src/qt-compositor/hardware_integration/hardware_integration.pri
src/qt-compositor/hardware_integration/wayland_egl/waylandeglintegration.cpp
src/qt-compositor/hardware_integration/wayland_egl/waylandeglintegration.h
src/qt-compositor/hardware_integration/xcomposite_egl/xcompositeeglintegration.cpp
src/qt-compositor/hardware_integration/xcomposite_egl/xcompositeeglintegration.h
src/qt-compositor/hardware_integration/xcomposite_glx/xcompositeglxintegration.cpp
src/qt-compositor/hardware_integration/xcomposite_glx/xcompositeglxintegration.h
src/qt-compositor/wayland_wrapper/wlsurface.cpp
src/qt-compositor/wayland_wrapper/wlsurface.h

index 3ff3583..7f2d47b 100644 (file)
@@ -57,7 +57,7 @@ class QmlCompositor : public QQuickView, public WaylandCompositor
 {
     Q_OBJECT
 public:
-    QmlCompositor() : WaylandCompositor(this, const_cast<QOpenGLContext *>(QOpenGLContext::currentContext())) {
+    QmlCompositor() : WaylandCompositor(this) {
         //setMouseTracking(true);
         setSource(QUrl(QLatin1String("qrc:qml/QmlCompositor/main.qml")));
         setResizeMode(QQuickView::SizeRootObjectToView);
index 8e71860..ea7ed34 100644 (file)
@@ -49,7 +49,7 @@
 #include <QMouseEvent>
 
 #ifdef QT_COMPOSITOR_WAYLAND_GL
-#include <QGLContext>
+#include <QOpenGLContext>
 #include <QGLWidget>
 #endif
 
@@ -82,7 +82,7 @@ class QWidgetCompositor : public QWidget, public WaylandCompositor
     Q_OBJECT
 public:
     QWidgetCompositor()
-        : WaylandCompositor(windowHandle(),const_cast<QGLContext *>(context())->contextHandle())
+        : WaylandCompositor(windowHandle())
         , m_moveSurface(0)
         , m_dragSourceSurface(0)
     {
@@ -155,7 +155,7 @@ protected:
         for (int i = 0; i < m_surfaces.size(); ++i) {
             if (m_surfaces.at(i)->type() == WaylandSurface::Texture) {
 #ifdef QT_COMPOSITOR_WAYLAND_GL
-                drawTexture(m_surfaces.at(i)->geometry(), m_surfaces.at(i)->texture());
+                drawTexture(m_surfaces.at(i)->geometry(), m_surfaces.at(i)->texture(QOpenGLContext::currentContext()));
                 break;
 #endif //QT_COMPOSITOR_WAYLAND_GL
             } else if (m_surfaces.at(i)->type() == WaylandSurface::Shm) {
index 88dd757..98bcb0c 100644 (file)
@@ -28,7 +28,7 @@ isEmpty(QT_SOURCE_TREE) {
 #HEADERS += $$TOUCHSCREEN_BASE/qtouchscreen.h
 #INCLUDEPATH += $$TOUCHSCREEN_BASE
 #LIBS += -ludev -lmtdev
-QT += gui-private widgets widgets-private
+QT += gui-private widgets widgets-private opengl opengl-private
 
 target.path += $$[QT_INSTALL_DATA]/bin
 INSTALLS += target
index d5fcb84..d1f017f 100644 (file)
@@ -4,7 +4,7 @@
 #include <QTouchEvent>
 
 QWindowCompositor::QWindowCompositor(QOpenGLWindow *window)
-    : WaylandCompositor(window, window->context())
+    : WaylandCompositor(window)
     , m_window(window)
 {
     m_backgroundImage = QImage(QLatin1String(":/background.jpg"));
@@ -100,7 +100,7 @@ void QWindowCompositor::render()
     //If type == WaylandSurface::Texture draw textureId at geometry
     foreach (WaylandSurface *surface, m_surfaces) {
         if (surface->type() == WaylandSurface::Texture)
-            m_renderer->drawTexture(surface->texture(), surface->geometry(), 1); //depth argument should be dynamic (focused should be top).
+            m_renderer->drawTexture(surface->texture(QOpenGLContext::currentContext()), surface->geometry(), 1); //depth argument should be dynamic (focused should be top).
         else if (surface->type() == WaylandSurface::Shm)
             m_renderer->drawImage(surface->image(), surface->geometry());
     }
index dfae71b..1072662 100644 (file)
@@ -17,5 +17,5 @@ contains(QT, declarative) {
 
 !isEmpty(QT.core.MAJOR_VERSION):greaterThan(QT.core.MAJOR_VERSION, 4) {
     QT += core-private
-    contains(QT, declarative):QT += declarative-private opengl-private gui-private
+    contains(QT, declarative):QT += declarative-private gui-private
 }
index c8cff06..a42950f 100644 (file)
@@ -50,9 +50,8 @@
 #include "waylandsurfaceitem.h"
 #endif
 
-WaylandCompositor::WaylandCompositor(QWindow *window, QOpenGLContext *context, const char *socketName)
+WaylandCompositor::WaylandCompositor(QWindow *window, const char *socketName)
     : m_compositor(0)
-    , m_glContext(context)
     , m_toplevel_widget(window)
     , m_socket_name(socketName)
 {
@@ -110,11 +109,6 @@ WaylandSurface *WaylandCompositor::directRenderSurface() const
     return surf ? surf->handle() : 0;
 }
 
-QOpenGLContext * WaylandCompositor::glContext() const
-{
-    return m_glContext;
-}
-
 QWindow * WaylandCompositor::window() const
 {
     return m_toplevel_widget;
index de5a4a8..9f2973a 100644 (file)
@@ -44,9 +44,7 @@
 #include <QObject>
 #include <QImage>
 #include <QRect>
-#include <QOpenGLContext>
 
-class QGLContext;
 class QWidget;
 class QMimeData;
 class WaylandSurface;
@@ -59,7 +57,7 @@ namespace Wayland
 class WaylandCompositor
 {
 public:
-    WaylandCompositor(QWindow *window = 0, QOpenGLContext *context = 0, const char *socketName = 0);
+    WaylandCompositor(QWindow *window = 0, const char *socketName = 0);
     virtual ~WaylandCompositor();
 
     void frameFinished(WaylandSurface *surface = 0);
@@ -71,7 +69,6 @@ public:
     void setDirectRenderSurface(WaylandSurface *surface);
     WaylandSurface *directRenderSurface() const;
 
-    QOpenGLContext *glContext() const;
     QWindow *window()const;
 
     virtual void surfaceCreated(WaylandSurface *surface) = 0;
@@ -97,7 +94,6 @@ private:
     static void retainedSelectionChanged(QMimeData *mimeData, void *param);
 
     Wayland::Compositor *m_compositor;
-    QOpenGLContext *m_glContext;
     QWindow  *m_toplevel_widget;
     QByteArray m_socket_name;
 };
index f16a03f..8fdc737 100644 (file)
@@ -52,17 +52,16 @@ QImage WaylandSurface::image() const
 }
 
 #ifdef QT_COMPOSITOR_WAYLAND_GL
-GLuint WaylandSurface::texture() const
+GLuint WaylandSurface::texture(QOpenGLContext *context) const
 {
     Q_D(const WaylandSurface);
-    return d->surface->textureId();
+    return d->surface->textureId(context);
 }
 #else //QT_COMPOSITOR_WAYLAND_GL
-uint WaylandSurface::texture() const
+uint WaylandSurface::texture(QOpenGLContext *) const
 {
     return 0;
 }
-
 #endif
 
 Wayland::Surface * WaylandSurface::handle() const
index dd6685b..d7cb218 100644 (file)
@@ -46,7 +46,8 @@
 #include <QtCore/QVariantMap>
 
 #ifdef QT_COMPOSITOR_WAYLAND_GL
-#include <QtOpenGL/QGLContext>
+#include <QtGui/QOpenGLContext>
+#include <QtGui/qopengl.h>
 #endif
 
 class WaylandSurfacePrivate;
@@ -78,9 +79,9 @@ public:
 
     QImage image() const;
 #ifdef QT_COMPOSITOR_WAYLAND_GL
-    GLuint texture() const;
+    GLuint texture(QOpenGLContext *context) const;
 #else
-    uint texture() const;
+    uint texture(QOpenGLContext *context) const;
 #endif
 
     void sendMousePressEvent(const QPoint &pos, Qt::MouseButton button);
index e17767a..bf91499 100644 (file)
@@ -225,8 +225,10 @@ QSGNode *WaylandSurfaceItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeDa
     if (m_damaged) {
         QSGTexture *oldTexture = m_texture;
         if (m_surface->type() == WaylandSurface::Texture) {
+            QOpenGLContext *context = QOpenGLContext::currentContext();
+
             QSGEngine::TextureOption opt = useTextureAlpha() ? QSGEngine::TextureHasAlphaChannel : QSGEngine::TextureOption(0);
-            m_texture = canvas()->sceneGraphEngine()->createTextureFromId(m_surface->texture(),
+            m_texture = canvas()->sceneGraphEngine()->createTextureFromId(m_surface->texture(context),
                                                                           m_surface->geometry().size(),
                                                                           opt);
         } else {
index 0b021d3..0d16f78 100644 (file)
@@ -116,7 +116,7 @@ void Dri2XcbHWIntegration::initializeHardware(Wayland::Display *waylandDisplay)
     waylandDisplay->addGlobalObject(m_drm_object->base(),&wl_drm_interface,&drm_interface,post_drm_device);
 }
 
-GLuint Dri2XcbHWIntegration::createTextureFromBuffer(wl_buffer *buffer)
+GLuint Dri2XcbHWIntegration::createTextureFromBuffer(wl_buffer *buffer, QOpenGLContext *)
 {
     Dri2XcbBuffer *dri2Buffer = Wayland::wayland_cast<Dri2XcbBuffer *>(buffer);
 
index e54debd..9ed3558 100644 (file)
@@ -12,7 +12,7 @@ public:
 
     void initializeHardware(Wayland::Display *waylandDisplay);
 
-    GLuint createTextureFromBuffer(wl_buffer *buffer);
+    GLuint createTextureFromBuffer(wl_buffer *buffer, QOpenGLContext *context);
 
 private:
     DrmObject *m_drm_object;
index 339e20a..9f1f409 100644 (file)
@@ -57,7 +57,7 @@ public:
     /** Bind the Wayland buffer to the textureId. The correct context is the current context,
         so there is no need to do makeCurrent in this function.
      **/
-    virtual GLuint createTextureFromBuffer(struct wl_buffer *buffer) = 0;
+    virtual GLuint createTextureFromBuffer(struct wl_buffer *buffer, QOpenGLContext *context) = 0;
     virtual bool isYInverted(struct wl_buffer *) const { return true; }
 
     virtual bool setDirectRenderSurface(WaylandSurface *) {return false;}
index c7533bd..02a834b 100644 (file)
@@ -8,7 +8,6 @@ isEmpty(QT_WAYLAND_GL_CONFIG):QT_WAYLAND_GL_CONFIG = $$(QT_WAYLAND_GL_CONFIG)
         $$PWD/graphicshardwareintegration.cpp
 
     DEFINES += QT_COMPOSITOR_WAYLAND_GL
-    QT += opengl
 
     isEqual(QT_WAYLAND_GL_CONFIG, custom) {
         QT_WAYLAND_GL_INTEGRATION = $$QT_WAYLAND_GL_CONFIG
index 2d8fb19..80e1aec 100644 (file)
@@ -64,10 +64,8 @@ class WaylandEglIntegrationPrivate
 public:
     WaylandEglIntegrationPrivate()
         : egl_display(EGL_NO_DISPLAY)
-        , egl_context(EGL_NO_CONTEXT)
     { }
     EGLDisplay egl_display;
-    EGLContext egl_context;
     bool valid;
 };
 
@@ -81,8 +79,6 @@ WaylandEglIntegration::WaylandEglIntegration(WaylandCompositor *compositor)
 void WaylandEglIntegration::initializeHardware(Wayland::Display *waylandDisplay)
 {
     Q_D(WaylandEglIntegration);
-    //We need a window id now :)
-    m_compositor->window()->winId();
 
     QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface();
     if (nativeInterface) {
@@ -98,12 +94,10 @@ void WaylandEglIntegration::initializeHardware(Wayland::Display *waylandDisplay)
 
         if (!d->valid)
             qWarning("Failed to initialize egl display\n");
-
-        d->egl_context = nativeInterface->nativeResourceForContext("EglContext", m_compositor->glContext());
     }
 }
 
-GLuint WaylandEglIntegration::createTextureFromBuffer(wl_buffer *buffer)
+GLuint WaylandEglIntegration::createTextureFromBuffer(wl_buffer *buffer, QOpenGLContext *context)
 {
     Q_D(WaylandEglIntegration);
     if (!d->valid) {
@@ -111,7 +105,10 @@ GLuint WaylandEglIntegration::createTextureFromBuffer(wl_buffer *buffer)
         return 0;
     }
 
-    EGLImageKHR image = eglCreateImageKHR(d->egl_display, d->egl_context,
+    QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface();
+    EGLContext egl_context = nativeInterface->nativeResourceForContext("EglContext", context);
+
+    EGLImageKHR image = eglCreateImageKHR(d->egl_display, egl_context,
                                           EGL_WAYLAND_BUFFER_WL,
                                           buffer, NULL);
 
index 4e98d18..39a63c6 100644 (file)
@@ -54,7 +54,7 @@ public:
 
     void initializeHardware(Wayland::Display *waylandDisplay);
 
-    GLuint createTextureFromBuffer(wl_buffer *buffer);
+    GLuint createTextureFromBuffer(wl_buffer *buffer, QOpenGLContext *context);
 
     bool setDirectRenderSurface(WaylandSurface *);
     bool postBuffer(struct wl_buffer *);
index e32183a..c730a35 100644 (file)
@@ -60,7 +60,7 @@ void XCompositeEglIntegration::initializeHardware(Wayland::Display *waylandDispl
     waylandDisplay->addGlobalObject(handler->base(), &wl_xcomposite_interface, &XCompositeHandler::xcomposite_interface,XCompositeHandler::send_root_information);
 }
 
-GLuint XCompositeEglIntegration::createTextureFromBuffer(wl_buffer *buffer)
+GLuint XCompositeEglIntegration::createTextureFromBuffer(wl_buffer *buffer, QOpenGLContext *)
 {
     XCompositeBuffer *compositorBuffer = Wayland::wayland_cast<XCompositeBuffer *>(buffer);
     Pixmap pixmap = XCompositeNameWindowPixmap(mDisplay, compositorBuffer->window());
index 9cf08a7..9e3b16f 100644 (file)
@@ -14,7 +14,7 @@ public:
 
     void initializeHardware(Wayland::Display *waylandDisplay);
 
-    GLuint createTextureFromBuffer(struct wl_buffer *buffer);
+    GLuint createTextureFromBuffer(struct wl_buffer *buffer, QOpenGLContext *context);
     bool isYInverted(wl_buffer *) const;
 
 private:
index 17c68d1..41b6367 100644 (file)
@@ -73,7 +73,7 @@ void XCompositeGLXIntegration::initializeHardware(Wayland::Display *waylandDispl
     delete glContext;
 }
 
-GLuint XCompositeGLXIntegration::createTextureFromBuffer(wl_buffer *buffer)
+GLuint XCompositeGLXIntegration::createTextureFromBuffer(wl_buffer *buffer, QOpenGLContext *)
 {
     XCompositeBuffer *compositorBuffer = Wayland::wayland_cast<XCompositeBuffer *>(buffer);
     Pixmap pixmap = XCompositeNameWindowPixmap(mDisplay, compositorBuffer->window());
index ace454e..43f062f 100644 (file)
@@ -16,7 +16,7 @@ public:
 
     void initializeHardware(Wayland::Display *waylandDisplay);
 
-    GLuint createTextureFromBuffer(struct wl_buffer *buffer);
+    GLuint createTextureFromBuffer(struct wl_buffer *buffer, QOpenGLContext *context);
     bool isYInverted(wl_buffer *) const;
 
 private:
index cf8a443..6769bf2 100644 (file)
@@ -188,9 +188,9 @@ bool Surface::isYInverted() const
 
     if (d->compositor->graphicsHWIntegration()) {
         if (d->type() == WaylandSurface::Texture) {
-            if (textureId()) {
+            //if (textureId()) {
                 return d->compositor->graphicsHWIntegration()->isYInverted(d->buffer());
-            }
+            //}
         } else if (d->type() == WaylandSurface::Direct) {
             return d->compositor->graphicsHWIntegration()->isYInverted(d->buffer());
         }
@@ -238,7 +238,7 @@ QImage Surface::image() const
 }
 
 #ifdef QT_COMPOSITOR_WAYLAND_GL
-GLuint Surface::textureId() const
+GLuint Surface::textureId(QOpenGLContext *context) const
 {
     Q_D(const Surface);
     if (d->compositor->graphicsHWIntegration() && d->type() == WaylandSurface::Texture
@@ -251,7 +251,7 @@ GLuint Surface::textureId() const
         Surface *that = const_cast<Surface *>(this);
         GraphicsHardwareIntegration *hwIntegration = d->compositor->graphicsHWIntegration();
         that->d_func()->previousBuffer = d->buffer();
-        that->d_func()->texture_id = hwIntegration->createTextureFromBuffer(d->buffer());
+        that->d_func()->texture_id = hwIntegration->createTextureFromBuffer(d->buffer(), context);
         that->d_func()->textureCreatedForBuffer = true;
     }
     return d->texture_id;
index 31e10c7..a7e27da 100644 (file)
@@ -52,7 +52,8 @@
 #include <QtCore/QMetaType>
 
 #ifdef QT_COMPOSITOR_WAYLAND_GL
-#include <QtOpenGL/QGLContext>
+#include <QtGui/QOpenGLContext>
+#include <QtGui/qopengl.h>
 #endif
 
 namespace Wayland {
@@ -80,7 +81,7 @@ public:
     QImage image() const;
 
 #ifdef QT_COMPOSITOR_WAYLAND_GL
-    GLuint textureId() const;
+    GLuint textureId(QOpenGLContext *context) const;
 #endif
 
     void sendMousePressEvent(int x, int y, Qt::MouseButton button);