JeffyCN / drm-cursor

Fake cursor plane with regular drm plane.
GNU Lesser General Public License v2.1
7 stars 5 forks source link

current version seem's not to support changing resolution #3

Closed docterling closed 1 year ago

docterling commented 1 year ago

in rk3566,after boot it works fine but when i change output res 4k@30 to 1080P60,the cursor disappered,and the log:

[48212.563] DRM_INFO: drm_get_ctx(499) atomic drm API enabled [48212.563] DRM_INFO: drm_get_ctx(532) max fps: 60 [48212.563] DRM_DEBUG: drm_get_ctx(587) found 0 CRTC: 85(0) (3840x2160) prefer plane: 0 [48212.563] DRM_DEBUG: drm_get_ctx(595) found 1 CRTCs [48212.563] DRM_DEBUG: drm_get_ctx(644) found plane: 57[primary] crtcs: 0x1 (ARGB) [48212.563] DRM_DEBUG: drm_get_ctx(644) found plane: 71[cursor ] crtcs: 0x1 (AFBC) [48212.563] DRM_DEBUG: drm_get_ctx(644) found plane: 87[overlay] crtcs: 0x1 (ARGB) [48212.563] DRM_INFO: drm_get_ctx(653) using libdrm-cursor (1.4.0~20220929) [48212.563] DRM_DEBUG: drmModeSetCursor(1249) fd: 4 crtc: 85 handle: 4 size: 48x48 [48212.564] DRM_INFO: drm_crtc_bind_plane(717) CRTC[85]: using cursor plane [48212.564] DRM_DEBUG: drm_crtc_bind_plane(724) CRTC[85]: bind plane: 71(AFBC) [48212.565] DRM_DEBUG: drm_crtc_thread_fn(917) CRTC[85]: thread started [48212.565] DRM_DEBUG: drm_set_cursor(1144) CRTC[85]: request setting new cursor 4 (48x48) [48212.565] DRM_DEBUG: drm_crtc_thread_fn(975) CRTC[85]: set new cursor 4 (48x48) [48212.565] DRM_DEBUG: drm_crtc_create_fb(872) CRTC[85]: convert FB from 4 (48x48) to (48x48) offset: (0,0) [48212.583] DRM_ERROR: egl_init_ctx(283) failed to find EGL config for AB24, force using the first [48212.644] DRM_DEBUG: drm_crtc_create_fb(904) CRTC[85]: created FB: 152 [48212.644] DRM_DEBUG: drm_crtc_update_cursor(845) CRTC[85]: setting fb: 152 (48x48) on plane: 71 at (0,0) [48212.658] DRM_INFO: drm_crtc_thread_fn(1023) CRTC[85]: it works! [48261.045] DRM_DEBUG: drmModeSetCursor(1249) fd: 4 crtc: 85 handle: 4 size: 32x32 [48261.045] DRM_DEBUG: drm_set_cursor(1144) CRTC[85]: request setting new cursor 4 (32x32) [48261.045] DRM_DEBUG: drm_crtc_thread_fn(975) CRTC[85]: set new cursor 4 (32x32) [48261.045] DRM_DEBUG: drm_crtc_create_fb(872) CRTC[85]: convert FB from 4 (32x32) to (32x32) offset: (0,0) [48261.045] DRM_ERROR: egl_handle_to_fd(366) failed to get fd (2) [48261.045] DRM_ERROR: egl_convert_fb(473) failed to get dma fd [48261.045] DRM_ERROR: drm_crtc_create_fb(900) CRTC[85]: failed to create FB [48261.052] DRM_DEBUG: drm_crtc_update_cursor(820) CRTC[85]: disabling cursor [48261.052] DRM_DEBUG: drm_crtc_thread_fn(1043) CRTC[85]: thread error

could u see what's going on here

JeffyCN commented 1 year ago

it works well on my side.

[48261.045] DRM_DEBUG: drmModeSetCursor(1249) fd: 4 crtc: 85 handle: 4 size: 32x32
[48261.045] DRM_DEBUG: drm_crtc_create_fb(872) CRTC[85]: convert FB from 4 (32x32) to (32x32) offset: (0,0)
[48261.045] DRM_ERROR: egl_handle_to_fd(366) failed to get fd (2)

it means that the client tries to set drm FB with handle 4 as the cursor image, but the drm driver report ENOENT error(buf not exist).

so it seems like a client buf management issue or drm driver buf life-cycle issue, you can add logs there to debug.

docterling commented 1 year ago

when i change res i will close the drm fd and reopen it,so it looks like the fds were the same(4) but not when call drmModeSetCursor->drm_get_ctx if (ctx->inited) return ctx; if(ctx->fd < 0) return NULL; ctx->fd = dup(fd); if(ctx->fd < 0) return NULL; first calling it will dup the fd,second call to this inited flag is true,it will return,ctx->fd was the first fd that i already close,does this the problem?

JeffyCN commented 1 year ago

write, different file context would not share fb handles.

JeffyCN commented 1 year ago

try this:

+++ b/drm_cursor.c
@@ -472,8 +472,13 @@ static drm_ctx *drm_get_ctx(int fd)
   uint32_t i, max_fps, count_crtcs;
   const char *config;

-  if (ctx->inited)
+  if (ctx->inited) {
+    if (ctx->fd != fd) {
+      close(ctx->fd);
+      ctx->fd = dup(fd);
+    }
     return ctx;
+  }
docterling commented 1 year ago

