Permalink
Browse files

A bunch of minor changes: drm_utils, perror and more.

1. Modify function find_drm_configuration and rename to drm_autoconf
   In some cases active encoder is not set for active connector and active crtc is not set
   for encoder in use. In this case the first supported encoder (by connector) and crtc
	(by encoder) are selected.

2. Use perror whenever looks reasonable
  • Loading branch information...
1 parent 62696b7 commit 71b93164d4635e0796fe3b8af71352ac8595b0f9 matsi committed Oct 24, 2012
Showing with 128 additions and 60 deletions.
  1. +23 −18 drm_dumb_bo.c
  2. +28 −22 drm_dumb_bo_libkms.c
  3. +12 −12 drm_gl_simple.c
  4. +62 −7 drm_utils.c
  5. +3 −1 drm_utils.h
View
@@ -43,6 +43,7 @@ int main(char argc, char *argv[])
struct drm_mode_destroy_dumb dreq;
struct drm_mode_create_dumb creq;
struct drm_mode_map_dumb mreq;
+
drmModeCrtcPtr saved_crtc;
@@ -57,10 +58,10 @@ int main(char argc, char *argv[])
exit(-1);
}
- drmDropMaster(fd);
+ drmSetMaster(fd);
if (drmGetCap(fd, DRM_CAP_DUMB_BUFFER, &has_dumb) < 0) {
- perror("DRM_CAP_DUMB_BUFFER ioctl");
+ perror("failed drmGetCap(DRM_CAP_DUMB_BUFFER)");
ret = -EFAULT;
goto err_close;
}
@@ -71,23 +72,25 @@ int main(char argc, char *argv[])
goto err_close;
}
- /* find current DRM configuration */
+ /* try DRM auto configuration */
- if (!find_drm_configuration(fd, &kms_data)) {
+ if (!drm_autoconf(fd, &kms_data)) {
fprintf(stderr, "failed to setup KMS\n");
ret = -EFAULT;
goto err_close;
}
+ dump_drm_configuration(&kms_data);
+
/* create dumb buffer object */
- creq.height = kms_data.mode.vdisplay;
- creq.width = kms_data.mode.hdisplay;
+ creq.height = kms_data.mode->vdisplay;
+ creq.width = kms_data.mode->hdisplay;
creq.bpp = 32;
ret = drmIoctl(fd, DRM_IOCTL_MODE_CREATE_DUMB, &creq);
if (ret) {
- fprintf(stderr, "failed drmIoctl(DRM_IOCTL_MODE_CREATE_DUMB)\n");
+ perror("failed drmIoctl(DRM_IOCTL_MODE_CREATE_DUMB)\n");
goto err_close;
}
@@ -97,44 +100,46 @@ int main(char argc, char *argv[])
/* create framebuffer for dumb buffer object */
- ret = drmModeAddFB(fd, kms_data.mode.hdisplay, kms_data.mode.vdisplay,
+ ret = drmModeAddFB(fd, kms_data.mode->hdisplay, kms_data.mode->vdisplay,
24, 32, dbo.stride, dbo.handle, &dbo.fb);
if (ret) {
- fprintf(stderr, "cannot add drm framebuffer for dumb buffer object\n");
+ perror("failed drmModeAddFB()\n");
goto err_destroy;
}
+ drmModeDirtyFB(fd, dbo.fb, NULL, 0);
+
/* map dumb buffer object */
mreq.handle = dbo.handle;
ret = drmIoctl(fd, DRM_IOCTL_MODE_MAP_DUMB, &mreq);
if (ret) {
- fprintf(stderr, "failed drmIoctl(DRM_IOCTL_MODE_MAP_DUMB)\n");
+ perror("failed drmIoctl(DRM_IOCTL_MODE_MAP_DUMB)");
goto err_fb;
}
dbo.map = mmap(0, dbo.size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, mreq.offset);
if (dbo.map == MAP_FAILED) {
- fprintf(stderr, "cannot mmap dumb buffer\n");
+ perror("failed mmap()");
ret = -EFAULT;
goto err_fb;
}
/* store current crtc */
- saved_crtc = drmModeGetCrtc(fd, kms_data.encoder->crtc_id);
+ saved_crtc = drmModeGetCrtc(fd, kms_data.crtc->crtc_id);
if (saved_crtc == NULL) {
- fprintf(stderr, "failed to get current mode\n");
+ perror("failed drmModeGetCrtc(current)");
goto err_unmap;
}
/* setup new crtc */
- ret = drmModeSetCrtc(fd, kms_data.encoder->crtc_id, dbo.fb, 0, 0,
- &kms_data.connector->connector_id, 1, &kms_data.mode);
+ ret = drmModeSetCrtc(fd, kms_data.crtc->crtc_id, dbo.fb, 0, 0,
+ &kms_data.connector->connector_id, 1, kms_data.mode);
if (ret) {
- fprintf(stderr, "cannot set new drm crtc");
+ perror("failed drmModeSetCrtc(new)");
goto err_unmap;
}
@@ -148,8 +153,8 @@ int main(char argc, char *argv[])
};
uint32_t *dst = (uint32_t *) dbo.map;
- uint32_t h = kms_data.mode.vdisplay;
- uint32_t w = kms_data.mode.hdisplay;
+ uint32_t h = kms_data.mode->vdisplay;
+ uint32_t w = kms_data.mode->hdisplay;
uint32_t color;
int i, j;
View
@@ -41,7 +41,7 @@ int main(char argc, char *argv[])
KMS_WIDTH, 0,
KMS_HEIGHT, 0,
KMS_BO_TYPE, KMS_BO_TYPE_SCANOUT_X8R8G8B8,
- KMS_TERMINATE_PROP_LIST, 0
+ KMS_TERMINATE_PROP_LIST
};
fd = open(device_name, O_RDWR | O_CLOEXEC);
@@ -50,79 +50,85 @@ int main(char argc, char *argv[])
exit(-1);
}
+ drmSetMaster(fd);
+
/* find current DRM configuration */
- if (!find_drm_configuration(fd, &kms_data)) {
+ if (!drm_autoconf(fd, &kms_data)) {
fprintf(stderr, "failed to setup KMS\n");
ret = -EFAULT;
goto err_close;
}
+ dump_drm_configuration(&kms_data);
+
/* set display dimensions for chosen configuration */
- attr[1] = kms_data.mode.hdisplay;
- attr[3] = kms_data.mode.vdisplay;
+ attr[1] = kms_data.mode->hdisplay;
+ attr[3] = kms_data.mode->vdisplay;
/* create kms driver */
ret = kms_create(fd, &drv);
if (ret) {
- fprintf(stderr, "failed to setup kms driver\n");
+ perror("failed kms_create()");
goto err_close;
}
/* create dumb buffer object */
ret = kms_bo_create(drv, attr, &bo);
if (ret) {
- fprintf(stderr, "failed to create dumb bo\n");
+ perror("failed kms_bo_create()");
goto err_driver_destroy;
}
ret = kms_bo_get_prop(bo, KMS_PITCH, &stride);
if (ret) {
- fprintf(stderr, "failed to get attrs of dumb bo\n");
+ perror("failed kms_bo_get_prop(KMS_PITCH)");
goto err_buffer_destroy;
}
ret = kms_bo_get_prop(bo, KMS_HANDLE, &handle);
if (ret) {
- fprintf(stderr, "failed to get attrs of dumb bo\n");
+ perror("failed kms_bo_get_prop(KMS_HANDLE)");
goto err_buffer_destroy;
}
/* map dumb buffer object */
ret = kms_bo_map(bo, (void **) &dst);
if (ret) {
- fprintf(stderr, "failed to map buffer object\n");
+ perror("failed kms_bo_map()");
goto err_buffer_destroy;
}
/* create drm framebuffer */
- ret = drmModeAddFB(fd, kms_data.mode.hdisplay, kms_data.mode.vdisplay, 24, 32, stride, handle, &fb);
+ ret = drmModeAddFB(fd, kms_data.mode->hdisplay, kms_data.mode->vdisplay, 24, 32, stride, handle, &fb);
if (ret) {
- fprintf(stderr, "cannot add drm framebuffer for dumb buffer object\n");
+ perror("failed drmModeAddFB()");
goto err_buffer_unmap;
}
/* store current crtc */
- saved_crtc = drmModeGetCrtc(fd, kms_data.encoder->crtc_id);
+ saved_crtc = drmModeGetCrtc(fd, kms_data.crtc->crtc_id);
if (saved_crtc == NULL) {
- fprintf(stderr, "failed to get current mode\n");
+ perror("failed drmModeGetCrtc(current)");
goto err_buffer_unmap;
}
/* setup new crtc */
- ret = drmModeSetCrtc(fd, kms_data.encoder->crtc_id, fb, 0, 0,
- &kms_data.connector->connector_id, 1, &kms_data.mode);
+ ret = drmModeSetCrtc(fd, kms_data.crtc->crtc_id, fb, 0, 0,
+ &kms_data.connector->connector_id, 1, kms_data.mode);
if (ret) {
- fprintf(stderr, "cannot set new drm crtc");
+ perror("failed drmModeSetCrtc(new)");
goto err_buffer_unmap;
- }
+ }
+
+ drmModeDirtyFB(fd, fb, NULL, 0);
/* draw on the screen */
@@ -133,8 +139,8 @@ int main(char argc, char *argv[])
0x00FF00FF, 0x00FFFF00, 0x0000FFFF,
};
- uint32_t h = kms_data.mode.vdisplay;
- uint32_t w = kms_data.mode.hdisplay;
+ uint32_t h = kms_data.mode->vdisplay;
+ uint32_t w = kms_data.mode->hdisplay;
uint32_t color;
int i, j;
@@ -160,19 +166,19 @@ int main(char argc, char *argv[])
err_buffer_unmap:
ret = kms_bo_unmap(bo);
if (ret) {
- fprintf(stderr, "cannot unmap dumb buffer");
+ perror("failed kms_bo_unmap(new)");
}
err_buffer_destroy:
ret = kms_bo_destroy(&bo);
if (ret) {
- fprintf(stderr, "cannot destroy dumb buffer");
+ perror("failed kms_bo_destroy(new)");
}
err_driver_destroy:
ret = kms_destroy(&drv);
if (ret) {
- fprintf(stderr, "cannot destroy kms driver");
+ perror("failed kms_destroy(new)");
}
err_close:
View
@@ -32,7 +32,6 @@
#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
-#include <GL/glu.h>
#include <GL/glext.h>
#include <EGL/egl.h>
@@ -127,12 +126,14 @@ int main(int argc, char *argv[])
/* Find the first available KMS configuration */
- if (!find_drm_configuration(fd, &kms)) {
+ if (!drm_autoconf(fd, &kms)) {
fprintf(stderr, "failed to setup KMS\n");
ret = -EFAULT;
goto close_fd;
}
+ dump_drm_configuration(&kms);
+
/* Init EGL and create EGL context */
gbm = gbm_create_device(fd);
@@ -200,7 +201,7 @@ int main(int argc, char *argv[])
glGenRenderbuffers(1, &rfb);
glBindRenderbuffer(GL_RENDERBUFFER, rfb);
- bo = gbm_bo_create(gbm, kms.mode.hdisplay, kms.mode.vdisplay,
+ bo = gbm_bo_create(gbm, kms.mode->hdisplay, kms.mode->vdisplay,
GBM_BO_FORMAT_XRGB8888, GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
if (bo == NULL) {
@@ -224,29 +225,28 @@ int main(int argc, char *argv[])
handle = gbm_bo_get_handle(bo).u32;
stride = gbm_bo_get_pitch(bo);
- ret = drmModeAddFB(fd, kms.mode.hdisplay, kms.mode.vdisplay,
+ ret = drmModeAddFB(fd, kms.mode->hdisplay, kms.mode->vdisplay,
24, 32, stride, handle, &fb_id);
if (ret) {
- fprintf(stderr, "failed to create fb\n");
+ perror("failed drmModeAddFB()");
goto rm_rb;
}
/* store original crtc */
- saved_crtc = drmModeGetCrtc(fd, kms.encoder->crtc_id);
+ saved_crtc = drmModeGetCrtc(fd, kms.crtc->crtc_id);
if (saved_crtc == NULL) {
- fprintf(stderr, "failed to get current mode\n");
+ perror("failed drmModeGetCrtc(current)");
goto rm_fb;
}
/* set new crtc: display DRM framebuffer */
- ret = drmModeSetCrtc(fd, kms.encoder->crtc_id, fb_id, 0, 0,
- &kms.connector->connector_id, 1, &kms.mode);
+ ret = drmModeSetCrtc(fd, kms.crtc->crtc_id, fb_id, 0, 0, &kms.connector->connector_id, 1, kms.mode);
if (ret) {
- fprintf(stderr, "failed to set mode: %m\n");
+ perror("failed drmModeSetCrtc(new)");
goto free_saved_crtc;
}
@@ -263,7 +263,7 @@ int main(int argc, char *argv[])
*/
for(i = 0; i < 10; i++) {
- render_stuff(kms.mode.hdisplay, kms.mode.vdisplay, angle);
+ render_stuff(kms.mode->hdisplay, kms.mode->vdisplay, angle);
angle += 1.0;
(void) getchar();
}
@@ -276,7 +276,7 @@ int main(int argc, char *argv[])
saved_crtc->x, saved_crtc->y, &kms.connector->connector_id, 1, &saved_crtc->mode);
if (ret) {
- fprintf(stderr, "failed to restore crtc: %m\n");
+ perror("failed drmModeSetCrtc(restore original)");
}
/* cleanup */
Oops, something went wrong.

0 comments on commit 71b9316

Please sign in to comment.