All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paulo Zanoni <przanoni@gmail.com>
To: dri-devel@lists.freedesktop.org
Cc: Paulo Zanoni <paulo.r.zanoni@intel.com>
Subject: [PATCH 2/3 xf86-video-intel] Update the rotation property whenever we change the rotation.
Date: Tue, 20 Mar 2012 11:53:22 -0300	[thread overview]
Message-ID: <1332255203-4530-2-git-send-email-przanoni@gmail.com> (raw)
In-Reply-To: <1332255203-4530-1-git-send-email-przanoni@gmail.com>

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

Don't worry if that fails: only the KVMr feature will be affected.

We still need to change the sna/ code.

Signed-off-by: Paulo Zanoni <paulo.r.zanoni@intel.com>
---
 src/intel.h         |    3 ++
 src/intel_display.c |   79 +++++++++++++++++++++++++++++++++++++++++++++++++++
 src/intel_driver.c  |    2 +
 3 files changed, 84 insertions(+), 0 deletions(-)

diff --git a/src/intel.h b/src/intel.h
index f806aea..29df531 100644
--- a/src/intel.h
+++ b/src/intel.h
@@ -644,4 +644,7 @@ static inline Bool intel_pixmap_is_offscreen(PixmapPtr pixmap)
 	return priv && priv->offscreen;
 }
 
+/* intel_display.c */
+void intel_crtc_leave_vt(ScrnInfoPtr scrn);
+
 #endif /* _I830_H_ */
diff --git a/src/intel_display.c b/src/intel_display.c
index abdc372..dad0fe1 100644
--- a/src/intel_display.c
+++ b/src/intel_display.c
@@ -82,6 +82,7 @@ struct intel_crtc {
 	uint32_t rotate_fb_id;
 	xf86CrtcPtr crtc;
 	struct list link;
+	drmModePropertyPtr rotation_prop;
 };
 
 struct intel_property {
@@ -418,6 +419,44 @@ done:
 	return ret;
 }
 
+static void
+intel_crtc_inform_rotation(xf86CrtcPtr crtc, Rotation rotation)
+{
+	struct intel_crtc *intel_crtc = crtc->driver_private;
+	int ret, int_rotation;
+
+	/* Try to inform the Kernel about our current rotation but don't
+	 * worry if that fails */
+	if (intel_crtc->rotation_prop->prop_id) {
+
+		switch (rotation) {
+		case RR_Rotate_0:
+			int_rotation = 0;
+			break;
+		case RR_Rotate_90:
+			int_rotation = 90;
+			break;
+		case RR_Rotate_180:
+			int_rotation = 180;
+			break;
+		case RR_Rotate_270:
+			int_rotation = 270;
+			break;
+		default:
+			int_rotation = 0;
+		}
+
+		ret = drmModeCrtcSetProperty(intel_crtc->mode->fd,
+					     crtc_id(intel_crtc),
+					     intel_crtc->rotation_prop->prop_id,
+					     int_rotation);
+		if (ret)
+			xf86DrvMsg(crtc->scrn->scrnIndex, X_WARNING,
+				   "Failed to set CRTC rotation: %s\n",
+				   strerror(-ret));
+	}
+}
+
 static Bool
 intel_crtc_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
 			  Rotation rotation, int x, int y)
@@ -464,6 +503,8 @@ intel_crtc_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
 		crtc->y = saved_y;
 		crtc->rotation = saved_rotation;
 		crtc->mode = saved_mode;
+	} else {
+		intel_crtc_inform_rotation(crtc, rotation);
 	}
 	return ret;
 }
@@ -640,12 +681,48 @@ intel_crtc_destroy(xf86CrtcPtr crtc)
 		intel_crtc->cursor = NULL;
 	}
 
+	if (intel_crtc->rotation_prop)
+		drmModeFreeProperty(intel_crtc->rotation_prop);
+
 	list_del(&intel_crtc->link);
 	free(intel_crtc);
 
 	crtc->driver_private = NULL;
 }
 
+static void
+intel_crtc_load_properties(struct intel_mode *mode,
+			   struct intel_crtc *crtc)
+{
+	unsigned int i;
+	drmModeCrtcPropertiesPtr props;
+	drmModePropertyPtr prop;
+
+	crtc->rotation_prop = NULL;
+
+	props = drmModeCrtcGetProperties(mode->fd, crtc_id(crtc));
+	if (props) {
+		for (i = 0; i < props->count_props; i++) {
+			prop = drmModeGetProperty(mode->fd, props->props[i]);
+			if (!strcmp(prop->name, "rotation"))
+				crtc->rotation_prop = prop;
+			else
+				drmModeFreeProperty(prop);
+		}
+		drmModeFreeCrtcProperties(props);
+	}
+}
+
+void
+intel_crtc_leave_vt(ScrnInfoPtr scrn)
+{
+	int i;
+	xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+
+	for (i = 0; i < xf86_config->num_crtc; i++)
+		intel_crtc_inform_rotation(xf86_config->crtc[i], RR_Rotate_0);
+}
+
 static const xf86CrtcFuncsRec intel_crtc_funcs = {
 	.dpms = intel_crtc_dpms,
 	.set_mode_major = intel_crtc_set_mode_major,
@@ -692,6 +769,8 @@ intel_crtc_init(ScrnInfoPtr scrn, struct intel_mode *mode, int num)
 
 	intel_crtc->crtc = crtc;
 	list_add(&intel_crtc->link, &mode->crtcs);
+
+	intel_crtc_load_properties(mode, intel_crtc);
 }
 
 static Bool
diff --git a/src/intel_driver.c b/src/intel_driver.c
index 4265de8..98466a3 100644
--- a/src/intel_driver.c
+++ b/src/intel_driver.c
@@ -1115,6 +1115,8 @@ static void I830LeaveVT(int scrnIndex, int flags)
 	intel_screen_private *intel = intel_get_screen_private(scrn);
 	int ret;
 
+	intel_crtc_leave_vt(scrn);
+
 	xf86RotateFreeShadow(scrn);
 
 	xf86_hide_cursors(scrn);
-- 
1.7.9.1

  reply	other threads:[~2012-03-20 14:54 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-20 14:53 [PATCH 1/3 xf86-video-intel] Avoid duplicated code with intel_output_create_ranged_atom Paulo Zanoni
2012-03-20 14:53 ` Paulo Zanoni [this message]
2012-03-26 13:22   ` [PATCH 2/3 xf86-video-intel] Update the rotation property whenever we change the rotation Chris Wilson
2012-03-20 14:53 ` [PATCH 3/3 xf86-video-intel] Add underscan properties Paulo Zanoni
2012-03-26 13:22 ` [PATCH 1/3 xf86-video-intel] Avoid duplicated code with intel_output_create_ranged_atom Chris Wilson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1332255203-4530-2-git-send-email-przanoni@gmail.com \
    --to=przanoni@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=paulo.r.zanoni@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.