diff --git a/src/lib/SRMConnector.c b/src/lib/SRMConnector.c index e6eef67..305afda 100644 --- a/src/lib/SRMConnector.c +++ b/src/lib/SRMConnector.c @@ -105,7 +105,7 @@ UInt8 srmConnectorSetCursor(SRMConnector *connector, UInt8 *pixels) pthread_mutex_lock(&connector->propsMutex); - if (connector->device->clientCapAtomic) + if (connector->currentCursorPlane) { if (pixels) { @@ -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; @@ -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; diff --git a/src/lib/SRMConnector.h b/src/lib/SRMConnector.h index b3ab56a..352606f 100644 --- a/src/lib/SRMConnector.h +++ b/src/lib/SRMConnector.h @@ -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); diff --git a/src/lib/SRMCore.c b/src/lib/SRMCore.c index 5c30455..c7d815e 100644 --- a/src/lib/SRMCore.c +++ b/src/lib/SRMCore.c @@ -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; diff --git a/src/lib/private/SRMConnectorPrivate.h b/src/lib/private/SRMConnectorPrivate.h index 18f3ef2..dd24429 100644 --- a/src/lib/private/SRMConnectorPrivate.h +++ b/src/lib/private/SRMConnectorPrivate.h @@ -81,8 +81,8 @@ struct SRMConnectorStruct Int32 cursorIndex; Int32 cursorX, cursorY; - UInt8 cursorVisible; UInt32 atomicChanges; + UInt8 cursorVisible; // Interface for OpenGL events SRMConnectorInterface *interface; diff --git a/src/lib/private/SRMCorePrivate.h b/src/lib/private/SRMCorePrivate.h index b5deed7..fe2d54b 100644 --- a/src/lib/private/SRMCorePrivate.h +++ b/src/lib/private/SRMCorePrivate.h @@ -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); diff --git a/src/lib/private/modes/SRMRenderModeCommon.c b/src/lib/private/modes/SRMRenderModeCommon.c index b53019e..94f41e0 100644 --- a/src/lib/private/modes/SRMRenderModeCommon.c +++ b/src/lib/private/modes/SRMRenderModeCommon.c @@ -1,6 +1,7 @@ +#include +#include #include #include -#include #include #include #include @@ -9,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -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; @@ -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; @@ -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, @@ -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, @@ -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: @@ -397,7 +410,7 @@ void srmRenderModeCommonDestroyCursor(SRMConnector *connector) { if (connector->cursorVisible) { - if (connector->device->clientCapAtomic) + if (connector->currentCursorPlane) { drmModeAtomicReqPtr req; req = drmModeAtomicAlloc(); @@ -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); @@ -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); @@ -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); @@ -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; @@ -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; @@ -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, @@ -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)