From 19ba0796e85613fbd2f5ebba754717635ee6cfda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 31 Dec 2022 02:54:12 +0100 Subject: [PATCH] DebugTools: port screenshot() away from std::string. Simple & easy, for a change. --- src/Magnum/DebugTools/Screenshot.cpp | 11 +++++------ src/Magnum/DebugTools/Screenshot.h | 18 +++++++++++------- .../DebugTools/Test/ScreenshotGLTest.cpp | 1 - 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/Magnum/DebugTools/Screenshot.cpp b/src/Magnum/DebugTools/Screenshot.cpp index fd57482de..1e7a00c74 100644 --- a/src/Magnum/DebugTools/Screenshot.cpp +++ b/src/Magnum/DebugTools/Screenshot.cpp @@ -26,9 +26,8 @@ #include "Screenshot.h" #include -#include +#include #include -#include #include "Magnum/PixelFormat.h" #include "Magnum/Image.h" @@ -39,12 +38,12 @@ namespace Magnum { namespace DebugTools { -bool screenshot(GL::AbstractFramebuffer& framebuffer, const std::string& filename) { +bool screenshot(GL::AbstractFramebuffer& framebuffer, const Containers::StringView filename) { PluginManager::Manager manager; return screenshot(manager, framebuffer, filename); } -bool screenshot(PluginManager::Manager& manager, GL::AbstractFramebuffer& framebuffer, const std::string& filename) { +bool screenshot(PluginManager::Manager& manager, GL::AbstractFramebuffer& framebuffer, const Containers::StringView filename) { /* Get the implementation-specific color read format for given framebuffer */ const GL::PixelFormat format = framebuffer.implementationColorReadFormat(); const GL::PixelType type = framebuffer.implementationColorReadType(); @@ -68,12 +67,12 @@ bool screenshot(PluginManager::Manager& manager, return screenshot(manager, framebuffer, *genericFormat, filename); } -bool screenshot(GL::AbstractFramebuffer& framebuffer, const PixelFormat format, const std::string& filename) { +bool screenshot(GL::AbstractFramebuffer& framebuffer, const PixelFormat format, const Containers::StringView filename) { PluginManager::Manager manager; return screenshot(manager, framebuffer, format, filename); } -bool screenshot(PluginManager::Manager& manager, GL::AbstractFramebuffer& framebuffer, const PixelFormat format, const std::string& filename) { +bool screenshot(PluginManager::Manager& manager, GL::AbstractFramebuffer& framebuffer, const PixelFormat format, const Containers::StringView filename) { Containers::Pointer converter; if(!(converter = manager.loadAndInstantiate("AnyImageConverter"))) return false; diff --git a/src/Magnum/DebugTools/Screenshot.h b/src/Magnum/DebugTools/Screenshot.h index 7e9ded2d2..dbb81b49f 100644 --- a/src/Magnum/DebugTools/Screenshot.h +++ b/src/Magnum/DebugTools/Screenshot.h @@ -29,7 +29,6 @@ * @brief Function @ref Magnum::DebugTools::screenshot() */ -#include #include #include "Magnum/Magnum.h" @@ -37,6 +36,11 @@ #include "Magnum/GL/GL.h" #include "Magnum/Trade/Trade.h" +#ifdef MAGNUM_BUILD_DEPRECATED +/* The filename used to be a std::string */ +#include +#endif + namespace Magnum { namespace DebugTools { /** @@ -51,7 +55,7 @@ using @ref GL::AbstractFramebuffer::implementationColorReadFormat() and @ref GL::AbstractFramebuffer::implementationColorReadType() and then mapped back to the generic @ref Magnum::PixelFormat "PixelFormat". If, for some reason, the driver-suggested pixel format is not desired, use the -@ref screenshot(GL::AbstractFramebuffer&, PixelFormat, const std::string&) +@ref screenshot(GL::AbstractFramebuffer&, PixelFormat, Containers::StringView) overload instead. The read pixel data are saved using the @@ -66,7 +70,7 @@ map the detected pixel format back to a generic format, if either the for given file format could not be loaded, or if the file saving fails (for example due to unsupported pixel format). A message is printed in each case. */ -bool MAGNUM_DEBUGTOOLS_EXPORT screenshot(GL::AbstractFramebuffer& framebuffer, const std::string& filename); +bool MAGNUM_DEBUGTOOLS_EXPORT screenshot(GL::AbstractFramebuffer& framebuffer, Containers::StringView filename); /** @overload @m_since{2019,10} @@ -75,7 +79,7 @@ Useful in case you already have an instance of the converter plugin manager in your application or if you intend to save screenshots often, as the operation doesn't involve costly dynamic library loading and unloading on every call. */ -bool MAGNUM_DEBUGTOOLS_EXPORT screenshot(PluginManager::Manager& manager, GL::AbstractFramebuffer& framebuffer, const std::string& filename); +bool MAGNUM_DEBUGTOOLS_EXPORT screenshot(PluginManager::Manager& manager, GL::AbstractFramebuffer& framebuffer, Containers::StringView filename); /** @brief Save a screenshot in requested pixel format to a file @@ -84,12 +88,12 @@ bool MAGNUM_DEBUGTOOLS_EXPORT screenshot(PluginManager::Manager& manager, GL::AbstractFramebuffer& framebuffer, PixelFormat format, const std::string& filename); +bool MAGNUM_DEBUGTOOLS_EXPORT screenshot(PluginManager::Manager& manager, GL::AbstractFramebuffer& framebuffer, PixelFormat format, Containers::StringView filename); }} diff --git a/src/Magnum/DebugTools/Test/ScreenshotGLTest.cpp b/src/Magnum/DebugTools/Test/ScreenshotGLTest.cpp index 26ec110d1..534a649e1 100644 --- a/src/Magnum/DebugTools/Test/ScreenshotGLTest.cpp +++ b/src/Magnum/DebugTools/Test/ScreenshotGLTest.cpp @@ -26,7 +26,6 @@ #include #include #include -#include /** @todo remove when screenshot() is -free */ #include #include #include