gralloc_priv.h revision f5811ba2dfb9bc9abf754b2e87b1568ef5ee3356
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    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
49    struct fb_var_screeninfo info;
50    struct fb_fix_screeninfo finfo;
51    float xdpi;
52    float ydpi;
53    float fps;
54};
55
56/*****************************************************************************/
57
58#ifdef __cplusplus
59struct private_handle_t : public native_handle {
60#else
61struct private_handle_t {
62    struct native_handle nativeHandle;
63#endif
64
65    enum {
66        PRIV_FLAGS_FRAMEBUFFER = 0x00000001
67    };
68
69    // file-descriptors
70    int     fd;
71    // ints
72    int     magic;
73    int     flags;
74    int     size;
75    int     offset;
76
77    // FIXME: the attributes below should be out-of-line
78    uint64_t base __attribute__((aligned(8)));
79    int     pid;
80
81#ifdef __cplusplus
82    static inline int sNumInts() {
83        return (((sizeof(private_handle_t) - sizeof(native_handle_t))/sizeof(int)) - sNumFds);
84    }
85    static const int sNumFds = 1;
86    static const int sMagic = 0x3141592;
87
88    private_handle_t(int fd, int size, int flags) :
89        fd(fd), magic(sMagic), flags(flags), size(size), offset(0),
90        base(0), pid(getpid())
91    {
92        version = sizeof(native_handle);
93        numInts = sNumInts();
94        numFds = sNumFds;
95    }
96    ~private_handle_t() {
97        magic = 0;
98    }
99
100    static int validate(const native_handle* h) {
101        const private_handle_t* hnd = (const private_handle_t*)h;
102        if (!h || h->version != sizeof(native_handle) ||
103                h->numInts != sNumInts() || h->numFds != sNumFds ||
104                hnd->magic != sMagic)
105        {
106            ALOGE("invalid gralloc handle (at %p)", h);
107            return -EINVAL;
108        }
109        return 0;
110    }
111#endif
112};
113
114#endif /* GRALLOC_PRIV_H_ */
115