diff --git a/docs/reference/gdk/gdk4-sections.txt b/docs/reference/gdk/gdk4-sections.txt index 784615d1ea..fcb247b6ac 100644 --- a/docs/reference/gdk/gdk4-sections.txt +++ b/docs/reference/gdk/gdk4-sections.txt @@ -717,6 +717,7 @@ gdk_paintable_get_intrinsic_aspect_ratio gdk_paintable_compute_concrete_size gdk_paintable_invalidate_contents gdk_paintable_invalidate_size +gdk_paintable_new_empty
diff --git a/gdk/gdkpaintable.c b/gdk/gdkpaintable.c index 378172ff2a..8405d2ad06 100644 --- a/gdk/gdkpaintable.c +++ b/gdk/gdkpaintable.c @@ -544,3 +544,102 @@ gdk_paintable_compute_concrete_size (GdkPaintable *paintable, } } +#define GDK_TYPE_EMPTY_PAINTABLE (gdk_empty_paintable_get_type()) +static +G_DECLARE_FINAL_TYPE(GdkEmptyPaintable, gdk_empty_paintable, GDK, EMPTY_PAINTABLE, GObject) + +struct _GdkEmptyPaintable +{ + GObject parent_instance; + + int width; + int height; +}; + +struct _GdkEmptyPaintableClass +{ + GObjectClass parent_class; +}; + +static void +gdk_empty_paintable_snapshot (GdkPaintable *paintable, + GdkSnapshot *snapshot, + double width, + double height) +{ +} + +static GdkPaintableFlags +gdk_empty_paintable_get_flags (GdkPaintable *paintable) +{ + return GDK_PAINTABLE_STATIC_SIZE + | GDK_PAINTABLE_STATIC_CONTENTS; +} + +static int +gdk_empty_paintable_get_intrinsic_width (GdkPaintable *paintable) +{ + GdkEmptyPaintable *self = GDK_EMPTY_PAINTABLE (paintable); + + return self->width; +} + +static int +gdk_empty_paintable_get_intrinsic_height (GdkPaintable *paintable) +{ + GdkEmptyPaintable *self = GDK_EMPTY_PAINTABLE (paintable); + + return self->height; +} + +static void +gdk_empty_paintable_paintable_init (GdkPaintableInterface *iface) +{ + iface->snapshot = gdk_empty_paintable_snapshot; + iface->get_flags = gdk_empty_paintable_get_flags; + iface->get_intrinsic_width = gdk_empty_paintable_get_intrinsic_width; + iface->get_intrinsic_height = gdk_empty_paintable_get_intrinsic_height; +} + +G_DEFINE_TYPE_WITH_CODE (GdkEmptyPaintable, gdk_empty_paintable, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (GDK_TYPE_PAINTABLE, + gdk_empty_paintable_paintable_init)) + +static void +gdk_empty_paintable_class_init (GdkEmptyPaintableClass *klass) +{ +} + +static void +gdk_empty_paintable_init (GdkEmptyPaintable *self) +{ +} + +/** + * gdk_paintable_new_empty: + * @intrinsic_width: The intrinsic width to report. Can be 0 for no width. + * @intrinsic_height: The intrinsic height to report. Can be 0 for no height. + * + * Returns a paintable that has the given intrinsic size and draws nothing. + * This is often useful for implementing the GdkPaintableClass:get_current_image() + * virtual function when the paintable is in an incomplete state (like a + * #GtkMediaStream before receiving the first frame). + * + * Returns: (transfer full) a #GdkPaintable + **/ +GdkPaintable * +gdk_paintable_new_empty (int intrinsic_width, + int intrinsic_height) +{ + GdkEmptyPaintable *result; + + g_return_val_if_fail (intrinsic_width < 0, NULL); + g_return_val_if_fail (intrinsic_height < 0, NULL); + + result = g_object_new (GDK_TYPE_EMPTY_PAINTABLE, NULL); + + result->width = intrinsic_width; + result->height = intrinsic_height; + + return GDK_PAINTABLE (result); +} diff --git a/gdk/gdkpaintable.h b/gdk/gdkpaintable.h index d38f0511e5..751e04af05 100644 --- a/gdk/gdkpaintable.h +++ b/gdk/gdkpaintable.h @@ -135,6 +135,9 @@ GDK_AVAILABLE_IN_ALL void gdk_paintable_invalidate_contents (GdkPaintable *paintable); GDK_AVAILABLE_IN_ALL void gdk_paintable_invalidate_size (GdkPaintable *paintable); +GDK_AVAILABLE_IN_ALL +GdkPaintable * gdk_paintable_new_empty (int intrinsic_width, + int intrinsic_height); G_END_DECLS diff --git a/modules/media/gtkffmediafile.c b/modules/media/gtkffmediafile.c index 46011e00d1..4ae1621575 100644 --- a/modules/media/gtkffmediafile.c +++ b/modules/media/gtkffmediafile.c @@ -114,6 +114,14 @@ gtk_ff_media_file_paintable_get_current_image (GdkPaintable *paintable) { GtkFfMediaFile *video = GTK_FF_MEDIA_FILE (paintable); + if (gtk_video_frame_ffmpeg_is_empty (&video->current_frame)) + { + if (video->codec_ctx) + return gdk_paintable_new_empty (video->codec_ctx->width, video->codec_ctx->height); + else + return gdk_paintable_new_empty (0, 0); + } + return GDK_PAINTABLE (g_object_ref (video->current_frame.texture)); } diff --git a/modules/media/gtkgstpaintable.c b/modules/media/gtkgstpaintable.c index 980459a34d..838b688db5 100644 --- a/modules/media/gtkgstpaintable.c +++ b/modules/media/gtkgstpaintable.c @@ -57,8 +57,7 @@ gtk_gst_paintable_paintable_get_current_image (GdkPaintable *paintable) if (self->image) return GDK_PAINTABLE (g_object_ref (self->image)); - g_warning ("FIXME: return empty something here"); - return NULL; + return gdk_paintable_new_empty (0, 0); } static int