feat(region): add SRgnDuplicate

This commit is contained in:
Adam Heinermann 2025-04-21 00:03:37 -07:00 committed by fallenoak
parent 4dcb438394
commit 335962e3fc
4 changed files with 61 additions and 1 deletions

View file

@ -349,6 +349,29 @@ void SRgnDelete(HSRGN handle) {
s_rgntable.Delete(handle);
}
void SRgnDuplicate(HSRGN orighandle, HSRGN *handle, uint32_t reserved) {
STORM_VALIDATE_BEGIN;
STORM_VALIDATE(handle);
*handle = nullptr;
STORM_VALIDATE(orighandle);
STORM_VALIDATE(reserved == 0);
STORM_VALIDATE_END_VOID;
HLOCKEDRGN origlockedhandle;
auto rgn = s_rgntable.Lock(orighandle, &origlockedhandle, 0);
if (rgn) {
HLOCKEDRGN newlockedhandle;
auto newrgn = s_rgntable.NewLock(handle, &newlockedhandle);
*newrgn = *rgn;
s_rgntable.Unlock(newlockedhandle);
s_rgntable.Unlock(origlockedhandle);
}
}
void SRgnGetBoundingRectf(HSRGN handle, RECTF* rect) {
STORM_VALIDATE_BEGIN;
STORM_VALIDATE(handle);

View file

@ -8,10 +8,12 @@ void SRgnClear(HSRGN handle);
void SRgnCombineRectf(HSRGN handle, RECTF* rect, void* param, int32_t combineMode);
void SRgnCreate(HSRGN* handlePtr, uint32_t reserved);
void SRgnCreate(HSRGN* handlePtr, uint32_t reserved = 0);
void SRgnDelete(HSRGN handle);
void SRgnDuplicate(HSRGN orighandle, HSRGN *handle, uint32_t reserved = 0);
void SRgnGetBoundingRectf(HSRGN handle, RECTF* rect);
void SRgnGetRectsf(HSRGN handle, uint32_t* numrects, RECTF* buffer);

View file

@ -12,6 +12,10 @@ class TSHashObject {
TSLink<T> m_linktoslot;
TSLink<T> m_linktofull;
TKey m_key;
TSHashObject & operator=(const TSHashObject &source) {
return *this;
}
};
#endif

View file

@ -92,6 +92,37 @@ TEST_CASE("SRgnCombineRectf", "[region]") {
}
}
TEST_CASE("SRgnDuplicate", "[region]") {
RgnDataTest region;
SECTION("creates an independent copy of a region") {
RECTF baseRect = { -1.0f, 1.0f, 1.0f, 2.0f };
SRgnCombineRectf(region, &baseRect, nullptr, SRGN_OR);
HSRGN newrgn = nullptr;
SRgnDuplicate(region, &newrgn);
REQUIRE(newrgn != nullptr);
SRgnClear(region);
uint32_t numrects = 1;
RECTF buffer[1];
SRgnGetRectsf(newrgn, &numrects, buffer);
REQUIRE(numrects == 1);
CHECK_THAT(buffer[0], MatchesRect(baseRect));
}
SECTION("sets handle to null when using an invalid region object") {
HSRGN inval = reinterpret_cast<HSRGN>(1234);
HSRGN newrgn = reinterpret_cast<HSRGN>(12345);
SRgnDuplicate(inval, &newrgn);
CHECK(newrgn == nullptr);
}
}
TEST_CASE("SRgnGetRectsf", "[region]") {
RgnDataTest region;