Signed-off-by: falkTX <falktx@falktx.com>pull/409/head
| @@ -1,6 +1,6 @@ | |||||
| /* | /* | ||||
| * DISTRHO Plugin Framework (DPF) | * DISTRHO Plugin Framework (DPF) | ||||
| * Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com> | |||||
| * Copyright (C) 2012-2022 Filipe Coelho <falktx@falktx.com> | |||||
| * | * | ||||
| * Permission to use, copy, modify, and/or distribute this software for any purpose with | * 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 | * or without fee is hereby granted, provided that the above copyright notice and this | ||||
| @@ -53,6 +53,15 @@ public: | |||||
| sgc.done(); | 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. | Overloaded functions to ensure they apply to the Window class. | ||||
| */ | */ | ||||
| @@ -105,13 +105,17 @@ public: | |||||
| /** Early context clearing, useful for standalone windows not created by you. */ | /** Early context clearing, useful for standalone windows not created by you. */ | ||||
| void done(); | void done(); | ||||
| /** Get a valid context back again. */ | |||||
| void reinit(); | |||||
| DISTRHO_DECLARE_NON_COPYABLE(ScopedGraphicsContext) | DISTRHO_DECLARE_NON_COPYABLE(ScopedGraphicsContext) | ||||
| DISTRHO_PREVENT_HEAP_ALLOCATION | DISTRHO_PREVENT_HEAP_ALLOCATION | ||||
| private: | private: | ||||
| Window& window; | Window& window; | ||||
| Window::PrivateData* ppData; | |||||
| Window::PrivateData* const ppData; | |||||
| bool active; | bool active; | ||||
| bool reenter; | |||||
| }; | }; | ||||
| /** | /** | ||||
| @@ -1,6 +1,6 @@ | |||||
| /* | /* | ||||
| * DISTRHO Plugin Framework (DPF) | * DISTRHO Plugin Framework (DPF) | ||||
| * Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com> | |||||
| * Copyright (C) 2012-2022 Filipe Coelho <falktx@falktx.com> | |||||
| * | * | ||||
| * Permission to use, copy, modify, and/or distribute this software for any purpose with | * 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 | * or without fee is hereby granted, provided that the above copyright notice and this | ||||
| @@ -61,13 +61,20 @@ void ImageBaseAboutWindow<ImageType>::setImage(const ImageType& image) | |||||
| if (img == image) | if (img == image) | ||||
| return; | return; | ||||
| img = image; | |||||
| if (image.isInvalid()) | if (image.isInvalid()) | ||||
| { | |||||
| img = image; | |||||
| return; | return; | ||||
| } | |||||
| reinit(); | |||||
| img = image; | |||||
| setSize(image.getSize()); | setSize(image.getSize()); | ||||
| setGeometryConstraints(image.getWidth(), image.getHeight(), true, true); | setGeometryConstraints(image.getWidth(), image.getHeight(), true, true); | ||||
| done(); | |||||
| } | } | ||||
| template <class ImageType> | template <class ImageType> | ||||
| @@ -27,12 +27,16 @@ START_NAMESPACE_DGL | |||||
| Window::ScopedGraphicsContext::ScopedGraphicsContext(Window& win) | Window::ScopedGraphicsContext::ScopedGraphicsContext(Window& win) | ||||
| : window(win), | : window(win), | ||||
| ppData(nullptr), | ppData(nullptr), | ||||
| active(puglBackendEnter(window.pData->view)) {} | |||||
| active(puglBackendEnter(window.pData->view)), | |||||
| reenter(false) | |||||
| { | |||||
| } | |||||
| Window::ScopedGraphicsContext::ScopedGraphicsContext(Window& win, Window& transientWin) | Window::ScopedGraphicsContext::ScopedGraphicsContext(Window& win, Window& transientWin) | ||||
| : window(win), | : window(win), | ||||
| ppData(transientWin.pData), | ppData(transientWin.pData), | ||||
| active(false) | |||||
| active(false), | |||||
| reenter(true) | |||||
| { | { | ||||
| puglBackendLeave(ppData->view); | puglBackendLeave(ppData->view); | ||||
| active = puglBackendEnter(window.pData->view); | active = puglBackendEnter(window.pData->view); | ||||
| @@ -51,13 +55,26 @@ void Window::ScopedGraphicsContext::done() | |||||
| active = false; | active = false; | ||||
| } | } | ||||
| if (ppData != nullptr) | |||||
| if (reenter) | |||||
| { | { | ||||
| reenter = false; | |||||
| DISTRHO_SAFE_ASSERT_RETURN(ppData != nullptr,); | |||||
| puglBackendEnter(ppData->view); | 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 | // Window | ||||