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 "vpe10_background.h"
26 #include "common.h"
27 #include "vpe_priv.h"
28
vpe10_split_bg_gap(struct vpe_rect * gaps,const struct vpe_rect * target_rect,uint32_t max_width,uint16_t max_gaps,uint16_t * num_gaps,uint16_t num_multiple)29 bool vpe10_split_bg_gap(struct vpe_rect *gaps, const struct vpe_rect *target_rect,
30 uint32_t max_width, uint16_t max_gaps, uint16_t *num_gaps, uint16_t num_multiple)
31 {
32 uint16_t gap_cnt, gap_idx, num_gaps_t;
33 uint16_t prev_idx = *num_gaps - 1;
34 uint32_t gap_width, gap_height;
35 int32_t gap_x, gap_y;
36
37 // -1 is for removing the previous "going-to-be" splitted segment
38 num_gaps_t = *num_gaps - 1;
39 gap_x = gaps[prev_idx].x;
40 gap_y = gaps[prev_idx].y;
41 gap_width = gaps[prev_idx].width;
42 gap_height = gaps[prev_idx].height;
43
44 gap_cnt = (uint16_t)((gap_width + max_width - 1) / max_width);
45
46 if (gap_cnt % num_multiple != 0) {
47 gap_cnt += (num_multiple - (gap_cnt % num_multiple));
48 max_width = (uint16_t)((gap_width + gap_cnt - 1) / gap_cnt);
49 }
50
51 if (num_gaps_t + gap_cnt > max_gaps)
52 return false;
53
54 for (gap_idx = prev_idx; gap_idx < num_gaps_t + gap_cnt; gap_idx++) {
55 gaps[gap_idx].y = gap_y;
56 gaps[gap_idx].height = gap_height;
57 gaps[gap_idx].x = gap_x;
58 gaps[gap_idx].width = gap_width < max_width ? gap_width : max_width;
59
60 gap_x = gap_x + (int32_t)gaps[gap_idx].width;
61 gap_width = gap_width - gaps[gap_idx].width;
62 }
63
64 *num_gaps = num_gaps_t + gap_cnt;
65 return true;
66 }
67