am f3dcf4a2: am e6a4b5d8: am a6302fad: libcamera2: new return code when camera in use
[GitHub/LineageOS/android_hardware_samsung_slsi_exynos5.git] / include / gralloc_priv.h
CommitLineData
6198e543 1/*
6198e543
DZ
2 * Copyright (C) 2008 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#ifndef GRALLOC_PRIV_H_
18#define GRALLOC_PRIV_H_
19
20#include <stdint.h>
a8b0b07d
RSZ
21#include <limits.h>
22#include <sys/cdefs.h>
23#include <hardware/gralloc.h>
6198e543
DZ
24#include <pthread.h>
25#include <errno.h>
a8b0b07d 26#include <unistd.h>
6198e543 27
6198e543
DZ
28#include <cutils/native_handle.h>
29
a8b0b07d 30#include <linux/fb.h>
6198e543 31
a8b0b07d 32/*****************************************************************************/
6198e543 33
a8b0b07d 34struct private_module_t;
6198e543 35struct private_handle_t;
98aa5b4b 36typedef int ion_user_handle_t;
6198e543 37
a8b0b07d 38struct private_module_t {
6198e543
DZ
39 gralloc_module_t base;
40
8c372e39 41 struct private_handle_t* framebuffer;
a8b0b07d
RSZ
42 uint32_t flags;
43 uint32_t numBuffers;
44 uint32_t bufferMask;
6198e543 45 pthread_mutex_t lock;
a8b0b07d
RSZ
46 buffer_handle_t currentBuffer;
47 int ionfd;
6198e543 48
d37bc2b2
GH
49 int xres;
50 int yres;
51 int line_length;
6198e543
DZ
52 float xdpi;
53 float ydpi;
54 float fps;
dd557381
GH
55 void *queue;
56 pthread_mutex_t queue_lock;
6198e543 57
6198e543
DZ
58};
59
a8b0b07d
RSZ
60/*****************************************************************************/
61
6198e543 62#ifdef __cplusplus
a8b0b07d 63struct private_handle_t : public native_handle {
6198e543 64#else
a8b0b07d 65struct private_handle_t {
6198e543
DZ
66 struct native_handle nativeHandle;
67#endif
68
06f1fa77
AR
69// set if using video encoding colorspace
70#define GRALLOC_USAGE_PRIVATE_CHROMA (GRALLOC_USAGE_PRIVATE_0)
71
6198e543
DZ
72 enum {
73 PRIV_FLAGS_FRAMEBUFFER = 0x00000001,
74 PRIV_FLAGS_USES_UMP = 0x00000002,
80b3e6c2 75 PRIV_FLAGS_USES_ION = 0x00000020
6198e543
DZ
76 };
77
a8b0b07d 78 // file-descriptors
6198e543 79 int fd;
a8b0b07d
RSZ
80 int fd1;
81 int fd2;
82 // ints
6198e543
DZ
83 int magic;
84 int flags;
85 int size;
6198e543 86 int offset;
6198e543
DZ
87
88 int format;
6198e543
DZ
89 int width;
90 int height;
6198e543 91 int stride;
70212e56 92 int vstride;
b528b809 93 int gamut;
d09ee48e 94 int chroma;
6198e543 95
a8b0b07d
RSZ
96 // FIXME: the attributes below should be out-of-line
97 void *base;
ec68ab21
RSZ
98 void *base1;
99 void *base2;
98aa5b4b
RL
100 ion_user_handle_t handle;
101 ion_user_handle_t handle1;
102 ion_user_handle_t handle2;
6198e543
DZ
103
104#ifdef __cplusplus
471812b7 105 static const int sNumFds = 3;
d09ee48e 106 static const int sNumInts = 17;
6198e543 107 static const int sMagic = 0x3141592;
06062cd9 108
a8b0b07d
RSZ
109
110 private_handle_t(int fd, int size, int flags, int w,
70212e56 111 int h, int format, int stride, int vstride) :
ec68ab21 112 fd(fd), fd1(-1), fd2(-1), magic(sMagic), flags(flags), size(size),
70212e56 113 offset(0), format(format), width(w), height(h), stride(stride),
d09ee48e
AR
114 vstride(vstride), gamut(0), chroma(0), base(0), handle(0), handle1(0),
115 handle2(0)
6198e543
DZ
116 {
117 version = sizeof(native_handle);
ec68ab21
RSZ
118 numInts = sNumInts + 2;
119 numFds = sNumFds - 2;
120 }
121
122 private_handle_t(int fd, int fd1, int size, int flags, int w,
123 int h, int format, int stride, int vstride) :
124 fd(fd), fd1(fd1), fd2(-1), magic(sMagic), flags(flags), size(size),
125 offset(0), format(format), width(w), height(h), stride(stride),
d09ee48e
AR
126 vstride(vstride), gamut(0), chroma(0), base(0), base1(0), base2(0),
127 handle(0), handle1(0), handle2(0)
ec68ab21
RSZ
128 {
129 version = sizeof(native_handle);
130 numInts = sNumInts + 1;
131 numFds = sNumFds - 1;
6198e543
DZ
132 }
133
a8b0b07d 134 private_handle_t(int fd, int fd1, int fd2, int size, int flags, int w,
70212e56 135 int h, int format, int stride, int vstride) :
a8b0b07d 136 fd(fd), fd1(fd1), fd2(fd2), magic(sMagic), flags(flags), size(size),
70212e56 137 offset(0), format(format), width(w), height(h), stride(stride),
d09ee48e
AR
138 vstride(vstride), gamut(0), chroma(0), base(0), base1(0), base2(0),
139 handle(0), handle1(0), handle2(0)
6198e543
DZ
140 {
141 version = sizeof(native_handle);
6198e543 142 numInts = sNumInts;
a8b0b07d 143 numFds = sNumFds;
6198e543 144 }
a8b0b07d 145 ~private_handle_t() {
6198e543
DZ
146 magic = 0;
147 }
148
a8b0b07d 149 static int validate(const native_handle* h) {
6198e543 150 const private_handle_t* hnd = (const private_handle_t*)h;
6198e543 151 if (!h || h->version != sizeof(native_handle) ||
ec68ab21
RSZ
152 hnd->numInts + hnd->numFds != sNumInts + sNumFds ||
153 hnd->magic != sMagic)
a8b0b07d
RSZ
154 {
155 ALOGE("invalid gralloc handle (at %p)", reinterpret_cast<void *>(const_cast<native_handle *>(h)));
6198e543 156 return -EINVAL;
a8b0b07d 157 }
6198e543
DZ
158 return 0;
159 }
160
161 static private_handle_t* dynamicCast(const native_handle* in)
162 {
163 if (validate(in) == 0)
164 return (private_handle_t*) in;
165
166 return NULL;
167 }
a8b0b07d 168
6198e543
DZ
169#endif
170};
171
172#endif /* GRALLOC_PRIV_H_ */