blob: 2a6fe9006946110aa788fc92e4cd47ab05bc6cd6 [file] [log] [blame]
Dima Zavin6198e542012-02-29 17:02:46 -08001/*
2 * Copyright (C) 2010-2011 ARM Limited. All rights reserved.
3 *
4 * Copyright (C) 2008 The Android Open Source Project
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19#ifndef GRALLOC_PRIV_H_
20#define GRALLOC_PRIV_H_
21
22#include <stdint.h>
23#include <pthread.h>
24#include <errno.h>
25#include <linux/fb.h>
26
27#include <hardware/gralloc.h>
28#include <cutils/native_handle.h>
29
30#include "ump.h"
31
Dima Zavina9301d12012-03-01 10:22:09 -080032/* UGH.. HACK */
33enum {
34 GRALLOC_USAGE_HW_FIMC1 = 0x01000000,
35 GRALLOC_USAGE_HW_ION = 0x02000000,
36 GRALLOC_USAGE_YUV_ADDR = 0x04000000,
37 /* SEC Private usage , for Overlay path at HWC */
38 GRALLOC_USAGE_HWC_HWOVERLAY = 0x20000000,
39
40 /* SEC Private usage , for HWC to set HDMI S3D format */
41 /* HDMI should display this buffer as S3D SBS LR/RL*/
42 GRALLOC_USAGE_PRIVATE_SBS_LR = 0x00400000,
43 GRALLOC_USAGE_PRIVATE_SBS_RL = 0x00200000,
44 /* HDMI should display this buffer as 3D TB LR/RL*/
45 GRALLOC_USAGE_PRIVATE_TB_LR = 0x00100000,
Erik Gilling80b3e6c2012-04-05 15:34:47 -070046 GRALLOC_USAGE_PRIVATE_TB_RL = 0x00080000
Dima Zavina9301d12012-03-01 10:22:09 -080047};
48
Dima Zavin6198e542012-02-29 17:02:46 -080049/*
Dima Zavin06062cd2012-04-03 00:10:57 -070050 * HWC_HWOVERLAY is flag for location of glReadPixel().
51 * Enable this define if you want that glReadPixel() is in HWComposer.
52 * If you disable this define, glReadPixel() is not called in threadloop().
Dima Zavin6198e542012-02-29 17:02:46 -080053 */
54#define HWC_HWOVERLAY 1
55
56#define GRALLOC_ARM_UMP_MODULE 1
57
58struct private_handle_t;
59
60struct private_module_t
61{
62 gralloc_module_t base;
63
64 private_handle_t* framebuffer;
65 uint32_t flags;
66 uint32_t numBuffers;
67 uint32_t bufferMask;
68 pthread_mutex_t lock;
69 buffer_handle_t currentBuffer;
70 int ion_client;
71
72 struct fb_var_screeninfo info;
73 struct fb_fix_screeninfo finfo;
74 float xdpi;
75 float ydpi;
76 float fps;
Dima Zavin06062cd2012-04-03 00:10:57 -070077 int enableVSync;
Dima Zavin6198e542012-02-29 17:02:46 -080078
79 enum {
80 PRIV_USAGE_LOCKED_FOR_POST = 0x80000000
81 };
82};
83
84#ifdef __cplusplus
85struct private_handle_t : public native_handle
86{
87#else
88struct private_handle_t
89{
90 struct native_handle nativeHandle;
91#endif
92
93 enum {
94 PRIV_FLAGS_FRAMEBUFFER = 0x00000001,
95 PRIV_FLAGS_USES_UMP = 0x00000002,
Erik Gilling80b3e6c2012-04-05 15:34:47 -070096 PRIV_FLAGS_USES_ION = 0x00000020
Dima Zavin6198e542012-02-29 17:02:46 -080097 };
98
99 enum {
100 LOCK_STATE_WRITE = 1<<31,
101 LOCK_STATE_MAPPED = 1<<30,
102 LOCK_STATE_READ_MASK = 0x3FFFFFFF
103 };
104
105 // Following member is for ION memory only
106 int fd;
107 int magic;
108 int flags;
109 int size;
110 int base;
111 int lockState;
112 int writeOwner;
113 int pid;
114
115 // Following members are for UMP memory only
116 ump_secure_id ump_id;
117 ump_handle ump_mem_handle;
118
119 // Following members is for framebuffer only
120 int offset;
121 int paddr;
122
123 int format;
124 int usage;
125 int width;
126 int height;
127 int bpp;
128 int stride;
129
130 /* Following members are for YUV information */
131 unsigned int yaddr;
132 unsigned int uoffset;
133 unsigned int voffset;
134 int ion_client;
135
136#ifdef __cplusplus
137 static const int sNumInts = 21;
138 static const int sNumFds = 1;
139 static const int sMagic = 0x3141592;
Dima Zavin06062cd2012-04-03 00:10:57 -0700140
Dima Zavin6198e542012-02-29 17:02:46 -0800141 private_handle_t(int flags, int size, int base, int lock_state, ump_secure_id secure_id, ump_handle handle):
142 magic(sMagic),
143 flags(flags),
144 size(size),
145 base(base),
146 lockState(lock_state),
147 writeOwner(0),
148 pid(getpid()),
149 ump_id(secure_id),
150 ump_mem_handle(handle),
151 fd(0),
152 format(0),
153 usage(0),
154 width(0),
155 height(0),
156 bpp(0),
157 stride(0),
158 yaddr(0),
159 uoffset(0),
160 voffset(0),
161 offset(0)
162 {
163 version = sizeof(native_handle);
164 numFds = sNumFds;
165 numInts = sNumInts;
166 }
167
168 private_handle_t(int flags, int size, int base, int lock_state, int fb_file, int fb_offset):
169 magic(sMagic),
170 flags(flags),
171 size(size),
172 base(base),
173 lockState(lock_state),
174 writeOwner(0),
175 pid(getpid()),
176 ump_id(UMP_INVALID_SECURE_ID),
177 ump_mem_handle(UMP_INVALID_MEMORY_HANDLE),
178 fd(fb_file),
179 format(0),
180 usage(0),
181 width(0),
182 height(0),
183 bpp(0),
184 stride(0),
185 yaddr(0),
186 uoffset(0),
187 voffset(0),
188 offset(fb_offset)
189 {
190 version = sizeof(native_handle);
191 numFds = sNumFds;
192 numInts = sNumInts;
193 }
194
195 ~private_handle_t()
196 {
197 magic = 0;
198 }
199
200 bool usesPhysicallyContiguousMemory()
201 {
202 return (flags & PRIV_FLAGS_FRAMEBUFFER) ? true : false;
203 }
204
205 static int validate(const native_handle* h)
206 {
207 const private_handle_t* hnd = (const private_handle_t*)h;
208
209 if (!h || h->version != sizeof(native_handle) ||
210 h->numInts != sNumInts ||
211 h->numFds != sNumFds ||
212 hnd->magic != sMagic)
213 return -EINVAL;
214
215 return 0;
216 }
217
218 static private_handle_t* dynamicCast(const native_handle* in)
219 {
220 if (validate(in) == 0)
221 return (private_handle_t*) in;
222
223 return NULL;
224 }
225#endif
226};
227
228#endif /* GRALLOC_PRIV_H_ */