hwc: Add vpu client

Stub implementation of VPU in HWC.
This commit passes through binder calls from HWC
to the VPU library. It also has stub prepare/draw calls
in the VPU client object which can be used to configure
VPU in the composition cycle.

Change-Id: I2606f2884e870448d29ef26e02faac92e157e2c6
diff --git a/libhwcomposer/Android.mk b/libhwcomposer/Android.mk
index d47e4b0..12b822a 100644
--- a/libhwcomposer/Android.mk
+++ b/libhwcomposer/Android.mk
@@ -25,4 +25,9 @@
                                  hwc_dump_layers.cpp \
                                  hwc_ad.cpp
 
+ifeq ($(call is-board-platform-in-list, mpq8092), true)
+    LOCAL_SRC_FILES += hwc_vpuclient.cpp
+endif
+
+
 include $(BUILD_SHARED_LIBRARY)
diff --git a/libhwcomposer/hwc.cpp b/libhwcomposer/hwc.cpp
index 1290cc4..b9b0a61 100644
--- a/libhwcomposer/hwc.cpp
+++ b/libhwcomposer/hwc.cpp
@@ -38,6 +38,7 @@
 #include "hwc_copybit.h"
 #include "hwc_ad.h"
 #include "profiler.h"
+#include "hwc_vpuclient.h"
 
 using namespace qhwc;
 using namespace overlay;
@@ -155,6 +156,9 @@
         hwc_layer_1_t *fbLayer = &list->hwLayers[last];
         if(fbLayer->handle) {
             setListStats(ctx, list, dpy);
+#ifdef VPU_TARGET
+            ctx->mVPUClient->prepare(ctx, list);
+#endif
             if(ctx->mMDPComp[dpy]->prepare(ctx, list) < 0) {
                 const int fbZ = 0;
                 ctx->mFBUpdate[dpy]->prepare(ctx, list, fbZ);
@@ -441,6 +445,9 @@
             ALOGE("%s: MDPComp draw failed", __FUNCTION__);
             ret = -1;
         }
+#ifdef VPU_TARGET
+        ctx->mVPUClient->draw(ctx, list);
+#endif
 
         //TODO We dont check for SKIP flag on this layer because we need PAN
         //always. Last layer is always FB
diff --git a/libhwcomposer/hwc_qclient.cpp b/libhwcomposer/hwc_qclient.cpp
index 12a9f32..a17565b 100644
--- a/libhwcomposer/hwc_qclient.cpp
+++ b/libhwcomposer/hwc_qclient.cpp
@@ -30,6 +30,7 @@
 #include <hwc_qclient.h>
 #include <IQService.h>
 #include <hwc_utils.h>
+#include <hwc_vpuclient.h>
 
 #define QCLIENT_DEBUG 0
 
@@ -51,6 +52,12 @@
 }
 
 status_t QClient::notifyCallback(uint32_t msg, uint32_t value) {
+
+    if (msg > IQService::VPU_COMMAND_LIST_START &&
+        msg < IQService::VPU_COMMAND_LIST_END) {
+        return vpuCommand(msg, value);
+    }
+
     switch(msg) {
         case IQService::SECURING:
             securing(value);
@@ -117,6 +124,16 @@
     return result;
 }
 
+android::status_t QClient::vpuCommand(uint32_t command, uint32_t setting) {
+    status_t result = NO_INIT;
+#ifdef QCOM_BSP
+#ifdef VPU_TARGET
+    result = mHwcContext->mVPUClient->processCommand(command, setting);
+#endif
+#endif
+    return result;
+}
+
 void QClient::setExtOrientation(uint32_t orientation) {
     mHwcContext->mExtOrientation = orientation;
 }
diff --git a/libhwcomposer/hwc_qclient.h b/libhwcomposer/hwc_qclient.h
index 848d8d2..fa1d6b0 100644
--- a/libhwcomposer/hwc_qclient.h
+++ b/libhwcomposer/hwc_qclient.h
@@ -62,6 +62,7 @@
     android::status_t screenRefresh();
     void setExtOrientation(uint32_t orientation);
     void setBufferMirrorMode(uint32_t enable);
+    android::status_t vpuCommand(uint32_t command, uint32_t setting);
 
     hwc_context_t *mHwcContext;
     const android::sp<android::IMediaDeathNotifier> mMPDeathNotifier;
diff --git a/libhwcomposer/hwc_utils.cpp b/libhwcomposer/hwc_utils.cpp
index 51cac7f..af914e7 100644
--- a/libhwcomposer/hwc_utils.cpp
+++ b/libhwcomposer/hwc_utils.cpp
@@ -37,6 +37,7 @@
 #include "mdp_version.h"
 #include "hwc_copybit.h"
 #include "hwc_dump_layers.h"
+#include "hwc_vpuclient.h"
 #include "external.h"
 #include "virtual.h"
 #include "hwc_qclient.h"
@@ -194,8 +195,10 @@
     ctx->mPrevDestVideo.left = ctx->mPrevDestVideo.top =
         ctx->mPrevDestVideo.right = ctx->mPrevDestVideo.bottom = 0;
     ctx->mPrevTransformVideo = 0;
-
     ctx->mBufferMirrorMode = false;
+#ifdef VPU_TARGET
+    ctx->mVPUClient = new VPUClient();
+#endif
 
     ALOGI("Initializing Qualcomm Hardware Composer");
     ALOGI("MDP version: %d", ctx->mMDP.version);
@@ -230,6 +233,12 @@
         ctx->mExtDisplay = NULL;
     }
 
