blob: 50e074df717939e4eb1213755390195d5c8ffc6c [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
32/*
33 * HWC_HWOVERLAY is flag for location of glFinish().
34 * Enable this define if you want that glFinish() is in HWComposer.
35 * If you disable this define, glFinish() is called in threadloop().
36 */
37#define HWC_HWOVERLAY 1
38
39#define GRALLOC_ARM_UMP_MODULE 1
40
41struct private_handle_t;
42
43struct private_module_t
44{
45 gralloc_module_t base;
46
47 private_handle_t* framebuffer;
48 uint32_t flags;
49 uint32_t numBuffers;
50 uint32_t bufferMask;
51 pthread_mutex_t lock;
52 buffer_handle_t currentBuffer;
53 int ion_client;
54
55 struct fb_var_screeninfo info;
56 struct fb_fix_screeninfo finfo;
57 float xdpi;
58 float ydpi;
59 float fps;
60
61 enum {
62 PRIV_USAGE_LOCKED_FOR_POST = 0x80000000
63 };
64};
65
66#ifdef __cplusplus
67struct private_handle_t : public native_handle
68{
69#else
70struct private_handle_t
71{
72 struct native_handle nativeHandle;
73#endif
74
75 enum {
76 PRIV_FLAGS_FRAMEBUFFER = 0x00000001,
77 PRIV_FLAGS_USES_UMP = 0x00000002,
78 PRIV_FLAGS_USES_ION = 0x00000020,
79 };
80
81 enum {
82 LOCK_STATE_WRITE = 1<<31,
83 LOCK_STATE_MAPPED = 1<<30,
84 LOCK_STATE_READ_MASK = 0x3FFFFFFF
85 };
86
87 // Following member is for ION memory only
88 int fd;
89 int magic;
90 int flags;
91 int size;
92 int base;
93 int lockState;
94 int writeOwner;
95 int pid;
96
97 // Following members are for UMP memory only
98 ump_secure_id ump_id;
99 ump_handle ump_mem_handle;
100
101 // Following members is for framebuffer only
102 int offset;
103 int paddr;
104
105 int format;
106 int usage;
107 int width;
108 int height;
109 int bpp;
110 int stride;
111
112 /* Following members are for YUV information */
113 unsigned int yaddr;
114 unsigned int uoffset;
115 unsigned int voffset;
116 int ion_client;
117
118#ifdef __cplusplus
119 static const int sNumInts = 21;
120 static const int sNumFds = 1;
121 static const int sMagic = 0x3141592;
122 private_handle_t(int flags, int size, int base, int lock_state, ump_secure_id secure_id, ump_handle handle):
123 magic(sMagic),
124 flags(flags),
125 size(size),
126 base(base),
127 lockState(lock_state),
128 writeOwner(0),
129 pid(getpid()),
130 ump_id(secure_id),
131 ump_mem_handle(handle),
132 fd(0),
133 format(0),
134 usage(0),
135 width(0),
136 height(0),
137 bpp(0),
138 stride(0),
139 yaddr(0),
140 uoffset(0),
141 voffset(0),
142 offset(0)
143 {
144 version = sizeof(native_handle);
145 numFds = sNumFds;
146 numInts = sNumInts;
147 }
148
149 private_handle_t(int flags, int size, int base, int lock_state, int fb_file, int fb_offset):
150 magic(sMagic),
151 flags(flags),
152 size(size),
153 base(base),
154 lockState(lock_state),
155 writeOwner(0),
156 pid(getpid()),
157 ump_id(UMP_INVALID_SECURE_ID),
158 ump_mem_handle(UMP_INVALID_MEMORY_HANDLE),
159 fd(fb_file),
160 format(0),
161 usage(0),
162 width(0),
163 height(0),
164 bpp(0),
165 stride(0),
166 yaddr(0),
167 uoffset(0),
168 voffset(0),
169 offset(fb_offset)
170 {
171 version = sizeof(native_handle);
172 numFds = sNumFds;
173 numInts = sNumInts;
174 }
175
176 ~private_handle_t()
177 {
178 magic = 0;
179 }
180
181 bool usesPhysicallyContiguousMemory()
182 {
183 return (flags & PRIV_FLAGS_FRAMEBUFFER) ? true : false;
184 }
185
186 static int validate(const native_handle* h)
187 {
188 const private_handle_t* hnd = (const private_handle_t*)h;
189
190 if (!h || h->version != sizeof(native_handle) ||
191 h->numInts != sNumInts ||
192 h->numFds != sNumFds ||
193 hnd->magic != sMagic)
194 return -EINVAL;
195
196 return 0;
197 }
198
199 static private_handle_t* dynamicCast(const native_handle* in)
200 {
201 if (validate(in) == 0)
202 return (private_handle_t*) in;
203
204 return NULL;
205 }
206#endif
207};
208
209#endif /* GRALLOC_PRIV_H_ */