Update for CTS test: 72/261072/3
authorTianhao Ni <tianhao.ni@samsung.com>
Fri, 9 Jul 2021 08:36:53 +0000 (16:36 +0800)
committerTianhao Ni <tianhao.ni@samsung.com>
Thu, 19 Aug 2021 06:15:26 +0000 (14:15 +0800)
- Upgrade wsi vulkan version to sync with vulkan loader & vulkan header
- Implement vkCreateWaylandSurfaceKHR & vkDestroySurfaceKHR for TPL display management
- Fix issues of CTS wsi cases

Change-Id: I96a4e0bc9e36a8aa71819f886a293a4994629e6e
Signed-off-by: Tianhao Ni <tianhao.ni@samsung.com>
13 files changed:
CMakeLists.txt
layer/VkLayer_window_system_integration.json
layer/layer.cpp
layer/private_data.hpp
layer/surface_api.cpp
layer/surface_api.hpp
layer/swapchain_api.cpp
wsi/swapchain_base_tizen.cpp
wsi/swapchain_base_tizen.hpp
wsi/tizen/surface_properties.cpp
wsi/tizen/swapchain.cpp
wsi/tizen/swapchain.hpp
wsi/wsi_factory.cpp

index 0b43e99b802afc0d8f90fee93db1c909f80c0939..0f022de284fc948c150b7bf8604a12863b751113 100644 (file)
@@ -139,6 +139,7 @@ if(BUILD_WSI_WAYLAND)
    target_link_libraries(wayland_wsi drm_utils wsialloc ${WAYLAND_CLIENT_LDFLAGS})
    list(APPEND LINK_WSI_LIBS wayland_wsi)
 elseif(BUILD_WSI_TIZEN)
+   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVK_USE_PLATFORM_WAYLAND_KHR")
    add_library(tizen_wsi STATIC
       wsi/tizen/surface_properties.cpp
       wsi/tizen/swapchain.cpp)
index 89bfbe9a67c9843ffa6b2acb4d72930d2c932ac4..2a0a845d7b31a8cfc649f5b61f393909ab24f375 100644 (file)
@@ -4,7 +4,7 @@
         "name": "VK_LAYER_window_system_integration",
         "type": "GLOBAL",
         "library_path": "./libVkLayer_window_system_integration.so",
