Switch to dma_buf based gralloc
authorRebecca Schultz Zavin <rebecca@android.com>
Tue, 26 Jun 2012 19:50:15 +0000 (12:50 -0700)
committerErik Gilling <konkers@android.com>
Thu, 26 Jul 2012 00:37:44 +0000 (17:37 -0700)
Change-Id: Id804e26df5d60a174bb3f83f997d0d015459f1b0
Signed-off-by: Rebecca Schultz Zavin <rebecca@android.com>
exynos_omx/openmax/exynos_omx/osal/Exynos_OSAL_Android.cpp
include/gralloc_priv.h
include/ump.h
libcamera/Android.mk [deleted file]
libcamera2/ExynosCameraHWInterface2.cpp
libhwc/hwc.cpp

index 1c43b5c5c75d415fd444743fb26b3ce846f01f21..b54081c0b7fac6b9c1e8dd2d9e7dfc6045b9330e 100644 (file)
@@ -84,7 +84,7 @@ OMX_ERRORTYPE Exynos_OSAL_LockANBHandle(
     case OMX_COLOR_FormatYUV420Planar:
     case OMX_COLOR_FormatYUV420SemiPlanar:
     case OMX_SEC_COLOR_FormatNV12Tiled:
-        usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_YUV_ADDR;
+        usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN;
         break;
     default:
         usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN;
@@ -100,11 +100,11 @@ OMX_ERRORTYPE Exynos_OSAL_LockANBHandle(
     vplanes[0].fd = priv_hnd->fd;
     vplanes[0].offset = 0;
     vplanes[0].addr = vaddr[0];
-    vplanes[1].fd = priv_hnd->u_fd;
-    vplanes[1].offset = priv_hnd->uoffset;
+    vplanes[1].fd = priv_hnd->fd1;
+    vplanes[1].offset = 0;
     vplanes[1].addr = vaddr[1];
-    vplanes[2].fd = priv_hnd->v_fd;
-    vplanes[2].offset = priv_hnd->voffset;
+    vplanes[2].fd = priv_hnd->fd2;
+    vplanes[2].offset = 0;
     vplanes[2].addr = vaddr[2];
 
     Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: buffer locked: 0x%x", __func__, *vaddr);
@@ -325,8 +325,7 @@ OMX_ERRORTYPE Exynos_OSAL_GetANBParameter(
         /* NOTE: OMX_IndexParamGetAndroidNativeBuffer returns original 'nUsage' without any
          * modifications since currently not defined what the 'nUsage' is for.
          */
-        pANBParams->nUsage |= (GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_EXTERNAL_DISP
-                           | GRALLOC_USAGE_HW_ION | GRALLOC_USAGE_HWC_HWOVERLAY);
+        pANBParams->nUsage |= (GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_EXTERNAL_DISP);
     }
         break;
 
index 20bc9d4cf6ad9bb022b8581a2ec9977648f15310..9c35e85c5ea83d5f19b46b6569007729fa37fcd2 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;
 
-struct private_module_t
-{
+struct private_module_t {
     gralloc_module_t base;
 
+    private_handle_t* framebuffer;
+    uint32_t flags;
+    uint32_t numBuffers;
+    uint32_t bufferMask;
     pthread_mutex_t lock;
-    int ion_client;
+    buffer_handle_t currentBuffer;
+    int ionfd;
 
     int xres;
     int yres;
@@ -70,22 +51,17 @@ struct private_module_t
     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
 
@@ -95,128 +71,64 @@ struct private_handle_t
         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;
+    // FIXME: the attributes below should be out-of-line
+    void    *base;
 
 #ifdef __cplusplus
-    static const int sNumInts = 21;
     static const int sNumFds = 3;
+    static const int sNumInts = 9;
     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) :
+        fd(fd), magic(sMagic), flags(flags), size(size),
+       offset(0), format(format), width(w), height(h), stride(stride), base(0)
     {
         version = sizeof(native_handle);
-        numFds = sNumFds;
         numInts = sNumInts;
+        numFds = sNumFds;
+       fd1 = 0;
+       fd2 = 0;
     }
 
-    private_handle_t(int flags, int size, int base, int lock_state, int fb_file, int fb_offset):
-        fd(fb_file),
-        u_fd(0),
-        v_fd(0),
-        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),
-        offset(fb_offset),
-        format(0),
-        usage(0),
-        width(0),
-        height(0),
-        bpp(0),
-        stride(0),
-        yaddr(0),
-        uoffset(0),
-        voffset(0)
+    private_handle_t(int fd, int fd1, int fd2, int size, int flags, int w,
+                    int h, int format, int stride) :
+        fd(fd), fd1(fd1), fd2(fd2), magic(sMagic), flags(flags), size(size),
+       offset(0), format(format), width(w), height(h), stride(stride), base(0)
     {
         version = sizeof(native_handle);
-        numFds = sNumFds;
         numInts = sNumInts;
+        numFds = sNumFds;
     }
-
-    ~private_handle_t()
-    {
+    ~private_handle_t() {
         magic = 0;
     }
 
-    bool usesPhysicallyContiguousMemory()
-    {
-        return (flags & PRIV_FLAGS_FRAMEBUFFER) ? true : false;
-    }
-
-    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)
+                h->numInts != sNumInts || h->numFds != sNumFds ||
+                hnd->magic != sMagic) 
+        {
+            ALOGE("invalid gralloc handle (at %p)", reinterpret_cast<void *>(const_cast<native_handle *>(h)));
             return -EINVAL;
-
+        }
         return 0;
     }
 
