Changeset View
Changeset View
Standalone View
Standalone View
plugins/platforms/drm/drm_buffer_gbm.cpp
- This file was added.
1 | /******************************************************************** | ||||
---|---|---|---|---|---|
2 | KWin - the KDE window manager | ||||
3 | This file is part of the KDE project. | ||||
4 | | ||||
5 | Copyright 2017 Roman Gilg <subdiff@gmail.com> | ||||
6 | Copyright 2015 Martin Gräßlin <mgraesslin@kde.org> | ||||
7 | | ||||
8 | This program is free software; you can redistribute it and/or modify | ||||
9 | it under the terms of the GNU General Public License as published by | ||||
10 | the Free Software Foundation; either version 2 of the License, or | ||||
11 | (at your option) any later version. | ||||
12 | | ||||
13 | This program is distributed in the hope that it will be useful, | ||||
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
16 | GNU General Public License for more details. | ||||
17 | | ||||
18 | You should have received a copy of the GNU General Public License | ||||
19 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
20 | *********************************************************************/ | ||||
21 | #include "drm_backend.h" | ||||
22 | #include "drm_buffer_gbm.h" | ||||
23 | | ||||
24 | #include "logging.h" | ||||
25 | | ||||
26 | // system | ||||
27 | #include <sys/mman.h> | ||||
28 | #include <errno.h> | ||||
29 | // drm | ||||
30 | #include <xf86drm.h> | ||||
31 | #include <gbm.h> | ||||
32 | | ||||
33 | namespace KWin | ||||
34 | { | ||||
35 | | ||||
36 | // DrmSurfaceBuffer | ||||
37 | DrmSurfaceBuffer::DrmSurfaceBuffer(DrmBackend *backend, gbm_surface *surface) | ||||
38 | : DrmBuffer(backend) | ||||
39 | , m_surface(surface) | ||||
40 | { | ||||
41 | m_bo = gbm_surface_lock_front_buffer(surface); | ||||
42 | if (!m_bo) { | ||||
43 | qCWarning(KWIN_DRM) << "Locking front buffer failed"; | ||||
44 | return; | ||||
45 | } | ||||
46 | m_size = QSize(gbm_bo_get_width(m_bo), gbm_bo_get_height(m_bo)); | ||||
47 | if (drmModeAddFB(m_backend->fd(), m_size.width(), m_size.height(), 24, 32, gbm_bo_get_stride(m_bo), gbm_bo_get_handle(m_bo).u32, &m_bufferId) != 0) { | ||||
48 | qCWarning(KWIN_DRM) << "drmModeAddFB failed"; | ||||
49 | } | ||||
50 | gbm_bo_set_user_data(m_bo, this, nullptr); | ||||
51 | } | ||||
52 | | ||||
53 | DrmSurfaceBuffer::~DrmSurfaceBuffer() | ||||
54 | { | ||||
55 | if (m_bufferId) { | ||||
56 | drmModeRmFB(m_backend->fd(), m_bufferId); | ||||
57 | } | ||||
58 | releaseGbm(); | ||||
59 | } | ||||
60 | | ||||
61 | void DrmSurfaceBuffer::releaseGbm() | ||||
62 | { | ||||
63 | if (m_bo) { | ||||
64 | gbm_surface_release_buffer(m_surface, m_bo); | ||||
65 | m_bo = nullptr; | ||||
66 | } | ||||
67 | } | ||||
68 | | ||||
69 | } |