| 1 | // Copyright (C) 2016 LG Electronics Inc, author: <mikko.levonmaa@lge.com> |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | #include <QtWaylandClient/private/qwaylandshm_p.h> |
| 4 | #include <QtWaylandClient/private/qwaylanddisplay_p.h> |
| 5 | |
| 6 | #include "qwaylandsharedmemoryformathelper_p.h" |
| 7 | |
| 8 | QT_BEGIN_NAMESPACE |
| 9 | |
| 10 | namespace QtWaylandClient { |
| 11 | |
| 12 | QWaylandShm::QWaylandShm(QWaylandDisplay *display, int version, uint32_t id) |
| 13 | : QtWayland::wl_shm(display->wl_registry(), id, qMin(version, 2)) |
| 14 | { |
| 15 | } |
| 16 | |
| 17 | QWaylandShm::~QWaylandShm() |
| 18 | { |
| 19 | if (version() < WL_SHM_RELEASE_SINCE_VERSION) { |
| 20 | wl_shm_destroy(object()); |
| 21 | } else { |
| 22 | wl_shm_release(object()); |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | void QWaylandShm::shm_format(uint32_t format) |
| 27 | { |
| 28 | m_formats << format; |
| 29 | } |
| 30 | |
| 31 | bool QWaylandShm::formatSupported(wl_shm_format format) const |
| 32 | { |
| 33 | return m_formats.contains(format); |
| 34 | } |
| 35 | |
| 36 | bool QWaylandShm::formatSupported(QImage::Format format) const |
| 37 | { |
| 38 | wl_shm_format fmt = formatFrom(format); |
| 39 | return formatSupported(format: fmt); |
| 40 | } |
| 41 | |
| 42 | wl_shm_format QWaylandShm::formatFrom(QImage::Format format) |
| 43 | { |
| 44 | return QWaylandSharedMemoryFormatHelper::fromQImageFormat(format); |
| 45 | } |
| 46 | |
| 47 | QImage::Format QWaylandShm::formatFrom(wl_shm_format format) |
| 48 | { |
| 49 | return QWaylandSharedMemoryFormatHelper::fromWaylandShmFormat(format); |
| 50 | } |
| 51 | |
| 52 | } |
| 53 | |
| 54 | QT_END_NAMESPACE |
| 55 | |