Permalink
Browse files

Modify: make it work in vmware linux guest

1. Change ordering:
   Add framebuffer after mmap.

2. Add drmModeDirtyFB
   Without this call everything works fine with intel drm driver i915, but not on vmware
   (vmwgfx driver).

3. Add define for _FILE_OFFSET_BITS
   Without this define mmap incorrectly handles its last parameter (offset).
  • Loading branch information...
1 parent 71b9316 commit c100bf80c9c683f2418768a22d160d49a321f303 matsi committed Oct 24, 2012
Showing with 30 additions and 25 deletions.
  1. +30 −25 drm_dumb_bo.c
View
@@ -1,3 +1,5 @@
+#define _FILE_OFFSET_BITS 64
+
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -46,11 +48,7 @@ int main(char argc, char *argv[])
drmModeCrtcPtr saved_crtc;
-
memset(&dbo, 0, sizeof(dbo));
- memset(&mreq, 0, sizeof(mreq));
- memset(&creq, 0, sizeof(creq));
- memset(&dreq, 0, sizeof(dreq));
fd = open(device_name, O_RDWR | O_CLOEXEC);
if (fd < 0) {
@@ -60,30 +58,33 @@ int main(char argc, char *argv[])
drmSetMaster(fd);
- if (drmGetCap(fd, DRM_CAP_DUMB_BUFFER, &has_dumb) < 0) {
- perror("failed drmGetCap(DRM_CAP_DUMB_BUFFER)");
+ /* try DRM auto configuration */
+
+ if (!drm_autoconf(fd, &kms_data)) {
+ fprintf(stderr, "failed to setup KMS\n");
ret = -EFAULT;
goto err_close;
}
- if (!has_dumb) {
- fprintf(stderr, "driver does not support dumb buffers\n");
+ dump_drm_configuration(&kms_data);
+
+ /* check dumb buffer support */
+
+ if (drmGetCap(fd, DRM_CAP_DUMB_BUFFER, &has_dumb) < 0) {
+ perror("failed drmGetCap(DRM_CAP_DUMB_BUFFER)");
ret = -EFAULT;
goto err_close;
}
- /* try DRM auto configuration */
-
- if (!drm_autoconf(fd, &kms_data)) {
- fprintf(stderr, "failed to setup KMS\n");
+ if (!has_dumb) {
+ fprintf(stderr, "driver does not support dumb buffers\n");
ret = -EFAULT;
goto err_close;
}
- dump_drm_configuration(&kms_data);
-
/* create dumb buffer object */
+ memset(&creq, 0, sizeof(creq));
creq.height = kms_data.mode->vdisplay;
creq.width = kms_data.mode->hdisplay;
creq.bpp = 32;
@@ -98,19 +99,9 @@ int main(char argc, char *argv[])
dbo.stride = creq.pitch;
dbo.size = creq.size;
- /* create framebuffer for dumb buffer object */
-
- ret = drmModeAddFB(fd, kms_data.mode->hdisplay, kms_data.mode->vdisplay,
- 24, 32, dbo.stride, dbo.handle, &dbo.fb);
- if (ret) {
- perror("failed drmModeAddFB()\n");
- goto err_destroy;
- }
-
- drmModeDirtyFB(fd, dbo.fb, NULL, 0);
-
/* map dumb buffer object */
+ memset(&mreq, 0, sizeof(mreq));
mreq.handle = dbo.handle;
ret = drmIoctl(fd, DRM_IOCTL_MODE_MAP_DUMB, &mreq);
@@ -126,6 +117,15 @@ int main(char argc, char *argv[])
goto err_fb;
}
+ /* create framebuffer for dumb buffer object */
+
+ ret = drmModeAddFB(fd, kms_data.mode->hdisplay, kms_data.mode->vdisplay,
+ 24, 32, dbo.stride, dbo.handle, &dbo.fb);
+ if (ret) {
+ perror("failed drmModeAddFB()\n");
+ goto err_destroy;
+ }
+
/* store current crtc */
saved_crtc = drmModeGetCrtc(fd, kms_data.crtc->crtc_id);
@@ -143,6 +143,8 @@ int main(char argc, char *argv[])
goto err_unmap;
}
+ drmModeDirtyFB(fd, dbo.fb, NULL, 0);
+
/* draw on the screen */
do {
@@ -184,7 +186,10 @@ int main(char argc, char *argv[])
drmModeRmFB(fd, dbo.fb);
err_destroy:
+
+ memset(&dreq, 0, sizeof(dreq));
dreq.handle = dbo.handle;
+
ret = drmIoctl(fd, DRM_IOCTL_MODE_DESTROY_DUMB, &dreq);
if (ret) {
fprintf(stderr, "cannot destroy dumb buffer");

0 comments on commit c100bf8

Please sign in to comment.