Skip to content

Commit

Permalink
[gpu] Detach GL context when the window is destroyed
Browse files Browse the repository at this point in the history
It avoids a bug where the process keeps running when we close it.
  • Loading branch information
dacap committed Nov 28, 2024
1 parent b66b822 commit 31b8b48
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions os/skia/skia_window_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ class SkiaWindowBase : public T {
, m_colorSpace(nullptr) {
}

~SkiaWindowBase() {
#if SK_SUPPORT_GPU
detachGpuContext();
#endif
}

void initColorSpace() {
// Needed on macOS because WindowOSX::colorSpace() needs the
// m_nsWindow created, and that happens after
Expand Down Expand Up @@ -80,10 +86,8 @@ class SkiaWindowBase : public T {
m_surface.reset();

#if SK_SUPPORT_GPU
// Re-create OpenGL context
m_gl.detachGL();
if (m_glCtx && m_glCtx->isValid())
m_glCtx->destroyGLContext();
// Detach and re-create OpenGL context
detachGpuContext();

// GPU-accelerated surface
if (m_glCtx && m_preferGpuAcceleration) {
Expand Down Expand Up @@ -239,6 +243,15 @@ class SkiaWindowBase : public T {
#endif

private:

#if SK_SUPPORT_GPU
void detachGpuContext() {
m_gl.detachGL();
if (m_glCtx && m_glCtx->isValid())
m_glCtx->destroyGLContext();
}
#endif

bool m_preferGpuAcceleration = false;
Backend m_backend = Backend::NONE;
// Flag used to avoid accessing to an invalid m_surface in the first
Expand Down

0 comments on commit 31b8b48

Please sign in to comment.