Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Ayn Loki panel refresh rates in gamescope #9

Open
wants to merge 17 commits into
base: gamescope-plus
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 122 additions & 8 deletions src/drm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ struct drm_t g_DRM = {};
uint32_t g_nDRMFormat = DRM_FORMAT_INVALID;
uint32_t g_nDRMFormatOverlay = DRM_FORMAT_INVALID; // for partial composition, we may have more limited formats than base planes + alpha.
bool g_bRotated = false;
bool g_rotate_ctl_enable = false;
bool g_bDisplayTypeInternal = false;
bool g_bUseLayers = true;
bool g_bDebugLayers = false;
const char *g_sOutputName = nullptr;
uint32_t targetConnector;

#ifndef DRM_CAP_ATOMIC_ASYNC_PAGE_FLIP
#define DRM_CAP_ATOMIC_ASYNC_PAGE_FLIP 0x15
Expand All @@ -65,7 +68,10 @@ bool g_bSupportsAsyncFlips = false;

enum drm_mode_generation g_drmModeGeneration = DRM_MODE_GENERATE_CVT;
enum g_panel_orientation g_drmModeOrientation = PANEL_ORIENTATION_AUTO;
enum g_rotate_ctl g_drmRotateCTL;
std::atomic<uint64_t> g_drmEffectiveOrientation[DRM_SCREEN_TYPE_COUNT]{ {DRM_MODE_ROTATE_0}, {DRM_MODE_ROTATE_0} };
enum g_panel_external_orientation g_drmModeExternalOrientation = PANEL_EXTERNAL_ORIENTATION_AUTO;
enum g_panel_type g_drmPanelType = PANEL_TYPE_AUTO;

bool g_bForceDisableColorMgmt = false;

Expand Down Expand Up @@ -95,6 +101,19 @@ static uint32_t galileo_display_rates[] =
90,
};

static uint32_t legion_go_display_rates[] =
{
60,
144,
};

static uint32_t loki_display_rates[] =
{
40,
50,
60,
};

static uint32_t get_conn_display_info_flags(struct drm_t *drm, struct connector *connector)
{
if (!connector)
Expand Down Expand Up @@ -905,8 +924,13 @@ static void parse_edid( drm_t *drm, struct connector *conn)
conn->valid_display_rates = std::span(galileo_display_rates);
} else {
conn->is_galileo_display = 0;
if ( conn->is_steam_deck_display )
if ( conn->is_steam_deck_display ) {
conn->valid_display_rates = std::span(steam_deck_display_rates);
} else if ( strcmp(conn->make_pnp, "LEN") == 0 && strcmp(conn->model, "Go Display") == 0 ) {
conn->valid_display_rates = std::span(legion_go_display_rates);
} else if ( strcmp(conn->make_pnp, "AYN") == 0 && strcmp(conn->model, "LK-GOLDSPV58") == 0 ) {
conn->valid_display_rates = std::span(loki_display_rates);
}
}

drm_hdr_parse_edid(drm, conn, edid);
Expand Down Expand Up @@ -1240,6 +1264,14 @@ static bool setup_best_connector(struct drm_t *drm, bool force, bool initial)
}
}

for (auto &kv : drm->connectors) {
struct connector *conn = &kv.second;
if ( conn->id == targetConnector)
{
best = conn;
}
}

