am 25ffbfe5: exynos: gralloc: implement gralloc_lock_ycbcr
[GitHub/LineageOS/android_hardware_samsung_slsi_exynos5.git] / include / gralloc_priv.h
index 6984cd1a85c03d3890b5f5523983b71c62f70470..416101c934571062f927d18b4e267a9a293b2421 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * Copyright (C) 2010-2011 ARM Limited. All rights reserved.
- *
  * Copyright (C) 2008 The Android Open Source Project
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
 #define GRALLOC_PRIV_H_
 
 #include <stdint.h>
+#include <limits.h>
+#include <sys/cdefs.h>
+#include <hardware/gralloc.h>
 #include <pthread.h>
 #include <errno.h>
-#include <linux/fb.h>
+#include <unistd.h>
 
-#include <hardware/gralloc.h>
 #include <cutils/native_handle.h>
 
-#include "ump.h"
-
-/* UGH.. HACK */
-enum {
-    GRALLOC_USAGE_HW_FIMC1        = 0x01000000,
-    GRALLOC_USAGE_HW_ION          = 0x02000000,
-    GRALLOC_USAGE_YUV_ADDR        = 0x04000000,
-    /* SEC Private usage , for Overlay path at HWC */
-    GRALLOC_USAGE_HWC_HWOVERLAY     = 0x20000000,
-
-    /* SEC Private usage , for HWC to set HDMI S3D format */
-    /* HDMI should display this buffer as S3D SBS LR/RL*/
-    GRALLOC_USAGE_PRIVATE_SBS_LR        = 0x00400000,
-    GRALLOC_USAGE_PRIVATE_SBS_RL        = 0x00200000,
-    /* HDMI should display this buffer as 3D TB LR/RL*/
-    GRALLOC_USAGE_PRIVATE_TB_LR         = 0x00100000,
-    GRALLOC_USAGE_PRIVATE_TB_RL         = 0x00080000
-};
-
-/*
- * HWC_HWOVERLAY is flag for location of glReadPixel().
- * Enable this define if you want that glReadPixel() is in HWComposer.
- * If you disable this define, glReadPixel() is not called in threadloop().
- */
-#define HWC_HWOVERLAY 1
+#include <linux/fb.h>
 
-#define GRALLOC_ARM_UMP_MODULE 1
+/*****************************************************************************/
 
+struct private_module_t;
 struct private_handle_t;
+typedef int ion_user_handle_t;
 
