Skip to content

Commit 30b09ed

Browse files
committed
modesetting: add "FallbackCursor" option
On many cards, SIZE_HINTS isn't implemented, so the hardware cursor used is the fallback one. With this, we allow the user to specify what size the hardware cursor should have, instead of forcing 64x64. Signed-off-by: stefan11111 <[email protected]>
1 parent 4089219 commit 30b09ed

File tree

4 files changed

+64
-23
lines changed

4 files changed

+64
-23
lines changed

hw/xfree86/drivers/video/modesetting/driver.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ static SymTabRec Chipsets[] = {
131131

132132
static const OptionInfoRec Options[] = {
133133
{OPTION_SW_CURSOR, "SWcursor", OPTV_BOOLEAN, {0}, FALSE},
134+
{OPTION_FALLBACK_CURSOR, "FallbackCursor", OPTV_STRING, {0}, FALSE},
134135
{OPTION_DEVICE_PATH, "kmsdev", OPTV_STRING, {0}, FALSE},
135136
{OPTION_SHADOW_FB, "ShadowFB", OPTV_BOOLEAN, {0}, FALSE},
136137
{OPTION_ACCEL_METHOD, "AccelMethod", OPTV_STRING, {0}, FALSE},

hw/xfree86/drivers/video/modesetting/driver.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ struct ms_vrr_priv {
5454

5555
typedef enum {
5656
OPTION_SW_CURSOR,
57+
OPTION_FALLBACK_CURSOR,
5758
OPTION_DEVICE_PATH,
5859
OPTION_SHADOW_FB,
5960
OPTION_ACCEL_METHOD,

hw/xfree86/drivers/video/modesetting/drmmode_display.c

Lines changed: 58 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2785,8 +2785,63 @@ drmmode_crtc_vrr_init(int drm_fd, xf86CrtcPtr crtc)
27852785
drmModeFreeObjectProperties(drm_props);
27862786
}
27872787

2788+
static drmmode_cursor_dim_rec
2789+
drmmode_cursor_get_fallback(drmmode_ptr drmmode)
2790+
{
2791+
drmmode_cursor_dim_rec fallback;
2792+
2793+
const char *fallback_cursor_str = xf86GetOptValString(drmmode->Options,
2794+
OPTION_FALLBACK_CURSOR);
2795+
2796+
char *height;
2797+
2798+
if (!fallback_cursor_str) {
2799+
goto kms_default;
2800+
}
2801+
2802+
errno = 0;
2803+
fallback.width = strtol(fallback_cursor_str, &height, 10);
2804+
if (errno || fallback.width == 0) {
2805+
goto kms_default;
2806+
}
2807+
2808+
if (*height == '\0') {
2809+
/* we have a width, but don't have a height */
2810+
fallback.height = fallback.width;
2811+
return fallback;
2812+
}
2813+
2814+
fallback.height = strtol(height + 1, NULL, 10);
2815+
if (errno || fallback.height == 0) {
2816+
goto kms_default;
2817+
}
2818+
2819+
return fallback;
2820+
kms_default:
2821+
/* This is the safest fallback value as
2822+
* it is the default value that KMS uses. */
2823+
fallback = (drmmode_cursor_dim_rec){
2824+
.width = 64,
2825+
.height = 64,
2826+
};
2827+
2828+
#if 0 /* We could instead use the largest possible cursor, but that uses more power */
2829+
ret = drmGetCap(drmmode->fd, DRM_CAP_CURSOR_WIDTH, &value);
2830+
if (!ret) {
2831+
fallback.width = value;
2832+
}
2833+
2834+
ret = drmGetCap(drmmode->fd, DRM_CAP_CURSOR_HEIGHT, &value);
2835+
if (!ret) {
2836+
fallback.height = value;
2837+
}
2838+
#endif
2839+
2840+
return fallback;
2841+
}
2842+
27882843
static unsigned int
2789-
drmmode_crtc_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, drmModeResPtr mode_res, drmmode_cursor_dim_rec fallback, int num)
2844+
drmmode_crtc_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, drmModeResPtr mode_res, int num)
27902845
{
27912846
xf86CrtcPtr crtc;
27922847
drmmode_crtc_private_ptr drmmode_crtc;
@@ -2817,8 +2872,7 @@ drmmode_crtc_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, drmModeResPtr mode_res
28172872
drmmode_crtc->cursor.num_dimensions = 1;
28182873
drmmode_crtc->cursor.dimensions = xnfalloc(sizeof(drmmode_cursor_dim_rec));
28192874

2820-
drmmode_crtc->cursor.dimensions[0].width = fallback.width;
2821-
drmmode_crtc->cursor.dimensions[0].height = fallback.height;
2875+
drmmode_crtc->cursor.dimensions[0] = drmmode_cursor_get_fallback(drmmode);
28222876

28232877
props = drmModeObjectGetProperties(drmmode->fd, mode_res->crtcs[num],
28242878
DRM_MODE_OBJECT_CRTC);
@@ -4143,31 +4197,12 @@ drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp)
41434197
xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, MS_LOGLEVEL_DEBUG,
41444198
"Up to %d crtcs needed for screen.\n", crtcs_needed);
41454199

4146-
/* This is the safest fallback value as
4147-
* it is the default value that KMS uses. */
4148-
drmmode_cursor_dim_rec fallback = {
4149-
.width = 64,
4150-
.height = 64,
4151-
};
4152-
4153-
#if 0 /* We could instead use the largest possible cursor, but that uses more power */
4154-
ret = drmGetCap(drmmode->fd, DRM_CAP_CURSOR_WIDTH, &value);
4155-
if (!ret) {
4156-
fallback.width = value;
4157-
}
4158-
4159-
ret = drmGetCap(drmmode->fd, DRM_CAP_CURSOR_HEIGHT, &value);
4160-
if (!ret) {
4161-
fallback.height = value;
4162-
}
4163-
#endif
4164-
41654200
xf86CrtcSetSizeRange(pScrn, 320, 200, mode_res->max_width,
41664201
mode_res->max_height);
41674202
for (i = 0; i < mode_res->count_crtcs; i++)
41684203
if (!xf86IsEntityShared(pScrn->entityList[0]) ||
41694204
(crtcs_needed && !(ms_ent->assigned_crtcs & (1 << i))))
4170-
crtcs_needed -= drmmode_crtc_init(pScrn, drmmode, mode_res, fallback, i);
4205+
crtcs_needed -= drmmode_crtc_init(pScrn, drmmode, mode_res, i);
41714206

41724207
/* All ZaphodHeads outputs provided with matching crtcs? */
41734208
if (xf86IsEntityShared(pScrn->entityList[0]) && (crtcs_needed > 0))

hw/xfree86/drivers/video/modesetting/modesetting.man

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ are supported:
4949
Selects software cursor. The default is
5050
.B off.
5151
.TP
52+
.BI "Option \*qFallbackCursor\*q \*q" string \*q
53+
The size of the cursor to use if SIZE_HINTS isn't available.
54+
The default is "64x64".
55+
.TP
5256
.BI "Option \*qkmsdev\*q \*q" string \*q
5357
The framebuffer device to use. Default: /dev/dri/card0.
5458
.TP

0 commit comments

Comments
 (0)