summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Bornecrantz <jakob@aurora.(none)>2008-01-30 15:47:26 +0100
committerJakob Bornecrantz <jakob@aurora.(none)>2008-01-30 15:47:26 +0100
commit841ef9eb8da8058d6495e9f8e1b14af2709dfaa1 (patch)
tree5651372b901eda9d4f7b8c8c23a57ca93a73ef91
parentb9b6f9234dd9e702a7d58978cbd88dc297b2b51a (diff)
ModeFB demo now display cursor
-rw-r--r--libdrm/xf86drmMode.c5
-rw-r--r--tests/modedemo/demo.c1
-rw-r--r--tests/modefb/Makefile2
-rw-r--r--tests/modefb/demo.c82
4 files changed, 60 insertions, 30 deletions
diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c
index 86572872..681ad417 100644
--- a/libdrm/xf86drmMode.c
+++ b/libdrm/xf86drmMode.c
@@ -329,7 +329,10 @@ int drmModeSetCursor(int fd, uint32_t crtcId, drmBO *bo, uint32_t width, uint32_
arg.crtc = crtcId;
arg.width = width;
arg.height = height;
- arg.handle = bo->handle;
+ if (bo)
+ arg.handle = bo->handle;
+ else
+ arg.handle = 0;
return ioctl(fd, DRM_IOCTL_MODE_CURSOR, &arg);
}
diff --git a/tests/modedemo/demo.c b/tests/modedemo/demo.c
index 1efeb272..b399aec1 100644
--- a/tests/modedemo/demo.c
+++ b/tests/modedemo/demo.c
@@ -244,4 +244,5 @@ void prettyCursor(int fd, unsigned int handle)
ptr[i] = 0xFFFF00FF;
drmBOUnmap(fd, &bo);
+ drmBOUnreference(fd, &bo);
}
diff --git a/tests/modefb/Makefile b/tests/modefb/Makefile
index 84c6c86a..467fb11a 100644
--- a/tests/modefb/Makefile
+++ b/tests/modefb/Makefile
@@ -5,7 +5,7 @@ all: app
# -D_POSIX_SOURCE -D_XOPEN_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE \
app: demo.c
- @gcc $(CFLAGS) -o app -Wall demo.c
+ @gcc $(CFLAGS) -o app -Wall -I../../libdrm -I../../shared-core -L../../libdrm/.libs -ldrm demo.c
clean:
@rm -f app
diff --git a/tests/modefb/demo.c b/tests/modefb/demo.c
index 0dbf01c7..9af369c2 100644
--- a/tests/modefb/demo.c
+++ b/tests/modefb/demo.c
@@ -5,25 +5,37 @@
#include <string.h>
#include "linux/fb.h"
#include "sys/ioctl.h"
+#include "xf86drm.h"
+#include "xf86drmMode.h"
-
+void pretty(int fd);
void setMode(struct fb_var_screeninfo *var);
void pan(int fd, struct fb_var_screeninfo *var, int x, int y);
-void cursor(int fd);
+void cursor(int fd, int drmfd);
+void prettyCursor(int fd, unsigned int handle, unsigned int color);
+
+extern void sleep(int);
int main(int argc, char **argv)
{
struct fb_var_screeninfo var;
struct fb_fix_screeninfo fix;
+ const char* driver = "i915";
const char* name = "/dev/fb0";
int fd = open(name, O_RDONLY);
+ int drmfd = drmOpen(driver, NULL);
if (fd == -1) {
printf("open %s : %s\n", name, strerror(errno));
return 1;
}
+ if (drmfd < 0) {
+ printf("drmOpen failed\n");
+ return 1;
+ }
+
memset(&var, 0, sizeof(struct fb_var_screeninfo));
memset(&fix, 0, sizeof(struct fb_fix_screeninfo));
@@ -50,7 +62,7 @@ int main(int argc, char **argv)
sleep(2);
printf("cursor\n");
- cursor(fd);
+ cursor(fd, drmfd);
return 0;
}
@@ -66,38 +78,52 @@ void pan(int fd, struct fb_var_screeninfo *var, int x, int y)
}
/*
- * Currently isn't supported in the driver
+ * Cursor support removed from the fb kernel interface
+ * using drm instead.
*/
-void cursor(int fd)
+void cursor(int fd, int drmfd)
{
- struct fb_cursor cur;
- void *data = malloc(64 * 64 * 4);
- memset(&cur, 0, sizeof(cur));
-
- cur.set = FB_CUR_SETIMAGE | FB_CUR_SETPOS | FB_CUR_SETSIZE;
- cur.enable = 1;
- cur.image.dx = 1;
- cur.image.dy = 1;
- cur.image.width = 2;
- cur.image.height = 2;
- cur.image.depth = 32;
- cur.image.data = data;
-
- if (ioctl(fd, FBIO_CURSOR, &cur))
- printf("cursor error: %s\n", strerror(errno));
+ drmModeResPtr res = drmModeGetResources(drmfd);
+ uint32_t crtc = res->crtcs[1]; /* select crtc here */
+ drmBO bo;
+ int ret;
+ ret = drmBOCreate(drmfd, 64 * 64 * 4, 0, 0,
+ DRM_BO_FLAG_READ |
+ DRM_BO_FLAG_WRITE |
+ DRM_BO_FLAG_MEM_VRAM |
+ DRM_BO_FLAG_NO_EVICT,
+ DRM_BO_HINT_DONT_FENCE, &bo);
+
+ if (ret) {
+ printf("failed to create buffer: %s\n", strerror(ret));
+ return;
+ }
+ prettyCursor(drmfd, bo.handle, 0xFFFF00FF);
+ drmModeSetCursor(drmfd, crtc, &bo, 64, 64);
+ drmModeMoveCursor(drmfd, crtc, 0, 0);
+ sleep(2);
+ drmModeMoveCursor(drmfd, crtc, 40, 40);
+ prettyCursor(drmfd, bo.handle, 0xFFFF0000);
sleep(2);
+ drmModeSetCursor(drmfd, crtc, 0, 0, 0);
+ drmBOUnreference(drmfd, &bo);
+}
+
+void prettyCursor(int drmfd, unsigned int handle, unsigned int color)
+{
+ drmBO bo;
+ unsigned int *ptr;
+ int i;
- memset(&cur, 0, sizeof(cur));
- cur.set = FB_CUR_SETPOS;
- cur.enable = 0;
- cur.image.dx = 100;
- cur.image.dy = 100;
+ drmBOReference(drmfd, handle, &bo);
+ drmBOMap(drmfd, &bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE, 0, (void**)&ptr);
- if (ioctl(fd, FBIO_CURSOR, &cur))
- printf("cursor error: %s\n", strerror(errno));
+ for (i = 0; i < (64 * 64); i++)
+ ptr[i] = color;
- free(data);
+ drmBOUnmap(drmfd, &bo);
+ drmBOUnreference(drmfd, &bo);
}
struct drm_mode