vulkan: Add gralloc1 usage to VK_ANDROID_native_buffer
Replaces the gralloc0-style 'int' usage in
vkGetSwapchainGrallocUsage2ANDROID and VkNativeBufferANDROID with a
gralloc1-style pair of uint64_t usages. A later change will plumb this
to and from ANativeWindow; for now we just collapse and expand from
32-bit usage.
Test: vulkanGears
Change-Id: I4555ba9d6ca1d15ed0791dc0bda01a1443890d02
diff --git a/vulkan/libvulkan/swapchain.cpp b/vulkan/libvulkan/swapchain.cpp
index f4ee375..e18968c 100644
--- a/vulkan/libvulkan/swapchain.cpp
+++ b/vulkan/libvulkan/swapchain.cpp
@@ -812,13 +812,19 @@
int gralloc_usage = 0;
if (dispatch.GetSwapchainGrallocUsage2ANDROID) {
+ uint64_t consumer_usage, producer_usage;
result = dispatch.GetSwapchainGrallocUsage2ANDROID(
device, create_info->imageFormat, create_info->imageUsage,
- swapchain_image_usage, &gralloc_usage);
+ swapchain_image_usage, &consumer_usage, &producer_usage);
if (result != VK_SUCCESS) {
ALOGE("vkGetSwapchainGrallocUsage2ANDROID failed: %d", result);
return VK_ERROR_INITIALIZATION_FAILED;
}
+ // TODO: This is the same translation done by Gralloc1On0Adapter.
+ // Remove it once ANativeWindow has been updated to take gralloc1-style
+ // usages.
+ gralloc_usage =
+ static_cast<int>(consumer_usage) | static_cast<int>(producer_usage);
} else if (dispatch.GetSwapchainGrallocUsageANDROID) {
result = dispatch.GetSwapchainGrallocUsageANDROID(
device, create_info->imageFormat, create_info->imageUsage,
@@ -827,8 +833,6 @@
ALOGE("vkGetSwapchainGrallocUsageANDROID failed: %d", result);
return VK_ERROR_INITIALIZATION_FAILED;
}
- } else {
- gralloc_usage = GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE;
}
err = native_window_set_usage(surface.window.get(), gralloc_usage);
if (err != 0) {
@@ -918,6 +922,12 @@
image_native_buffer.stride = img.buffer->stride;
image_native_buffer.format = img.buffer->format;
image_native_buffer.usage = img.buffer->usage;
+ // TODO: Adjust once ANativeWindowBuffer supports gralloc1-style usage.
+ // For now, this is the same translation Gralloc1On0Adapter does.
+ image_native_buffer.usage2.consumer =
+ static_cast<uint64_t>(img.buffer->usage);
+ image_native_buffer.usage2.producer =
+ static_cast<uint64_t>(img.buffer->usage);
result =
dispatch.CreateImage(device, &image_create, nullptr, &img.image);