[retro-gtk/gtk-cleanup: 5/12] gl-display: Add retro_gl_clear_texture() and use autocleanups
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [retro-gtk/gtk-cleanup: 5/12] gl-display: Add retro_gl_clear_texture() and use autocleanups
- Date: Sun, 24 May 2020 13:01:23 +0000 (UTC)
commit e234afa4c598b7703e17439dd1549eb337ce5888
Author: Adrien Plazas <kekun plazas laposte net>
Date: Sun May 24 14:36:43 2020 +0200
gl-display: Add retro_gl_clear_texture() and use autocleanups
This makes the code safer and more concise.
retro-gtk/retro-gl-display.c | 21 +++++++--------------
retro-gtk/retro-gl-private.h | 8 ++++++++
2 files changed, 15 insertions(+), 14 deletions(-)
---
diff --git a/retro-gtk/retro-gl-display.c b/retro-gtk/retro-gl-display.c
index ae21e7c..1c158a6 100644
--- a/retro-gtk/retro-gl-display.c
+++ b/retro-gtk/retro-gl-display.c
@@ -10,6 +10,7 @@
#include "retro-gl-display-private.h"
#include <epoxy/gl.h>
+#include "retro-gl-private.h"
#include "retro-glsl-filter-private.h"
#include "retro-pixbuf.h"
#include "retro-pixdata.h"
@@ -63,10 +64,7 @@ static void
clear_video (RetroGLDisplay *self)
{
g_clear_object (&self->pixbuf);
- if (self->pixdata != NULL) {
- retro_pixdata_free (self->pixdata);
- self->pixdata = NULL;
- }
+ g_clear_pointer (&self->pixdata, retro_pixdata_free);
}
static void
@@ -255,8 +253,7 @@ realize (RetroGLDisplay *self)
(const GLvoid *) offsetof (RetroVertex, texture_coordinates));
}
- glDeleteTextures (1, &self->texture);
- self->texture = 0;
+ retro_gl_clear_texture (&self->texture);
glGenTextures (1, &self->texture);
glBindTexture (GL_TEXTURE_2D, self->texture);
@@ -279,8 +276,7 @@ unrealize (RetroGLDisplay *self)
gtk_gl_area_make_current (GTK_GL_AREA (self));
- glDeleteTextures (1, &self->texture);
- self->texture = 0;
+ retro_gl_clear_texture (&self->texture);
for (filter = 0; filter < RETRO_VIDEO_FILTER_COUNT; filter++)
g_clear_object (&self->glsl_filter[filter]);
}
@@ -314,14 +310,11 @@ retro_gl_display_finalize (GObject *object)
RetroGLDisplay *self = (RetroGLDisplay *) object;
RetroVideoFilter filter;
- glDeleteTextures (1, &self->texture);
- self->texture = 0;
+ retro_gl_clear_texture (&self->texture);
for (filter = 0; filter < RETRO_VIDEO_FILTER_COUNT; filter++)
g_clear_object (&self->glsl_filter[filter]);
- if (self->core != NULL)
- g_object_unref (self->core);
- if (self->pixbuf != NULL)
- g_object_unref (self->pixbuf);
+ g_clear_object (&self->core);
+ g_clear_object (&self->pixbuf);
G_OBJECT_CLASS (retro_gl_display_parent_class)->finalize (object);
}
diff --git a/retro-gtk/retro-gl-private.h b/retro-gtk/retro-gl-private.h
index 7d43999..9693b07 100644
--- a/retro-gtk/retro-gl-private.h
+++ b/retro-gtk/retro-gl-private.h
@@ -21,6 +21,14 @@ retro_gl_steal_object (GLuint *ptr)
return ref;
}
+static inline void
+retro_gl_clear_texture (GLuint *ptr)
+{
+ glDeleteTextures (1, ptr);
+
+ *ptr = 0;
+}
+
static inline void
retro_gl_autocleanup_delete_shader (GLuint *ptr)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]