From f091b80fae52b039c520f5893bbce801d96607bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 11 Oct 2023 12:20:11 +0200 Subject: [PATCH] TextureTools: make the DistanceField class movable. No reason not to, even though the move is destructive. Also unblocks Text::DistanceFieldGlyphCache which wasn't movable due to this and one other problem. --- src/Magnum/TextureTools/DistanceField.cpp | 4 ++ src/Magnum/TextureTools/DistanceField.h | 18 ++++++++ .../TextureTools/Test/DistanceFieldGLTest.cpp | 44 ++++++++++++++++--- 3 files changed, 60 insertions(+), 6 deletions(-) diff --git a/src/Magnum/TextureTools/DistanceField.cpp b/src/Magnum/TextureTools/DistanceField.cpp index 8dc82b6a6..ddc58bc05 100644 --- a/src/Magnum/TextureTools/DistanceField.cpp +++ b/src/Magnum/TextureTools/DistanceField.cpp @@ -186,8 +186,12 @@ DistanceField::DistanceField(const UnsignedInt radius): _state{new State{radius} } } +DistanceField::DistanceField(DistanceField&&) noexcept = default; + DistanceField::~DistanceField() = default; +DistanceField& DistanceField::operator=(DistanceField&&) noexcept = default; + UnsignedInt DistanceField::radius() const { return _state->radius; } void DistanceField::operator()(GL::Texture2D& input, GL::Framebuffer& output, const Range2Di& rectangle, const Vector2i& diff --git a/src/Magnum/TextureTools/DistanceField.h b/src/Magnum/TextureTools/DistanceField.h index 86ca00ebe..99d077658 100644 --- a/src/Magnum/TextureTools/DistanceField.h +++ b/src/Magnum/TextureTools/DistanceField.h @@ -104,8 +104,26 @@ class MAGNUM_TEXTURETOOLS_EXPORT DistanceField { */ explicit DistanceField(UnsignedInt radius); + /** @brief Copying is not allowed */ + DistanceField(const DistanceField&) = delete; + + /** + * @brief Move constructor + * @m_since_latest + * + * Performs a destructive move, i.e. the original object isn't usable + * afterwards anymore. + */ + DistanceField(DistanceField&&) noexcept; + ~DistanceField(); + /** @brief Copying is not allowed */ + DistanceField& operator=(const DistanceField&) = delete; + + /** @brief Move constructor */ + DistanceField& operator=(DistanceField&&) noexcept; + /** @brief Max lookup radius */ UnsignedInt radius() const; diff --git a/src/Magnum/TextureTools/Test/DistanceFieldGLTest.cpp b/src/Magnum/TextureTools/Test/DistanceFieldGLTest.cpp index 68628d034..ea33d5206 100644 --- a/src/Magnum/TextureTools/Test/DistanceFieldGLTest.cpp +++ b/src/Magnum/TextureTools/Test/DistanceFieldGLTest.cpp @@ -63,9 +63,13 @@ namespace Magnum { namespace TextureTools { namespace Test { namespace { struct DistanceFieldGLTest: GL::OpenGLTester { explicit DistanceFieldGLTest(); + void construct(); + void constructCopy(); + void constructMove(); + /* This tests the GL::Texture overload, which itself calls into the GL::Framebuffer overload so both are covered */ - void test(); + void run(); #ifndef MAGNUM_TARGET_WEBGL void benchmark(); #endif @@ -79,7 +83,7 @@ const struct { const char* name; Vector2i size; Vector2i offset; -} TestData[]{ +} RunData[]{ {"", {64, 64}, {}}, {"with offset", {128, 96}, {64, 32}}, }; @@ -89,8 +93,12 @@ using namespace Containers::Literals; /* for SwiftShader detection */ #endif DistanceFieldGLTest::DistanceFieldGLTest() { - addInstancedTests({&DistanceFieldGLTest::test}, - Containers::arraySize(TestData)); + addTests({&DistanceFieldGLTest::construct, + &DistanceFieldGLTest::constructCopy, + &DistanceFieldGLTest::constructMove}); + + addInstancedTests({&DistanceFieldGLTest::run}, + Containers::arraySize(RunData)); #ifndef MAGNUM_TARGET_WEBGL addBenchmarks({&DistanceFieldGLTest::benchmark}, 5, BenchmarkType::GpuTime); @@ -120,8 +128,32 @@ DistanceFieldGLTest::DistanceFieldGLTest() { } } -void DistanceFieldGLTest::test() { - auto&& data = TestData[testCaseInstanceId()]; +void DistanceFieldGLTest::construct() { + DistanceField distanceField{32}; + CORRADE_COMPARE(distanceField.radius(), 32); +} + +void DistanceFieldGLTest::constructCopy() { + CORRADE_VERIFY(!std::is_copy_constructible{}); + CORRADE_VERIFY(!std::is_copy_assignable{}); +} + +void DistanceFieldGLTest::constructMove() { + DistanceField a{16}; + + DistanceField b = Utility::move(a); + CORRADE_COMPARE(b.radius(), 16); + + DistanceField c{8}; + c = Utility::move(b); + CORRADE_COMPARE(c.radius(), 16); + + CORRADE_VERIFY(std::is_nothrow_move_constructible::value); + CORRADE_VERIFY(std::is_nothrow_move_assignable::value); +} + +void DistanceFieldGLTest::run() { + auto&& data = RunData[testCaseInstanceId()]; setTestCaseDescription(data.name); Containers::Pointer importer;