Permalink
Browse files

init repo with drm tests and experiments

  • Loading branch information...
1 parent dc0ff6f commit 15b42d553d051b2c3d9ec0e45fcd4bd4d4e040c6 matsi committed Sep 4, 2012
Showing with 635 additions and 4 deletions.
  1. +2 −0 .gitignore
  2. +61 −0 CMakeLists.txt
  3. +0 −4 README.md
  4. +197 −0 drm_info.c
  5. +375 −0 test.c
View
@@ -0,0 +1,2 @@
+
+build
View
@@ -0,0 +1,61 @@
+cmake_minimum_required(VERSION 2.6)
+project(drm_tests)
+
+add_executable(test test.c)
+add_executable(drm_info drm_info.c)
+
+# find headers
+
+FIND_PATH(EGL_INCLUDE_DIR
+NAMES EGL/egl.h
+PATHS /usr/include /usr/local/include
+)
+
+FIND_PATH(GL_INCLUDE_DIR
+NAMES GL/gl.h
+PATHS /usr/include /usr/local/include
+)
+
+FIND_PATH(DRM_INCLUDE_DIR
+NAMES drm.h
+PATHS /usr/include/libdrm /usr/local/include/libdrm
+)
+
+FIND_PATH(GBM_INCLUDE_DIR
+NAMES gbm.h
+PATHS /usr/include /usr/local/include
+)
+
+# find libraries
+
+FIND_LIBRARY(GL_LIBRARY
+NAMES GL
+PATHS /usr/lib /usr/local/lib
+)
+
+FIND_LIBRARY(EGL_LIBRARY
+NAMES EGL
+PATHS /usr/lib /usr/local/lib
+)
+
+FIND_LIBRARY(DRM_LIBRARY
+NAMES drm
+PATHS /usr/lib /usr/local/lib
+)
+
+FIND_LIBRARY(GBM_LIBRARY
+NAMES gbm
+PATHS /usr/lib /usr/local/lib
+)
+
+# set headers paths
+
+include_directories(${EGL_INCLUDE_DIR})
+include_directories(${DRM_INCLUDE_DIR})
+include_directories(${GBM_INCLUDE_DIR})
+include_directories(${GL_INCLUDE_DIR})
+
+# set libraries paths
+
+target_link_libraries(test ${EGL_LIBRARY} ${DRM_LIBRARY} ${GBM_LIBRARY} ${GL_LIBRARY})
+target_link_libraries(drm_info ${DRM_LIBRARY} ${GBM_LIBRARY})
View
@@ -1,4 +0,0 @@
-drm_test
-========
-
-drm examples
View
@@ -0,0 +1,197 @@
+/*
+ * Copyright © 2011 Kristian Høgsberg
+ * Copyright © 2011 Benjamin Franzke
+ *
+ * Copyright © 2012 matsi
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission. The copyright holders make no representations
+ * about the suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#include <stdbool.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdio.h>
+#include <fcntl.h>
+
+#include <gbm.h>
+#include <drm.h>
+#include <xf86drmMode.h>
+
+static const char device_name[] = "/dev/dri/card0";
+
+int main(int argc, char *argv[])
+{
+ drmModeConnector *connector;
+ drmModeEncoder *encoder;
+ drmModeModeInfo *mode;
+ drmModeRes *resources;
+
+ struct gbm_device *gbm;
+ int i, fd, ret;
+
+ fd = open(device_name, O_RDWR);
+ if (fd < 0) {
+ fprintf(stderr, "couldn't open %s, skipping\n", device_name);
+ ret = -1;
+ goto exit;
+ }
+
+ gbm = gbm_create_device(fd);
+ if (gbm == NULL) {
+ fprintf(stderr, "couldn't create gbm device\n");
+ ret = -1;
+ goto close_fd;
+ }
+
+ /* From xf86drmMode.h:
+
+ typedef struct _drmModeRes {
+
+ int count_fbs;
+ uint32_t *fbs;
+
+ int count_crtcs;
+ uint32_t *crtcs;
+
+ int count_connectors;
+ uint32_t *connectors;
+
+ int count_encoders;
+ uint32_t *encoders;
+
+ uint32_t min_width, max_width;
+ uint32_t min_height, max_height;
+ } drmModeRes, *drmModeResPtr;
+
+ */
+
+ resources = drmModeGetResources(fd);
+ if (!resources) {
+ fprintf(stderr, "drmModeGetResources failed\n");
+ ret = -1;
+ goto destroy_gbm_device;
+ }
+
+ /* From xf86drmMode.h:
+
+ typedef struct _drmModeConnector {
+ uint32_t connector_id;
+ uint32_t encoder_id; // Encoder currently connected
+ uint32_t connector_type;
+ uint32_t connector_type_id;
+ drmModeConnection connection;
+ uint32_t mmWidth, mmHeight; // HxW in millimeters
+ drmModeSubPixel subpixel;
+
+ int count_modes;
+ drmModeModeInfoPtr modes;
+
+ int count_props;
+ uint32_t *props; // List of property ids
+ uint64_t *prop_values; // List of property values
+
+ int count_encoders;
+ uint32_t *encoders; // List of encoder ids
+ } drmModeConnector, *drmModeConnectorPtr;
+
+ */
+
+
+ for (i = 0; i < resources->count_connectors; i++) {
+ connector = drmModeGetConnector(fd, resources->connectors[i]);
+ if (connector == NULL)
+ continue;
+
+ if (connector->connection == DRM_MODE_CONNECTED && connector->count_modes > 0)
+ break;
+
+ drmModeFreeConnector(connector);
+ }
+
+ if (i == resources->count_connectors) {
+ fprintf(stderr, "No currently active connector found.\n");
+ ret = -1;
+ goto destroy_gbm_device;
+ }
+
+ /* From xf86drmMode.h:
+
+ typedef struct _drmModeEncoder {
+ uint32_t encoder_id;
+ uint32_t encoder_type;
+ uint32_t crtc_id;
+ uint32_t possible_crtcs;
+ uint32_t possible_clones;
+ } drmModeEncoder, *drmModeEncoderPtr;
+
+ */
+
+ for (i = 0; i < resources->count_encoders; i++) {
+ encoder = drmModeGetEncoder(fd, resources->encoders[i]);
+
+ if (encoder == NULL)
+ continue;
+
+ if (encoder->encoder_id == connector->encoder_id)
+ break;
+
+ drmModeFreeEncoder(encoder);
+ }
+
+ if (i == resources->count_encoders) {
+ fprintf(stderr, "No matching encoder for connector found.\n");
+ ret = -1;
+ goto drm_free_connector;
+ }
+
+ /* From xf86drmMode.h:
+
+ typedef struct _drmModeModeInfo {
+ uint32_t clock;
+ uint16_t hdisplay, hsync_start, hsync_end, htotal, hskew;
+ uint16_t vdisplay, vsync_start, vsync_end, vtotal, vscan;
+
+ uint32_t vrefresh;
+
+ uint32_t flags;
+ uint32_t type;
+ char name[DRM_DISPLAY_MODE_LEN];
+ } drmModeModeInfo, *drmModeModeInfoPtr;
+
+ */
+
+ for (i = 0, mode = connector->modes; i < connector->count_modes; i++, mode++) {
+ printf("mode: %s\n", mode->name);
+ }
+
+ drmModeFreeEncoder(encoder);
+
+drm_free_connector:
+ drmModeFreeConnector(connector);
+
+destroy_gbm_device:
+ gbm_device_destroy(gbm);
+
+close_fd:
+ close(fd);
+
+exit:
+ return ret;
+}
Oops, something went wrong.

0 comments on commit 15b42d5

Please sign in to comment.