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

KDE's Doxygen guidelines are available online.