gralloc_priv.h revision eba311ba2addea7d9dac89fffaf765655a8ff9e6
1/*
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/* 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,
46    GRALLOC_USAGE_PRIVATE_TB_RL         = 0x00080000
47};
48
49/*
50 * 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().
53 */
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    pthread_mutex_t lock;
65    int ion_client;
66
67    int xres;
68    int yres;
69    int line_length;
70    float xdpi;
71    float ydpi;
72    float fps;
73    int enableVSync;
74
75    void *queue;
76    pthread_mutex_t queue_lock;
77
78    enum {
79        PRIV_USAGE_LOCKED_FOR_POST = 0x80000000
80    };
81};
82
83#ifdef __cplusplus
84struct private_handle_t : public native_handle
85{
86#else
87struct private_handle_t
88{
89    struct native_handle nativeHandle;
90#endif
91
92    enum {
93        PRIV_FLAGS_FRAMEBUFFER = 0x00000001,
94        PRIV_FLAGS_USES_UMP    = 0x00000002,
95        PRIV_FLAGS_USES_ION    = 0x00000020
96    };
97
98    enum {
99        LOCK_STATE_WRITE     =   1<<31,
100        LOCK_STATE_MAPPED    =   1<<30,
101        LOCK_STATE_READ_MASK =   0x3FFFFFFF
102    };
103
104    // Following member is for ION memory only
105    int     fd;
106    int     u_fd;
107    int     v_fd;
108    int     magic;
109    int     flags;
110    int     size;
111    int     base;
112    int     lockState;
113    int     writeOwner;
114    int     pid;
115
116    // Following members are for UMP memory only
117    ump_secure_id  ump_id;
118    ump_handle     ump_mem_handle;
119
120    // Following members is for framebuffer only
121    int     offset;
122    int     paddr;
123
124    int     format;
125    int     usage;
126    int     width;
127    int     height;
128    int     bpp;
129    int     stride;
130
131    /* Following members are for YUV information */
132    unsigned int yaddr;
133    unsigned int uoffset;
134    unsigned int voffset;
135    int     ion_client;
136
137#ifdef __cplusplus
138    static const int sNumInts = 21;
139    static const int sNumFds = 3;
140    static const int sMagic = 0x3141592;
141
142    private_handle_t(int flags, int size, int base, int lock_state, ump_secure_id secure_id, ump_handle handle):
143	fd(0),
144        u_fd(0),
145        v_fd(0),
146        magic(sMagic),
147        flags(flags),
148        size(size),
149        base(base),
150        lockState(lock_state),
151        writeOwner(0),
152        pid(getpid()),
153        ump_id(secure_id),
154        ump_mem_handle(handle),
155        offset(0),
156        format(0),
157        usage(0),
158        width(0),
159        height(0),
160        bpp(0),
161        stride(0),
162        yaddr(0),
163        uoffset(0),
164        voffset(0)
165    {
166        version = sizeof(native_handle);
167        numFds = sNumFds;
168        numInts = sNumInts;
169    }
170
171    private_handle_t(int flags, int size, int base, int lock_state, int fb_file, int fb_offset):
172        fd(fb_file),
173        u_fd(0),
174        v_fd(0),
175        magic(sMagic),
176        flags(flags),
177        size(size),
178        base(base),
179        lockState(lock_state),
180        writeOwner(0),
181        pid(getpid()),
182        ump_id(UMP_INVALID_SECURE_ID),
183        ump_mem_handle(UMP_INVALID_MEMORY_HANDLE),
184        offset(fb_offset),
185        format(0),
186        usage(0),
187        width(0),
188        height(0),
189        bpp(0),
190        stride(0),
191        yaddr(0),
192        uoffset(0),
193        voffset(0)
194    {
195        version = sizeof(native_handle);
196        numFds = sNumFds;
197        numInts = sNumInts;
198    }
199
200    ~private_handle_t()
201    {
202        magic = 0;
203    }
204
205    bool usesPhysicallyContiguousMemory()
206    {
207        return (flags & PRIV_FLAGS_FRAMEBUFFER) ? true : false;
208    }
209
210    static int validate(const native_handle* h)
211    {
212        const private_handle_t* hnd = (const private_handle_t*)h;
213
214        if (!h || h->version != sizeof(native_handle) ||
215            h->numInts != sNumInts ||
216            h->numFds != sNumFds ||
217            hnd->magic != sMagic)
218            return -EINVAL;
219
220        return 0;
221    }
222
223    static private_handle_t* dynamicCast(const native_handle* in)
224    {
225        if (validate(in) == 0)
226            return (private_handle_t*) in;
227
228        return NULL;
229    }
230#endif
231};
232
233#endif /* GRALLOC_PRIV_H_ */
234