xref: /OK3568_Linux_fs/external/linux-rga/core/utils/utils.cpp (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Copyright (C) 2022 Rockchip Electronics Co., Ltd.
3  * Authors:
4  *  Cerf Yu <cerf.yu@rock-chips.com>
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #include "rga.h"
20 #include "utils.h"
21 
get_compatible_format(int format)22 static int get_compatible_format(int format) {
23 #if LINUX
24     if (format == 0)
25         return format;
26 
27     if ((format >> 8) != 0) {
28         return format;
29     } else {
30         return format << 8;
31     }
32 #endif
33     return format;
34 }
35 
convert_to_rga_format(int ex_format)36 int convert_to_rga_format(int ex_format) {
37     if (is_drm_fourcc(ex_format))
38         return get_format_from_drm_fourcc(ex_format);
39 
40     ex_format = get_compatible_format(ex_format);
41     if (is_android_hal_format(ex_format))
42         return get_format_from_android_hal(ex_format);
43     else if (is_rga_format(ex_format))
44         return ex_format;
45 
46     return RK_FORMAT_UNKNOWN;
47 }
48