blob: aa1ceb221d7e0857beb50b158b9418750fb708dc [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
Dima Zavin6198e542012-02-29 17:02:46 -080064 pthread_mutex_t lock;
Dima Zavin6198e542012-02-29 17:02:46 -080065 int ion_client;
66
Greg Hackmannd37bc2b2012-05-23 16:29:43 -070067 int xres;
68 int yres;
69 int line_length;
Dima Zavin6198e542012-02-29 17:02:46 -080070 float xdpi;
71 float ydpi;
72 float fps;
Dima Zavin06062cd2012-04-03 00:10:57 -070073 int enableVSync;
Greg Hackmanndd557382012-05-03 14:51:28 -070074
75 void *queue;
76 pthread_mutex_t queue_lock;
Dima Zavin6198e542012-02-29 17:02:46 -080077
78 enum {
79 PRIV_USAGE_LOCKED_FOR_POST = 0x80000000
80 };
81};
82
83#ifdef __cplusplus
84struct private_handle_t : public native_handle
85{
86#else
87struct private_handle_t
88{
89 struct native_handle nativeHandle;
90#endif
91
92 enum {
93 PRIV_FLAGS_FRAMEBUFFER = 0x00000001,
94 PRIV_FLAGS_USES_UMP = 0x00000002,
Erik Gilling80b3e6c2012-04-05 15:34:47 -070095 PRIV_FLAGS_USES_ION = 0x00000020
Dima Zavin6198e542012-02-29 17:02:46 -080096 };
97
98 enum {
99 LOCK_STATE_WRITE = 1<<31,
100 LOCK_STATE_MAPPED = 1<<30,
101 LOCK_STATE_READ_MASK = 0x3FFFFFFF
102 };
103
104 // Following member is for ION memory only
105 int fd;
Rebecca Schultz Zavin471812b2012-05-15 16:49:56 -0700106 int u_fd;
107 int v_fd;
Dima Zavin6198e542012-02-29 17:02:46 -0800108 int magic;
109 int flags;
110 int size;
111 int base;
112 int lockState;
113 int writeOwner;
114 int pid;
115
116 // Following members are for UMP memory only
117 ump_secure_id ump_id;
118 ump_handle ump_mem_handle;
119
120 // Following members is for framebuffer only
121 int offset;
122 int paddr;
123
124 int format;
125 int usage;
126 int width;
127 int height;
128 int bpp;
129 int stride;
130
131 /* Following members are for YUV information */
132 unsigned int yaddr;
133 unsigned int uoffset;
134 unsigned int voffset;
135 int ion_client;
136
137#ifdef __cplusplus
138 static const int sNumInts = 21;
Rebecca Schultz Zavin471812b2012-05-15 16:49:56 -0700139 static const int sNumFds = 3;
Dima Zavin6198e542012-02-29 17:02:46 -0800140 static const int sMagic = 0x3141592;
Dima Zavin06062cd2012-04-03 00:10:57 -0700141
Dima Zavin6198e542012-02-29 17:02:46 -0800142 private_handle_t(int flags, int size, int base, int lock_state, ump_secure_id secure_id, ump_handle handle):
Rebecca Schultz Zavin471812b2012-05-15 16:49:56 -0700143 fd(0),
144 u_fd(0),
145 v_fd(0),
Dima Zavin6198e542012-02-29 17:02:46 -0800146 magic(sMagic),
147 flags(flags),
148 size(size),
149 base(base),
150 lockState(lock_state),
151 writeOwner(0),
152 pid(getpid()),
153 ump_id(secure_id),
154 ump_mem_handle(handle),
Rebecca Schultz Zavin471812b2012-05-15 16:49:56 -0700155 offset(0),
Dima Zavin6198e542012-02-29 17:02:46 -0800156 format(0),
157 usage(0),
158 width(0),
159 height(0),
160 bpp(0),
161 stride(0),
162 yaddr(0),
163 uoffset(0),
Rebecca Schultz Zavin471812b2012-05-15 16:49:56 -0700164 voffset(0)
Dima Zavin6198e542012-02-29 17:02:46 -0800165 {
166 version = sizeof(native_handle);
167 numFds = sNumFds;
168 numInts = sNumInts;
169 }
170
171 private_handle_t(int flags, int size, int base, int lock_state, int fb_file, int fb_offset):
172 magic(sMagic),
173 flags(flags),
174 size(size),
175 base(base),
176 lockState(lock_state),
177 writeOwner(0),
178 pid(getpid()),
179 ump_id(UMP_INVALID_SECURE_ID),
180 ump_mem_handle(UMP_INVALID_MEMORY_HANDLE),
181 fd(fb_file),
Rebecca Schultz Zavin471812b2012-05-15 16:49:56 -0700182 u_fd(0),
183 v_fd(0),
Dima Zavin6198e542012-02-29 17:02:46 -0800184 format(0),
185 usage(0),
186 width(0),
187 height(0),
188 bpp(0),
189 stride(0),
190 yaddr(0),
191 uoffset(0),
192 voffset(0),
193 offset(fb_offset)
194 {
195 version = sizeof(native_handle);
196 numFds = sNumFds;
197 numInts = sNumInts;
198 }
199
200 ~private_handle_t()
201 {
202 magic = 0;
203 }
204
205 bool usesPhysicallyContiguousMemory()
206 {
207 return (flags & PRIV_FLAGS_FRAMEBUFFER) ? true : false;
208 }
209
210 static int validate(const native_handle* h)
211 {
212 const private_handle_t* hnd = (const private_handle_t*)h;
213
214 if (!h || h->version != sizeof(native_handle) ||
215 h->numInts != sNumInts ||
216 h->numFds != sNumFds ||
217 hnd->magic != sMagic)
218 return -EINVAL;
219
220 return 0;
221 }
222
223 static private_handle_t* dynamicCast(const native_handle* in)
224 {
225 if (validate(in) == 0)
226 return (private_handle_t*) in;
227
228 return NULL;
229 }
230#endif
231};
232
233#endif /* GRALLOC_PRIV_H_ */