diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/modedemo/demo.c | 47 | ||||
-rw-r--r-- | tests/modefb/Makefile | 14 | ||||
-rw-r--r-- | tests/modefb/demo.c | 150 | ||||
-rwxr-xr-x | tests/modefb/test | 1 |
4 files changed, 211 insertions, 1 deletions
diff --git a/tests/modedemo/demo.c b/tests/modedemo/demo.c index 594d60db..1efeb272 100644 --- a/tests/modedemo/demo.c +++ b/tests/modedemo/demo.c @@ -34,7 +34,9 @@ static struct drm_mode_modeinfo mode = { drmModeFBPtr createFB(int fd, drmModeResPtr res); int findConnectedOutputs(int fd, drmModeResPtr res, drmModeOutputPtr *out); drmModeCrtcPtr findFreeCrtc(int fd, drmModeResPtr res); +void testCursor(int fd, uint32_t crtc); void prettyColors(int fd, unsigned int handle); +void prettyCursor(int fd, unsigned int handle); int main(int argc, char **argv) { @@ -98,6 +100,11 @@ int main(int argc, char **argv) drmModeSetCrtc(fd, crtc->crtc_id, framebuffer->buffer_id, 100, 100, &out[0]->output_id, 1, &mode); sleep(2); + printf("0 0\n"); + drmModeSetCrtc(fd, crtc->crtc_id, framebuffer->buffer_id, 1, 1, &out[0]->output_id, 1, &mode); + + testCursor(fd, crtc->crtc_id); + /* turn the crtc off just in case */ drmModeSetCrtc(fd, crtc->crtc_id, 0, 0, 0, 0, 0, 0); @@ -166,7 +173,7 @@ int findConnectedOutputs(int fd, drmModeResPtr res, drmModeOutputPtr *out) drmModeCrtcPtr findFreeCrtc(int fd, drmModeResPtr res) { - return drmModeGetCrtc(fd, res->crtcs[0]); + return drmModeGetCrtc(fd, res->crtcs[1]); } void draw(unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned int v, unsigned int *ptr) @@ -200,3 +207,41 @@ void prettyColors(int fd, unsigned int handle) drmBOUnmap(fd, &bo); } + +void testCursor(int fd, uint32_t crtc) +{ + drmBO bo; + int ret; + ret = drmBOCreate(fd, 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); + + prettyCursor(fd, bo.handle); + + printf("set cursor\n"); + drmModeSetCursor(fd, crtc, &bo, 64, 64); + printf("move cursor 0, 0\n"); + drmModeMoveCursor(fd, crtc, 0, 0); + sleep(2); + printf("move cursor 40, 40\n"); + drmModeMoveCursor(fd, crtc, 40, 40); + sleep(2); +} + +void prettyCursor(int fd, unsigned int handle) +{ + drmBO bo; + unsigned int *ptr; + int i; + + drmBOReference(fd, handle, &bo); + drmBOMap(fd, &bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE, 0, (void**)&ptr); + + for (i = 0; i < (64 * 64); i++) + ptr[i] = 0xFFFF00FF; + + drmBOUnmap(fd, &bo); +} diff --git a/tests/modefb/Makefile b/tests/modefb/Makefile new file mode 100644 index 00000000..84c6c86a --- /dev/null +++ b/tests/modefb/Makefile @@ -0,0 +1,14 @@ + +all: app + +#CFLAGS = -g -ansi -pedantic -DPOSIX_C_SOURCE=199309L \ +# -D_POSIX_SOURCE -D_XOPEN_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE \ + +app: demo.c + @gcc $(CFLAGS) -o app -Wall demo.c + +clean: + @rm -f app + +run: app + sudo ./test diff --git a/tests/modefb/demo.c b/tests/modefb/demo.c new file mode 100644 index 00000000..0dbf01c7 --- /dev/null +++ b/tests/modefb/demo.c @@ -0,0 +1,150 @@ +#include <stdio.h> +#include <stdlib.h> +#include <errno.h> +#include <fcntl.h> +#include <string.h> +#include "linux/fb.h" +#include "sys/ioctl.h" + + +void setMode(struct fb_var_screeninfo *var); +void pan(int fd, struct fb_var_screeninfo *var, int x, int y); +void cursor(int fd); + +int main(int argc, char **argv) +{ + struct fb_var_screeninfo var; + struct fb_fix_screeninfo fix; + const char* name = "/dev/fb0"; + + int fd = open(name, O_RDONLY); + + if (fd == -1) { + printf("open %s : %s\n", name, strerror(errno)); + return 1; + } + + memset(&var, 0, sizeof(struct fb_var_screeninfo)); + memset(&fix, 0, sizeof(struct fb_fix_screeninfo)); + + if (ioctl(fd, FBIOGET_VSCREENINFO, &var)) + printf("var %s\n", strerror(errno)); + if (ioctl(fd, FBIOGET_FSCREENINFO, &fix)) + printf("fix %s\n", strerror(errno)); + + setMode(&var); + printf("pan: 0, 0\n"); + pan(fd, &var, 0, 0); + sleep(2); + printf("pan: 100, 0\n"); + pan(fd, &var, 100, 0); + sleep(2); + printf("pan: 0, 100\n"); + pan(fd, &var, 0, 100); + sleep(2); + printf("pan: 100, 100\n"); + pan(fd, &var, 100, 100); + sleep(2); + printf("pan: 0, 0\n"); + pan(fd, &var, 0, 0); + sleep(2); + + printf("cursor\n"); + cursor(fd); + return 0; +} + +void pan(int fd, struct fb_var_screeninfo *var, int x, int y) +{ + var->xoffset = x; + var->yoffset = y; + + var->activate = FB_ACTIVATE_NOW; + + if (ioctl(fd, FBIOPUT_VSCREENINFO, var)) + printf("pan error: %s\n", strerror(errno)); +} + +/* + * Currently isn't supported in the driver + */ +void cursor(int fd) +{ + 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)); + + sleep(2); + + memset(&cur, 0, sizeof(cur)); + cur.set = FB_CUR_SETPOS; + cur.enable = 0; + cur.image.dx = 100; + cur.image.dy = 100; + + if (ioctl(fd, FBIO_CURSOR, &cur)) + printf("cursor error: %s\n", strerror(errno)); + + free(data); +} + +struct drm_mode +{ + int clock; + int hdisplay; + int hsync_start; + int hsync_end; + int htotal; + int hskew; + int vdisplay; + int vsync_start; + int vsync_end; + int vtotal; + int vscan; + int vrefresh; + int flags; +}; + +struct drm_mode mode = +{ + .clock = 25200, + .hdisplay = 640, + .hsync_start = 656, + .hsync_end = 752, + .htotal = 800, + .hskew = 0, + .vdisplay = 480, + .vsync_start = 490, + .vsync_end = 492, + .vtotal = 525, + .vscan = 0, + .vrefresh = 60000, /* vertical refresh * 1000 */ + .flags = 10, +}; + +void setMode(struct fb_var_screeninfo *var) { + var->activate = FB_ACTIVATE_NOW; + var->xres = mode.hdisplay; + var->right_margin = mode.hsync_start - mode.hdisplay; + var->hsync_len = mode.hsync_end - mode.hsync_start; + var->left_margin = mode.htotal - mode.hsync_end; + var->yres = mode.vdisplay; + var->lower_margin = mode.vsync_start - mode.vdisplay; + var->vsync_len = mode.vsync_end - mode.vsync_start; + var->upper_margin = mode.vtotal - mode.vsync_end; + var->pixclock = 10000000 / mode.htotal * 1000 / mode.vtotal * 100; + /* avoid overflow */ + var->pixclock = var->pixclock * 1000 / mode.vrefresh; +} diff --git a/tests/modefb/test b/tests/modefb/test new file mode 100755 index 00000000..f98e3708 --- /dev/null +++ b/tests/modefb/test @@ -0,0 +1 @@ +LD_PRELOAD=../../libdrm/.libs/libdrm.so ./app |