From 5199c7834dad039917037cd3797079209b1841de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Tue, 26 Mar 2019 10:09:45 +0100 Subject: [PATCH] backends/native: Move underscan setting to MetaOutputKms The 'underscan' property is a drm connector property, not a CRTC property, so we would never find it. We also didn't advertise support for the feature, meaning even if it was on the CRTC, Settings wouldn't know about it. Fix this by moving the property to where it belongs: in MetaOutputKms, and properly advertise support for it if the property is found. https://gitlab.gnome.org/GNOME/mutter/merge_requests/507 --- src/backends/native/meta-crtc-kms.c | 89 --------------------------- src/backends/native/meta-crtc-kms.h | 3 - src/backends/native/meta-output-kms.c | 62 ++++++++++++++++++- 3 files changed, 59 insertions(+), 95 deletions(-) diff --git a/src/backends/native/meta-crtc-kms.c b/src/backends/native/meta-crtc-kms.c index 79a9b1e76..8c2fbfe3c 100644 --- a/src/backends/native/meta-crtc-kms.c +++ b/src/backends/native/meta-crtc-kms.c @@ -41,9 +41,6 @@ typedef struct _MetaCrtcKms { unsigned int index; - uint32_t underscan_prop_id; - uint32_t underscan_hborder_prop_id; - uint32_t underscan_vborder_prop_id; uint32_t primary_plane_id; uint32_t rotation_prop_id; uint32_t rotation_map[ALL_TRANSFORMS]; @@ -137,54 +134,6 @@ meta_crtc_kms_apply_transform (MetaCrtc *crtc) } } -void -meta_crtc_kms_set_underscan (MetaCrtc *crtc, - gboolean is_underscanning) -{ - MetaCrtcKms *crtc_kms = crtc->driver_private; - MetaGpu *gpu = meta_crtc_get_gpu (crtc); - MetaGpuKms *gpu_kms = META_GPU_KMS (gpu); - int kms_fd; - - if (!crtc_kms->underscan_prop_id) - return; - - kms_fd = meta_gpu_kms_get_fd (gpu_kms); - - if (is_underscanning) - { - drmModeObjectSetProperty (kms_fd, crtc->crtc_id, - DRM_MODE_OBJECT_CRTC, - crtc_kms->underscan_prop_id, (uint64_t) 1); - - if (crtc_kms->underscan_hborder_prop_id) - { - uint64_t value; - - value = crtc->current_mode->width * 0.05; - drmModeObjectSetProperty (kms_fd, crtc->crtc_id, - DRM_MODE_OBJECT_CRTC, - crtc_kms->underscan_hborder_prop_id, value); - } - if (crtc_kms->underscan_vborder_prop_id) - { - uint64_t value; - - value = crtc->current_mode->height * 0.05; - drmModeObjectSetProperty (kms_fd, crtc->crtc_id, - DRM_MODE_OBJECT_CRTC, - crtc_kms->underscan_vborder_prop_id, value); - } - - } - else - { - drmModeObjectSetProperty (kms_fd, crtc->crtc_id, - DRM_MODE_OBJECT_CRTC, - crtc_kms->underscan_prop_id, (uint64_t) 0); - } -} - static int find_property_index (MetaGpu *gpu, drmModeObjectPropertiesPtr props, @@ -533,43 +482,6 @@ init_crtc_rotations (MetaCrtc *crtc, } } -static void -find_crtc_properties (MetaCrtc *crtc, - MetaGpuKms *gpu_kms) -{ - MetaCrtcKms *crtc_kms = crtc->driver_private; - int kms_fd; - drmModeObjectPropertiesPtr props; - unsigned int i; - - kms_fd = meta_gpu_kms_get_fd (gpu_kms); - props = drmModeObjectGetProperties (kms_fd, crtc->crtc_id, - DRM_MODE_OBJECT_CRTC); - if (!props) - return; - - for (i = 0; i < props->count_props; i++) - { - drmModePropertyPtr prop = drmModeGetProperty (kms_fd, props->props[i]); - if (!prop) - continue; - - if ((prop->flags & DRM_MODE_PROP_ENUM) && - strcmp (prop->name, "underscan") == 0) - crtc_kms->underscan_prop_id = prop->prop_id; - else if ((prop->flags & DRM_MODE_PROP_RANGE) && - strcmp (prop->name, "underscan hborder") == 0) - crtc_kms->underscan_hborder_prop_id = prop->prop_id; - else if ((prop->flags & DRM_MODE_PROP_RANGE) && - strcmp (prop->name, "underscan vborder") == 0) - crtc_kms->underscan_vborder_prop_id = prop->prop_id; - - drmModeFreeProperty (prop); - } - - drmModeFreeObjectProperties (props); -} - static void meta_crtc_destroy_notify (MetaCrtc *crtc) { @@ -628,7 +540,6 @@ meta_create_kms_crtc (MetaGpuKms *gpu_kms, crtc->driver_private = crtc_kms; crtc->driver_notify = (GDestroyNotify) meta_crtc_destroy_notify; - find_crtc_properties (crtc, gpu_kms); init_crtc_rotations (crtc, gpu); return crtc; diff --git a/src/backends/native/meta-crtc-kms.h b/src/backends/native/meta-crtc-kms.h index 622ea5502..456f4400a 100644 --- a/src/backends/native/meta-crtc-kms.h +++ b/src/backends/native/meta-crtc-kms.h @@ -44,9 +44,6 @@ gboolean meta_crtc_kms_is_transform_handled (MetaCrtc *crtc, void meta_crtc_kms_apply_transform (MetaCrtc *crtc); -void meta_crtc_kms_set_underscan (MetaCrtc *crtc, - gboolean is_underscanning); - GArray * meta_crtc_kms_get_modifiers (MetaCrtc *crtc, uint32_t format); diff --git a/src/backends/native/meta-output-kms.c b/src/backends/native/meta-output-kms.c index f3fa17e58..f3cc543c4 100644 --- a/src/backends/native/meta-output-kms.c +++ b/src/backends/native/meta-output-kms.c @@ -56,6 +56,10 @@ typedef struct _MetaOutputKms uint32_t edid_blob_id; uint32_t tile_blob_id; + uint32_t underscan_prop_id; + uint32_t underscan_hborder_prop_id; + uint32_t underscan_vborder_prop_id; + int suggested_x; int suggested_y; uint32_t hotplug_mode_update; @@ -66,13 +70,55 @@ typedef struct _MetaOutputKms void meta_output_kms_set_underscan (MetaOutput *output) { + MetaOutputKms *output_kms = output->driver_private; + MetaGpu *gpu = meta_output_get_gpu (output); + MetaGpuKms *gpu_kms = META_GPU_KMS (gpu); MetaCrtc *crtc; + int kms_fd; + uint32_t connector_id; - crtc = meta_output_get_assigned_crtc (output); - if (!crtc) + if (!output_kms->underscan_prop_id) return; - meta_crtc_kms_set_underscan (crtc, output->is_underscanning); + crtc = meta_output_get_assigned_crtc (output); + kms_fd = meta_gpu_kms_get_fd (gpu_kms); + connector_id = output_kms->connector->connector_id; + + if (output->is_underscanning && crtc && crtc->current_mode) + { + drmModeObjectSetProperty (kms_fd, connector_id, + DRM_MODE_OBJECT_CONNECTOR, + output_kms->underscan_prop_id, + (uint64_t) 1); + + if (output_kms->underscan_hborder_prop_id) + { + uint64_t value; + + value = MIN (128, crtc->current_mode->width * 0.05); + drmModeObjectSetProperty (kms_fd, connector_id, + DRM_MODE_OBJECT_CONNECTOR, + output_kms->underscan_hborder_prop_id, + value); + } + if (output_kms->underscan_vborder_prop_id) + { + uint64_t value; + + value = MIN (128, crtc->current_mode->height * 0.05); + drmModeObjectSetProperty (kms_fd, connector_id, + DRM_MODE_OBJECT_CONNECTOR, + output_kms->underscan_vborder_prop_id, + value); + } + } + else + { + drmModeObjectSetProperty (kms_fd, connector_id, + DRM_MODE_OBJECT_CONNECTOR, + output_kms->underscan_prop_id, + (uint64_t) 0); + } } uint32_t @@ -312,6 +358,15 @@ find_connector_properties (MetaGpuKms *gpu_kms, strcmp (prop->name, "panel orientation") == 0) handle_panel_orientation (output, prop, output_kms->connector->prop_values[i]); + else if ((prop->flags & DRM_MODE_PROP_ENUM) && + strcmp (prop->name, "underscan") == 0) + output_kms->underscan_prop_id = prop->prop_id; + else if ((prop->flags & DRM_MODE_PROP_RANGE) && + strcmp (prop->name, "underscan hborder") == 0) + output_kms->underscan_hborder_prop_id = prop->prop_id; + else if ((prop->flags & DRM_MODE_PROP_RANGE) && + strcmp (prop->name, "underscan vborder") == 0) + output_kms->underscan_vborder_prop_id = prop->prop_id; drmModeFreeProperty (prop); } @@ -639,6 +694,7 @@ meta_create_kms_output (MetaGpuKms *gpu_kms, output->suggested_x = output_kms->suggested_x; output->suggested_y = output_kms->suggested_y; output->hotplug_mode_update = output_kms->hotplug_mode_update; + output->supports_underscanning = output_kms->underscan_prop_id != 0; if (output_kms->edid_blob_id != 0) {