From 686081077ac3fa4672127341d5457f888f6de6c5 Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Fri, 18 Aug 2023 15:07:42 +0200 Subject: [PATCH] cogl: Port Journal away from CoglObject Part-of: --- cogl/cogl/cogl-framebuffer.c | 2 +- cogl/cogl/cogl-journal-private.h | 18 +++++++++++------- cogl/cogl/cogl-journal.c | 24 ++++++++++++++++++++---- 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/cogl/cogl/cogl-framebuffer.c b/cogl/cogl/cogl-framebuffer.c index b5cf644fa..1c3d554a0 100644 --- a/cogl/cogl/cogl-framebuffer.c +++ b/cogl/cogl/cogl-framebuffer.c @@ -346,7 +346,7 @@ cogl_framebuffer_dispose (GObject *object) g_clear_pointer (&priv->clip_stack, _cogl_clip_stack_unref); g_clear_object (&priv->modelview_stack); g_clear_object (&priv->projection_stack); - g_clear_pointer (&priv->journal, _cogl_journal_free); + g_clear_object (&priv->journal); ctx->framebuffers = g_list_remove (ctx->framebuffers, framebuffer); diff --git a/cogl/cogl/cogl-journal-private.h b/cogl/cogl/cogl-journal-private.h index a8280f3da..34ddaec5b 100644 --- a/cogl/cogl/cogl-journal-private.h +++ b/cogl/cogl/cogl-journal-private.h @@ -31,7 +31,6 @@ #pragma once #include "cogl/cogl-texture.h" -#include "cogl/cogl-object-private.h" #include "cogl/cogl-clip-stack.h" #include "cogl/cogl-fence-private.h" @@ -39,6 +38,8 @@ typedef struct _CoglJournal { + GObject parent_instance; + /* A pointer the framebuffer that is using this journal. This is only valid when the journal is not empty. It *does* take a reference on the framebuffer. Although this creates a circular @@ -67,6 +68,15 @@ typedef struct _CoglJournal } CoglJournal; +#define COGL_TYPE_JOURNAL (cogl_journal_get_type ()) + +COGL_EXPORT +G_DECLARE_FINAL_TYPE (CoglJournal, + cogl_journal, + COGL, + JOURNAL, + GObject) + /* To improve batching of geometry when submitting vertices to OpenGL we * log the texture rectangles we want to draw to a journal, so when we * later flush the journal we aim to batch data, and gl draw calls. */ @@ -85,9 +95,6 @@ typedef struct _CoglJournalEntry CoglJournal * _cogl_journal_new (CoglFramebuffer *framebuffer); -void -_cogl_journal_free (CoglJournal *journal); - void _cogl_journal_log_quad (CoglJournal *journal, const float *position, @@ -116,6 +123,3 @@ _cogl_journal_try_read_pixel (CoglJournal *journal, int y, CoglBitmap *bitmap, gboolean *found_intersection); - -gboolean -_cogl_is_journal (void *object); diff --git a/cogl/cogl/cogl-journal.c b/cogl/cogl/cogl-journal.c index 6f1da9a30..065e669de 100644 --- a/cogl/cogl/cogl-journal.c +++ b/cogl/cogl/cogl-journal.c @@ -122,9 +122,12 @@ typedef void (*CoglJournalBatchCallback) (CoglJournalEntry *start, typedef gboolean (*CoglJournalBatchTest) (CoglJournalEntry *entry0, CoglJournalEntry *entry1); -void -_cogl_journal_free (CoglJournal *journal) +G_DEFINE_TYPE (CoglJournal, cogl_journal, G_TYPE_OBJECT); + +static void +cogl_journal_dispose (GObject *object) { + CoglJournal *journal = COGL_JOURNAL (object); int i; if (journal->entries) @@ -136,13 +139,26 @@ _cogl_journal_free (CoglJournal *journal) if (journal->vbo_pool[i]) cogl_object_unref (journal->vbo_pool[i]); - g_free (journal); + G_OBJECT_CLASS (cogl_journal_parent_class)->dispose (object); +} + +static void +cogl_journal_init (CoglJournal *journal) +{ +} + +static void +cogl_journal_class_init (CoglJournalClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (class); + + object_class->dispose = cogl_journal_dispose; } CoglJournal * _cogl_journal_new (CoglFramebuffer *framebuffer) { - CoglJournal *journal = g_new0 (CoglJournal, 1); + CoglJournal *journal = g_object_new (COGL_TYPE_JOURNAL, NULL); journal->framebuffer = framebuffer; journal->entries = g_array_new (FALSE, FALSE, sizeof (CoglJournalEntry));