swapchain: add query for MaxBufferCount

The current vkCreateSwapchainKHR use the hard coded maxImageCount from
GetPhysicalDeviceSurfaceCapabilitiesKHR, which results in possible
conflicts with the maxBufferCount set by BufferQueueConsumer. Thus add
a query to grab the consumer set maxBufferCount into maxImageCount of
surface capability.

Test: adb shell setprop debug.hwui.renderer skiavk
Test: open Play store search and click on apps
Bug: b/71894146
Change-Id: Iba75d977b13a849b62e6c4f259f7ca519ac26db8
diff --git a/vulkan/libvulkan/swapchain.cpp b/vulkan/libvulkan/swapchain.cpp
index 9fbde8c..9266b12 100644
--- a/vulkan/libvulkan/swapchain.cpp
+++ b/vulkan/libvulkan/swapchain.cpp
@@ -573,8 +573,15 @@
     }
 
     // TODO(jessehall): Figure out what the min/max values should be.
+    int max_buffer_count;
+    err = window->query(window, NATIVE_WINDOW_MAX_BUFFER_COUNT, &max_buffer_count);
+    if (err != 0) {
+        ALOGE("NATIVE_WINDOW_MAX_BUFFER_COUNT query failed: %s (%d)",
+              strerror(-err), err);
+        return VK_ERROR_SURFACE_LOST_KHR;
+    }
     capabilities->minImageCount = 2;
-    capabilities->maxImageCount = 3;
+    capabilities->maxImageCount = static_cast<uint32_t>(max_buffer_count);
 
     capabilities->currentExtent =
         VkExtent2D{static_cast<uint32_t>(width), static_cast<uint32_t>(height)};