From 23b98c3ad7f4e495f0212b6e1471d1a81dcc8e4c Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=B8rgen=20Lind?= Date: Mon, 19 Dec 2011 12:48:47 +0100 Subject: [PATCH] Make all QWaylandWindows have a wl_surface for the entire lifespan This solves that we dont have to cache the generic objects, and we conform with upstream wayland Change-Id: Ib8e15b734f09988f4f00989aeb1c274636709dc9 Reviewed-by: Laszlo Agocs --- .../wayland_egl/qwaylandeglwindow.cpp | 37 +++----------- .../gl_integration/wayland_egl/qwaylandeglwindow.h | 3 -- .../platforms/wayland/qwaylandshmwindow.cpp | 1 - src/plugins/platforms/wayland/qwaylandwindow.cpp | 58 +++++++++------------- src/plugins/platforms/wayland/qwaylandwindow.h | 3 +- 5 files changed, 32 insertions(+), 70 deletions(-) diff --git a/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandeglwindow.cpp b/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandeglwindow.cpp index e9da602..97ba7ab 100644 --- a/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandeglwindow.cpp +++ b/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandeglwindow.cpp @@ -55,15 +55,12 @@ QWaylandEglWindow::QWaylandEglWindow(QWindow *window) : QWaylandWindow(window) - , m_waylandEglWindow(0) + , m_eglIntegration(static_cast(mDisplay->eglIntegration())) + , m_waylandEglWindow(wl_egl_window_create(mSurface,window->width(),window->height())) , m_eglSurface(0) , m_eglConfig(0) , m_format(window->format()) { - m_eglIntegration = static_cast(mDisplay->eglIntegration()); - - //super creates a new surface - newSurfaceCreated(); } QWaylandEglWindow::~QWaylandEglWindow() @@ -72,6 +69,10 @@ QWaylandEglWindow::~QWaylandEglWindow() eglDestroySurface(m_eglIntegration->eglDisplay(), m_eglSurface); m_eglSurface = 0; } + + if (m_waylandEglWindow) { + wl_egl_window_destroy(m_waylandEglWindow); + } } QWaylandWindow::WindowType QWaylandEglWindow::windowType() const @@ -88,28 +89,6 @@ void QWaylandEglWindow::setGeometry(const QRect &rect) } } -void QWaylandEglWindow::newSurfaceCreated() -{ - if (m_waylandEglWindow) - wl_egl_window_destroy(m_waylandEglWindow); - - QSize size = geometry().size(); - if (!size.isValid()) - size = QSize(0,0); - - if (m_eglSurface) { - eglDestroySurface(m_eglIntegration->eglDisplay(), m_eglSurface); - m_eglSurface = 0; - } - - m_waylandEglWindow = wl_egl_window_create(mSurface, size.width(), size.height()); - -#ifdef QT_WAYLAND_WINDOWMANAGER_SUPPORT - //remove when we don't delay wl_surface creation -// QWaylandWindowManagerIntegration::instance()->flushPropertyChanges(this); -#endif -} - QSurfaceFormat QWaylandEglWindow::format() const { return m_format; @@ -121,8 +100,8 @@ EGLSurface QWaylandEglWindow::eglSurface() const return 0; if (!m_eglSurface) { - if (!m_eglConfig) - m_eglConfig = q_configFromGLFormat(m_eglIntegration->eglDisplay(), window()->format(), true); + m_eglConfig = q_configFromGLFormat(m_eglIntegration->eglDisplay(), window()->format(), true); + const_cast(this)->m_format = q_glFormatFromConfig(m_eglIntegration->eglDisplay(),m_eglConfig); EGLNativeWindowType window = m_waylandEglWindow; m_eglSurface = eglCreateWindowSurface(m_eglIntegration->eglDisplay(), m_eglConfig, window, 0); diff --git a/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandeglwindow.h b/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandeglwindow.h index d435a51..db02351 100644 --- a/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandeglwindow.h +++ b/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandeglwindow.h @@ -60,9 +60,6 @@ public: QSurfaceFormat format() const; -protected: - void newSurfaceCreated(); - private: QWaylandEglIntegration *m_eglIntegration; struct wl_egl_window *m_waylandEglWindow; diff --git a/src/plugins/platforms/wayland/qwaylandshmwindow.cpp b/src/plugins/platforms/wayland/qwaylandshmwindow.cpp index ba5e46c..dfb19c9 100644 --- a/src/plugins/platforms/wayland/qwaylandshmwindow.cpp +++ b/src/plugins/platforms/wayland/qwaylandshmwindow.cpp @@ -50,7 +50,6 @@ QWaylandShmWindow::QWaylandShmWindow(QWindow *window) : QWaylandWindow(window) { - newSurfaceCreated(); } QWaylandShmWindow::~QWaylandShmWindow() diff --git a/src/plugins/platforms/wayland/qwaylandwindow.cpp b/src/plugins/platforms/wayland/qwaylandwindow.cpp index 43eafaf..73ed850 100644 --- a/src/plugins/platforms/wayland/qwaylandwindow.cpp +++ b/src/plugins/platforms/wayland/qwaylandwindow.cpp @@ -63,9 +63,10 @@ QWaylandWindow::QWaylandWindow(QWindow *window) : QPlatformWindow(window) - , mSurface(0) - , mShellSurface(0) , mDisplay(QWaylandScreen::waylandScreenFromWindow(window)->display()) + , mSurface(mDisplay->createSurface(this)) + , mShellSurface(mDisplay->shell()->createShellSurface(this)) + , mExtendedWindow(0) , mBuffer(0) , mWaitingForFrameSync(false) , mFrameCallback(0) @@ -73,10 +74,16 @@ QWaylandWindow::QWaylandWindow(QWindow *window) static WId id = 1; mWindowId = id++; + if (mDisplay->windowExtension()) + mExtendedWindow = mDisplay->windowExtension()->getExtendedWindow(this); + #ifdef QT_WAYLAND_WINDOWMANAGER_SUPPORT - mDisplay->windowManagerIntegration()->mapClientToProcess(qApp->applicationPid()); - mDisplay->windowManagerIntegration()->authenticateWithToken(); + mDisplay->windowManagerIntegration()->mapClientToProcess(qApp->applicationPid()); + mDisplay->windowManagerIntegration()->authenticateWithToken(); #endif + + //all surfaces are toplevel surfaces for now + wl_shell_surface_set_toplevel(mShellSurface->handle()); } QWaylandWindow::~QWaylandWindow() @@ -105,22 +112,14 @@ void QWaylandWindow::setParent(const QPlatformWindow *parent) void QWaylandWindow::setVisible(bool visible) { - if (!mSurface && visible) { - mSurface = mDisplay->createSurface(this); - mShellSurface = mDisplay->shell()->createShellSurface(this); - if (mDisplay->windowExtension()) - mExtendedWindow = mDisplay->windowExtension()->getExtendedWindow(this); - newSurfaceCreated(); - wl_shell_surface_set_toplevel(mShellSurface->handle()); - } - if (!visible) { - delete mShellSurface; - mShellSurface = 0; - delete mExtendedWindow; - mExtendedWindow = 0; - wl_surface_destroy(mSurface); - mSurface = NULL; + if (visible) { + if (mBuffer) { + wl_surface_attach(mSurface, mBuffer->buffer(),0,0); + QWindowSystemInterface::handleSynchronousExposeEvent(window(), QRect(QPoint(), geometry().size())); + } + } else { + wl_surface_attach(mSurface, 0,0,0); } } @@ -140,9 +139,11 @@ void QWaylandWindow::configure(uint32_t time, uint32_t edges, void QWaylandWindow::attach(QWaylandBuffer *buffer) { mBuffer = buffer; - if (mSurface) { - wl_surface_attach(mSurface, buffer->buffer(),0,0); - QWindowSystemInterface::handleSynchronousExposeEvent(window(), QRect(QPoint(), geometry().size())); + + if (window()->visible()) { + wl_surface_attach(mSurface, mBuffer->buffer(),0,0); + if (buffer) + QWindowSystemInterface::handleSynchronousExposeEvent(window(), QRect(QPoint(), geometry().size())); } } @@ -160,19 +161,6 @@ void QWaylandWindow::damage(const QRect &rect) rect.x(), rect.y(), rect.width(), rect.height()); } -void QWaylandWindow::newSurfaceCreated() -{ - if (mBuffer) { - wl_surface_attach(mSurface,mBuffer->buffer(),0,0); - // do not damage the surface here, as this leads to graphical corruptions in the compositor until - // the first frame has been rendered - } -#ifdef QT_WAYLAND_WINDOWMANAGER_SUPPORT - //TODO: remove when we don't delay wl_surface creation -// QWaylandWindowManagerIntegration::instance()->flushPropertyChanges(this); -#endif -} - const wl_callback_listener QWaylandWindow::callbackListener = { QWaylandWindow::frameCallback }; diff --git a/src/plugins/platforms/wayland/qwaylandwindow.h b/src/plugins/platforms/wayland/qwaylandwindow.h index 8ce8161..fb4ac74 100644 --- a/src/plugins/platforms/wayland/qwaylandwindow.h +++ b/src/plugins/platforms/wayland/qwaylandwindow.h @@ -83,12 +83,11 @@ public: QWaylandExtendedSurface *extendedWindow() const; protected: + QWaylandDisplay *mDisplay; struct wl_surface *mSurface; QWaylandShellSurface *mShellSurface; QWaylandExtendedSurface *mExtendedWindow; - virtual void newSurfaceCreated(); - QWaylandDisplay *mDisplay; QWaylandBuffer *mBuffer; WId mWindowId; bool mWaitingForFrameSync; -- 2.7.4