-        "api_version": "1.0.68",
+        "api_version": "1.2.179",
         "implementation_version": "1",
         "description": "Window system integration layer",
         "functions": {
index 08bf84ec92a57bc862eeceb95a81ce63750bf945..30f63d74d568f7c25219b09e1ce4771f34dda8d7 100644 (file)
@@ -35,7 +35,7 @@
 #include "util/custom_allocator.hpp"
 #include "wsi/wsi_factory.hpp"
 
-#define VK_LAYER_API_VERSION VK_MAKE_VERSION(1, 0, VK_HEADER_VERSION)
+#define VK_LAYER_API_VERSION VK_MAKE_VERSION(1, 2, VK_HEADER_VERSION)
 
 namespace layer
 {
@@ -429,6 +429,8 @@ VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL wsi_layer_vkGetInstance
    GET_PROC_ADDR(vkDestroyInstance);
    GET_PROC_ADDR(vkCreateDevice);
    GET_PROC_ADDR(vkDestroyDevice);
+   GET_PROC_ADDR(vkCreateWaylandSurfaceKHR);
+   GET_PROC_ADDR(vkDestroySurfaceKHR);
    GET_PROC_ADDR(vkGetPhysicalDeviceSurfaceSupportKHR);
    GET_PROC_ADDR(vkGetPhysicalDeviceSurfaceCapabilitiesKHR);
    GET_PROC_ADDR(vkGetPhysicalDeviceSurfaceFormatsKHR);
index a5f04be1f87d2f4befbefe5610c7f259f73180c1..09b7f29ddd5b861e7cbf82939307024aea332c07 100644 (file)
@@ -55,7 +55,9 @@ namespace layer
    OPTIONAL(GetPhysicalDeviceSurfaceFormatsKHR)         \
    OPTIONAL(GetPhysicalDeviceSurfacePresentModesKHR)    \
    OPTIONAL(GetPhysicalDeviceSurfaceSupportKHR)         \
-   OPTIONAL(GetPhysicalDeviceImageFormatProperties2KHR)
+   OPTIONAL(GetPhysicalDeviceImageFormatProperties2KHR) \
+   OPTIONAL(CreateWaylandSurfaceKHR);                   \
+   OPTIONAL(DestroySurfaceKHR);
 
 struct instance_dispatch_table
 {
@@ -102,7 +104,7 @@ struct instance_dispatch_table
    OPTIONAL(GetSwapchainImagesKHR)                  \
    OPTIONAL(AcquireNextImageKHR)                    \
    OPTIONAL(QueuePresentKHR)                        \
-   REQUIRED(GetMemoryFdPropertiesKHR)
+   OPTIONAL(GetMemoryFdPropertiesKHR)
 
 struct device_dispatch_table
 {
index 98c0613226c3d50defabd34aa58bfb34d6a4e60d..430db850708e3ee42a8d61db44e49bdcb9c9cb5c 100644 (file)
 #include "surface_api.hpp"
 
 extern "C" {
+#include <tpl.h>
+}
+
+extern "C" {
+
+// Implements extension VK_KHR_wayland_surface
+VKAPI_ATTR VkResult wsi_layer_vkCreateWaylandSurfaceKHR(VkInstance instance, const VkWaylandSurfaceCreateInfoKHR* pCreateInfo,
+                                                              const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface)
+{
+   auto &inst = layer::instance_private_data::get(instance);
+   tpl_display_t *tpl_display = nullptr;
+
+   tpl_display = tpl_display_get_with_backend_type(TPL_BACKEND_WAYLAND_VULKAN_WSI_THREAD, reinterpret_cast<tpl_handle_t>(pCreateInfo->display));
+   if (tpl_display) {
+      tpl_object_reference(reinterpret_cast<tpl_object_t *>(tpl_display));
+   } else {
+      tpl_display = tpl_display_create(TPL_BACKEND_WAYLAND_VULKAN_WSI_THREAD, reinterpret_cast<tpl_handle_t>(pCreateInfo->display));
+   }
+
+   if (NULL == tpl_display) {
+      wsi_error("Failed to create TPL display for wl_display[%p] wl_surface[%p]", pCreateInfo->display, pCreateInfo->surface);
+      return VK_ERROR_INITIALIZATION_FAILED;
+   }
+
+   wsi_info("Create TPL display[%p] for wl_display[%p] wl_surface[%p]", tpl_display, pCreateInfo->display, pCreateInfo->surface);
+   return inst.disp.CreateWaylandSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
+}
+
+VKAPI_ATTR void wsi_layer_vkDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface, const VkAllocationCallbacks* pAllocator)
+{
+   auto &inst = layer::instance_private_data::get(instance);
+   VkIcdSurfaceWayland *surface_base = reinterpret_cast<VkIcdSurfaceWayland *>(surface);
+   if (!surface_base)
+      return;
+
+   tpl_display_t *tpl_display = tpl_display_get(reinterpret_cast<tpl_handle_t>(surface_base->display));
+   if (tpl_display) {
+      tpl_object_unreference(reinterpret_cast<tpl_object_t *>(tpl_display));
+   }
+   wsi_info("Destroy TPL display[%p] for wl_display[%p] wl_surface[%p]", tpl_display, surface_base->display, surface_base->surface);
+
+   inst.disp.DestroySurfaceKHR(instance, surface, pAllocator);
+}
 
 /**
  * @brief Implements vkGetPhysicalDeviceSurfaceCapabilitiesKHR Vulkan entrypoint.
index 9dc46360a2ee4cfc5df937334e4cfdbb9bdbe3e4..d5bb9bfaeef1457a3ca750816fd740201bcd75a4 100644 (file)
 
 extern "C" {
 
+VKAPI_ATTR VkResult wsi_layer_vkCreateWaylandSurfaceKHR(VkInstance instance, const VkWaylandSurfaceCreateInfoKHR* pCreateInfo,
+                                                              const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface);
+
+VKAPI_ATTR void wsi_layer_vkDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface, const VkAllocationCallbacks* pAllocator);
+
 /**
  * @brief Implements vkGetPhysicalDeviceSurfaceCapabilitiesKHR Vulkan entrypoint.
  */
index 7a6c58644a7fe5bbf24250744f1a20b62c05dd85..eb8e1962da7312867542652fc5eb96616151aa5b 100644 (file)
 
 extern "C" {
 
+static bool swapchain_on_prensent = false;
+
 VKAPI_ATTR VkResult wsi_layer_vkCreateSwapchainKHR(VkDevice device,
                                                    const VkSwapchainCreateInfoKHR *pSwapchainCreateInfo,
                                                    const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain)
 {
+   if (swapchain_on_prensent) {
+      wsi_error("Already created other swapchain");
+      return VK_ERROR_INITIALIZATION_FAILED;
+   }
+
    assert(pSwapchain != nullptr);
    layer::device_private_data &device_data = layer::device_private_data::get(device);
    VkSurfaceKHR surface = pSwapchainCreateInfo->surface;
@@ -59,12 +66,15 @@ VKAPI_ATTR VkResult wsi_layer_vkCreateSwapchainKHR(VkDevice device,
    wsi::swapchain_base *sc = wsi::allocate_surface_swapchain(surface, device_data, pAllocator);
    if (sc == nullptr)
    {
+      wsi_error("Alloc swapchain failed.");
       return VK_ERROR_OUT_OF_HOST_MEMORY;
    }
+   wsi_info("Created new swapchain [%p], VkSurface [%p].", sc, surface);
 
    VkResult result = sc->init(device, pSwapchainCreateInfo);
    if (result != VK_SUCCESS)
    {
+      wsi_error("Init swapchain failed, ret [%d].", result);
       /* Error occured during initialization, need to free allocated memory. */
       wsi::destroy_surface_swapchain(sc, pAllocator);
       return result;
@@ -72,6 +82,7 @@ VKAPI_ATTR VkResult wsi_layer_vkCreateSwapchainKHR(VkDevice device,
 
    *pSwapchain = reinterpret_cast<VkSwapchainKHR>(sc);
    device_data.add_layer_swapchain(*pSwapchain);
+   swapchain_on_prensent = true;
    return result;
 }
 
@@ -79,15 +90,20 @@ VKAPI_ATTR void wsi_layer_vkDestroySwapchainKHR(VkDevice device, VkSwapchainKHR
                                                 const VkAllocationCallbacks *pAllocator)
 {
    layer::device_private_data &device_data = layer::device_private_data::get(device);
+   if (!swapc)
+      return;
 
    if (!device_data.layer_owns_swapchain(swapc))
    {
       return device_data.disp.DestroySwapchainKHR(device_data.device, swapc, pAllocator);
    }
 
+   wsi_info("Destroy swapchain [%p], VkSurface [%p].", swapc);
+
    assert(swapc != VK_NULL_HANDLE);
    wsi::swapchain_base *sc = reinterpret_cast<wsi::swapchain_base *>(swapc);
    wsi::destroy_surface_swapchain(sc, pAllocator);
+   swapchain_on_prensent = false;
 }
 
 VKAPI_ATTR VkResult wsi_layer_vkGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapc,
index d74b7e9545f97a5e0a1025774664038e465fcb88..1f81fa08ffcd2eb8092915b799565194238b4c30 100644 (file)
@@ -46,6 +46,7 @@ VkResult swapchain_base::init(VkDevice device, const VkSwapchainCreateInfoKHR *s
    result = init_platform(device, swapchain_create_info);
    if (result != VK_SUCCESS)
    {
+      wsi_error("Init platform for VkSurface[%p] failed", m_surface);
       return result;
    }
 
@@ -69,6 +70,7 @@ VkResult swapchain_base::init(VkDevice device, const VkSwapchainCreateInfoKHR *s
    result = create_image(image_create_info);
    if (result != VK_SUCCESS)
    {
+      wsi_error("Create image for VkSurface[%p] failed", m_surface);
       return result;
    }
 
@@ -77,7 +79,7 @@ VkResult swapchain_base::init(VkDevice device, const VkSwapchainCreateInfoKHR *s
    if (swapchain_create_info->oldSwapchain != VK_NULL_HANDLE)
    {
       /* TO BE DONE - How to reuse the old swapchain */
-         /*
+      /*
       m_ancestor = swapchain_create_info->oldSwapchain;
 
       auto *ancestor = reinterpret_cast<swapchain_base *>(m_ancestor);
index 9e62bf4683504f0227d56ad2b46c53e0d7a18d73..308384ac214d434c242d29b0c696918e67f13cd0 100644 (file)
@@ -6,6 +6,12 @@
 #include <util/timed_semaphore.hpp>
 #include <util/custom_allocator.hpp>
 
+#define LOG_TAG "WSI"
+#include <dlog/dlog.h>
+
+#define wsi_info(f, x...)    LOGI(f, ##x)
+#define wsi_error(f, x...)   LOGE(f, ##x)
+
 namespace wsi
 {
 struct swapchain_image
index fceb584c370364c6d812ecd7984b19fb2e41aca1..cfdae9b9df396bc55c87bb0ebed837fe7fa718a2 100644 (file)
@@ -21,7 +21,6 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  * SOFTWARE.
  */
-#define VK_USE_PLATFORM_WAYLAND_KHR 1
 
 extern "C" {
 #include <vulkan/vk_icd.h>
@@ -58,9 +57,9 @@ VkResult surface_properties::get_surface_capabilities(VkPhysicalDevice physical_
    if (vk_surf == NULL || vk_surf->display == NULL || vk_surf->surface == NULL)
       return VK_ERROR_SURFACE_LOST_KHR;
 
-   tpl_display_t *tpl_display = tpl_display_create(TPL_BACKEND_WAYLAND_VULKAN_WSI_THREAD, vk_surf->display);
-   if (tpl_display == NULL) {
-      return VK_ERROR_OUT_OF_HOST_MEMORY;
+   tpl_display_t *tpl_display = tpl_display_get(reinterpret_cast<tpl_handle_t>(vk_surf->display));
+   if (!tpl_display) {
+      return VK_ERROR_SURFACE_LOST_KHR;
    }
 
    int cnt_min = 0, cnt_max = 0;
@@ -143,9 +142,9 @@ VkResult surface_properties::get_surface_present_modes(VkPhysicalDevice physical
    if (vk_surf == NULL || vk_surf->display == NULL || vk_surf->surface == NULL)
       return VK_ERROR_SURFACE_LOST_KHR;
 
-   tpl_display_t *tpl_display = tpl_display_create(TPL_BACKEND_WAYLAND_VULKAN_WSI_THREAD, vk_surf->display);
-   if (tpl_display == NULL) {
-      return VK_ERROR_OUT_OF_HOST_MEMORY;
+   tpl_display_t *tpl_display = tpl_display_get(reinterpret_cast<tpl_handle_t>(vk_surf->display));
+   if (!tpl_display) {
+      return VK_ERROR_SURFACE_LOST_KHR;
    }
 
    int tplModes;
index 3785caf71a1396156f4dc526c479317e90bfb389..62294333218071e90728577f468238574fb8e5c8 100644 (file)
@@ -22,8 +22,6 @@
  * SOFTWARE.
  */
 
-#define VK_USE_PLATFORM_WAYLAND_KHR 1
-
 #include "swapchain.hpp"
 
 #include <cstring>
 #include <climits>
 #include <drm_fourcc.h>
 
-#if VULKAN_WSI_DEBUG > 0
-#define WSI_PRINT_ERROR(fmt, ...) fprintf(stderr, "[%s:%d - %s]" fmt, __FILE__, __LINE__, __func__, ##__VA_ARGS__)
-#else
-#define WSI_PRINT_ERROR(...) (void)0
-#endif
-
 namespace wsi
 {
 namespace tizen
 {
-
 struct swapchain::tizen_image_data
 {
    int buffer_fd;
@@ -60,7 +51,6 @@ struct swapchain::tizen_image_data
 swapchain::swapchain(layer::device_private_data &dev_data, const VkAllocationCallbacks *pAllocator)
    : swapchain_base(dev_data, pAllocator)
    , m_tpl_surface(nullptr)
-   , m_tpl_display(nullptr)
 {
 }
 
@@ -68,9 +58,10 @@ swapchain::~swapchain()
 {
    teardown();
    destroy_image();
-   tpl_surface_destroy_swapchain(m_tpl_surface);
-   tpl_object_unreference((tpl_object_t *)m_tpl_surface);
-   tpl_object_unreference((tpl_object_t *)m_tpl_display);
+   if (m_tpl_surface) {
+      tpl_surface_destroy_swapchain(m_tpl_surface);
+      tpl_object_unreference((tpl_object_t *)m_tpl_surface);
+   }
 }
 
 #define TBM_FORMAT_0   0
@@ -129,7 +120,7 @@ wsi_tizen_get_tbm_format(VkFormat format, VkCompositeAlphaFlagBitsKHR comp)
       break;
    }
 
-       return 0;
+   return 0;
 }
 
 VkResult swapchain::init_platform(VkDevice device, const VkSwapchainCreateInfoKHR *pSwapchainCreateInfo)
@@ -139,23 +130,26 @@ VkResult swapchain::init_platform(VkDevice device, const VkSwapchainCreateInfoKH
    int tpl_present_mode;
    tpl_result_t res;
 
-   m_tpl_display = tpl_display_create(TPL_BACKEND_WAYLAND_VULKAN_WSI_THREAD, vk_surf->display);
-   if (m_tpl_display == NULL) {
-      WSI_PRINT_ERROR("create tpl display failed\n");
-         return VK_ERROR_INITIALIZATION_FAILED;
+   tpl_display_t *tpl_display = tpl_display_get(reinterpret_cast<tpl_handle_t>(vk_surf->display));
+   if (!tpl_display) {
+      wsi_error("Get tpl display failed\n");
+      return VK_ERROR_SURFACE_LOST_KHR;
    }
-   tpl_object_reference((tpl_object_t *)m_tpl_display);
 
-   format = wsi_tizen_get_tbm_format(pSwapchainCreateInfo->imageFormat, pSwapchainCreateInfo->compositeAlpha);
-   m_tpl_surface = tpl_surface_get(m_tpl_display, vk_surf->surface);
-   if (m_tpl_surface == NULL)
-      m_tpl_surface = tpl_surface_create(m_tpl_display, vk_surf->surface, TPL_SURFACE_TYPE_WINDOW, format);
+   m_tpl_surface = tpl_surface_get(tpl_display, vk_surf->surface);
+   wsi_info("Get tpl_surface[%p] from tpl_display[%p]", m_tpl_surface, tpl_display);
+   if (m_tpl_surface == NULL) {
+      format = wsi_tizen_get_tbm_format(pSwapchainCreateInfo->imageFormat, pSwapchainCreateInfo->compositeAlpha);
+      m_tpl_surface = tpl_surface_create(tpl_display, vk_surf->surface, TPL_SURFACE_TYPE_WINDOW, format);
+   } else {
+      wsi_error("tpl_surface[%p] already in use", m_tpl_surface);
+      return VK_ERROR_INITIALIZATION_FAILED;
+   }
 
    if (m_tpl_surface == NULL) {
-      WSI_PRINT_ERROR("create tpl surface failed\n");
-         return VK_ERROR_INITIALIZATION_FAILED;
+      wsi_error("create tpl surface failed\n");
+      return VK_ERROR_INITIALIZATION_FAILED;
    }
-   tpl_object_reference((tpl_object_t *)m_tpl_surface);
 
    switch(pSwapchainCreateInfo->presentMode) {
       case VK_PRESENT_MODE_IMMEDIATE_KHR:
@@ -171,16 +165,16 @@ VkResult swapchain::init_platform(VkDevice device, const VkSwapchainCreateInfoKH
          tpl_present_mode = TPL_DISPLAY_PRESENT_MODE_FIFO_RELAXED;
          break;
       default:
-         WSI_PRINT_ERROR("unsupported present mode, presentMode[%d].", pSwapchainCreateInfo->presentMode);
+         wsi_error("unsupported present mode, presentMode[%d].", pSwapchainCreateInfo->presentMode);
          return VK_ERROR_INITIALIZATION_FAILED;
    }
 
    res = tpl_surface_create_swapchain(m_tpl_surface, format,
-                                                                          pSwapchainCreateInfo->imageExtent.width, pSwapchainCreateInfo->imageExtent.height,
-                                                                          pSwapchainCreateInfo->minImageCount, tpl_present_mode);
+                                      pSwapchainCreateInfo->imageExtent.width, pSwapchainCreateInfo->imageExtent.height,
+                                      pSwapchainCreateInfo->minImageCount, tpl_present_mode);
    if (res != TPL_ERROR_NONE) {
-          WSI_PRINT_ERROR("create swapchain failed, ret[%d].\n", res);
-          return VK_ERROR_INITIALIZATION_FAILED;
+      wsi_error("create swapchain failed, ret[%d].\n", res);
+      return VK_ERROR_INITIALIZATION_FAILED;
    }
 
    return VK_SUCCESS;
@@ -212,7 +206,7 @@ VkResult swapchain::allocate_image(const VkImageCreateInfo &image_create_info, t
    result = m_device_data.disp.CreateImage(m_device, &image_info, get_allocation_callbacks(), image);
    if (result != VK_SUCCESS)
    {
-      WSI_PRINT_ERROR("Image creation failed.\n");
+      wsi_error("Image creation failed.\n");
       return result;
    }
 
@@ -223,7 +217,7 @@ VkResult swapchain::allocate_image(const VkImageCreateInfo &image_create_info, t
                                                      image_data->buffer_fd, &mem_props);
    if (result != VK_SUCCESS)
    {
-      WSI_PRINT_ERROR("Error querying Fd properties.\n");
+      wsi_error("Error querying Fd properties.\n");
       return result;
    }
 
@@ -238,7 +232,7 @@ VkResult swapchain::allocate_image(const VkImageCreateInfo &image_create_info, t
    off_t dma_buf_size = lseek(image_data->buffer_fd, 0, SEEK_END);
    if (dma_buf_size < 0)
    {
-      WSI_PRINT_ERROR("Failed to get DMA Buf size.\n");
+      wsi_error("Failed to get DMA Buf size.\n");
       return VK_ERROR_OUT_OF_HOST_MEMORY;
    }
 
@@ -257,7 +251,7 @@ VkResult swapchain::allocate_image(const VkImageCreateInfo &image_create_info, t
 
    if (result != VK_SUCCESS)
    {
-      WSI_PRINT_ERROR("Failed to import memory.\n");
+      wsi_error("Failed to import memory.\n");
       return result;
    }
    result = m_device_data.disp.BindImageMemory(m_device, *image, image_data->memory, 0);
@@ -278,22 +272,30 @@ VkResult swapchain::create_image(const VkImageCreateInfo &image_create_info)
    else if (res != TPL_ERROR_NONE)
       return VK_ERROR_INITIALIZATION_FAILED;
 
+   wsi_info("Get swapchain buffer numbers [%d], swapchain [%p], tpl_surface [%p]", tbm_buf_cnt, this, m_tpl_surface);
+
    if (tbm_buf_cnt < 2)
       return VK_ERROR_OUT_OF_HOST_MEMORY;
 
    res = tpl_surface_get_swapchain_buffers(m_tpl_surface, &buffers, &tbm_buf_cnt);
-   if (res == TPL_ERROR_OUT_OF_MEMORY)
-      return VK_ERROR_OUT_OF_HOST_MEMORY;
-   else if (res != TPL_ERROR_NONE)
+   if (res != TPL_ERROR_NONE) {
+      wsi_error("Get TPL swapchain buffers failed, ret[%d], swapchain [%p], tpl_surface [%p]", res, this, m_tpl_surface);
+      if (res == TPL_ERROR_OUT_OF_MEMORY)
+         return VK_ERROR_OUT_OF_HOST_MEMORY;
+
       return VK_ERROR_INITIALIZATION_FAILED;
+   }
 
-   if (!m_swapchain_images.try_resize(tbm_buf_cnt))
+   if (!m_swapchain_images.try_resize(tbm_buf_cnt)) {
+      wsi_error("Resize m_swapchain_images failed");
       return VK_ERROR_OUT_OF_HOST_MEMORY;
+   }
 
+   wsi_info("Create swapchain images [%p], swapchain [%p], tpl_surface [%p]", &m_swapchain_images, this, m_tpl_surface);
    i = 0;
    for (auto &image: m_swapchain_images) {
       tizen_image_data *image_data = nullptr;
-         if (get_allocation_callbacks() != nullptr)
+      if (get_allocation_callbacks() != nullptr)
       {
          image_data = static_cast<tizen_image_data *>(
             get_allocation_callbacks()->pfnAllocation(get_allocation_callbacks()->pUserData, sizeof(tizen_image_data),
@@ -301,32 +303,38 @@ VkResult swapchain::create_image(const VkImageCreateInfo &image_create_info)
       } else {
          image_data = static_cast<tizen_image_data *>(malloc(sizeof(tizen_image_data)));
       }
+      if (!image_data) {
+         wsi_error("Allocate image data failed");
+         result = VK_ERROR_OUT_OF_HOST_MEMORY;
+         goto out;
+      }
 
       tbm_surface_info_s info;
       tbm_bo bo = tbm_surface_internal_get_bo(buffers[i], 0);
       tbm_bo_handle bo_handle = tbm_bo_get_handle(bo, TBM_DEVICE_3D);
       tbm_surface_get_info(buffers[i], &info);
 
-         image_data->tbm_buffer = buffers[i];
-      image_data->buffer_fd = bo_handle.u32;
+      image_data->tbm_buffer = buffers[i];
+      image_data->buffer_fd = bo_handle.u32;//tbm_bo_export_fd(bo);
       image_data->stride = info.planes[0].stride;
       image_data->offset = info.planes[0].offset;
-         image_data->memory = VK_NULL_HANDLE;
+      image_data->memory = VK_NULL_HANDLE;
+
+      wsi_info("New image[%d] - tbm_buffer [%p], buffer fd [%d]", i, image_data->tbm_buffer, image_data->buffer_fd);
 
-         image.data = static_cast<void *>(image_data);
+      image.data = static_cast<void *>(image_data);
 
       result = allocate_image(image_create_info, image_data, &image.image);
       if (result != VK_SUCCESS)
       {
-         WSI_PRINT_ERROR("Failed to allocate image.\n");
+         wsi_error("Failed to allocate image, ret [%d].", result);
          goto out;
       }
 
-         /* Initialize presentation fence. */
-         VkFenceCreateInfo fenceInfo = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
+      /* Initialize presentation fence. */
+      VkFenceCreateInfo fenceInfo = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
       result = m_device_data.disp.CreateFence(m_device, &fenceInfo, get_allocation_callbacks(), &image.present_fence);
-
-         i++;
+      i++;
    }
 
    return VK_SUCCESS;
@@ -342,17 +350,22 @@ VkResult swapchain::acquire_image(uint32_t *image_index)
 {
    tbm_surface_h tbm_buf = tpl_surface_dequeue_buffer_with_sync(m_tpl_surface, UINT64_MAX, NULL);
 
-   if (tbm_buf == NULL)
+   if (tbm_buf == NULL) {
+      wsi_error("Dequeue buffer failed, swapchain [%p], tpl_surface [%p]", this, m_tpl_surface);
       return VK_ERROR_SURFACE_LOST_KHR;
+   }
+
 
    for (unsigned int i = 0; i < m_swapchain_images.size(); i++) {
       tizen_image_data *image_data = reinterpret_cast<tizen_image_data *>(m_swapchain_images[i].data);
       if (image_data->tbm_buffer == tbm_buf) {
          *image_index = i;
+         //wsi_error("Acquire image [%d], tbm_buffer [%p], swapchain [%p], tpl_surface [%p]", i, tbm_buf, this, m_tpl_surface);
          return VK_SUCCESS;
       }
    }
 
+   wsi_error("Invalid swapchain buffer [%p], swapchain [%p], tpl_surface [%p]", tbm_buf, this, m_tpl_surface);
    return VK_ERROR_SURFACE_LOST_KHR;
 }
 
index d2c277c70e6f068ecbcb23d8221f0f9572cb5b70..b6424271e965d4d583a6b8e1f56957c357ed8d2b 100644 (file)
@@ -83,7 +83,7 @@ private:
    struct tizen_image_data;
    VkResult allocate_image(const VkImageCreateInfo &image_create_info, tizen_image_data *image_data, VkImage *image);
 
-   tpl_display_t *m_tpl_display;
+   //tpl_display_t *m_tpl_display;
    tpl_surface_t *m_tpl_surface;
 
 };
index ed2624bea47a8256e0fd950abefde958a7d59178..3367a7c2a63906b66b3952a9d25576fea8eb8b1b 100644 (file)
@@ -104,6 +104,10 @@ static swapchain_base *allocate_swapchain(layer::device_private_data &dev_data,
    }
    void *memory = pAllocator->pfnAllocation(pAllocator->pUserData, sizeof(swapchain_type), alignof(swapchain_type),
                                             VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
+   if (!memory) {
+      wsi_error("Allocate swapchain memory failed");
+      return NULL;
+   }
    return new (memory) swapchain_type(dev_data, pAllocator);
 }