(Reland) Remove non-createColorBuffer() uses of setupVkColorBuffer

... to support upcoming changes which hope to make Gfxstream VK
not depend on Gfxstream GL which aims to allow running Gfxstream
without host GL.

* vkRegisterImageColorBufferGOOGLE() is believed to be unused so
  on_vkRegisterImageColorBufferGOOGLE() marked as deprecated.

* vkRegisterBufferColorBufferGOOGLE() is believed to be unused so
  on_vkRegisterBufferColorBufferGOOGLE() marked as deprecated.

* rcSetColorBufferVulkanMode2() should already require the existence
  of the ColorBuffer in question because setupVkColorBuffer()
  currently depends on the GL ColorBuffer already existing.

* on_vkAllocateMemory() for importing memory from an existing
  Buffer/ColorBuffer should already require the existence of the
  Buffer/ColorBuffer because setupVkColorBuffer() currently depends
  on the GL ColorBuffer already existing.

The reland has no changes versus the original change (aosp/2264928)
but is included as a part of this topic. This change relies on
ColorBuffer creation not being deferred (which was previously only
the case when running with DisplayVk or guest ANGLE).

Reland note: no changes from previous aosp/2385353.

Bug: b/233939967
Test: android build
Test: cmake build
Test: cvd start --gpu_mode=gfxstream
Test: gfxstream unit tests
Change-Id: Id196d046c6aedaf2e59e681c930ef9d7766f16bb
diff --git a/stream-servers/vulkan/VkCommonOperations.cpp b/stream-servers/vulkan/VkCommonOperations.cpp
index 9524ba1..49418e0 100644
--- a/stream-servers/vulkan/VkCommonOperations.cpp
+++ b/stream-servers/vulkan/VkCommonOperations.cpp
@@ -1504,8 +1504,8 @@
     return true;
 }
 
-static VkFormat glFormat2VkFormat(GLint internalformat) {
-    switch (internalformat) {
+static VkFormat glFormat2VkFormat(GLint internalFormat) {
+    switch (internalFormat) {
         case GL_R8:
         case GL_LUMINANCE:
             return VK_FORMAT_R8_UNORM;
@@ -1539,7 +1539,7 @@
             return VK_FORMAT_R8G8_UNORM;
         default:
             VK_COMMON_ERROR("Unhandled format %d, falling back to VK_FORMAT_R8G8B8A8_UNORM",
-                            internalformat);
+                            internalFormat);
             return VK_FORMAT_R8G8B8A8_UNORM;
     }
 };
@@ -1566,6 +1566,50 @@
     return false;
 }
 
