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