1 /*
2  * Copyright (C) 2017 Red Hat
3  * Copyright (C) 2020 NVIDIA CORPORATION
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of the
8  * License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18  * 02111-1307, USA.
19  */
20 
21 #ifndef META_OUTPUT_H
22 #define META_OUTPUT_H
23 
24 #include <glib-object.h>
25 
26 #include "backends/meta-backend-types.h"
27 #include "backends/meta-gpu.h"
28 #include "core/util-private.h"
29 
30 struct _MetaTileInfo
31 {
32   uint32_t group_id;
33   uint32_t flags;
34   uint32_t max_h_tiles;
35   uint32_t max_v_tiles;
36   uint32_t loc_h_tile;
37   uint32_t loc_v_tile;
38   uint32_t tile_w;
39   uint32_t tile_h;
40 };
41 
42 /* The first 17 matches the values in drm_mode.h, the ones starting with
43  * 1000 do not. */
44 typedef enum
45 {
46   META_CONNECTOR_TYPE_Unknown = 0,
47   META_CONNECTOR_TYPE_VGA = 1,
48   META_CONNECTOR_TYPE_DVII = 2,
49   META_CONNECTOR_TYPE_DVID = 3,
50   META_CONNECTOR_TYPE_DVIA = 4,
51   META_CONNECTOR_TYPE_Composite = 5,
52   META_CONNECTOR_TYPE_SVIDEO = 6,
53   META_CONNECTOR_TYPE_LVDS = 7,
54   META_CONNECTOR_TYPE_Component = 8,
55   META_CONNECTOR_TYPE_9PinDIN = 9,
56   META_CONNECTOR_TYPE_DisplayPort = 10,
57   META_CONNECTOR_TYPE_HDMIA = 11,
58   META_CONNECTOR_TYPE_HDMIB = 12,
59   META_CONNECTOR_TYPE_TV = 13,
60   META_CONNECTOR_TYPE_eDP = 14,
61   META_CONNECTOR_TYPE_VIRTUAL = 15,
62   META_CONNECTOR_TYPE_DSI = 16,
63 
64   META_CONNECTOR_TYPE_META = 1000,
65 } MetaConnectorType;
66 
67 typedef struct _MetaOutputInfo
68 {
69   grefcount ref_count;
70 
71   char *name;
72   char *vendor;
73   char *product;
74   char *serial;
75   int width_mm;
76   int height_mm;
77   CoglSubpixelOrder subpixel_order;
78 
79   MetaConnectorType connector_type;
80   MetaMonitorTransform panel_orientation_transform;
81 
82   MetaCrtcMode *preferred_mode;
83   MetaCrtcMode **modes;
84   unsigned int n_modes;
85 
86   MetaCrtc **possible_crtcs;
87   unsigned int n_possible_crtcs;
88 
89   MetaOutput **possible_clones;
90   unsigned int n_possible_clones;
91 
92   int backlight_min;
93   int backlight_max;
94 
95   gboolean supports_underscanning;
96   gboolean supports_color_transform;
97 
98   /*
99    * Get a new preferred mode on hotplug events, to handle dynamic guest
100    * resizing.
101    */
102   gboolean hotplug_mode_update;
103   int suggested_x;
104   int suggested_y;
105 
106   MetaTileInfo tile_info;
107 } MetaOutputInfo;
108 
109 gboolean
110 meta_tile_info_equal (MetaTileInfo *a,
111                       MetaTileInfo *b);
112 
113 #define META_TYPE_OUTPUT_INFO (meta_output_info_get_type ())
114 META_EXPORT_TEST
115 GType meta_output_info_get_type (void);
116 
117 META_EXPORT_TEST
118 MetaOutputInfo * meta_output_info_new (void);
119 
120 META_EXPORT_TEST
121 MetaOutputInfo * meta_output_info_ref (MetaOutputInfo *output_info);
122 
123 META_EXPORT_TEST
124 void meta_output_info_unref (MetaOutputInfo *output_info);
125 
126 META_EXPORT_TEST
127 void meta_output_info_parse_edid (MetaOutputInfo *output_info,
128                                   GBytes         *edid);
129 
130 gboolean meta_output_is_laptop  (MetaOutput *output);
131 
132 G_DEFINE_AUTOPTR_CLEANUP_FUNC (MetaOutputInfo, meta_output_info_unref)
133 
134 #define META_TYPE_OUTPUT (meta_output_get_type ())
135 META_EXPORT_TEST
136 G_DECLARE_DERIVABLE_TYPE (MetaOutput, meta_output, META, OUTPUT, GObject)
137 
138 struct _MetaOutputClass
139 {
140   GObjectClass parent_class;
141 };
142 
143 META_EXPORT_TEST
144 uint64_t meta_output_get_id (MetaOutput *output);
145 
146 META_EXPORT_TEST
147 MetaGpu * meta_output_get_gpu (MetaOutput *output);
148 
149 META_EXPORT_TEST
150 MetaMonitor * meta_output_get_monitor (MetaOutput *output);
151 
152 void meta_output_set_monitor (MetaOutput  *output,
153                               MetaMonitor *monitor);
154 
155 void meta_output_unset_monitor (MetaOutput *output);
156 
157 const char * meta_output_get_name (MetaOutput *output);
158 
159 META_EXPORT_TEST
160 gboolean meta_output_is_primary (MetaOutput *output);
161 
162 META_EXPORT_TEST
163 gboolean meta_output_is_presentation (MetaOutput *output);
164 
165 META_EXPORT_TEST
166 gboolean meta_output_is_underscanning (MetaOutput *output);
167 
168 void meta_output_set_backlight (MetaOutput *output,
169                                 int         backlight);
170 
171 int meta_output_get_backlight (MetaOutput *output);
172 
173 void meta_output_add_possible_clone (MetaOutput *output,
174                                      MetaOutput *possible_clone);
175 
176 META_EXPORT_TEST
177 const MetaOutputInfo * meta_output_get_info (MetaOutput *output);
178 
179 META_EXPORT_TEST
180 void meta_output_assign_crtc (MetaOutput                 *output,
181                               MetaCrtc                   *crtc,
182                               const MetaOutputAssignment *output_assignment);
183 
184 META_EXPORT_TEST
185 void meta_output_unassign_crtc (MetaOutput *output);
186 
187 META_EXPORT_TEST
188 MetaCrtc * meta_output_get_assigned_crtc (MetaOutput *output);
189 
190 MetaMonitorTransform meta_output_logical_to_crtc_transform (MetaOutput           *output,
191                                                             MetaMonitorTransform  transform);
192 
193 MetaMonitorTransform meta_output_crtc_to_logical_transform (MetaOutput           *output,
194                                                             MetaMonitorTransform  transform);
195 
196 #endif /* META_OUTPUT_H */
197