+bool isColorBufferExportedToGl(uint32_t colorBufferHandle, bool* exported) {
+    if (!sVkEmulation || !sVkEmulation->live) {
+        GFXSTREAM_ABORT(FatalError(ABORT_REASON_OTHER)) << "Vulkan emulation not available.";
+    }
+
+    AutoLock lock(sVkEmulationLock);
+
+    auto info = android::base::find(sVkEmulation->colorBuffers, colorBufferHandle);
+    if (!info) {
+        return false;
+    }
+
+    *exported = info->glExported;
+    return true;
+}
+
+bool getColorBufferAllocationInfo(uint32_t colorBufferHandle, VkDeviceSize* outSize,
+                                  uint32_t* outMemoryTypeIndex, void** outMappedPtr) {
+    if (!sVkEmulation || !sVkEmulation->live) {
+        GFXSTREAM_ABORT(FatalError(ABORT_REASON_OTHER)) << "Vulkan emulation not available.";
+    }
+
+    AutoLock lock(sVkEmulationLock);
+
+    auto info = android::base::find(sVkEmulation->colorBuffers, colorBufferHandle);
+    if (!info) {
+        return false;
+    }
+
+    if (outSize) {
+        *outSize = info->memory.size;
+    }
+
+    if (outMemoryTypeIndex) {
+        *outMemoryTypeIndex = info->memory.typeIndex;
+    }
+
+    if (outMappedPtr) {
+        *outMappedPtr = info->memory.mappedPtr;
+    }
+
+    return true;
+}
+
 static uint32_t lastGoodTypeIndex(uint32_t indices) {
     for (int32_t i = 31; i >= 0; --i) {
         if (indices & (1 << i)) {
@@ -1677,21 +1721,17 @@
 // We should make it so the guest can only allocate external images/
 // buffers of one type index for image and one type index for buffer
 // to begin with, via filtering from the host.
-bool setupVkColorBuffer(uint32_t colorBufferHandle, bool vulkanOnly, uint32_t memoryProperty,
-                        bool* exported, VkDeviceSize* allocSize, uint32_t* typeIndex,
-                        void** mappedPtr) {
+bool setupVkColorBuffer(uint32_t colorBufferHandle, bool vulkanOnly, uint32_t memoryProperty) {
     if (!isColorBufferVulkanCompatible(colorBufferHandle)) return false;
 
-    auto vk = sVkEmulation->dvk;
-
     auto fb = FrameBuffer::getFB();
 
     int width;
     int height;
-    GLint internalformat;
+    GLint internalFormat;
     FrameworkFormat frameworkFormat;
 
-    if (!fb->getColorBufferInfo(colorBufferHandle, &width, &height, &internalformat,
+    if (!fb->getColorBufferInfo(colorBufferHandle, &width, &height, &internalFormat,
                                 &frameworkFormat)) {
         return false;
     }
@@ -1702,18 +1742,6 @@
 
     // Already setup
     if (infoPtr) {
-        // Setting exported is required for on_vkCreateImage backed by
-        // an AHardwareBuffer.
-        if (exported) *exported = infoPtr->glExported;
-        // 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;
-        // Update the mappedPtr to what the host driver wanted, otherwise we
-        // may map the same memory twice.
-        if (mappedPtr) *mappedPtr = infoPtr->memory.mappedPtr;
         return true;
     }
 
@@ -1721,7 +1749,7 @@
     bool glCompatible = (frameworkFormat == FRAMEWORK_FORMAT_GL_COMPATIBLE);
     switch (frameworkFormat) {
         case FrameworkFormat::FRAMEWORK_FORMAT_GL_COMPATIBLE:
-            vkFormat = glFormat2VkFormat(internalformat);
+            vkFormat = glFormat2VkFormat(internalFormat);
             break;
         case FrameworkFormat::FRAMEWORK_FORMAT_NV12:
             vkFormat = VK_FORMAT_G8_B8R8_2PLANE_420_UNORM;
@@ -1734,8 +1762,8 @@
             vkFormat = VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM;
             break;
         default:
-            vkFormat = glFormat2VkFormat(internalformat);
-            fprintf(stderr, "WARNING: unsupported framework format %d\n", frameworkFormat);
+            VK_COMMON_ERROR("WARNING: unhandled framework format %d\n", frameworkFormat);
+            vkFormat = glFormat2VkFormat(internalFormat);
             break;
     }
 
@@ -1773,6 +1801,8 @@
 
     imageCi->pNext = extImageCiPtr;
 
+    auto vk = sVkEmulation->dvk;
+
     VkResult createRes =
         vk->vkCreateImage(sVkEmulation->device, imageCi.get(), nullptr, &res.image);
     if (createRes != VK_SUCCESS) {
@@ -1888,11 +1918,6 @@
         res.vulkanMode = VkEmulation::VulkanMode::VulkanOnly;
     }
 
-    if (exported) *exported = res.glExported;
-    if (allocSize) *allocSize = res.memory.size;
-    if (typeIndex) *typeIndex = res.memory.typeIndex;
-    if (mappedPtr) *mappedPtr = res.memory.mappedPtr;
-
     sVkEmulation->colorBuffers[colorBufferHandle] = res;
     return true;
 }
@@ -2453,6 +2478,30 @@
     return memoryInfoPtr->pageOffset;
 }
 
+bool getBufferAllocationInfo(uint32_t bufferHandle, VkDeviceSize* outSize,
+                             uint32_t* outMemoryTypeIndex) {
+    if (!sVkEmulation || !sVkEmulation->live) {
+        GFXSTREAM_ABORT(FatalError(ABORT_REASON_OTHER)) << "Vulkan emulation not available.";
+    }
+
+    AutoLock lock(sVkEmulationLock);
+
+    auto info = android::base::find(sVkEmulation->buffers, bufferHandle);
+    if (!info) {
+        return false;
+    }
+
+    if (outSize) {
+        *outSize = info->memory.size;
+    }
+
+    if (outMemoryTypeIndex) {
+        *outMemoryTypeIndex = info->memory.typeIndex;
+    }
+
+    return true;
+}
+
 bool setupVkBuffer(uint32_t bufferHandle, bool vulkanOnly, uint32_t memoryProperty, bool* exported,
                    VkDeviceSize* allocSize, uint32_t* typeIndex) {
     if (vulkanOnly == false) {