Home | History | Annotate | Download | only in gralloc
      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 
     34 struct private_module_t;
     35 struct private_handle_t;
     36 
     37 struct 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
     59 struct private_handle_t : public native_handle {
     60 #else
     61 struct 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     int     base;
     79     int     pid;
     80 
     81 #ifdef __cplusplus
     82     static const int sNumInts = 6;
     83     static const int sNumFds = 1;
     84     static const int sMagic = 0x3141592;
     85 
     86     private_handle_t(int fd, int size, int flags) :
     87         fd(fd), magic(sMagic), flags(flags), size(size), offset(0),
     88         base(0), pid(getpid())
     89     {
     90         version = sizeof(native_handle);
     91         numInts = sNumInts;
     92         numFds = sNumFds;
     93     }
     94     ~private_handle_t() {
     95         magic = 0;
     96     }
     97 
     98     static int validate(const native_handle* h) {
     99         const private_handle_t* hnd = (const private_handle_t*)h;
    100         if (!h || h->version != sizeof(native_handle) ||
    101                 h->numInts != sNumInts || h->numFds != sNumFds ||
    102                 hnd->magic != sMagic)
    103         {
    104             ALOGE("invalid gralloc handle (at %p)", h);
    105             return -EINVAL;
    106         }
    107         return 0;
    108     }
    109 #endif
    110 };
    111 
    112 #endif /* GRALLOC_PRIV_H_ */
    113