(Reland) Make Gfxstream VK Buffer setup not depend on GL

... and instead have FrameBuffer send the size directly.

Remove VkCommonOperations usage of FrameBuffer.

Reland note: no changes from previous aosp/2385355.

Bug: b/233939967
Test: android build
Test: cmake build
Test: cvd start --gpu_mode=gfxstream
Test: gfxstream unit tests
Change-Id: I82a28a83e6bc5f70953dd4730dabaa721184e4ac
diff --git a/stream-servers/FrameBuffer.cpp b/stream-servers/FrameBuffer.cpp
index 95c4326..04b344f 100644
--- a/stream-servers/FrameBuffer.cpp
+++ b/stream-servers/FrameBuffer.cpp
@@ -1145,59 +1145,42 @@
 }
 
 HandleType FrameBuffer::createBuffer(uint64_t p_size, uint32_t memoryProperty) {
-    HandleType handle = 0;
-    {
-        AutoLock mutex(m_lock);
-        // Hold the ColorBuffer map lock so that the new handle won't collide with a ColorBuffer
-        // handle.
-        AutoLock colorBufferMapLock(m_colorBufferMapLock);
-        handle = createBufferWithHandleLocked(p_size, genHandle_locked());
-    }
-
-    bool setupStatus =
-            goldfish_vk::setupVkBuffer(handle, /* vulkanOnly */ true, memoryProperty);
-    assert(setupStatus);
-    return handle;
+    AutoLock mutex(m_lock);
+    AutoLock colorBufferMapLock(m_colorBufferMapLock);
+    return createBufferWithHandleLocked(p_size, genHandle_locked(), memoryProperty);
 }
 
 void FrameBuffer::createBufferWithHandle(uint64_t size, HandleType handle) {
-    {
-        AutoLock mutex(m_lock);
-        AutoLock colorBufferMapLock(m_colorBufferMapLock);
+    AutoLock mutex(m_lock);
+    AutoLock colorBufferMapLock(m_colorBufferMapLock);
 
-        // Check for handle collision
-        if (m_buffers.count(handle) != 0) {
-            GFXSTREAM_ABORT(FatalError(ABORT_REASON_OTHER))
-                << "Buffer already exists with handle " << handle;
-        }
-
-        handle = createBufferWithHandleLocked(size, handle);
-        if (!handle) {
-            return;
-        }
+    if (m_buffers.count(handle) != 0) {
+        GFXSTREAM_ABORT(FatalError(ABORT_REASON_OTHER))
+            << "Buffer already exists with handle " << handle;
     }
 
-    if (m_displayVk || m_guestUsesAngle) {
-        goldfish_vk::setupVkBuffer(handle, /* vulkanOnly */ true,
-                                   VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
-    }
+    createBufferWithHandleLocked(size, handle, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
 }
 
-HandleType FrameBuffer::createBufferWithHandleLocked(int p_size,
-                                                     HandleType handle) {
+HandleType FrameBuffer::createBufferWithHandleLocked(int p_size, HandleType handle,
+                                                     uint32_t memoryProperty) {
     if (m_buffers.count(handle) != 0) {
         GFXSTREAM_ABORT(FatalError(ABORT_REASON_OTHER))
             << "Buffer already exists with handle " << handle;
     }
 
     BufferPtr buffer(Buffer::create(p_size, handle, getPbufferSurfaceContextHelper()));
-
-    if (buffer) {
-        m_buffers[handle] = {std::move(buffer)};
-    } else {
-        handle = 0;
+    if (!buffer) {
         ERR("Create buffer failed.\n");
+        return 0;
     }
+
+    m_buffers[handle] = {std::move(buffer)};
+
+    if (m_displayVk || m_guestUsesAngle) {
+        goldfish_vk::setupVkBuffer(handle, /* vulkanOnly */ true, memoryProperty);
+    }
+
     return handle;
 }
 
diff --git a/stream-servers/FrameBuffer.h b/stream-servers/FrameBuffer.h
index 126576a..5fb0349 100644
--- a/stream-servers/FrameBuffer.h
+++ b/stream-servers/FrameBuffer.h
@@ -699,7 +699,7 @@
     HandleType createColorBufferWithHandleLocked(int p_width, int p_height, GLenum p_internalFormat,
                                                  FrameworkFormat p_frameworkFormat,
                                                  HandleType handle);
-    HandleType createBufferWithHandleLocked(int p_size, HandleType handle);
+    HandleType createBufferWithHandleLocked(int p_size, HandleType handle, uint32_t memoryProperty);
 
     void recomputeLayout();
     void setDisplayPoseInSkinUI(int totalHeight);
diff --git a/stream-servers/vulkan/VkCommonOperations.cpp b/stream-servers/vulkan/VkCommonOperations.cpp
index f8b8f9a..d91cc44 100644
--- a/stream-servers/vulkan/VkCommonOperations.cpp
+++ b/stream-servers/vulkan/VkCommonOperations.cpp
@@ -25,15 +25,14 @@
 #include <sstream>
 #include <unordered_set>
 
-#include "FrameBuffer.h"
 #include "VkFormatUtils.h"
 #include "VulkanDispatch.h"
-#include "aemu/base/synchronization/Lock.h"
-#include "aemu/base/containers/Lookup.h"
 #include "aemu/base/Optional.h"
-#include "aemu/base/containers/StaticMap.h"
-#include "aemu/base/system/System.h"
 #include "aemu/base/Tracing.h"
+#include "aemu/base/containers/Lookup.h"
+#include "aemu/base/containers/StaticMap.h"
+#include "aemu/base/synchronization/Lock.h"
+#include "aemu/base/system/System.h"
 #include "common/goldfish_vk_dispatch.h"
 #include "host-common/GfxstreamFatalError.h"
 #include "host-common/emugl_vm_operations.h"
@@ -1504,6 +1503,9 @@
     return true;
 }
 
+// From ANGLE "src/common/angleutils.h"
+#define GL_BGR10_A2_ANGLEX 0x6AF9
+
 static VkFormat glFormat2VkFormat(GLint internalFormat) {
     switch (internalFormat) {
         case GL_R8:
@@ -2505,20 +2507,13 @@
     return true;
 }
 
-bool setupVkBuffer(uint32_t bufferHandle, bool vulkanOnly, uint32_t memoryProperty, bool* exported,
-                   VkDeviceSize* allocSize, uint32_t* typeIndex) {
+bool setupVkBuffer(uint64_t size, uint32_t bufferHandle, bool vulkanOnly, uint32_t memoryProperty) {
     if (vulkanOnly == false) {
-        fprintf(stderr, "Data buffers should be vulkanOnly. Setup failed.\n");
+        VK_COMMON_ERROR("Data buffers should be vulkanOnly. Setup failed.");
         return false;
     }
 
     auto vk = sVkEmulation->dvk;
-    auto fb = FrameBuffer::getFB();
-
-    int size;
-    if (!fb->getBufferInfo(bufferHandle, &size)) {
-        return false;
-    }
 
     AutoLock lock(sVkEmulationLock);
 
@@ -2526,12 +2521,6 @@
 
     // Already setup
     if (infoPtr) {
-        // Update the allocation size to what the host driver wanted, or we
-        // might get VK_ERROR_OUT_OF_DEVICE_MEMORY and a host crash
-        if (allocSize) *allocSize = infoPtr->memory.size;
-        // Update the type index to what the host driver wanted, or we might
-        // get VK_ERROR_DEVICE_LOST
-        if (typeIndex) *typeIndex = infoPtr->memory.typeIndex;
         return true;
     }
 
@@ -2639,9 +2628,6 @@
     }
 
     res.glExported = false;
-    if (exported) *exported = res.glExported;
-    if (allocSize) *allocSize = res.memory.size;
-    if (typeIndex) *typeIndex = res.memory.typeIndex;
 
     sVkEmulation->buffers[bufferHandle] = res;
     return allocRes;
diff --git a/stream-servers/vulkan/VkCommonOperations.h b/stream-servers/vulkan/VkCommonOperations.h
index 021ae2f..88b5afc 100644
--- a/stream-servers/vulkan/VkCommonOperations.h
+++ b/stream-servers/vulkan/VkCommonOperations.h
@@ -454,9 +454,8 @@
 bool getBufferAllocationInfo(uint32_t bufferHandle, VkDeviceSize* outSize,
                              uint32_t* outMemoryTypeIndex);
 
-bool setupVkBuffer(uint32_t bufferHandle, bool vulkanOnly = false, uint32_t memoryProperty = 0,
-                   bool* exported = nullptr, VkDeviceSize* allocSize = nullptr,
-                   uint32_t* typeIndex = nullptr);
+bool setupVkBuffer(uint64_t size, uint32_t bufferHandle, bool vulkanOnly = false,
+                   uint32_t memoryProperty = 0);
 bool teardownVkBuffer(uint32_t bufferHandle);
 VK_EXT_MEMORY_HANDLE getBufferExtMemoryHandle(uint32_t bufferHandle);