From 758ede11d0967b38eba75241fb5dadb395f29617 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Tue, 9 Jul 2019 14:45:48 +0200 Subject: [PATCH 02/28] cogl: Define autoptr cleanup functions for Cogl types Make possible to use g_autoptr () with Cogl types https://gitlab.gnome.org/GNOME/mutter/merge_requests/682 --- cogl/cogl/Makefile.am | 1 + cogl/cogl/cogl-autocleanups.h | 67 +++++++++++++++++++++++++++++++++++ cogl/cogl/cogl.h | 2 ++ 3 files changed, 70 insertions(+) create mode 100644 cogl/cogl/cogl-autocleanups.h diff --git a/cogl/cogl/Makefile.am b/cogl/cogl/Makefile.am index 66accf709..ecb5e8b59 100644 --- a/cogl/cogl/Makefile.am +++ b/cogl/cogl/Makefile.am @@ -38,60 +38,61 @@ endif AM_CFLAGS = $(COGL_DEP_CFLAGS) $(COGL_EXTRA_CFLAGS) $(MAINTAINER_CFLAGS) BUILT_SOURCES += cogl-defines.h cogl-egl-defines.h cogl-gl-header.h DISTCLEANFILES += cogl-defines.h cogl-egl-defines.h cogl-gl-header.h EXTRA_DIST += cogl-defines.h.in cogl-egl-defines.h.in cogl-gl-header.h.in pc_files = mutter-cogl-$(LIBMUTTER_API_VERSION).pc pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = $(pc_files) DISTCLEANFILES += $(pc_files) cogl_deprecated_h = \ deprecated/cogl-material-compat.h \ deprecated/cogl-vertex-buffer.h \ deprecated/cogl-shader.h \ deprecated/cogl-clutter.h \ deprecated/cogl-type-casts.h \ deprecated/cogl-auto-texture.h \ $(NULL) cogl_deprecated_nonintrospected_h = \ deprecated/cogl-framebuffer-deprecated.h \ $(NULL) # public 1.x api headers cogl_1_public_h = \ $(cogl_deprecated_h) \ cogl1-context.h \ + cogl-autocleanups.h \ cogl-bitmap.h \ cogl-color.h \ cogl-matrix.h \ cogl-offscreen.h \ cogl-primitives.h \ cogl-texture.h \ cogl-types.h \ cogl.h \ $(NULL) cogl_nonintrospected_h = \ cogl-object.h \ cogl-renderer.h \ cogl-swap-chain.h \ cogl-onscreen-template.h \ cogl-display.h \ cogl-context.h \ cogl-pipeline.h \ cogl-pipeline-state.h \ cogl-pipeline-layer-state.h \ cogl-snippet.h \ cogl-gles2.h \ cogl-gles2-types.h \ cogl-index-buffer.h \ cogl-attribute-buffer.h \ cogl-indices.h \ cogl-attribute.h \ cogl-primitive.h \ cogl-framebuffer.h \ cogl-onscreen.h \ diff --git a/cogl/cogl/cogl-autocleanups.h b/cogl/cogl/cogl-autocleanups.h new file mode 100644 index 000000000..f18002418 --- /dev/null +++ b/cogl/cogl/cogl-autocleanups.h @@ -0,0 +1,67 @@ +/* + * Cogl + * + * A Low Level GPU Graphics and Utilities API + * + * Copyright (C) 2009 Intel Corporation. + * Copyright (C) 2019 Canonical Ltd. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ + +#if !defined(__COGL_H_INSIDE__) && !defined(COGL_COMPILATION) +#error "Only can be included directly." +#endif + +#ifndef __COGL_AUTOCLEANUPS_H__ +#define __COGL_AUTOCLEANUPS_H__ + +#ifndef __GI_SCANNER__ + +G_DEFINE_AUTOPTR_CLEANUP_FUNC (CoglAtlasTexture, cogl_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (CoglAttribute, cogl_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (CoglAttributeBuffer, cogl_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (CoglBitmap, cogl_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (CoglColor, cogl_color_free) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (CoglDisplay, cogl_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (CoglEuler, cogl_euler_free) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (CoglFramebuffer, cogl_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (CoglIndices, cogl_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (CoglHandle, cogl_handle_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (CoglMatrix, cogl_matrix_free) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (CoglMatrixEntry, cogl_matrix_entry_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (CoglMatrixStack, cogl_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (CoglObject, cogl_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (CoglOffscreen, cogl_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (CoglOnscreenTemplate, cogl_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (CoglPath, cogl_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (CoglPipeline, cogl_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (CoglQuaternion, cogl_quaternion_free) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (CoglRenderer, cogl_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (CoglSnippet, cogl_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (CoglTexture, cogl_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (CoglTexture2D, cogl_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (CoglTexture2DSliced, cogl_object_unref) + +#endif /* __GI_SCANNER__ */ + +#endif /* __COGL_AUTOCLEANUPS_H__ */ diff --git a/cogl/cogl/cogl.h b/cogl/cogl/cogl.h index 5210e3c59..c7cf7e6a8 100644 --- a/cogl/cogl/cogl.h +++ b/cogl/cogl/cogl.h @@ -127,51 +127,53 @@ #include #include #include #include /* XXX: This will definitly go away once all the Clutter winsys * code has been migrated down into Cogl! */ #include /* * API deprecations */ #include /* * Cogl Path api compatability * * The cogl_path_ api used to be part of the core Cogl api so for * compatability we include cogl-path.h via cogl.h * * Note: we have to make sure not to include cogl-path.h while * building core cogl or generating the Cogl .gir data because * cogl-path now gets built after cogl and some cogl-path headers are * only generated at build time... */ #if defined (COGL_HAS_COGL_PATH_SUPPORT) && \ !defined (COGL_COMPILATION) && \ !defined (COGL_GIR_SCANNING) #include #endif +#include + /** * SECTION:cogl * @short_description: General purpose API * * General utility functions for COGL. */ /* The gobject introspection scanner seems to parse public headers in * isolation which means we need to be extra careful about how we * define and undefine __COGL_H_INSIDE__ used to detect when internal * headers are incorrectly included by developers. In the gobject * introspection case we have to manually define __COGL_H_INSIDE__ as * a commandline argument for the scanner which means we must be * careful not to undefine it in a header... */ #ifdef __COGL_MUST_UNDEF_COGL_H_INSIDE__ #undef __COGL_H_INSIDE__ #undef __COGL_MUST_UNDEF_COGL_H_INSIDE__ #endif #endif /* __COGL_H__ */ -- 2.26.2