Created
April 22, 2015 05:16
-
-
Save bboozzoo/de25cb7d163987c8fd46 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <stdint.h> | |
#include <string.h> | |
#include <xf86drm.h> | |
#include <xf86drmMode.h> | |
#include <drm_fourcc.h> | |
#include <libkms.h> | |
#define LOG(...) \ | |
do { \ | |
fprintf(stderr, __VA_ARGS__); \ | |
} while(0) | |
int main(int argc, char **argv) | |
{ | |
int fd; | |
struct kms_driver *kms; | |
fd = drmOpen("radeon", NULL); | |
LOG("fd: %d\n", fd); | |
drmModeResPtr resources; | |
uint32_t crtc_id; | |
uint32_t connector_id; | |
resources = drmModeGetResources(fd); | |
crtc_id = resources->crtcs[0]; | |
drmModeConnectorPtr connector; | |
uint32_t width = 0; | |
uint32_t height = 0; | |
int i; | |
for (i = 0; i < resources->count_connectors; i++) | |
{ | |
connector_id = resources->connectors[i]; | |
LOG("crtc: %d\n", crtc_id); | |
LOG("connector: %d\n", connector_id); | |
connector = drmModeGetConnector(fd, connector_id); | |
LOG("connection: %d\n", connector->connection); | |
if (connector->connection == DRM_MODE_DISCONNECTED) | |
continue; | |
drmModeModeInfo mode; | |
mode = connector->modes[0]; | |
width = mode.hdisplay; | |
height = mode.vdisplay; | |
} | |
/* LOG("modes: %d\n", connector->count_modes); */ | |
LOG("width x height: %d x %d\n", width, height); | |
if (width == 0 || height == 0) | |
{ | |
LOG("no suitable connector found\n"); | |
exit(1); | |
} | |
kms_create(fd, &kms); | |
unsigned bo_attribs[] = { | |
KMS_WIDTH, width, | |
KMS_HEIGHT, height, | |
KMS_BO_TYPE, KMS_BO_TYPE_SCANOUT_X8R8G8B8, | |
KMS_TERMINATE_PROP_LIST | |
}; | |
struct kms_bo *bo; | |
kms_bo_create(kms, bo_attribs, &bo); | |
uint32_t handles[4]; | |
uint32_t pitches[4]; | |
uint32_t offsets[4]; | |
kms_bo_get_prop(bo, KMS_HANDLE, &handles[0]); | |
kms_bo_get_prop(bo, KMS_PITCH, &pitches[0]); | |
offsets[0] = 0; | |
LOG("pitch: %d\n", pitches[0]); | |
LOG("offset: %d\n", offsets[0]); | |
int fb_id; | |
int format = DRM_FORMAT_XRGB8888; | |
LOG("format: %08x\n", format); | |
LOG("ARGB8888: %08x\n", DRM_FORMAT_ARGB8888); | |
LOG("ABGR8888: %08x\n", DRM_FORMAT_ABGR8888); | |
LOG("RGBA8888: %08x\n", DRM_FORMAT_RGBA8888); | |
LOG("BGRA8888: %08x\n", DRM_FORMAT_BGRA8888); | |
if (drmModeAddFB2(fd, width, height, format, | |
handles, pitches, offsets, &fb_id, 0)) | |
{ | |
LOG("addfb2 failed: %m\n"); | |
} | |
else | |
{ | |
LOG("buffer created: %d\n", fb_id); | |
drmModeRmFB(fd, fb_id); | |
} | |
kms_destroy(&kms); | |
drmClose(fd); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment