1 /*
2 * Copyright (C) 2010-2019 ARM Limited. All rights reserved.
3 *
4 * Copyright (C) 2008 The Android Open Source Project
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 #ifndef GRALLOC_HELPER_H_
20 #define GRALLOC_HELPER_H_
21
22 #include <unistd.h>
23 #include <sys/mman.h>
24 #include <android/log.h>
25
26 #include "VendorVideoAPI.h"
27
28 #if __has_include(<video/mfc_macros.h>)
29 #include <video/mfc_macros.h>
30 #else
31 #include "local_mfc_macros.h"
32 #endif
33
34 #ifndef AWAR
35 #define AWAR(fmt, args...) \
36 __android_log_print(ANDROID_LOG_WARN, "[Gralloc-Warning]", "%s:%d " fmt, __func__, __LINE__, ##args)
37 #endif
38 #ifndef AINF
39 #define AINF(fmt, args...) __android_log_print(ANDROID_LOG_INFO, "[Gralloc]", fmt, ##args)
40 #endif
41 #ifndef AERR
42 #define AERR(fmt, args...) \
43 __android_log_print(ANDROID_LOG_ERROR, "[Gralloc-ERROR]", "%s:%d " fmt, __func__, __LINE__, ##args)
44 #endif
45 #ifndef AERR_IF
46 #define AERR_IF(eq, fmt, args...) \
47 if ((eq)) \
48 AERR(fmt, args)
49 #endif
50
51 #define GRALLOC_ALIGN(value, base) ((((value) + (base) -1) / (base)) * (base))
52
53 #define GRALLOC_MAX(a, b) (((a)>(b))?(a):(b))
54
55 #define GRALLOC_UNUSED(x) ((void)x)
56
57 /* LSI integration */
58 #define GRALLOC1_USAGE_SW_WRITE_MASK 0x000000F0
59 #define GRALLOC1_USAGE_SW_READ_MASK 0x0000000F
60 #define GRALLOC1_USAGE_READ_OFTEN ((1ULL << 1) | (1ULL << 2))
61 #define GRALLOC1_USAGE_WRITE_OFTEN ((1ULL << 5) | (1ULL << 6))
62
63 #define VIDEO_PRIV_DATA_SIZE sizeof(ExynosVideoMeta)
64
65 #define PLANE_SIZE(w, h, ext_size) ((w) * (h) + ext_size)
66 // 10bit format
67 #define P010_PLANE_SIZE(w, h, ext_size) ((((w) * 2) * (h)) + ext_size)
68
69 // 8+2 format
70 #define NV12N_S8B_LUMA_SIZE(w, h, ext_size) PLANE_SIZE(w, h, ext_size)
71 #define NV12N_S8B_CHROMA_SIZE(w, h, ext_size) (GRALLOC_ALIGN(((w) * (h)) + ext_size, 16))
72 #define NV12N_S2B_SIZE(w, h) ((GRALLOC_ALIGN((w) / 4, 16) * (h)) + 64)
73 #define NV12M_S8B_SIZE(w, h, ext_size) PLANE_SIZE(w, h, ext_size)
74
75 #ifdef GRALLOC_MSCL_ALIGN_RESTRICTION
76 #define NV12M_S2B_LUMA_SIZE(w, h, ext_size) ((GRALLOC_ALIGN((w) / 4, 16) * (GRALLOC_ALIGN(h, 16))) + ext_size)
77 #define NV12M_S2B_CHROMA_SIZE(w, h, ext_size) ((GRALLOC_ALIGN((w) / 4, 16) * (GRALLOC_ALIGN(h, 16) / 2)) + ext_size)
78 #else
79 #define NV12M_S2B_LUMA_SIZE(w, h, ext_size) ((GRALLOC_ALIGN((w) / 4, 16) * (h)) + ext_size)
80 #define NV12M_S2B_CHROMA_SIZE(w, h, ext_size) ((GRALLOC_ALIGN((w) / 4, 16) * (h / 2)) + ext_size)
81 #endif
82
83 // MSCL
84 #define MSCL_ALIGN 128
85
86 #ifdef GRALLOC_MSCL_ALIGN_RESTRICTION
87 #define MSCL_EXT_SIZE 512
88 #else
89 #define MSCL_EXT_SIZE 0
90 #endif
91
92 #ifdef GRALLOC_MSCL_ALLOC_RESTRICTION
93 #define SIZE_4K 4096
94 #else
95 #define SIZE_4K 0
96 #endif
97
round_up_to_page_size(size_t x)98 static inline size_t round_up_to_page_size(size_t x)
99 {
100 return (x + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
101 }
102
103 #endif /* GRALLOC_HELPER_H_ */
104