anv/wsi: split out surface creation to avoid instance API
authorDave Airlie <airlied@redhat.com>
Fri, 14 Oct 2016 01:51:36 +0000 (02:51 +0100)
committerDave Airlie <airlied@redhat.com>
Wed, 19 Oct 2016 00:15:43 +0000 (10:15 +1000)
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/intel/vulkan/anv_wsi_wayland.c
src/intel/vulkan/anv_wsi_x11.c

index 16a96470fa0cbcf163193e2e4460190809624bf9..fe43eb162202bcd366816fc1216baa5e234b2ca1 100644 (file)
@@ -422,20 +422,14 @@ wsi_wl_surface_get_present_modes(VkIcdSurfaceBase *surface,
    return VK_SUCCESS;
 }
 
-VkResult anv_CreateWaylandSurfaceKHR(
-    VkInstance                                  _instance,
-    const VkWaylandSurfaceCreateInfoKHR*        pCreateInfo,
-    const VkAllocationCallbacks*                pAllocator,
-    VkSurfaceKHR*                               pSurface)
+static VkResult anv_create_wl_surface(const VkAllocationCallbacks *pAllocator,
+                                      const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
+                                      VkSurfaceKHR *pSurface)
 {
-   ANV_FROM_HANDLE(anv_instance, instance, _instance);
-
-   assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR);
-
    VkIcdSurfaceWayland *surface;
 
-   surface = vk_alloc2(&instance->alloc, pAllocator, sizeof *surface, 8,
-                        VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+   surface = vk_alloc(pAllocator, sizeof *surface, 8,
+                      VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
    if (surface == NULL)
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
 
@@ -448,6 +442,24 @@ VkResult anv_CreateWaylandSurfaceKHR(
    return VK_SUCCESS;
 }
 
+VkResult anv_CreateWaylandSurfaceKHR(
+    VkInstance                                  _instance,
+    const VkWaylandSurfaceCreateInfoKHR*        pCreateInfo,
+    const VkAllocationCallbacks*                pAllocator,
+    VkSurfaceKHR*                               pSurface)
+{
+   ANV_FROM_HANDLE(anv_instance, instance, _instance);
+   const VkAllocationCallbacks *alloc;
+   assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR);
+
+   if (pAllocator)
+      alloc = pAllocator;
+   else
+      alloc = &instance->alloc;
+
+   return anv_create_wl_surface(alloc, pCreateInfo, pSurface);
+}
+
 struct wsi_wl_image {
    VkImage image;
    VkDeviceMemory memory;
index f56df40b498cefe4650837abbbf9c79f2710d247..8bc54f237863f5e1afe4c75e8be47a9b8d89b952 100644 (file)
@@ -434,20 +434,14 @@ x11_surface_get_present_modes(VkIcdSurfaceBase *surface,
    return VK_SUCCESS;
 }
 
-VkResult anv_CreateXcbSurfaceKHR(
-    VkInstance                                  _instance,
-    const VkXcbSurfaceCreateInfoKHR*            pCreateInfo,
-    const VkAllocationCallbacks*                pAllocator,
-    VkSurfaceKHR*                               pSurface)
+static VkResult anv_create_xcb_surface(const VkAllocationCallbacks *pAllocator,
+                                       const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
+                                       VkSurfaceKHR *pSurface)
 {
-   ANV_FROM_HANDLE(anv_instance, instance, _instance);
-
-   assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR);
-
    VkIcdSurfaceXcb *surface;
 
-   surface = vk_alloc2(&instance->alloc, pAllocator, sizeof *surface, 8,
-                        VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+   surface = vk_alloc(pAllocator, sizeof *surface, 8,
+                      VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
    if (surface == NULL)
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
 
@@ -456,24 +450,35 @@ VkResult anv_CreateXcbSurfaceKHR(
    surface->window = pCreateInfo->window;
 
    *pSurface = _VkIcdSurfaceBase_to_handle(&surface->base);
-
    return VK_SUCCESS;
 }
 
-VkResult anv_CreateXlibSurfaceKHR(
+VkResult anv_CreateXcbSurfaceKHR(
     VkInstance                                  _instance,
-    const VkXlibSurfaceCreateInfoKHR*           pCreateInfo,
+    const VkXcbSurfaceCreateInfoKHR*            pCreateInfo,
     const VkAllocationCallbacks*                pAllocator,
     VkSurfaceKHR*                               pSurface)
 {
    ANV_FROM_HANDLE(anv_instance, instance, _instance);
+   const VkAllocationCallbacks *alloc;
+   assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR);
 
-   assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR);
+   if (pAllocator)
+     alloc = pAllocator;
+   else
+     alloc = &instance->alloc;
 
+   return anv_create_xcb_surface(alloc, pCreateInfo, pSurface);
+}
+
+static VkResult anv_create_xlib_surface(const VkAllocationCallbacks *pAllocator,
+                                        const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
+                                        VkSurfaceKHR *pSurface)
+{
    VkIcdSurfaceXlib *surface;
 
-   surface = vk_alloc2(&instance->alloc, pAllocator, sizeof *surface, 8,
-                        VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+   surface = vk_alloc(pAllocator, sizeof *surface, 8,
+                      VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
    if (surface == NULL)
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
 
@@ -482,10 +487,28 @@ VkResult anv_CreateXlibSurfaceKHR(
    surface->window = pCreateInfo->window;
 
    *pSurface = _VkIcdSurfaceBase_to_handle(&surface->base);
-
    return VK_SUCCESS;
 }
 
+VkResult anv_CreateXlibSurfaceKHR(
+    VkInstance                                  _instance,
+    const VkXlibSurfaceCreateInfoKHR*           pCreateInfo,
+    const VkAllocationCallbacks*                pAllocator,
+    VkSurfaceKHR*                               pSurface)
+{
+   ANV_FROM_HANDLE(anv_instance, instance, _instance);
+   const VkAllocationCallbacks *alloc;
+
+   assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR);
+
+   if (pAllocator)
+     alloc = pAllocator;
+   else
+     alloc = &instance->alloc;
+
+   return anv_create_xlib_surface(alloc, pCreateInfo, pSurface);
+}
+
 struct x11_image {
    VkImage image;
    VkDeviceMemory memory;