diff options
author | Gerd Hoffmann <kraxel@redhat.com> | 2019-02-04 08:19:36 +0100 |
---|---|---|
committer | Gerd Hoffmann <kraxel@redhat.com> | 2019-02-04 08:19:36 +0100 |
commit | 679347ddc22e82197c31ef89e388154084506f72 (patch) | |
tree | c60d383df85c5834a6b7c22e7351b65413e78851 | |
parent | fb7fa435af36197db5493775d01b4339484ae225 (diff) | |
download | fbida-679347ddc22e82197c31ef89e388154084506f72.tar.gz |
drm format wireup
-rw-r--r-- | drmtools.c | 51 | ||||
-rw-r--r-- | fbcon.c | 13 | ||||
-rw-r--r-- | fbpdf.c | 4 | ||||
-rw-r--r-- | fbtools.c | 3 | ||||
-rw-r--r-- | gfx.h | 1 |
5 files changed, 49 insertions, 23 deletions
@@ -156,7 +156,7 @@ int drm_init_dev(const char *dev, const char *output, const char *mode) return 0; } -static int drm_init_fb(struct drmfb *fb) +static int drm_init_fb(struct drmfb *fb, struct gfxfmt *fmt) { struct drm_mode_map_dumb mreq; int rc; @@ -165,19 +165,28 @@ static int drm_init_fb(struct drmfb *fb) memset(&fb->creq, 0, sizeof(fb->creq)); fb->creq.width = drm_mode->hdisplay; fb->creq.height = drm_mode->vdisplay; - fb->creq.bpp = 32; + fb->creq.bpp = fmt->bpp; rc = drmIoctl(drm_fd, DRM_IOCTL_MODE_CREATE_DUMB, &fb->creq); if (rc < 0) { fprintf(stderr, "drm: DRM_IOCTL_MODE_CREATE_DUMB: %s\n", strerror(errno)); return -1; } rc = drmModeAddFB(drm_fd, fb->creq.width, fb->creq.height, - 24, 32, fb->creq.pitch, + fmt->depth, fmt->bpp, fb->creq.pitch, fb->creq.handle, &fb->id); if (rc < 0) { - fprintf(stderr, "drm: drmModeAddFB() failed\n"); + fprintf(stderr, "drm: drmModeAddFB(%c%c%c%c) failed\n", + (fmt->fourcc >> 0) & 0xff, + (fmt->fourcc >> 8) & 0xff, + (fmt->fourcc >> 16) & 0xff, + (fmt->fourcc >> 24) & 0xff); return -1; } + fprintf(stderr, "drm: drmModeAddFB(%c%c%c%c) OK\n", + (fmt->fourcc >> 0) & 0xff, + (fmt->fourcc >> 8) & 0xff, + (fmt->fourcc >> 16) & 0xff, + (fmt->fourcc >> 24) & 0xff); /* map framebuffer */ memset(&mreq, 0, sizeof(mreq)); @@ -229,7 +238,9 @@ gfxstate *drm_init(const char *device, const char *output, { struct stat st; gfxstate *gfx; + gfxfmt *fmt = NULL; char dev[64]; + int i; if (device) { snprintf(dev, sizeof(dev), "%s", device); @@ -240,7 +251,13 @@ gfxstate *drm_init(const char *device, const char *output, if (drm_init_dev(dev, output, mode) < 0) return NULL; - if (drm_init_fb(&fb1) < 0) + for (i = 0; i < fmt_count; i++) { + if (drm_init_fb(&fb1, fmt_list + i) < 0) + continue; + fmt = fmt_list + i; + break; + } + if (fmt == NULL) return NULL; if (drm_show_fb(&fb1) < 0) return NULL; @@ -253,16 +270,17 @@ gfxstate *drm_init(const char *device, const char *output, gfx->vdisplay = drm_mode->vdisplay; gfx->stride = fb1.creq.pitch; gfx->mem = fb1.mem; - - gfx->rlen = 8; - gfx->glen = 8; - gfx->blen = 8; - gfx->tlen = 8; - gfx->roff = 16; - gfx->goff = 8; - gfx->boff = 0; - gfx->toff = 24; - gfx->bits_per_pixel = 32; + gfx->fmt = fmt; + + gfx->rlen = PIXMAN_FORMAT_R(fmt->pixman); + gfx->glen = PIXMAN_FORMAT_G(fmt->pixman); + gfx->blen = PIXMAN_FORMAT_B(fmt->pixman); + gfx->tlen = PIXMAN_FORMAT_A(fmt->pixman); + gfx->roff = gfx->blen + gfx->glen; + gfx->goff = gfx->blen; + gfx->boff = 0; + gfx->toff = gfx->blen + gfx->glen + gfx->rlen; + gfx->bits_per_pixel = PIXMAN_FORMAT_BPP(fmt->pixman); gfx->restore_display = drm_restore_display; gfx->cleanup_display = drm_cleanup_display; @@ -270,9 +288,10 @@ gfxstate *drm_init(const char *device, const char *output, fstat(drm_fd, &st); gfx->devnum = st.st_rdev; + snprintf(gfx->devpath, sizeof(gfx->devpath), "%s", dev); if (pageflip) { - if (drm_init_fb(&fb2) == 0) { + if (drm_init_fb(&fb2, fmt) == 0) { gfx->mem2 = fb2.mem; } else { fprintf(stderr, "drm: can't alloc two fbs, pageflip disabled.\n"); @@ -322,8 +322,13 @@ static void child_exec_shell(struct winsize *win) #if 1 fprintf(stderr, "# \n"); - fprintf(stderr, "# This is fbcon @%s, using %s-%d.\n", - seat_name, font_name, font_size); + fprintf(stderr, "# This is fbcon @%s, device %s, format %c%c%c%c, font %s-%d.\n", + seat_name, gfx->devpath, + (gfx->fmt->fourcc >> 0) & 0xff, + (gfx->fmt->fourcc >> 8) & 0xff, + (gfx->fmt->fourcc >> 16) & 0xff, + (gfx->fmt->fourcc >> 24) & 0xff, + font_name, font_size); fprintf(stderr, "# \n"); #endif @@ -398,7 +403,7 @@ int main(int argc, char *argv[]) /* init cairo */ surface1 = cairo_image_surface_create_for_data(gfx->mem, - CAIRO_FORMAT_ARGB32, + gfx->fmt->cairo, gfx->hdisplay, gfx->vdisplay, gfx->stride); @@ -410,7 +415,7 @@ int main(int argc, char *argv[]) cairo_font_extents(context1, &extents); if (gfx->mem2) { surface2 = cairo_image_surface_create_for_data(gfx->mem2, - CAIRO_FORMAT_ARGB32, + gfx->fmt->cairo, gfx->hdisplay, gfx->vdisplay, gfx->stride); @@ -337,13 +337,13 @@ int main(int argc, char *argv[]) } surface1 = cairo_image_surface_create_for_data(gfx->mem, - CAIRO_FORMAT_ARGB32, + gfx->fmt->cairo, gfx->hdisplay, gfx->vdisplay, gfx->stride); if (gfx->mem2) { surface2 = cairo_image_surface_create_for_data(gfx->mem2, - CAIRO_FORMAT_ARGB32, + gfx->fmt->cairo, gfx->hdisplay, gfx->vdisplay, gfx->stride); @@ -324,7 +324,8 @@ gfxstate* fb_init(const char *device, char *mode) gfx->cleanup_display = fb_cleanup_display; fstat(fb, &st); - gfx->devnum = st.st_rdev; + gfx->devnum = st.st_rdev; + snprintf(gfx->devpath, sizeof(gfx->devpath), "%s", device); return gfx; @@ -43,6 +43,7 @@ struct gfxstate { uint32_t rlen, glen, blen, tlen; uint32_t roff, goff, boff, toff; + char devpath[128]; dev_t devnum; /* calls */ |