1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <cstring>
18 
19 #include <log/log.h>
20 
21 #include <exynos_format.h> // hardware/smasung_slsi/exynos/include
22 #include <mali_gralloc_formats.h>
23 
24 static uint32_t all_fimg2d_gs201_formats[] = {
25     HAL_PIXEL_FORMAT_RGBA_8888,
26     HAL_PIXEL_FORMAT_BGRA_8888,
27     HAL_PIXEL_FORMAT_RGBA_1010102,
28     HAL_PIXEL_FORMAT_RGBX_8888,
29     HAL_PIXEL_FORMAT_RGB_888,
30     HAL_PIXEL_FORMAT_RGB_565,
31     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_P,
32     HAL_PIXEL_FORMAT_YCrCb_420_SP,                  // NV21 (YVU420 semi-planar)
33     HAL_PIXEL_FORMAT_EXYNOS_YCrCb_420_SP_M,         // NV21 on multi-buffer
34     HAL_PIXEL_FORMAT_EXYNOS_YCrCb_420_SP_M_FULL,    // NV21 on multi-buffer
35     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP,           // NV12 (YUV420 semi-planar)
36     HAL_PIXEL_FORMAT_GOOGLE_NV12_SP,                // NV12 (YUV420 semi-planar)
37     MALI_GRALLOC_FORMAT_INTERNAL_YUV420_8BIT_I,     // NV12 AFBC
38     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN,          // NV12 with MFC alignment constraints
39     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M,
40     // NV12M with MFC alignment constraints on multi-buffer
41     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_PRIV,
42     // NV12M with MFC alignment constraints on multi-buffer
43     HAL_PIXEL_FORMAT_YCbCr_422_SP,                  // YUV422 2P (YUV422 semi-planar)
44     HAL_PIXEL_FORMAT_YCBCR_P010,
45     HAL_PIXEL_FORMAT_GOOGLE_NV12_SP_10B,
46     MALI_GRALLOC_FORMAT_INTERNAL_YUV420_10BIT_I,
47     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_P010_SPN,
48     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_P010_M,
49     MALI_GRALLOC_FORMAT_INTERNAL_P010,
50     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_SBWC,
51     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_SBWC,
52     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_10B_SBWC,
53     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_10B_SBWC,
54     HAL_PIXEL_FORMAT_EXYNOS_YCrCb_420_SP_M_SBWC,
55     HAL_PIXEL_FORMAT_EXYNOS_YCrCb_420_SP_M_10B_SBWC,
56     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_SBWC_L50,
57     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_SBWC_L75,
58     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_SBWC_L50,
59     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_SBWC_L75,
60     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_10B_SBWC_L40,
61     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_10B_SBWC_L60,
62     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_10B_SBWC_L80,
63     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_10B_SBWC_L40,
64     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_10B_SBWC_L60,
65     HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_10B_SBWC_L80,
66 };
67 
68 static int all_hwc_gs201_dataspaces[] = {
69     HAL_DATASPACE_STANDARD_BT709,
70     HAL_DATASPACE_STANDARD_BT709 | HAL_DATASPACE_RANGE_FULL,
71     HAL_DATASPACE_STANDARD_BT709 | HAL_DATASPACE_RANGE_LIMITED,
72     HAL_DATASPACE_STANDARD_BT2020,
73     HAL_DATASPACE_STANDARD_BT2020 | HAL_DATASPACE_RANGE_FULL,
74     HAL_DATASPACE_STANDARD_BT2020 | HAL_DATASPACE_RANGE_LIMITED,
75     HAL_DATASPACE_STANDARD_BT601_625,
76     HAL_DATASPACE_STANDARD_BT601_625 | HAL_DATASPACE_RANGE_FULL,
77     HAL_DATASPACE_STANDARD_BT601_625 | HAL_DATASPACE_RANGE_LIMITED,
78     HAL_DATASPACE_STANDARD_BT601_525,
79     HAL_DATASPACE_STANDARD_BT601_525 | HAL_DATASPACE_RANGE_FULL,
80     HAL_DATASPACE_STANDARD_BT601_525 | HAL_DATASPACE_RANGE_LIMITED,
81     HAL_DATASPACE_STANDARD_BT601_625_UNADJUSTED,
82     HAL_DATASPACE_STANDARD_BT601_625_UNADJUSTED | HAL_DATASPACE_RANGE_FULL,
83     HAL_DATASPACE_STANDARD_BT601_625_UNADJUSTED | HAL_DATASPACE_RANGE_LIMITED,
84     HAL_DATASPACE_STANDARD_BT601_525_UNADJUSTED,
85     HAL_DATASPACE_STANDARD_BT601_525_UNADJUSTED | HAL_DATASPACE_RANGE_FULL,
86     HAL_DATASPACE_STANDARD_BT601_525_UNADJUSTED | HAL_DATASPACE_RANGE_LIMITED,
87     HAL_DATASPACE_STANDARD_DCI_P3,
88     HAL_DATASPACE_STANDARD_DCI_P3 | HAL_DATASPACE_RANGE_FULL,
89     HAL_DATASPACE_STANDARD_DCI_P3 | HAL_DATASPACE_RANGE_LIMITED,
90     HAL_DATASPACE_STANDARD_FILM,
91     HAL_DATASPACE_STANDARD_FILM | HAL_DATASPACE_RANGE_FULL,
92     HAL_DATASPACE_STANDARD_FILM | HAL_DATASPACE_RANGE_LIMITED,
93     // 0 should be treated as BT709 Limited range
94     0,
95     HAL_DATASPACE_RANGE_FULL,
96     HAL_DATASPACE_RANGE_LIMITED,
97     // Deprecated legacy dataspace definitions
98     HAL_DATASPACE_SRGB,
99     HAL_DATASPACE_JFIF,
100     HAL_DATASPACE_BT601_525,
101     HAL_DATASPACE_BT601_625,
102     HAL_DATASPACE_BT709,
103 };
104 
105 const static stHW2DCapability __capability_fimg2d_gs201 = {
106     .max_upsampling_num = {8, 8},
107     .max_downsampling_factor = {4, 4},
108     .max_upsizing_num = {8, 8},
109     .max_downsizing_factor = {4, 4},
110     .min_src_dimension = {1, 1},
111     .max_src_dimension = {8192, 8192},
112     .min_dst_dimension = {1, 1},
113     .max_dst_dimension = {8192, 8192},
114     .min_pix_align = {1, 1},
115     .rescaling_count = 0,
116     .compositing_mode = HW2DCapability::BLEND_NONE | HW2DCapability::BLEND_SRC_COPY
117                          | HW2DCapability::BLEND_SRC_OVER,
118     .transform_type = HW2DCapability::TRANSFORM_ALL,
119     .auxiliary_feature = HW2DCapability::FEATURE_PLANE_ALPHA | HW2DCapability::FEATURE_UORDER_WRITE
120                          | HW2DCapability::FEATURE_AFBC_ENCODE | HW2DCapability::FEATURE_AFBC_DECODE
121                          | HW2DCapability::FEATURE_SOLIDCOLOR,
122     .num_formats = ARRSIZE(all_fimg2d_gs201_formats),
123     .num_dataspaces = ARRSIZE(all_hwc_gs201_dataspaces),
124     .max_layers = 4,
125     .pixformats = all_fimg2d_gs201_formats,
126     .dataspaces = all_hwc_gs201_dataspaces,
127     .base_align = 1,
128 };
129 
130 static const HW2DCapability capability_fimg2d_gs201(__capability_fimg2d_gs201);
131 
createAcrylicCompositorG2D(const char * spec)132 inline Acrylic *createAcrylicCompositorG2D(const char *spec)
133 {
134     Acrylic *compositor = nullptr;
135 
136     if (strcmp(spec, "fimg2d_gs201") == 0) {
137         compositor = new AcrylicCompositorG2D(capability_fimg2d_gs201, /*halfmt_to_g2dfmt*/ true);
138     }
139     return compositor;
140 }
141