if (!force) {
if ((!best && drm->connector) || (best && best == drm->connector)) {
// Let's keep our current connector
Expand Down Expand Up @@ -1970,8 +2002,29 @@ static uint64_t determine_drm_orientation(struct drm_t *drm, struct connector *c
static void update_drm_effective_orientation(struct drm_t *drm, struct connector *conn, const drmModeModeInfo *mode)
{
drm_screen_type screenType = drm_get_connector_type(conn->connector);

if (screenType == DRM_SCREEN_TYPE_INTERNAL)
if ( screenType == DRM_SCREEN_TYPE_EXTERNAL && g_bDisplayTypeInternal == true )
{
switch ( g_drmModeExternalOrientation )
{
case PANEL_EXTERNAL_ORIENTATION_0:
g_drmEffectiveOrientation[screenType] = DRM_MODE_ROTATE_0;
break;
case PANEL_EXTERNAL_ORIENTATION_90:
g_drmEffectiveOrientation[screenType] = DRM_MODE_ROTATE_90;
break;
case PANEL_EXTERNAL_ORIENTATION_180:
g_drmEffectiveOrientation[screenType] = DRM_MODE_ROTATE_180;
break;
case PANEL_EXTERNAL_ORIENTATION_270:
g_drmEffectiveOrientation[screenType] = DRM_MODE_ROTATE_270;
break;
case PANEL_EXTERNAL_ORIENTATION_AUTO:
g_drmEffectiveOrientation[screenType] = determine_drm_orientation(drm, conn, mode);
break;
}
return;
}
else if ( screenType == DRM_SCREEN_TYPE_INTERNAL )
{
switch ( g_drmModeOrientation )
{
Expand Down Expand Up @@ -2001,6 +2054,27 @@ static void update_drm_effective_orientation(struct drm_t *drm, struct connector
static void update_drm_effective_orientations(struct drm_t *drm, struct connector *conn, const drmModeModeInfo *mode)
{
drm_screen_type screenType = drm_get_connector_type(conn->connector);

if (g_rotate_ctl_enable)
{
switch (g_drmRotateCTL)
{
default:
case NORMAL:
g_drmEffectiveOrientation[screenType] = DRM_MODE_ROTATE_0;
break;
case LEFT_UP:
g_drmEffectiveOrientation[screenType] = DRM_MODE_ROTATE_90;
break;
case UPSIDEDOWN:
g_drmEffectiveOrientation[screenType] = DRM_MODE_ROTATE_180;
break;
case RIGHT_UP:
g_drmEffectiveOrientation[screenType] = DRM_MODE_ROTATE_270;
break;
}
return;
}
if (screenType == DRM_SCREEN_TYPE_INTERNAL)
{
update_drm_effective_orientation(drm, conn, mode);
Expand Down Expand Up @@ -2851,6 +2925,11 @@ static bool drm_set_crtc( struct drm_t *drm, struct crtc *crtc )
return true;
}

void drm_set_prefered_connector( struct drm_t *drm, uint32_t connector_type_id )
{
targetConnector = connector_type_id;
}

bool drm_set_connector( struct drm_t *drm, struct connector *conn )
{
drm_log.infof("selecting connector %s", conn->name);
Expand Down Expand Up @@ -2901,11 +2980,27 @@ bool drm_get_vrr_in_use(struct drm_t *drm)

drm_screen_type drm_get_connector_type(drmModeConnector *connector)
{
if (connector->connector_type == DRM_MODE_CONNECTOR_eDP ||
connector->connector_type == DRM_MODE_CONNECTOR_LVDS ||
connector->connector_type == DRM_MODE_CONNECTOR_DSI)
return DRM_SCREEN_TYPE_INTERNAL;

// Set to the default state of false to make sure the external display isn't rotated when a system is docked
g_bDisplayTypeInternal = false;
switch ( g_drmPanelType )
{
case PANEL_TYPE_INTERNAL:
return DRM_SCREEN_TYPE_INTERNAL;
break;
case PANEL_TYPE_EXTERNAL:
if (connector->connector_type == DRM_MODE_CONNECTOR_eDP ||
connector->connector_type == DRM_MODE_CONNECTOR_LVDS ||
connector->connector_type == DRM_MODE_CONNECTOR_DSI)
g_bDisplayTypeInternal = true;
return DRM_SCREEN_TYPE_EXTERNAL;
break;
case PANEL_TYPE_AUTO:
if (connector->connector_type == DRM_MODE_CONNECTOR_eDP ||
connector->connector_type == DRM_MODE_CONNECTOR_LVDS ||
connector->connector_type == DRM_MODE_CONNECTOR_DSI)
return DRM_SCREEN_TYPE_INTERNAL;
break;
}
return DRM_SCREEN_TYPE_EXTERNAL;
}

Expand Down Expand Up @@ -3074,6 +3169,25 @@ bool drm_set_refresh( struct drm_t *drm, int refresh )
return drm_set_mode(drm, &mode);
}

void drm_set_orientation( struct drm_t *drm, bool isRotated)
{
int width = g_nOutputWidth;
int height = g_nOutputHeight;
g_bRotated = isRotated;
if ( g_bRotated ) {
int tmp = width;
width = height;
height = tmp;
}

if (!drm->connector || !drm->connector->connector)
return;

drmModeConnector *connector = drm->connector->connector;
const drmModeModeInfo *mode = find_mode(connector, width, height, 0);
update_drm_effective_orientations(drm, drm->connector, mode);
}

bool drm_set_resolution( struct drm_t *drm, int width, int height )
{
if (!drm->connector || !drm->connector->connector)
Expand Down
27 changes: 27 additions & 0 deletions src/drm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,13 +335,39 @@ enum g_panel_orientation {
PANEL_ORIENTATION_AUTO,
};

enum g_rotate_ctl{
NORMAL,
LEFT_UP,
UPSIDEDOWN,
RIGHT_UP,
};
enum g_panel_external_orientation {
PANEL_EXTERNAL_ORIENTATION_0, /* NORMAL */
PANEL_EXTERNAL_ORIENTATION_270, /* RIGHT */
PANEL_EXTERNAL_ORIENTATION_90, /* LEFT */
PANEL_EXTERNAL_ORIENTATION_180, /* UPSIDE DOWN */
PANEL_EXTERNAL_ORIENTATION_AUTO,
};

enum g_panel_type {
PANEL_TYPE_INTERNAL,
PANEL_TYPE_EXTERNAL,
PANEL_TYPE_AUTO,
};

extern enum drm_mode_generation g_drmModeGeneration;
extern enum g_panel_orientation g_drmModeOrientation;
extern enum g_rotate_ctl g_drmRotateCTL;
extern bool g_rotate_ctl_enable;
extern enum g_panel_external_orientation g_drmModeExternalOrientation;
extern enum g_panel_type g_drmPanelType;

extern std::atomic<uint64_t> g_drmEffectiveOrientation[DRM_SCREEN_TYPE_COUNT]; // DRM_MODE_ROTATE_*

extern bool g_bForceDisableColorMgmt;

void drm_set_orientation( struct drm_t *drm, bool isRotated );

bool init_drm(struct drm_t *drm, int width, int height, int refresh, bool wants_adaptive_sync);
void finish_drm(struct drm_t *drm);
int drm_commit(struct drm_t *drm, const struct FrameInfo_t *frameInfo );
Expand All @@ -352,6 +378,7 @@ uint32_t drm_fbid_from_dmabuf( struct drm_t *drm, struct wlr_buffer *buf, struct
void drm_lock_fbid( struct drm_t *drm, uint32_t fbid );
void drm_unlock_fbid( struct drm_t *drm, uint32_t fbid );
void drm_drop_fbid( struct drm_t *drm, uint32_t fbid );
void drm_set_prefered_connector( struct drm_t *drm, uint32_t connector_type_id );
bool drm_set_connector( struct drm_t *drm, struct connector *conn );
bool drm_set_mode( struct drm_t *drm, const drmModeModeInfo *mode );
bool drm_set_refresh( struct drm_t *drm, int refresh );
Expand Down
42 changes: 42 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ const struct option *gamescope_options = (struct option[]){
{ "disable-xres", no_argument, nullptr, 'x' },
{ "fade-out-duration", required_argument, nullptr, 0 },
{ "force-orientation", required_argument, nullptr, 0 },
{ "force-external-orientation", required_argument, nullptr, 0 },
{ "force-panel-type", required_argument, nullptr, 0 },
{ "force-windows-fullscreen", no_argument, nullptr, 0 },

{ "disable-color-management", no_argument, nullptr, 0 },
Expand Down Expand Up @@ -167,6 +169,8 @@ const char usage[] =
" --xwayland-count create N xwayland servers\n"
" --prefer-vk-device prefer Vulkan device for compositing (ex: 1002:7300)\n"
" --force-orientation rotate the internal display (left, right, normal, upsidedown)\n"
" --force-external-orientation rotate the external display (left, right, normal, upsidedown)\n"
" --force-panel-type force gamescope to treat the display as either internal or external\n"
" --force-windows-fullscreen force windows inside of gamescope to be the size of the nested display (fullscreen)\n"
" --cursor-scale-height if specified, sets a base output height to linearly scale the cursor against.\n"
" --hdr-enabled enable HDR output (needs Gamescope WSI layer enabled for support from clients)\n"
Expand Down Expand Up @@ -265,6 +269,8 @@ bool g_bHeadless = false;

bool g_bGrabbed = false;

bool g_bExternalForced = false;

GamescopeUpscaleFilter g_upscaleFilter = GamescopeUpscaleFilter::LINEAR;
GamescopeUpscaleScaler g_upscaleScaler = GamescopeUpscaleScaler::AUTO;

Expand Down Expand Up @@ -353,6 +359,18 @@ static enum drm_mode_generation parse_drm_mode_generation(const char *str)
}
}

static enum g_panel_type force_panel_type(const char *str)
{
if (strcmp(str, "internal") == 0) {
return PANEL_TYPE_INTERNAL;
} else if (strcmp(str, "external") == 0) {
return PANEL_TYPE_EXTERNAL;
} else {
fprintf( stderr, "gamescope: invalid value for --force-panel-type\n" );
exit(1);
}
}

static enum g_panel_orientation force_orientation(const char *str)
{
if (strcmp(str, "normal") == 0) {
Expand Down Expand Up @@ -408,6 +426,26 @@ static enum GamescopeUpscaleFilter parse_upscaler_filter(const char *str)
struct sigaction handle_signal_action = {};
extern pid_t child_pid;

static enum g_panel_external_orientation force_external_orientation(const char *str)
{
if (strcmp(str, "normal") == 0) {
g_bExternalForced = true;
return PANEL_EXTERNAL_ORIENTATION_0;
} else if (strcmp(str, "right") == 0) {
g_bExternalForced = true;
return PANEL_EXTERNAL_ORIENTATION_270;
} else if (strcmp(str, "left") == 0) {
g_bExternalForced = true;
return PANEL_EXTERNAL_ORIENTATION_90;
} else if (strcmp(str, "upsidedown") == 0) {
g_bExternalForced = true;
return PANEL_EXTERNAL_ORIENTATION_180;
} else {
fprintf( stderr, "gamescope: invalid value for --force-external-orientation\n" );
exit(1);
}
}

static void handle_signal( int sig )
{
switch ( sig ) {
Expand Down Expand Up @@ -614,6 +652,10 @@ int main(int argc, char **argv)
g_drmModeGeneration = parse_drm_mode_generation( optarg );
} else if (strcmp(opt_name, "force-orientation") == 0) {
g_drmModeOrientation = force_orientation( optarg );
} else if (strcmp(opt_name, "force-external-orientation") == 0) {
g_drmModeExternalOrientation = force_external_orientation( optarg );
} else if (strcmp(opt_name, "force-panel-type") == 0) {
g_drmPanelType = force_panel_type( optarg );
} else if (strcmp(opt_name, "sharpness") == 0 ||
strcmp(opt_name, "fsr-sharpness") == 0) {
g_upscaleFilterSharpness = atoi( optarg );
Expand Down
2 changes: 2 additions & 0 deletions src/main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ extern bool g_bFullscreen;

extern bool g_bGrabbed;

extern bool g_bExternalForced;

enum class GamescopeUpscaleFilter : uint32_t
{
LINEAR = 0,
Expand Down
Loading