blob: 8ffd161429cef978fdf7b757d40c1eaeeed98ca5 [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 */
138 unsigned int yaddr;
139 unsigned int uoffset;
140 unsigned int voffset;
codeworkxf1be2fe2012-03-24 17:38:29 +0100141
142#ifdef __cplusplus
codeworkx62f02ba2012-05-20 12:00:36 +0200143 static const int sNumInts = 21;
144 static const int sNumFds = 1;
145 static const int sMagic = 0x3141592;
codeworkxf1be2fe2012-03-24 17:38:29 +0100146
codeworkx62f02ba2012-05-20 12:00:36 +0200147 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):
148 fd(fd_val),
149 magic(sMagic),
150 flags(flags),
151 size(size),
152 base(base),
153 lockState(lock_state),
154 writeOwner(0),
155 pid(getpid()),
156 ump_id((int)secure_id),
157 ump_mem_handle((int)handle),
158 offset(offset_val),
159 paddr(paddr_val),
160 format(0),
161 usage(0),
162 width(0),
163 height(0),
164 bpp(0),
165 stride(0),
166 ion_client(0),
167 yaddr(0),
168 uoffset(0),
169 voffset(0)
170 {
171 version = sizeof(native_handle);
172 numFds = sNumFds;
173 numInts = sNumInts;
174 }
codeworkxf1be2fe2012-03-24 17:38:29 +0100175
codeworkx62f02ba2012-05-20 12:00:36 +0200176 private_handle_t(int flags, int size, int base, int lock_state, int fb_file, int fb_offset):
177 fd(fb_file),
178 magic(sMagic),
179 flags(flags),
180 size(size),
181 base(base),
182 lockState(lock_state),
183 writeOwner(0),
184 pid(getpid()),
185 ump_id((int)UMP_INVALID_SECURE_ID),
186 ump_mem_handle((int)UMP_INVALID_MEMORY_HANDLE),
187 offset(fb_offset),
188 paddr(0),
189 format(0),
190 usage(0),
191 width(0),
192 height(0),
193 bpp(0),
194 stride(0),
195 ion_client(0),
196 yaddr(0),
197 uoffset(0),
198 voffset(0)
199 {
200 version = sizeof(native_handle);
201 numFds = sNumFds;
202 numInts = sNumInts;
203 }
codeworkxf1be2fe2012-03-24 17:38:29 +0100204
codeworkx62f02ba2012-05-20 12:00:36 +0200205 ~private_handle_t()
206 {
207 magic = 0;
208 }
codeworkxf1be2fe2012-03-24 17:38:29 +0100209
codeworkx62f02ba2012-05-20 12:00:36 +0200210 bool usesPhysicallyContiguousMemory()
211 {
212 return (flags & PRIV_FLAGS_FRAMEBUFFER) ? true : false;
213 }
codeworkxf1be2fe2012-03-24 17:38:29 +0100214
codeworkx62f02ba2012-05-20 12:00:36 +0200215 static int validate(const native_handle* h)
216 {
217 const private_handle_t* hnd = (const private_handle_t*)h;
218 if (!h || h->version != sizeof(native_handle) ||
219 h->numInts != sNumInts ||
220 h->numFds != sNumFds ||
221 hnd->magic != sMagic)
222 return -EINVAL;
223 return 0;
224 }
codeworkxf1be2fe2012-03-24 17:38:29 +0100225
codeworkx62f02ba2012-05-20 12:00:36 +0200226 static private_handle_t* dynamicCast(const native_handle* in)
227 {
228 if (validate(in) == 0)
229 return (private_handle_t*) in;
230 return NULL;
231 }
codeworkxf1be2fe2012-03-24 17:38:29 +0100232#endif
233};
234
235#endif /* GRALLOC_PRIV_H_ */