[DRM] open with drmModeGetResources()

This commit is contained in:
Nick Black 2021-11-02 17:25:49 -04:00
parent 66fdb620b7
commit 642ac08e31
10 changed files with 53 additions and 19 deletions

View File

@ -232,6 +232,7 @@ target_include_directories(notcurses-core
"${PROJECT_BINARY_DIR}/include" "${PROJECT_BINARY_DIR}/include"
"${TERMINFO_INCLUDE_DIRS}" "${TERMINFO_INCLUDE_DIRS}"
"${ZLIB_INCLUDE_DIRS}" "${ZLIB_INCLUDE_DIRS}"
"${DRM_INCLUDE_DIRS}"
) )
target_include_directories(notcurses-core-static target_include_directories(notcurses-core-static
BEFORE BEFORE
@ -242,6 +243,7 @@ target_include_directories(notcurses-core-static
"${PROJECT_BINARY_DIR}/include" "${PROJECT_BINARY_DIR}/include"
"${TERMINFO_STATIC_INCLUDE_DIRS}" "${TERMINFO_STATIC_INCLUDE_DIRS}"
"${ZLIB_STATIC_INCLUDE_DIRS}" "${ZLIB_STATIC_INCLUDE_DIRS}"
"${DRM_STATIC_INCLUDE_DIRS}"
) )
target_link_libraries(notcurses-core target_link_libraries(notcurses-core
PRIVATE PRIVATE

View File

@ -354,7 +354,6 @@ typedef enum {
NCPIXEL_NONE = 0, NCPIXEL_NONE = 0,
NCPIXEL_SIXEL, // sixel NCPIXEL_SIXEL, // sixel
NCPIXEL_LINUXFB, // linux framebuffer NCPIXEL_LINUXFB, // linux framebuffer
NCPIXEL_ITERM2, // iTerm2
// C=1 (disabling scrolling) was only introduced in 0.20.0, at the same // C=1 (disabling scrolling) was only introduced in 0.20.0, at the same
// time as animation. prior to this, graphics had to be entirely redrawn // time as animation. prior to this, graphics had to be entirely redrawn
// on any change, and it wasn't possible to use the bottom line. // on any change, and it wasn't possible to use the bottom line.
@ -368,6 +367,7 @@ typedef enum {
// original image (which we now deflate, since we needn't unpack it later). // original image (which we now deflate, since we needn't unpack it later).
// the only data we need keep is the auxvecs. // the only data we need keep is the auxvecs.
NCPIXEL_KITTY_SELFREF, NCPIXEL_KITTY_SELFREF,
NCPIXEL_DRM, // direct rendering manager (unix)
} ncpixelimpl_e; } ncpixelimpl_e;
// Returns a non-zero constant corresponding to some pixel-blitting // Returns a non-zero constant corresponding to some pixel-blitting

View File

@ -43,10 +43,10 @@ typedef enum {
NCPIXEL_NONE = 0, NCPIXEL_NONE = 0,
NCPIXEL_SIXEL, // sixel NCPIXEL_SIXEL, // sixel
NCPIXEL_LINUXFB, // linux framebuffer NCPIXEL_LINUXFB, // linux framebuffer
NCPIXEL_ITERM2, // iTerm2
NCPIXEL_KITTY_STATIC, // kitty pre-0.20.0 NCPIXEL_KITTY_STATIC, // kitty pre-0.20.0
NCPIXEL_KITTY_ANIMATED, // kitty pre-0.22.0 NCPIXEL_KITTY_ANIMATED, // kitty pre-0.22.0
NCPIXEL_KITTY_SELFREF, // kitty 0.22.0+, wezterm NCPIXEL_KITTY_SELFREF, // kitty 0.22.0+, wezterm
NCPIXEL_DRM, // direct rendering manager
} ncpixelimpl_e; } ncpixelimpl_e;
``` ```

View File

@ -1418,7 +1418,6 @@ typedef enum {
NCPIXEL_NONE = 0, NCPIXEL_NONE = 0,
NCPIXEL_SIXEL, // sixel NCPIXEL_SIXEL, // sixel
NCPIXEL_LINUXFB, // linux framebuffer NCPIXEL_LINUXFB, // linux framebuffer
NCPIXEL_ITERM2, // iTerm2
// C=1 (disabling scrolling) was only introduced in 0.20.0, at the same // C=1 (disabling scrolling) was only introduced in 0.20.0, at the same
// time as animation. prior to this, graphics had to be entirely redrawn // time as animation. prior to this, graphics had to be entirely redrawn
// on any change, and it wasn't possible to use the bottom line. // on any change, and it wasn't possible to use the bottom line.
@ -1432,6 +1431,7 @@ typedef enum {
// original image (which we now deflate, since we needn't unpack it later). // original image (which we now deflate, since we needn't unpack it later).
// the only data we need keep is the auxvecs. // the only data we need keep is the auxvecs.
NCPIXEL_KITTY_SELFREF, NCPIXEL_KITTY_SELFREF,
NCPIXEL_DRM, // direct rendering manager (unix)
} ncpixelimpl_e; } ncpixelimpl_e;
// Can we blit pixel-accurate bitmaps? // Can we blit pixel-accurate bitmaps?

View File

@ -386,8 +386,8 @@ tinfo_debug_bitmaps(struct ncplane* n, const tinfo* ti, const char* indent){
case NCPIXEL_LINUXFB: case NCPIXEL_LINUXFB:
ncplane_printf(n, "%sframebuffer graphics supported", indent); ncplane_printf(n, "%sframebuffer graphics supported", indent);
break; break;
case NCPIXEL_ITERM2: case NCPIXEL_DRM:
ncplane_printf(n, "%siTerm2 graphics supported", indent); ncplane_printf(n, "%sDRM graphics supported", indent);
break; break;
case NCPIXEL_KITTY_STATIC: case NCPIXEL_KITTY_STATIC:
ncplane_printf(n, "%srgba pixel graphics support", indent); ncplane_printf(n, "%srgba pixel graphics support", indent);

View File

@ -737,11 +737,41 @@ int get_linux_fb_pixelgeom(tinfo* ti, unsigned* ypix, unsigned *xpix){
return 0; return 0;
} }
#ifdef USE_DRM
#include <xf86drm.h>
#include <xf86drmMode.h>
bool is_linux_drm(tinfo* ti){
// FIXME need check for multiple devices! same problem below for framebuffers
const char* dev = "/dev/dri/card1";
loginfo("checking for linux drm at %s\n", dev);
int fd = open(dev, O_RDWR | O_CLOEXEC);
if(fd < 0){
logdebug("couldn't open drm device %s\n", dev);
return false;
}
drmModeResPtr dptr = drmModeGetResources(fd);
if(dptr == NULL){
close(fd);
return false;
}
loginfo("found drm on %s (fd %d)\n", dev, fd);
close(fd);
// FIXME
return true;
}
#else
bool is_linux_drm(tinfo* ti){
(void)ti;
return false;
}
#endif
bool is_linux_framebuffer(tinfo* ti){ bool is_linux_framebuffer(tinfo* ti){
// FIXME there might be multiple framebuffers present; how do we determine // FIXME there might be multiple framebuffers present; how do we determine
// which one is ours? // which one is ours?
const char* dev = "/dev/fb0"; const char* dev = "/dev/fb0";
loginfo("Checking for Linux framebuffer at %s\n", dev); loginfo("checking for linux framebuffer at %s\n", dev);
int fd = open(dev, O_RDWR | O_CLOEXEC); int fd = open(dev, O_RDWR | O_CLOEXEC);
if(fd < 0){ if(fd < 0){
logdebug("Couldn't open framebuffer device %s\n", dev); logdebug("Couldn't open framebuffer device %s\n", dev);

View File

@ -26,6 +26,10 @@ bool is_linux_console(int fd);
int reprogram_console_font(struct tinfo* ti, unsigned no_font_changes, int reprogram_console_font(struct tinfo* ti, unsigned no_font_changes,
bool* halfblocks, bool* quadrants); bool* halfblocks, bool* quadrants);
// if is_linux_console() returned true, call this to determine whether it is
// a drawable DRM buffer. do not call if not a verified console!
bool is_linux_drm(struct tinfo* ti);
// if is_linux_console() returned true, call this to determine whether it is // if is_linux_console() returned true, call this to determine whether it is
// a drawable framebuffer console. do not call if not a verified console! // a drawable framebuffer console. do not call if not a verified console!
bool is_linux_framebuffer(struct tinfo* ti); bool is_linux_framebuffer(struct tinfo* ti);

View File

@ -114,7 +114,7 @@ setup_kitty_bitmaps(tinfo* ti, int fd, ncpixelimpl_e level){
#ifdef __linux__ #ifdef __linux__
static inline void static inline void
setup_fbcon_bitmaps(tinfo* ti, int fd){ setup_fbcon_bitmaps(tinfo* ti, int fd, ncpixelimpl_e impl){
ti->pixel_scrub = fbcon_scrub; ti->pixel_scrub = fbcon_scrub;
ti->pixel_remove = NULL; ti->pixel_remove = NULL;
ti->pixel_draw = NULL; ti->pixel_draw = NULL;
@ -128,7 +128,7 @@ setup_fbcon_bitmaps(tinfo* ti, int fd){
ti->pixel_wipe = fbcon_wipe; ti->pixel_wipe = fbcon_wipe;
ti->pixel_trans_auxvec = kitty_trans_auxvec; ti->pixel_trans_auxvec = kitty_trans_auxvec;
set_pixel_blitter(fbcon_blit); set_pixel_blitter(fbcon_blit);
ti->pixel_implementation = NCPIXEL_LINUXFB; ti->pixel_implementation = impl;
sprite_init(ti, fd); sprite_init(ti, fd);
} }
#endif #endif
@ -677,18 +677,15 @@ apply_term_heuristics(tinfo* ti, const char* termname, queried_terminals_e qterm
// no quadrants, no sextants, no rgb, but it does have braille // no quadrants, no sextants, no rgb, but it does have braille
#ifdef __linux__ #ifdef __linux__
}else if(qterm == TERMINAL_LINUX){ }else if(qterm == TERMINAL_LINUX){
struct utsname un; if(is_linux_drm(ti)){
if(uname(&un) == 0){ termname = "DRM";
ti->termversion = strdup(un.release); setup_fbcon_bitmaps(ti, ti->linux_fb_fd, NCPIXEL_DRM);
} }else if(is_linux_framebuffer(ti)){
if(is_linux_framebuffer(ti)){ termname = "FBcon";
termname = "Linux framebuffer"; setup_fbcon_bitmaps(ti, ti->linux_fb_fd, NCPIXEL_LINUXFB);
setup_fbcon_bitmaps(ti, ti->linux_fb_fd);
}else{ }else{
termname = "Linux console"; termname = "Linux VT";
} }
ti->caps.halfblocks = false;
ti->caps.braille = false; // no caps.braille, no caps.sextants in linux console
if(ti->ttyfd >= 0){ if(ti->ttyfd >= 0){
reprogram_console_font(ti, nonewfonts, &ti->caps.halfblocks, reprogram_console_font(ti, nonewfonts, &ti->caps.halfblocks,
&ti->caps.quadrants); &ti->caps.quadrants);

View File

@ -179,7 +179,7 @@ typedef struct tinfo {
int gpmfd; // connection to GPM daemon int gpmfd; // connection to GPM daemon
pthread_t gpmthread; // thread handle for GPM watcher pthread_t gpmthread; // thread handle for GPM watcher
#ifdef __linux__ #ifdef __linux__
int linux_fb_fd; // linux framebuffer device fd int linux_fb_fd; // linux drm/fbcon device fd
char* linux_fb_dev; // device corresponding to linux_fb_dev char* linux_fb_dev; // device corresponding to linux_fb_dev
uint8_t* linux_fbuffer; // mmap()ed framebuffer uint8_t* linux_fbuffer; // mmap()ed framebuffer
size_t linux_fb_len; // size of map size_t linux_fb_len; // size of map

View File

@ -1,5 +1,6 @@
// Populated by CMake; not installed // Populated by CMake; not installed
#cmakedefine DFSG_BUILD #cmakedefine DFSG_BUILD
#cmakedefine USE_DRM
#cmakedefine USE_GPM #cmakedefine USE_GPM
#cmakedefine USE_QRCODEGEN #cmakedefine USE_QRCODEGEN
// exclusive with USE_OIIO // exclusive with USE_OIIO