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
should_generate_visual_confirm(enum vpe_stream_type stream_type)32 static bool should_generate_visual_confirm(enum vpe_stream_type stream_type)
33 {
34 switch (stream_type) {
35 case VPE_STREAM_TYPE_INPUT:
36 case VPE_STREAM_TYPE_BG_GEN:
37 return true;
38 default:
39 return false;
40 break;
41 }
42 }
43
get_visual_confirm_segs_count(uint32_t max_seg_width,uint32_t target_rect_width)44 static uint16_t get_visual_confirm_segs_count(uint32_t max_seg_width, uint32_t target_rect_width)
45 {
46 // Unlike max_gaps logic in vpe10_calculate_segments, we are pure BG seg, no need to worry
47 // stream splitted among one of the segment. so no need to "+1", just round up the calculated
48 // number of segments.
49 uint16_t seg_cnt = (uint16_t)(max((target_rect_width + max_seg_width - 1) / max_seg_width, 1));
50
51 return seg_cnt;
52 }
53
vpe_get_visual_confirm_total_seg_count(struct vpe_priv * vpe_priv,uint32_t max_seg_width,const struct vpe_build_param * params)54 static uint16_t vpe_get_visual_confirm_total_seg_count(
55 struct vpe_priv *vpe_priv, uint32_t max_seg_width, const struct vpe_build_param *params)
56 {
57 uint16_t segs_num = 0;
58 uint16_t total_visual_confirm_segs = 0;
59 uint16_t stream_idx;
60 struct stream_ctx *stream_ctx;
61
62 if (vpe_priv->init.debug.visual_confirm_params.input_format) {
63 for (stream_idx = 0; stream_idx < vpe_priv->num_streams; stream_idx++) {
64 stream_ctx = &vpe_priv->stream_ctx[stream_idx];
65 if (should_generate_visual_confirm(stream_ctx->stream_type))
66 total_visual_confirm_segs += get_visual_confirm_segs_count(
67 max_seg_width, stream_ctx->stream.scaling_info.dst_rect.width);
68 }
69 }
70
71 if (vpe_priv->init.debug.visual_confirm_params.output_format) {
72 total_visual_confirm_segs +=
73 get_visual_confirm_segs_count(max_seg_width, params->target_rect.width);
74 }
75
76 return total_visual_confirm_segs;
77 }
78
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)79 struct vpe_color vpe_get_visual_confirm_color(enum vpe_surface_pixel_format format,
80 struct vpe_color_space cs, enum color_space output_cs, struct transfer_func *output_tf,
81 enum vpe_surface_pixel_format output_format, bool enable_3dlut)
82 {
83 struct vpe_color visual_confirm_color;
84 visual_confirm_color.is_ycbcr = false;
85 visual_confirm_color.rgba.a = 0.0;
86 visual_confirm_color.rgba.r = 0.0;
87 visual_confirm_color.rgba.g = 0.0;
88 visual_confirm_color.rgba.b = 0.0;
89
90 switch (format) {
91 case VPE_SURFACE_PIXEL_FORMAT_VIDEO_420_YCbCr:
92 case VPE_SURFACE_PIXEL_FORMAT_VIDEO_420_YCrCb:
93 // YUV420 8bit: Green
94 visual_confirm_color.rgba.r = 0.0;
95 visual_confirm_color.rgba.g = 1.0;
96 visual_confirm_color.rgba.b = 0.0;
97 break;
98 case VPE_SURFACE_PIXEL_FORMAT_VIDEO_420_10bpc_YCbCr:
99 case VPE_SURFACE_PIXEL_FORMAT_VIDEO_420_10bpc_YCrCb:
100 // YUV420 10bit: yellow (SDR)
101 switch (cs.tf) {
102 case VPE_TF_G22:
103 case VPE_TF_G24:
104 visual_confirm_color.rgba.r = 1.0;
105 visual_confirm_color.rgba.g = 1.0;
106 visual_confirm_color.rgba.b = 0.0;
107 break;
108 // YUV420 10bit: White (HDR)
109 case VPE_TF_PQ:
110 case VPE_TF_HLG:
111 if (enable_3dlut) {
112 visual_confirm_color.rgba.r = 1.0;
113 visual_confirm_color.rgba.g = 1.0;
114 visual_confirm_color.rgba.b = 1.0;
115 } else {
116 visual_confirm_color.rgba.r = 1.0;
117 visual_confirm_color.rgba.g = 0.0;
118 visual_confirm_color.rgba.b = 0.0;
119 }
120 break;
121 default:
122 break;
123 }
124 break;
125 case VPE_SURFACE_PIXEL_FORMAT_GRPH_ARGB8888:
126 case VPE_SURFACE_PIXEL_FORMAT_GRPH_ABGR8888:
127 case VPE_SURFACE_PIXEL_FORMAT_GRPH_RGBA8888:
128 case VPE_SURFACE_PIXEL_FORMAT_GRPH_BGRA8888:
129 case VPE_SURFACE_PIXEL_FORMAT_GRPH_XRGB8888:
130 case VPE_SURFACE_PIXEL_FORMAT_GRPH_XBGR8888:
131 case VPE_SURFACE_PIXEL_FORMAT_GRPH_RGBX8888:
132 case VPE_SURFACE_PIXEL_FORMAT_GRPH_BGRX8888:
133 // RGBA and RGBX 8 bit and variants : Pink
134 visual_confirm_color.rgba.r = 1.0;
135 visual_confirm_color.rgba.g = 0.5;
136 visual_confirm_color.rgba.b = 1.0;
137 break;
138 case VPE_SURFACE_PIXEL_FORMAT_GRPH_ARGB2101010:
139 case VPE_SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010:
140 case VPE_SURFACE_PIXEL_FORMAT_GRPH_RGBA1010102:
141 case VPE_SURFACE_PIXEL_FORMAT_GRPH_BGRA1010102:
142 // RGBA 10 bit and variants : Cyan
143 visual_confirm_color.rgba.r = 0.0;
144 visual_confirm_color.rgba.g = 1.0;
145 visual_confirm_color.rgba.b = 1.0;
146 break;
147 case VPE_SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616F:
148 case VPE_SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616F:
149 case VPE_SURFACE_PIXEL_FORMAT_GRPH_RGBA16161616F:
150 case VPE_SURFACE_PIXEL_FORMAT_GRPH_BGRA16161616F:
151 // FP16 and variants: orange
152 visual_confirm_color.rgba.r = 1.0;
153 visual_confirm_color.rgba.g = 0.21972f;
154 visual_confirm_color.rgba.b = 0.0;
155 break;
156 default:
157 break;
158 }
159
160 // Due to there will be regamma (ogam), need convert the bg color for visual confirm
161 vpe_bg_color_convert(
162 output_cs, output_tf, output_format, &visual_confirm_color, NULL, enable_3dlut);
163
164 // Experimental: To make FP16 Linear color looks more visually ok
165 if (vpe_is_fp16(output_format)) {
166 visual_confirm_color.rgba.r /= 125;
167 visual_confirm_color.rgba.g /= 125;
168 visual_confirm_color.rgba.b /= 125;
169 }
170
171 return visual_confirm_color;
172 }
173
vpe_create_visual_confirm_segs(struct vpe_priv * vpe_priv,const struct vpe_build_param * params,uint32_t max_seg_width)174 enum vpe_status vpe_create_visual_confirm_segs(
175 struct vpe_priv *vpe_priv, const struct vpe_build_param *params, uint32_t max_seg_width)
176 {
177 uint16_t stream_idx;
178 struct stream_ctx *stream_ctx;
179 struct vpe_rect visual_confirm_rect;
180 struct vpe_rect *visual_confirm_gaps;
181 struct vpe_rect *current_gap;
182
183 uint16_t total_seg_cnt =
184 vpe_get_visual_confirm_total_seg_count(vpe_priv, max_seg_width, params);
185 uint16_t seg_cnt = 0;
186
187 if (!total_seg_cnt)
188 return VPE_STATUS_OK;
189
190 visual_confirm_gaps = vpe_zalloc(sizeof(struct vpe_rect) * total_seg_cnt);
191 if (!visual_confirm_gaps)
192 return VPE_STATUS_NO_MEMORY;
193
194 current_gap = visual_confirm_gaps;
195
196 // Do visual confirm bg generation for intput format
197 if (vpe_priv->init.debug.visual_confirm_params.input_format &&
198 params->target_rect.height > 2 * VISUAL_CONFIRM_HEIGHT) {
199 for (stream_idx = 0; stream_idx < params->num_streams; stream_idx++) {
200 stream_ctx = &vpe_priv->stream_ctx[stream_idx];
201 visual_confirm_rect = stream_ctx->stream.scaling_info.dst_rect;
202 visual_confirm_rect.y += 0;
203 visual_confirm_rect.height = VISUAL_CONFIRM_HEIGHT;
204 seg_cnt = get_visual_confirm_segs_count(
205 max_seg_width, stream_ctx->stream.scaling_info.dst_rect.width);
206 vpe_full_bg_gaps(current_gap, &visual_confirm_rect, seg_cnt);
207 vpe_priv->resource.create_bg_segments(
208 vpe_priv, current_gap, seg_cnt, VPE_CMD_OPS_BG_VSCF_INPUT);
209 current_gap += seg_cnt;
210 }
211 }
212 // Do visual confirm bg generation for output format
213 if (vpe_priv->init.debug.visual_confirm_params.output_format &&
214 params->target_rect.height > VISUAL_CONFIRM_HEIGHT) {
215 visual_confirm_rect = params->target_rect;
216 visual_confirm_rect.y += VISUAL_CONFIRM_HEIGHT;
217 visual_confirm_rect.height = VISUAL_CONFIRM_HEIGHT;
218 seg_cnt = get_visual_confirm_segs_count(max_seg_width, params->target_rect.width);
219 vpe_full_bg_gaps(current_gap, &visual_confirm_rect, seg_cnt);
220 vpe_priv->resource.create_bg_segments(
221 vpe_priv, current_gap, seg_cnt, VPE_CMD_OPS_BG_VSCF_OUTPUT);
222 current_gap += seg_cnt;
223 }
224
225 if (visual_confirm_gaps != NULL) {
226 vpe_free(visual_confirm_gaps);
227 visual_confirm_gaps = NULL;
228 current_gap = NULL;
229 }
230
231 return VPE_STATUS_OK;
232 }
233