gralloc_priv.h revision a8b0b07d250370ddc8291b5853325693959b6861
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 ionfd;
47
48    int xres;
49    int yres;
50    int line_length;
51    float xdpi;
52    float ydpi;
53    float fps;
54    void *queue;
55    pthread_mutex_t queue_lock;
56
57};
58
59/*****************************************************************************/
60
61#ifdef __cplusplus
62struct private_handle_t : public native_handle {
63#else
64struct private_handle_t {
65    struct native_handle nativeHandle;
66#endif
67
68    enum {
69        PRIV_FLAGS_FRAMEBUFFER = 0x00000001,
70        PRIV_FLAGS_USES_UMP    = 0x00000002,
71        PRIV_FLAGS_USES_ION    = 0x00000020
72    };
73
74    // file-descriptors
75    int     fd;
76    int     fd1;
77    int     fd2;
78    // ints
79    int     magic;
80    int     flags;
81    int     size;
82    int     offset;
83
84    int     format;
85    int     width;
86    int     height;
87    int     stride;
88
89    // FIXME: the attributes below should be out-of-line
90    void    *base;
91
92#ifdef __cplusplus
93    static const int sNumFds = 3;
94    static const int sNumInts = 9;
95    static const int sMagic = 0x3141592;
96
97
98    private_handle_t(int fd, int size, int flags, int w,
99		     int h, int format, int stride) :
100        fd(fd), magic(sMagic), flags(flags), size(size),
101	offset(0), format(format), width(w), height(h), stride(stride), base(0)
102    {
103        version = sizeof(native_handle);
104        numInts = sNumInts;
105        numFds = sNumFds;
106	fd1 = 0;
107	fd2 = 0;
108    }
109
110    private_handle_t(int fd, int fd1, int fd2, int size, int flags, int w,
111		     int h, int format, int stride) :
112        fd(fd), fd1(fd1), fd2(fd2), magic(sMagic), flags(flags), size(size),
113	offset(0), format(format), width(w), height(h), stride(stride), base(0)
114    {
115        version = sizeof(native_handle);
116        numInts = sNumInts;
117        numFds = sNumFds;
118    }
119    ~private_handle_t() {
120        magic = 0;
121    }
122
123    static int validate(const native_handle* h) {
124        const private_handle_t* hnd = (const private_handle_t*)h;
125        if (!h || h->version != sizeof(native_handle) ||
126                h->numInts != sNumInts || h->numFds != sNumFds ||
127                hnd->magic != sMagic)
128        {
129            ALOGE("invalid gralloc handle (at %p)", reinterpret_cast<void *>(const_cast<native_handle *>(h)));
130            return -EINVAL;
131        }
132        return 0;
133    }
134
135    static private_handle_t* dynamicCast(const native_handle* in)
136    {
137        if (validate(in) == 0)
138            return (private_handle_t*) in;
139
140        return NULL;
141    }
142
143#endif
144};
145
146#endif /* GRALLOC_PRIV_H_ */
147