Skip to content

Commit

Permalink
paintable: Introduce gdk_paintable_new_empty()
Browse files Browse the repository at this point in the history
Also, use it where appropriate.
  • Loading branch information
Benjamin Otte committed Apr 5, 2018
1 parent ffc7b2b commit c74854f
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/reference/gdk/gdk4-sections.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
<SECTION>

<SECTION>
Expand Down
99 changes: 99 additions & 0 deletions gdk/gdkpaintable.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
3 changes: 3 additions & 0 deletions gdk/gdkpaintable.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions modules/media/gtkffmediafile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
3 changes: 1 addition & 2 deletions modules/media/gtkgstpaintable.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c74854f

Please sign in to comment.