AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: <sunpeng.li-5C7GfCeVMHo@public.gmane.org>
To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
Cc: "Leo (Sunpeng) Li" <sunpeng.li-5C7GfCeVMHo@public.gmane.org>,
	michel-otUistvHUpPR7s880joybQ@public.gmane.org,
	harry.wentland-5C7GfCeVMHo@public.gmane.org
Subject: [PATCH xf86-video-amdgpu 03/13] List disabled color properties on RandR outputs without a CRTC
Date: Thu, 3 May 2018 14:31:45 -0400	[thread overview]
Message-ID: <1525372315-28462-4-git-send-email-sunpeng.li@amd.com> (raw)
In-Reply-To: <1525372315-28462-1-git-send-email-sunpeng.li-5C7GfCeVMHo@public.gmane.org>

From: "Leo (Sunpeng) Li" <sunpeng.li@amd.com>

The properties on an RandR output needs to stay consistent throughout
it's lifecycle. However, we cannot list color properties on an output if
there is no CRTC attached.

Therefore, create a fake CRTC, and initialize "disabled" color
properites on outputs without a CRTC.

Signed-off-by: Leo (Sunpeng) Li <sunpeng.li@amd.com>
---
 src/drmmode_display.c | 154 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 154 insertions(+)

diff --git a/src/drmmode_display.c b/src/drmmode_display.c
index 85de01e..c28796c 100644
--- a/src/drmmode_display.c
+++ b/src/drmmode_display.c
@@ -869,6 +869,124 @@ err_allocs:
 }
 
 /**
+ * Configure and change a color property on a CRTC, through RandR. Only the
+ * specified output will be affected, even if the CRTC is attached to multiple
+ * outputs. If the request is pending, then the change will make it's way into
+ * the kernel DRM driver. Otherwise, the request will be a user-land only
+ * update.
+ *
+ * @output: RandR output to set the property on.
+ * @crtc: The driver-private CRTC object containing the color properties.
+ * @cm_prop_index: Color management property to configure and change.
+ * @pending: Whether this request is pending.
+ *
+ * Return 0 on success, X-defined error code otherwise.
+ */
+static int rr_configure_and_change_cm_property(xf86OutputPtr output,
+					       drmmode_crtc_private_ptr crtc,
+					       enum drmmode_cm_prop cm_prop_index,
+					       Bool pending)
+{
+	Bool need_configure = TRUE;
+	unsigned long length = 0;
+	void *data = NULL;
+	int format = 0;
+	uint16_t value;
+	INT32 range[2];
+	Atom atom;
+	int err;
+
+	if (cm_prop_index == CM_INVALID_PROP)
+		return BadName;
+
+	atom = MakeAtom(CM_PROP_NAMES[cm_prop_index],
+			strlen(CM_PROP_NAMES[cm_prop_index]),
+			TRUE);
+	if (!atom)
+		return BadAlloc;
+
+	if (cm_prop_index == CM_GAMMA_LUT_SIZE) {
+		format = 32;
+		length = 1;
+		data = &crtc->gamma_lut_size;
+		range[0] = 0;
+		range[1] = -1;
+
+	} else if (cm_prop_index == CM_DEGAMMA_LUT_SIZE) {
+		format = 32;
+		length = 1;
+		data = &crtc->degamma_lut_size;
+		range[0] = 0;
+		range[1] = -1;
+
+	} else if (cm_prop_index == CM_GAMMA_LUT) {
+		format = 16;
+		range[0] = 0;
+		range[1] = (1 << 16) - 1; // Max 16 bit unsigned int.
+		if (crtc->gamma_lut) {
+			/* Convert from 8bit size to 16bit size */
+			length = sizeof(*crtc->gamma_lut) >> 1;
+			length *= crtc->gamma_lut_size;
+			data = crtc->gamma_lut;
+		} else {
+			length = 1;
+			value = 0;
+			data = &value;
+		}
+	} else if (cm_prop_index == CM_DEGAMMA_LUT) {
+		format = 16;
+		range[0] = 0;
+		range[1] = (1 << 16) - 1; // Max 16 bit unsigned int.
+		if (crtc->degamma_lut) {
+			/* Convert from 8bit size to 16bit size */
+			length = sizeof(*crtc->degamma_lut) >> 1;
+			length *= crtc->degamma_lut_size;
+			data = crtc->degamma_lut;
+		} else {
+			length = 1;
+			value = 0;
+			data = &value;
+		}
+	} else {
+		/* CTM is fixed-point S31.32 format. */
+		format = 16;
+		need_configure = FALSE;
+		if (crtc->ctm) {
+			length = sizeof(*crtc->ctm) >> 1;
+			data = crtc->ctm;
+		} else {
+			length = 1;
+			value = 0;
+			data = &value;
+		}
+	}
+
+	if (need_configure) {
+		err = RRConfigureOutputProperty(output->randr_output, atom,
+						FALSE, TRUE, FALSE, 2, range);
+		if (err) {
+			xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
+				   "Configuring color management property %s failed with %d\n",
+				   CM_PROP_NAMES[cm_prop_index], err);
+			return err;
+		}
+	}
+
+	err = RRChangeOutputProperty(output->randr_output, atom,
+				     XA_INTEGER, format,
+				     PropModeReplace,
+				     length, data, FALSE, pending);
+	if (err) {
+		xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
+			   "Changing color management property %s failed with %d\n",
+			   CM_PROP_NAMES[cm_prop_index], err);
+		return err;
+	}
+
+	return 0;
+}
+
+/**
  * Push staged color management properties on the CRTC to DRM.
  *
  * @crtc: The CRTC containing staged properties
@@ -1851,6 +1969,40 @@ static Bool drmmode_property_ignore(drmModePropertyPtr prop)
 	return FALSE;
 }
 
+/**
+ * Using a fake CRTC, configure and change color properties for the output,
+ * using the default (0) color properties on the fake CRTC. Use to initialize
+ * color management properties on an output where a CRTC has not yet been
+ * attached.
+ */
+static void drmmode_disabled_crtc_create_resources(xf86OutputPtr output)
+{
+	drmmode_crtc_private_ptr fake_crtc;
+	int i, ret;
+
+	/* Create a fake crtc */
+	fake_crtc = calloc(1, sizeof(drmmode_crtc_private_rec));
+	if (!fake_crtc) {
+		xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
+			   "Memory error creating resources for fake CRTC\n");
+		return;
+	}
+
+	for (i = 0; i < CM_NUM_PROPS; i++) {
+		ret = rr_configure_and_change_cm_property(output, fake_crtc, i,
+							  FALSE);
+		if (ret) {
+			xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
+				   "Configur and change cm property error %d\n",
+				   ret);
+			break;
+		}
+	}
+
+	free(fake_crtc);
+	return;
+}
+
 static void drmmode_output_create_resources(xf86OutputPtr output)
 {
 	AMDGPUInfoPtr info = AMDGPUPTR(output->scrn);
@@ -1978,6 +2130,8 @@ static void drmmode_output_create_resources(xf86OutputPtr output)
 			}
 		}
 	}
