spec: Add support for VK_KHR_incremental_present
[platform/core/uifw/vulkan-wsi-tizen.git] / src / wsi / swapchain_tpl.c
index d2d3bcd..708b21e 100644 (file)
@@ -35,14 +35,22 @@ struct vk_swapchain_tpl {
        tbm_surface_h                   *buffers;
 };
 
+struct swap_region
+{
+       int num_rects;
+       int *rects;
+};
 static VkResult
 swapchain_tpl_queue_present_image(VkQueue                                       queue,
                                                                  vk_swapchain_t                        *chain,
                                                                  tbm_surface_h                          tbm_surface,
-                                                                 int                                            sync_fd)
+                                                                 int                                            sync_fd,
+                                                                 int num_rects,
+                                                                 const VkRectLayerKHR *rects)
 {
        tpl_result_t             res;
        vk_swapchain_tpl_t      *swapchain_tpl = chain->backend_data;
+       struct swap_region *region = NULL;
 
        if (chain->is_retired == VK_TRUE) {
                res = tpl_surface_cancel_dequeued_buffer(swapchain_tpl->tpl_surface, tbm_surface);
@@ -53,13 +61,43 @@ swapchain_tpl_queue_present_image(VkQueue                                    queue,
                return VK_ERROR_OUT_OF_DATE_KHR;
        }
 
+       if (num_rects >= 1) {
+               region = (struct swap_region *)malloc(sizeof(struct swap_region));
+               if (!region)
+               {
+                       VK_ERROR("Failed to allocate swap_region");
+                       return VK_ERROR_DEVICE_LOST;
+               }
+
+               region->num_rects = num_rects;
+
+               region->rects = (int *)malloc(sizeof(int) * 4 * num_rects);
+               if (!region->rects)
+               {
+                       VK_ERROR("Failed to allocate swap_region->rects.");
+                       free(region);
+                       return VK_ERROR_DEVICE_LOST;
+               }
+
+               for (int i = 0; i < num_rects; i++) {
+                       VkRectLayerKHR *pRects = &rects[i];
+                       //copy first 4 ints from VkRectLayerKHR
+                       memcpy((char *)region->rects + sizeof(int)*4*i, (char *)pRects, sizeof(int) * 4);
+               }
+
+       }
        res = tpl_surface_enqueue_buffer_with_damage_and_sync(swapchain_tpl->tpl_surface,
-                                                                                                                 tbm_surface, 0, NULL, sync_fd);
+                                                                                                                 tbm_surface, region ? region->num_rects : 0, region ? region->rects : NULL, sync_fd);
        if (res == TPL_ERROR_NONE && chain->oldSwapchain != VK_NULL_HANDLE) {
                chain->oldSwapchain->is_retired = VK_TRUE;
                chain->oldSwapchain = VK_NULL_HANDLE;
        }
 
+       if (region) {
+               if (region->rects) free(region->rects);
+
+               free(region);
+       }
        return res == TPL_ERROR_NONE ? VK_SUCCESS : VK_ERROR_DEVICE_LOST;
 }