#define GST_CAT_DEFAULT gst_vulkan_swapper_debug
GST_DEBUG_CATEGORY (GST_CAT_DEFAULT);
-#define RENDER_GET_LOCK(o) &(GST_VULKAN_SWAPPER (o)->priv->render_lock)
-#define RENDER_LOCK(o) g_mutex_lock (RENDER_GET_LOCK(o));
-#define RENDER_UNLOCK(o) g_mutex_unlock (RENDER_GET_LOCK(o));
-
struct _GstVulkanSwapperPrivate
{
VkSurfaceKHR surface;
#define DEFAULT_PIXEL_ASPECT_RATIO_N 0
#define DEFAULT_PIXEL_ASPECT_RATIO_D 1
+#define GET_PRIV(swapper) gst_vulkan_swapper_get_instance_private (swapper)
+
#define gst_vulkan_swapper_parent_class parent_class
G_DEFINE_TYPE_WITH_CODE (GstVulkanSwapper, gst_vulkan_swapper,
GST_TYPE_OBJECT, G_ADD_PRIVATE (GstVulkanSwapper)
static void _on_window_resize (GstVulkanWindow * window,
guint width, guint height, GstVulkanSwapper * swapper);
+static inline GMutex *
+render_get_lock (gpointer swapper)
+{
+ GstVulkanSwapperPrivate *priv = GET_PRIV (swapper);
+ return &priv->render_lock;
+}
+
+#define RENDER_LOCK(o) g_mutex_lock (render_get_lock(o));
+#define RENDER_UNLOCK(o) g_mutex_unlock (render_get_lock(o));
+
static gboolean
_get_function_table (GstVulkanSwapper * swapper)
{
+ GstVulkanSwapperPrivate *priv = GET_PRIV (swapper);
GstVulkanDevice *device = swapper->device;
GstVulkanInstance *instance = gst_vulkan_device_get_instance (device);
GST_ERROR_OBJECT (swapper, "Failed to get instance from the device");
return FALSE;
}
-#define GET_PROC_ADDRESS_REQUIRED(obj, type, name) \
+#define GET_PROC_ADDRESS_REQUIRED(type, name) \
G_STMT_START { \
- obj->priv->G_PASTE (, name) = G_PASTE(G_PASTE(gst_vulkan_, type), _get_proc_address) (type, "vk" G_STRINGIFY(name)); \
- if (!obj->priv->G_PASTE(, name)) { \
- GST_ERROR_OBJECT (obj, "Failed to find required function vk" G_STRINGIFY(name)); \
+ priv->G_PASTE (, name) = G_PASTE(G_PASTE(gst_vulkan_, type), _get_proc_address) (type, "vk" G_STRINGIFY(name)); \
+ if (!priv->G_PASTE(, name)) { \
+ GST_ERROR_OBJECT (swapper, "Failed to find required function vk" G_STRINGIFY(name)); \
gst_object_unref (instance); \
return FALSE; \
} \
} G_STMT_END
- GET_PROC_ADDRESS_REQUIRED (swapper, instance,
- GetPhysicalDeviceSurfaceSupportKHR);
- GET_PROC_ADDRESS_REQUIRED (swapper, instance,
- GetPhysicalDeviceSurfaceCapabilitiesKHR);
- GET_PROC_ADDRESS_REQUIRED (swapper, instance,
- GetPhysicalDeviceSurfaceFormatsKHR);
- GET_PROC_ADDRESS_REQUIRED (swapper, instance,
- GetPhysicalDeviceSurfacePresentModesKHR);
- GET_PROC_ADDRESS_REQUIRED (swapper, instance, DestroySurfaceKHR);
- GET_PROC_ADDRESS_REQUIRED (swapper, device, CreateSwapchainKHR);
- GET_PROC_ADDRESS_REQUIRED (swapper, device, DestroySwapchainKHR);
- GET_PROC_ADDRESS_REQUIRED (swapper, device, GetSwapchainImagesKHR);
- GET_PROC_ADDRESS_REQUIRED (swapper, device, AcquireNextImageKHR);
- GET_PROC_ADDRESS_REQUIRED (swapper, device, QueuePresentKHR);
+ GET_PROC_ADDRESS_REQUIRED (instance, GetPhysicalDeviceSurfaceSupportKHR);
+ GET_PROC_ADDRESS_REQUIRED (instance, GetPhysicalDeviceSurfaceCapabilitiesKHR);
+ GET_PROC_ADDRESS_REQUIRED (instance, GetPhysicalDeviceSurfaceFormatsKHR);
+ GET_PROC_ADDRESS_REQUIRED (instance, GetPhysicalDeviceSurfacePresentModesKHR);
+ GET_PROC_ADDRESS_REQUIRED (instance, DestroySurfaceKHR);
+ GET_PROC_ADDRESS_REQUIRED (device, CreateSwapchainKHR);
+ GET_PROC_ADDRESS_REQUIRED (device, DestroySwapchainKHR);
+ GET_PROC_ADDRESS_REQUIRED (device, GetSwapchainImagesKHR);
+ GET_PROC_ADDRESS_REQUIRED (device, AcquireNextImageKHR);
+ GET_PROC_ADDRESS_REQUIRED (device, QueuePresentKHR);
gst_object_unref (instance);
static gboolean
_vulkan_swapper_ensure_surface (GstVulkanSwapper * swapper, GError ** error)
{
- if (!swapper->priv->surface) {
- if (!(swapper->priv->surface =
+ GstVulkanSwapperPrivate *priv = GET_PRIV (swapper);
+
+ if (!priv->surface) {
+ if (!(priv->surface =
gst_vulkan_window_get_surface (swapper->window, error))) {
return FALSE;
}
_choose_queue (GstVulkanDevice * device, GstVulkanQueue * queue,
struct choose_data *data)
{
+ GstVulkanSwapperPrivate *priv = GET_PRIV (data->swapper);
guint flags =
device->physical_device->queue_family_props[queue->family].queueFlags;
VkPhysicalDevice gpu;
VkBool32 physical_device_supported;
err =
- data->swapper->priv->GetPhysicalDeviceSurfaceSupportKHR (gpu,
- queue->index, data->swapper->priv->surface, &physical_device_supported);
+ priv->GetPhysicalDeviceSurfaceSupportKHR (gpu,
+ queue->index, priv->surface, &physical_device_supported);
if (gst_vulkan_error_to_g_error (err, &error,
"GetPhysicalDeviceSurfaceSupport") < 0) {
GST_DEBUG_OBJECT (data->swapper,
static void
dump_surface_properties (GstVulkanSwapper * swapper)
{
+ GstVulkanSwapperPrivate *priv = GET_PRIV (swapper);
+
GST_TRACE_OBJECT (swapper, "surface %p, n images [%" G_GUINT32_FORMAT ", %"
G_GUINT32_FORMAT "], extent [%" GST_VULKAN_EXTENT2D_FORMAT ", %"
GST_VULKAN_EXTENT2D_FORMAT "], max layers %" G_GUINT32_FORMAT
" transforms supported 0x%x current transform 0x%x, alpha flags 0x%x, "
- "supported image usage flags 0x%x", swapper->priv->surface,
- swapper->priv->surf_props.minImageCount,
- swapper->priv->surf_props.maxImageCount,
- GST_VULKAN_EXTENT2D_ARGS (swapper->priv->surf_props.minImageExtent),
- GST_VULKAN_EXTENT2D_ARGS (swapper->priv->surf_props.maxImageExtent),
- swapper->priv->surf_props.maxImageArrayLayers,
- swapper->priv->surf_props.supportedTransforms,
- swapper->priv->surf_props.currentTransform,
- swapper->priv->surf_props.supportedCompositeAlpha,
- swapper->priv->surf_props.supportedUsageFlags);
+ "supported image usage flags 0x%x", priv->surface,
+ priv->surf_props.minImageCount,
+ priv->surf_props.maxImageCount,
+ GST_VULKAN_EXTENT2D_ARGS (priv->surf_props.minImageExtent),
+ GST_VULKAN_EXTENT2D_ARGS (priv->surf_props.maxImageExtent),
+ priv->surf_props.maxImageArrayLayers,
+ priv->surf_props.supportedTransforms,
+ priv->surf_props.currentTransform,
+ priv->surf_props.supportedCompositeAlpha,
+ priv->surf_props.supportedUsageFlags);
}
static void
dump_surface_formats (GstVulkanSwapper * swapper)
{
+ GstVulkanSwapperPrivate *priv = GET_PRIV (swapper);
int i;
- for (i = 0; i < swapper->priv->n_surf_formats; i++) {
+ for (i = 0; i < priv->n_surf_formats; i++) {
GST_DEBUG_OBJECT (swapper, "surface %p format 0x%x colorspace 0x%x",
- swapper->priv->surface, swapper->priv->surf_formats[i].format,
- swapper->priv->surf_formats[i].colorSpace);
+ priv->surface, priv->surf_formats[i].format,
+ priv->surf_formats[i].colorSpace);
}
}
static void
dump_surface_present_modes (GstVulkanSwapper * swapper)
{
+ GstVulkanSwapperPrivate *priv = GET_PRIV (swapper);
int i;
- for (i = 0; i < swapper->priv->n_surf_present_modes; i++) {
+ for (i = 0; i < priv->n_surf_present_modes; i++) {
GST_DEBUG_OBJECT (swapper, "surface %p present modes 0x%x",
- swapper->priv->surface, swapper->priv->surf_present_modes[i]);
+ priv->surface, priv->surf_present_modes[i]);
}
}
_vulkan_swapper_retrieve_surface_properties (GstVulkanSwapper * swapper,
GError ** error)
{
+ GstVulkanSwapperPrivate *priv = GET_PRIV (swapper);
VkPhysicalDevice gpu;
VkResult err;
- if (swapper->priv->surf_formats)
+ if (priv->surf_formats)
return TRUE;
gpu = gst_vulkan_device_get_physical_device (swapper->device);
return FALSE;
err =
- swapper->priv->GetPhysicalDeviceSurfaceCapabilitiesKHR (gpu,
- swapper->priv->surface, &swapper->priv->surf_props);
+ priv->GetPhysicalDeviceSurfaceCapabilitiesKHR (gpu,
+ priv->surface, &priv->surf_props);
if (gst_vulkan_error_to_g_error (err, error,
"GetPhysicalDeviceSurfaceCapabilitiesKHR") < 0)
return FALSE;
dump_surface_properties (swapper);
err =
- swapper->priv->GetPhysicalDeviceSurfaceFormatsKHR (gpu,
- swapper->priv->surface, &swapper->priv->n_surf_formats, NULL);
+ priv->GetPhysicalDeviceSurfaceFormatsKHR (gpu,
+ priv->surface, &priv->n_surf_formats, NULL);
if (gst_vulkan_error_to_g_error (err, error,
"GetPhysicalDeviceSurfaceFormatsKHR") < 0)
return FALSE;
- swapper->priv->surf_formats =
- g_new0 (VkSurfaceFormatKHR, swapper->priv->n_surf_formats);
+ priv->surf_formats = g_new0 (VkSurfaceFormatKHR, priv->n_surf_formats);
err =
- swapper->priv->GetPhysicalDeviceSurfaceFormatsKHR (gpu,
- swapper->priv->surface, &swapper->priv->n_surf_formats,
- swapper->priv->surf_formats);
+ priv->GetPhysicalDeviceSurfaceFormatsKHR (gpu,
+ priv->surface, &priv->n_surf_formats, priv->surf_formats);
if (gst_vulkan_error_to_g_error (err, error,
"GetPhysicalDeviceSurfaceFormatsKHR") < 0)
return FALSE;
dump_surface_formats (swapper);
err =
- swapper->priv->GetPhysicalDeviceSurfacePresentModesKHR (gpu,
- swapper->priv->surface, &swapper->priv->n_surf_present_modes, NULL);
+ priv->GetPhysicalDeviceSurfacePresentModesKHR (gpu,
+ priv->surface, &priv->n_surf_present_modes, NULL);
if (gst_vulkan_error_to_g_error (err, error,
"GetPhysicalDeviceSurfacePresentModesKHR") < 0)
return FALSE;
- swapper->priv->surf_present_modes =
- g_new0 (VkPresentModeKHR, swapper->priv->n_surf_present_modes);
+ priv->surf_present_modes =
+ g_new0 (VkPresentModeKHR, priv->n_surf_present_modes);
err =
- swapper->priv->GetPhysicalDeviceSurfacePresentModesKHR (gpu,
- swapper->priv->surface, &swapper->priv->n_surf_present_modes,
- swapper->priv->surf_present_modes);
+ priv->GetPhysicalDeviceSurfacePresentModesKHR (gpu,
+ priv->surface, &priv->n_surf_present_modes, priv->surf_present_modes);
if (gst_vulkan_error_to_g_error (err, error,
"GetPhysicalDeviceSurfacePresentModesKHR") < 0)
return FALSE;
static gboolean
_on_window_close (GstVulkanWindow * window, GstVulkanSwapper * swapper)
{
- g_atomic_int_set (&swapper->priv->to_quit, 1);
+ GstVulkanSwapperPrivate *priv = GET_PRIV (swapper);
+
+ g_atomic_int_set (&priv->to_quit, 1);
return TRUE;
}
const GValue * value, GParamSpec * pspec)
{
GstVulkanSwapper *swapper = GST_VULKAN_SWAPPER (object);
+ GstVulkanSwapperPrivate *priv = GET_PRIV (swapper);
switch (prop_id) {
case PROP_FORCE_ASPECT_RATIO:
- swapper->priv->force_aspect_ratio = g_value_get_boolean (value);
+ priv->force_aspect_ratio = g_value_get_boolean (value);
break;
case PROP_PIXEL_ASPECT_RATIO:
- swapper->priv->par_n = gst_value_get_fraction_numerator (value);
- swapper->priv->par_d = gst_value_get_fraction_denominator (value);
+ priv->par_n = gst_value_get_fraction_numerator (value);
+ priv->par_d = gst_value_get_fraction_denominator (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
GValue * value, GParamSpec * pspec)
{
GstVulkanSwapper *swapper = GST_VULKAN_SWAPPER (object);
+ GstVulkanSwapperPrivate *priv = GET_PRIV (swapper);
switch (prop_id) {
case PROP_FORCE_ASPECT_RATIO:
- g_value_set_boolean (value, swapper->priv->force_aspect_ratio);
+ g_value_set_boolean (value, priv->force_aspect_ratio);
break;
case PROP_PIXEL_ASPECT_RATIO:
- gst_value_set_fraction (value, swapper->priv->par_n,
- swapper->priv->par_d);
+ gst_value_set_fraction (value, priv->par_n, priv->par_d);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
gst_vulkan_swapper_finalize (GObject * object)
{
GstVulkanSwapper *swapper = GST_VULKAN_SWAPPER (object);
+ GstVulkanSwapperPrivate *priv = GET_PRIV (swapper);
GstVulkanInstance *instance =
gst_vulkan_device_get_instance (swapper->device);
int i;
- g_signal_handler_disconnect (swapper->window, swapper->priv->draw_id);
- swapper->priv->draw_id = 0;
+ g_signal_handler_disconnect (swapper->window, priv->draw_id);
+ priv->draw_id = 0;
- g_signal_handler_disconnect (swapper->window, swapper->priv->close_id);
- swapper->priv->close_id = 0;
+ g_signal_handler_disconnect (swapper->window, priv->close_id);
+ priv->close_id = 0;
- g_signal_handler_disconnect (swapper->window, swapper->priv->resize_id);
- swapper->priv->resize_id = 0;
+ g_signal_handler_disconnect (swapper->window, priv->resize_id);
+ priv->resize_id = 0;
- if (!gst_vulkan_trash_list_wait (swapper->priv->trash_list, -1))
+ if (!gst_vulkan_trash_list_wait (priv->trash_list, -1))
GST_WARNING_OBJECT (swapper, "Failed to wait for all fences to complete "
"before shutting down");
- gst_object_unref (swapper->priv->trash_list);
- swapper->priv->trash_list = NULL;
+ gst_object_unref (priv->trash_list);
+ priv->trash_list = NULL;
- if (swapper->priv->swap_chain_images) {
- for (i = 0; i < swapper->priv->n_swap_chain_images; i++) {
- gst_memory_unref ((GstMemory *) swapper->priv->swap_chain_images[i]);
- swapper->priv->swap_chain_images[i] = NULL;
+ if (priv->swap_chain_images) {
+ for (i = 0; i < priv->n_swap_chain_images; i++) {
+ gst_memory_unref ((GstMemory *) priv->swap_chain_images[i]);
+ priv->swap_chain_images[i] = NULL;
}
- g_free (swapper->priv->swap_chain_images);
+ g_free (priv->swap_chain_images);
}
- swapper->priv->swap_chain_images = NULL;
+ priv->swap_chain_images = NULL;
- if (swapper->priv->swap_chain)
- swapper->priv->DestroySwapchainKHR (swapper->device->device,
- swapper->priv->swap_chain, NULL);
- swapper->priv->swap_chain = VK_NULL_HANDLE;
+ if (priv->swap_chain)
+ priv->DestroySwapchainKHR (swapper->device->device, priv->swap_chain, NULL);
+ priv->swap_chain = VK_NULL_HANDLE;
- if (swapper->priv->surface) {
- swapper->priv->DestroySurfaceKHR (instance->instance,
- swapper->priv->surface, NULL);
+ if (priv->surface) {
+ priv->DestroySurfaceKHR (instance->instance, priv->surface, NULL);
}
- swapper->priv->surface = VK_NULL_HANDLE;
+ priv->surface = VK_NULL_HANDLE;
- g_free (swapper->priv->surf_present_modes);
- swapper->priv->surf_present_modes = NULL;
+ g_free (priv->surf_present_modes);
+ priv->surf_present_modes = NULL;
- g_free (swapper->priv->surf_formats);
- swapper->priv->surf_formats = NULL;
+ g_free (priv->surf_formats);
+ priv->surf_formats = NULL;
- gst_buffer_replace (&swapper->priv->current_buffer, NULL);
- gst_caps_replace (&swapper->priv->caps, NULL);
+ gst_buffer_replace (&priv->current_buffer, NULL);
+ gst_caps_replace (&priv->caps, NULL);
- g_mutex_clear (&swapper->priv->render_lock);
+ g_mutex_clear (&priv->render_lock);
if (swapper->cmd_pool)
gst_object_unref (swapper->cmd_pool);
static void
gst_vulkan_swapper_init (GstVulkanSwapper * swapper)
{
- swapper->priv = gst_vulkan_swapper_get_instance_private (swapper);
+ GstVulkanSwapperPrivate *priv = GET_PRIV (swapper);
- g_mutex_init (&swapper->priv->render_lock);
+ g_mutex_init (&priv->render_lock);
- swapper->priv->force_aspect_ratio = DEFAULT_FORCE_ASPECT_RATIO;
- swapper->priv->par_n = DEFAULT_PIXEL_ASPECT_RATIO_N;
- swapper->priv->par_d = DEFAULT_PIXEL_ASPECT_RATIO_D;
+ priv->force_aspect_ratio = DEFAULT_FORCE_ASPECT_RATIO;
+ priv->par_n = DEFAULT_PIXEL_ASPECT_RATIO_N;
+ priv->par_d = DEFAULT_PIXEL_ASPECT_RATIO_D;
- swapper->priv->trash_list = gst_vulkan_trash_fence_list_new ();
+ priv->trash_list = gst_vulkan_trash_fence_list_new ();
}
static void
gst_vulkan_swapper_new (GstVulkanDevice * device, GstVulkanWindow * window)
{
GstVulkanSwapper *swapper;
+ GstVulkanSwapperPrivate *priv;
swapper = g_object_new (GST_TYPE_VULKAN_SWAPPER, NULL);
gst_object_ref_sink (swapper);
gst_object_unref (swapper);
return NULL;
}
+ priv = GET_PRIV (swapper);
- swapper->priv->close_id = g_signal_connect (swapper->window, "close",
+ priv->close_id = g_signal_connect (swapper->window, "close",
(GCallback) _on_window_close, swapper);
- swapper->priv->draw_id = g_signal_connect (swapper->window, "draw",
+ priv->draw_id = g_signal_connect (swapper->window, "draw",
(GCallback) _on_window_draw, swapper);
- swapper->priv->resize_id = g_signal_connect (swapper->window, "resize",
+ priv->resize_id = g_signal_connect (swapper->window, "resize",
(GCallback) _on_window_resize, swapper);
return swapper;
gst_vulkan_swapper_get_supported_caps (GstVulkanSwapper * swapper,
GError ** error)
{
+ GstVulkanSwapperPrivate *priv = GET_PRIV (swapper);
GstStructure *s;
GstCaps *caps;
g_value_init (&list, GST_TYPE_LIST);
- if (swapper->priv->n_surf_formats
- && swapper->priv->surf_formats[0].format == VK_FORMAT_UNDEFINED) {
+ if (priv->n_surf_formats
+ && priv->surf_formats[0].format == VK_FORMAT_UNDEFINED) {
_add_vk_format_to_list (&list, VK_FORMAT_B8G8R8A8_UNORM);
} else {
- for (i = 0; i < swapper->priv->n_surf_formats; i++) {
- _add_vk_format_to_list (&list, swapper->priv->surf_formats[i].format);
+ for (i = 0; i < priv->n_surf_formats; i++) {
+ _add_vk_format_to_list (&list, priv->surf_formats[i].format);
}
}
_allocate_swapchain (GstVulkanSwapper * swapper, GstCaps * caps,
GError ** error)
{
+ GstVulkanSwapperPrivate *priv = GET_PRIV (swapper);
VkSurfaceTransformFlagsKHR preTransform;
VkCompositeAlphaFlagsKHR alpha_flags;
VkPresentModeKHR present_mode;
gpu = gst_vulkan_device_get_physical_device (swapper->device);
err =
- swapper->priv->GetPhysicalDeviceSurfaceCapabilitiesKHR (gpu,
- swapper->priv->surface, &swapper->priv->surf_props);
+ priv->GetPhysicalDeviceSurfaceCapabilitiesKHR (gpu,
+ priv->surface, &priv->surf_props);
if (gst_vulkan_error_to_g_error (err, error,
"GetPhysicalDeviceSurfaceCapabilitiesKHR") < 0)
return FALSE;
/* width and height are either both -1, or both not -1. */
- if (swapper->priv->surf_props.currentExtent.width == -1) {
+ if (priv->surf_props.currentExtent.width == -1) {
/* If the surface size is undefined, the size is set to
* the size of the images requested. */
guint width, height;
gst_vulkan_window_get_surface_dimensions (swapper->window, &width, &height);
swapchain_dims.width = width;
swapchain_dims.height = height;
- swapper->priv->any_current_extent = TRUE;
+ priv->any_current_extent = TRUE;
} else {
/* If the surface size is defined, the swap chain size must match */
- swapchain_dims = swapper->priv->surf_props.currentExtent;
- swapper->priv->any_current_extent = FALSE;
+ swapchain_dims = priv->surf_props.currentExtent;
+ priv->any_current_extent = FALSE;
}
/* If mailbox mode is available, use it, as is the lowest-latency non-
* and is fastest (though it tears). If not, fall back to FIFO which is
* always available. */
present_mode = VK_PRESENT_MODE_FIFO_KHR;
- for (i = 0; i < swapper->priv->n_surf_present_modes; i++) {
- if (swapper->priv->surf_present_modes[i] == VK_PRESENT_MODE_MAILBOX_KHR) {
+ for (i = 0; i < priv->n_surf_present_modes; i++) {
+ if (priv->surf_present_modes[i] == VK_PRESENT_MODE_MAILBOX_KHR) {
present_mode = VK_PRESENT_MODE_MAILBOX_KHR;
break;
}
if ((present_mode != VK_PRESENT_MODE_MAILBOX_KHR) &&
- (swapper->priv->surf_present_modes[i] ==
- VK_PRESENT_MODE_IMMEDIATE_KHR)) {
+ (priv->surf_present_modes[i] == VK_PRESENT_MODE_IMMEDIATE_KHR)) {
present_mode = VK_PRESENT_MODE_IMMEDIATE_KHR;
}
}
/* Determine the number of VkImage's to use in the swap chain (we desire to
* own only 1 image at a time, besides the images being displayed and
* queued for display): */
- n_images_wanted = swapper->priv->surf_props.minImageCount + 1;
- if ((swapper->priv->surf_props.maxImageCount > 0) &&
- (n_images_wanted > swapper->priv->surf_props.maxImageCount)) {
+ n_images_wanted = priv->surf_props.minImageCount + 1;
+ if ((priv->surf_props.maxImageCount > 0) &&
+ (n_images_wanted > priv->surf_props.maxImageCount)) {
/* Application must settle for fewer images than desired: */
- n_images_wanted = swapper->priv->surf_props.maxImageCount;
+ n_images_wanted = priv->surf_props.maxImageCount;
}
- if (swapper->priv->surf_props.
+ if (priv->surf_props.
supportedTransforms & VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR) {
preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
} else {
- preTransform = swapper->priv->surf_props.currentTransform;
+ preTransform = priv->surf_props.currentTransform;
}
- format = gst_vulkan_format_from_video_info (&swapper->priv->v_info, 0);
- color_space = _vk_color_space_from_video_info (&swapper->priv->v_info);
+ format = gst_vulkan_format_from_video_info (&priv->v_info, 0);
+ color_space = _vk_color_space_from_video_info (&priv->v_info);
- if ((swapper->priv->surf_props.supportedCompositeAlpha &
+ if ((priv->surf_props.supportedCompositeAlpha &
VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR) != 0) {
alpha_flags = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
- } else if ((swapper->priv->surf_props.supportedCompositeAlpha &
+ } else if ((priv->surf_props.supportedCompositeAlpha &
VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR) != 0) {
alpha_flags = VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR;
} else {
return FALSE;
}
- if ((swapper->priv->surf_props.supportedUsageFlags &
+ if ((priv->surf_props.supportedUsageFlags &
VK_IMAGE_USAGE_TRANSFER_DST_BIT) != 0) {
usage |= VK_IMAGE_USAGE_TRANSFER_DST_BIT;
} else {
"Incorrect usage flags available for the swap images");
return FALSE;
}
- if ((swapper->priv->
+ if ((priv->
surf_props.supportedUsageFlags & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT)
!= 0) {
usage |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
VkSwapchainCreateInfoKHR swap_chain_info = { 0, };
VkSwapchainKHR old_swap_chain;
- old_swap_chain = swapper->priv->swap_chain;
+ old_swap_chain = priv->swap_chain;
/* *INDENT-OFF* */
swap_chain_info = (VkSwapchainCreateInfoKHR) {
.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR,
.pNext = NULL,
- .surface = swapper->priv->surface,
+ .surface = priv->surface,
.minImageCount = n_images_wanted,
.imageFormat = format,
.imageColorSpace = color_space,
/* *INDENT-ON* */
err =
- swapper->priv->CreateSwapchainKHR (swapper->device->device,
- &swap_chain_info, NULL, &swapper->priv->swap_chain);
+ priv->CreateSwapchainKHR (swapper->device->device,
+ &swap_chain_info, NULL, &priv->swap_chain);
if (gst_vulkan_error_to_g_error (err, error, "vkCreateSwapchainKHR") < 0)
return FALSE;
if (old_swap_chain != VK_NULL_HANDLE) {
- swapper->priv->DestroySwapchainKHR (swapper->device->device,
- old_swap_chain, NULL);
+ priv->DestroySwapchainKHR (swapper->device->device, old_swap_chain, NULL);
}
}
err =
- swapper->priv->GetSwapchainImagesKHR (swapper->device->device,
- swapper->priv->swap_chain, &swapper->priv->n_swap_chain_images, NULL);
+ priv->GetSwapchainImagesKHR (swapper->device->device,
+ priv->swap_chain, &priv->n_swap_chain_images, NULL);
if (gst_vulkan_error_to_g_error (err, error, "vkGetSwapchainImagesKHR") < 0)
return FALSE;
- swap_chain_images = g_new0 (VkImage, swapper->priv->n_swap_chain_images);
+ swap_chain_images = g_new0 (VkImage, priv->n_swap_chain_images);
err =
- swapper->priv->GetSwapchainImagesKHR (swapper->device->device,
- swapper->priv->swap_chain, &swapper->priv->n_swap_chain_images,
- swap_chain_images);
+ priv->GetSwapchainImagesKHR (swapper->device->device,
+ priv->swap_chain, &priv->n_swap_chain_images, swap_chain_images);
if (gst_vulkan_error_to_g_error (err, error, "vkGetSwapchainImagesKHR") < 0) {
g_free (swap_chain_images);
return FALSE;
}
- swapper->priv->swap_chain_images =
- g_new0 (GstVulkanImageMemory *, swapper->priv->n_swap_chain_images);
- for (i = 0; i < swapper->priv->n_swap_chain_images; i++) {
- swapper->priv->swap_chain_images[i] = (GstVulkanImageMemory *)
+ priv->swap_chain_images =
+ g_new0 (GstVulkanImageMemory *, priv->n_swap_chain_images);
+ for (i = 0; i < priv->n_swap_chain_images; i++) {
+ priv->swap_chain_images[i] = (GstVulkanImageMemory *)
gst_vulkan_image_memory_wrapped (swapper->device, swap_chain_images[i],
format, swapchain_dims.width, swapchain_dims.height,
VK_IMAGE_TILING_OPTIMAL, usage, NULL, NULL);
- swapper->priv->swap_chain_images[i]->barrier.parent.pipeline_stages =
+ priv->swap_chain_images[i]->barrier.parent.pipeline_stages =
VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
- swapper->priv->swap_chain_images[i]->barrier.parent.access_flags =
+ priv->swap_chain_images[i]->barrier.parent.access_flags =
VK_ACCESS_MEMORY_READ_BIT;
- swapper->priv->swap_chain_images[i]->barrier.image_layout =
+ priv->swap_chain_images[i]->barrier.image_layout =
VK_IMAGE_LAYOUT_UNDEFINED;
}
static gboolean
_swapchain_resize (GstVulkanSwapper * swapper, GError ** error)
{
+ GstVulkanSwapperPrivate *priv = GET_PRIV (swapper);
int i;
if (!swapper->queue) {
}
}
- if (swapper->priv->swap_chain_images) {
- for (i = 0; i < swapper->priv->n_swap_chain_images; i++) {
- if (swapper->priv->swap_chain_images[i])
- gst_memory_unref ((GstMemory *) swapper->priv->swap_chain_images[i]);
+ if (priv->swap_chain_images) {
+ for (i = 0; i < priv->n_swap_chain_images; i++) {
+ if (priv->swap_chain_images[i])
+ gst_memory_unref ((GstMemory *) priv->swap_chain_images[i]);
}
- g_free (swapper->priv->swap_chain_images);
- swapper->priv->swap_chain_images = NULL;
+ g_free (priv->swap_chain_images);
+ priv->swap_chain_images = NULL;
}
- return _allocate_swapchain (swapper, swapper->priv->caps, error);
+ return _allocate_swapchain (swapper, priv->caps, error);
}
static gboolean
configure_display_from_info (GstVulkanSwapper * swapper, GstVideoInfo * vinfo)
{
+ GstVulkanSwapperPrivate *priv = GET_PRIV (swapper);
gint width;
gint height;
gboolean ok;
par_n = 1;
/* get display's PAR */
- if (swapper->priv->par_n != 0 && swapper->priv->par_d != 0) {
- display_par_n = swapper->priv->par_n;
- display_par_d = swapper->priv->par_d;
+ if (priv->par_n != 0 && priv->par_d != 0) {
+ display_par_n = priv->par_n;
+ display_par_d = priv->par_d;
} else {
display_par_n = 1;
display_par_d = 1;
if (height % display_ratio_den == 0) {
GST_DEBUG_OBJECT (swapper, "keeping video height");
- swapper->priv->dar_width = (guint)
+ priv->dar_width = (guint)
gst_util_uint64_scale_int (height, display_ratio_num,
display_ratio_den);
- swapper->priv->dar_height = height;
+ priv->dar_height = height;
} else if (width % display_ratio_num == 0) {
GST_DEBUG_OBJECT (swapper, "keeping video width");
- swapper->priv->dar_width = width;
- swapper->priv->dar_height = (guint)
+ priv->dar_width = width;
+ priv->dar_height = (guint)
gst_util_uint64_scale_int (width, display_ratio_den, display_ratio_num);
} else {
GST_DEBUG_OBJECT (swapper, "approximating while keeping video height");
- swapper->priv->dar_width = (guint)
+ priv->dar_width = (guint)
gst_util_uint64_scale_int (height, display_ratio_num,
display_ratio_den);
- swapper->priv->dar_height = height;
+ priv->dar_height = height;
}
- GST_DEBUG_OBJECT (swapper, "scaling to %dx%d", swapper->priv->dar_width,
- swapper->priv->dar_height);
+ GST_DEBUG_OBJECT (swapper, "scaling to %dx%d", priv->dar_width,
+ priv->dar_height);
return TRUE;
}
gst_vulkan_swapper_set_caps (GstVulkanSwapper * swapper, GstCaps * caps,
GError ** error)
{
- if (!gst_video_info_from_caps (&swapper->priv->v_info, caps)) {
+ GstVulkanSwapperPrivate *priv = GET_PRIV (swapper);
+
+ if (!gst_video_info_from_caps (&priv->v_info, caps)) {
g_set_error (error, GST_VULKAN_ERROR,
VK_ERROR_INITIALIZATION_FAILED, "Failed to get GstVideoInfo from caps");
return FALSE;
}
- if (!configure_display_from_info (swapper, &swapper->priv->v_info)) {
+ if (!configure_display_from_info (swapper, &priv->v_info)) {
g_set_error (error, GST_VULKAN_ERROR,
VK_ERROR_INITIALIZATION_FAILED, "Failed to configure display sizes");
return FALSE;
}
- gst_caps_replace (&swapper->priv->caps, caps);
+ gst_caps_replace (&priv->caps, caps);
return _swapchain_resize (swapper, error);
}
_build_render_buffer_cmd (GstVulkanSwapper * swapper, guint32 swap_idx,
GstBuffer * buffer, GstVulkanCommandBuffer ** cmd_ret, GError ** error)
{
+ GstVulkanSwapperPrivate *priv = GET_PRIV (swapper);
GstMemory *in_mem;
GstVulkanImageMemory *swap_img;
GstVulkanCommandBuffer *cmd_buf;
GstVideoRectangle src, dst, rslt;
VkResult err;
- g_return_val_if_fail (swap_idx < swapper->priv->n_swap_chain_images, FALSE);
- swap_img = swapper->priv->swap_chain_images[swap_idx];
+ g_return_val_if_fail (swap_idx < priv->n_swap_chain_images, FALSE);
+ swap_img = priv->swap_chain_images[swap_idx];
if (!(cmd_buf = gst_vulkan_command_pool_create (swapper->cmd_pool, error)))
return FALSE;
}
src.x = src.y = 0;
- src.w = swapper->priv->dar_width;
- src.h = swapper->priv->dar_height;
+ src.w = priv->dar_width;
+ src.h = priv->dar_height;
dst.x = dst.y = 0;
dst.w = gst_vulkan_image_memory_get_width (swap_img);
dst.h = gst_vulkan_image_memory_get_height (swap_img);
- gst_video_sink_center_rect (src, dst, &rslt,
- swapper->priv->force_aspect_ratio);
+ gst_video_sink_center_rect (src, dst, &rslt, priv->force_aspect_ratio);
GST_TRACE_OBJECT (swapper, "rendering into result rectangle %ux%u+%u,%u "
"src %ux%u dst %ux%u", rslt.w, rslt.h, rslt.x, rslt.y, src.w, src.h,
},
.srcOffsets = {
{0, 0, 0},
- {GST_VIDEO_INFO_WIDTH (&swapper->priv->v_info), GST_VIDEO_INFO_HEIGHT (&swapper->priv->v_info), 1},
+ {GST_VIDEO_INFO_WIDTH (&priv->v_info), GST_VIDEO_INFO_HEIGHT (&priv->v_info), 1},
},
.dstSubresource = {
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
_render_buffer_unlocked (GstVulkanSwapper * swapper,
GstBuffer * buffer, GError ** error)
{
+ GstVulkanSwapperPrivate *priv = GET_PRIV (swapper);
VkSemaphore acquire_semaphore = { 0, };
VkSemaphore present_semaphore = { 0, };
VkSemaphoreCreateInfo semaphore_info = { 0, };
guint32 swap_idx;
VkResult err, present_err = VK_SUCCESS;
- gst_vulkan_trash_list_gc (swapper->priv->trash_list);
+ gst_vulkan_trash_list_gc (priv->trash_list);
if (!buffer) {
g_set_error (error, GST_VULKAN_ERROR,
goto error;
}
- if (g_atomic_int_get (&swapper->priv->to_quit)) {
+ if (g_atomic_int_get (&priv->to_quit)) {
g_set_error (error, GST_VULKAN_ERROR, VK_ERROR_SURFACE_LOST_KHR,
"Output window was closed");
goto error;
}
- gst_buffer_replace (&swapper->priv->current_buffer, buffer);
+ gst_buffer_replace (&priv->current_buffer, buffer);
/* *INDENT-OFF* */
semaphore_info = (VkSemaphoreCreateInfo) {
goto error;
err =
- swapper->priv->AcquireNextImageKHR (swapper->device->device,
- swapper->priv->swap_chain, -1, acquire_semaphore, VK_NULL_HANDLE,
- &swap_idx);
+ priv->AcquireNextImageKHR (swapper->device->device,
+ priv->swap_chain, -1, acquire_semaphore, VK_NULL_HANDLE, &swap_idx);
/* TODO: Deal with the VK_SUBOPTIMAL_KHR and VK_ERROR_OUT_OF_DATE_KHR */
if (err == VK_ERROR_OUT_OF_DATE_KHR) {
GST_DEBUG_OBJECT (swapper, "out of date frame acquired");
if (gst_vulkan_error_to_g_error (err, error, "vkQueueSubmit") < 0)
goto error;
- gst_vulkan_trash_list_add (swapper->priv->trash_list,
+ gst_vulkan_trash_list_add (priv->trash_list,
gst_vulkan_trash_new_mini_object_unref (gst_vulkan_fence_ref (fence),
GST_MINI_OBJECT_CAST (cmd_buf)));
- gst_vulkan_trash_list_add (swapper->priv->trash_list,
+ gst_vulkan_trash_list_add (priv->trash_list,
gst_vulkan_trash_new_free_semaphore (fence, acquire_semaphore));
acquire_semaphore = VK_NULL_HANDLE;
.waitSemaphoreCount = 1,
.pWaitSemaphores = &present_semaphore,
.swapchainCount = 1,
- .pSwapchains = &swapper->priv->swap_chain,
+ .pSwapchains = &priv->swap_chain,
.pImageIndices = &swap_idx,
.pResults = &present_err,
};
/* *INDENT-ON* */
- err = swapper->priv->QueuePresentKHR (swapper->queue->queue, &present);
+ err = priv->QueuePresentKHR (swapper->queue->queue, &present);
if (present_err == VK_ERROR_OUT_OF_DATE_KHR) {
GST_DEBUG_OBJECT (swapper, "out of date frame submitted");
if (gst_vulkan_error_to_g_error (err, error, "vkQueueSubmit") < 0)
goto error;
- gst_vulkan_trash_list_add (swapper->priv->trash_list,
+ gst_vulkan_trash_list_add (priv->trash_list,
gst_vulkan_trash_new_free_semaphore (fence, present_semaphore));
fence = NULL;
}
static void
_on_window_draw (GstVulkanWindow * window, GstVulkanSwapper * swapper)
{
+ GstVulkanSwapperPrivate *priv = GET_PRIV (swapper);
GError *error = NULL;
RENDER_LOCK (swapper);
- if (!swapper->priv->current_buffer) {
+ if (!priv->current_buffer) {
GST_DEBUG_OBJECT (swapper, "No buffer to render");
RENDER_UNLOCK (swapper);
return;
}
/* TODO: perform some rate limiting of the number of redraw events */
- if (!_render_buffer_unlocked (swapper, swapper->priv->current_buffer, &error))
+ if (!_render_buffer_unlocked (swapper, priv->current_buffer, &error))
GST_ERROR_OBJECT (swapper, "Failed to redraw buffer %p %s",
- swapper->priv->current_buffer, error->message);
+ priv->current_buffer, error->message);
g_clear_error (&error);
RENDER_UNLOCK (swapper);
}
_on_window_resize (GstVulkanWindow * window, guint width, guint height,
GstVulkanSwapper * swapper)
{
+ GstVulkanSwapperPrivate *priv = GET_PRIV (swapper);
GError *error = NULL;
RENDER_LOCK (swapper);
- if (swapper->priv->any_current_extent) {
+ if (priv->any_current_extent) {
if (!_swapchain_resize (swapper, &error))
GST_ERROR_OBJECT (swapper, "Failed to resize swapchain: %s",
error->message);