1 /*
2 * Copyright Samsung Electronics Co.,LTD.
3 * Copyright (C) 2016 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 #ifndef __HARDWARE_EXYNOS_ACRYLIC_INTERNAL_H__
19 #define __HARDWARE_EXYNOS_ACRYLIC_INTERNAL_H__
20
21 #include <cerrno>
22 #include <cstring>
23
24 #include <hardware/exynos/acryl.h>
25
26 #ifndef ALOGERR
27 #define ALOGERR(fmt, args...) ((void)ALOG(LOG_ERROR, LOG_TAG, fmt " [%s]", ##args, strerror(errno)))
28 #endif
29
30 #ifdef LOG_NDEBUG
31 #define LOGASSERT ALOG_ASSERT
32 #else
33 #define LOGASSERT(cond, ...) if (!(cond)) ALOGE(__VA_ARGS__)
34 #endif
35
36 #ifdef LIBACRYL_DEBUG
37 #define ALOGD_TEST(args...) ALOGD("TEST: " args)
38 #else
39 #define ALOGD_TEST(...)
40 #endif
41
42 #define ARRSIZE(arr) (sizeof(arr) / sizeof(arr[0]))
43
get_width(hwc_rect_t & rect)44 static inline int32_t get_width(hwc_rect_t &rect)
45 {
46 return rect.right - rect.left;
47 }
48
get_height(hwc_rect_t & rect)49 static inline int32_t get_height(hwc_rect_t &rect)
50 {
51 return rect.bottom - rect.top;
52 }
53
54 static inline bool operator==(hw2d_coord_t xy1, hw2d_coord_t xy2)
55 {
56 return (xy1.hori == xy2.hori) && (xy1.vert == xy2.vert);
57 }
58
59 static inline bool operator!=(hw2d_coord_t xy1, hw2d_coord_t xy2)
60 {
61 return !(xy1 == xy2);
62 }
63
64 static inline bool operator==(hw2d_rect_t r1, hw2d_rect_t r2)
65 {
66 return (r1.pos == r2.pos) && (r1.size == r2.size);
67 }
68
69 static inline bool operator!=(hw2d_rect_t r1, hw2d_rect_t r2)
70 {
71 return !(r1 == r2);
72 }
73
74 static inline bool operator==(hw2d_rect_t r1, hwc_rect_t r2)
75 {
76 return (r1.pos.hori == r2.left) && (r1.pos.vert == r2.top) &&
77 ((r1.pos.hori + r1.size.hori) == r2.right) &&
78 ((r1.pos.vert + r1.size.vert) == r2.bottom);
79
80 }
81
82 static inline bool operator==(hwc_rect_t r1, hw2d_rect_t r2)
83 {
84 return operator==(r2, r1);
85 }
86
87 static inline bool operator!=(hw2d_rect_t r1, hwc_rect_t r2)
88 {
89 return !(r1 == r2);
90 }
91
92 static inline bool operator!=(hwc_rect_t r1, hw2d_rect_t r2)
93 {
94 return !(r2 == r1);
95 }
96
97 static inline bool operator>(hw2d_rect_t rect, hw2d_coord_t xy)
98 {
99 int32_t len = static_cast<int32_t>(rect.pos.hori) + rect.size.hori;
100 if (len > xy.hori)
101 return true;
102
103 len = static_cast<int32_t>(rect.pos.vert) + rect.size.vert;
104 if (len > xy.vert)
105 return true;
106
107 return false;
108 }
109
area_is_zero(hw2d_rect_t rect)110 static inline bool area_is_zero(hw2d_rect_t rect)
111 {
112 return (rect.size.hori == 0) && (rect.size.vert == 0);
113 }
114
115 uint32_t halfmt_to_v4l2(uint32_t halfmt);
116 uint32_t halfmt_to_v4l2_deprecated(uint32_t halfmt);
117 unsigned int halfmt_buf_count(uint32_t fmt);
118 size_t halfmt_plane_length(uint32_t fmt, unsigned int plane, uint32_t width, uint32_t height);
119 uint32_t haldataspace_to_v4l2(int dataspace, uint32_t width, uint32_t height);
120 uint32_t find_format_equivalent(uint32_t fmt);
121 uint8_t halfmt_chroma_subsampling(uint32_t fmt);
122 unsigned int halfmt_bpp(uint32_t fmt);
123 uint8_t halfmt_plane_count(uint32_t fmt);
124
125 #endif /* __HARDWARE_EXYNOS_ACRYLIC_INTERNAL_H__ */
126