widi: Optimize widi presentation mode path

BZ: 123991

Currently BG/presentation mode video playback is streamed at local display resolution
instead of content resolution. This is resulted in unnecessary scaling and color conversions.

This patch optimizes BG mode video playback path and RGB data path if
1. There is only one RGB or NV12 layer and this layer is not in the Primary display layers
2. there is no transformation and
3. there is no blending

These optimizations are done by setting overlay flag when the above conditions are met.

If the layer is NV12, HWC sends the decoder's khandles to Widi pipeline(same as in extended mode).
If the layer is RGB, we allocate NV12 buffers to blit the RGB framebuffer into, and then
send those buffers to widi pipeline.

Signed-off-by: mamatha balguri <mamatha.balguri@intel.com>
Change-Id: Ia108f263b749087992f71be03114489e8428f20b
Reviewed-on: http://android.intel.com:8080/119106
Reviewed-by: Crabtree, Robert <robert.crabtree@intel.com>
Reviewed-by: Qiu, Junhai <junhai.qiu@intel.com>
Tested-by: Sun, Hang L <hang.l.sun@intel.com>
Reviewed-by: cactus <cactus@intel.com>
Tested-by: cactus <cactus@intel.com>
diff --git a/include/VirtualDevice.h b/include/VirtualDevice.h
index 0a5c47e..372ac94 100644
--- a/include/VirtualDevice.h
+++ b/include/VirtualDevice.h
@@ -28,7 +28,6 @@
 #ifndef VIRTUAL_DEVICE_H
 #define VIRTUAL_DEVICE_H
 
-
 #include <IDisplayDevice.h>
 #include "IFrameServer.h"
 
@@ -42,11 +41,23 @@
 class VirtualDevice : public IDisplayDevice, public BnFrameServer {
 protected:
     struct CachedBuffer : public android::RefBase {
-        CachedBuffer(BufferManager *mgr, buffer_handle_t handle);
+        CachedBuffer(BufferManager *mgr, uint32_t handle);
         ~CachedBuffer();
         BufferManager *manager;
         BufferMapper *mapper;
     };
+    struct HeldCscBuffer : public android::RefBase {
+        HeldCscBuffer(const android::sp<VirtualDevice>& vd, uint32_t handle);
+        virtual ~HeldCscBuffer();
+        android::sp<VirtualDevice> vd;
+        uint32_t handle;
+    };
+    struct HeldDecoderBuffer : public android::RefBase {
+        HeldDecoderBuffer(const sp<VirtualDevice>& vd, const android::sp<CachedBuffer>& cachedBuffer);
+        virtual ~HeldDecoderBuffer();
+        android::sp<VirtualDevice> vd;
+        android::sp<CachedBuffer> cachedBuffer;
+    };
     struct Configuration {
         sp<IFrameTypeChangeListener> typeChangeListener;
         sp<IFrameListener> frameListener;
@@ -57,19 +68,30 @@
     Mutex mConfigLock;
     Configuration mCurrentConfig;
     Configuration mNextConfig;
+    size_t mLayerToSend;
 
     uint32_t mExtLastKhandle;
     int64_t mExtLastTimestamp;
 
-    Mutex mListenerLock;
-    FrameInfo mLastFrameInfo;
+    int64_t mRenderTimestamp;
 
-    android::KeyedVector<buffer_handle_t, android::sp<CachedBuffer> > mDisplayBufferCache;
+    // colorspace conversion
+    Mutex mCscLock;
+    android::List<uint32_t> mAvailableCscBuffers;
+    int mCscBuffersToCreate;
+    uint32_t mCscWidth;
+    uint32_t mCscHeight;
+
+    FrameInfo mLastInputFrameInfo;
+    FrameInfo mLastOutputFrameInfo;
+
+    android::KeyedVector<uint32_t, android::sp<CachedBuffer> > mMappedBufferCache;
     android::Mutex mHeldBuffersLock;
-    android::KeyedVector<uint32_t, android::sp<CachedBuffer> > mHeldBuffers;
+    android::KeyedVector<uint32_t, android::sp<android::RefBase> > mHeldBuffers;
 
 private:
-    android::sp<CachedBuffer> getDisplayBuffer(buffer_handle_t handle);
+    android::sp<CachedBuffer> getMappedBuffer(uint32_t handle);
+    void sendToWidi(const hwc_layer_1_t& layer);
 
 public:
     VirtualDevice(Hwcomposer& hwc, DisplayPlaneManager& dpm);