• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "vpe_priv.h"
27 
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)28 bool vpe10_split_bg_gap(struct vpe_rect *gaps, const struct vpe_rect *target_rect,
29     uint32_t max_width, uint16_t max_gaps, uint16_t *num_gaps, uint16_t num_multiple)
30 {
31     uint16_t gap_cnt, gap_idx, num_gaps_t;
32     uint16_t prev_idx = *num_gaps - 1;
33     uint32_t gap_width, gap_height;
34     int32_t  gap_x, gap_y;
35 
36     // -1 is for removing the previous "going-to-be" splitted segment
37     num_gaps_t = *num_gaps - 1;
38     gap_x      = gaps[prev_idx].x;
39     gap_y      = gaps[prev_idx].y;
40     gap_width  = gaps[prev_idx].width;
41     gap_height = gaps[prev_idx].height;
42 
43     gap_cnt = (uint16_t)((gap_width + max_width - 1) / max_width);
44 
45     if (gap_cnt % num_multiple != 0) {
46         gap_cnt += (num_multiple - (gap_cnt % num_multiple));
47         max_width = (uint16_t)((gap_width + gap_cnt - 1) / gap_cnt);
48     }
49 
50     // if gap width, after calculation < VPE_MIN_VIEWPORT_SIZE, don't further split
51     // need return true, not false, to prevent go to full BG flow
52     if ((gap_width < VPE_MIN_VIEWPORT_SIZE) || (max_width < VPE_MIN_VIEWPORT_SIZE))
53         return true;
54 
55     if (num_gaps_t + gap_cnt > max_gaps)
56         return false;
57 
58     for (gap_idx = prev_idx; gap_idx < num_gaps_t + gap_cnt; gap_idx++) {
59         gaps[gap_idx].y      = gap_y;
60         gaps[gap_idx].height = gap_height;
61         gaps[gap_idx].x      = gap_x;
62         gaps[gap_idx].width  = gap_width < max_width ? gap_width : max_width;
63 
64         gap_x     = gap_x + (int32_t)gaps[gap_idx].width;
65         gap_width = gap_width - gaps[gap_idx].width;
66     }
67 
68     *num_gaps = num_gaps_t + gap_cnt;
69     return true;
70 }
71