+#ifdef VPU_TARGET
+    if(ctx->mVPUClient) {
+        delete ctx->mVPUClient;
+    }
+#endif
+
     for(int i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
         if(ctx->mFBUpdate[i]) {
             delete ctx->mFBUpdate[i];
diff --git a/libhwcomposer/hwc_utils.h b/libhwcomposer/hwc_utils.h
index d77673b..c5a7be9 100644
--- a/libhwcomposer/hwc_utils.h
+++ b/libhwcomposer/hwc_utils.h
@@ -57,6 +57,7 @@
 class CopyBit;
 class HwcDebug;
 class AssertiveDisplay;
+class VPUClient;
 
 
 struct MDPInfo {
@@ -351,6 +352,7 @@
     qhwc::MDPComp *mMDPComp[HWC_NUM_DISPLAY_TYPES];
     qhwc::HwcDebug *mHwcDebug[HWC_NUM_DISPLAY_TYPES];
     qhwc::AssertiveDisplay *mAD;
+    qhwc::VPUClient *mVPUClient;
 
     // No animation on External display feature
     // Notifies hwcomposer about the device orientation before animation.
diff --git a/libhwcomposer/hwc_vpuclient.cpp b/libhwcomposer/hwc_vpuclient.cpp
new file mode 100644
index 0000000..bdfeae5
--- /dev/null
+++ b/libhwcomposer/hwc_vpuclient.cpp
@@ -0,0 +1,88 @@
+/*
+* Copyright (c) 2013 The Linux Foundation. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+*    * Redistributions of source code must retain the above copyright
+*      notice, this list of conditions and the following disclaimer.
+*    * Redistributions in binary form must reproduce the above
+*      copyright notice, this list of conditions and the following
+*      disclaimer in the documentation and/or other materials provided
+*      with the distribution.
+*    * Neither the name of The Linux Foundation. nor the names of its
+*      contributors may be used to endorse or promote products derived
+*      from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+* ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include <dlfcn.h>
+#include "hwc_vpuclient.h"
+#include "hwc_utils.h"
+#include <vpu/vpu.h>
+
+
+using namespace vpu;
+namespace qhwc {
+
+VPUClient::VPUClient()
+{
+    mVPULib = dlopen("libvpu.so", RTLD_NOW);
+    VPU* (*init)();
+    *(void **) &init =  dlsym(mVPULib, "getObject");
+    if(init)
+        mVPU = init();
+    else
+        mVPU = NULL;
+}
+
+VPUClient::~VPUClient()
+{
+    void (*destroy) (VPU*);
+    *(void **) &destroy = dlsym(mVPULib, "deleteObject");
+    dlclose(mVPULib);
+}
+
+int VPUClient::prepare(hwc_context_t *ctx,
+                                hwc_display_contents_1_t* list)
+{
+    int err = 0;
+    if(!mVPU)
+        return err;
+    // * Check VPU status
+    // * Check session availability
+    // * Other individual checks
+    // Do not pass hwc context/list
+    // Mark buffers to be drawn for VPU
+    return err;
+}
+
+int VPUClient::draw(hwc_context_t *ctx,
+                             hwc_display_contents_1_t* list)
+{
+    int err = 0;
+    if(!mVPU)
+        return err;
+    // Queue buffers to VPU
+    return err;
+}
+
+int VPUClient::processCommand(uint32_t command, uint32_t setting)
+{
+    if(!mVPU)
+        return 0;
+    return mVPU->processCommand(command, setting);
+}
+
+}; // namespace qhwc
diff --git a/libhwcomposer/hwc_vpuclient.h b/libhwcomposer/hwc_vpuclient.h
new file mode 100644
index 0000000..8cc7137
--- /dev/null
+++ b/libhwcomposer/hwc_vpuclient.h
@@ -0,0 +1,63 @@
+/*
+* Copyright (c) 2013 The Linux Foundation. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+*    * Redistributions of source code must retain the above copyright
+*      notice, this list of conditions and the following disclaimer.
+*    * Redistributions in binary form must reproduce the above
+*      copyright notice, this list of conditions and the following
+*      disclaimer in the documentation and/or other materials provided
+*      with the distribution.
+*    * Neither the name of The Linux Foundation. nor the names of its
+*      contributors may be used to endorse or promote products derived
+*      from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+* ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef HWC_VPU_H
+#define HWC_VPU_H
+
+#include <sys/types.h>
+
+//Forward declarations
+struct hwc_display_contents_1;
+typedef struct hwc_display_contents_1 hwc_display_contents_1_t;
+struct hwc_context_t;
+namespace vpu {
+class VPU;
+};
+
+namespace qhwc {
+
+class VPUClient {
+public:
+    VPUClient();
+
+    ~VPUClient();
+
+    int prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list);
+
+    int draw(hwc_context_t *ctx, hwc_display_contents_1_t* list);
+
+    int processCommand(uint32_t command, uint32_t setting);
+
+private:
+    vpu::VPU *mVPU;
+    void* mVPULib;
+
+}; // class VPU
+}; // namespace qhwc
+#endif /* end of include guard: HWC_VPU_H */