mesa: Add "shader/" path to #include statements in shader parser/lexer sources
[mesa.git] / src / gallium / state_trackers / xorg / xorg_output.c
1 /*
2 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
15 * of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 *
25 *
26 * Author: Alan Hourihane <alanh@tungstengraphics.com>
27 * Author: Jakob Bornecrantz <wallbraker@gmail.com>
28 *
29 */
30
31 #include "xorg-server.h"
32 #include <xf86.h>
33 #include <xf86i2c.h>
34 #include <xf86Crtc.h>
35 #include <errno.h>
36 #include <fcntl.h>
37 #include <unistd.h>
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <stdint.h>
41 #include <string.h>
42 #include <sys/stat.h>
43 #include <sys/types.h>
44
45 #ifdef HAVE_XEXTPROTO_71
46 #include <X11/extensions/dpmsconst.h>
47 #else
48 #define DPMS_SERVER
49 #include <X11/extensions/dpms.h>
50 #endif
51
52 #include "X11/Xatom.h"
53
54 #include "xorg_tracker.h"
55
56 static char *output_enum_list[] = {
57 "Unknown",
58 "VGA",
59 "DVI",
60 "DVI",
61 "DVI",
62 "Composite",
63 "SVIDEO",
64 "LVDS",
65 "CTV",
66 "DIN",
67 "DP",
68 "HDMI",
69 "HDMI",
70 };
71
72 static void
73 output_create_resources(xf86OutputPtr output)
74 {
75 #ifdef RANDR_12_INTERFACE
76 #endif /* RANDR_12_INTERFACE */
77 }
78
79 static void
80 output_dpms(xf86OutputPtr output, int mode)
81 {
82 }
83
84 static xf86OutputStatus
85 output_detect(xf86OutputPtr output)
86 {
87 drmModeConnectorPtr drm_connector = output->driver_private;
88
89 switch (drm_connector->connection) {
90 case DRM_MODE_CONNECTED:
91 return XF86OutputStatusConnected;
92 case DRM_MODE_DISCONNECTED:
93 return XF86OutputStatusDisconnected;
94 default:
95 return XF86OutputStatusUnknown;
96 }
97 }
98
99 static DisplayModePtr
100 output_get_modes(xf86OutputPtr output)
101 {
102 drmModeConnectorPtr drm_connector = output->driver_private;
103 drmModeModeInfoPtr drm_mode = NULL;
104 DisplayModePtr modes = NULL, mode = NULL;
105 int i;
106
107 for (i = 0; i < drm_connector->count_modes; i++) {
108 drm_mode = &drm_connector->modes[i];
109 if (drm_mode) {
110 mode = xcalloc(1, sizeof(DisplayModeRec));
111 if (!mode)
112 continue;
113 mode->Clock = drm_mode->clock;
114 mode->HDisplay = drm_mode->hdisplay;
115 mode->HSyncStart = drm_mode->hsync_start;
116 mode->HSyncEnd = drm_mode->hsync_end;
117 mode->HTotal = drm_mode->htotal;
118 mode->VDisplay = drm_mode->vdisplay;
119 mode->VSyncStart = drm_mode->vsync_start;
120 mode->VSyncEnd = drm_mode->vsync_end;
121 mode->VTotal = drm_mode->vtotal;
122 mode->Flags = drm_mode->flags;
123 mode->HSkew = drm_mode->hskew;
124 mode->VScan = drm_mode->vscan;
125 mode->VRefresh = xf86ModeVRefresh(mode);
126 mode->Private = (void *)drm_mode;
127 mode->type = 0;
128 if (drm_mode->type & DRM_MODE_TYPE_PREFERRED)
129 mode->type |= M_T_PREFERRED;
130 if (drm_mode->type & DRM_MODE_TYPE_DRIVER)
131 mode->type |= M_T_DRIVER;
132 xf86SetModeDefaultName(mode);
133 modes = xf86ModesAdd(modes, mode);
134 xf86PrintModeline(0, mode);
135 }
136 }
137
138 return modes;
139 }
140
141 static int
142 output_mode_valid(xf86OutputPtr output, DisplayModePtr pMode)
143 {
144 return MODE_OK;
145 }
146
147 #ifdef RANDR_12_INTERFACE
148 static Bool
149 output_set_property(xf86OutputPtr output, Atom property, RRPropertyValuePtr value)
150 {
151 return TRUE;
152 }
153 #endif /* RANDR_12_INTERFACE */
154
155 #ifdef RANDR_13_INTERFACE
156 static Bool
157 output_get_property(xf86OutputPtr output, Atom property)
158 {
159 return TRUE;
160 }
161 #endif /* RANDR_13_INTERFACE */
162
163 static void
164 output_destroy(xf86OutputPtr output)
165 {
166 drmModeFreeConnector(output->driver_private);
167 }
168
169 static const xf86OutputFuncsRec output_funcs = {
170 .create_resources = output_create_resources,
171 #ifdef RANDR_12_INTERFACE
172 .set_property = output_set_property,
173 #endif
174 #ifdef RANDR_13_INTERFACE
175 .get_property = output_get_property,
176 #endif
177 .dpms = output_dpms,
178 .detect = output_detect,
179
180 .get_modes = output_get_modes,
181 .mode_valid = output_mode_valid,
182 .destroy = output_destroy,
183 };
184
185 void
186 xorg_output_init(ScrnInfoPtr pScrn)
187 {
188 modesettingPtr ms = modesettingPTR(pScrn);
189 xf86OutputPtr output;
190 drmModeResPtr res;
191 drmModeConnectorPtr drm_connector = NULL;
192 drmModeEncoderPtr drm_encoder = NULL;
193 char name[32];
194 int c, v, p;
195
196 res = drmModeGetResources(ms->fd);
197 if (res == 0) {
198 DRV_ERROR("Failed drmModeGetResources\n");
199 return;
200 }
201
202 for (c = 0; c < res->count_connectors; c++) {
203 drm_connector = drmModeGetConnector(ms->fd, res->connectors[c]);
204 if (!drm_connector)
205 goto out;
206
207 #if 0
208 for (p = 0; p < drm_connector->count_props; p++) {
209 drmModePropertyPtr prop;
210
211 prop = drmModeGetProperty(ms->fd, drm_connector->props[p]);
212
213 name = NULL;
214 if (prop) {
215 ErrorF("VALUES %d\n", prop->count_values);
216
217 for (v = 0; v < prop->count_values; v++)
218 ErrorF("%s %lld\n", prop->name, prop->values[v]);
219 }
220 }
221 #else
222 (void)p;
223 (void)v;
224 #endif
225
226 snprintf(name, 32, "%s%d",
227 output_enum_list[drm_connector->connector_type],
228 drm_connector->connector_type_id);
229
230
231 output = xf86OutputCreate(pScrn, &output_funcs, name);
232 if (!output)
233 continue;
234
235 drm_encoder = drmModeGetEncoder(ms->fd, drm_connector->encoders[0]);
236 if (drm_encoder) {
237 output->possible_crtcs = drm_encoder->possible_crtcs;
238 output->possible_clones = drm_encoder->possible_clones;
239 } else {
240 output->possible_crtcs = 0;
241 output->possible_clones = 0;
242 }
243 output->driver_private = drm_connector;
244 output->subpixel_order = SubPixelHorizontalRGB;
245 output->interlaceAllowed = FALSE;
246 output->doubleScanAllowed = FALSE;
247 }
248
249 out:
250 drmModeFreeResources(res);
251 }
252
253 /* vim: set sw=4 ts=8 sts=4: */