Changeset View
Changeset View
Standalone View
Standalone View
plugins/qpa/offscreensurface.cpp
- This file was added.
1 | /******************************************************************** | ||||
---|---|---|---|---|---|
2 | KWin - the KDE window manager | ||||
3 | This file is part of the KDE project. | ||||
4 | | ||||
5 | Copyright (C) 2019 Vlad Zagorodniy <vladzzag@gmail.com> | ||||
6 | | ||||
7 | This program is free software; you can redistribute it and/or modify | ||||
8 | it under the terms of the GNU General Public License as published by | ||||
9 | the Free Software Foundation; either version 2 of the License, or | ||||
10 | (at your option) any later version. | ||||
11 | | ||||
12 | This program is distributed in the hope that it will be useful, | ||||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | GNU General Public License for more details. | ||||
16 | | ||||
17 | You should have received a copy of the GNU General Public License | ||||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | *********************************************************************/ | ||||
20 | | ||||
21 | #include "offscreensurface.h" | ||||
22 | #include "eglhelpers.h" | ||||
23 | #include "main.h" | ||||
24 | #include "platform.h" | ||||
25 | | ||||
26 | #include <QOffscreenSurface> | ||||
27 | | ||||
28 | namespace KWin | ||||
29 | { | ||||
30 | namespace QPA | ||||
31 | { | ||||
32 | | ||||
33 | OffscreenSurface::OffscreenSurface(QOffscreenSurface *surface) | ||||
34 | : QPlatformOffscreenSurface(surface) | ||||
35 | , m_eglDisplay(kwinApp()->platform()->sceneEglDisplay()) | ||||
36 | { | ||||
37 | const QSize size = surface->size(); | ||||
38 | | ||||
39 | EGLConfig config = configFromFormat(m_eglDisplay, surface->requestedFormat(), EGL_PBUFFER_BIT); | ||||
40 | if (config == EGL_NO_CONFIG_KHR) { | ||||
41 | return; | ||||
42 | } | ||||
43 | | ||||
44 | const EGLint attributes[] = { | ||||
45 | EGL_WIDTH, size.width(), | ||||
46 | EGL_HEIGHT, size.height(), | ||||
47 | EGL_NONE | ||||
48 | }; | ||||
49 | | ||||
50 | m_surface = eglCreatePbufferSurface(m_eglDisplay, config, attributes); | ||||
51 | if (m_surface == EGL_NO_SURFACE) { | ||||
52 | return; | ||||
53 | } | ||||
54 | | ||||
55 | // Requested and actual surface format might be different. | ||||
56 | m_format = formatFromConfig(m_eglDisplay, config); | ||||
57 | } | ||||
58 | | ||||
59 | OffscreenSurface::~OffscreenSurface() | ||||
60 | { | ||||
61 | if (m_surface != EGL_NO_SURFACE) { | ||||
62 | eglDestroySurface(m_eglDisplay, m_surface); | ||||
63 | } | ||||
64 | } | ||||
65 | | ||||
66 | QSurfaceFormat OffscreenSurface::format() const | ||||
67 | { | ||||
68 | return m_format; | ||||
69 | } | ||||
70 | | ||||
71 | bool OffscreenSurface::isValid() const | ||||
72 | { | ||||
73 | return m_surface != EGL_NO_SURFACE; | ||||
74 | } | ||||
75 | | ||||
76 | EGLSurface OffscreenSurface::nativeHandle() const | ||||
77 | { | ||||
78 | return m_surface; | ||||
79 | } | ||||
80 | | ||||
81 | } // namespace QPA | ||||
82 | } // namespace KWin |