+
+	drmmode_disabled_crtc_create_resources(output);
 }
 
 static void
-- 
2.7.4

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

  parent reply	other threads:[~2018-05-03 18:31 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-03 18:31 [PATCH xf86-video-amdgpu 00/13] Enabling Color Management - Round 2 sunpeng.li-5C7GfCeVMHo
     [not found] ` <1525372315-28462-1-git-send-email-sunpeng.li-5C7GfCeVMHo@public.gmane.org>
2018-05-03 18:31   ` [PATCH xf86-video-amdgpu 01/13] Add color management properties to driver-private CRTC object sunpeng.li-5C7GfCeVMHo
     [not found]     ` <1525372315-28462-2-git-send-email-sunpeng.li-5C7GfCeVMHo@public.gmane.org>
2018-05-16 17:07       ` Michel Dänzer
     [not found]         ` <0dda7c80-2bdc-52a7-8dcf-ad5a7f6e9346-otUistvHUpPR7s880joybQ@public.gmane.org>
2018-05-17 21:43           ` Leo Li
2018-05-03 18:31   ` [PATCH xf86-video-amdgpu 02/13] Push color properties to kernel DRM on CRTC init sunpeng.li-5C7GfCeVMHo
     [not found]     ` <1525372315-28462-3-git-send-email-sunpeng.li-5C7GfCeVMHo@public.gmane.org>
2018-05-16 17:08       ` Michel Dänzer
     [not found]         ` <a2b8ff58-edcc-bb95-f630-1926b1a8874b-otUistvHUpPR7s880joybQ@public.gmane.org>
2018-05-17 21:43           ` Leo Li
     [not found]             ` <db641905-9dea-015d-24d2-fa25d136abfc-5C7GfCeVMHo@public.gmane.org>
2018-05-18  7:52               ` Michel Dänzer
2018-05-03 18:31   ` sunpeng.li-5C7GfCeVMHo [this message]
     [not found]     ` <1525372315-28462-4-git-send-email-sunpeng.li-5C7GfCeVMHo@public.gmane.org>
2018-05-16 17:09       ` [PATCH xf86-video-amdgpu 03/13] List disabled color properties on RandR outputs without a CRTC Michel Dänzer
     [not found]         ` <62d1f2e3-d271-658a-7bf4-88b41b080266-otUistvHUpPR7s880joybQ@public.gmane.org>
2018-05-17 21:43           ` Leo Li
2018-05-03 18:31   ` [PATCH xf86-video-amdgpu 04/13] Use CRTC's color properties if output has a CRTC attached sunpeng.li-5C7GfCeVMHo
2018-05-03 18:31   ` [PATCH xf86-video-amdgpu 05/13] Enable setting of color properties though RandR sunpeng.li-5C7GfCeVMHo
2018-05-03 18:31   ` [PATCH xf86-video-amdgpu 06/13] Compose non-legacy with legacy gamma LUT before pushing to kernel DRM sunpeng.li-5C7GfCeVMHo
2018-05-03 18:31   ` [PATCH xf86-video-amdgpu 07/13] Also compose LUT when setting legacy gamma sunpeng.li-5C7GfCeVMHo
2018-05-03 18:31   ` [PATCH xf86-video-amdgpu 08/13] Set driver-private CRTC's dpms mode on disable sunpeng.li-5C7GfCeVMHo
     [not found]     ` <1525372315-28462-9-git-send-email-sunpeng.li-5C7GfCeVMHo@public.gmane.org>
2018-05-16 17:09       ` Michel Dänzer
     [not found]         ` <12553d4f-c171-112b-bad6-6f53d47aa8e3-otUistvHUpPR7s880joybQ@public.gmane.org>
2018-05-17 21:43           ` Leo Li
     [not found]             ` <6cf602ed-b43d-d446-74a0-a39d35042f5a-5C7GfCeVMHo@public.gmane.org>
2018-05-18 10:35               ` Michel Dänzer
2018-05-03 18:31   ` [PATCH xf86-video-amdgpu 09/13] Move drmmode_do_crtc_dpms sunpeng.li-5C7GfCeVMHo
2018-05-03 18:31   ` [PATCH xf86-video-amdgpu 10/13] Push staged color properties when DPMS state toggles On sunpeng.li-5C7GfCeVMHo
     [not found]     ` <1525372315-28462-11-git-send-email-sunpeng.li-5C7GfCeVMHo@public.gmane.org>
2018-05-16 17:10       ` Michel Dänzer
     [not found]         ` <23a9fe2a-df1c-6ecb-b60e-bdcb22d8179c-otUistvHUpPR7s880joybQ@public.gmane.org>
2018-05-17 21:44           ` Leo Li
     [not found]             ` <f323d1de-d517-805f-d373-a7310ec6496c-5C7GfCeVMHo@public.gmane.org>
2018-05-18  8:01               ` Michel Dänzer
     [not found]                 ` <6500b993-624a-45aa-6310-958ca8c1f21b-otUistvHUpPR7s880joybQ@public.gmane.org>
2018-05-24 19:01                   ` Leo Li
2018-05-03 18:31   ` [PATCH xf86-video-amdgpu 11/13] Push staged color properties on output detect sunpeng.li-5C7GfCeVMHo
2018-05-03 18:31   ` [PATCH xf86-video-amdgpu 12/13] Update color properties on modeset major sunpeng.li-5C7GfCeVMHo
2018-05-03 18:31   ` [PATCH xf86-video-amdgpu 13/13] Refactor pushing color management properties into a function sunpeng.li-5C7GfCeVMHo
2018-05-14 13:38   ` [PATCH xf86-video-amdgpu 00/13] Enabling Color Management - Round 2 Leo Li
2018-05-14 14:17   ` Michel Dänzer
2018-05-16 17:06   ` Michel Dänzer
     [not found]     ` <b3a7fcde-fe69-5944-1857-c2b43fa068de-otUistvHUpPR7s880joybQ@public.gmane.org>
2018-05-17 21:43       ` Leo Li
     [not found]         ` <62c350eb-8634-5bab-e14e-6d75315e3f56-5C7GfCeVMHo@public.gmane.org>
2018-05-18  8:10           ` Michel Dänzer
     [not found]             ` <8fe3423f-8d9e-120c-32e1-7a6a7fd81606-otUistvHUpPR7s880joybQ@public.gmane.org>
2018-05-24 20:29               ` Leo Li
     [not found]                 ` <7c183caf-d2de-cf56-ed31-7922b24d3a8e-5C7GfCeVMHo@public.gmane.org>
2018-05-25  7:51                   ` Michel Dänzer

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=1525372315-28462-4-git-send-email-sunpeng.li@amd.com \
    --to=sunpeng.li-5c7gfcevmho@public.gmane.org \
    --cc=amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    --cc=harry.wentland-5C7GfCeVMHo@public.gmane.org \
    --cc=michel-otUistvHUpPR7s880joybQ@public.gmane.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox