hwc: vpuclient: vpuClient implementation

Vpuclient is the client side for VFM in hwc. It follows the
similar pattern of prepare and draw. It has 2 step prepare
including: setVpuSession and prepare. The setVpuSession function
passes all the layers from the SF list to VFM, which marks
the layers that it can support. After this, the layer
allocation/configuration is done, and finally in prepare the
allocated pipes are passed down to VFM. The draw function
passes the handle to the VFM to draw the video layer.

Change-Id: I5d8795de35ed98716f7fa4cd48506b488cb3cb5d
diff --git a/libhwcomposer/hwc_vpuclient.h b/libhwcomposer/hwc_vpuclient.h
index 9985517..bb2a4b6 100644
--- a/libhwcomposer/hwc_vpuclient.h
+++ b/libhwcomposer/hwc_vpuclient.h
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2013 The Linux Foundation. All rights reserved.
+* Copyright (c) 2013-2014 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
@@ -31,13 +31,20 @@
 #define HWC_VPU_H
 
 #include <sys/types.h>
+#include "hwc_utils.h"
+
+#define MAX_PIPES_PER_LAYER 2
 
 //Forward declarations
 struct hwc_display_contents_1;
 typedef struct hwc_display_contents_1 hwc_display_contents_1_t;
+struct hwc_layer_1;
+typedef struct hwc_layer_1 hwc_layer_1_t;
 struct hwc_context_t;
+
 namespace vpu {
 class VPU;
+struct LayerList;
 };
 namespace android {
 class Parcel;
@@ -47,21 +54,91 @@
 
 class VPUClient {
 public:
-    VPUClient();
+    VPUClient(hwc_context_t *ctx);
 
     ~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 setupVpuSession(hwc_context_t *ctx, int display,
+                            hwc_display_contents_1_t* list);
+    int prepare(hwc_context_t *ctx, int display,
+                            hwc_display_contents_1_t* list);
+    int predraw(hwc_context_t *ctx, int display,
+                            hwc_display_contents_1_t* list);
+    int draw(hwc_context_t *ctx, int display,
+                            hwc_display_contents_1_t* list);
     int processCommand(uint32_t command,
-            const android::Parcel* inParcel, android::Parcel* outParcel);
+        const android::Parcel* inParcel, android::Parcel* outParcel);
+    int getLayerFormat(int dpy, hwc_layer_1_t *layer);
+    int getWidth(int dpy, hwc_layer_1_t *layer);
+    int getHeight(int dpy, hwc_layer_1_t *layer);
+    bool supportedVPULayer(int dpy, hwc_layer_1_t *layer);
 
 private:
     vpu::VPU *mVPU;
     void* mVPULib;
 
+    /* VpuLayerProp struct:
+     *  This struct corresponds to only one layer
+     *  pipeCount: number of pipes required for a layer
+     *  pipeID[]: pipe ids corresponding to the layer
+     */
+    struct VpuLayerProp {
+        int format;
+        int width;
+        int height;
+        int pipeCount;
+        bool vpuLayer;
+        bool firstBuffer;
+        hwc_frect_t sourceCropf;
+        hwc_layer_1_t *layer;
+        int pipeID[MAX_PIPES_PER_LAYER];
+        int dest[MAX_PIPES_PER_LAYER];
+    };
+    int mNumVpuLayers;  /* total num of vpu supported layers */
+    int mGpuFallback;   /* all layers are not supported by vpu */
+
+    VpuLayerProp mProp[HWC_NUM_DISPLAY_TYPES][MAX_NUM_APP_LAYERS];
+    int mDebugLogs;
+    private_handle_t *mHnd[HWC_NUM_DISPLAY_TYPES][MAX_NUM_APP_LAYERS];
+    vpu::LayerList *vList[HWC_NUM_DISPLAY_TYPES];
+
+    /* Private debug functions */
+    int32_t isDebug() { return (mDebugLogs >= 1); }
+    int32_t isDebug2() { return (mDebugLogs >= 2); }
+
+    /* Private Get/Set functions */
+    int getLayerIdx(int dpy, hwc_layer_1_t *layer);
+    void getPipeId(VpuLayerProp* prop, int &pipe);
+    void getPipeId(VpuLayerProp* prop, int &lPipe, int &rPipe);
+    int getDest(VpuLayerProp* prop, int pipenum);
+    void setPipeCount(VpuLayerProp* prop, int count);
+    void setPipeId(VpuLayerProp* prop, int lPipeId, int rPipeId);
+    void setPipeId(VpuLayerProp* prop, int pipeId);
+    void setDest(VpuLayerProp* prop, int lDest, int rDest);
+    void setDest(VpuLayerProp* prop, int dest);
+
+    /* Private implementations */
+    bool supportedVPULayer(VpuLayerProp* prop);
+    bool allocResLayerPipes(hwc_context_t* ctx, int dpy,
+                            hwc_display_contents_1_t* list);
+    bool allocLayerPipes(hwc_context_t* ctx, int dpy,
+                            hwc_display_contents_1_t* list);
+    bool allocResLayerPipesSplit(hwc_context_t* ctx, int dpy,
+                            hwc_display_contents_1_t* list);
+    bool allocLayerPipesSplit(hwc_context_t* ctx, int dpy,
+                            hwc_display_contents_1_t* list);
+    bool configureLayers(hwc_context_t* ctx, int dpy,
+                            hwc_display_contents_1_t* list);
+    bool configureLayersSplit(hwc_context_t* ctx, int dpy,
+                            hwc_display_contents_1_t* list);
+    void setMDPCompLayerFlags(hwc_context_t *ctx, int dpy,
+                            hwc_display_contents_1_t* list);
+    bool drawDummyLayers(hwc_context_t* ctx, int dpy,
+                            hwc_display_contents_1_t* list);
+    bool queueHandle(hwc_context_t* ctx, VpuLayerProp* prop,
+                            private_handle_t* hnd);
+    bool queueHandleSplit(hwc_context_t* ctx, VpuLayerProp* prop,
+                            private_handle_t* hnd);
 }; // class VPU
 }; // namespace qhwc
 #endif /* end of include guard: HWC_VPU_H */