[PATCH 3/3 xf86-video-intel] Add underscan properties

Paulo Zanoni przanoni at gmail.com
Tue Mar 20 07:53:23 PDT 2012


From: Paulo Zanoni <paulo.r.zanoni at intel.com>

In the Kernel side, these are crtc properties (since in the hardware,
underscan use the panel fitters, which are attached to the pipes).
Ideally we should make these as crtc properties too, but since xrandr
doesn't have support for them, we expose the atoms as output
properties. This is not the best solution, but making the kernel
underscan properties be output properties instead of crtc properties
would be even more wrong.

We still need to change the sna/ code.

Signed-off-by: Paulo Zanoni <paulo.r.zanoni at intel.com>
---
 src/intel_display.c |   98 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 97 insertions(+), 1 deletions(-)

diff --git a/src/intel_display.c b/src/intel_display.c
index dad0fe1..f0cddce 100644
--- a/src/intel_display.c
+++ b/src/intel_display.c
@@ -83,6 +83,8 @@ struct intel_crtc {
 	xf86CrtcPtr crtc;
 	struct list link;
 	drmModePropertyPtr rotation_prop;
+	drmModePropertyPtr underscan_x_prop;
+	drmModePropertyPtr underscan_y_prop;
 };
 
 struct intel_property {
@@ -111,6 +113,8 @@ struct intel_output {
 	int backlight_max;
 	xf86OutputPtr output;
 	struct list link;
+	Atom underscan_x_atom;
+	Atom underscan_y_atom;
 };
 
 static void
@@ -683,6 +687,10 @@ intel_crtc_destroy(xf86CrtcPtr crtc)
 
 	if (intel_crtc->rotation_prop)
 		drmModeFreeProperty(intel_crtc->rotation_prop);
+	if (intel_crtc->underscan_x_prop)
+		drmModeFreeProperty(intel_crtc->underscan_x_prop);
+	if (intel_crtc->underscan_y_prop)
+		drmModeFreeProperty(intel_crtc->underscan_y_prop);
 
 	list_del(&intel_crtc->link);
 	free(intel_crtc);
@@ -699,6 +707,8 @@ intel_crtc_load_properties(struct intel_mode *mode,
 	drmModePropertyPtr prop;
 
 	crtc->rotation_prop = NULL;
+	crtc->underscan_x_prop = NULL;
+	crtc->underscan_y_prop = NULL;
 
 	props = drmModeCrtcGetProperties(mode->fd, crtc_id(crtc));
 	if (props) {
@@ -706,6 +716,10 @@ intel_crtc_load_properties(struct intel_mode *mode,
 			prop = drmModeGetProperty(mode->fd, props->props[i]);
 			if (!strcmp(prop->name, "rotation"))
 				crtc->rotation_prop = prop;
+			else if (!strcmp(prop->name, "underscan x"))
+				crtc->underscan_x_prop = prop;
+			else if (!strcmp(prop->name, "underscan y"))
+				crtc->underscan_y_prop = prop;
 			else
 				drmModeFreeProperty(prop);
 		}
@@ -1200,6 +1214,19 @@ intel_output_create_resources(xf86OutputPtr output)
 					intel_output->backlight_active_level,
 					FALSE);
 	}
+	intel_output_create_ranged_atom(output, &intel_output->underscan_x_atom,
+					"underscan x", 0, 100, 0, FALSE);
+	intel_output_create_ranged_atom(output, &intel_output->underscan_y_atom,
+					"underscan y", 0, 100, 0, FALSE);
+}
+
+static struct intel_crtc *
+intel_output_get_crtc(xf86OutputPtr output)
+{
+	if (output->crtc)
+		return output->crtc->driver_private;
+	else
+		return 0;
 }
 
 static Bool
@@ -1229,6 +1256,36 @@ intel_output_set_property(xf86OutputPtr output, Atom property,
 		return TRUE;
 	}
 
+	if (property == intel_output->underscan_x_atom ||
+	    property == intel_output->underscan_y_atom) {
+		uint32_t val;
+		struct intel_crtc *intel_crtc;
+		drmModePropertyPtr drm_prop;
+
+		val = *(uint32_t *)value->data;
+		if (value->type != XA_INTEGER || value->format != 32 ||
+		    value->size != 1 || val > 100)
+			return FALSE;
+
+		intel_crtc = intel_output_get_crtc(output);
+		if (intel_crtc) {
+			if (property == intel_output->underscan_x_atom)
+				drm_prop = intel_crtc->underscan_x_prop;
+			else
+				drm_prop = intel_crtc->underscan_y_prop;
+
+			if (!drm_prop)
+				return FALSE;
+
+			drmModeCrtcSetProperty(mode->fd,
+					       intel_crtc->mode_crtc->crtc_id,
+					       drm_prop->prop_id,
+					       (uint64_t) val);
+
+		}
+		return TRUE;
+	}
+
 	for (i = 0; i < intel_output->num_props; i++) {
 		struct intel_property *p = &intel_output->props[i];
 
@@ -1279,10 +1336,11 @@ static Bool
 intel_output_get_property(xf86OutputPtr output, Atom property)
 {
 	struct intel_output *intel_output = output->driver_private;
+	struct intel_mode *mode = intel_output->mode;
 	int err;
+	INT32 val;
 
 	if (property == backlight_atom || property == backlight_deprecated_atom) {
-		INT32 val;
 
 		if (! intel_output->backlight_iface)
 			return FALSE;
@@ -1303,6 +1361,44 @@ intel_output_get_property(xf86OutputPtr output, Atom property)
 		return TRUE;
 	}
 
+	if (property == intel_output->underscan_x_atom ||
+	    property == intel_output->underscan_y_atom) {
+		struct intel_crtc *intel_crtc = NULL;
+		drmModeCrtcPropertiesPtr props;
+		unsigned int i;
+
+		intel_crtc = intel_output_get_crtc(output);
+
+		if (!intel_crtc) {
+			val = 0;
+		} else {
+			props = drmModeCrtcGetProperties(mode->fd,
+						intel_crtc->mode_crtc->crtc_id);
+			if (!props)
+				return FALSE;
+
+			for (i = 0; i < props->count_props; i++) {
+				if (props->props[i] == intel_crtc->underscan_x_prop->prop_id &&
+				    property == intel_output->underscan_x_atom)
+					val = props->prop_values[i];
+				else if (props->props[i] == intel_crtc->underscan_y_prop->prop_id &&
+					 property == intel_output->underscan_y_atom)
+					val = props->prop_values[i];
+			}
+			drmModeFreeCrtcProperties(props);
+		}
+
+		err = RRChangeOutputProperty(output->randr_output, property,
+					     XA_INTEGER, 32, PropModeReplace,
+					     1, &val, FALSE, TRUE);
+		if (err != 0) {
+			xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
+				   "RRChangeOutputProperty error, %d\n", err);
+			return FALSE;
+		}
+		return TRUE;
+	}
+
 	return FALSE;
 }
 
-- 
1.7.9.1



More information about the dri-devel mailing list