diff --git a/dgl/StandaloneWindow.hpp b/dgl/StandaloneWindow.hpp index 673a85e6..017a3a7d 100644 --- a/dgl/StandaloneWindow.hpp +++ b/dgl/StandaloneWindow.hpp @@ -1,6 +1,6 @@ /* * DISTRHO Plugin Framework (DPF) - * Copyright (C) 2012-2021 Filipe Coelho + * Copyright (C) 2012-2022 Filipe Coelho * * Permission to use, copy, modify, and/or distribute this software for any purpose with * or without fee is hereby granted, provided that the above copyright notice and this @@ -53,6 +53,15 @@ public: sgc.done(); } + /** + Get a graphics context back again. + Called when a valid graphics context is needed outside the constructor. + */ + void reinit() + { + sgc.reinit(); + } + /** Overloaded functions to ensure they apply to the Window class. */ diff --git a/dgl/Window.hpp b/dgl/Window.hpp index 99719888..b18fe071 100644 --- a/dgl/Window.hpp +++ b/dgl/Window.hpp @@ -105,13 +105,17 @@ public: /** Early context clearing, useful for standalone windows not created by you. */ void done(); + /** Get a valid context back again. */ + void reinit(); + DISTRHO_DECLARE_NON_COPYABLE(ScopedGraphicsContext) DISTRHO_PREVENT_HEAP_ALLOCATION private: Window& window; - Window::PrivateData* ppData; + Window::PrivateData* const ppData; bool active; + bool reenter; }; /** diff --git a/dgl/src/ImageBaseWidgets.cpp b/dgl/src/ImageBaseWidgets.cpp index eadc57fb..b1a79393 100644 --- a/dgl/src/ImageBaseWidgets.cpp +++ b/dgl/src/ImageBaseWidgets.cpp @@ -1,6 +1,6 @@ /* * DISTRHO Plugin Framework (DPF) - * Copyright (C) 2012-2021 Filipe Coelho + * Copyright (C) 2012-2022 Filipe Coelho * * Permission to use, copy, modify, and/or distribute this software for any purpose with * or without fee is hereby granted, provided that the above copyright notice and this @@ -61,13 +61,20 @@ void ImageBaseAboutWindow::setImage(const ImageType& image) if (img == image) return; - img = image; - if (image.isInvalid()) + { + img = image; return; + } + + reinit(); + + img = image; setSize(image.getSize()); setGeometryConstraints(image.getWidth(), image.getHeight(), true, true); + + done(); } template diff --git a/dgl/src/Window.cpp b/dgl/src/Window.cpp index 37c61d11..56bc2f7b 100644 --- a/dgl/src/Window.cpp +++ b/dgl/src/Window.cpp @@ -27,12 +27,16 @@ START_NAMESPACE_DGL Window::ScopedGraphicsContext::ScopedGraphicsContext(Window& win) : window(win), ppData(nullptr), - active(puglBackendEnter(window.pData->view)) {} + active(puglBackendEnter(window.pData->view)), + reenter(false) +{ +} Window::ScopedGraphicsContext::ScopedGraphicsContext(Window& win, Window& transientWin) : window(win), ppData(transientWin.pData), - active(false) + active(false), + reenter(true) { puglBackendLeave(ppData->view); active = puglBackendEnter(window.pData->view); @@ -51,13 +55,26 @@ void Window::ScopedGraphicsContext::done() active = false; } - if (ppData != nullptr) + if (reenter) { + reenter = false; + DISTRHO_SAFE_ASSERT_RETURN(ppData != nullptr,); + puglBackendEnter(ppData->view); - ppData = nullptr; } } +void Window::ScopedGraphicsContext::reinit() +{ + DISTRHO_SAFE_ASSERT_RETURN(!active,); + DISTRHO_SAFE_ASSERT_RETURN(!reenter,); + DISTRHO_SAFE_ASSERT_RETURN(ppData != nullptr,); + + reenter = true; + puglBackendLeave(ppData->view); + active = puglBackendEnter(window.pData->view); +} + // ----------------------------------------------------------------------- // Window