summaryrefslogtreecommitdiff
path: root/src/backends/native/meta-kms-impl-device.h
blob: 20dc3cd0bc5ee4943cb4e33b42796307fe77205a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
 * Copyright (C) 2019 Red Hat
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 */

#ifndef META_KMS_IMPL_DEVICE_H
#define META_KMS_IMPL_DEVICE_H

#include <glib-object.h>
#include <stdint.h>
#include <xf86drm.h>
#include <xf86drmMode.h>

#include "backends/native/meta-device-pool.h"
#include "backends/native/meta-kms-device.h"
#include "backends/native/meta-kms-page-flip-private.h"
#include "backends/native/meta-kms-types.h"
#include "backends/native/meta-kms-update.h"
#include "backends/native/meta-kms.h"

typedef struct _MetaKmsDeviceCaps
{
  gboolean has_cursor_size;
  uint64_t cursor_width;
  uint64_t cursor_height;

  gboolean prefers_shadow_buffer;
  gboolean uses_monotonic_clock;
  gboolean addfb2_modifiers;
} MetaKmsDeviceCaps;


typedef struct _MetaKmsEnum
{
  const char *name;
  gboolean valid;
  uint64_t value;
  uint64_t bitmask;
} MetaKmsEnum;

typedef struct _MetaKmsProp MetaKmsProp;

struct _MetaKmsProp
{
  const char *name;
  uint32_t type;
  MetaKmsPropType internal_type;

  unsigned int num_enum_values;
  MetaKmsEnum *enum_values;
  uint64_t default_value;

  uint64_t range_min;
  uint64_t range_max;

  int64_t range_min_signed;
  int64_t range_max_signed;

  uint64_t supported_variants;

  uint32_t prop_id;
  uint64_t value;
};

#define META_TYPE_KMS_IMPL_DEVICE (meta_kms_impl_device_get_type ())
G_DECLARE_DERIVABLE_TYPE (MetaKmsImplDevice, meta_kms_impl_device,
                          META, KMS_IMPL_DEVICE,
                          GObject)

struct _MetaKmsImplDeviceClass
{
  GObjectClass parent_class;

  MetaDeviceFile * (* open_device_file) (MetaKmsImplDevice  *impl_device,
                                         const char         *path,
                                         GError            **error);
  void (* setup_drm_event_context) (MetaKmsImplDevice *impl_device,
                                    drmEventContext   *drm_event_context);
  MetaKmsFeedback * (* process_update) (MetaKmsImplDevice *impl_device,
                                        MetaKmsUpdate     *update,
                                        MetaKmsUpdateFlag  flags);
  void (* disable) (MetaKmsImplDevice *impl_device);
  void (* handle_page_flip_callback) (MetaKmsImplDevice   *impl_device,
                                      MetaKmsPageFlipData *page_flip_data);
  void (* discard_pending_page_flips) (MetaKmsImplDevice *impl_device);
  void (* prepare_shutdown) (MetaKmsImplDevice *impl_device);
};

enum
{
  META_KMS_ERROR_USER_INHIBITED,
  META_KMS_ERROR_DENY_LISTED,
  META_KMS_ERROR_NOT_SUPPORTED,
};

enum
{
  META_KMS_DEVICE_FILE_TAG_ATOMIC = 1 << 0,
  META_KMS_DEVICE_FILE_TAG_SIMPLE = 1 << 1,
};

#define META_KMS_ERROR meta_kms_error_quark ()
GQuark meta_kms_error_quark (void);

MetaKmsDevice * meta_kms_impl_device_get_device (MetaKmsImplDevice *impl_device);

GList * meta_kms_impl_device_copy_connectors (MetaKmsImplDevice *impl_device);

GList * meta_kms_impl_device_copy_crtcs (MetaKmsImplDevice *impl_device);

GList * meta_kms_impl_device_copy_planes (MetaKmsImplDevice *impl_device);

GList * meta_kms_impl_device_peek_connectors (MetaKmsImplDevice *impl_device);

GList * meta_kms_impl_device_peek_crtcs (MetaKmsImplDevice *impl_device);

GList * meta_kms_impl_device_peek_planes (MetaKmsImplDevice *impl_device);

const MetaKmsDeviceCaps * meta_kms_impl_device_get_caps (MetaKmsImplDevice *impl_device);

GList * meta_kms_impl_device_copy_fallback_modes (MetaKmsImplDevice *impl_device);

const char * meta_kms_impl_device_get_driver_name (MetaKmsImplDevice *impl_device);

const char * meta_kms_impl_device_get_driver_description (MetaKmsImplDevice *impl_device);

const char * meta_kms_impl_device_get_path (MetaKmsImplDevice *impl_device);

gboolean meta_kms_impl_device_dispatch (MetaKmsImplDevice  *impl_device,
                                        GError            **error);

void meta_kms_impl_device_disable (MetaKmsImplDevice *impl_device);

drmModePropertyPtr meta_kms_impl_device_find_property (MetaKmsImplDevice       *impl_device,
                                                       drmModeObjectProperties *props,
                                                       const char              *prop_name,
                                                       int                     *idx);

int meta_kms_impl_device_get_fd (MetaKmsImplDevice *impl_device);

void meta_kms_impl_device_hold_fd (MetaKmsImplDevice *impl_device);

void meta_kms_impl_device_unhold_fd (MetaKmsImplDevice *impl_device);

MetaKmsResourceChanges meta_kms_impl_device_update_states (MetaKmsImplDevice *impl_device,
                                                           uint32_t           crtc_id,
                                                           uint32_t           connector_id);

void meta_kms_impl_device_notify_modes_set (MetaKmsImplDevice *impl_device);

MetaKmsPlane * meta_kms_impl_device_add_fake_plane (MetaKmsImplDevice *impl_device,
                                                    MetaKmsPlaneType   plane_type,
                                                    MetaKmsCrtc       *crtc);

void meta_kms_impl_device_update_prop_table (MetaKmsImplDevice *impl_device,
                                             uint32_t          *drm_props,
                                             uint64_t          *drm_props_values,
                                             int                n_drm_props,
                                             MetaKmsProp       *props,
                                             int                n_props);

void meta_kms_impl_device_reload_prop_values (MetaKmsImplDevice *impl_device,
                                              uint32_t          *drm_props,
                                              uint64_t          *drm_prop_values,
                                              int                n_drm_props,
                                              gpointer           user_data,
                                              ...);

MetaKmsFeedback * meta_kms_impl_device_process_update (MetaKmsImplDevice *impl_device,
                                                       MetaKmsUpdate     *update,
                                                       MetaKmsUpdateFlag  flags)
  G_GNUC_WARN_UNUSED_RESULT;

void meta_kms_impl_device_handle_page_flip_callback (MetaKmsImplDevice   *impl_device,
                                                     MetaKmsPageFlipData *page_flip_data);

void meta_kms_impl_device_discard_pending_page_flips (MetaKmsImplDevice *impl_device);

gboolean meta_kms_impl_device_init_mode_setting (MetaKmsImplDevice  *impl_device,
                                                 GError            **error);

void meta_kms_impl_device_prepare_shutdown (MetaKmsImplDevice *impl_device);

uint64_t meta_kms_prop_convert_value (MetaKmsProp *prop,
                                      uint64_t     value);

#endif /* META_KMS_IMPL_DEVICE_H */