blob: 871a84f4547f68213be9c688f53ca6dc01ee589c [file] [log] [blame]
codeworkxf1be2fe2012-03-24 17:38:29 +01001/*
2 * Copyright (C) 2010 ARM Limited. All rights reserved.
3 *
codeworkx62f02ba2012-05-20 12:00:36 +02004 * Portions of this code have been modified from the original.
5 * These modifications are:
6 * * includes
7 * * struct private_handle_t
8 * * usesPhysicallyContiguousMemory()
9 * * validate()
10 * * dynamicCast()
11 *
codeworkxf1be2fe2012-03-24 17:38:29 +010012 * Copyright (C) 2008 The Android Open Source Project
13 *
14 * Licensed under the Apache License, Version 2.0 (the "License");
15 * you may not use this file except in compliance with the License.
16 * You may obtain a copy of the License at
17 *
18 * http://www.apache.org/licenses/LICENSE-2.0
19 *
20 * Unless required by applicable law or agreed to in writing, software
21 * distributed under the License is distributed on an "AS IS" BASIS,
22 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 * See the License for the specific language governing permissions and
24 * limitations under the License.
25 */
26
27#ifndef GRALLOC_PRIV_H_
28#define GRALLOC_PRIV_H_
29
30#include <stdint.h>
31#include <pthread.h>
32#include <errno.h>
33#include <linux/fb.h>
34
35#include <hardware/gralloc.h>
36#include <cutils/native_handle.h>
37
codeworkx62f02ba2012-05-20 12:00:36 +020038/*#include <ump/ump.h>*/
39#include "ump.h"
40
41/*
42 * HWC_HWOVERLAY is flag for location of glReadPixels().
43 * Enable this define if you want that glReadPixesl() is in HWComposer.
44 * If you disable this define, glReadPixesl() is called in threadloop().
45 */
46#define HWC_HWOVERLAY 1
codeworkxf1be2fe2012-03-24 17:38:29 +010047
48#define GRALLOC_ARM_UMP_MODULE 1
49
codeworkx23280fc2012-07-03 19:22:20 +020050enum {
51 /* SEC Private usage , for HWC to set HDMI S3D format */
52 /* HDMI should display this buffer as S3D SBS LR/RL*/
53 GRALLOC_USAGE_PRIVATE_SBS_LR = 0x00400000,
54 GRALLOC_USAGE_PRIVATE_SBS_RL = 0x00200000,
55
56 /* HDMI should display this buffer as 3D TB LR/RL*/
57 GRALLOC_USAGE_PRIVATE_TB_LR = 0x00100000,
58 GRALLOC_USAGE_PRIVATE_TB_RL = 0x00080000,
59};
60
codeworkxf1be2fe2012-03-24 17:38:29 +010061struct private_handle_t;
62
codeworkx62f02ba2012-05-20 12:00:36 +020063struct private_module_t {
64 gralloc_module_t base;
codeworkxf1be2fe2012-03-24 17:38:29 +010065
codeworkx62f02ba2012-05-20 12:00:36 +020066 private_handle_t* framebuffer;
67 uint32_t flags;
68 uint32_t numBuffers;
69 uint32_t bufferMask;
70 pthread_mutex_t lock;
71 buffer_handle_t currentBuffer;
72 int ion_client;
codeworkxf1be2fe2012-03-24 17:38:29 +010073
codeworkx62f02ba2012-05-20 12:00:36 +020074 struct fb_var_screeninfo info;
75 struct fb_fix_screeninfo finfo;
76 float xdpi;
77 float ydpi;
78 float fps;
79 int enableVSync;
codeworkxf1be2fe2012-03-24 17:38:29 +010080
codeworkx62f02ba2012-05-20 12:00:36 +020081 enum {
82 PRIV_USAGE_LOCKED_FOR_POST = 0x80000000
83 };
codeworkxf1be2fe2012-03-24 17:38:29 +010084};
85
codeworkx62f02ba2012-05-20 12:00:36 +020086#ifdef USE_PARTIAL_FLUSH
87struct private_handle_rect {
88 int handle;
89 int stride;
90 int l;
91 int t;
92 int w;
93 int h;
94 int locked;
95 struct private_handle_rect *next;
96};
97#endif
98
codeworkxf1be2fe2012-03-24 17:38:29 +010099#ifdef __cplusplus
100struct private_handle_t : public native_handle
101{
102#else
codeworkx62f02ba2012-05-20 12:00:36 +0200103struct private_handle_t {
104 struct native_handle nativeHandle;
codeworkxf1be2fe2012-03-24 17:38:29 +0100105#endif
codeworkx62f02ba2012-05-20 12:00:36 +0200106 enum {
107 PRIV_FLAGS_FRAMEBUFFER = 0x00000001,
108 PRIV_FLAGS_USES_UMP = 0x00000002,
109 PRIV_FLAGS_USES_PMEM = 0x00000004,
110 PRIV_FLAGS_USES_IOCTL = 0x00000008,
111 PRIV_FLAGS_USES_HDMI = 0x00000010,
112 PRIV_FLAGS_USES_ION = 0x00000020,
113 PRIV_FLAGS_NONE_CACHED = 0x00000040,
114 };
codeworkxf1be2fe2012-03-24 17:38:29 +0100115
codeworkx62f02ba2012-05-20 12:00:36 +0200116 enum {
117 LOCK_STATE_WRITE = 1<<31,
118 LOCK_STATE_MAPPED = 1<<30,
119 LOCK_STATE_READ_MASK = 0x3FFFFFFF
120 };
codeworkxf1be2fe2012-03-24 17:38:29 +0100121
codeworkx62f02ba2012-05-20 12:00:36 +0200122 int fd;
codeworkxf1be2fe2012-03-24 17:38:29 +0100123
codeworkx62f02ba2012-05-20 12:00:36 +0200124 int magic;
125 int flags;
126 int size;
127 int base;
128 int lockState;
129 int writeOwner;
130 int pid;
codeworkxf1be2fe2012-03-24 17:38:29 +0100131
codeworkx62f02ba2012-05-20 12:00:36 +0200132 /* Following members are for UMP memory only */
133 int ump_id;
134 int ump_mem_handle;
135 int offset;
136 int paddr;
codeworkxf1be2fe2012-03-24 17:38:29 +0100137
codeworkx62f02ba2012-05-20 12:00:36 +0200138 int format;
139 int usage;
140 int width;
141 int height;
142 int bpp;
143 int stride;
codeworkxf1be2fe2012-03-24 17:38:29 +0100144
codeworkx62f02ba2012-05-20 12:00:36 +0200145 /* Following members are for ION memory only */
146 int ion_client;
147
148 /* Following members ard for YUV information */
149 unsigned int yaddr;
150 unsigned int uoffset;
151 unsigned int voffset;
codeworkxf1be2fe2012-03-24 17:38:29 +0100152
153#ifdef __cplusplus
codeworkx62f02ba2012-05-20 12:00:36 +0200154 static const int sNumInts = 21;
155 static const int sNumFds = 1;
156 static const int sMagic = 0x3141592;
codeworkxf1be2fe2012-03-24 17:38:29 +0100157
codeworkx62f02ba2012-05-20 12:00:36 +0200158 private_handle_t(int flags, int size, int base, int lock_state, ump_secure_id secure_id, ump_handle handle,int fd_val, int offset_val, int paddr_val):
159 fd(fd_val),
160 magic(sMagic),
161 flags(flags),
162 size(size),
163 base(base),
164 lockState(lock_state),
165 writeOwner(0),
166 pid(getpid()),
167 ump_id((int)secure_id),
168 ump_mem_handle((int)handle),
169 offset(offset_val),
170 paddr(paddr_val),
171 format(0),
172 usage(0),
173 width(0),
174 height(0),
175 bpp(0),
176 stride(0),
177 ion_client(0),
178 yaddr(0),
179 uoffset(0),
180 voffset(0)
181 {
182 version = sizeof(native_handle);
183 numFds = sNumFds;
184 numInts = sNumInts;
185 }
codeworkxf1be2fe2012-03-24 17:38:29 +0100186
codeworkx62f02ba2012-05-20 12:00:36 +0200187 private_handle_t(int flags, int size, int base, int lock_state, int fb_file, int fb_offset):
188 fd(fb_file),
189 magic(sMagic),
190 flags(flags),
191 size(size),
192 base(base),
193 lockState(lock_state),
194 writeOwner(0),
195 pid(getpid()),
196 ump_id((int)UMP_INVALID_SECURE_ID),
197 ump_mem_handle((int)UMP_INVALID_MEMORY_HANDLE),
198 offset(fb_offset),
199 paddr(0),
200 format(0),
201 usage(0),
202 width(0),
203 height(0),
204 bpp(0),
205 stride(0),
206 ion_client(0),
207 yaddr(0),
208 uoffset(0),
209 voffset(0)
210 {
211 version = sizeof(native_handle);
212 numFds = sNumFds;
213 numInts = sNumInts;
214 }
codeworkxf1be2fe2012-03-24 17:38:29 +0100215
codeworkx62f02ba2012-05-20 12:00:36 +0200216 ~private_handle_t()
217 {
218 magic = 0;
219 }
codeworkxf1be2fe2012-03-24 17:38:29 +0100220
codeworkx62f02ba2012-05-20 12:00:36 +0200221 bool usesPhysicallyContiguousMemory()
222 {
223 return (flags & PRIV_FLAGS_FRAMEBUFFER) ? true : false;
224 }
codeworkxf1be2fe2012-03-24 17:38:29 +0100225
codeworkx62f02ba2012-05-20 12:00:36 +0200226 static int validate(const native_handle* h)
227 {
228 const private_handle_t* hnd = (const private_handle_t*)h;
229 if (!h || h->version != sizeof(native_handle) ||
230 h->numInts != sNumInts ||
231 h->numFds != sNumFds ||
232 hnd->magic != sMagic)
233 return -EINVAL;
234 return 0;
235 }
codeworkxf1be2fe2012-03-24 17:38:29 +0100236
codeworkx62f02ba2012-05-20 12:00:36 +0200237 static private_handle_t* dynamicCast(const native_handle* in)
238 {
239 if (validate(in) == 0)
240 return (private_handle_t*) in;
241 return NULL;
242 }
codeworkxf1be2fe2012-03-24 17:38:29 +0100243#endif
244};
245
246#endif /* GRALLOC_PRIV_H_ */