-struct private_module_t
-{
+struct private_module_t {
     gralloc_module_t base;
 
-    private_handle_t* framebuffer;
+    struct private_handle_t* framebuffer;
     uint32_t flags;
     uint32_t numBuffers;
     uint32_t bufferMask;
     pthread_mutex_t lock;
+    unsigned int refcount;
     buffer_handle_t currentBuffer;
-    int ion_client;
+    int ionfd;
 
-    struct fb_var_screeninfo info;
-    struct fb_fix_screeninfo finfo;
+    int xres;
+    int yres;
+    int line_length;
     float xdpi;
     float ydpi;
     float fps;
-    int enableVSync;
+    void *queue;
+    pthread_mutex_t queue_lock;
 
-    enum {
-        PRIV_USAGE_LOCKED_FOR_POST = 0x80000000
-    };
 };
 
+/*****************************************************************************/
+
 #ifdef __cplusplus
-struct private_handle_t : public native_handle
-{
+struct private_handle_t : public native_handle {
 #else
-struct private_handle_t
-{
+struct private_handle_t {
     struct native_handle nativeHandle;
 #endif
 
+// set if using video encoding colorspace
+#define GRALLOC_USAGE_PRIVATE_CHROMA (GRALLOC_USAGE_PRIVATE_0)
+
     enum {
         PRIV_FLAGS_FRAMEBUFFER = 0x00000001,
         PRIV_FLAGS_USES_UMP    = 0x00000002,
         PRIV_FLAGS_USES_ION    = 0x00000020
     };
 
-    enum {
-        LOCK_STATE_WRITE     =   1<<31,
-        LOCK_STATE_MAPPED    =   1<<30,
-        LOCK_STATE_READ_MASK =   0x3FFFFFFF
-    };
-
-    // Following member is for ION memory only
+    // file-descriptors
     int     fd;
-    int     u_fd;
-    int     v_fd;
+    int     fd1;
+    int     fd2;
+    // ints
     int     magic;
     int     flags;
     int     size;
-    int     base;
-    int     lockState;
-    int     writeOwner;
-    int     pid;
-
-    // Following members are for UMP memory only
-    ump_secure_id  ump_id;
-    ump_handle     ump_mem_handle;
-
-    // Following members is for framebuffer only
     int     offset;
-    int     paddr;
 
     int     format;
-    int     usage;
     int     width;
     int     height;
-    int     bpp;
     int     stride;
-
-    /* Following members are for YUV information */
-    unsigned int yaddr;
-    unsigned int uoffset;
-    unsigned int voffset;
-    int     ion_client;
+    int     vstride;
+    int     gamut;
+    int     chroma;
+
+    // FIXME: the attributes below should be out-of-line
+    void    *base;
+    void    *base1;
+    void    *base2;
+    ion_user_handle_t handle;
+    ion_user_handle_t handle1;
+    ion_user_handle_t handle2;
 
 #ifdef __cplusplus
-    static const int sNumInts = 21;
     static const int sNumFds = 3;
+    static const int sNumInts = 17;
     static const int sMagic = 0x3141592;
 
-    private_handle_t(int flags, int size, int base, int lock_state, ump_secure_id secure_id, ump_handle handle):
-       fd(0),
-        u_fd(0),
-        v_fd(0),
-        magic(sMagic),
-        flags(flags),
-        size(size),
-        base(base),
-        lockState(lock_state),
-        writeOwner(0),
-        pid(getpid()),
-        ump_id(secure_id),
-        ump_mem_handle(handle),
-        offset(0),
-        format(0),
-        usage(0),
-        width(0),
-        height(0),
-        bpp(0),
-        stride(0),
-        yaddr(0),
-        uoffset(0),
-        voffset(0)
+
+    private_handle_t(int fd, int size, int flags, int w,
+                    int h, int format, int stride, int vstride) :
+        fd(fd), fd1(-1), fd2(-1), magic(sMagic), flags(flags), size(size),
+        offset(0), format(format), width(w), height(h), stride(stride),
+        vstride(vstride), gamut(0), chroma(0), base(0), handle(0), handle1(0),
+        handle2(0)
     {
         version = sizeof(native_handle);
-        numFds = sNumFds;
-        numInts = sNumInts;
+        numInts = sNumInts + 2;
+        numFds = sNumFds - 2;
     }
 
-    private_handle_t(int flags, int size, int base, int lock_state, int fb_file, int fb_offset):
-        magic(sMagic),
-        flags(flags),
-        size(size),
-        base(base),
-        lockState(lock_state),
-        writeOwner(0),
-        pid(getpid()),
-        ump_id(UMP_INVALID_SECURE_ID),
-        ump_mem_handle(UMP_INVALID_MEMORY_HANDLE),
-        fd(fb_file),
-        u_fd(0),
-        v_fd(0),
-        format(0),
-        usage(0),
-        width(0),
-        height(0),
-        bpp(0),
-        stride(0),
-        yaddr(0),
-        uoffset(0),
-        voffset(0),
-        offset(fb_offset)
+    private_handle_t(int fd, int fd1, int size, int flags, int w,
+                    int h, int format, int stride, int vstride) :
+        fd(fd), fd1(fd1), fd2(-1), magic(sMagic), flags(flags), size(size),
+        offset(0), format(format), width(w), height(h), stride(stride),
+        vstride(vstride), gamut(0), chroma(0), base(0), base1(0), base2(0),
+        handle(0), handle1(0), handle2(0)
     {
         version = sizeof(native_handle);
-        numFds = sNumFds;
-        numInts = sNumInts;
+        numInts = sNumInts + 1;
+        numFds = sNumFds - 1;
     }
 
-    ~private_handle_t()
+    private_handle_t(int fd, int fd1, int fd2, int size, int flags, int w,
+                    int h, int format, int stride, int vstride) :
+        fd(fd), fd1(fd1), fd2(fd2), magic(sMagic), flags(flags), size(size),
+        offset(0), format(format), width(w), height(h), stride(stride),
+        vstride(vstride), gamut(0), chroma(0), base(0), base1(0), base2(0),
+        handle(0), handle1(0), handle2(0)
     {
-        magic = 0;
+        version = sizeof(native_handle);
+        numInts = sNumInts;
+        numFds = sNumFds;
     }
-
-    bool usesPhysicallyContiguousMemory()
-    {
-        return (flags & PRIV_FLAGS_FRAMEBUFFER) ? true : false;
+    ~private_handle_t() {
+        magic = 0;
     }
 
-    static int validate(const native_handle* h)
-    {
+    static int validate(const native_handle* h) {
         const private_handle_t* hnd = (const private_handle_t*)h;
-
         if (!h || h->version != sizeof(native_handle) ||
-            h->numInts != sNumInts ||
-            h->numFds != sNumFds ||
-            hnd->magic != sMagic)
+            hnd->numInts + hnd->numFds != sNumInts + sNumFds || 
+            hnd->magic != sMagic) 
+        {
+            ALOGE("invalid gralloc handle (at %p)", reinterpret_cast<void *>(const_cast<native_handle *>(h)));
             return -EINVAL;
-
+        }
         return 0;
     }
 
@@ -228,6 +166,7 @@ struct private_handle_t
 
         return NULL;
     }
+
 #endif
 };