@@ -588,86 +588,49 @@ static void KMSDRM_DeinitDisplays(SDL_VideoDevice *_this)
588588 }
589589}
590590
591- static uint32_t KMSDRM_CrtcGetPropId (uint32_t drm_fd ,
592- drmModeObjectPropertiesPtr props ,
593- char const * name )
591+ static bool KMSDRM_ConnectorCheckVrrCapable (uint32_t drm_fd , uint32_t output_id )
594592{
595- uint32_t i , prop_id = 0 ;
596-
597- for (i = 0 ; !prop_id && i < props -> count_props ; ++ i ) {
598- drmModePropertyPtr drm_prop =
599- KMSDRM_drmModeGetProperty (drm_fd , props -> props [i ]);
600-
601- if (!drm_prop ) {
602- continue ;
603- }
593+ bool found = false;
594+ uint64_t prop_value = 0 ;
604595
605- if (SDL_strcmp (drm_prop -> name , name ) == 0 ) {
606- prop_id = drm_prop -> prop_id ;
596+ drmModeObjectPropertiesPtr props = KMSDRM_drmModeObjectGetProperties (drm_fd , output_id , DRM_MODE_OBJECT_CONNECTOR );
597+ if (props ) {
598+ for (uint32_t i = 0 ; !found && i < props -> count_props ; ++ i ) {
599+ drmModePropertyPtr prop = KMSDRM_drmModeGetProperty (drm_fd , props -> props [i ]);
600+ if (prop ) {
601+ if (SDL_strcasecmp (prop -> name , "VRR_CAPABLE" ) == 0 ) {
602+ prop_value = props -> prop_values [i ];
603+ found = true;
604+ }
605+ KMSDRM_drmModeFreeProperty (prop );
606+ }
607607 }
608-
609- KMSDRM_drmModeFreeProperty (drm_prop );
608+ KMSDRM_drmModeFreeObjectProperties (props );
610609 }
611-
612- return prop_id ;
613- }
614-
615- static bool KMSDRM_VrrPropId (uint32_t drm_fd , uint32_t crtc_id , uint32_t * vrr_prop_id )
616- {
617- drmModeObjectPropertiesPtr drm_props ;
618-
619- drm_props = KMSDRM_drmModeObjectGetProperties (drm_fd ,
620- crtc_id ,
621- DRM_MODE_OBJECT_CRTC );
622-
623- if (!drm_props ) {
624- return false;
610+ if (found ) {
611+ return prop_value ? true : false;
625612 }
626-
627- * vrr_prop_id = KMSDRM_CrtcGetPropId (drm_fd ,
628- drm_props ,
629- "VRR_ENABLED" );
630-
631- KMSDRM_drmModeFreeObjectProperties (drm_props );
632-
633- return true;
613+ return false;
634614}
635615
636- static bool KMSDRM_ConnectorCheckVrrCapable (uint32_t drm_fd ,
637- uint32_t output_id ,
638- char const * name )
616+ static bool KMSDRM_VrrPropId (uint32_t drm_fd , uint32_t crtc_id , uint32_t * vrr_prop_id )
639617{
640- uint32_t i ;
641618 bool found = false;
642- uint64_t prop_value = 0 ;
643-
644- drmModeObjectPropertiesPtr props = KMSDRM_drmModeObjectGetProperties (drm_fd ,
645- output_id ,
646- DRM_MODE_OBJECT_CONNECTOR );
647-
648- if (!props ) {
649- return false;
650- }
651-
652- for (i = 0 ; !found && i < props -> count_props ; ++ i ) {
653- drmModePropertyPtr drm_prop = KMSDRM_drmModeGetProperty (drm_fd , props -> props [i ]);
654-
655- if (!drm_prop ) {
656- continue ;
657- }
658-
659- if (SDL_strcasecmp (drm_prop -> name , name ) == 0 ) {
660- prop_value = props -> prop_values [i ];
661- found = true;
619+ drmModeObjectPropertiesPtr props = KMSDRM_drmModeObjectGetProperties (drm_fd , crtc_id , DRM_MODE_OBJECT_CRTC );
620+ if (props ) {
621+ for (uint32_t i = 0 ; !found && i < props -> count_props ; ++ i ) {
622+ drmModePropertyPtr prop = KMSDRM_drmModeGetProperty (drm_fd , props -> props [i ]);
623+ if (prop ) {
624+ if (SDL_strcmp (prop -> name , "VRR_ENABLED" ) == 0 ) {
625+ * vrr_prop_id = prop -> prop_id ;
626+ found = true;
627+ }
628+ KMSDRM_drmModeFreeProperty (prop );
629+ }
662630 }
663-
664- KMSDRM_drmModeFreeProperty (drm_prop );
631+ KMSDRM_drmModeFreeObjectProperties (props );
665632 }
666- if (found ) {
667- return prop_value ? true : false;
668- }
669-
670- return false;
633+ return found ;
671634}
672635
673636static void KMSDRM_CrtcSetVrr (uint32_t drm_fd , uint32_t crtc_id , bool enabled )
@@ -677,119 +640,67 @@ static void KMSDRM_CrtcSetVrr(uint32_t drm_fd, uint32_t crtc_id, bool enabled)
677640 return ;
678641 }
679642
680- KMSDRM_drmModeObjectSetProperty (drm_fd ,
681- crtc_id ,
682- DRM_MODE_OBJECT_CRTC ,
683- vrr_prop_id ,
684- enabled );
643+ KMSDRM_drmModeObjectSetProperty (drm_fd , crtc_id , DRM_MODE_OBJECT_CRTC , vrr_prop_id , enabled );
685644}
686645
687646static bool KMSDRM_CrtcGetVrr (uint32_t drm_fd , uint32_t crtc_id )
688647{
689- uint32_t object_prop_id , vrr_prop_id ;
690- drmModeObjectPropertiesPtr props ;
691- bool object_prop_value ;
692- int i ;
648+ uint32_t vrr_prop_id = 0 ;
649+ bool found = false;
650+ uint64_t prop_value = 0 ;
693651
694652 if (!KMSDRM_VrrPropId (drm_fd , crtc_id , & vrr_prop_id )) {
695653 return false;
696654 }
697655
698- props = KMSDRM_drmModeObjectGetProperties (drm_fd ,
699- crtc_id ,
700- DRM_MODE_OBJECT_CRTC );
701-
702- if (!props ) {
703- return false;
704- }
705-
706- for (i = 0 ; i < props -> count_props ; ++ i ) {
707- drmModePropertyPtr drm_prop = KMSDRM_drmModeGetProperty (drm_fd , props -> props [i ]);
708-
709- if (!drm_prop ) {
710- continue ;
711- }
712-
713- object_prop_id = drm_prop -> prop_id ;
714- object_prop_value = props -> prop_values [i ] ? true : false;
715-
716- KMSDRM_drmModeFreeProperty (drm_prop );
717-
718- if (object_prop_id == vrr_prop_id ) {
719- return object_prop_value ;
656+ drmModeObjectPropertiesPtr props = KMSDRM_drmModeObjectGetProperties (drm_fd , crtc_id , DRM_MODE_OBJECT_CRTC );
657+ if (props ) {
658+ for (uint32_t i = 0 ; !found && i < props -> count_props ; ++ i ) {
659+ drmModePropertyPtr prop = KMSDRM_drmModeGetProperty (drm_fd , props -> props [i ]);
660+ if (prop ) {
661+ if (prop -> prop_id == vrr_prop_id ) {
662+ prop_value = props -> prop_values [i ];
663+ found = true;
664+ }
665+ KMSDRM_drmModeFreeProperty (prop );
666+ }
720667 }
668+ KMSDRM_drmModeFreeObjectProperties (props );
721669 }
722- return false;
723- }
724-
725- static bool KMSDRM_OrientationPropId (uint32_t drm_fd , uint32_t crtc_id , uint32_t * orientation_prop_id )
726- {
727- drmModeObjectPropertiesPtr drm_props ;
728-
729- drm_props = KMSDRM_drmModeObjectGetProperties (drm_fd ,
730- crtc_id ,
731- DRM_MODE_OBJECT_CONNECTOR );
732-
733- if (!drm_props ) {
734- return false;
670+ if (found ) {
671+ return prop_value ? true : false;
735672 }
736-
737- * orientation_prop_id = KMSDRM_CrtcGetPropId (drm_fd ,
738- drm_props ,
739- "panel orientation" );
740-
741- KMSDRM_drmModeFreeObjectProperties (drm_props );
742-
743- return true;
673+ return false;
744674}
745675
746676static int KMSDRM_CrtcGetOrientation (uint32_t drm_fd , uint32_t crtc_id )
747677{
748- uint32_t orientation_prop_id ;
749- drmModeObjectPropertiesPtr props ;
750- int i ;
751- bool done = false;
678+ bool found = false;
752679 int orientation = 0 ;
753680
754- if (!KMSDRM_OrientationPropId (drm_fd , crtc_id , & orientation_prop_id )) {
755- return orientation ;
756- }
757-
758- props = KMSDRM_drmModeObjectGetProperties (drm_fd ,
759- crtc_id ,
760- DRM_MODE_OBJECT_CONNECTOR );
761-
762- if (!props ) {
763- return orientation ;
764- }
765-
766- for (i = 0 ; i < props -> count_props && !done ; ++ i ) {
767- drmModePropertyPtr drm_prop = KMSDRM_drmModeGetProperty (drm_fd , props -> props [i ]);
768-
769- if (!drm_prop ) {
770- continue ;
771- }
772-
773- if (drm_prop -> prop_id == orientation_prop_id && (drm_prop -> flags & DRM_MODE_PROP_ENUM )) {
774- if (drm_prop -> count_enums ) {
775- // "Normal" is the default of no rotation (0 degrees)
776- if (SDL_strcmp (drm_prop -> enums [0 ].name , "Left Side Up" ) == 0 ) {
777- orientation = 90 ;
778- } else if (SDL_strcmp (drm_prop -> enums [0 ].name , "Upside Down" ) == 0 ) {
779- orientation = 180 ;
780- } else if (SDL_strcmp (drm_prop -> enums [0 ].name , "Right Side Up" ) == 0 ) {
781- orientation = 270 ;
681+ drmModeObjectPropertiesPtr props = KMSDRM_drmModeObjectGetProperties (drm_fd , crtc_id , DRM_MODE_OBJECT_CONNECTOR );
682+ if (props ) {
683+ for (uint32_t i = 0 ; !found && i < props -> count_props ; ++ i ) {
684+ drmModePropertyPtr prop = KMSDRM_drmModeGetProperty (drm_fd , props -> props [i ]);
685+ if (prop ) {
686+ if (SDL_strcasecmp (prop -> name , "panel orientation" ) == 0 && (prop -> flags & DRM_MODE_PROP_ENUM )) {
687+ if (prop -> count_enums ) {
688+ // "Normal" is the default of no rotation (0 degrees)
689+ if (SDL_strcmp (prop -> enums [0 ].name , "Left Side Up" ) == 0 ) {
690+ orientation = 90 ;
691+ } else if (SDL_strcmp (prop -> enums [0 ].name , "Upside Down" ) == 0 ) {
692+ orientation = 180 ;
693+ } else if (SDL_strcmp (prop -> enums [0 ].name , "Right Side Up" ) == 0 ) {
694+ orientation = 270 ;
695+ }
696+ }
697+ found = true;
782698 }
699+ KMSDRM_drmModeFreeProperty (prop );
783700 }
784-
785- done = true;
786701 }
787-
788- KMSDRM_drmModeFreeProperty (drm_prop );
702+ KMSDRM_drmModeFreeObjectProperties (props );
789703 }
790-
791- KMSDRM_drmModeFreeObjectProperties (props );
792-
793704 return orientation ;
794705}
795706
@@ -964,7 +875,7 @@ static void KMSDRM_AddDisplay(SDL_VideoDevice *_this, drmModeConnector *connecto
964875 // save previous vrr state
965876 dispdata -> saved_vrr = KMSDRM_CrtcGetVrr (viddata -> drm_fd , crtc -> crtc_id );
966877 // try to enable vrr
967- if (KMSDRM_ConnectorCheckVrrCapable (viddata -> drm_fd , connector -> connector_id , "VRR_CAPABLE" )) {
878+ if (KMSDRM_ConnectorCheckVrrCapable (viddata -> drm_fd , connector -> connector_id )) {
968879 SDL_LogDebug (SDL_LOG_CATEGORY_VIDEO , "Enabling VRR" );
969880 KMSDRM_CrtcSetVrr (viddata -> drm_fd , crtc -> crtc_id , true);
970881 }
0 commit comments