Home | History | Annotate | Download | only in libgralloc-qsd8k
      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 enum {
     33     /* gralloc usage bit indicating a pmem_adsp allocation should be used */
     34     GRALLOC_USAGE_PRIVATE_PMEM_ADSP = GRALLOC_USAGE_PRIVATE_0,
     35 };
     36 
     37 /*****************************************************************************/
     38 
     39 enum {
     40     /* OEM specific HAL formats */
     41     //HAL_PIXEL_FORMAT_YCbCr_422_SP = 0x100, // defined in hardware.h
     42     //HAL_PIXEL_FORMAT_YCrCb_420_SP = 0x101, // defined in hardware.h
     43     HAL_PIXEL_FORMAT_YCbCr_422_P  = 0x102,
     44     HAL_PIXEL_FORMAT_YCbCr_420_P  = 0x103,
     45     //HAL_PIXEL_FORMAT_YCbCr_422_I  = 0x104, // defined in hardware.h
     46     HAL_PIXEL_FORMAT_YCbCr_420_I  = 0x105,
     47     HAL_PIXEL_FORMAT_CbYCrY_422_I = 0x106,
     48     HAL_PIXEL_FORMAT_CbYCrY_420_I = 0x107,
     49     HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED     = 0x108,
     50     HAL_PIXEL_FORMAT_YCbCr_420_SP           = 0x109,
     51     HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO    = 0x10A,
     52     HAL_PIXEL_FORMAT_YCrCb_422_SP           = 0x10B,
     53     HAL_PIXEL_FORMAT_YCrCb_420_SP_INTERLACE = 0x10C,
     54 };
     55 
     56 /*****************************************************************************/
     57 
     58 struct private_module_t;
     59 struct private_handle_t;
     60 struct PmemAllocator;
     61 
     62 struct private_module_t {
     63     gralloc_module_t base;
     64 
     65     struct private_handle_t* framebuffer;
     66     uint32_t fbFormat;
     67     uint32_t flags;
     68     uint32_t numBuffers;
     69     uint32_t bufferMask;
     70     pthread_mutex_t lock;
     71     buffer_handle_t currentBuffer;
     72 
     73     struct fb_var_screeninfo info;
     74     struct fb_fix_screeninfo finfo;
     75     float xdpi;
     76     float ydpi;
     77     float fps;
     78 
     79     enum {
     80         // flag to indicate we'll post this buffer
     81         PRIV_USAGE_LOCKED_FOR_POST = 0x80000000
     82     };
     83 };
     84 
     85 /*****************************************************************************/
     86 
     87 #ifdef __cplusplus
     88 struct private_handle_t : public native_handle {
     89 #else
     90 struct private_handle_t {
     91     native_handle_t nativeHandle;
     92 #endif
     93 
     94     enum {
     95         PRIV_FLAGS_FRAMEBUFFER    = 0x00000001,
     96         PRIV_FLAGS_USES_PMEM      = 0x00000002,
     97         PRIV_FLAGS_USES_PMEM_ADSP = 0x00000004,
     98         PRIV_FLAGS_NEEDS_FLUSH    = 0x00000008,
     99     };
    100 
    101     enum {
    102         LOCK_STATE_WRITE     =   1<<31,
    103         LOCK_STATE_MAPPED    =   1<<30,
    104         LOCK_STATE_READ_MASK =   0x3FFFFFFF
    105     };
    106 
    107     // file-descriptors
    108     int     fd;
    109     // ints
    110     int     magic;
    111     int     flags;
    112     int     size;
    113     int     offset;
    114     int     gpu_fd; // stored as an int, b/c we don't want it marshalled
    115 
    116     // FIXME: the attributes below should be out-of-line
    117     int     base;
    118     int     lockState;
    119     int     writeOwner;
    120     int     gpuaddr; // The gpu address mapped into the mmu. If using ashmem, set to 0 They don't care
    121     int     pid;
    122 
    123 #ifdef __cplusplus
    124     static const int sNumInts = 10;
    125     static const int sNumFds = 1;
    126     static const int sMagic = 'gmsm';
    127 
    128     private_handle_t(int fd, int size, int flags) :
    129         fd(fd), magic(sMagic), flags(flags), size(size), offset(0), gpu_fd(-1),
    130         base(0), lockState(0), writeOwner(0), gpuaddr(0), pid(getpid())
    131     {
    132         version = sizeof(native_handle);
    133         numInts = sNumInts;
    134         numFds = sNumFds;
    135     }
    136     ~private_handle_t() {
    137         magic = 0;
    138     }
    139 
    140     bool usesPhysicallyContiguousMemory() {
    141         return (flags & PRIV_FLAGS_USES_PMEM) != 0;
    142     }
    143 
    144     static int validate(const native_handle* h) {
    145         const private_handle_t* hnd = (const private_handle_t*)h;
    146         if (!h || h->version != sizeof(native_handle) ||
    147                 h->numInts != sNumInts || h->numFds != sNumFds ||
    148                 hnd->magic != sMagic)
    149         {
    150             ALOGE("invalid gralloc handle (at %p)", h);
    151             return -EINVAL;
    152         }
    153         return 0;
    154     }
    155 
    156     static private_handle_t* dynamicCast(const native_handle* in) {
    157         if (validate(in) == 0) {
    158             return (private_handle_t*) in;
    159         }
    160         return NULL;
    161     }
    162 #endif
    163 };
    164 
    165 #endif /* GRALLOC_PRIV_H_ */
    166