blob: 92b97790c049eba2af80be8c27c1bf4cdaf2a5cb [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;
Greg Hackmanndd557382012-05-03 14:51:28 -070078
79 void *queue;
80 pthread_mutex_t queue_lock;
Dima Zavin6198e542012-02-29 17:02:46 -080081
82 enum {
83 PRIV_USAGE_LOCKED_FOR_POST = 0x80000000
84 };
85};
86
87#ifdef __cplusplus
88struct private_handle_t : public native_handle
89{
90#else
91struct private_handle_t
92{
93 struct native_handle nativeHandle;
94#endif
95
96 enum {
97 PRIV_FLAGS_FRAMEBUFFER = 0x00000001,
98 PRIV_FLAGS_USES_UMP = 0x00000002,
Erik Gilling80b3e6c2012-04-05 15:34:47 -070099 PRIV_FLAGS_USES_ION = 0x00000020
Dima Zavin6198e542012-02-29 17:02:46 -0800100 };
101
102 enum {
103 LOCK_STATE_WRITE = 1<<31,
104 LOCK_STATE_MAPPED = 1<<30,
105 LOCK_STATE_READ_MASK = 0x3FFFFFFF
106 };
107
108 // Following member is for ION memory only
109 int fd;
Rebecca Schultz Zavin471812b2012-05-15 16:49:56 -0700110 int u_fd;
111 int v_fd;
Dima Zavin6198e542012-02-29 17:02:46 -0800112 int magic;
113 int flags;
114 int size;
115 int base;
116 int lockState;
117 int writeOwner;
118 int pid;
119
120 // Following members are for UMP memory only
121 ump_secure_id ump_id;
122 ump_handle ump_mem_handle;
123
124 // Following members is for framebuffer only
125 int offset;
126 int paddr;
127
128 int format;
129 int usage;
130 int width;
131 int height;
132 int bpp;
133 int stride;
134
135 /* Following members are for YUV information */
136 unsigned int yaddr;
137 unsigned int uoffset;
138 unsigned int voffset;
139 int ion_client;
140
141#ifdef __cplusplus
142 static const int sNumInts = 21;
Rebecca Schultz Zavin471812b2012-05-15 16:49:56 -0700143 static const int sNumFds = 3;
Dima Zavin6198e542012-02-29 17:02:46 -0800144 static const int sMagic = 0x3141592;
Dima Zavin06062cd2012-04-03 00:10:57 -0700145
Dima Zavin6198e542012-02-29 17:02:46 -0800146 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 -0700147 fd(0),
148 u_fd(0),
149 v_fd(0),
Dima Zavin6198e542012-02-29 17:02:46 -0800150 magic(sMagic),
151 flags(flags),
152 size(size),
153 base(base),
154 lockState(lock_state),
155 writeOwner(0),
156 pid(getpid()),
157 ump_id(secure_id),
158 ump_mem_handle(handle),
Rebecca Schultz Zavin471812b2012-05-15 16:49:56 -0700159 offset(0),
Dima Zavin6198e542012-02-29 17:02:46 -0800160 format(0),
161 usage(0),
162 width(0),
163 height(0),
164 bpp(0),
165 stride(0),
166 yaddr(0),
167 uoffset(0),
Rebecca Schultz Zavin471812b2012-05-15 16:49:56 -0700168 voffset(0)
Dima Zavin6198e542012-02-29 17:02:46 -0800169 {
170 version = sizeof(native_handle);
171 numFds = sNumFds;
172 numInts = sNumInts;
173 }
174
175 private_handle_t(int flags, int size, int base, int lock_state, int fb_file, int fb_offset):
176 magic(sMagic),
177 flags(flags),
178 size(size),
179 base(base),
180 lockState(lock_state),
181 writeOwner(0),
182 pid(getpid()),
183 ump_id(UMP_INVALID_SECURE_ID),
184 ump_mem_handle(UMP_INVALID_MEMORY_HANDLE),
185 fd(fb_file),
Rebecca Schultz Zavin471812b2012-05-15 16:49:56 -0700186 u_fd(0),
187 v_fd(0),
Dima Zavin6198e542012-02-29 17:02:46 -0800188 format(0),
189 usage(0),
190 width(0),
191 height(0),
192 bpp(0),
193 stride(0),
194 yaddr(0),
195 uoffset(0),
196 voffset(0),
197 offset(fb_offset)
198 {
199 version = sizeof(native_handle);
200 numFds = sNumFds;
201 numInts = sNumInts;
202 }
203
204 ~private_handle_t()
205 {
206 magic = 0;
207 }
208
209 bool usesPhysicallyContiguousMemory()
210 {
211 return (flags & PRIV_FLAGS_FRAMEBUFFER) ? true : false;
212 }
213
214 static int validate(const native_handle* h)
215 {
216 const private_handle_t* hnd = (const private_handle_t*)h;
217
218 if (!h || h->version != sizeof(native_handle) ||
219 h->numInts != sNumInts ||
220 h->numFds != sNumFds ||
221 hnd->magic != sMagic)
222 return -EINVAL;
223
224 return 0;
225 }
226
227 static private_handle_t* dynamicCast(const native_handle* in)
228 {
229 if (validate(in) == 0)
230 return (private_handle_t*) in;
231
232 return NULL;
233 }
234#endif
235};
236
237#endif /* GRALLOC_PRIV_H_ */