1 /*
2 * Copyright (C) 2021 Red Hat
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17 * 02111-1307, USA.
18 */
19
20 #include "config.h"
21
22 #include "backends/native/meta-kms-impl-device-dummy.h"
23
24 #include "backends/native/meta-backend-native-private.h"
25 #include "backends/native/meta-kms.h"
26
27 struct _MetaKmsImplDeviceDummy
28 {
29 MetaKmsImplDevice parent;
30 };
31
32 static GInitableIface *initable_parent_iface;
33
34 static void
35 initable_iface_init (GInitableIface *iface);
36
G_DEFINE_TYPE_WITH_CODE(MetaKmsImplDeviceDummy,meta_kms_impl_device_dummy,META_TYPE_KMS_IMPL_DEVICE,G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,initable_iface_init))37 G_DEFINE_TYPE_WITH_CODE (MetaKmsImplDeviceDummy,
38 meta_kms_impl_device_dummy,
39 META_TYPE_KMS_IMPL_DEVICE,
40 G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
41 initable_iface_init))
42
43 static void
44 meta_kms_impl_device_dummy_discard_pending_page_flips (MetaKmsImplDevice *impl_device)
45 {
46 }
47
48 static MetaDeviceFile *
meta_kms_impl_device_dummy_open_device_file(MetaKmsImplDevice * impl_device,const char * path,GError ** error)49 meta_kms_impl_device_dummy_open_device_file (MetaKmsImplDevice *impl_device,
50 const char *path,
51 GError **error)
52 {
53 MetaKmsDevice *device = meta_kms_impl_device_get_device (impl_device);
54 MetaKms *kms = meta_kms_device_get_kms (device);
55 MetaBackend *backend = meta_kms_get_backend (kms);
56 MetaDevicePool *device_pool =
57 meta_backend_native_get_device_pool (META_BACKEND_NATIVE (backend));
58 g_autoptr (MetaDeviceFile) device_file = NULL;
59 int fd;
60 g_autofree char *render_node_path = NULL;
61
62 device_file = meta_device_pool_open (device_pool, path,
63 META_DEVICE_FILE_FLAG_NONE,
64 error);
65 if (!device_file)
66 return NULL;
67
68 fd = meta_device_file_get_fd (device_file);
69 render_node_path = drmGetRenderDeviceNameFromFd (fd);
70 if (!render_node_path)
71 {
72 g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
73 "Couldn't find render node device for '%s' (%s)",
74 meta_kms_impl_device_get_path (impl_device),
75 meta_kms_impl_device_get_driver_name (impl_device));
76 return NULL;
77 }
78
79 meta_topic (META_DEBUG_KMS, "Found render node '%s' from '%s'",
80 render_node_path, path);
81
82 return meta_device_pool_open (device_pool, render_node_path,
83 META_DEVICE_FILE_FLAG_NONE,
84 error);
85 }
86
87 static gboolean
meta_kms_impl_device_dummy_initable_init(GInitable * initable,GCancellable * cancellable,GError ** error)88 meta_kms_impl_device_dummy_initable_init (GInitable *initable,
89 GCancellable *cancellable,
90 GError **error)
91 {
92 MetaKmsImplDevice *impl_device = META_KMS_IMPL_DEVICE (initable);
93
94 if (!initable_parent_iface->init (initable, cancellable, error))
95 return FALSE;
96
97 g_message ("Added device '%s' (%s) using no mode setting.",
98 meta_kms_impl_device_get_path (impl_device),
99 meta_kms_impl_device_get_driver_name (impl_device));
100
101 return TRUE;
102 }
103
104 static void
initable_iface_init(GInitableIface * iface)105 initable_iface_init (GInitableIface *iface)
106 {
107 initable_parent_iface = g_type_interface_peek_parent (iface);
108
109 iface->init = meta_kms_impl_device_dummy_initable_init;
110 }
111
112 static void
meta_kms_impl_device_dummy_init(MetaKmsImplDeviceDummy * impl_device_dummy)113 meta_kms_impl_device_dummy_init (MetaKmsImplDeviceDummy *impl_device_dummy)
114 {
115 }
116
117 static void
meta_kms_impl_device_dummy_class_init(MetaKmsImplDeviceDummyClass * klass)118 meta_kms_impl_device_dummy_class_init (MetaKmsImplDeviceDummyClass *klass)
119 {
120 MetaKmsImplDeviceClass *impl_device_class =
121 META_KMS_IMPL_DEVICE_CLASS (klass);
122
123 impl_device_class->open_device_file =
124 meta_kms_impl_device_dummy_open_device_file;
125 impl_device_class->discard_pending_page_flips =
126 meta_kms_impl_device_dummy_discard_pending_page_flips;
127 }
128