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"
49 #include "util/u_rect.h"
53 drmModeCrtcPtr drm_crtc
;
56 struct pipe_texture
*cursor_tex
;
57 unsigned cursor_handle
;
61 crtc_dpms(xf86CrtcPtr crtc
, int mode
)
63 //ScrnInfoPtr pScrn = crtc->scrn;
76 crtc_lock(xf86CrtcPtr crtc
)
82 crtc_unlock(xf86CrtcPtr crtc
)
87 crtc_prepare(xf86CrtcPtr crtc
)
92 crtc_commit(xf86CrtcPtr crtc
)
97 crtc_mode_fixup(xf86CrtcPtr crtc
, DisplayModePtr mode
,
98 DisplayModePtr adjusted_mode
)
104 crtc_mode_set(xf86CrtcPtr crtc
, DisplayModePtr mode
,
105 DisplayModePtr adjusted_mode
, int x
, int y
)
107 xf86CrtcConfigPtr config
= XF86_CRTC_CONFIG_PTR(crtc
->scrn
);
108 modesettingPtr ms
= modesettingPTR(crtc
->scrn
);
109 xf86OutputPtr output
= config
->output
[config
->compat_output
];
110 drmModeConnectorPtr drm_connector
= output
->driver_private
;
111 struct crtc_private
*crtcp
= crtc
->driver_private
;
112 drmModeCrtcPtr drm_crtc
= crtcp
->drm_crtc
;
113 drmModeModeInfo drm_mode
;
115 drm_mode
.clock
= mode
->Clock
;
116 drm_mode
.hdisplay
= mode
->HDisplay
;
117 drm_mode
.hsync_start
= mode
->HSyncStart
;
118 drm_mode
.hsync_end
= mode
->HSyncEnd
;
119 drm_mode
.htotal
= mode
->HTotal
;
120 drm_mode
.vdisplay
= mode
->VDisplay
;
121 drm_mode
.vsync_start
= mode
->VSyncStart
;
122 drm_mode
.vsync_end
= mode
->VSyncEnd
;
123 drm_mode
.vtotal
= mode
->VTotal
;
124 drm_mode
.flags
= mode
->Flags
;
125 drm_mode
.hskew
= mode
->HSkew
;
126 drm_mode
.vscan
= mode
->VScan
;
127 drm_mode
.vrefresh
= mode
->VRefresh
;
129 xf86SetModeDefaultName(mode
);
130 strncpy(drm_mode
.name
, mode
->name
, DRM_DISPLAY_MODE_LEN
);
132 drmModeSetCrtc(ms
->fd
, drm_crtc
->crtc_id
, ms
->fb_id
, x
, y
,
133 &drm_connector
->connector_id
, 1, &drm_mode
);
138 crtc_load_lut(xf86CrtcPtr crtc
)
140 //ScrnInfoPtr pScrn = crtc->scrn;
145 crtc_gamma_set(xf86CrtcPtr crtc
, CARD16
* red
, CARD16
* green
, CARD16
* blue
,
151 crtc_shadow_allocate(xf86CrtcPtr crtc
, int width
, int height
)
153 //ScrnInfoPtr pScrn = crtc->scrn;
159 crtc_shadow_create(xf86CrtcPtr crtc
, void *data
, int width
, int height
)
161 //ScrnInfoPtr pScrn = crtc->scrn;
167 crtc_shadow_destroy(xf86CrtcPtr crtc
, PixmapPtr rotate_pixmap
, void *data
)
169 //ScrnInfoPtr pScrn = crtc->scrn;
173 crtc_destroy(xf86CrtcPtr crtc
)
175 struct crtc_private
*crtcp
= crtc
->driver_private
;
177 if (crtcp
->cursor_tex
)
178 pipe_texture_reference(&crtcp
->cursor_tex
, NULL
);
180 drmModeFreeCrtc(crtcp
->drm_crtc
);
185 crtc_load_cursor_argb(xf86CrtcPtr crtc
, CARD32
* image
)
188 modesettingPtr ms
= modesettingPTR(crtc
->scrn
);
189 struct crtc_private
*crtcp
= crtc
->driver_private
;
190 struct pipe_transfer
*transfer
;
192 if (!crtcp
->cursor_tex
) {
193 struct pipe_texture templat
;
196 memset(&templat
, 0, sizeof(templat
));
197 templat
.tex_usage
|= PIPE_TEXTURE_USAGE_RENDER_TARGET
;
198 templat
.tex_usage
|= PIPE_TEXTURE_USAGE_PRIMARY
;
199 templat
.target
= PIPE_TEXTURE_2D
;
200 templat
.last_level
= 0;
201 templat
.depth
[0] = 1;
202 templat
.format
= PIPE_FORMAT_A8R8G8B8_UNORM
;
203 templat
.width
[0] = 64;
204 templat
.height
[0] = 64;
205 pf_get_block(templat
.format
, &templat
.block
);
207 crtcp
->cursor_tex
= ms
->screen
->texture_create(ms
->screen
,
209 ms
->api
->local_handle_from_texture(ms
->api
,
213 &crtcp
->cursor_handle
);
216 transfer
= ms
->screen
->get_tex_transfer(ms
->screen
, crtcp
->cursor_tex
,
220 ptr
= ms
->screen
->transfer_map(ms
->screen
, transfer
);
221 util_copy_rect(ptr
, &crtcp
->cursor_tex
->block
,
222 transfer
->stride
, 0, 0,
223 64, 64, (void*)image
, 64 * 4, 0, 0);
224 ms
->screen
->transfer_unmap(ms
->screen
, transfer
);
225 ms
->screen
->tex_transfer_destroy(transfer
);
229 crtc_set_cursor_position(xf86CrtcPtr crtc
, int x
, int y
)
231 modesettingPtr ms
= modesettingPTR(crtc
->scrn
);
232 struct crtc_private
*crtcp
= crtc
->driver_private
;
234 drmModeMoveCursor(ms
->fd
, crtcp
->drm_crtc
->crtc_id
, x
, y
);
238 crtc_show_cursor(xf86CrtcPtr crtc
)
240 modesettingPtr ms
= modesettingPTR(crtc
->scrn
);
241 struct crtc_private
*crtcp
= crtc
->driver_private
;
243 if (crtcp
->cursor_tex
)
244 drmModeSetCursor(ms
->fd
, crtcp
->drm_crtc
->crtc_id
,
245 crtcp
->cursor_handle
, 64, 64);
249 crtc_hide_cursor(xf86CrtcPtr crtc
)
251 modesettingPtr ms
= modesettingPTR(crtc
->scrn
);
252 struct crtc_private
*crtcp
= crtc
->driver_private
;
254 drmModeSetCursor(ms
->fd
, crtcp
->drm_crtc
->crtc_id
, 0, 0, 0);
257 static const xf86CrtcFuncsRec crtc_funcs
= {
262 .unlock
= crtc_unlock
,
263 .mode_fixup
= crtc_mode_fixup
,
264 .prepare
= crtc_prepare
,
265 .mode_set
= crtc_mode_set
,
266 .commit
= crtc_commit
,
267 .gamma_set
= crtc_gamma_set
,
268 .shadow_create
= crtc_shadow_create
,
269 .shadow_allocate
= crtc_shadow_allocate
,
270 .shadow_destroy
= crtc_shadow_destroy
,
271 .set_cursor_position
= crtc_set_cursor_position
,
272 .show_cursor
= crtc_show_cursor
,
273 .hide_cursor
= crtc_hide_cursor
,
274 .load_cursor_image
= NULL
, /* lets convert to argb only */
275 .set_cursor_colors
= NULL
, /* using argb only */
276 .load_cursor_argb
= crtc_load_cursor_argb
,
277 .destroy
= crtc_destroy
,
281 crtc_cursor_destroy(xf86CrtcPtr crtc
)
283 struct crtc_private
*crtcp
= crtc
->driver_private
;
285 if (crtcp
->cursor_tex
) {
286 pipe_texture_reference(&crtcp
->cursor_tex
, NULL
);
291 crtc_init(ScrnInfoPtr pScrn
)
293 modesettingPtr ms
= modesettingPTR(pScrn
);
296 drmModeCrtcPtr drm_crtc
= NULL
;
297 struct crtc_private
*crtcp
;
300 res
= drmModeGetResources(ms
->fd
);
302 ErrorF("Failed drmModeGetResources %d\n", errno
);
306 for (c
= 0; c
< res
->count_crtcs
; c
++) {
307 drm_crtc
= drmModeGetCrtc(ms
->fd
, res
->crtcs
[c
]);
311 crtc
= xf86CrtcCreate(pScrn
, &crtc_funcs
);
315 crtcp
= xcalloc(1, sizeof(struct crtc_private
));
317 xf86CrtcDestroy(crtc
);
321 crtcp
->drm_crtc
= drm_crtc
;
323 crtc
->driver_private
= crtcp
;
328 drmModeFreeResources(res
);
331 /* vim: set sw=4 ts=8 sts=4: */