Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qwlbuffermanager.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
5#include <QWaylandCompositor>
6#include <QtWaylandCompositor/private/qwaylandcompositor_p.h>
7#include <QtWaylandCompositor/private/qwlclientbufferintegration_p.h>
8#include <QDebug>
9
11
12namespace QtWayland {
13
20
22{
24 {
25 notify = BufferManager::destroy_listener_callback;
26 wl_list_init(&this->link);
27 }
28
29 BufferManager *d = nullptr;
30};
31
32void BufferManager::registerBuffer(wl_resource *buffer_resource, ClientBuffer *clientBuffer)
33{
34 m_buffers[buffer_resource] = clientBuffer;
35
36 auto *destroy_listener = new buffer_manager_destroy_listener;
37 destroy_listener->d = this;
38 wl_resource_add_destroy_listener(buffer_resource, destroy_listener);
39
40}
41
42ClientBuffer *BufferManager::getBuffer(wl_resource *buffer_resource)
43{
44 if (!buffer_resource)
45 return nullptr;
46
47 auto it = m_buffers.find(buffer_resource);
48 if (it != m_buffers.end())
49 return it.value();
50
51 ClientBuffer *newBuffer = nullptr;
52
53 for (auto *integration : QWaylandCompositorPrivate::get(m_compositor)->clientBufferIntegrations()) {
54 newBuffer = integration->createBufferFor(buffer_resource);
55 if (newBuffer)
56 break;
57 }
58
59 if (newBuffer)
60 registerBuffer(buffer_resource, newBuffer);
61 else
62 qCWarning(qLcWaylandCompositorHardwareIntegration) << "Could not create buffer for resource.";
63
64 return newBuffer;
65}
66
67
68void BufferManager::destroy_listener_callback(wl_listener *listener, void *data)
69{
70 buffer_manager_destroy_listener *destroy_listener = static_cast<buffer_manager_destroy_listener *>(listener);
71 BufferManager *self = destroy_listener->d;
72 struct ::wl_resource *buffer = static_cast<struct ::wl_resource *>(data);
73
74 wl_list_remove(&destroy_listener->link);
75 delete destroy_listener;
76
77 Q_ASSERT(self);
79
80 ClientBuffer *clientBuffer = self->m_buffers.take(buffer);
81
82 if (!clientBuffer)
83 return;
84
85 clientBuffer->setDestroyed();
86}
87
88}
\inmodule QtCore
Definition qobject.h:103
static QWaylandCompositorPrivate * get(QWaylandCompositor *compositor)
\qmltype WaylandCompositor \instantiates QWaylandCompositor \inqmlmodule QtWayland....
friend struct buffer_manager_destroy_listener
ClientBuffer * getBuffer(struct ::wl_resource *buffer_resource)
void registerBuffer(struct ::wl_resource *buffer_resource, ClientBuffer *clientBuffer)
BufferManager(QWaylandCompositor *compositor)
QSet< QString >::iterator it
Combined button and popup list for selecting options.
#define qCWarning(category,...)
static QOpenGLCompositor * compositor
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLuint buffer
GLintptr GLsizeiptr GLeglClientBufferEXT clientBuffer
#define Q_ASSERT(cond)
Definition qrandom.cpp:47