@@ -227,6 +139,7 @@ struct private_handle_t
 
         return NULL;
     }
+
 #endif
 };
 
index 487e2c2472832e9a008f72da05c51a54590bbe59..e5ea652a924b481a2eecea994385599190a897de 100644 (file)
@@ -79,7 +79,6 @@
 
 #include "ump_platform.h"
 #include "ump_common.h"
-#include "ion.h"
 
 #ifndef __KERNEL__
 #include <stdlib.h>
diff --git a/libcamera/Android.mk b/libcamera/Android.mk
deleted file mode 100644 (file)
index d46dff4..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-# HAL module implemenation stored in
-# hw/<COPYPIX_HARDWARE_MODULE_ID>.<ro.product.board>.so
-LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_SHARED_LIBRARIES)/hw
-
-LOCAL_C_INCLUDES += \
-       hardware/samsung_slsi/exynos5/include \
-       frameworks/native/include
-
-LOCAL_SRC_FILES:= \
-       ExynosCamera.cpp \
-       ExynosJpegEncoderForCamera.cpp \
-       ExynosCameraHWInterface.cpp
-
-LOCAL_SHARED_LIBRARIES:= libutils libcutils libbinder liblog libcamera_client libhardware
-
-LOCAL_CFLAGS += -DGAIA_FW_BETA
-
-LOCAL_SHARED_LIBRARIES += libexynosutils libhwjpeg libexynosv4l2 libcsc libion_exynos
-
-LOCAL_MODULE := oldcamera.exynos5
-
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_SHARED_LIBRARY)
index 28af963ab0b73c34f189e7d88db4718ae6d89c9a..ebd22cca4d8815f84a8b81d10de0747377114769 100644 (file)
@@ -526,10 +526,10 @@ int ExynosCameraHWInterface2::allocateStream(uint32_t width, uint32_t height, in
     int fd = 0, i, j;
     *stream_id = 0;
     *format_actual = HAL_PIXEL_FORMAT_YV12;
-    *usage = GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_YUV_ADDR;
+    *usage = GRALLOC_USAGE_SW_WRITE_OFTEN;
     *max_buffers = 8;
 
+
      m_streamThread->SetParameter(*stream_id, width, height, *format_actual, stream_ops, *usage, fd, &(m_camera_info.preview));
     return 0;
 }
@@ -588,8 +588,8 @@ int ExynosCameraHWInterface2::registerStreamBuffers(uint32_t stream_id, int num_
                     const private_handle_t *priv_handle = reinterpret_cast<const private_handle_t *>(buffers[i]);
 
                     v4l2_buf.m.planes[0].m.fd = priv_handle->fd;
-                    v4l2_buf.m.planes[1].m.fd = priv_handle->u_fd;
-                    v4l2_buf.m.planes[2].m.fd = priv_handle->v_fd;
+                    v4l2_buf.m.planes[1].m.fd = priv_handle->fd1;
+                    v4l2_buf.m.planes[2].m.fd = priv_handle->fd2;
 
                     // HACK
                     m_streamThread->m_parameters.grallocVirtAddr[i] = virtAddr[0];
@@ -1016,7 +1016,7 @@ void ExynosCameraHWInterface2::m_streamThreadFunc(SignalDrivenThread * self)
             struct v4l2_plane  planes[VIDEO_MAX_PLANES];
 
 
-                   
+
             v4l2_buf.m.planes = planes;
             v4l2_buf.type       = m_camera_info.preview.type;
             v4l2_buf.memory     = m_camera_info.preview.memory;
@@ -1026,14 +1026,14 @@ void ExynosCameraHWInterface2::m_streamThreadFunc(SignalDrivenThread * self)
             const private_handle_t *priv_handle = reinterpret_cast<const private_handle_t *>(*buf);
 
             v4l2_buf.m.planes[0].m.fd = priv_handle->fd;
-            v4l2_buf.m.planes[1].m.fd = priv_handle->u_fd;
-            v4l2_buf.m.planes[2].m.fd = priv_handle->v_fd;
+            v4l2_buf.m.planes[1].m.fd = priv_handle->fd1;
+            v4l2_buf.m.planes[2].m.fd = priv_handle->fd2;
 
             // HACK
             v4l2_buf.m.planes[0].length  = 1920*1088;
             v4l2_buf.m.planes[1].length  = 1920*1088/4;
             v4l2_buf.m.planes[2].length  = 1920*1088/4;
-            
+
 
             if (exynos_v4l2_qbuf(m_camera_info.preview.fd, &v4l2_buf) < 0) {
                 ALOGE("ERR(%s):preview exynos_v4l2_qbuf() fail", __func__);
index d948f382a0816b305e60888a625d8512315ad158..2a6071055c8e05b1e7191d67fdbdcd5b781b39f5 100644 (file)
@@ -13,7 +13,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 #include <errno.h>
 #include <fcntl.h>
 #include <poll.h>
@@ -103,8 +102,8 @@ static void dump_layer(hwc_layer_1_t const *l)
 
 static void dump_handle(private_handle_t *h)
 {
-    ALOGV("\t\tformat = %d, width = %u, height = %u, bpp = %u, stride = %u",
-            h->format, h->width, h->height, h->bpp, h->stride);
+    ALOGV("\t\tformat = %d, width = %u, height = %u, stride = %u",
+            h->format, h->width, h->height, h->stride);
 }
 
 static void dump_config(s3c_fb_win_config &c)