1 /* Copyright 2023 Advanced Micro Devices, Inc.
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a
4 * copy of this software and associated documentation files (the "Software"),
5 * to deal in the Software without restriction, including without limitation
6 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 * and/or sell copies of the Software, and to permit persons to whom the
8 * Software is furnished to do so, subject to the following conditions:
9 *
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
17 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
18 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
19 * OTHER DEALINGS IN THE SOFTWARE.
20 *
21 * Authors: AMD
22 *
23 */
24
25 #include "vpe_visual_confirm.h"
26 #include "common.h"
27 #include "vpe_priv.h"
28 #include "color_bg.h"
29 #include "background.h"
30 #include "resource.h"
31
get_visual_confirm_segs_count(uint32_t max_seg_width,uint32_t target_rect_width)32 static uint16_t get_visual_confirm_segs_count(uint32_t max_seg_width, uint32_t target_rect_width)
33 {
34 // Unlike max_gaps logic in vpe10_calculate_segments, we are pure BG seg, no need to worry
35 // stream splitted among one of the segment. so no need to "+1", just round up the calculated
36 // number of segments.
37 uint16_t seg_cnt = (uint16_t)(max((target_rect_width + max_seg_width - 1) / max_seg_width, 1));
38
39 return seg_cnt;
40 }
41
vpe_get_visual_confirm_total_seg_count(struct vpe_priv * vpe_priv,uint32_t max_seg_width,const struct vpe_build_param * params)42 static uint16_t vpe_get_visual_confirm_total_seg_count(
43 struct vpe_priv *vpe_priv, uint32_t max_seg_width, const struct vpe_build_param *params)
44 {
45 uint16_t segs_num = 0;
46 uint16_t total_visual_confirm_segs = 0;
47 uint16_t stream_idx;
48 struct stream_ctx *stream_ctx;
49
50 if (vpe_priv->init.debug.visual_confirm_params.input_format) {
51 for (stream_idx = 0; stream_idx < vpe_priv->num_streams; stream_idx++) {
52 stream_ctx = &vpe_priv->stream_ctx[stream_idx];
53 total_visual_confirm_segs += get_visual_confirm_segs_count(
54 max_seg_width, stream_ctx->stream.scaling_info.dst_rect.width);
55 }
56 }
57
58 if (vpe_priv->init.debug.visual_confirm_params.output_format) {
59 total_visual_confirm_segs +=
60 get_visual_confirm_segs_count(max_seg_width, params->target_rect.width);
61 }
62
63 return total_visual_confirm_segs;
64 }
65
vpe_get_visual_confirm_color(enum vpe_surface_pixel_format format,struct vpe_color_space cs,enum color_space output_cs,struct transfer_func * output_tf,enum vpe_surface_pixel_format output_format,bool enable_3dlut)66 struct vpe_color vpe_get_visual_confirm_color(enum vpe_surface_pixel_format format,
67 struct vpe_color_space cs, enum color_space output_cs, struct transfer_func *output_tf,
68 enum vpe_surface_pixel_format output_format, bool enable_3dlut)
69 {
70 struct vpe_color visual_confirm_color;
71 visual_confirm_color.is_ycbcr = false;
72 visual_confirm_color.rgba.a = 0.0;
73 visual_confirm_color.rgba.r = 0.0;
74 visual_confirm_color.rgba.g = 0.0;
75 visual_confirm_color.rgba.b = 0.0;
76
77 switch (format) {
78 case VPE_SURFACE_PIXEL_FORMAT_VIDEO_420_YCbCr:
79 case VPE_SURFACE_PIXEL_FORMAT_VIDEO_420_YCrCb:
80 // YUV420 8bit: Green
81 visual_confirm_color.rgba.r = 0.0;
82 visual_confirm_color.rgba.g = 1.0;
83 visual_confirm_color.rgba.b = 0.0;
84 break;
85 case VPE_SURFACE_PIXEL_FORMAT_VIDEO_420_10bpc_YCbCr:
86 case VPE_SURFACE_PIXEL_FORMAT_VIDEO_420_10bpc_YCrCb:
87 // YUV420 10bit: yellow (SDR)
88 switch (cs.tf) {
89 case VPE_TF_G22:
90 case VPE_TF_G24:
91 visual_confirm_color.rgba.r = 1.0;
92 visual_confirm_color.rgba.g = 1.0;
93 visual_confirm_color.rgba.b = 0.0;
94 break;
95 // YUV420 10bit: White (HDR)
96 case VPE_TF_PQ:
97 case VPE_TF_HLG:
98 if (enable_3dlut) {
99 visual_confirm_color.rgba.r = 1.0;
100 visual_confirm_color.rgba.g = 1.0;
101 visual_confirm_color.rgba.b = 1.0;
102 } else {
103 visual_confirm_color.rgba.r = 1.0;
104 visual_confirm_color.rgba.g = 0.0;
105 visual_confirm_color.rgba.b = 0.0;
106 }
107 break;
108 default:
109 break;
110 }
111 break;
112 case VPE_SURFACE_PIXEL_FORMAT_GRPH_ARGB8888:
113 case VPE_SURFACE_PIXEL_FORMAT_GRPH_ABGR8888:
114 case VPE_SURFACE_PIXEL_FORMAT_GRPH_RGBA8888:
115 case VPE_SURFACE_PIXEL_FORMAT_GRPH_BGRA8888:
116 case VPE_SURFACE_PIXEL_FORMAT_GRPH_XRGB8888:
117 case VPE_SURFACE_PIXEL_FORMAT_GRPH_XBGR8888:
118 case VPE_SURFACE_PIXEL_FORMAT_GRPH_RGBX8888:
119 case VPE_SURFACE_PIXEL_FORMAT_GRPH_BGRX8888:
120 // RGBA and RGBX 8 bit and variants : Pink
121 visual_confirm_color.rgba.r = 1.0;
122 visual_confirm_color.rgba.g = 0.5;
123 visual_confirm_color.rgba.b = 1.0;
124 break;
125 case VPE_SURFACE_PIXEL_FORMAT_GRPH_ARGB2101010:
126 case VPE_SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010:
127 case VPE_SURFACE_PIXEL_FORMAT_GRPH_RGBA1010102:
128 case VPE_SURFACE_PIXEL_FORMAT_GRPH_BGRA1010102:
129 // RGBA 10 bit and variants : Cyan
130 visual_confirm_color.rgba.r = 0.0;
131 visual_confirm_color.rgba.g = 1.0;
132 visual_confirm_color.rgba.b = 1.0;
133 break;
134 case VPE_SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616F:
135 case VPE_SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616F:
136 case VPE_SURFACE_PIXEL_FORMAT_GRPH_RGBA16161616F:
137 case VPE_SURFACE_PIXEL_FORMAT_GRPH_BGRA16161616F:
138 // FP16 and variants: orange
139 visual_confirm_color.rgba.r = 1.0;
140 visual_confirm_color.rgba.g = 0.21972f;
141 visual_confirm_color.rgba.b = 0.0;
142 break;
143 default:
144 break;
145 }
146
147 // Due to there will be regamma (ogam), need convert the bg color for visual confirm
148 vpe_bg_color_convert(output_cs, output_tf, &visual_confirm_color, enable_3dlut);
149
150 // Experimental: To make FP16 Linear color looks more visually ok
151 if (vpe_is_fp16(output_format)) {
152 visual_confirm_color.rgba.r /= 125;
153 visual_confirm_color.rgba.g /= 125;
154 visual_confirm_color.rgba.b /= 125;
155 }
156
157 return visual_confirm_color;
158 }
159
vpe_create_visual_confirm_segs(struct vpe_priv * vpe_priv,const struct vpe_build_param * params,uint32_t max_seg_width)160 enum vpe_status vpe_create_visual_confirm_segs(
161 struct vpe_priv *vpe_priv, const struct vpe_build_param *params, uint32_t max_seg_width)
162 {
163 uint16_t stream_idx;
164 struct stream_ctx *stream_ctx;
165 struct vpe_rect visual_confirm_rect;
166 struct vpe_rect *visual_confirm_gaps;
167 struct vpe_rect *current_gap;
168
169 uint16_t total_seg_cnt =
170 vpe_get_visual_confirm_total_seg_count(vpe_priv, max_seg_width, params);
171 uint16_t seg_cnt = 0;
172
173 if (!total_seg_cnt)
174 return VPE_STATUS_OK;
175
176 visual_confirm_gaps = vpe_zalloc(sizeof(struct vpe_rect) * total_seg_cnt);
177 if (!visual_confirm_gaps)
178 return VPE_STATUS_NO_MEMORY;
179
180 current_gap = visual_confirm_gaps;
181
182 // Do visual confirm bg generation for intput format
183 if (vpe_priv->init.debug.visual_confirm_params.input_format &&
184 params->target_rect.height > 2 * VISUAL_CONFIRM_HEIGHT) {
185 for (stream_idx = 0; stream_idx < params->num_streams; stream_idx++) {
186 stream_ctx = &vpe_priv->stream_ctx[stream_idx];
187 visual_confirm_rect = stream_ctx->stream.scaling_info.dst_rect;
188 visual_confirm_rect.y += 0;
189 visual_confirm_rect.height = VISUAL_CONFIRM_HEIGHT;
190 seg_cnt = get_visual_confirm_segs_count(
191 max_seg_width, stream_ctx->stream.scaling_info.dst_rect.width);
192 vpe_full_bg_gaps(current_gap, &visual_confirm_rect, seg_cnt);
193 vpe_priv->resource.create_bg_segments(
194 vpe_priv, current_gap, seg_cnt, VPE_CMD_OPS_BG_VSCF_INPUT);
195 current_gap += seg_cnt;
196 }
197 }
198 // Do visual confirm bg generation for output format
199 if (vpe_priv->init.debug.visual_confirm_params.output_format &&
200 params->target_rect.height > VISUAL_CONFIRM_HEIGHT) {
201 visual_confirm_rect = params->target_rect;
202 visual_confirm_rect.y += VISUAL_CONFIRM_HEIGHT;
203 visual_confirm_rect.height = VISUAL_CONFIRM_HEIGHT;
204 seg_cnt = get_visual_confirm_segs_count(max_seg_width, params->target_rect.width);
205 vpe_full_bg_gaps(current_gap, &visual_confirm_rect, seg_cnt);
206 vpe_priv->resource.create_bg_segments(
207 vpe_priv, current_gap, seg_cnt, VPE_CMD_OPS_BG_VSCF_OUTPUT);
208 }
209
210 if (visual_confirm_gaps != NULL) {
211 vpe_free(visual_confirm_gaps);
212 visual_confirm_gaps = NULL;
213 current_gap = NULL;
214 }
215
216 return VPE_STATUS_OK;
217 }
218