Skip to content

Commit

Permalink
app: [X11] don't recreate EGL surface during resize
Browse files Browse the repository at this point in the history
According to #565 X11 GPU drivers don't deal well with recreation of
EGL surfaces.

Thanks to Walter Schneider for debugging this issue and coming up with
the original patch.

Fixes: https://todo.sr.ht/~eliasnaur/gio/565
Co-authored-by: Walter Werner SCHNEIDER <[email protected]>
Signed-off-by: Elias Naur <[email protected]>
  • Loading branch information
eliasnaur and SchnWalter committed May 1, 2024
1 parent ba1e34e commit 38d8889
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 36 deletions.
2 changes: 1 addition & 1 deletion app/egl_wayland.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (c *wlContext) Refresh() error {
}
c.eglWin = eglWin
eglSurf := egl.NativeWindowType(uintptr(unsafe.Pointer(eglWin)))
if err := c.Context.CreateSurface(eglSurf, width, height); err != nil {
if err := c.Context.CreateSurface(eglSurf); err != nil {
return err
}
if err := c.Context.MakeCurrent(); err != nil {
Expand Down
29 changes: 12 additions & 17 deletions app/egl_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
package app

import (
"golang.org/x/sys/windows"

"gioui.org/internal/egl"
)

Expand All @@ -24,6 +22,18 @@ func init() {
if err != nil {
return nil, err
}
win, _, _ := w.HWND()
eglSurf := egl.NativeWindowType(win)
if err := ctx.CreateSurface(eglSurf); err != nil {
ctx.Release()
return nil, err
}
if err := ctx.MakeCurrent(); err != nil {
ctx.Release()
return nil, err
}
defer ctx.ReleaseCurrent()
ctx.EnableVSync(true)
return &glContext{win: w, Context: ctx}, nil
},
})
Expand All @@ -37,21 +47,6 @@ func (c *glContext) Release() {
}

func (c *glContext) Refresh() error {
c.Context.ReleaseSurface()
var (
win windows.Handle
width, height int
)
win, width, height = c.win.HWND()
eglSurf := egl.NativeWindowType(win)
if err := c.Context.CreateSurface(eglSurf, width, height); err != nil {
return err
}
if err := c.Context.MakeCurrent(); err != nil {
return err
}
c.Context.EnableVSync(true)
c.Context.ReleaseCurrent()
return nil
}

Expand Down
23 changes: 12 additions & 11 deletions app/egl_x11.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ func init() {
if err != nil {
return nil, err
}
win, _, _ := w.window()
eglSurf := egl.NativeWindowType(uintptr(win))
if err := ctx.CreateSurface(eglSurf); err != nil {
ctx.Release()
return nil, err
}
if err := ctx.MakeCurrent(); err != nil {
ctx.Release()
return nil, err
}
defer ctx.ReleaseCurrent()
ctx.EnableVSync(true)
return &x11Context{win: w, Context: ctx}, nil
}
}
Expand All @@ -37,17 +49,6 @@ func (c *x11Context) Release() {
}

func (c *x11Context) Refresh() error {
c.Context.ReleaseSurface()
win, width, height := c.win.window()
eglSurf := egl.NativeWindowType(uintptr(win))
if err := c.Context.CreateSurface(eglSurf, width, height); err != nil {
return err
}
if err := c.Context.MakeCurrent(); err != nil {
return err
}
defer c.Context.ReleaseCurrent()
c.Context.EnableVSync(true)
return nil
}

Expand Down
11 changes: 4 additions & 7 deletions internal/egl/egl.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ import (
)

type Context struct {
disp _EGLDisplay
eglCtx *eglContext
eglSurf _EGLSurface
width, height int
disp _EGLDisplay
eglCtx *eglContext
eglSurf _EGLSurface
}

type eglContext struct {
Expand Down Expand Up @@ -121,11 +120,9 @@ func (c *Context) VisualID() int {
return c.eglCtx.visualID
}

func (c *Context) CreateSurface(win NativeWindowType, width, height int) error {
func (c *Context) CreateSurface(win NativeWindowType) error {
eglSurf, err := createSurface(c.disp, c.eglCtx, win)
c.eglSurf = eglSurf
c.width = width
c.height = height
return err
}

Expand Down

0 comments on commit 38d8889

Please sign in to comment.