KWayland

eglstream_controller_interface.cpp
1 /*
2  SPDX-FileCopyrightText: 2019 NVIDIA Inc.
3 
4  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6 #include "clientconnection.h"
7 #include "display.h"
8 #include "eglstream_controller_interface_p.h"
9 #include "logging.h"
10 
11 #include <QLibrary>
12 
13 namespace KWayland
14 {
15 namespace Server
16 {
17 const quint32 EglStreamControllerInterface::Private::s_version = 1;
18 
19 #ifndef K_DOXYGEN
20 const struct wl_eglstream_controller_interface EglStreamControllerInterface::Private::s_interface = {attachStreamConsumer, attachStreamConsumerAttribs};
21 #endif
22 
23 void EglStreamControllerInterface::Private::attachStreamConsumer(wl_client *client, wl_resource *resource, wl_resource *surface, wl_resource *eglStream)
24 {
25  wl_array noAttribs = {0, 0, nullptr};
26  attachStreamConsumerAttribs(client, resource, surface, eglStream, &noAttribs);
27 }
28 
29 void EglStreamControllerInterface::Private::attachStreamConsumerAttribs(wl_client *client,
30  wl_resource *resource,
31  wl_resource *surface,
32  wl_resource *eglStream,
33  wl_array *attribs)
34 {
35  Q_UNUSED(client);
36  Private *p = reinterpret_cast<Private *>(wl_resource_get_user_data(resource));
37  Q_EMIT p->q->streamConsumerAttached(SurfaceInterface::get(surface), eglStream, attribs);
38 }
39 
40 EglStreamControllerInterface::Private::Private(EglStreamControllerInterface *q, Display *display)
41  // libnvidia-egl-wayland.so.1 may not be present on all systems, so we load it dynamically
42  : Global::Private(display,
43  reinterpret_cast<wl_interface *>(QLibrary::resolve(QLatin1String("libnvidia-egl-wayland.so.1"), "wl_eglstream_controller_interface")),
44  s_version)
45  , q(q)
46 {
47 }
48 
49 void EglStreamControllerInterface::Private::create()
50 {
51  // bail out early if we were unable to load the interface
52  if (m_interface == nullptr) {
53  qCWarning(KWAYLAND_SERVER) << "failed to resolve wl_eglstream_controller_interface";
54  return;
55  }
56 
57  Global::Private::create();
58 }
59 
60 void EglStreamControllerInterface::Private::bind(wl_client *client, uint32_t version, uint32_t id)
61 {
62  wl_resource *r = display->getConnection(client)->createResource(m_interface, version, id);
63  if (r == nullptr) {
64  wl_client_post_no_memory(client);
65  return;
66  }
67 
68  wl_resource_set_implementation(r, &s_interface, this, nullptr);
69 }
70 
71 EglStreamControllerInterface::~EglStreamControllerInterface() = default;
72 
73 EglStreamControllerInterface::EglStreamControllerInterface(Display *display, QObject *parent)
74  : Global(new Private(this, display), parent)
75 {
76 }
77 
78 void EglStreamControllerInterface::create()
79 {
80  static_cast<Private &>(*d).create();
81 }
82 
83 }
84 }
85 
86 #include "moc_eglstream_controller_interface.cpp"
static SurfaceInterface * get(wl_resource *native)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Sep 26 2023 03:48:28 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.