Skip to content

Commit

Permalink
Add SRM_DISABLE_CURSOR and SRM_FORCE_LEGACY_CURSOR envs
Browse files Browse the repository at this point in the history
  • Loading branch information
ehopperdietzel committed Sep 7, 2024
1 parent b54ef30 commit 6ed5c42
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 42 deletions.
18 changes: 13 additions & 5 deletions src/lib/SRMConnector.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ UInt8 srmConnectorSetCursor(SRMConnector *connector, UInt8 *pixels)

pthread_mutex_lock(&connector->propsMutex);

if (connector->device->clientCapAtomic)
if (connector->currentCursorPlane)
{
if (pixels)
{
Expand Down Expand Up @@ -171,7 +171,7 @@ UInt8 srmConnectorSetCursorPos(SRMConnector *connector, Int32 x, Int32 y)
connector->cursorX = x;
connector->cursorY = y;

if (connector->device->clientCapAtomic)
if (connector->currentCursorPlane)
{
if (connector->cursorVisible)
connector->atomicChanges |= SRM_ATOMIC_CHANGE_CURSOR_POSITION;
Expand Down Expand Up @@ -304,14 +304,22 @@ UInt8 srmConnectorInitialize(SRMConnector *connector, SRMConnectorInterface *int
connector->currentEncoder = bestEncoder;
connector->currentCrtc = bestCrtc;
connector->currentPrimaryPlane = bestPrimaryPlane;
connector->currentCursorPlane = bestCursorPlane;

bestEncoder->currentConnector = connector;
bestCrtc->currentConnector = connector;
bestPrimaryPlane->currentConnector = connector;

if (bestCursorPlane)
bestCursorPlane->currentConnector = connector;
// When using legacy cursor IOCTLs, the plane is choosen by the driver
if (!connector->device->core->forceLegacyCursor && connector->device->clientCapAtomic)
{
connector->currentCursorPlane = bestCursorPlane;

if (bestCursorPlane)
bestCursorPlane->currentConnector = connector;
}
else
connector->currentCursorPlane = NULL;


connector->interfaceData = userData;
connector->interface = interface;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/SRMConnector.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ SRMPlane *srmConnectorGetCurrentPrimaryPlane(SRMConnector *connector);
* This function returns the currently used @ref SRMPlane associated with the cursor display plane for the given @ref SRMConnector.
*
* @param connector Pointer to the @ref SRMConnector for which to retrieve the current cursor plane.
* @return The currently used @ref SRMPlane for the cursor display.
* @return The currently used @ref SRMPlane for the cursor display or NULL if not assigned.
*/
SRMPlane *srmConnectorGetCurrentCursorPlane(SRMConnector *connector);

Expand Down
25 changes: 23 additions & 2 deletions src/lib/SRMCore.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,34 @@ SRMCore *srmCoreCreate(SRMInterface *interface, void *userData)
core->interfaceUserData = userData;
core->isSuspended = 0;

const char *env = getenv("SRM_DISABLE_CUSTOM_SCANOUT");
// Default env values
setenv("SRM_FORCE_LEGACY_API", "0", 0);
setenv("SRM_FORCE_LEGACY_CURSOR", "1", 0);
setenv("SRM_FORCE_GL_ALLOCATION", "0", 0);
setenv("SRM_RENDER_MODE_ITSELF_FB_COUNT", "2", 0);
setenv("SRM_RENDER_MODE_PRIME_FB_COUNT", "2", 0);
setenv("SRM_RENDER_MODE_DUMB_FB_COUNT", "2", 0);
setenv("SRM_RENDER_MODE_CPU_FB_COUNT", "2", 0);
setenv("SRM_ENABLE_WRITEBACK_CONNECTORS", "0", 0);
setenv("SRM_DISABLE_CUSTOM_SCANOUT", "0", 0);
setenv("SRM_DISABLE_CURSOR", "0", 0);
setenv("SRM_NVIDIA_CURSOR", "1", 0);

const char *env = getenv("SRM_DISABLE_CUSTOM_SCANOUT");
core->customBufferScanoutIsDisabled = env && atoi(env) == 1;

SRMDebug("[core] Custom scanout enabled: %s.",
core->customBufferScanoutIsDisabled ? "NO" : "YES");

env = getenv("SRM_DISABLE_CURSOR");
core->disableCursorPlanes = env && atoi(env) == 1;
SRMDebug("[core] Cursor enabled: %s.",
core->disableCursorPlanes ? "NO" : "YES");

env = getenv("SRM_FORCE_LEGACY_CURSOR");
core->forceLegacyCursor = env && atoi(env) == 1;
SRMDebug("[core] Force legacy cursor: %s.",
core->forceLegacyCursor ? "YES" : "NO");

// REF -
if (!srmCoreUpdateEGLExtensions(core))
goto fail;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/private/SRMConnectorPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ struct SRMConnectorStruct

Int32 cursorIndex;
Int32 cursorX, cursorY;
UInt8 cursorVisible;
UInt32 atomicChanges;
UInt8 cursorVisible;

// Interface for OpenGL events
SRMConnectorInterface *interface;
Expand Down
3 changes: 3 additions & 0 deletions src/lib/private/SRMCorePrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ struct SRMCoreStruct
pthread_cond_t deallocatorCond;
pthread_mutex_t deallocatorMutex;

// Env options
UInt8 customBufferScanoutIsDisabled;
UInt8 forceLegacyCursor;
UInt8 disableCursorPlanes;
};

UInt8 srmCoreInitDeallocator(SRMCore *core);
Expand Down
92 changes: 59 additions & 33 deletions src/lib/private/modes/SRMRenderModeCommon.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <private/modes/SRMRenderModeCommon.h>
#include <private/SRMCorePrivate.h>
#include <private/SRMCrtcPrivate.h>
#include <private/SRMPlanePrivate.h>
#include <private/modes/SRMRenderModeCommon.h>
#include <private/SRMDevicePrivate.h>
#include <private/SRMConnectorPrivate.h>
#include <private/SRMConnectorModePrivate.h>
Expand All @@ -9,6 +10,7 @@
#include <SRMCore.h>
#include <SRMLog.h>
#include <stdlib.h>
#include <string.h>
#include <xf86drmMode.h>
#include <poll.h>
#include <unistd.h>
Expand All @@ -31,7 +33,7 @@ Int8 srmRenderModeCommonMatchConfigToVisual(EGLDisplay egl_display, EGLint visua
return -1;
}

Int8 srmRenderModeCommonChooseEGLConfiguration(EGLDisplay egl_display, const EGLint *attribs, EGLint visual_id, EGLConfig *config_out)
Int8 srmRenderModeCommonChooseEGLConfiguration(EGLDisplay egl_display, const EGLint *attribs, EGLint visual_id, EGLConfig *config_out)
{
EGLint count = 0;
EGLint matched = 0;
Expand All @@ -56,22 +58,17 @@ Int8 srmRenderModeCommonChooseEGLConfiguration(EGLDisplay egl_display, const EG
}

if (!visual_id)
{
config_index = 0;
}

if (config_index == -1)
{
config_index = srmRenderModeCommonMatchConfigToVisual(egl_display, visual_id, configs, matched);
}

if (config_index != -1)
{
*config_out = configs[config_index];
}

out:
free(configs);

if (config_index == -1)
return 0;

Expand Down Expand Up @@ -148,10 +145,16 @@ UInt8 srmRenderModeCommonCreateCursor(SRMConnector *connector)
return 0;
}

if (connector->device->core->disableCursorPlanes)
return 0;

Int32 ret;

connector->cursorIndex = 0;

UInt8 blankBuffer[64*64*4];
memset(blankBuffer, 0, sizeof(blankBuffer));

for (int i = 0; i < 2; i++)
{
connector->cursor[i].bo = gbm_bo_create(connector->device->gbm,
Expand All @@ -163,7 +166,7 @@ UInt8 srmRenderModeCommonCreateCursor(SRMConnector *connector)
if (!connector->cursor[i].bo)
goto fail;

if (!connector->device->clientCapAtomic)
if (!connector->currentCursorPlane)
continue;

ret = drmModeAddFB(connector->device->fd,
Expand All @@ -179,6 +182,16 @@ UInt8 srmRenderModeCommonCreateCursor(SRMConnector *connector)
goto fail;
}

if (!connector->currentCursorPlane)
{
ret = drmModeSetCursor(connector->device->fd,
connector->currentCrtc->id,
gbm_bo_get_handle(connector->cursor[0].bo).u32,
64, 64);
if (ret)
goto fail;
}

return 1;

fail:
Expand Down Expand Up @@ -397,7 +410,7 @@ void srmRenderModeCommonDestroyCursor(SRMConnector *connector)
{
if (connector->cursorVisible)
{
if (connector->device->clientCapAtomic)
if (connector->currentCursorPlane)
{
drmModeAtomicReqPtr req;
req = drmModeAtomicAlloc();
Expand Down Expand Up @@ -577,7 +590,8 @@ Int32 srmRenderModeCommonUpdateMode(SRMConnector *connector, UInt32 fb)

if (ret)
{
connector->cursorIndex = prevCursorIndex;
if (connector->currentCursorPlane)
connector->cursorIndex = prevCursorIndex;
SRMError("Failed set mode with same size on device %s connector %d. Error: %d. (atomic)",
connector->device->name,
connector->id, ret);
Expand Down Expand Up @@ -851,7 +865,8 @@ void srmRenderModeCommonResumeRendering(SRMConnector *connector, UInt32 fb)

if (ret)
{
connector->cursorIndex = prevCursorIndex;
if (connector->currentCursorPlane)
connector->cursorIndex = prevCursorIndex;
SRMError("Failed to resume crtc mode on device %s connector %d.",
connector->device->name,
connector->id);
Expand Down Expand Up @@ -987,7 +1002,8 @@ Int32 srmRenderModeCommonInitCrtc(SRMConnector *connector, UInt32 fb)

if (ret)
{
connector->cursorIndex = prevCursorIndex;
if (connector->currentCursorPlane)
connector->cursorIndex = prevCursorIndex;
SRMError("Failed to set crtc mode on device %s connector %d (atomic).",
connector->device->name,
connector->id);
Expand Down Expand Up @@ -1068,7 +1084,7 @@ void srmRenderModeCommonPageFlip(SRMConnector *connector, UInt32 fb)
req,
DRM_MODE_PAGE_FLIP_EVENT | DRM_MODE_ATOMIC_NONBLOCK,
connector, 0);
if (ret)
if (ret && connector->currentCursorPlane)
connector->cursorIndex = prevCursorIndex;
else
connector->atomicChanges = 0;
Expand Down Expand Up @@ -1109,7 +1125,7 @@ void srmRenderModeCommonPageFlip(SRMConnector *connector, UInt32 fb)
connector, 0);
drmModeAtomicFree(req);

if (ret)
if (ret && connector->currentCursorPlane)
connector->cursorIndex = prevCursorIndex;
else
connector->atomicChanges = 0;
Expand Down Expand Up @@ -1318,26 +1334,11 @@ void srmRenderModeCommonSyncState(SRMConnector *connector)
if (!connector->currentCrtc)
return;

if (connector->device->clientCapAtomic)
if (connector->cursor[0].bo)
{
if (connector->propIDs.content_type)
connector->atomicChanges |= SRM_ATOMIC_CHANGE_CONTENT_TYPE;

if (connector->cursor[0].bo)
if (connector->currentCursorPlane)
connector->atomicChanges |= SRM_ATOMIC_CHANGE_CURSOR_POSITION | SRM_ATOMIC_CHANGE_CURSOR_VISIBILITY;

if (connector->gamma)
connector->atomicChanges |= SRM_ATOMIC_CHANGE_GAMMA_LUT;
}
else
{
if (connector->propIDs.content_type)
drmModeConnectorSetProperty(connector->device->fd,
connector->id,
connector->propIDs.content_type,
connector->contentType);

if (connector->cursor[0].bo)
else
{
if (connector->cursorVisible)
drmModeSetCursor(connector->device->fd,
Expand All @@ -1357,6 +1358,31 @@ void srmRenderModeCommonSyncState(SRMConnector *connector)
connector->cursorX,
connector->cursorY);
}
}
else
{
drmModeSetCursor(connector->device->fd,
connector->currentCrtc->id,
0,
0,
0);
}

if (connector->device->clientCapAtomic)
{
if (connector->propIDs.content_type)
connector->atomicChanges |= SRM_ATOMIC_CHANGE_CONTENT_TYPE;

if (connector->gamma)
connector->atomicChanges |= SRM_ATOMIC_CHANGE_GAMMA_LUT;
}
else
{
if (connector->propIDs.content_type)
drmModeConnectorSetProperty(connector->device->fd,
connector->id,
connector->propIDs.content_type,
connector->contentType);

/* This is always != NULL if gammaSize > 0 */
if (connector->gamma)
Expand Down

0 comments on commit 6ed5c42

Please sign in to comment.