1/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef GRALLOC_PRIV_H_
18#define GRALLOC_PRIV_H_
19
20#include <stdint.h>
21#include <limits.h>
22#include <sys/cdefs.h>
23#include <hardware/gralloc.h>
24#include <pthread.h>
25#include <errno.h>
26#include <unistd.h>
27
28#include <cutils/native_handle.h>
29
30#include <linux/fb.h>
31
32/*****************************************************************************/
33
34struct private_module_t;
35struct private_handle_t;
36
37struct private_module_t {
38    gralloc_module_t base;
39
40    struct private_handle_t* framebuffer;
41    uint32_t flags;
42    uint32_t numBuffers;
43    uint32_t bufferMask;
44    pthread_mutex_t lock;
45    buffer_handle_t currentBuffer;
46    int pmem_master;
47    void* pmem_master_base;
48    unsigned long master_phys;
49    int gpu;
50    void* gpu_base;
51    int fb_map_offset;
52
53    struct fb_var_screeninfo info;
54    struct fb_fix_screeninfo finfo;
55    float xdpi;
56    float ydpi;
57    float fps;
58};
59
60/*****************************************************************************/
61
62#ifdef __cplusplus
63struct private_handle_t : public native_handle {
64#else
65struct private_handle_t {
66    native_handle_t nativeHandle;
67#endif
68
69    enum {
70        PRIV_FLAGS_FRAMEBUFFER = 0x00000001,
71        PRIV_FLAGS_USES_PMEM   = 0x00000002,
72        PRIV_FLAGS_USES_GPU    = 0x00000004,
73    };
74
75    // file-descriptors
76    int     fd;
77    // ints
78    int     magic;
79    int     flags;
80    int     size;
81    int     offset;
82    int     gpu_fd; // stored as an int, b/c we don't want it marshalled
83
84    // FIXME: the attributes below should be out-of-line
85    int     base;
86    int     map_offset;
87    int     pid;
88
89#ifdef __cplusplus
90    static const int sNumInts = 8;
91    static const int sNumFds = 1;
92    static const int sMagic = 'gmsm';
93
94    private_handle_t(int fd, int size, int flags) :
95        fd(fd), magic(sMagic), flags(flags), size(size), offset(0),
96        base(0), pid(getpid())
97    {
98        version = sizeof(native_handle);
99        numInts = sNumInts;
100        numFds = sNumFds;
101    }
102    ~private_handle_t() {
103        magic = 0;
104    }
105
106    static int validate(const native_handle* h) {
107        const private_handle_t* hnd = (const private_handle_t*)h;
108        if (!h || h->version != sizeof(native_handle) ||
109                h->numInts != sNumInts || h->numFds != sNumFds ||
110                hnd->magic != sMagic)
111        {
112            LOGE("invalid gralloc handle (at %p)", h);
113            return -EINVAL;
114        }
115        return 0;
116    }
117#endif
118};
119
120#endif /* GRALLOC_PRIV_H_ */
121