summaryrefslogtreecommitdiff
path: root/src/gallium/state_trackers/xorg/xorg_crtc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gallium/state_trackers/xorg/xorg_crtc.c')
-rw-r--r--src/gallium/state_trackers/xorg/xorg_crtc.c222
1 files changed, 138 insertions, 84 deletions
diff --git a/src/gallium/state_trackers/xorg/xorg_crtc.c b/src/gallium/state_trackers/xorg/xorg_crtc.c
index 67fe29a69da..ddcaedde37e 100644
--- a/src/gallium/state_trackers/xorg/xorg_crtc.c
+++ b/src/gallium/state_trackers/xorg/xorg_crtc.c
@@ -52,20 +52,24 @@
#include "pipe/p_inlines.h"
#include "util/u_rect.h"
+#ifdef HAVE_LIBKMS
+#include "libkms.h"
+#endif
+
struct crtc_private
{
drmModeCrtcPtr drm_crtc;
/* hwcursor */
struct pipe_texture *cursor_tex;
+ struct kms_bo *cursor_bo;
+
unsigned cursor_handle;
};
static void
crtc_dpms(xf86CrtcPtr crtc, int mode)
{
- //ScrnInfoPtr pScrn = crtc->scrn;
-
switch (mode) {
case DPMSModeOn:
case DPMSModeStandby:
@@ -77,44 +81,29 @@ crtc_dpms(xf86CrtcPtr crtc, int mode)
}
static Bool
-crtc_lock(xf86CrtcPtr crtc)
-{
- return FALSE;
-}
-
-static void
-crtc_unlock(xf86CrtcPtr crtc)
-{
-}
-
-static void
-crtc_prepare(xf86CrtcPtr crtc)
-{
-}
-
-static void
-crtc_commit(xf86CrtcPtr crtc)
-{
-}
-
-static Bool
-crtc_mode_fixup(xf86CrtcPtr crtc, DisplayModePtr mode,
- DisplayModePtr adjusted_mode)
-{
- return TRUE;
-}
-
-static void
-crtc_mode_set(xf86CrtcPtr crtc, DisplayModePtr mode,
- DisplayModePtr adjusted_mode, int x, int y)
+crtc_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
+ Rotation rotation, int x, int y)
{
xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
modesettingPtr ms = modesettingPTR(crtc->scrn);
- xf86OutputPtr output = config->output[config->compat_output];
- drmModeConnectorPtr drm_connector = output->driver_private;
+ xf86OutputPtr output = NULL;
+ drmModeConnectorPtr drm_connector;
struct crtc_private *crtcp = crtc->driver_private;
drmModeCrtcPtr drm_crtc = crtcp->drm_crtc;
drmModeModeInfo drm_mode;
+ int i, ret;
+
+ for (i = 0; i < config->num_output; output = NULL, i++) {
+ output = config->output[i];
+
+ if (output->crtc == crtc)
+ break;
+ }
+
+ if (!output)
+ return FALSE;
+
+ drm_connector = output->driver_private;
drm_mode.clock = mode->Clock;
drm_mode.hdisplay = mode->HDisplay;
@@ -133,60 +122,65 @@ crtc_mode_set(xf86CrtcPtr crtc, DisplayModePtr mode,
xf86SetModeDefaultName(mode);
strncpy(drm_mode.name, mode->name, DRM_DISPLAY_MODE_LEN);
- drmModeSetCrtc(ms->fd, drm_crtc->crtc_id, ms->fb_id, x, y,
- &drm_connector->connector_id, 1, &drm_mode);
-}
+ ret = drmModeSetCrtc(ms->fd, drm_crtc->crtc_id, ms->fb_id, x, y,
+ &drm_connector->connector_id, 1, &drm_mode);
-#if 0
-static void
-crtc_load_lut(xf86CrtcPtr crtc)
-{
- //ScrnInfoPtr pScrn = crtc->scrn;
+ if (ret)
+ return FALSE;
+
+ crtc->x = x;
+ crtc->y = y;
+ crtc->mode = *mode;
+ crtc->rotation = rotation;
+
+ return TRUE;
}
-#endif
static void
crtc_gamma_set(xf86CrtcPtr crtc, CARD16 * red, CARD16 * green, CARD16 * blue,
int size)
{
+ /* XXX: hockup */
}
static void *
crtc_shadow_allocate(xf86CrtcPtr crtc, int width, int height)
{
- //ScrnInfoPtr pScrn = crtc->scrn;
-
return NULL;
}
static PixmapPtr
crtc_shadow_create(xf86CrtcPtr crtc, void *data, int width, int height)
{
- //ScrnInfoPtr pScrn = crtc->scrn;
-
return NULL;
}
static void
crtc_shadow_destroy(xf86CrtcPtr crtc, PixmapPtr rotate_pixmap, void *data)
{
- //ScrnInfoPtr pScrn = crtc->scrn;
}
+/*
+ * Cursor functions
+ */
+
static void
-crtc_destroy(xf86CrtcPtr crtc)
+crtc_set_cursor_colors(xf86CrtcPtr crtc, int bg, int fg)
{
- struct crtc_private *crtcp = crtc->driver_private;
+ /* XXX: See if this one is needed, as we only support ARGB cursors */
+}
- if (crtcp->cursor_tex)
- pipe_texture_reference(&crtcp->cursor_tex, NULL);
+static void
+crtc_set_cursor_position(xf86CrtcPtr crtc, int x, int y)
+{
+ modesettingPtr ms = modesettingPTR(crtc->scrn);
+ struct crtc_private *crtcp = crtc->driver_private;
- drmModeFreeCrtc(crtcp->drm_crtc);
- xfree(crtcp);
+ drmModeMoveCursor(ms->fd, crtcp->drm_crtc->crtc_id, x, y);
}
static void
-crtc_load_cursor_argb(xf86CrtcPtr crtc, CARD32 * image)
+crtc_load_cursor_argb_ga3d(xf86CrtcPtr crtc, CARD32 * image)
{
unsigned char *ptr;
modesettingPtr ms = modesettingPTR(crtc->scrn);
@@ -229,13 +223,54 @@ crtc_load_cursor_argb(xf86CrtcPtr crtc, CARD32 * image)
ms->screen->tex_transfer_destroy(transfer);
}
+#if HAVE_LIBKMS
static void
-crtc_set_cursor_position(xf86CrtcPtr crtc, int x, int y)
+crtc_load_cursor_argb_kms(xf86CrtcPtr crtc, CARD32 * image)
{
modesettingPtr ms = modesettingPTR(crtc->scrn);
struct crtc_private *crtcp = crtc->driver_private;
+ unsigned char *ptr;
- drmModeMoveCursor(ms->fd, crtcp->drm_crtc->crtc_id, x, y);
+ if (!crtcp->cursor_bo) {
+ unsigned attr[8];
+
+ attr[0] = KMS_BO_TYPE;
+ attr[1] = KMS_BO_TYPE_CURSOR;
+ attr[2] = KMS_WIDTH;
+ attr[3] = 64;
+ attr[4] = KMS_HEIGHT;
+ attr[5] = 64;
+ attr[6] = 0;
+
+ if (kms_bo_create(ms->kms, attr, &crtcp->cursor_bo))
+ return;
+
+ if (kms_bo_get_prop(crtcp->cursor_bo, KMS_HANDLE,
+ &crtcp->cursor_handle))
+ goto err_bo_destroy;
+ }
+
+ kms_bo_map(crtcp->cursor_bo, (void**)&ptr);
+ memcpy(ptr, image, 64*64*4);
+ kms_bo_unmap(crtcp->cursor_bo);
+
+ return;
+
+err_bo_destroy:
+ kms_bo_destroy(crtcp->cursor_bo);
+}
+#endif
+
+static void
+crtc_load_cursor_argb(xf86CrtcPtr crtc, CARD32 * image)
+{
+ modesettingPtr ms = modesettingPTR(crtc->scrn);
+ if (ms->screen)
+ crtc_load_cursor_argb_ga3d(crtc, image);
+#ifdef HAVE_LIBKMS
+ else if (ms->kms)
+ crtc_load_cursor_argb_kms(crtc, image);
+#endif
}
static void
@@ -244,7 +279,7 @@ crtc_show_cursor(xf86CrtcPtr crtc)
modesettingPtr ms = modesettingPTR(crtc->scrn);
struct crtc_private *crtcp = crtc->driver_private;
- if (crtcp->cursor_tex)
+ if (crtcp->cursor_tex || crtcp->cursor_bo)
drmModeSetCursor(ms->fd, crtcp->drm_crtc->crtc_id,
crtcp->cursor_handle, 64, 64);
}
@@ -258,41 +293,60 @@ crtc_hide_cursor(xf86CrtcPtr crtc)
drmModeSetCursor(ms->fd, crtcp->drm_crtc->crtc_id, 0, 0, 0);
}
+/**
+ * Called at vt leave
+ */
+void
+xorg_crtc_cursor_destroy(xf86CrtcPtr crtc)
+{
+ struct crtc_private *crtcp = crtc->driver_private;
+
+ if (crtcp->cursor_tex)
+ pipe_texture_reference(&crtcp->cursor_tex, NULL);
+#ifdef HAVE_LIBKMS
+ if (crtcp->cursor_bo)
+ kms_bo_destroy(crtcp->cursor_bo);
+#endif
+
+ xfree(crtcp);
+}
+
+/*
+ * Misc functions
+ */
+
+static void
+crtc_destroy(xf86CrtcPtr crtc)
+{
+ struct crtc_private *crtcp = crtc->driver_private;
+
+ if (crtcp->cursor_tex)
+ pipe_texture_reference(&crtcp->cursor_tex, NULL);
+
+ drmModeFreeCrtc(crtcp->drm_crtc);
+ xfree(crtcp);
+}
+
static const xf86CrtcFuncsRec crtc_funcs = {
.dpms = crtc_dpms,
- .save = NULL,
- .restore = NULL,
- .lock = crtc_lock,
- .unlock = crtc_unlock,
- .mode_fixup = crtc_mode_fixup,
- .prepare = crtc_prepare,
- .mode_set = crtc_mode_set,
- .commit = crtc_commit,
- .gamma_set = crtc_gamma_set,
- .shadow_create = crtc_shadow_create,
- .shadow_allocate = crtc_shadow_allocate,
- .shadow_destroy = crtc_shadow_destroy,
+ .set_mode_major = crtc_set_mode_major,
+
+ .set_cursor_colors = crtc_set_cursor_colors,
.set_cursor_position = crtc_set_cursor_position,
.show_cursor = crtc_show_cursor,
.hide_cursor = crtc_hide_cursor,
- .load_cursor_image = NULL, /* lets convert to argb only */
- .set_cursor_colors = NULL, /* using argb only */
.load_cursor_argb = crtc_load_cursor_argb,
- .destroy = crtc_destroy,
-};
-void
-crtc_cursor_destroy(xf86CrtcPtr crtc)
-{
- struct crtc_private *crtcp = crtc->driver_private;
+ .shadow_create = crtc_shadow_create,
+ .shadow_allocate = crtc_shadow_allocate,
+ .shadow_destroy = crtc_shadow_destroy,
- if (crtcp->cursor_tex) {
- pipe_texture_reference(&crtcp->cursor_tex, NULL);
- }
-}
+ .gamma_set = crtc_gamma_set,
+ .destroy = crtc_destroy,
+};
void
-crtc_init(ScrnInfoPtr pScrn)
+xorg_crtc_init(ScrnInfoPtr pScrn)
{
modesettingPtr ms = modesettingPTR(pScrn);
xf86CrtcPtr crtc;
@@ -309,6 +363,7 @@ crtc_init(ScrnInfoPtr pScrn)
for (c = 0; c < res->count_crtcs; c++) {
drm_crtc = drmModeGetCrtc(ms->fd, res->crtcs[c]);
+
if (!drm_crtc)
continue;
@@ -325,7 +380,6 @@ crtc_init(ScrnInfoPtr pScrn)
crtcp->drm_crtc = drm_crtc;
crtc->driver_private = crtcp;
-
}
out: