In Vk DeferredLayerUpdater make sure we releause buffers to foreign queue.

For Vulkan we need to make sure that when we draw AHBs we must
transition them to and from the foreign queue so that the producer is
able to write new data to them and we are able to see the new writes.

Test: Manual running of Lens app
Bug: 178773035
Change-Id: I807709d2b671bf5a01a82237f3b5838734f0d978
diff --git a/libs/hwui/DeferredLayerUpdater.h b/libs/hwui/DeferredLayerUpdater.h
index 6731e9c..8f79c4e 100644
--- a/libs/hwui/DeferredLayerUpdater.h
+++ b/libs/hwui/DeferredLayerUpdater.h
@@ -20,9 +20,12 @@
 #include <SkImage.h>
 #include <SkMatrix.h>
 #include <android/hardware_buffer.h>
-#include <cutils/compiler.h>
 #include <android/surface_texture.h>
+#include <cutils/compiler.h>
+#include <utils/Errors.h>
 
+#include <EGL/egl.h>
+#include <EGL/eglext.h>
 #include <map>
 #include <memory>
 
@@ -103,13 +106,16 @@
      */
     class ImageSlot {
     public:
-        ~ImageSlot() { clear(); }
+        ~ImageSlot() {}
 
         sk_sp<SkImage> createIfNeeded(AHardwareBuffer* buffer, android_dataspace dataspace,
                                       bool forceCreate, GrDirectContext* context);
 
+        void releaseQueueOwnership(GrDirectContext* context);
+
+        void clear(GrDirectContext* context);
+
     private:
-        void clear();
 
         // the dataspace associated with the current image
         android_dataspace mDataspace = HAL_DATASPACE_UNKNOWN;
@@ -123,6 +129,10 @@
         AutoBackendTextureRelease* mTextureRelease = nullptr;
     };
 
+    static status_t createReleaseFence(bool useFenceSync, EGLSyncKHR* eglFence, EGLDisplay* display,
+                                       int* releaseFence, void* handle);
+    static status_t fenceWait(int fence, void* handle);
+
     /**
      * DeferredLayerUpdater stores the SkImages that have been allocated by the BufferQueue
      * for each buffer slot.
@@ -142,6 +152,7 @@
     SkMatrix* mTransform;
     bool mGLContextAttached;
     bool mUpdateTexImage;
+    int mCurrentSlot = -1;
 
     Layer* mLayer;
 };