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

Commit a6fc4e5d authored by silence_dogood's avatar silence_dogood Committed by android-build-merger
Browse files

Merge "Vulkan: Fixing return code for vkQueuePresentKHR" into qt-dev

am: 5cada23f

Change-Id: Ib1645fdd419d18f58f742fc95d54eac8cab689b7
parents 65fbc560 5cada23f
Loading
Loading
Loading
Loading
+36 −4
Original line number Original line Diff line number Diff line
@@ -55,6 +55,22 @@ const VkSurfaceTransformFlagsKHR kSupportedTransforms =
    // VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_270_BIT_KHR |
    // VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_270_BIT_KHR |
    VK_SURFACE_TRANSFORM_INHERIT_BIT_KHR;
    VK_SURFACE_TRANSFORM_INHERIT_BIT_KHR;


int TranslateVulkanToNativeTransform(VkSurfaceTransformFlagBitsKHR transform) {
    switch (transform) {
        // TODO: See TODO in TranslateNativeToVulkanTransform
        case VK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR:
            return NATIVE_WINDOW_TRANSFORM_ROT_90;
        case VK_SURFACE_TRANSFORM_ROTATE_180_BIT_KHR:
            return NATIVE_WINDOW_TRANSFORM_ROT_180;
        case VK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR:
            return NATIVE_WINDOW_TRANSFORM_ROT_270;
        case VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR:
        case VK_SURFACE_TRANSFORM_INHERIT_BIT_KHR:
        default:
            return 0;
    }
}

VkSurfaceTransformFlagBitsKHR TranslateNativeToVulkanTransform(int native) {
VkSurfaceTransformFlagBitsKHR TranslateNativeToVulkanTransform(int native) {
    // Native and Vulkan transforms are isomorphic, but are represented
    // Native and Vulkan transforms are isomorphic, but are represented
    // differently. Vulkan transforms are built up of an optional horizontal
    // differently. Vulkan transforms are built up of an optional horizontal
@@ -210,10 +226,12 @@ enum { MIN_NUM_FRAMES_AGO = 5 };
struct Swapchain {
struct Swapchain {
    Swapchain(Surface& surface_,
    Swapchain(Surface& surface_,
              uint32_t num_images_,
              uint32_t num_images_,
              VkPresentModeKHR present_mode)
              VkPresentModeKHR present_mode,
              int pre_transform_)
        : surface(surface_),
        : surface(surface_),
          num_images(num_images_),
          num_images(num_images_),
          mailbox_mode(present_mode == VK_PRESENT_MODE_MAILBOX_KHR),
          mailbox_mode(present_mode == VK_PRESENT_MODE_MAILBOX_KHR),
          pre_transform(pre_transform_),
          frame_timestamps_enabled(false),
          frame_timestamps_enabled(false),
          shared(present_mode == VK_PRESENT_MODE_SHARED_DEMAND_REFRESH_KHR ||
          shared(present_mode == VK_PRESENT_MODE_SHARED_DEMAND_REFRESH_KHR ||
                 present_mode == VK_PRESENT_MODE_SHARED_CONTINUOUS_REFRESH_KHR) {
                 present_mode == VK_PRESENT_MODE_SHARED_CONTINUOUS_REFRESH_KHR) {
@@ -235,6 +253,7 @@ struct Swapchain {
    Surface& surface;
    Surface& surface;
    uint32_t num_images;
    uint32_t num_images;
    bool mailbox_mode;
    bool mailbox_mode;
    int pre_transform;
    bool frame_timestamps_enabled;
    bool frame_timestamps_enabled;
    int64_t refresh_duration;
    int64_t refresh_duration;
    bool shared;
    bool shared;
@@ -1237,9 +1256,9 @@ VkResult CreateSwapchainKHR(VkDevice device,
                                         VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
                                         VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
    if (!mem)
    if (!mem)
        return VK_ERROR_OUT_OF_HOST_MEMORY;
        return VK_ERROR_OUT_OF_HOST_MEMORY;
    Swapchain* swapchain =
    Swapchain* swapchain = new (mem)
        new (mem) Swapchain(surface, num_images, create_info->presentMode);
        Swapchain(surface, num_images, create_info->presentMode,

                  TranslateVulkanToNativeTransform(create_info->preTransform));
    // -- Dequeue all buffers and create a VkImage for each --
    // -- Dequeue all buffers and create a VkImage for each --
    // Any failures during or after this must cancel the dequeued buffers.
    // Any failures during or after this must cancel the dequeued buffers.


@@ -1713,6 +1732,19 @@ VkResult QueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* present_info) {
                ReleaseSwapchainImage(device, window, fence, img);
                ReleaseSwapchainImage(device, window, fence, img);
                OrphanSwapchain(device, &swapchain);
                OrphanSwapchain(device, &swapchain);
            }
            }
            int window_transform_hint;
            err = window->query(window, NATIVE_WINDOW_TRANSFORM_HINT,
                                &window_transform_hint);
            if (err != 0) {
                ALOGE("NATIVE_WINDOW_TRANSFORM_HINT query failed: %s (%d)",
                      strerror(-err), err);
                swapchain_result = WorstPresentResult(
                    swapchain_result, VK_ERROR_SURFACE_LOST_KHR);
            }
            if (swapchain.pre_transform != window_transform_hint) {
                swapchain_result =
                    WorstPresentResult(swapchain_result, VK_SUBOPTIMAL_KHR);
            }
        } else {
        } else {
            ReleaseSwapchainImage(device, nullptr, fence, img);
            ReleaseSwapchainImage(device, nullptr, fence, img);
            swapchain_result = VK_ERROR_OUT_OF_DATE_KHR;
            swapchain_result = VK_ERROR_OUT_OF_DATE_KHR;