#include "swapchain_api.hpp"
#include <util/helpers.hpp>
+static bool swapchain_on_prensent = false;
VWL_VKAPI_CALL(VkResult)
wsi_layer_vkCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pSwapchainCreateInfo,
const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain) VWL_API_POST
{
+ 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;
auto 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);
return result;
}
}
*pSwapchain = reinterpret_cast<VkSwapchainKHR>(sc.release());
+ swapchain_on_prensent = true;
return result;
}
const VkAllocationCallbacks *pAllocator) VWL_API_POST
{
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);
auto *sc = reinterpret_cast<wsi::swapchain_base *>(swapc);
wsi::destroy_surface_swapchain(sc, device_data, pAllocator);
+ swapchain_on_prensent = false;
}
VWL_VKAPI_CALL(VkResult)
* 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;
swapchain::swapchain(layer::device_private_data &dev_data, const VkAllocationCallbacks *pAllocator)
: swapchain_base(dev_data, pAllocator)
, m_tpl_surface(nullptr)
- , m_tpl_display(nullptr)
{
}
{
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
break;
}
- return 0;
+ return 0;
}
VkResult swapchain::init_platform(VkDevice device, const VkSwapchainCreateInfoKHR *pSwapchainCreateInfo)
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:
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;
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;
}
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;
}
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;
}
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);
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),
} 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;
{
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;
}