Skip to content

Instantly share code, notes, and snippets.

@carlocaione
Created February 18, 2015 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlocaione/f7886ca2dd78c6bcdcbb to your computer and use it in GitHub Desktop.
Save carlocaione/f7886ca2dd78c6bcdcbb to your computer and use it in GitHub Desktop.
drmModeResPtr res;
drmModeCrtcPtr crtc;
drmModeFBPtr fb;
struct drm_mode_map_dumb mreq;
int ret;
uint8_t *map;
size_t size;
unsigned int i, j, off;
uint8_t r, g, b;
FILE *file = fopen("/root/LOG", "a");
res = drmModeGetResources(pARMSOC->drmFD);
crtc = drmModeGetCrtc(pARMSOC->drmFD, res->crtcs[0]);
fb = drmModeGetFB(pARMSOC->drmFD, crtc->buffer_id);
fprintf(file, "crtc->buffer_id: %d, fb->handle: %d\n", crtc->buffer_id, fb->handle);
memset(&mreq, 0, sizeof(mreq));
mreq.handle = fb->handle;
ret = drmIoctl(pARMSOC->drmFD, DRM_IOCTL_MODE_MAP_DUMB, &mreq);
if (ret) {
fprintf(file, "error in drmIoctl\n");
}
size = fb->pitch * fb->height;
map = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, pARMSOC->drmFD, mreq.offset);
if (map == MAP_FAILED) {
fprintf(file, "error in mmap\n");
}
srand(time(NULL));
memset(map, 0, size);
for (j = 0; j < fb->height; j++) {
for (i = 0; i < fb->width; i++) {
r = rand() % 0xff;
g = rand() % 0xff;
b = rand() % 0xff;
off = fb->pitch * j + i * 4;
*(uint32_t *)&map[off] = (r << 16) | (g << 8) | b;
}
}
fclose(file);
drmModeFreeCrtc(crtc);
drmModeFreeResources(res);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment