@@ -191,6 +191,12 @@ DrmRenderer::~DrmRenderer()
191191 m_PropSetter.set (*zpos, zpos->initialValue ());
192192 }
193193 }
194+ for (auto &plane : m_UnusedActivePlanes) {
195+ SDL_LogInfo (SDL_LOG_CATEGORY_APPLICATION ,
196+ " Restoring previously active plane: %u" ,
197+ plane.second .objectId ());
198+ m_PropSetter.restoreToInitial (plane.second );
199+ }
194200
195201 m_PropSetter.apply ();
196202 }
@@ -392,6 +398,14 @@ void DrmRenderer::prepareToRender()
392398 }
393399 }
394400
401+ // Disable all other active planes in atomic mode
402+ for (auto &plane : m_UnusedActivePlanes) {
403+ SDL_LogInfo (SDL_LOG_CATEGORY_APPLICATION ,
404+ " Disabling unused plane: %u" ,
405+ plane.second .objectId ());
406+ m_PropSetter.disablePlane (plane.second );
407+ }
408+
395409 m_PropSetter.apply ();
396410
397411 // We've now changed state that must be restored
@@ -598,22 +612,28 @@ bool DrmRenderer::initialize(PDECODER_PARAMETERS params)
598612 }
599613
600614 // Find the active plane (if any) on this CRTC with the highest zpos.
601- // We'll need to use a plane with a equal or greater zpos to be visible.
615+ // We'll need to use a plane with a equal or greater zpos to be visible,
616+ // or we'll disable the active planes if we're in atomic mode.
602617 std::set<uint64_t > activePlanesZpos;
603618 for (uint32_t i = 0 ; i < planeRes->count_planes ; i++) {
604619 drmModePlane* plane = drmModeGetPlane (m_DrmFd, planeRes->planes [i]);
605620 if (plane != nullptr ) {
621+ DrmPropertyMap props { m_DrmFd, planeRes->planes [i], DRM_MODE_OBJECT_PLANE };
622+
606623 if (plane->crtc_id == m_Crtc.objectId ()) {
607624 // Don't consider cursor planes when searching for the highest active zpos
608- DrmPropertyMap props { m_DrmFd, planeRes->planes [i], DRM_MODE_OBJECT_PLANE };
609- if (props.property (" type" )->initialValue () == DRM_PLANE_TYPE_PRIMARY ||
610- props.property (" type" )->initialValue () == DRM_PLANE_TYPE_OVERLAY ) {
625+ uint64_t type = props.property (" type" )->initialValue ();
626+ if (type == DRM_PLANE_TYPE_PRIMARY || type == DRM_PLANE_TYPE_OVERLAY ) {
611627 SDL_LogInfo (SDL_LOG_CATEGORY_APPLICATION ,
612628 " Plane %u is active on CRTC %u" ,
613629 plane->plane_id ,
614630 plane->crtc_id );
615631
616- if (auto zpos = props.property (" zpos" )) {
632+ // We can only restore state of planes on atomic
633+ if (m_PropSetter.isAtomic ()) {
634+ m_UnusedActivePlanes.try_emplace (planeRes->planes [i], m_DrmFd, planeRes->planes [i], DRM_MODE_OBJECT_PLANE );
635+ }
636+ else if (auto zpos = props.property (" zpos" )) {
617637 activePlanesZpos.emplace (zpos->initialValue ());
618638 }
619639 }
@@ -752,6 +772,7 @@ bool DrmRenderer::initialize(PDECODER_PARAMETERS params)
752772 SDL_assert (!m_VideoPlane.isValid ());
753773 m_VideoPlane.load (m_DrmFd, plane->plane_id , DRM_MODE_OBJECT_PLANE );
754774 SDL_LogInfo (SDL_LOG_CATEGORY_APPLICATION , " Selected plane %u for video" , plane->plane_id );
775+ m_UnusedActivePlanes.erase (plane->plane_id );
755776 drmModeFreePlane (plane);
756777 }
757778 }
@@ -831,6 +852,7 @@ bool DrmRenderer::initialize(PDECODER_PARAMETERS params)
831852 m_OverlayPlanes[overlayIndex++].load (m_DrmFd, plane->plane_id , DRM_MODE_OBJECT_PLANE );
832853 SDL_LogInfo (SDL_LOG_CATEGORY_APPLICATION , " Selected plane %u for overlay %d" ,
833854 plane->plane_id , overlayIndex);
855+ m_UnusedActivePlanes.erase (plane->plane_id );
834856 drmModeFreePlane (plane);
835857 }
836858 }
0 commit comments