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