drm/client: Use common display mode for cloned outputs
Subsystems (2)
Thomas Zimmermann
maintainerPATCH 1/1 drm/client: Use common display mode for cloned outputs
For cloned outputs, don't pick a default resolution of 1024x768 as most hardware can do better. Instead look through the modes of all connectors to find a common mode for all of them.
--- drivers/gpu/drm/drm_client_modeset.c | 54 +++++++++++++++++----------- 1 file changed, 34 insertions(+), 20 deletions(-)
drivers/gpu/drm/drm_client_modeset.c +34 -20
@@ -266,7 +266,7 @@ static bool drm_client_target_cloned(struct drm_device *dev, {int count, i, j;bool can_clone = false; -struct drm_display_mode *dmt_mode, *mode; +struct drm_display_mode *mode, *common_mode =NULL ;/* only contemplate cloning in the single crtc case */ if (dev->mode_config.num_crtc >1 )
@@ -309,35 +309,49 @@ static bool drm_client_target_cloned(struct drm_device *dev,return true; } -/* try and find a 1024x768 mode on each connector */ - can_clone = true; - dmt_mode =drm_mode_find_dmt (dev,1024 ,768 ,60 , false); - -if (!dmt_mode) - goto fail; +/* try and find a mode common among connectors */ + can_clone = false;for (i =0 ; i < connector_count; i++) {if (!enabled[i])continue ; -list_for_each_entry (mode, &connectors[i]->modes, head) { -if (drm_mode_match (mode, dmt_mode, -DRM_MODE_MATCH_TIMINGS | -DRM_MODE_MATCH_CLOCK | -DRM_MODE_MATCH_FLAGS | -DRM_MODE_MATCH_3D_FLAGS )) - modes[i] = mode; +list_for_each_entry (common_mode, &connectors[i]->modes, head) { + can_clone = true; + +for (j =1 ; j < connector_count; j++) { +if (!enabled[i]) +continue ; + + can_clone = false; +list_for_each_entry (mode, &connectors[j]->modes, head) { + can_clone =drm_mode_match (common_mode, mode, +DRM_MODE_MATCH_TIMINGS | +DRM_MODE_MATCH_CLOCK | +DRM_MODE_MATCH_FLAGS | +DRM_MODE_MATCH_3D_FLAGS ); +if (can_clone) +break ;// found common mode on connector + } +if (!can_clone) +break ;// try next common mode + } +if (can_clone) +break ;// found common mode among all connectors } -if (!modes[i]) - can_clone = false; +break ; } -kfree (dmt_mode); -if (can_clone) { -drm_dbg_kms (dev,"can clone using 1024x768\n" ); +for (i =0 ; i < connector_count; i++) { +if (!enabled[i]) +continue ; + modes[i] = common_mode; + + } +drm_dbg_kms (dev,"can clone using" DRM_MODE_FMT "\n" ,DRM_MODE_ARG (common_mode));return true; } -fail: +drm_info (dev,"kms: can't enable cloning when we probably wanted to.\n" );return false; }
Signature · 1 line
2.45.2
Quoted 40 lines · Thomas Zimmermann
For cloned outputs, don't pick a default resolution of 1024x768 as most hardware can do better. Instead look through the modes of all connectors to find a common mode for all of them.
Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/gpu/drm/drm_client_modeset.c | 54 +++++++++++++++++----------- 1 file changed, 34 insertions(+), 20 deletions(-)drivers/gpu/drm/drm_client_modeset.c +3
-8@@ -266,7 +266,7 @@ static bool drm_client_target_cloned(struct drm_device *dev, {int count, i, j;bool can_clone = false; -struct drm_display_mode *dmt_mode, *mode; +struct drm_display_mode *mode, *common_mode =NULL ;/* only contemplate cloning in the single crtc case */ if (dev->mode_config.num_crtc >1 )@@ -309,35 +309,49 @@ static bool drm_client_target_cloned(struct drm_device *dev,return true; } -/* try and find a 1024x768 mode on each connector */ - can_clone = true; - dmt_mode =drm_mode_find_dmt (dev,1024 ,768 ,60 , false); - -if (!dmt_mode) - goto fail; +/* try and find a mode common among connectors */ + can_clone = false;for (i =0 ; i < connector_count; i++) {if (!enabled[i])continue ; -list_for_each_entry (mode, &connectors[i]->modes, head) {
drivers/gpu/drm/drm_client_modeset.c static bool drm_client_target_cloned(struct drm_device *dev, · line 322
Quoted 10 lines
drivers/gpu/drm/drm_client_modeset.c +4
-6-if (drm_mode_match (mode, dmt_mode, -DRM_MODE_MATCH_TIMINGS | -DRM_MODE_MATCH_CLOCK | -DRM_MODE_MATCH_FLAGS | -DRM_MODE_MATCH_3D_FLAGS )) - modes[i] = mode; +list_for_each_entry (common_mode, &connectors[i]->modes, head) { + can_clone = true; + +for (j =1 ; j < connector_count; j++) {
Should this start from i instead of 1?
Anyway, I have a hard time wrapping my head around this whole thing. I think it would greatly benefit from a helper function to search for a mode from an array of connectors.
BR,
Jani.
Quoted 41 lines
drivers/gpu/drm/drm_client_modeset.c +27
-6+if (!enabled[i]) +continue ; + + can_clone = false; +list_for_each_entry (mode, &connectors[j]->modes, head) { + can_clone =drm_mode_match (common_mode, mode, +DRM_MODE_MATCH_TIMINGS | +DRM_MODE_MATCH_CLOCK | +DRM_MODE_MATCH_FLAGS | +DRM_MODE_MATCH_3D_FLAGS ); +if (can_clone) +break ;// found common mode on connector + } +if (!can_clone) +break ;// try next common mode + } +if (can_clone) +break ;// found common mode among all connectors } -if (!modes[i]) - can_clone = false; +break ; } -kfree (dmt_mode); -if (can_clone) { -drm_dbg_kms (dev,"can clone using 1024x768\n" ); +for (i =0 ; i < connector_count; i++) { +if (!enabled[i]) +continue ; + modes[i] = common_mode; + + } +drm_dbg_kms (dev,"can clone using" DRM_MODE_FMT "\n" ,DRM_MODE_ARG (common_mode));return true; } -fail: +drm_info (dev,"kms: can't enable cloning when we probably wanted to.\n" );return false; }
Signature · 1 line
Jani Nikula, Intel
Thomas Zimmermann
maintainerHi
Am 02.08.24 um 10:03 schrieb Jani Nikula:
Quoted 40 lines · Thomas Zimmermann
Quoted 39 lines
For cloned outputs, don't pick a default resolution of 1024x768 as most hardware can do better. Instead look through the modes of all connectors to find a common mode for all of them.
Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/gpu/drm/drm_client_modeset.c | 54 +++++++++++++++++----------- 1 file changed, 34 insertions(+), 20 deletions(-)drivers/gpu/drm/drm_client_modeset.c +3
-7@@ -266,7 +266,7 @@ static bool drm_client_target_cloned(struct drm_device *dev, {int count, i, j;bool can_clone = false; -struct drm_display_mode *dmt_mode, *mode; +struct drm_display_mode *mode, *common_mode =NULL ;/* only contemplate cloning in the single crtc case */ if (dev->mode_config.num_crtc >1 )@@ -309,35 +309,49 @@ static bool drm_client_target_cloned(struct drm_device *dev,return true; } -/* try and find a 1024x768 mode on each connector */ - can_clone = true; - dmt_mode =drm_mode_find_dmt (dev,1024 ,768 ,60 , false); - -if (!dmt_mode) - goto fail; +/* try and find a mode common among connectors */ + can_clone = false;for (i =0 ; i < connector_count; i++) {if (!enabled[i])continue ;
Quoted 12 lines
drivers/gpu/drm/drm_client_modeset.c static bool drm_client_target_cloned(struct drm_device *dev, · line 322
Quoted 11 lines
drivers/gpu/drm/drm_client_modeset.c +4
-7-list_for_each_entry (mode, &connectors[i]->modes, head) { -if (drm_mode_match (mode, dmt_mode, -DRM_MODE_MATCH_TIMINGS | -DRM_MODE_MATCH_CLOCK | -DRM_MODE_MATCH_FLAGS | -DRM_MODE_MATCH_3D_FLAGS )) - modes[i] = mode; +list_for_each_entry (common_mode, &connectors[i]->modes, head) { + can_clone = true; + +for (j =1 ; j < connector_count; j++) {Should this start from i instead of 1?
Right, it would make sense.
Quoted 4 lines
Anyway, I have a hard time wrapping my head around this whole thing. I think it would greatly benefit from a helper function to search for a mode from an array of connectors.
That's what it does. Here, the outer-most loop tries to find the first enabled connector. For each of its modes, the inner loops test if that mode is also present on all other enabled connectors.
All of the client's mode-selection code is fairly obscure. I don't really dare touching it.
Best regards
Thomas
Quoted 46 lines
BR,
Jani.Quoted 41 lines
drivers/gpu/drm/drm_client_modeset.c +27
-6+if (!enabled[i]) +continue ; + + can_clone = false; +list_for_each_entry (mode, &connectors[j]->modes, head) { + can_clone =drm_mode_match (common_mode, mode, +DRM_MODE_MATCH_TIMINGS | +DRM_MODE_MATCH_CLOCK | +DRM_MODE_MATCH_FLAGS | +DRM_MODE_MATCH_3D_FLAGS ); +if (can_clone) +break ;// found common mode on connector + } +if (!can_clone) +break ;// try next common mode + } +if (can_clone) +break ;// found common mode among all connectors } -if (!modes[i]) - can_clone = false; +break ; } -kfree (dmt_mode); -if (can_clone) { -drm_dbg_kms (dev,"can clone using 1024x768\n" ); +for (i =0 ; i < connector_count; i++) { +if (!enabled[i]) +continue ; + modes[i] = common_mode; + + } +drm_dbg_kms (dev,"can clone using" DRM_MODE_FMT "\n" ,DRM_MODE_ARG (common_mode));return true; } -fail: +drm_info (dev,"kms: can't enable cloning when we probably wanted to.\n" );return false; }
Signature · 7 lines
-- Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Frankenstrasse 146, 90461 Nuernberg, Germany GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman HRB 36809 (AG Nuernberg)
Quoted 63 lines · Thomas Zimmermann
Hi
Am 02.08.24 um 10:03 schrieb Jani Nikula:
Quoted 40 lines · Thomas Zimmermann
Quoted 39 lines
For cloned outputs, don't pick a default resolution of 1024x768 as most hardware can do better. Instead look through the modes of all connectors to find a common mode for all of them.
Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/gpu/drm/drm_client_modeset.c | 54 +++++++++++++++++----------- 1 file changed, 34 insertions(+), 20 deletions(-)drivers/gpu/drm/drm_client_modeset.c +3
-7@@ -266,7 +266,7 @@ static bool drm_client_target_cloned(struct drm_device *dev, {int count, i, j;bool can_clone = false; -struct drm_display_mode *dmt_mode, *mode; +struct drm_display_mode *mode, *common_mode =NULL ;/* only contemplate cloning in the single crtc case */ if (dev->mode_config.num_crtc >1 )@@ -309,35 +309,49 @@ static bool drm_client_target_cloned(struct drm_device *dev,return true; } -/* try and find a 1024x768 mode on each connector */ - can_clone = true; - dmt_mode =drm_mode_find_dmt (dev,1024 ,768 ,60 , false); - -if (!dmt_mode) - goto fail; +/* try and find a mode common among connectors */ + can_clone = false;for (i =0 ; i < connector_count; i++) {if (!enabled[i])continue ;Quoted 12 lines
drivers/gpu/drm/drm_client_modeset.c static bool drm_client_target_cloned(struct drm_device *dev, · line 322
Quoted 11 lines
drivers/gpu/drm/drm_client_modeset.c +4
-7-list_for_each_entry (mode, &connectors[i]->modes, head) { -if (drm_mode_match (mode, dmt_mode, -DRM_MODE_MATCH_TIMINGS | -DRM_MODE_MATCH_CLOCK | -DRM_MODE_MATCH_FLAGS | -DRM_MODE_MATCH_3D_FLAGS )) - modes[i] = mode; +list_for_each_entry (common_mode, &connectors[i]->modes, head) { + can_clone = true; + +for (j =1 ; j < connector_count; j++) {Should this start from i instead of 1?
Right, it would make sense.
Quoted 4 lines
Anyway, I have a hard time wrapping my head around this whole thing. I think it would greatly benefit from a helper function to search for a mode from an array of connectors.
Quoted 6 lines
That's what it does. Here, the outer-most loop tries to find the first enabled connector. For each of its modes, the inner loops test if that mode is also present on all other enabled connectors.
All of the client's mode-selection code is fairly obscure. I don't really dare touching it.
I mean just refactoring the above loops to smaller pieces.
BR,
Jani.
Quoted 50 lines
Best regards
ThomasQuoted 46 lines
BR,
Jani.Quoted 41 lines
drivers/gpu/drm/drm_client_modeset.c +27
-6+if (!enabled[i]) +continue ; + + can_clone = false; +list_for_each_entry (mode, &connectors[j]->modes, head) { + can_clone =drm_mode_match (common_mode, mode, +DRM_MODE_MATCH_TIMINGS | +DRM_MODE_MATCH_CLOCK | +DRM_MODE_MATCH_FLAGS | +DRM_MODE_MATCH_3D_FLAGS ); +if (can_clone) +break ;// found common mode on connector + } +if (!can_clone) +break ;// try next common mode + } +if (can_clone) +break ;// found common mode among all connectors } -if (!modes[i]) - can_clone = false; +break ; } -kfree (dmt_mode); -if (can_clone) { -drm_dbg_kms (dev,"can clone using 1024x768\n" ); +for (i =0 ; i < connector_count; i++) { +if (!enabled[i]) +continue ; + modes[i] = common_mode; + + } +drm_dbg_kms (dev,"can clone using" DRM_MODE_FMT "\n" ,DRM_MODE_ARG (common_mode));return true; } -fail: +drm_info (dev,"kms: can't enable cloning when we probably wanted to.\n" );return false; }
Signature · 1 line
Jani Nikula, Intel