2023-05-25 11:15:57 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2023 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "core/graphicsbuffer.h"
|
|
|
|
#include "wayland/shmclientbuffer.h"
|
|
|
|
#include "utils/filedescriptor.h"
|
|
|
|
#include "utils/memorymap.h"
|
|
|
|
|
|
|
|
#include "qwayland-server-wayland.h"
|
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
namespace KWin
|
2023-05-25 11:15:57 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
class ShmClientBufferIntegrationPrivate : public QtWaylandServer::wl_shm
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ShmClientBufferIntegrationPrivate(Display *display, ShmClientBufferIntegration *q);
|
|
|
|
|
|
|
|
ShmClientBufferIntegration *q;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void shm_bind_resource(Resource *resource) override;
|
|
|
|
void shm_create_pool(Resource *resource, uint32_t id, int32_t fd, int32_t size) override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ShmPool : public QtWaylandServer::wl_shm_pool
|
|
|
|
{
|
|
|
|
public:
|
2023-09-13 17:59:29 +00:00
|
|
|
ShmPool(ShmClientBufferIntegration *integration, wl_client *client, int id, uint32_t version, FileDescriptor &&fd, MemoryMap &&mapping);
|
2023-05-25 11:15:57 +00:00
|
|
|
|
|
|
|
void ref();
|
|
|
|
void unref();
|
|
|
|
|
|
|
|
ShmClientBufferIntegration *integration;
|
2023-09-13 17:59:29 +00:00
|
|
|
MemoryMap mapping;
|
|
|
|
FileDescriptor fd;
|
2023-05-25 11:15:57 +00:00
|
|
|
int refCount = 1;
|
|
|
|
bool sigbusImpossible = false;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void shm_pool_destroy_resource(Resource *resource) override;
|
|
|
|
void shm_pool_create_buffer(Resource *resource, uint32_t id, int32_t offset, int32_t width, int32_t height, int32_t stride, uint32_t format) override;
|
|
|
|
void shm_pool_destroy(Resource *resource) override;
|
|
|
|
void shm_pool_resize(Resource *resource, int32_t size) override;
|
|
|
|
};
|
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
class KWIN_EXPORT ShmClientBuffer : public GraphicsBuffer
|
2023-05-25 11:15:57 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2023-09-13 17:59:29 +00:00
|
|
|
ShmClientBuffer(ShmPool *pool, ShmAttributes attributes, wl_client *client, uint32_t id);
|
2023-05-25 11:15:57 +00:00
|
|
|
~ShmClientBuffer() override;
|
|
|
|
|
2023-06-28 13:27:15 +00:00
|
|
|
Map map(MapFlags flags) override;
|
2023-05-25 11:15:57 +00:00
|
|
|
void unmap() override;
|
|
|
|
|
|
|
|
QSize size() const override;
|
|
|
|
bool hasAlphaChannel() const override;
|
2023-09-13 17:59:29 +00:00
|
|
|
const ShmAttributes *shmAttributes() const override;
|
2023-05-25 11:15:57 +00:00
|
|
|
|
|
|
|
static ShmClientBuffer *get(wl_resource *resource);
|
|
|
|
|
|
|
|
private:
|
|
|
|
static void buffer_destroy_resource(wl_resource *resource);
|
|
|
|
static void buffer_destroy(wl_client *client, wl_resource *resource);
|
|
|
|
static const struct wl_buffer_interface implementation;
|
|
|
|
|
|
|
|
wl_resource *m_resource = nullptr;
|
|
|
|
ShmPool *m_shmPool;
|
2023-09-13 17:59:29 +00:00
|
|
|
ShmAttributes m_shmAttributes;
|
2023-05-25 11:15:57 +00:00
|
|
|
};
|
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
} // namespace KWin
|