Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8f8deb20 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Use VkAndroidHardwareBufferUsageANDROID to compute HWUI usage flags"

parents 1e480e30 31c1b82a
Loading
Loading
Loading
Loading
+38 −5
Original line number Diff line number Diff line
@@ -256,11 +256,44 @@ VulkanSurface* VulkanSurface::Create(ANativeWindow* window, ColorMode colorMode,
        vkPixelFormat = VK_FORMAT_R16G16B16A16_SFLOAT;
    }

    uint64_t producerUsage =
            AHARDWAREBUFFER_USAGE_GPU_FRAMEBUFFER | AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE;
    uint64_t consumerUsage;
    native_window_get_consumer_usage(window, &consumerUsage);
    windowInfo.windowUsageFlags = consumerUsage | producerUsage;
    if (nullptr != vkManager.mGetPhysicalDeviceImageFormatProperties2) {
        VkPhysicalDeviceExternalImageFormatInfo externalImageFormatInfo;
        externalImageFormatInfo.sType =
                VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_IMAGE_FORMAT_INFO;
        externalImageFormatInfo.pNext = nullptr;
        externalImageFormatInfo.handleType =
                VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID;

        VkPhysicalDeviceImageFormatInfo2 imageFormatInfo;
        imageFormatInfo.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2;
        imageFormatInfo.pNext = &externalImageFormatInfo;
        imageFormatInfo.format = vkPixelFormat;
        imageFormatInfo.type = VK_IMAGE_TYPE_2D;
        imageFormatInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
        imageFormatInfo.usage = usageFlags;
        imageFormatInfo.flags = 0;

        VkAndroidHardwareBufferUsageANDROID hwbUsage;
        hwbUsage.sType = VK_STRUCTURE_TYPE_ANDROID_HARDWARE_BUFFER_USAGE_ANDROID;
        hwbUsage.pNext = nullptr;

        VkImageFormatProperties2 imgFormProps;
        imgFormProps.sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_PROPERTIES_2;
        imgFormProps.pNext = &hwbUsage;

        res = vkManager.mGetPhysicalDeviceImageFormatProperties2(vkManager.mPhysicalDevice,
                                                                 &imageFormatInfo, &imgFormProps);
        if (VK_SUCCESS != res) {
            ALOGE("Failed to query GetPhysicalDeviceImageFormatProperties2");
            return nullptr;
        }

        windowInfo.windowUsageFlags = hwbUsage.androidHardwareBufferUsage;

    } else {
        ALOGE("VulkanSurface::Create() vkmGetPhysicalDeviceImageFormatProperties2 is missing");
        return nullptr;
    }

    /*
     * Now we attempt to modify the window!