Qt 4.8
qwaylandeglwindow.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the plugins of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qwaylandeglwindow.h"
43 
44 #include "qwaylandscreen.h"
45 #include "qwaylandglcontext.h"
46 
48  : QWaylandWindow(window)
49  , mGLContext(0)
50  , mWaylandEglWindow(0)
51 {
52  mEglIntegration = static_cast<QWaylandEglIntegration *>(mDisplay->eglIntegration());
53  //super creates a new surface
55 }
56 
58 {
59  delete mGLContext;
60 }
61 
63 {
64  return QWaylandWindow::Egl;
65 }
66 
68 {
70  if (mWaylandEglWindow) {
71  wl_egl_window_resize(mWaylandEglWindow,rect.width(),rect.height(),0,0);
72  }
73 }
74 
76 {
77  const QWaylandWindow *wParent = static_cast<const QWaylandWindow *>(parent);
78 
79  mParentWindow = wParent;
80 }
81 
83 {
84  if (!mGLContext) {
85  QWaylandEglWindow *that = const_cast<QWaylandEglWindow *>(this);
86  that->mGLContext = new QWaylandGLContext(mEglIntegration->eglDisplay(),widget()->platformWindowFormat());
87 
88  EGLNativeWindowType window(reinterpret_cast<EGLNativeWindowType>(mWaylandEglWindow));
89  EGLSurface surface = eglCreateWindowSurface(mEglIntegration->eglDisplay(),mGLContext->eglConfig(),window,NULL);
90  that->mGLContext->setEglSurface(surface);
91  }
92 
93  return mGLContext;
94 }
95 
97 {
98  if (mWaylandEglWindow) {
99  wl_egl_window_destroy(mWaylandEglWindow);
100  }
101  wl_visual *visual = QWaylandScreen::waylandScreenFromWidget(widget())->visual();
102  QSize size = geometry().size();
103  if (!size.isValid())
104  size = QSize(0,0);
105 
106  mWaylandEglWindow = wl_egl_window_create(mSurface,size.width(),size.height(),visual);
107  if (mGLContext) {
108  EGLNativeWindowType window(reinterpret_cast<EGLNativeWindowType>(mWaylandEglWindow));
109  EGLSurface surface = eglCreateWindowSurface(mEglIntegration->eglDisplay(),mGLContext->eglConfig(),window,NULL);
110  mGLContext->setEglSurface(surface);
111  }
112 }
QWaylandEglIntegration * mEglIntegration
virtual void setGeometry(const QRect &rect)
This function is called by Qt whenever a window is moved or the window is resized.
virtual QRect geometry() const
Returnes the current geometry of a window.
struct wl_surface * mSurface
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
QWaylandEglWindow(QWidget *window)
The QPlatformWindow class provides an abstraction for top-level windows.
NativeWindowType EGLNativeWindowType
Definition: qegl_p.h:116
NSWindow * window
int width() const
Returns the width.
Definition: qsize.h:126
void setEglSurface(EGLSurface surface)
wl_visual * visual() const
struct wl_egl_window * mWaylandEglWindow
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
QWaylandGLContext * mGLContext
EGLConfig eglConfig() const
void setGeometry(const QRect &rect)
This function is called by Qt whenever a window is moved or the window is resized.
The QPlatformGLContext class provides an abstraction for native GL contexts.
void setParent(const QPlatformWindow *parent)
This function is called to enable native child widgets in QPA.
const QWaylandWindow * mParentWindow
int height() const
Returns the height.
Definition: qsize.h:129
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
bool isValid() const
Returns true if both the width and height is equal to or greater than 0; otherwise returns false...
Definition: qsize.h:123
QPlatformGLContext * glContext() const
Reimplement to return the glContext associated with the window.
WindowType windowType() const
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
QWaylandDisplay * mDisplay
static QWaylandScreen * waylandScreenFromWidget(QWidget *widget)
QWidget * widget() const
Returnes the widget which belongs to the QPlatformWindow.