From 26f013ba45b08a02bb028a461af68288a86fadb1 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 11 Jul 2013 16:08:41 -0700 Subject: [PATCH] Add a RegionDuplicate function This allocates a new region structure and copies a source region into it in a single API rather than forcing the caller to do both steps themselves. Signed-off-by: Keith Packard Reviewed-by: Adam Jackson --- dix/region.c | 15 +++++++++++++++ include/regionstr.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/dix/region.c b/dix/region.c index 737d2a861..15f3d01a5 100644 --- a/dix/region.c +++ b/dix/region.c @@ -255,6 +255,21 @@ RegionDestroy(RegionPtr pReg) free(pReg); } +RegionPtr +RegionDuplicate(RegionPtr pOld) +{ + RegionPtr pNew; + + pNew = RegionCreate(&pOld->extents, 0); + if (!pNew) + return NULL; + if (!RegionCopy(pNew, pOld)) { + RegionDestroy(pNew); + return NULL; + } + return pNew; +} + void RegionPrint(RegionPtr rgn) { diff --git a/include/regionstr.h b/include/regionstr.h index 805257b3f..4a0725d62 100644 --- a/include/regionstr.h +++ b/include/regionstr.h @@ -213,6 +213,8 @@ extern _X_EXPORT RegionPtr RegionCreate(BoxPtr /*rect */ , extern _X_EXPORT void RegionDestroy(RegionPtr /*pReg */ ); +extern _X_EXPORT RegionPtr RegionDuplicate(RegionPtr /* pOld */); + static inline Bool RegionCopy(RegionPtr dst, RegionPtr src) {