File indexing completed on 2024-05-19 05:32:36
0001 /* 0002 SPDX-FileCopyrightText: 2018 Fredrik Höglund <fredrik@kde.org> 0003 SPDX-FileCopyrightText: 2019 Roman Gilg <subdiff@gmail.com> 0004 SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org> 0005 SPDX-FileCopyrightText: 2021 Xaver Hugl <xaver.hugl@gmail.com> 0006 0007 Based on the libweston implementation, 0008 SPDX-FileCopyrightText: 2014, 2015 Collabora, Ltd. 0009 0010 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0011 */ 0012 #pragma once 0013 0014 #include "display.h" 0015 #include "linuxdmabufv1clientbuffer.h" 0016 #include "utils/ramfile.h" 0017 0018 #include "qwayland-server-linux-dmabuf-unstable-v1.h" 0019 0020 #include <QDebug> 0021 #include <QList> 0022 #include <QPointer> 0023 0024 #include <drm_fourcc.h> 0025 0026 namespace KWin 0027 { 0028 0029 class LinuxDmaBufV1FormatTable; 0030 0031 class LinuxDmaBufV1ClientBufferIntegrationPrivate : public QtWaylandServer::zwp_linux_dmabuf_v1 0032 { 0033 public: 0034 LinuxDmaBufV1ClientBufferIntegrationPrivate(LinuxDmaBufV1ClientBufferIntegration *q, Display *display); 0035 0036 LinuxDmaBufV1ClientBufferIntegration *q; 0037 std::unique_ptr<LinuxDmaBufV1Feedback> defaultFeedback; 0038 std::unique_ptr<LinuxDmaBufV1FormatTable> table; 0039 dev_t mainDevice; 0040 QPointer<RenderBackend> renderBackend; 0041 QHash<uint32_t, QList<uint64_t>> supportedModifiers; 0042 0043 protected: 0044 void zwp_linux_dmabuf_v1_bind_resource(Resource *resource) override; 0045 void zwp_linux_dmabuf_v1_destroy(Resource *resource) override; 0046 void zwp_linux_dmabuf_v1_create_params(Resource *resource, uint32_t params_id) override; 0047 void zwp_linux_dmabuf_v1_get_default_feedback(Resource *resource, uint32_t id) override; 0048 void zwp_linux_dmabuf_v1_get_surface_feedback(Resource *resource, uint32_t id, wl_resource *surface) override; 0049 }; 0050 0051 class LinuxDmaBufParamsV1 : public QtWaylandServer::zwp_linux_buffer_params_v1 0052 { 0053 public: 0054 LinuxDmaBufParamsV1(LinuxDmaBufV1ClientBufferIntegration *integration, ::wl_resource *resource); 0055 0056 protected: 0057 void zwp_linux_buffer_params_v1_destroy_resource(Resource *resource) override; 0058 void zwp_linux_buffer_params_v1_destroy(Resource *resource) override; 0059 void zwp_linux_buffer_params_v1_add(Resource *resource, 0060 int32_t fd, 0061 uint32_t plane_idx, 0062 uint32_t offset, 0063 uint32_t stride, 0064 uint32_t modifier_hi, 0065 uint32_t modifier_lo) override; 0066 void zwp_linux_buffer_params_v1_create(Resource *resource, int32_t width, int32_t height, uint32_t format, uint32_t flags) override; 0067 void 0068 zwp_linux_buffer_params_v1_create_immed(Resource *resource, uint32_t buffer_id, int32_t width, int32_t height, uint32_t format, uint32_t flags) override; 0069 0070 private: 0071 bool test(Resource *resource, uint32_t width, uint32_t height); 0072 0073 LinuxDmaBufV1ClientBufferIntegration *m_integration; 0074 DmaBufAttributes m_attrs; 0075 bool m_isUsed = false; 0076 }; 0077 0078 class LinuxDmaBufV1ClientBuffer : public GraphicsBuffer 0079 { 0080 Q_OBJECT 0081 0082 public: 0083 LinuxDmaBufV1ClientBuffer(DmaBufAttributes &&attrs); 0084 0085 QSize size() const override; 0086 bool hasAlphaChannel() const override; 0087 const DmaBufAttributes *dmabufAttributes() const override; 0088 0089 static LinuxDmaBufV1ClientBuffer *get(wl_resource *resource); 0090 0091 private: 0092 void initialize(wl_resource *resource); 0093 0094 static void buffer_destroy_resource(wl_resource *resource); 0095 static void buffer_destroy(wl_client *client, wl_resource *resource); 0096 static const struct wl_buffer_interface implementation; 0097 0098 wl_resource *m_resource = nullptr; 0099 DmaBufAttributes m_attrs; 0100 bool m_hasAlphaChannel = false; 0101 0102 friend class LinuxDmaBufParamsV1; 0103 }; 0104 0105 class LinuxDmaBufV1FormatTable 0106 { 0107 public: 0108 LinuxDmaBufV1FormatTable(const QHash<uint32_t, QList<uint64_t>> &supportedModifiers); 0109 0110 RamFile file; 0111 QMap<std::pair<uint32_t, uint64_t>, uint16_t> indices; 0112 }; 0113 0114 class LinuxDmaBufV1FeedbackPrivate : public QtWaylandServer::zwp_linux_dmabuf_feedback_v1 0115 { 0116 public: 0117 LinuxDmaBufV1FeedbackPrivate(LinuxDmaBufV1ClientBufferIntegrationPrivate *bufferintegration); 0118 0119 static LinuxDmaBufV1FeedbackPrivate *get(LinuxDmaBufV1Feedback *q); 0120 void send(Resource *resource); 0121 0122 QList<LinuxDmaBufV1Feedback::Tranche> m_tranches; 0123 LinuxDmaBufV1ClientBufferIntegrationPrivate *m_bufferintegration; 0124 0125 protected: 0126 void zwp_linux_dmabuf_feedback_v1_bind_resource(Resource *resource) override; 0127 void zwp_linux_dmabuf_feedback_v1_destroy(Resource *resource) override; 0128 }; 0129 }