aboutsummaryrefslogtreecommitdiffstats
path: root/meta-amd-bsp/recipes-kernel/linux/linux-yocto-4.14.71/0072-drm-amd-display-Refactor-to-move-gamma-correction-to.patch
blob: 86c94b91adff0d9f62183ff79f445baa08c93dfd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
From d2e6be5c4c3414043a20cd5b1820a78c37e3dedd Mon Sep 17 00:00:00 2001
From: Anthony Koo <Anthony.Koo@amd.com>
Date: Fri, 16 Dec 2016 10:43:21 -0500
Subject: [PATCH 0072/4131] drm/amd/display: Refactor to move gamma correction
 to module

Refactor part 4 - Moving input gamma correction programming into color module

DM will translate to dc_gamma structure, but programming will be moved into
the color module. Later, this will allow gamma correction to be added on top of
in/out transfer function curves.

Signed-off-by: Anthony Koo <anthony.koo@amd.com>
Reviewed-by: Anthony Koo <Anthony.Koo@amd.com>
Acked-by: Harry Wentland <Harry.Wentland@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
---
 drivers/gpu/drm/amd/display/modules/color/color.c  | 77 ++++++++++++++++++++++
 .../gpu/drm/amd/display/modules/inc/mod_color.h    |  4 ++
 2 files changed, 81 insertions(+)

diff --git a/drivers/gpu/drm/amd/display/modules/color/color.c b/drivers/gpu/drm/amd/display/modules/color/color.c
index 0610b82..6613ff9 100644
--- a/drivers/gpu/drm/amd/display/modules/color/color.c
+++ b/drivers/gpu/drm/amd/display/modules/color/color.c
@@ -69,6 +69,7 @@ struct color_state {
 	struct color_range saturation;
 	struct color_range brightness;
 	struct color_range hue;
+	struct dc_gamma *gamma;
 	enum dc_quantization_range preferred_quantization_range;
 };
 
@@ -1265,6 +1266,26 @@ static void calculate_csc_matrix(struct core_color *core_color,
 	}
 }
 
+static struct dc_surface *dc_stream_to_surface_from_pipe_ctx(
+		struct core_color *core_color,
+		const struct dc_stream *stream)
+{
+	int i;
+	struct core_dc *core_dc = DC_TO_CORE(core_color->dc);
+	struct core_stream *core_stream = DC_STREAM_TO_CORE(stream);
+	struct dc_surface *out_surface = NULL;
+
+	for (i = 0; i < MAX_PIPES; i++) {
+		if (core_dc->current_context->res_ctx.pipe_ctx[i].stream
+						== core_stream) {
+			out_surface = &core_dc->current_context->res_ctx.
+					pipe_ctx[i].surface->public;
+			break;
+		}
+	}
+	return out_surface;
+}
+
 struct mod_color *mod_color_create(struct dc *dc)
 {
 	int i = 0;
@@ -1369,6 +1390,10 @@ void mod_color_destroy(struct mod_color *mod_color)
 		struct core_color *core_color =
 				MOD_COLOR_TO_CORE(mod_color);
 
+		for (i = 0; i < core_color->num_sinks; i++)
+			if (core_color->state[i].gamma)
+				dc_gamma_release(core_color->state[i].gamma);
+
 		dm_free(core_color->state);
 
 		for (i = 0; i < core_color->num_sinks; i++)
@@ -1552,6 +1577,9 @@ bool mod_color_remove_sink(struct mod_color *mod_color,
 
 	for (i = 0; i < core_color->num_sinks; i++) {
 		if (core_color->caps[i].sink == sink) {
+			if (core_color->state[i].gamma)
+				dc_gamma_release(core_color->state[i].gamma);
+
 			/* To remove this sink, shift everything after down */
 			for (j = i; j < core_color->num_sinks - 1; j++) {
 				core_color->caps[j].sink =
@@ -2184,6 +2212,55 @@ bool mod_color_set_saturation(struct mod_color *mod_color,
 	return true;
 }
 
+bool mod_color_set_input_gamma_correction(struct mod_color *mod_color,
+		const struct dc_stream **streams, int num_streams,
+		struct dc_gamma *gamma)
+{
+	struct core_color *core_color = MOD_COLOR_TO_CORE(mod_color);
+	unsigned int stream_index, sink_index;
+
+	for (stream_index = 0; stream_index < num_streams; stream_index++) {
+		sink_index = sink_index_from_sink(core_color,
+				streams[stream_index]->sink);
+
+		struct dc_surface *surface =
+				dc_stream_to_surface_from_pipe_ctx(core_color,
+						streams[stream_index]);
+
+		if (surface != NULL) {
+			struct dc_transfer_func *input_tf =
+					dc_create_transfer_func(core_color->dc);
+			struct dc_surface_update updates = {0};
+
+			if (input_tf != NULL) {
+				input_tf->type = TF_TYPE_PREDEFINED;
+				input_tf->tf = TRANSFER_FUNCTION_SRGB;
+			}
+
+			if (core_color->state[sink_index].gamma != gamma) {
+				if (core_color->state[sink_index].gamma)
+					dc_gamma_release(
+						core_color->state[sink_index].
+						gamma);
+
+				dc_gamma_retain(gamma);
+				core_color->state[sink_index].gamma = gamma;
+			}
+
+			updates.surface = surface;
+			updates.gamma = gamma;
+			updates.in_transfer_func = input_tf;
+			dc_update_surfaces_for_target(core_color->dc, &updates,
+					1, NULL);
+
+			if (input_tf != NULL)
+				dc_transfer_func_release(input_tf);
+		}
+	}
+
+	return true;
+}
+
 bool mod_color_persist_user_preferred_quantization_range(
 		struct mod_color *mod_color,
 		const struct dc_sink *sink,
diff --git a/drivers/gpu/drm/amd/display/modules/inc/mod_color.h b/drivers/gpu/drm/amd/display/modules/inc/mod_color.h
index 787c2c0..fbf9081 100644
--- a/drivers/gpu/drm/amd/display/modules/inc/mod_color.h
+++ b/drivers/gpu/drm/amd/display/modules/inc/mod_color.h
@@ -168,6 +168,10 @@ bool mod_color_set_saturation(struct mod_color *mod_color,
 		const struct dc_stream **streams, int num_streams,
 		int saturation_value);
 
+bool mod_color_set_input_gamma_correction(struct mod_color *mod_color,
+		const struct dc_stream **streams, int num_streams,
+		struct dc_gamma *gamma);
+
 bool mod_color_persist_user_preferred_quantization_range(
 		struct mod_color *mod_color,
 		const struct dc_sink *sink,
-- 
2.7.4