1
0
Fork 0

cogl: Port Display away from CoglObject

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3193>
This commit is contained in:
Bilal Elmoussaoui 2023-08-17 11:40:09 +02:00 committed by Marge Bot
parent 748c1fb9f4
commit 0f54700101
6 changed files with 41 additions and 45 deletions

View file

@ -261,7 +261,7 @@ clutter_backend_do_real_create_context (ClutterBackend *backend,
error: error:
if (backend->cogl_display != NULL) if (backend->cogl_display != NULL)
{ {
cogl_object_unref (backend->cogl_display); g_object_unref (backend->cogl_display);
backend->cogl_display = NULL; backend->cogl_display = NULL;
} }

View file

@ -155,11 +155,11 @@ cogl_context_new (CoglDisplay *display,
cogl_object_unref(renderer); cogl_object_unref(renderer);
} }
else else
cogl_object_ref (display); g_object_ref (display);
if (!cogl_display_setup (display, error)) if (!cogl_display_setup (display, error))
{ {
cogl_object_unref (display); g_object_unref (display);
g_free (context); g_free (context);
return NULL; return NULL;
} }
@ -182,14 +182,14 @@ cogl_context_new (CoglDisplay *display,
winsys = _cogl_context_get_winsys (context); winsys = _cogl_context_get_winsys (context);
if (!winsys->context_init (context, error)) if (!winsys->context_init (context, error))
{ {
cogl_object_unref (display); g_object_unref (display);
g_free (context); g_free (context);
return NULL; return NULL;
} }
if (!context->driver_vtable->context_init (context)) if (!context->driver_vtable->context_init (context))
{ {
cogl_object_unref (display); g_object_unref (display);
g_free (context); g_free (context);
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Failed to initialize context"); "Failed to initialize context");
@ -302,7 +302,7 @@ cogl_context_new (CoglDisplay *display,
&local_error); &local_error);
if (!context->default_gl_texture_2d_tex) if (!context->default_gl_texture_2d_tex)
{ {
cogl_object_unref (display); g_object_unref (display);
g_free (context); g_free (context);
g_propagate_prefixed_error (error, local_error, g_propagate_prefixed_error (error, local_error,
"Failed to create 1x1 fallback texture: "); "Failed to create 1x1 fallback texture: ");
@ -392,7 +392,7 @@ _cogl_context_free (CoglContext *context)
driver->context_deinit (context); driver->context_deinit (context);
cogl_object_unref (context->display); g_object_unref (context->display);
g_hash_table_remove_all (context->named_pipelines); g_hash_table_remove_all (context->named_pipelines);
g_hash_table_destroy (context->named_pipelines); g_hash_table_destroy (context->named_pipelines);

View file

@ -30,14 +30,13 @@
#pragma once #pragma once
#include "cogl/cogl-object-private.h"
#include "cogl/cogl-display.h" #include "cogl/cogl-display.h"
#include "cogl/cogl-renderer.h" #include "cogl/cogl-renderer.h"
#include "cogl/cogl-onscreen-template.h" #include "cogl/cogl-onscreen-template.h"
struct _CoglDisplay struct _CoglDisplay
{ {
CoglObject _parent; GObjectClass parnet_class;
gboolean setup; gboolean setup;
CoglRenderer *renderer; CoglRenderer *renderer;

View file

@ -34,17 +34,13 @@
#include <string.h> #include <string.h>
#include "cogl/cogl-private.h" #include "cogl/cogl-private.h"
#include "cogl/cogl-object.h"
#include "cogl/cogl-display-private.h" #include "cogl/cogl-display-private.h"
#include "cogl/cogl-renderer-private.h" #include "cogl/cogl-renderer-private.h"
#include "cogl/cogl-gtype-private.h"
#include "cogl/winsys/cogl-winsys-private.h" #include "cogl/winsys/cogl-winsys-private.h"
static void _cogl_display_free (CoglDisplay *display);
COGL_OBJECT_DEFINE (Display, display); G_DEFINE_TYPE (CoglDisplay, cogl_display, G_TYPE_OBJECT);
COGL_GTYPE_DEFINE_CLASS (Display, display);
static const CoglWinsysVtable * static const CoglWinsysVtable *
_cogl_display_get_winsys (CoglDisplay *display) _cogl_display_get_winsys (CoglDisplay *display)
@ -53,8 +49,10 @@ _cogl_display_get_winsys (CoglDisplay *display)
} }
static void static void
_cogl_display_free (CoglDisplay *display) cogl_display_dispose (GObject *object)
{ {
CoglDisplay *display = COGL_DISPLAY (object);
const CoglWinsysVtable *winsys; const CoglWinsysVtable *winsys;
if (display->setup) if (display->setup)
@ -76,14 +74,27 @@ _cogl_display_free (CoglDisplay *display)
display->onscreen_template = NULL; display->onscreen_template = NULL;
} }
g_free (display); G_OBJECT_CLASS (cogl_display_parent_class)->dispose (object);
}
static void
cogl_display_init (CoglDisplay *display)
{
}
static void
cogl_display_class_init (CoglDisplayClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
object_class->dispose = cogl_display_dispose;
} }
CoglDisplay * CoglDisplay *
cogl_display_new (CoglRenderer *renderer, cogl_display_new (CoglRenderer *renderer,
CoglOnscreenTemplate *onscreen_template) CoglOnscreenTemplate *onscreen_template)
{ {
CoglDisplay *display = g_new0 (CoglDisplay, 1); CoglDisplay *display = g_object_new (COGL_TYPE_DISPLAY, NULL);
GError *error = NULL; GError *error = NULL;
_cogl_init (); _cogl_init ();
@ -99,8 +110,6 @@ cogl_display_new (CoglRenderer *renderer,
display->setup = FALSE; display->setup = FALSE;
display = _cogl_display_object_new (display);
cogl_display_set_onscreen_template (display, onscreen_template); cogl_display_set_onscreen_template (display, onscreen_template);
return display; return display;

View file

@ -44,8 +44,9 @@
G_BEGIN_DECLS G_BEGIN_DECLS
/** /**
* SECTION:cogl-display * CoglDisplay:
* @short_description: Common aspects of a display pipeline *
* Common aspects of a display pipeline
* *
* The basic intention for this object is to let the application * The basic intention for this object is to let the application
* configure common display preferences before creating a context, and * configure common display preferences before creating a context, and
@ -67,15 +68,14 @@ G_BEGIN_DECLS
typedef struct _CoglDisplay CoglDisplay; typedef struct _CoglDisplay CoglDisplay;
#define COGL_DISPLAY(OBJECT) ((CoglDisplay *)OBJECT) #define COGL_TYPE_DISPLAY (cogl_display_get_type ())
/**
* cogl_display_get_gtype:
*
* Returns: a #GType that can be used with the GLib type system.
*/
COGL_EXPORT COGL_EXPORT
GType cogl_display_get_gtype (void); G_DECLARE_FINAL_TYPE (CoglDisplay,
cogl_display,
COGL,
DISPLAY,
GObject)
/** /**
* cogl_display_new: * cogl_display_new:
@ -181,16 +181,4 @@ COGL_EXPORT gboolean
cogl_display_setup (CoglDisplay *display, cogl_display_setup (CoglDisplay *display,
GError **error); GError **error);
/**
* cogl_is_display:
* @object: A #CoglObject pointer
*
* Gets whether the given object references a #CoglDisplay.
*
* Return value: %TRUE if the object references a #CoglDisplay
* and %FALSE otherwise.
*/
COGL_EXPORT gboolean
cogl_is_display (void *object);
G_END_DECLS G_END_DECLS

View file

@ -249,11 +249,11 @@ cogl_renderer_check_onscreen_template (CoglRenderer *renderer,
display = cogl_display_new (renderer, onscreen_template); display = cogl_display_new (renderer, onscreen_template);
if (!cogl_display_setup (display, error)) if (!cogl_display_setup (display, error))
{ {
cogl_object_unref (display); g_object_unref (display);
return FALSE; return FALSE;
} }
cogl_object_unref (display); g_object_unref (display);
return TRUE; return TRUE;
} }