diff --git a/mtk/mtk/meson.build b/mtk/mtk/meson.build
index dd4d95259..b5cc5fd2e 100644
--- a/mtk/mtk/meson.build
+++ b/mtk/mtk/meson.build
@@ -21,7 +21,6 @@ if have_x11
endif
mtk_private_headers = [
- 'mtk-region-private.h',
]
diff --git a/mtk/mtk/mtk-region-private.h b/mtk/mtk/mtk-region-private.h
deleted file mode 100644
index 9ced6fad7..000000000
--- a/mtk/mtk/mtk-region-private.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Mtk
- *
- * A low-level base library.
- *
- * Copyright (C) 2023 Red Hat
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see .
- */
-
-#pragma once
-
-#include
-
-struct _MtkRegion
-{
- gatomicrefcount ref_count;
-
- pixman_region32_t inner_region;
-};
diff --git a/mtk/mtk/mtk-region.c b/mtk/mtk/mtk-region.c
index e01ed0c49..1bc029b98 100644
--- a/mtk/mtk/mtk-region.c
+++ b/mtk/mtk/mtk-region.c
@@ -22,8 +22,15 @@
*/
#include "config.h"
+
+#include
+
#include "mtk/mtk-region.h"
-#include "mtk/mtk-region-private.h"
+
+struct _MtkRegion
+{
+ pixman_region32_t inner_region;
+};
/**
* mtk_region_ref:
@@ -38,8 +45,15 @@ mtk_region_ref (MtkRegion *region)
{
g_return_val_if_fail (region != NULL, NULL);
- g_atomic_ref_count_inc (®ion->ref_count);
- return region;
+ return g_atomic_rc_box_acquire (region);
+}
+
+static void
+clear_region (gpointer data)
+{
+ MtkRegion *region = data;
+
+ pixman_region32_fini (®ion->inner_region);
}
void
@@ -47,11 +61,7 @@ mtk_region_unref (MtkRegion *region)
{
g_return_if_fail (region != NULL);
- if (g_atomic_ref_count_dec (®ion->ref_count))
- {
- pixman_region32_fini (®ion->inner_region);
- g_free (region);
- }
+ g_atomic_rc_box_release_full (region, clear_region);
}
G_DEFINE_BOXED_TYPE (MtkRegion, mtk_region,
@@ -62,9 +72,8 @@ mtk_region_create (void)
{
MtkRegion *region;
- region = g_new0 (MtkRegion, 1);
+ region = g_atomic_rc_box_new0 (MtkRegion);
- g_atomic_ref_count_init (®ion->ref_count);
pixman_region32_init (®ion->inner_region);
return region;
@@ -181,7 +190,7 @@ mtk_region_union_rectangle (MtkRegion *region,
pixman_region32_init_rect (&pixman_region,
rect->x, rect->y,
rect->width, rect->height);
- pixman_region32_union (®ion->inner_region,
+ pixman_region32_union (®ion->inner_region,
®ion->inner_region,
&pixman_region);
pixman_region32_fini (&pixman_region);
@@ -265,8 +274,8 @@ mtk_region_create_rectangle (const MtkRectangle *rect)
MtkRegion *region;
g_return_val_if_fail (rect != NULL, NULL);
- region = g_new0 (MtkRegion, 1);
- g_atomic_ref_count_init (®ion->ref_count);
+ region = g_atomic_rc_box_new0 (MtkRegion);
+
pixman_region32_init_rect (®ion->inner_region,
rect->x, rect->y,
rect->width, rect->height);
@@ -285,8 +294,7 @@ mtk_region_create_rectangles (const MtkRectangle *rects,
g_return_val_if_fail (rects != NULL, NULL);
g_return_val_if_fail (n_rects != 0, NULL);
- region = g_new0 (MtkRegion, 1);
- g_atomic_ref_count_init (®ion->ref_count);
+ region = g_atomic_rc_box_new0 (MtkRegion);
if (n_rects == 1)
{