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