blob: 6dd1597379f18bc6c8c8e91686a078ebd91ca61a [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;
36
Rebecca Schultz Zavina8b0b072012-06-26 12:50:15 -070037struct private_module_t {
Dima Zavin6198e542012-02-29 17:02:46 -080038 gralloc_module_t base;
39
Greg Hackmann8c372e32013-01-15 09:29:40 -080040 struct private_handle_t* framebuffer;
Rebecca Schultz Zavina8b0b072012-06-26 12:50:15 -070041 uint32_t flags;
42 uint32_t numBuffers;
43 uint32_t bufferMask;
Dima Zavin6198e542012-02-29 17:02:46 -080044 pthread_mutex_t lock;
Rebecca Schultz Zavina8b0b072012-06-26 12:50:15 -070045 buffer_handle_t currentBuffer;
46 int ionfd;
Dima Zavin6198e542012-02-29 17:02:46 -080047
Greg Hackmannd37bc2b2012-05-23 16:29:43 -070048 int xres;
49 int yres;
50 int line_length;
Dima Zavin6198e542012-02-29 17:02:46 -080051 float xdpi;
52 float ydpi;
53 float fps;
Greg Hackmanndd557382012-05-03 14:51:28 -070054 void *queue;
55 pthread_mutex_t queue_lock;
Dima Zavin6198e542012-02-29 17:02:46 -080056
Dima Zavin6198e542012-02-29 17:02:46 -080057};
58
Rebecca Schultz Zavina8b0b072012-06-26 12:50:15 -070059/*****************************************************************************/
60
Dima Zavin6198e542012-02-29 17:02:46 -080061#ifdef __cplusplus
Rebecca Schultz Zavina8b0b072012-06-26 12:50:15 -070062struct private_handle_t : public native_handle {
Dima Zavin6198e542012-02-29 17:02:46 -080063#else
Rebecca Schultz Zavina8b0b072012-06-26 12:50:15 -070064struct private_handle_t {
Dima Zavin6198e542012-02-29 17:02:46 -080065 struct native_handle nativeHandle;
66#endif
67
68 enum {
69 PRIV_FLAGS_FRAMEBUFFER = 0x00000001,
70 PRIV_FLAGS_USES_UMP = 0x00000002,
Erik Gilling80b3e6c2012-04-05 15:34:47 -070071 PRIV_FLAGS_USES_ION = 0x00000020
Dima Zavin6198e542012-02-29 17:02:46 -080072 };
73
Rebecca Schultz Zavina8b0b072012-06-26 12:50:15 -070074 // file-descriptors
Dima Zavin6198e542012-02-29 17:02:46 -080075 int fd;
Rebecca Schultz Zavina8b0b072012-06-26 12:50:15 -070076 int fd1;
77 int fd2;
78 // ints
Dima Zavin6198e542012-02-29 17:02:46 -080079 int magic;
80 int flags;
81 int size;
Dima Zavin6198e542012-02-29 17:02:46 -080082 int offset;
Dima Zavin6198e542012-02-29 17:02:46 -080083
84 int format;
Dima Zavin6198e542012-02-29 17:02:46 -080085 int width;
86 int height;
Dima Zavin6198e542012-02-29 17:02:46 -080087 int stride;
Rebecca Schultz Zavin70212e52012-08-15 11:17:04 -070088 int vstride;
Alex Rayb528b802013-01-30 21:19:59 -080089 int gamut;
Alex Rayd09ee482013-03-05 12:47:50 -080090 int chroma;
Dima Zavin6198e542012-02-29 17:02:46 -080091
Rebecca Schultz Zavina8b0b072012-06-26 12:50:15 -070092 // FIXME: the attributes below should be out-of-line
93 void *base;
Rebecca Schultz Zavinec68ab22012-08-27 10:58:52 -070094 void *base1;
95 void *base2;
96 struct ion_handle *handle;
97 struct ion_handle *handle1;
98 struct ion_handle *handle2;
Dima Zavin6198e542012-02-29 17:02:46 -080099
100#ifdef __cplusplus
Rebecca Schultz Zavin471812b2012-05-15 16:49:56 -0700101 static const int sNumFds = 3;
Alex Rayd09ee482013-03-05 12:47:50 -0800102 static const int sNumInts = 17;
Dima Zavin6198e542012-02-29 17:02:46 -0800103 static const int sMagic = 0x3141592;
Dima Zavin06062cd2012-04-03 00:10:57 -0700104
Rebecca Schultz Zavina8b0b072012-06-26 12:50:15 -0700105
106 private_handle_t(int fd, int size, int flags, int w,
Rebecca Schultz Zavin70212e52012-08-15 11:17:04 -0700107 int h, int format, int stride, int vstride) :
Rebecca Schultz Zavinec68ab22012-08-27 10:58:52 -0700108 fd(fd), fd1(-1), fd2(-1), magic(sMagic), flags(flags), size(size),
Rebecca Schultz Zavin70212e52012-08-15 11:17:04 -0700109 offset(0), format(format), width(w), height(h), stride(stride),
Alex Rayd09ee482013-03-05 12:47:50 -0800110 vstride(vstride), gamut(0), chroma(0), base(0), handle(0), handle1(0),
111 handle2(0)
Dima Zavin6198e542012-02-29 17:02:46 -0800112 {
113 version = sizeof(native_handle);
Rebecca Schultz Zavinec68ab22012-08-27 10:58:52 -0700114 numInts = sNumInts + 2;
115 numFds = sNumFds - 2;
116 }
117
118 private_handle_t(int fd, int fd1, int size, int flags, int w,
119 int h, int format, int stride, int vstride) :
120 fd(fd), fd1(fd1), fd2(-1), magic(sMagic), flags(flags), size(size),
121 offset(0), format(format), width(w), height(h), stride(stride),
Alex Rayd09ee482013-03-05 12:47:50 -0800122 vstride(vstride), gamut(0), chroma(0), base(0), base1(0), base2(0),
123 handle(0), handle1(0), handle2(0)
Rebecca Schultz Zavinec68ab22012-08-27 10:58:52 -0700124 {
125 version = sizeof(native_handle);
126 numInts = sNumInts + 1;
127 numFds = sNumFds - 1;
Dima Zavin6198e542012-02-29 17:02:46 -0800128 }
129
Rebecca Schultz Zavina8b0b072012-06-26 12:50:15 -0700130 private_handle_t(int fd, int fd1, int fd2, int size, int flags, int w,
Rebecca Schultz Zavin70212e52012-08-15 11:17:04 -0700131 int h, int format, int stride, int vstride) :
Rebecca Schultz Zavina8b0b072012-06-26 12:50:15 -0700132 fd(fd), fd1(fd1), fd2(fd2), magic(sMagic), flags(flags), size(size),
Rebecca Schultz Zavin70212e52012-08-15 11:17:04 -0700133 offset(0), format(format), width(w), height(h), stride(stride),
Alex Rayd09ee482013-03-05 12:47:50 -0800134 vstride(vstride), gamut(0), chroma(0), base(0), base1(0), base2(0),
135 handle(0), handle1(0), handle2(0)
Dima Zavin6198e542012-02-29 17:02:46 -0800136 {
137 version = sizeof(native_handle);
Dima Zavin6198e542012-02-29 17:02:46 -0800138 numInts = sNumInts;
Rebecca Schultz Zavina8b0b072012-06-26 12:50:15 -0700139 numFds = sNumFds;
Dima Zavin6198e542012-02-29 17:02:46 -0800140 }
Rebecca Schultz Zavina8b0b072012-06-26 12:50:15 -0700141 ~private_handle_t() {
Dima Zavin6198e542012-02-29 17:02:46 -0800142 magic = 0;
143 }
144
Rebecca Schultz Zavina8b0b072012-06-26 12:50:15 -0700145 static int validate(const native_handle* h) {
Dima Zavin6198e542012-02-29 17:02:46 -0800146 const private_handle_t* hnd = (const private_handle_t*)h;
Dima Zavin6198e542012-02-29 17:02:46 -0800147 if (!h || h->version != sizeof(native_handle) ||
Rebecca Schultz Zavinec68ab22012-08-27 10:58:52 -0700148 hnd->numInts + hnd->numFds != sNumInts + sNumFds ||
149 hnd->magic != sMagic)
Rebecca Schultz Zavina8b0b072012-06-26 12:50:15 -0700150 {
151 ALOGE("invalid gralloc handle (at %p)", reinterpret_cast<void *>(const_cast<native_handle *>(h)));
Dima Zavin6198e542012-02-29 17:02:46 -0800152 return -EINVAL;
Rebecca Schultz Zavina8b0b072012-06-26 12:50:15 -0700153 }
Dima Zavin6198e542012-02-29 17:02:46 -0800154 return 0;
155 }
156
157 static private_handle_t* dynamicCast(const native_handle* in)
158 {
159 if (validate(in) == 0)
160 return (private_handle_t*) in;
161
162 return NULL;
163 }
Rebecca Schultz Zavina8b0b072012-06-26 12:50:15 -0700164
Dima Zavin6198e542012-02-29 17:02:46 -0800165#endif
166};
167
168#endif /* GRALLOC_PRIV_H_ */