blob: 416101c934571062f927d18b4e267a9a293b2421 [file] [log] [blame]
Dima Zavin6198e542012-02-29 17:02:46 -08001/*
Dima Zavin6198e542012-02-29 17:02:46 -08002 * 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>
Rebecca Schultz Zavina8b0b072012-06-26 12:50:15 -070021#include <limits.h>
22#include <sys/cdefs.h>
23#include <hardware/gralloc.h>
Dima Zavin6198e542012-02-29 17:02:46 -080024#include <pthread.h>
25#include <errno.h>
Rebecca Schultz Zavina8b0b072012-06-26 12:50:15 -070026#include <unistd.h>
Dima Zavin6198e542012-02-29 17:02:46 -080027
Dima Zavin6198e542012-02-29 17:02:46 -080028#include <cutils/native_handle.h>
29
Rebecca Schultz Zavina8b0b072012-06-26 12:50:15 -070030#include <linux/fb.h>
Dima Zavin6198e542012-02-29 17:02:46 -080031
Rebecca Schultz Zavina8b0b072012-06-26 12:50:15 -070032/*****************************************************************************/
Dima Zavina9301d12012-03-01 10:22:09 -080033
Rebecca Schultz Zavina8b0b072012-06-26 12:50:15 -070034struct private_module_t;
Dima Zavin6198e542012-02-29 17:02:46 -080035struct private_handle_t;
Rom Lemarchand98aa5b42013-10-24 11:22:55 -070036typedef int ion_user_handle_t;
Dima Zavin6198e542012-02-29 17:02:46 -080037
Rebecca Schultz Zavina8b0b072012-06-26 12:50:15 -070038struct private_module_t {
Dima Zavin6198e542012-02-29 17:02:46 -080039 gralloc_module_t base;
40
Greg Hackmann8c372e32013-01-15 09:29:40 -080041 struct private_handle_t* framebuffer;
Rebecca Schultz Zavina8b0b072012-06-26 12:50:15 -070042 uint32_t flags;
43 uint32_t numBuffers;
44 uint32_t bufferMask;
Dima Zavin6198e542012-02-29 17:02:46 -080045 pthread_mutex_t lock;
Greg Hackmann4d9f47b2014-04-02 11:52:10 -070046 unsigned int refcount;
Rebecca Schultz Zavina8b0b072012-06-26 12:50:15 -070047 buffer_handle_t currentBuffer;
48 int ionfd;
Dima Zavin6198e542012-02-29 17:02:46 -080049
Greg Hackmannd37bc2b2012-05-23 16:29:43 -070050 int xres;
51 int yres;
52 int line_length;
Dima Zavin6198e542012-02-29 17:02:46 -080053 float xdpi;
54 float ydpi;
55 float fps;
Greg Hackmanndd557382012-05-03 14:51:28 -070056 void *queue;
57 pthread_mutex_t queue_lock;
Dima Zavin6198e542012-02-29 17:02:46 -080058
Dima Zavin6198e542012-02-29 17:02:46 -080059};
60
Rebecca Schultz Zavina8b0b072012-06-26 12:50:15 -070061/*****************************************************************************/
62
Dima Zavin6198e542012-02-29 17:02:46 -080063#ifdef __cplusplus
Rebecca Schultz Zavina8b0b072012-06-26 12:50:15 -070064struct private_handle_t : public native_handle {
Dima Zavin6198e542012-02-29 17:02:46 -080065#else
Rebecca Schultz Zavina8b0b072012-06-26 12:50:15 -070066struct private_handle_t {
Dima Zavin6198e542012-02-29 17:02:46 -080067 struct native_handle nativeHandle;
68#endif
69
Alex Ray06f1fa72013-04-15 11:24:13 -070070// set if using video encoding colorspace
71#define GRALLOC_USAGE_PRIVATE_CHROMA (GRALLOC_USAGE_PRIVATE_0)
72
Dima Zavin6198e542012-02-29 17:02:46 -080073 enum {
74 PRIV_FLAGS_FRAMEBUFFER = 0x00000001,
75 PRIV_FLAGS_USES_UMP = 0x00000002,
Erik Gilling80b3e6c2012-04-05 15:34:47 -070076 PRIV_FLAGS_USES_ION = 0x00000020
Dima Zavin6198e542012-02-29 17:02:46 -080077 };
78
Rebecca Schultz Zavina8b0b072012-06-26 12:50:15 -070079 // file-descriptors
Dima Zavin6198e542012-02-29 17:02:46 -080080 int fd;
Rebecca Schultz Zavina8b0b072012-06-26 12:50:15 -070081 int fd1;
82 int fd2;
83 // ints
Dima Zavin6198e542012-02-29 17:02:46 -080084 int magic;
85 int flags;
86 int size;
Dima Zavin6198e542012-02-29 17:02:46 -080087 int offset;
Dima Zavin6198e542012-02-29 17:02:46 -080088
89 int format;
Dima Zavin6198e542012-02-29 17:02:46 -080090 int width;
91 int height;
Dima Zavin6198e542012-02-29 17:02:46 -080092 int stride;
Rebecca Schultz Zavin70212e52012-08-15 11:17:04 -070093 int vstride;
Alex Rayb528b802013-01-30 21:19:59 -080094 int gamut;
Alex Rayd09ee482013-03-05 12:47:50 -080095 int chroma;
Dima Zavin6198e542012-02-29 17:02:46 -080096
Rebecca Schultz Zavina8b0b072012-06-26 12:50:15 -070097 // FIXME: the attributes below should be out-of-line
98 void *base;
Rebecca Schultz Zavinec68ab22012-08-27 10:58:52 -070099 void *base1;
100 void *base2;
Rom Lemarchand98aa5b42013-10-24 11:22:55 -0700101 ion_user_handle_t handle;
102 ion_user_handle_t handle1;
103 ion_user_handle_t handle2;
Dima Zavin6198e542012-02-29 17:02:46 -0800104
105#ifdef __cplusplus
Rebecca Schultz Zavin471812b2012-05-15 16:49:56 -0700106 static const int sNumFds = 3;
Alex Rayd09ee482013-03-05 12:47:50 -0800107 static const int sNumInts = 17;
Dima Zavin6198e542012-02-29 17:02:46 -0800108 static const int sMagic = 0x3141592;
Dima Zavin06062cd2012-04-03 00:10:57 -0700109
Rebecca Schultz Zavina8b0b072012-06-26 12:50:15 -0700110
111 private_handle_t(int fd, int size, int flags, int w,
Rebecca Schultz Zavin70212e52012-08-15 11:17:04 -0700112 int h, int format, int stride, int vstride) :
Rebecca Schultz Zavinec68ab22012-08-27 10:58:52 -0700113 fd(fd), fd1(-1), fd2(-1), magic(sMagic), flags(flags), size(size),
Rebecca Schultz Zavin70212e52012-08-15 11:17:04 -0700114 offset(0), format(format), width(w), height(h), stride(stride),
Alex Rayd09ee482013-03-05 12:47:50 -0800115 vstride(vstride), gamut(0), chroma(0), base(0), handle(0), handle1(0),
116 handle2(0)
Dima Zavin6198e542012-02-29 17:02:46 -0800117 {
118 version = sizeof(native_handle);
Rebecca Schultz Zavinec68ab22012-08-27 10:58:52 -0700119 numInts = sNumInts + 2;
120 numFds = sNumFds - 2;
121 }
122
123 private_handle_t(int fd, int fd1, int size, int flags, int w,
124 int h, int format, int stride, int vstride) :
125 fd(fd), fd1(fd1), fd2(-1), magic(sMagic), flags(flags), size(size),
126 offset(0), format(format), width(w), height(h), stride(stride),
Alex Rayd09ee482013-03-05 12:47:50 -0800127 vstride(vstride), gamut(0), chroma(0), base(0), base1(0), base2(0),
128 handle(0), handle1(0), handle2(0)
Rebecca Schultz Zavinec68ab22012-08-27 10:58:52 -0700129 {
130 version = sizeof(native_handle);
131 numInts = sNumInts + 1;
132 numFds = sNumFds - 1;
Dima Zavin6198e542012-02-29 17:02:46 -0800133 }
134
Rebecca Schultz Zavina8b0b072012-06-26 12:50:15 -0700135 private_handle_t(int fd, int fd1, int fd2, int size, int flags, int w,
Rebecca Schultz Zavin70212e52012-08-15 11:17:04 -0700136 int h, int format, int stride, int vstride) :
Rebecca Schultz Zavina8b0b072012-06-26 12:50:15 -0700137 fd(fd), fd1(fd1), fd2(fd2), magic(sMagic), flags(flags), size(size),
Rebecca Schultz Zavin70212e52012-08-15 11:17:04 -0700138 offset(0), format(format), width(w), height(h), stride(stride),
Alex Rayd09ee482013-03-05 12:47:50 -0800139 vstride(vstride), gamut(0), chroma(0), base(0), base1(0), base2(0),
140 handle(0), handle1(0), handle2(0)
Dima Zavin6198e542012-02-29 17:02:46 -0800141 {
142 version = sizeof(native_handle);
Dima Zavin6198e542012-02-29 17:02:46 -0800143 numInts = sNumInts;
Rebecca Schultz Zavina8b0b072012-06-26 12:50:15 -0700144 numFds = sNumFds;
Dima Zavin6198e542012-02-29 17:02:46 -0800145 }
Rebecca Schultz Zavina8b0b072012-06-26 12:50:15 -0700146 ~private_handle_t() {
Dima Zavin6198e542012-02-29 17:02:46 -0800147 magic = 0;
148 }
149
Rebecca Schultz Zavina8b0b072012-06-26 12:50:15 -0700150 static int validate(const native_handle* h) {
Dima Zavin6198e542012-02-29 17:02:46 -0800151 const private_handle_t* hnd = (const private_handle_t*)h;
Dima Zavin6198e542012-02-29 17:02:46 -0800152 if (!h || h->version != sizeof(native_handle) ||
Rebecca Schultz Zavinec68ab22012-08-27 10:58:52 -0700153 hnd->numInts + hnd->numFds != sNumInts + sNumFds ||
154 hnd->magic != sMagic)
Rebecca Schultz Zavina8b0b072012-06-26 12:50:15 -0700155 {
156 ALOGE("invalid gralloc handle (at %p)", reinterpret_cast<void *>(const_cast<native_handle *>(h)));
Dima Zavin6198e542012-02-29 17:02:46 -0800157 return -EINVAL;
Rebecca Schultz Zavina8b0b072012-06-26 12:50:15 -0700158 }
Dima Zavin6198e542012-02-29 17:02:46 -0800159 return 0;
160 }
161
162 static private_handle_t* dynamicCast(const native_handle* in)
163 {
164 if (validate(in) == 0)
165 return (private_handle_t*) in;
166
167 return NULL;
168 }
Rebecca Schultz Zavina8b0b072012-06-26 12:50:15 -0700169
Dima Zavin6198e542012-02-29 17:02:46 -0800170#endif
171};
172
173#endif /* GRALLOC_PRIV_H_ */