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"
45 #ifdef HAVE_XEXTPROTO_71
46 #include <X11/extensions/dpmsconst.h>
49 #include <X11/extensions/dpms.h>
52 #include "pipe/p_inlines.h"
53 #include "util/u_format.h"
54 #include "util/u_rect.h"
62 drmModeCrtcPtr drm_crtc
;
65 struct pipe_texture
*cursor_tex
;
66 struct kms_bo
*cursor_bo
;
68 unsigned cursor_handle
;
72 crtc_dpms(xf86CrtcPtr crtc
, int mode
)
85 crtc_set_mode_major(xf86CrtcPtr crtc
, DisplayModePtr mode
,
86 Rotation rotation
, int x
, int y
)
88 xf86CrtcConfigPtr config
= XF86_CRTC_CONFIG_PTR(crtc
->scrn
);
89 modesettingPtr ms
= modesettingPTR(crtc
->scrn
);
90 xf86OutputPtr output
= NULL
;
91 drmModeConnectorPtr drm_connector
;
92 struct crtc_private
*crtcp
= crtc
->driver_private
;
93 drmModeCrtcPtr drm_crtc
= crtcp
->drm_crtc
;
94 drmModeModeInfo drm_mode
;
97 for (i
= 0; i
< config
->num_output
; output
= NULL
, i
++) {
98 output
= config
->output
[i
];
100 if (output
->crtc
== crtc
)
107 drm_connector
= output
->driver_private
;
109 drm_mode
.clock
= mode
->Clock
;
110 drm_mode
.hdisplay
= mode
->HDisplay
;
111 drm_mode
.hsync_start
= mode
->HSyncStart
;
112 drm_mode
.hsync_end
= mode
->HSyncEnd
;
113 drm_mode
.htotal
= mode
->HTotal
;
114 drm_mode
.vdisplay
= mode
->VDisplay
;
115 drm_mode
.vsync_start
= mode
->VSyncStart
;
116 drm_mode
.vsync_end
= mode
->VSyncEnd
;
117 drm_mode
.vtotal
= mode
->VTotal
;
118 drm_mode
.flags
= mode
->Flags
;
119 drm_mode
.hskew
= mode
->HSkew
;
120 drm_mode
.vscan
= mode
->VScan
;
121 drm_mode
.vrefresh
= mode
->VRefresh
;
123 xf86SetModeDefaultName(mode
);
124 strncpy(drm_mode
.name
, mode
->name
, DRM_DISPLAY_MODE_LEN
);
126 ret
= drmModeSetCrtc(ms
->fd
, drm_crtc
->crtc_id
, ms
->fb_id
, x
, y
,
127 &drm_connector
->connector_id
, 1, &drm_mode
);
135 crtc
->rotation
= rotation
;
141 crtc_gamma_set(xf86CrtcPtr crtc
, CARD16
* red
, CARD16
* green
, CARD16
* blue
,
148 crtc_shadow_allocate(xf86CrtcPtr crtc
, int width
, int height
)
154 crtc_shadow_create(xf86CrtcPtr crtc
, void *data
, int width
, int height
)
160 crtc_shadow_destroy(xf86CrtcPtr crtc
, PixmapPtr rotate_pixmap
, void *data
)
169 crtc_set_cursor_colors(xf86CrtcPtr crtc
, int bg
, int fg
)
171 /* XXX: See if this one is needed, as we only support ARGB cursors */
175 crtc_set_cursor_position(xf86CrtcPtr crtc
, int x
, int y
)
177 modesettingPtr ms
= modesettingPTR(crtc
->scrn
);
178 struct crtc_private
*crtcp
= crtc
->driver_private
;
180 drmModeMoveCursor(ms
->fd
, crtcp
->drm_crtc
->crtc_id
, x
, y
);
184 crtc_load_cursor_argb_ga3d(xf86CrtcPtr crtc
, CARD32
* image
)
187 modesettingPtr ms
= modesettingPTR(crtc
->scrn
);
188 struct crtc_private
*crtcp
= crtc
->driver_private
;
189 struct pipe_transfer
*transfer
;
191 if (!crtcp
->cursor_tex
) {
192 struct pipe_texture templat
;
195 memset(&templat
, 0, sizeof(templat
));
196 templat
.tex_usage
|= PIPE_TEXTURE_USAGE_RENDER_TARGET
;
197 templat
.tex_usage
|= PIPE_TEXTURE_USAGE_PRIMARY
;
198 templat
.target
= PIPE_TEXTURE_2D
;
199 templat
.last_level
= 0;
201 templat
.format
= PIPE_FORMAT_A8R8G8B8_UNORM
;
203 templat
.height0
= 64;
205 crtcp
->cursor_tex
= ms
->screen
->texture_create(ms
->screen
,
207 ms
->api
->local_handle_from_texture(ms
->api
,
211 &crtcp
->cursor_handle
);
214 transfer
= ms
->screen
->get_tex_transfer(ms
->screen
, crtcp
->cursor_tex
,
218 ptr
= ms
->screen
->transfer_map(ms
->screen
, transfer
);
219 util_copy_rect(ptr
, crtcp
->cursor_tex
->format
,
220 transfer
->stride
, 0, 0,
221 64, 64, (void*)image
, 64 * 4, 0, 0);
222 ms
->screen
->transfer_unmap(ms
->screen
, transfer
);
223 ms
->screen
->tex_transfer_destroy(transfer
);
228 crtc_load_cursor_argb_kms(xf86CrtcPtr crtc
, CARD32
* image
)
230 modesettingPtr ms
= modesettingPTR(crtc
->scrn
);
231 struct crtc_private
*crtcp
= crtc
->driver_private
;
234 if (!crtcp
->cursor_bo
) {
237 attr
[0] = KMS_BO_TYPE
;
238 attr
[1] = KMS_BO_TYPE_CURSOR
;
241 attr
[4] = KMS_HEIGHT
;
245 if (kms_bo_create(ms
->kms
, attr
, &crtcp
->cursor_bo
))
248 if (kms_bo_get_prop(crtcp
->cursor_bo
, KMS_HANDLE
,
249 &crtcp
->cursor_handle
))
253 kms_bo_map(crtcp
->cursor_bo
, (void**)&ptr
);
254 memcpy(ptr
, image
, 64*64*4);
255 kms_bo_unmap(crtcp
->cursor_bo
);
260 kms_bo_destroy(&crtcp
->cursor_bo
);
265 crtc_load_cursor_argb(xf86CrtcPtr crtc
, CARD32
* image
)
267 modesettingPtr ms
= modesettingPTR(crtc
->scrn
);
269 crtc_load_cursor_argb_ga3d(crtc
, image
);
272 crtc_load_cursor_argb_kms(crtc
, image
);
277 crtc_show_cursor(xf86CrtcPtr crtc
)
279 modesettingPtr ms
= modesettingPTR(crtc
->scrn
);
280 struct crtc_private
*crtcp
= crtc
->driver_private
;
282 if (crtcp
->cursor_tex
|| crtcp
->cursor_bo
)
283 drmModeSetCursor(ms
->fd
, crtcp
->drm_crtc
->crtc_id
,
284 crtcp
->cursor_handle
, 64, 64);
288 crtc_hide_cursor(xf86CrtcPtr crtc
)
290 modesettingPtr ms
= modesettingPTR(crtc
->scrn
);
291 struct crtc_private
*crtcp
= crtc
->driver_private
;
293 drmModeSetCursor(ms
->fd
, crtcp
->drm_crtc
->crtc_id
, 0, 0, 0);
300 xorg_crtc_cursor_destroy(xf86CrtcPtr crtc
)
302 struct crtc_private
*crtcp
= crtc
->driver_private
;
304 if (crtcp
->cursor_tex
)
305 pipe_texture_reference(&crtcp
->cursor_tex
, NULL
);
307 if (crtcp
->cursor_bo
)
308 kms_bo_destroy(&crtcp
->cursor_bo
);
317 crtc_destroy(xf86CrtcPtr crtc
)
319 struct crtc_private
*crtcp
= crtc
->driver_private
;
321 xorg_crtc_cursor_destroy(crtc
);
323 drmModeFreeCrtc(crtcp
->drm_crtc
);
326 crtc
->driver_private
= NULL
;
329 static const xf86CrtcFuncsRec crtc_funcs
= {
331 .set_mode_major
= crtc_set_mode_major
,
333 .set_cursor_colors
= crtc_set_cursor_colors
,
334 .set_cursor_position
= crtc_set_cursor_position
,
335 .show_cursor
= crtc_show_cursor
,
336 .hide_cursor
= crtc_hide_cursor
,
337 .load_cursor_argb
= crtc_load_cursor_argb
,
339 .shadow_create
= crtc_shadow_create
,
340 .shadow_allocate
= crtc_shadow_allocate
,
341 .shadow_destroy
= crtc_shadow_destroy
,
343 .gamma_set
= crtc_gamma_set
,
344 .destroy
= crtc_destroy
,
348 xorg_crtc_init(ScrnInfoPtr pScrn
)
350 modesettingPtr ms
= modesettingPTR(pScrn
);
353 drmModeCrtcPtr drm_crtc
= NULL
;
354 struct crtc_private
*crtcp
;
357 res
= drmModeGetResources(ms
->fd
);
359 ErrorF("Failed drmModeGetResources %d\n", errno
);
363 for (c
= 0; c
< res
->count_crtcs
; c
++) {
364 drm_crtc
= drmModeGetCrtc(ms
->fd
, res
->crtcs
[c
]);
369 crtc
= xf86CrtcCreate(pScrn
, &crtc_funcs
);
373 crtcp
= xcalloc(1, sizeof(struct crtc_private
));
375 xf86CrtcDestroy(crtc
);
379 crtcp
->drm_crtc
= drm_crtc
;
381 crtc
->driver_private
= crtcp
;
385 drmModeFreeResources(res
);
388 /* vim: set sw=4 ts=8 sts=4: */