but the fds were the same,it's 4 maybe i should use an api to update the ctx->fd

JeffyCN commented 1 year ago

there's no easy way to tell that are the ctx->fd and new fd the same one(duped)...maybe i can try to use fcntl to check it

docterling commented 1 year ago

i've added a new api int drmModeUpdateCursorFd(int fd) { drm_ctx *ctx; ctx = drm_get_ctx(-1); if(ctx) { if(ctx->fd > 0) close(ctx->fd); ctx->fd = dup(fd); DRM_DEBUG("drmModeUpdateCursorFd ok...\n"); return 0; } DRM_DEBUG("drmModeUpdateCursorFd drm_get_ctx failed...\n"); return -1; } before i call drmModeSetCursor,i call drmModeUpdateCursorFd first,and it print ok,but the same error

[66068.682] DRM_DEBUG: drmModeUpdateCursorFd(1237) drmModeUpdateCursorFd ok... [66068.682] DRM_DEBUG: drmModeSetCursor(1265) fd: 4 crtc: 85 handle: 4 size: 32x32 [66068.682] DRM_DEBUG: drm_set_cursor(1145) CRTC[85]: request setting new cursor 4 (32x32) [66068.682] DRM_DEBUG: drm_crtc_thread_fn(976) CRTC[85]: set new cursor 4 (32x32) [66068.682] DRM_DEBUG: drm_crtc_create_fb(873) CRTC[85]: convert FB from 4 (32x32) to (32x32) offset: (0,450) [66068.682] DRM_ERROR: egl_handle_to_fd(366) failed to get fd (2) [66068.682] DRM_ERROR: egl_convert_fb(473) failed to get dma fd [66068.682] DRM_ERROR: drm_crtc_create_fb(901) CRTC[85]: failed to create FB [66068.689] DRM_DEBUG: drm_crtc_update_cursor(821) CRTC[85]: disabling cursor [66068.689] DRM_DEBUG: drm_crtc_thread_fn(1044) CRTC[85]: thread error

maybe it must do drmModeFreexxx and reinit all the things

JeffyCN commented 1 year ago

have you tried https://github.com/JeffyCN/drm-cursor/issues/3#issuecomment-1489839253

docterling commented 1 year ago

yes,the same i've found another thing crtc->egl_ctx,maybe it should reinit too.

JeffyCN commented 1 year ago

try this: https://github.com/JeffyCN/drm-cursor/commit/8b91f46bbe5e20dcabc1ab323e45f1ee52ceb5d5

docterling commented 1 year ago

[37211.887] DRM_INFO: drm_get_ctx(511) atomic drm API enabled [37211.887] DRM_INFO: drm_get_ctx(544) max fps: 60 [37211.887] DRM_DEBUG: drm_get_ctx(599) found 0 CRTC: 85(0) (1920x1080) prefer plane: 0 [37211.887] DRM_DEBUG: drm_get_ctx(607) found 1 CRTCs [37211.887] DRM_DEBUG: drm_get_ctx(656) found plane: 57[primary] crtcs: 0x1 (ARGB) [37211.887] DRM_DEBUG: drm_get_ctx(656) found plane: 71[cursor ] crtcs: 0x1 (AFBC) [37211.887] DRM_DEBUG: drm_get_ctx(656) found plane: 87[overlay] crtcs: 0x1 (ARGB) [37211.887] DRM_INFO: drm_get_ctx(665) using libdrm-cursor (1.4.0~20220929) [37211.887] DRM_DEBUG: drmModeSetCursor(1277) fd: 9 crtc: 85 handle: 4 size: 32x32 [37211.887] DRM_INFO: drm_crtc_bind_plane(729) CRTC[85]: using cursor plane [37211.887] DRM_DEBUG: drm_crtc_bind_plane(736) CRTC[85]: bind plane: 71(AFBC) [37211.888] DRM_DEBUG: drm_set_cursor(1157) CRTC[85]: request setting new cursor 4 (32x32) [37211.888] DRM_DEBUG: drm_crtc_thread_fn(930) CRTC[85]: thread started

no egl print,maybe some error ecurre,so it can't work

JeffyCN commented 1 year ago

forgot to handle -1 fd case(for thread_fn)

+++ b/drm_cursor.c
@@ -472,6 +472,9 @@ static drm_ctx *drm_get_ctx(int fd)
   uint32_t i, max_fps, count_crtcs;
   const char *config;

+  if (fd < 0)
+    return ctx;
docterling commented 1 year ago

yeah,it can show up now,but it looks like incorrect image when boot up the res is 4k@30,and the cursor size is 48x48,after change res to 1080P60,cursor size now set to 32x32 from the result pic show it seems like crop 32x32 from previeous 48x48 maybe the egl_ctx should reinit

JeffyCN commented 1 year ago

try the newest version, that function was broken by earlier commit

docterling commented 1 year ago

i've tried the newest version, chang res 4096x2160@60-4096x2160@30-3840x2160@60-.(many common res).-1024x768@60 and vice versa many times,it works fine.thanks. by the way,in high res(e.g.4096x2160@60) the mouse pointer speed feel slower than low res(e.g.1024x768@60) for now i read the /dev/input/eventx to get the x y of the mouse,and drmModeMoveCursor to move the pointer,no X and wayland things,is it possible to speed up the pointer?

JeffyCN commented 1 year ago

i don't think the cursor speed would be affected by screen resolution, unless the cursor size changed or slower in the client side

docterling commented 1 year ago

ok thx again