vulkan/ios: keep track of surface changes
This commit is contained in:
parent
c8614bf4da
commit
db157428ee
@ -66,10 +66,12 @@ struct _GstVulkanSwapperPrivate
|
|||||||
/* runtime variables */
|
/* runtime variables */
|
||||||
gint to_quit;
|
gint to_quit;
|
||||||
GstBuffer *current_buffer;
|
GstBuffer *current_buffer;
|
||||||
|
gboolean any_current_extent;
|
||||||
|
|
||||||
/* signal handlers */
|
/* signal handlers */
|
||||||
gulong close_id;
|
gulong close_id;
|
||||||
gulong draw_id;
|
gulong draw_id;
|
||||||
|
gulong resize_id;
|
||||||
|
|
||||||
/* properties */
|
/* properties */
|
||||||
gboolean force_aspect_ratio;
|
gboolean force_aspect_ratio;
|
||||||
@ -104,6 +106,8 @@ G_DEFINE_TYPE_WITH_CODE (GstVulkanSwapper, gst_vulkan_swapper,
|
|||||||
|
|
||||||
static void _on_window_draw (GstVulkanWindow * window,
|
static void _on_window_draw (GstVulkanWindow * window,
|
||||||
GstVulkanSwapper * swapper);
|
GstVulkanSwapper * swapper);
|
||||||
|
static void _on_window_resize (GstVulkanWindow * window,
|
||||||
|
guint width, guint height, GstVulkanSwapper * swapper);
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
_get_function_table (GstVulkanSwapper * swapper)
|
_get_function_table (GstVulkanSwapper * swapper)
|
||||||
@ -525,6 +529,9 @@ gst_vulkan_swapper_finalize (GObject * object)
|
|||||||
g_signal_handler_disconnect (swapper->window, swapper->priv->close_id);
|
g_signal_handler_disconnect (swapper->window, swapper->priv->close_id);
|
||||||
swapper->priv->close_id = 0;
|
swapper->priv->close_id = 0;
|
||||||
|
|
||||||
|
g_signal_handler_disconnect (swapper->window, swapper->priv->resize_id);
|
||||||
|
swapper->priv->resize_id = 0;
|
||||||
|
|
||||||
if (swapper->window)
|
if (swapper->window)
|
||||||
gst_object_unref (swapper->window);
|
gst_object_unref (swapper->window);
|
||||||
swapper->window = NULL;
|
swapper->window = NULL;
|
||||||
@ -586,6 +593,8 @@ gst_vulkan_swapper_new (GstVulkanDevice * device, GstVulkanWindow * window)
|
|||||||
(GCallback) _on_window_close, swapper);
|
(GCallback) _on_window_close, swapper);
|
||||||
swapper->priv->draw_id = g_signal_connect (swapper->window, "draw",
|
swapper->priv->draw_id = g_signal_connect (swapper->window, "draw",
|
||||||
(GCallback) _on_window_draw, swapper);
|
(GCallback) _on_window_draw, swapper);
|
||||||
|
swapper->priv->resize_id = g_signal_connect (swapper->window, "resize",
|
||||||
|
(GCallback) _on_window_resize, swapper);
|
||||||
|
|
||||||
return swapper;
|
return swapper;
|
||||||
}
|
}
|
||||||
@ -672,11 +681,15 @@ _allocate_swapchain (GstVulkanSwapper * swapper, GstCaps * caps,
|
|||||||
if (swapper->priv->surf_props.currentExtent.width == -1) {
|
if (swapper->priv->surf_props.currentExtent.width == -1) {
|
||||||
/* If the surface size is undefined, the size is set to
|
/* If the surface size is undefined, the size is set to
|
||||||
* the size of the images requested. */
|
* the size of the images requested. */
|
||||||
swapchain_dims.width = 320;
|
guint width, height;
|
||||||
swapchain_dims.height = 240;
|
gst_vulkan_window_get_surface_dimensions (swapper->window, &width, &height);
|
||||||
|
swapchain_dims.width = width;
|
||||||
|
swapchain_dims.height = height;
|
||||||
|
swapper->priv->any_current_extent = TRUE;
|
||||||
} else {
|
} else {
|
||||||
/* If the surface size is defined, the swap chain size must match */
|
/* If the surface size is defined, the swap chain size must match */
|
||||||
swapchain_dims = swapper->priv->surf_props.currentExtent;
|
swapchain_dims = swapper->priv->surf_props.currentExtent;
|
||||||
|
swapper->priv->any_current_extent = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If mailbox mode is available, use it, as is the lowest-latency non-
|
/* If mailbox mode is available, use it, as is the lowest-latency non-
|
||||||
@ -1319,3 +1332,18 @@ _on_window_draw (GstVulkanWindow * window, GstVulkanSwapper * swapper)
|
|||||||
g_clear_error (&error);
|
g_clear_error (&error);
|
||||||
RENDER_UNLOCK (swapper);
|
RENDER_UNLOCK (swapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_on_window_resize (GstVulkanWindow * window, guint width, guint height,
|
||||||
|
GstVulkanSwapper * swapper)
|
||||||
|
{
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
|
RENDER_LOCK (swapper);
|
||||||
|
if (swapper->priv->any_current_extent) {
|
||||||
|
if (!_swapchain_resize (swapper, &error))
|
||||||
|
GST_ERROR_OBJECT (swapper, "Failed to resize swapchain: %s",
|
||||||
|
error->message);
|
||||||
|
}
|
||||||
|
RENDER_UNLOCK (swapper);
|
||||||
|
}
|
||||||
|
@ -93,6 +93,7 @@ enum
|
|||||||
SIGNAL_0,
|
SIGNAL_0,
|
||||||
SIGNAL_CLOSE,
|
SIGNAL_CLOSE,
|
||||||
SIGNAL_DRAW,
|
SIGNAL_DRAW,
|
||||||
|
SIGNAL_RESIZE,
|
||||||
LAST_SIGNAL
|
LAST_SIGNAL
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -193,6 +194,10 @@ gst_vulkan_window_class_init (GstVulkanWindowClass * klass)
|
|||||||
g_signal_new ("draw", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, 0,
|
g_signal_new ("draw", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, 0,
|
||||||
NULL, NULL, NULL, G_TYPE_NONE, 0);
|
NULL, NULL, NULL, G_TYPE_NONE, 0);
|
||||||
|
|
||||||
|
gst_vulkan_window_signals[SIGNAL_RESIZE] =
|
||||||
|
g_signal_new ("resize", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, 0,
|
||||||
|
NULL, NULL, NULL, G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT);
|
||||||
|
|
||||||
gobject_class->set_property = gst_vulkan_window_set_property;
|
gobject_class->set_property = gst_vulkan_window_set_property;
|
||||||
gobject_class->get_property = gst_vulkan_window_get_property;
|
gobject_class->get_property = gst_vulkan_window_get_property;
|
||||||
gobject_class->finalize = gst_vulkan_window_finalize;
|
gobject_class->finalize = gst_vulkan_window_finalize;
|
||||||
@ -394,7 +399,8 @@ gst_vulkan_window_resize (GstVulkanWindow * window, gint width, gint height)
|
|||||||
window->priv->surface_width = width;
|
window->priv->surface_width = width;
|
||||||
window->priv->surface_height = height;
|
window->priv->surface_height = height;
|
||||||
|
|
||||||
/* XXX: possibly queue a resize/redraw */
|
g_signal_emit (window, gst_vulkan_window_signals[SIGNAL_RESIZE], 0, width,
|
||||||
|
height);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -431,6 +437,25 @@ gst_vulkan_window_set_window_handle (GstVulkanWindow * window, guintptr handle)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gst_vulkan_window_get_surface_dimensions (GstVulkanWindow * window,
|
||||||
|
guint * width, guint * height)
|
||||||
|
{
|
||||||
|
GstVulkanWindowClass *klass;
|
||||||
|
|
||||||
|
g_return_if_fail (GST_IS_VULKAN_WINDOW (window));
|
||||||
|
klass = GST_VULKAN_WINDOW_GET_CLASS (window);
|
||||||
|
|
||||||
|
if (klass->get_surface_dimensions) {
|
||||||
|
klass->get_surface_dimensions (window, width, height);
|
||||||
|
} else {
|
||||||
|
GST_DEBUG_OBJECT (window, "Returning size %ix%i",
|
||||||
|
window->priv->surface_width, window->priv->surface_height);
|
||||||
|
*width = window->priv->surface_width;
|
||||||
|
*height = window->priv->surface_height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
GType gst_vulkan_dummy_window_get_type (void);
|
GType gst_vulkan_dummy_window_get_type (void);
|
||||||
G_DEFINE_TYPE (GstVulkanDummyWindow, gst_vulkan_dummy_window,
|
G_DEFINE_TYPE (GstVulkanDummyWindow, gst_vulkan_dummy_window,
|
||||||
GST_TYPE_VULKAN_WINDOW);
|
GST_TYPE_VULKAN_WINDOW);
|
||||||
|
@ -90,6 +90,9 @@ struct _GstVulkanWindowClass {
|
|||||||
guint32 queue_family_idx);
|
guint32 queue_family_idx);
|
||||||
void (*set_window_handle) (GstVulkanWindow *window,
|
void (*set_window_handle) (GstVulkanWindow *window,
|
||||||
guintptr handle);
|
guintptr handle);
|
||||||
|
void (*get_surface_dimensions) (GstVulkanWindow *window,
|
||||||
|
guint * width,
|
||||||
|
guint * height);
|
||||||
|
|
||||||
/*< private >*/
|
/*< private >*/
|
||||||
gpointer _reserved[GST_PADDING];
|
gpointer _reserved[GST_PADDING];
|
||||||
@ -108,6 +111,10 @@ gboolean gst_vulkan_window_get_presentation_support (GstVulkanWi
|
|||||||
GstVulkanDevice *device,
|
GstVulkanDevice *device,
|
||||||
guint32 queue_family_idx);
|
guint32 queue_family_idx);
|
||||||
GST_VULKAN_API
|
GST_VULKAN_API
|
||||||
|
void gst_vulkan_window_get_surface_dimensions (GstVulkanWindow *window,
|
||||||
|
guint *width,
|
||||||
|
guint *height);
|
||||||
|
GST_VULKAN_API
|
||||||
void gst_vulkan_window_set_window_handle (GstVulkanWindow *window,
|
void gst_vulkan_window_set_window_handle (GstVulkanWindow *window,
|
||||||
guintptr handle);
|
guintptr handle);
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
@interface GstVulkanUIView : UIView
|
@interface GstVulkanUIView : UIView
|
||||||
|
- (void) setGstWindow:(GstVulkanWindowIos *)window_ios;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
typedef void (*GstVulkanWindowFunc) (gpointer data);
|
typedef void (*GstVulkanWindowFunc) (gpointer data);
|
||||||
|
@ -142,7 +142,9 @@ _create_window (GstVulkanWindowIos * window_ios)
|
|||||||
GstVulkanUIView *view;
|
GstVulkanUIView *view;
|
||||||
|
|
||||||
view = [[GstVulkanUIView alloc] initWithFrame:rect];
|
view = [[GstVulkanUIView alloc] initWithFrame:rect];
|
||||||
|
[view setGstWindow:window_ios];
|
||||||
view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
||||||
|
view.contentMode = UIViewContentModeRedraw;
|
||||||
|
|
||||||
priv->internal_view = (__bridge_retained gpointer)view;
|
priv->internal_view = (__bridge_retained gpointer)view;
|
||||||
[external_view addSubview:view];
|
[external_view addSubview:view];
|
||||||
@ -216,7 +218,9 @@ static void
|
|||||||
gst_vulkan_window_ios_close (GstVulkanWindow * window)
|
gst_vulkan_window_ios_close (GstVulkanWindow * window)
|
||||||
{
|
{
|
||||||
GstVulkanWindowIos *window_ios = GST_VULKAN_WINDOW_IOS (window);
|
GstVulkanWindowIos *window_ios = GST_VULKAN_WINDOW_IOS (window);
|
||||||
|
GstVulkanUIView *view = (__bridge GstVulkanUIView *) window_ios->priv->internal_view;
|
||||||
|
|
||||||
|
[view setGstWindow:NULL];
|
||||||
CFBridgingRelease (window_ios->priv->internal_view);
|
CFBridgingRelease (window_ios->priv->internal_view);
|
||||||
window_ios->priv->internal_view = NULL;
|
window_ios->priv->internal_view = NULL;
|
||||||
|
|
||||||
@ -240,13 +244,36 @@ gst_vulkan_window_ios_set_window_handle (GstVulkanWindow * window,
|
|||||||
window_ios->priv->external_view = view;
|
window_ios->priv->external_view = view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@implementation GstVulkanUIView
|
@implementation GstVulkanUIView {
|
||||||
|
GstVulkanWindowIos * window_ios;
|
||||||
|
|
||||||
|
guint width;
|
||||||
|
guint height;
|
||||||
|
};
|
||||||
|
|
||||||
+(Class) layerClass
|
+(Class) layerClass
|
||||||
{
|
{
|
||||||
return [CAMetalLayer class];
|
return [CAMetalLayer class];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-(void) setGstWindow:(GstVulkanWindowIos *) window
|
||||||
|
{
|
||||||
|
window_ios = window;
|
||||||
|
}
|
||||||
|
|
||||||
|
-(void) layoutSubViews
|
||||||
|
{
|
||||||
|
[super layoutSubviews];
|
||||||
|
CGSize rect = self.bounds.size;
|
||||||
|
GST_ERROR ("%ix%i", (int) rect.width, (int) rect.height);
|
||||||
|
gboolean resize = self->width != rect.width || self->height != rect.height;
|
||||||
|
self->width = rect.width;
|
||||||
|
self->height = rect.height;
|
||||||
|
if (resize && self->window_ios) {
|
||||||
|
gst_vulkan_window_resize (GST_VULKAN_WINDOW (self->window_ios), rect.width, rect.height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user