Home | History | Annotate | Download | only in OpenglSystemCommon
      1 #ifndef __GRALLOC_CB_H__
      2 #define __GRALLOC_CB_H__
      3 
      4 #include <hardware/hardware.h>
      5 #include <hardware/gralloc.h>
      6 #include <cutils/native_handle.h>
      7 
      8 #define BUFFER_HANDLE_MAGIC ((int)0xabfabfab)
      9 #define CB_HANDLE_NUM_INTS(nfds) (int)((sizeof(cb_handle_t) - (nfds)*sizeof(int)) / sizeof(int))
     10 
     11 //
     12 // Our buffer handle structure
     13 //
     14 struct cb_handle_t : public native_handle {
     15 
     16     cb_handle_t(int p_fd, int p_ashmemSize, int p_usage,
     17                 int p_width, int p_height,
     18                 int p_glFormat, int p_glType) :
     19         fd(p_fd),
     20         magic(BUFFER_HANDLE_MAGIC),
     21         usage(p_usage),
     22         width(p_width),
     23         height(p_height),
     24         glFormat(p_glFormat),
     25         glType(p_glType),
     26         ashmemSize(p_ashmemSize),
     27         ashmemBase(NULL),
     28         ashmemBasePid(0),
     29         mappedPid(0),
     30         lockedLeft(0),
     31         lockedTop(0),
     32         lockedWidth(0),
     33         lockedHeight(0),
     34         hostHandle(0)
     35     {
     36         version = sizeof(native_handle);
     37         numFds = 0;
     38         numInts = CB_HANDLE_NUM_INTS(numFds);
     39     }
     40 
     41     ~cb_handle_t() {
     42         magic = 0;
     43     }
     44 
     45     void setFd(int p_fd) {
     46         if (p_fd >= 0) {
     47             numFds = 1;
     48         }
     49         else {
     50             numFds = 0;
     51         }
     52         fd = p_fd;
     53         numInts = CB_HANDLE_NUM_INTS(numFds);
     54     }
     55 
     56     static bool validate(cb_handle_t * hnd) {
     57         return (hnd &&
     58                 hnd->version == sizeof(native_handle) &&
     59                 hnd->magic == BUFFER_HANDLE_MAGIC &&
     60                 hnd->numInts == CB_HANDLE_NUM_INTS(hnd->numFds));
     61     }
     62 
     63     bool canBePosted() {
     64         return (0 != (usage & GRALLOC_USAGE_HW_FB));
     65     }
     66 
     67     // file-descriptors
     68     int fd;  // ashmem fd (-1 of ashmem region did not allocated, i.e. no SW access needed)
     69 
     70     // ints
     71     int magic;              // magic number in order to validate a pointer to be a cb_handle_t
     72     int usage;              // usage bits the buffer was created with
     73     int width;              // buffer width
     74     int height;             // buffer height
     75     int glFormat;           // OpenGL format enum used for host h/w color buffer
     76     int glType;             // OpenGL type enum used when uploading to host
     77     int ashmemSize;         // ashmem region size for the buffer (0 unless is HW_FB buffer or
     78                             //                                    s/w access is needed)
     79     int ashmemBase;         // CPU address of the mapped ashmem region
     80     int ashmemBasePid;      // process id which mapped the ashmem region
     81     int mappedPid;          // process id which succeeded gralloc_register call
     82     int lockedLeft;         // region of buffer locked for s/w write
     83     int lockedTop;
     84     int lockedWidth;
     85     int lockedHeight;
     86     uint32_t hostHandle;
     87 };
     88 
     89 
     90 #endif //__GRALLOC_CB_H__
     91