Skip to content

Commit

Permalink
Initial implementation of decorations for EGL windows.
Browse files Browse the repository at this point in the history
Change-Id: I7521e583bf18f3690ecc6baacd05a5e92e9fd890
Reviewed-by: Samuel Rødal <samuel.rodal@digia.com>
Reviewed-by: Andy Nichols <andy.nichols@digia.com>
  • Loading branch information
giucam authored and Andy Nichols committed Nov 17, 2012
1 parent 41c62a3 commit 2246c01
Show file tree
Hide file tree
Showing 18 changed files with 559 additions and 71 deletions.
@@ -0,0 +1,65 @@
/****************************************************************************
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "qwaylandegldecoration.h"

#include "qwaylandeglwindow.h"

#include <QtGui/QPainter>
#include <QtGui/QOpenGLPaintDevice>

QWaylandEglDecoration::QWaylandEglDecoration(QWaylandEglWindow *window)
: QWaylandDecoration(window)
{
}

QWaylandEglDecoration::~QWaylandEglDecoration()
{
}

void QWaylandEglDecoration::paintDecoration()
{
glClearColor(backgroundColor().redF(), backgroundColor().greenF(), backgroundColor().blueF(), backgroundColor().alphaF());
glClear(GL_COLOR_BUFFER_BIT);

QOpenGLPaintDevice device(window()->frameGeometry().size());
paint(&device);
}
@@ -0,0 +1,59 @@
/****************************************************************************
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

#ifndef QWAYLANDEGLDECORATION_H
#define QWAYLANDEGLDECORATION_H

#include "qwaylanddecoration.h"

class QWaylandEglWindow;

class QWaylandEglDecoration : public QWaylandDecoration
{
public:
QWaylandEglDecoration(QWaylandEglWindow *window);
~QWaylandEglDecoration();

void paintDecoration();

};

#endif // QWAYLANDEGLDECORATION_H
Expand Up @@ -43,11 +43,15 @@

#include "qwaylandscreen.h"
#include "qwaylandglcontext.h"
#include "qwaylandegldecoration.h"

#include <QtPlatformSupport/private/qeglconvenience_p.h>

#include <QDebug>
#include <QtGui/QWindow>
#include <qpa/qwindowsysteminterface.h>
#include <QOpenGLFramebufferObject>
#include <QOpenGLContext>

#ifdef QT_WAYLAND_WINDOWMANAGER_SUPPORT
#include "windowmanager_integration/qwaylandwindowmanagerintegration.h"
Expand All @@ -56,11 +60,14 @@
QWaylandEglWindow::QWaylandEglWindow(QWindow *window)
: QWaylandWindow(window)
, m_eglIntegration(static_cast<QWaylandEglIntegration *>(mDisplay->eglIntegration()))
, m_waylandEglWindow(wl_egl_window_create(mSurface,window->width(),window->height()))
, m_waylandEglWindow(0)
, m_eglSurface(0)
, m_eglConfig(0)
, m_contentFBO(0)
, m_resize(false)
, m_format(window->format())
{
setGeometry(window->geometry());
}

QWaylandEglWindow::~QWaylandEglWindow()
Expand All @@ -71,6 +78,8 @@ QWaylandEglWindow::~QWaylandEglWindow()
}

wl_egl_window_destroy(m_waylandEglWindow);

delete m_contentFBO;
}

QWaylandWindow::WindowType QWaylandEglWindow::windowType() const
Expand All @@ -80,14 +89,32 @@ QWaylandWindow::WindowType QWaylandEglWindow::windowType() const

void QWaylandEglWindow::setGeometry(const QRect &rect)
{
int current_width, current_height;
wl_egl_window_get_attached_size(m_waylandEglWindow,&current_width,&current_height);
if (current_width != rect.width() || current_height != rect.height()) {
waitForFrameSync();
wl_egl_window_resize(m_waylandEglWindow, rect.width(), rect.height(), 0, 0);
createDecoration();
QMargins margins = frameMargins();
QSize sizeWithMargins = rect.size() + QSize(margins.left() + margins.right(), margins.top() + margins.bottom());

if (m_waylandEglWindow) {
int current_width, current_height;
wl_egl_window_get_attached_size(m_waylandEglWindow,&current_width,&current_height);
if (current_width != sizeWithMargins.width() || current_height != sizeWithMargins.height()) {
waitForFrameSync();
wl_egl_window_resize(m_waylandEglWindow, sizeWithMargins.width(), sizeWithMargins.height(), 0, 0);

m_resize = true;
}
} else {
m_waylandEglWindow = wl_egl_window_create(mSurface, sizeWithMargins.width(), sizeWithMargins.height());
}
QWaylandWindow::setGeometry(rect);
}

QRect QWaylandEglWindow::contentsRect() const
{
QRect r = geometry();
QMargins m = frameMargins();
return QRect(m.left(), m.bottom(), r.width(), r.height());
}

QSurfaceFormat QWaylandEglWindow::format() const
{
return m_format;
Expand All @@ -106,3 +133,36 @@ EGLSurface QWaylandEglWindow::eglSurface() const
return m_eglSurface;
}

GLuint QWaylandEglWindow::contentFBO() const
{
if (!decoration())
return 0;

if (m_resize || !m_contentFBO) {
QOpenGLFramebufferObject *old = m_contentFBO;
m_contentFBO = new QOpenGLFramebufferObject(geometry().width(), geometry().height(), QOpenGLFramebufferObject::CombinedDepthStencil);

delete old;
m_resize = false;
}

return m_contentFBO->handle();
}

GLuint QWaylandEglWindow::contentTexture() const
{
return m_contentFBO->texture();
}

void QWaylandEglWindow::bindContentFBO()
{
if (decoration()) {
contentFBO();
m_contentFBO->bind();
}
}

void QWaylandEglWindow::createDecorationInstance()
{
new QWaylandEglDecoration(this);
}
Expand Up @@ -47,6 +47,7 @@
#include "qwaylandeglintegration.h"

class QWaylandGLContext;
class QOpenGLFramebufferObject;

class QWaylandEglWindow : public QWaylandWindow
{
Expand All @@ -56,10 +57,19 @@ class QWaylandEglWindow : public QWaylandWindow
WindowType windowType() const;
void setGeometry(const QRect &rect);

QRect contentsRect() const;

EGLSurface eglSurface() const;
GLuint contentFBO() const;
GLuint contentTexture() const;

QSurfaceFormat format() const;

void bindContentFBO();

protected:
void createDecorationInstance();

private:
QWaylandEglIntegration *m_eglIntegration;
struct wl_egl_window *m_waylandEglWindow;
Expand All @@ -68,6 +78,8 @@ class QWaylandEglWindow : public QWaylandWindow

mutable EGLSurface m_eglSurface;
mutable EGLConfig m_eglConfig;
mutable QOpenGLFramebufferObject *m_contentFBO;
mutable bool m_resize;

QSurfaceFormat m_format;
};
Expand Down

0 comments on commit 2246c01

Please sign in to comment.