DPF

DISTRHO Plugin Framework
Log | Files | Refs | Submodules | README | LICENSE

commit 241845f387f03473e84254f7bfb73bd09460417a
parent 4336226e13cea171ebfdc30fac2e78565c7594ef
Author: falkTX <falktx@falktx.com>
Date:   Mon, 31 Oct 2022 00:51:53 +0000

Fix GL context issues when using ImageAboutWindow

Signed-off-by: falkTX <falktx@falktx.com>

Diffstat:
Mdgl/StandaloneWindow.hpp | 11++++++++++-
Mdgl/Window.hpp | 6+++++-
Mdgl/src/ImageBaseWidgets.cpp | 13++++++++++---
Mdgl/src/Window.cpp | 25+++++++++++++++++++++----
4 files changed, 46 insertions(+), 9 deletions(-)

diff --git a/dgl/StandaloneWindow.hpp b/dgl/StandaloneWindow.hpp @@ -1,6 +1,6 @@ /* * 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 * or without fee is hereby granted, provided that the above copyright notice and this @@ -54,6 +54,15 @@ public: } /** + 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. */ bool isVisible() const noexcept { return Window::isVisible(); } diff --git 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 @@ -1,6 +1,6 @@ /* * 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 * 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) return; - img = image; - if (image.isInvalid()) + { + img = image; return; + } + + reinit(); + + img = image; setSize(image.getSize()); setGeometryConstraints(image.getWidth(), image.getHeight(), true, true); + + done(); } template <class ImageType> diff --git 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