widi: Asynchronous color conversion

BZ: 183345

Hwcomposer's prepare() and commit() methods run as part of
SurfaceFlinger's main render loop. A synchronous color conversion
blit is being performed in VirtualDevice::commit() while in clone
mode. To prevent this blit from slowing down SurfaceFlinger's main
render loop, I move color conversion and frame submitting to a
dedicated thread.

Only one frame can be queued at a time, so VirtualDevice::commit()
will still block if the previous blit hasn't completed yet. But most
of the time, this won't happen because the previous blit will already
be done by the time of the next commit().

Ideally, we would start the blit in the main thread and wait for
completion in the other thread, but we don't have an API to do that.
So starting the blit is also deferred to the other thread and the
synchronous blit operation is used.

Change-Id: Icccaf1670a01c53a9589c58bc47babe69a4df463
Signed-off-by: Brian Rogers <brian.e.rogers@intel.com>
diff --git a/include/VirtualDevice.h b/include/VirtualDevice.h
index 120ea08..9953209 100644
--- a/include/VirtualDevice.h
+++ b/include/VirtualDevice.h
@@ -29,6 +29,9 @@
 #define VIRTUAL_DEVICE_H
 
 #include <IDisplayDevice.h>
+#include <SimpleThread.h>
+#include <utils/Condition.h>
+#include <utils/Mutex.h>
 #include "IFrameServer.h"
 
 namespace android {
@@ -84,6 +87,20 @@
     uint32_t mCscWidth;
     uint32_t mCscHeight;
 
+    // async blit info
+    DECLARE_THREAD(WidiBlitThread, VirtualDevice);
+    Condition mRequestQueued;
+    Condition mRequestProcessed;
+    uint32_t mBlitSrcHandle;
+    uint32_t mBlitDestHandle;
+    uint32_t mBlitCropWidth;
+    uint32_t mBlitCropHeight;
+    bool mDoBlit;
+    // async onFrameReady info
+    int64_t mFrameReadyRenderTs;
+    bool mDoOnFrameReady;
+    bool mCancelOnFrameReady;
+
     FrameInfo mLastInputFrameInfo;
     FrameInfo mLastOutputFrameInfo;