blob: 0c32fc6cfc0668fd01a61c7bb0d0140af8126c76 [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
50struct private_handle_t;
51
codeworkx62f02ba2012-05-20 12:00:36 +020052struct private_module_t {
53 gralloc_module_t base;
codeworkxf1be2fe2012-03-24 17:38:29 +010054
codeworkx62f02ba2012-05-20 12:00:36 +020055 private_handle_t* framebuffer;
56 uint32_t flags;
57 uint32_t numBuffers;
58 uint32_t bufferMask;
59 pthread_mutex_t lock;
60 buffer_handle_t currentBuffer;
61 int ion_client;
codeworkxf1be2fe2012-03-24 17:38:29 +010062
codeworkx62f02ba2012-05-20 12:00:36 +020063 struct fb_var_screeninfo info;
64 struct fb_fix_screeninfo finfo;
65 float xdpi;
66 float ydpi;
67 float fps;
68 int enableVSync;
codeworkxf1be2fe2012-03-24 17:38:29 +010069
codeworkx62f02ba2012-05-20 12:00:36 +020070 enum {
71 PRIV_USAGE_LOCKED_FOR_POST = 0x80000000
72 };
codeworkxf1be2fe2012-03-24 17:38:29 +010073};
74
codeworkx62f02ba2012-05-20 12:00:36 +020075#ifdef USE_PARTIAL_FLUSH
76struct private_handle_rect {
77 int handle;
78 int stride;
79 int l;
80 int t;
81 int w;
82 int h;
83 int locked;
84 struct private_handle_rect *next;
85};
86#endif
87
codeworkxf1be2fe2012-03-24 17:38:29 +010088#ifdef __cplusplus
89struct private_handle_t : public native_handle
90{
91#else
codeworkx62f02ba2012-05-20 12:00:36 +020092struct private_handle_t {
93 struct native_handle nativeHandle;
codeworkxf1be2fe2012-03-24 17:38:29 +010094#endif
codeworkx62f02ba2012-05-20 12:00:36 +020095 enum {
96 PRIV_FLAGS_FRAMEBUFFER = 0x00000001,
97 PRIV_FLAGS_USES_UMP = 0x00000002,
98 PRIV_FLAGS_USES_PMEM = 0x00000004,
99 PRIV_FLAGS_USES_IOCTL = 0x00000008,
100 PRIV_FLAGS_USES_HDMI = 0x00000010,
101 PRIV_FLAGS_USES_ION = 0x00000020,
102 PRIV_FLAGS_NONE_CACHED = 0x00000040,
103 };
codeworkxf1be2fe2012-03-24 17:38:29 +0100104
codeworkx62f02ba2012-05-20 12:00:36 +0200105 enum {
106 LOCK_STATE_WRITE = 1<<31,
107 LOCK_STATE_MAPPED = 1<<30,
108 LOCK_STATE_READ_MASK = 0x3FFFFFFF
109 };
codeworkxf1be2fe2012-03-24 17:38:29 +0100110
codeworkx62f02ba2012-05-20 12:00:36 +0200111 int fd;
codeworkxf1be2fe2012-03-24 17:38:29 +0100112
codeworkx62f02ba2012-05-20 12:00:36 +0200113 int magic;
114 int flags;
115 int size;
116 int base;
117 int lockState;
118 int writeOwner;
119 int pid;
codeworkxf1be2fe2012-03-24 17:38:29 +0100120
codeworkx62f02ba2012-05-20 12:00:36 +0200121 /* Following members are for UMP memory only */
122 int ump_id;
123 int ump_mem_handle;
124 int offset;
125 int paddr;
codeworkxf1be2fe2012-03-24 17:38:29 +0100126
codeworkx62f02ba2012-05-20 12:00:36 +0200127 int format;
128 int usage;
129 int width;
130 int height;
131 int bpp;
132 int stride;
codeworkxf1be2fe2012-03-24 17:38:29 +0100133
codeworkx62f02ba2012-05-20 12:00:36 +0200134 /* Following members are for ION memory only */
135 int ion_client;
136
137 /* Following members ard for YUV information */
Andrew Dodd2f662dd2012-12-06 00:16:18 -0500138#ifdef USELESS_SEC_YADDR
139 /* Samsung Mobile's blobs don't appear to be using yaddr
140 * in their header file, and none of the source uses it
141 * anywhere
142 */
codeworkx62f02ba2012-05-20 12:00:36 +0200143 unsigned int yaddr;
Andrew Dodd2f662dd2012-12-06 00:16:18 -0500144#endif
codeworkx62f02ba2012-05-20 12:00:36 +0200145 unsigned int uoffset;
146 unsigned int voffset;
codeworkxf1be2fe2012-03-24 17:38:29 +0100147
148#ifdef __cplusplus
codeworkx62f02ba2012-05-20 12:00:36 +0200149 static const int sNumInts = 21;
150 static const int sNumFds = 1;
151 static const int sMagic = 0x3141592;
codeworkxf1be2fe2012-03-24 17:38:29 +0100152
codeworkx62f02ba2012-05-20 12:00:36 +0200153 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):
154 fd(fd_val),
155 magic(sMagic),
156 flags(flags),
157 size(size),
158 base(base),
159 lockState(lock_state),
160 writeOwner(0),
161 pid(getpid()),
162 ump_id((int)secure_id),
163 ump_mem_handle((int)handle),
164 offset(offset_val),
165 paddr(paddr_val),
166 format(0),
167 usage(0),
168 width(0),
169 height(0),
170 bpp(0),
171 stride(0),
172 ion_client(0),
Andrew Dodd2f662dd2012-12-06 00:16:18 -0500173#ifdef USELESS_SEC_YADDR
codeworkx62f02ba2012-05-20 12:00:36 +0200174 yaddr(0),
Andrew Dodd2f662dd2012-12-06 00:16:18 -0500175#endif
codeworkx62f02ba2012-05-20 12:00:36 +0200176 uoffset(0),
177 voffset(0)
178 {
179 version = sizeof(native_handle);
180 numFds = sNumFds;
181 numInts = sNumInts;
182 }
codeworkxf1be2fe2012-03-24 17:38:29 +0100183
codeworkx62f02ba2012-05-20 12:00:36 +0200184 private_handle_t(int flags, int size, int base, int lock_state, int fb_file, int fb_offset):
185 fd(fb_file),
186 magic(sMagic),
187 flags(flags),
188 size(size),
189 base(base),
190 lockState(lock_state),
191 writeOwner(0),
192 pid(getpid()),
193 ump_id((int)UMP_INVALID_SECURE_ID),
194 ump_mem_handle((int)UMP_INVALID_MEMORY_HANDLE),
195 offset(fb_offset),
196 paddr(0),
197 format(0),
198 usage(0),
199 width(0),
200 height(0),
201 bpp(0),
202 stride(0),
203 ion_client(0),
Andrew Dodd2f662dd2012-12-06 00:16:18 -0500204#ifdef USELESS_SEC_YADDR
codeworkx62f02ba2012-05-20 12:00:36 +0200205 yaddr(0),
Andrew Dodd2f662dd2012-12-06 00:16:18 -0500206#endif
codeworkx62f02ba2012-05-20 12:00:36 +0200207 uoffset(0),
208 voffset(0)
209 {
210 version = sizeof(native_handle);
211 numFds = sNumFds;
212 numInts = sNumInts;
213 }
codeworkxf1be2fe2012-03-24 17:38:29 +0100214
codeworkx62f02ba2012-05-20 12:00:36 +0200215 ~private_handle_t()
216 {
217 magic = 0;
218 }
codeworkxf1be2fe2012-03-24 17:38:29 +0100219
codeworkx62f02ba2012-05-20 12:00:36 +0200220 bool usesPhysicallyContiguousMemory()
221 {
222 return (flags & PRIV_FLAGS_FRAMEBUFFER) ? true : false;
223 }
codeworkxf1be2fe2012-03-24 17:38:29 +0100224
codeworkx62f02ba2012-05-20 12:00:36 +0200225 static int validate(const native_handle* h)
226 {
227 const private_handle_t* hnd = (const private_handle_t*)h;
228 if (!h || h->version != sizeof(native_handle) ||
229 h->numInts != sNumInts ||
230 h->numFds != sNumFds ||
231 hnd->magic != sMagic)
232 return -EINVAL;
233 return 0;
234 }
codeworkxf1be2fe2012-03-24 17:38:29 +0100235
codeworkx62f02ba2012-05-20 12:00:36 +0200236 static private_handle_t* dynamicCast(const native_handle* in)
237 {
238 if (validate(in) == 0)
239 return (private_handle_t*) in;
240 return NULL;
241 }
codeworkxf1be2fe2012-03-24 17:38:29 +0100242#endif
243};
244
245#endif /* GRALLOC_PRIV_H_ */