mtk: Add a copy of MetaRectangle

Just to get the basics for porting Cogl to using it instead of
cairo_rectangle_int_t.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3128>
This commit is contained in:
Bilal Elmoussaoui 2023-07-19 15:45:56 +02:00
parent 765a918a62
commit c035e0e238
4 changed files with 107 additions and 0 deletions

View File

@ -3,9 +3,11 @@ mtk_mtk_includesubdir = mtk_includesubdir / 'mtk'
mtk_headers = [
'mtk.h',
'mtk-macros.h',
'mtk-rectangle.h',
]
mtk_sources = [
'mtk-rectangle.c',
]
mtk_private_headers = [

38
mtk/mtk/mtk-rectangle.c Normal file
View File

@ -0,0 +1,38 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "mtk/mtk-rectangle.h"
MtkRectangle *
mtk_rectangle_copy (const MtkRectangle *rect)
{
return g_memdup2 (rect, sizeof (MtkRectangle));
}
void
mtk_rectangle_free (MtkRectangle *rect)
{
g_free (rect);
}
G_DEFINE_BOXED_TYPE (MtkRectangle, mtk_rectangle,
mtk_rectangle_copy, mtk_rectangle_free);

66
mtk/mtk/mtk-rectangle.h Normal file
View File

@ -0,0 +1,66 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <cairo.h>
#include <glib-object.h>
#include "mtk/mtk-macros.h"
#define MTK_TYPE_RECTANGLE (mtk_rectangle_get_type ())
/**
* MtkRectangle:
* @x: X coordinate of the top-left corner
* @y: Y coordinate of the top-left corner
* @width: Width of the rectangle
* @height: Height of the rectangle
*/
#ifdef __GI_SCANNER__
/* The introspection scanner is currently unable to lookup how
* cairo_rectangle_int_t is actually defined. This prevents
* introspection data for the GdkRectangle type to include fields
* descriptions. To workaround this issue, we define it with the same
* content as cairo_rectangle_int_t, but only under the introspection
* define.
*/
struct _MtkRectangle
{
int x;
int y;
int width;
int height;
};
typedef struct _MtkRectangle MtkRectangle;
#else
typedef cairo_rectangle_int_t MtkRectangle;
#endif
MTK_EXPORT
GType mtk_rectangle_get_type (void);
MTK_EXPORT
MtkRectangle * mtk_rectangle_copy (const MtkRectangle *rect);
MTK_EXPORT
void mtk_rectangle_free (MtkRectangle *rect);

View File

@ -23,6 +23,7 @@
#define __MTK_H_INSIDE__
#include "mtk/mtk-rectangle.h"
#include "mtk/mtk-macros.h"
#undef __MTK_H_INSIDE__