xref: /netbsd-src/sys/external/bsd/drm2/dist/drm/amd/display/dc/basics/amdgpu_dc_common.c (revision 41ec02673d281bbb3d38e6c78504ce6e30c228c1)
1 /*	$NetBSD: amdgpu_dc_common.c,v 1.2 2021/12/18 23:45:00 riastradh Exp $	*/
2 
3 /*
4  * Copyright 2012-15 Advanced Micro Devices, Inc.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22  * OTHER DEALINGS IN THE SOFTWARE.
23  *
24  * Authors: AMD
25  *
26  */
27 
28 #include <sys/cdefs.h>
29 __KERNEL_RCSID(0, "$NetBSD: amdgpu_dc_common.c,v 1.2 2021/12/18 23:45:00 riastradh Exp $");
30 
31 #include "core_types.h"
32 #include "dc_common.h"
33 #include "basics/conversion.h"
34 
is_rgb_cspace(enum dc_color_space output_color_space)35 bool is_rgb_cspace(enum dc_color_space output_color_space)
36 {
37 	switch (output_color_space) {
38 	case COLOR_SPACE_SRGB:
39 	case COLOR_SPACE_SRGB_LIMITED:
40 	case COLOR_SPACE_2020_RGB_FULLRANGE:
41 	case COLOR_SPACE_2020_RGB_LIMITEDRANGE:
42 	case COLOR_SPACE_ADOBERGB:
43 		return true;
44 	case COLOR_SPACE_YCBCR601:
45 	case COLOR_SPACE_YCBCR709:
46 	case COLOR_SPACE_YCBCR601_LIMITED:
47 	case COLOR_SPACE_YCBCR709_LIMITED:
48 	case COLOR_SPACE_2020_YCBCR:
49 		return false;
50 	default:
51 		/* Add a case to switch */
52 		BREAK_TO_DEBUGGER();
53 		return false;
54 	}
55 }
56 
is_lower_pipe_tree_visible(struct pipe_ctx * pipe_ctx)57 bool is_lower_pipe_tree_visible(struct pipe_ctx *pipe_ctx)
58 {
59 	if (pipe_ctx->plane_state && pipe_ctx->plane_state->visible)
60 		return true;
61 	if (pipe_ctx->bottom_pipe && is_lower_pipe_tree_visible(pipe_ctx->bottom_pipe))
62 		return true;
63 	return false;
64 }
65 
is_upper_pipe_tree_visible(struct pipe_ctx * pipe_ctx)66 bool is_upper_pipe_tree_visible(struct pipe_ctx *pipe_ctx)
67 {
68 	if (pipe_ctx->plane_state && pipe_ctx->plane_state->visible)
69 		return true;
70 	if (pipe_ctx->top_pipe && is_upper_pipe_tree_visible(pipe_ctx->top_pipe))
71 		return true;
72 	return false;
73 }
74 
is_pipe_tree_visible(struct pipe_ctx * pipe_ctx)75 bool is_pipe_tree_visible(struct pipe_ctx *pipe_ctx)
76 {
77 	if (pipe_ctx->plane_state && pipe_ctx->plane_state->visible)
78 		return true;
79 	if (pipe_ctx->top_pipe && is_upper_pipe_tree_visible(pipe_ctx->top_pipe))
80 		return true;
81 	if (pipe_ctx->bottom_pipe && is_lower_pipe_tree_visible(pipe_ctx->bottom_pipe))
82 		return true;
83 	return false;
84 }
85 
build_prescale_params(struct dc_bias_and_scale * bias_and_scale,const struct dc_plane_state * plane_state)86 void build_prescale_params(struct  dc_bias_and_scale *bias_and_scale,
87 		const struct dc_plane_state *plane_state)
88 {
89 	if (plane_state->format >= SURFACE_PIXEL_FORMAT_VIDEO_BEGIN
90 			&& plane_state->format != SURFACE_PIXEL_FORMAT_INVALID
91 			&& plane_state->input_csc_color_matrix.enable_adjustment
92 			&& plane_state->coeff_reduction_factor.value != 0) {
93 		bias_and_scale->scale_blue = fixed_point_to_int_frac(
94 			dc_fixpt_mul(plane_state->coeff_reduction_factor,
95 					dc_fixpt_from_fraction(256, 255)),
96 				2,
97 				13);
98 		bias_and_scale->scale_red = bias_and_scale->scale_blue;
99 		bias_and_scale->scale_green = bias_and_scale->scale_blue;
100 	} else {
101 		bias_and_scale->scale_blue = 0x2000;
102 		bias_and_scale->scale_red = 0x2000;
103 		bias_and_scale->scale_green = 0x2000;
104 	}
105 }
106 
107