2 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
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.
26 * Author: Alan Hourihane <alanh@tungstengraphics.com>
27 * Author: Jakob Bornecrantz <wallbraker@gmail.com>
38 #include "xorg-server.h"
42 #include "xorg_tracker.h"
43 #include "xf86Modes.h"
46 #include <X11/extensions/dpms.h>
48 #include "pipe/p_inlines.h"
52 drmModeCrtcPtr drm_crtc
;
55 struct pipe_buffer
*cursor_buf
;
56 unsigned cursor_handle
;
60 crtc_dpms(xf86CrtcPtr crtc
, int mode
)
62 //ScrnInfoPtr pScrn = crtc->scrn;
75 crtc_lock(xf86CrtcPtr crtc
)
81 crtc_unlock(xf86CrtcPtr crtc
)
86 crtc_prepare(xf86CrtcPtr crtc
)
91 crtc_commit(xf86CrtcPtr crtc
)
96 crtc_mode_fixup(xf86CrtcPtr crtc
, DisplayModePtr mode
,
97 DisplayModePtr adjusted_mode
)
103 crtc_mode_set(xf86CrtcPtr crtc
, DisplayModePtr mode
,
104 DisplayModePtr adjusted_mode
, int x
, int y
)
106 xf86CrtcConfigPtr config
= XF86_CRTC_CONFIG_PTR(crtc
->scrn
);
107 modesettingPtr ms
= modesettingPTR(crtc
->scrn
);
108 xf86OutputPtr output
= config
->output
[config
->compat_output
];
109 drmModeConnectorPtr drm_connector
= output
->driver_private
;
110 struct crtc_private
*crtcp
= crtc
->driver_private
;
111 drmModeCrtcPtr drm_crtc
= crtcp
->drm_crtc
;
112 drmModeModeInfo drm_mode
;
114 drm_mode
.clock
= mode
->Clock
;
115 drm_mode
.hdisplay
= mode
->HDisplay
;
116 drm_mode
.hsync_start
= mode
->HSyncStart
;
117 drm_mode
.hsync_end
= mode
->HSyncEnd
;
118 drm_mode
.htotal
= mode
->HTotal
;
119 drm_mode
.vdisplay
= mode
->VDisplay
;
120 drm_mode
.vsync_start
= mode
->VSyncStart
;
121 drm_mode
.vsync_end
= mode
->VSyncEnd
;
122 drm_mode
.vtotal
= mode
->VTotal
;
123 drm_mode
.flags
= mode
->Flags
;
124 drm_mode
.hskew
= mode
->HSkew
;
125 drm_mode
.vscan
= mode
->VScan
;
126 drm_mode
.vrefresh
= mode
->VRefresh
;
128 xf86SetModeDefaultName(mode
);
129 strncpy(drm_mode
.name
, mode
->name
, DRM_DISPLAY_MODE_LEN
);
131 drmModeSetCrtc(ms
->fd
, drm_crtc
->crtc_id
, ms
->fb_id
, x
, y
,
132 &drm_connector
->connector_id
, 1, &drm_mode
);
137 crtc_load_lut(xf86CrtcPtr crtc
)
139 //ScrnInfoPtr pScrn = crtc->scrn;
144 crtc_gamma_set(xf86CrtcPtr crtc
, CARD16
* red
, CARD16
* green
, CARD16
* blue
,
150 crtc_shadow_allocate(xf86CrtcPtr crtc
, int width
, int height
)
152 //ScrnInfoPtr pScrn = crtc->scrn;
158 crtc_shadow_create(xf86CrtcPtr crtc
, void *data
, int width
, int height
)
160 //ScrnInfoPtr pScrn = crtc->scrn;
166 crtc_shadow_destroy(xf86CrtcPtr crtc
, PixmapPtr rotate_pixmap
, void *data
)
168 //ScrnInfoPtr pScrn = crtc->scrn;
172 crtc_destroy(xf86CrtcPtr crtc
)
174 struct crtc_private
*crtcp
= crtc
->driver_private
;
176 if (crtcp
->cursor_buf
)
177 pipe_buffer_reference(&crtcp
->cursor_buf
, NULL
);
179 drmModeFreeCrtc(crtcp
->drm_crtc
);
184 crtc_load_cursor_argb(xf86CrtcPtr crtc
, CARD32
* image
)
187 modesettingPtr ms
= modesettingPTR(crtc
->scrn
);
188 struct crtc_private
*crtcp
= crtc
->driver_private
;
190 if (!crtcp
->cursor_buf
) {
191 crtcp
->cursor_buf
= pipe_buffer_create(ms
->screen
,
193 PIPE_BUFFER_USAGE_CPU_WRITE
|
194 PIPE_BUFFER_USAGE_GPU_READ
,
196 ms
->api
->handle_from_buffer(ms
->api
,
199 &crtcp
->cursor_handle
);
202 ptr
= pipe_buffer_map(ms
->screen
, crtcp
->cursor_buf
, PIPE_BUFFER_USAGE_CPU_WRITE
);
205 memcpy(ptr
, image
, 64 * 64 * 4);
207 pipe_buffer_unmap(ms
->screen
, crtcp
->cursor_buf
);
211 crtc_set_cursor_position(xf86CrtcPtr crtc
, int x
, int y
)
213 modesettingPtr ms
= modesettingPTR(crtc
->scrn
);
214 struct crtc_private
*crtcp
= crtc
->driver_private
;
216 drmModeMoveCursor(ms
->fd
, crtcp
->drm_crtc
->crtc_id
, x
, y
);
220 crtc_show_cursor(xf86CrtcPtr crtc
)
222 modesettingPtr ms
= modesettingPTR(crtc
->scrn
);
223 struct crtc_private
*crtcp
= crtc
->driver_private
;
225 if (crtcp
->cursor_buf
)
226 drmModeSetCursor(ms
->fd
, crtcp
->drm_crtc
->crtc_id
,
227 crtcp
->cursor_handle
, 64, 64);
231 crtc_hide_cursor(xf86CrtcPtr crtc
)
233 modesettingPtr ms
= modesettingPTR(crtc
->scrn
);
234 struct crtc_private
*crtcp
= crtc
->driver_private
;
236 drmModeSetCursor(ms
->fd
, crtcp
->drm_crtc
->crtc_id
, 0, 0, 0);
239 static const xf86CrtcFuncsRec crtc_funcs
= {
244 .unlock
= crtc_unlock
,
245 .mode_fixup
= crtc_mode_fixup
,
246 .prepare
= crtc_prepare
,
247 .mode_set
= crtc_mode_set
,
248 .commit
= crtc_commit
,
249 .gamma_set
= crtc_gamma_set
,
250 .shadow_create
= crtc_shadow_create
,
251 .shadow_allocate
= crtc_shadow_allocate
,
252 .shadow_destroy
= crtc_shadow_destroy
,
253 .set_cursor_position
= crtc_set_cursor_position
,
254 .show_cursor
= crtc_show_cursor
,
255 .hide_cursor
= crtc_hide_cursor
,
256 .load_cursor_image
= NULL
, /* lets convert to argb only */
257 .set_cursor_colors
= NULL
, /* using argb only */
258 .load_cursor_argb
= crtc_load_cursor_argb
,
259 .destroy
= crtc_destroy
,
263 cursor_destroy(xf86CrtcPtr crtc
)
265 modesettingPtr ms
= modesettingPTR(crtc
->scrn
);
266 struct crtc_private
*crtcp
= crtc
->driver_private
;
268 if (crtcp
->cursor_buf
) {
269 pipe_buffer_reference(&crtcp
->cursor_buf
, NULL
);
274 crtc_init(ScrnInfoPtr pScrn
)
276 modesettingPtr ms
= modesettingPTR(pScrn
);
279 drmModeCrtcPtr drm_crtc
= NULL
;
280 struct crtc_private
*crtcp
;
283 res
= drmModeGetResources(ms
->fd
);
285 ErrorF("Failed drmModeGetResources %d\n", errno
);
289 for (c
= 0; c
< res
->count_crtcs
; c
++) {
290 drm_crtc
= drmModeGetCrtc(ms
->fd
, res
->crtcs
[c
]);
294 crtc
= xf86CrtcCreate(pScrn
, &crtc_funcs
);
298 crtcp
= xcalloc(1, sizeof(struct crtc_private
));
300 xf86CrtcDestroy(crtc
);
304 crtcp
->drm_crtc
= drm_crtc
;
306 crtc
->driver_private
= crtcp
;
311 drmModeFreeResources(res
);
314 /* vim: set sw=4 ts=8 sts=4: */