summaryrefslogtreecommitdiff
path: root/libacryl/acrylic_internal.h
blob: faf052d6baee75ee5561f0e86af963cae1a245fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
 * Copyright Samsung Electronics Co.,LTD.
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef __HARDWARE_EXYNOS_ACRYLIC_INTERNAL_H__
#define __HARDWARE_EXYNOS_ACRYLIC_INTERNAL_H__

#include <cerrno>
#include <cstring>

#include <hardware/exynos/acryl.h>

#ifndef ALOGERR
#define ALOGERR(fmt, args...) ((void)ALOG(LOG_ERROR, LOG_TAG, fmt " [%s]", ##args, strerror(errno)))
#endif

#ifdef LOG_NDEBUG
#define LOGASSERT ALOG_ASSERT
#else
#define LOGASSERT(cond, ...)  if (!(cond)) ALOGE(__VA_ARGS__)
#endif

#ifdef LIBACRYL_DEBUG
#define ALOGD_TEST(args...) ALOGD("TEST: " args)
#else
#define ALOGD_TEST(...)
#endif

#define ARRSIZE(arr) (sizeof(arr) / sizeof(arr[0]))

static inline int32_t get_width(hwc_rect_t &rect)
{
    return rect.right - rect.left;
}

static inline int32_t get_height(hwc_rect_t &rect)
{
    return rect.bottom - rect.top;
}

static inline bool operator==(hw2d_coord_t xy1, hw2d_coord_t xy2)
{
    return (xy1.hori == xy2.hori) && (xy1.vert == xy2.vert);
}

static inline bool operator!=(hw2d_coord_t xy1, hw2d_coord_t xy2)
{
    return !(xy1 == xy2);
}

static inline bool operator==(hw2d_rect_t r1, hw2d_rect_t r2)
{
    return (r1.pos == r2.pos) && (r1.size == r2.size);
}

static inline bool operator!=(hw2d_rect_t r1, hw2d_rect_t r2)
{
    return !(r1 == r2);
}

static inline bool operator==(hw2d_rect_t r1, hwc_rect_t r2)
{
    return (r1.pos.hori == r2.left) && (r1.pos.vert == r2.top) &&
           ((r1.pos.hori + r1.size.hori) == r2.right) &&
           ((r1.pos.vert + r1.size.vert) == r2.bottom);

}

static inline bool operator==(hwc_rect_t r1, hw2d_rect_t r2)
{
    return operator==(r2, r1);
}

static inline bool operator!=(hw2d_rect_t r1, hwc_rect_t r2)
{
    return !(r1 == r2);
}

static inline bool operator!=(hwc_rect_t r1, hw2d_rect_t r2)
{
    return !(r2 == r1);
}

static inline bool operator>(hw2d_rect_t rect, hw2d_coord_t xy)
{
    int32_t len = static_cast<int32_t>(rect.pos.hori) + rect.size.hori;
    if (len > xy.hori)
        return true;

    len = static_cast<int32_t>(rect.pos.vert) + rect.size.vert;
    if (len > xy.vert)
        return true;

    return false;
}

static inline bool area_is_zero(hw2d_rect_t rect)
{
    return (rect.size.hori == 0) && (rect.size.vert == 0);
}

uint32_t halfmt_to_v4l2(uint32_t halfmt);
uint32_t halfmt_to_v4l2_deprecated(uint32_t halfmt);
unsigned int halfmt_buf_count(uint32_t fmt);
size_t halfmt_plane_length(uint32_t fmt, unsigned int plane, uint32_t width, uint32_t height);
uint32_t haldataspace_to_v4l2(int dataspace, uint32_t width, uint32_t height);
uint32_t find_format_equivalent(uint32_t fmt);
uint8_t halfmt_chroma_subsampling(uint32_t fmt);
unsigned int halfmt_bpp(uint32_t fmt);
uint8_t halfmt_plane_count(uint32_t fmt);

#endif /* __HARDWARE_EXYNOS_ACRYLIC_INTERNAL_H__ */