mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-09 09:09:03 -04:00
[DRM] open with drmModeGetResources()
This commit is contained in:
parent
66fdb620b7
commit
642ac08e31
@ -232,6 +232,7 @@ target_include_directories(notcurses-core
|
||||
"${PROJECT_BINARY_DIR}/include"
|
||||
"${TERMINFO_INCLUDE_DIRS}"
|
||||
"${ZLIB_INCLUDE_DIRS}"
|
||||
"${DRM_INCLUDE_DIRS}"
|
||||
)
|
||||
target_include_directories(notcurses-core-static
|
||||
BEFORE
|
||||
@ -242,6 +243,7 @@ target_include_directories(notcurses-core-static
|
||||
"${PROJECT_BINARY_DIR}/include"
|
||||
"${TERMINFO_STATIC_INCLUDE_DIRS}"
|
||||
"${ZLIB_STATIC_INCLUDE_DIRS}"
|
||||
"${DRM_STATIC_INCLUDE_DIRS}"
|
||||
)
|
||||
target_link_libraries(notcurses-core
|
||||
PRIVATE
|
||||
|
2
USAGE.md
2
USAGE.md
@ -354,7 +354,6 @@ typedef enum {
|
||||
NCPIXEL_NONE = 0,
|
||||
NCPIXEL_SIXEL, // sixel
|
||||
NCPIXEL_LINUXFB, // linux framebuffer
|
||||
NCPIXEL_ITERM2, // iTerm2
|
||||
// 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
|
||||
// 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).
|
||||
// the only data we need keep is the auxvecs.
|
||||
NCPIXEL_KITTY_SELFREF,
|
||||
NCPIXEL_DRM, // direct rendering manager (unix)
|
||||
} ncpixelimpl_e;
|
||||
|
||||
// Returns a non-zero constant corresponding to some pixel-blitting
|
||||
|
@ -43,10 +43,10 @@ typedef enum {
|
||||
NCPIXEL_NONE = 0,
|
||||
NCPIXEL_SIXEL, // sixel
|
||||
NCPIXEL_LINUXFB, // linux framebuffer
|
||||
NCPIXEL_ITERM2, // iTerm2
|
||||
NCPIXEL_KITTY_STATIC, // kitty pre-0.20.0
|
||||
NCPIXEL_KITTY_ANIMATED, // kitty pre-0.22.0
|
||||
NCPIXEL_KITTY_SELFREF, // kitty 0.22.0+, wezterm
|
||||
NCPIXEL_DRM, // direct rendering manager
|
||||
} ncpixelimpl_e;
|
||||
```
|
||||
|
||||
|
@ -1418,7 +1418,6 @@ typedef enum {
|
||||
NCPIXEL_NONE = 0,
|
||||
NCPIXEL_SIXEL, // sixel
|
||||
NCPIXEL_LINUXFB, // linux framebuffer
|
||||
NCPIXEL_ITERM2, // iTerm2
|
||||
// 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
|
||||
// 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).
|
||||
// the only data we need keep is the auxvecs.
|
||||
NCPIXEL_KITTY_SELFREF,
|
||||
NCPIXEL_DRM, // direct rendering manager (unix)
|
||||
} ncpixelimpl_e;
|
||||
|
||||
// Can we blit pixel-accurate bitmaps?
|
||||
|
@ -386,8 +386,8 @@ tinfo_debug_bitmaps(struct ncplane* n, const tinfo* ti, const char* indent){
|
||||
case NCPIXEL_LINUXFB:
|
||||
ncplane_printf(n, "%sframebuffer graphics supported", indent);
|
||||
break;
|
||||
case NCPIXEL_ITERM2:
|
||||
ncplane_printf(n, "%siTerm2 graphics supported", indent);
|
||||
case NCPIXEL_DRM:
|
||||
ncplane_printf(n, "%sDRM graphics supported", indent);
|
||||
break;
|
||||
case NCPIXEL_KITTY_STATIC:
|
||||
ncplane_printf(n, "%srgba pixel graphics support", indent);
|
||||
|
@ -737,11 +737,41 @@ int get_linux_fb_pixelgeom(tinfo* ti, unsigned* ypix, unsigned *xpix){
|
||||
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){
|
||||
// FIXME there might be multiple framebuffers present; how do we determine
|
||||
// which one is ours?
|
||||
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);
|
||||
if(fd < 0){
|
||||
logdebug("Couldn't open framebuffer device %s\n", dev);
|
||||
|
@ -26,6 +26,10 @@ bool is_linux_console(int fd);
|
||||
int reprogram_console_font(struct tinfo* ti, unsigned no_font_changes,
|
||||
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
|
||||
// a drawable framebuffer console. do not call if not a verified console!
|
||||
bool is_linux_framebuffer(struct tinfo* ti);
|
||||
|
@ -114,7 +114,7 @@ setup_kitty_bitmaps(tinfo* ti, int fd, ncpixelimpl_e level){
|
||||
|
||||
#ifdef __linux__
|
||||
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_remove = NULL;
|
||||
ti->pixel_draw = NULL;
|
||||
@ -128,7 +128,7 @@ setup_fbcon_bitmaps(tinfo* ti, int fd){
|
||||
ti->pixel_wipe = fbcon_wipe;
|
||||
ti->pixel_trans_auxvec = kitty_trans_auxvec;
|
||||
set_pixel_blitter(fbcon_blit);
|
||||
ti->pixel_implementation = NCPIXEL_LINUXFB;
|
||||
ti->pixel_implementation = impl;
|
||||
sprite_init(ti, fd);
|
||||
}
|
||||
#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
|
||||
#ifdef __linux__
|
||||
}else if(qterm == TERMINAL_LINUX){
|
||||
struct utsname un;
|
||||
if(uname(&un) == 0){
|
||||
ti->termversion = strdup(un.release);
|
||||
}
|
||||
if(is_linux_framebuffer(ti)){
|
||||
termname = "Linux framebuffer";
|
||||
setup_fbcon_bitmaps(ti, ti->linux_fb_fd);
|
||||
if(is_linux_drm(ti)){
|
||||
termname = "DRM";
|
||||
setup_fbcon_bitmaps(ti, ti->linux_fb_fd, NCPIXEL_DRM);
|
||||
}else if(is_linux_framebuffer(ti)){
|
||||
termname = "FBcon";
|
||||
setup_fbcon_bitmaps(ti, ti->linux_fb_fd, NCPIXEL_LINUXFB);
|
||||
}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){
|
||||
reprogram_console_font(ti, nonewfonts, &ti->caps.halfblocks,
|
||||
&ti->caps.quadrants);
|
||||
|
@ -179,7 +179,7 @@ typedef struct tinfo {
|
||||
int gpmfd; // connection to GPM daemon
|
||||
pthread_t gpmthread; // thread handle for GPM watcher
|
||||
#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
|
||||
uint8_t* linux_fbuffer; // mmap()ed framebuffer
|
||||
size_t linux_fb_len; // size of map
|
||||
|
@ -1,5 +1,6 @@
|
||||
// Populated by CMake; not installed
|
||||
#cmakedefine DFSG_BUILD
|
||||
#cmakedefine USE_DRM
|
||||
#cmakedefine USE_GPM
|
||||
#cmakedefine USE_QRCODEGEN
|
||||
// exclusive with USE_OIIO
|
||||
|
Loading…
x
Reference in New Issue
Block a user