Skip to content

Commit 38d8889

Browse files
eliasnaurSchnWalter
andcommitted
app: [X11] don't recreate EGL surface during resize
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]>
1 parent ba1e34e commit 38d8889

File tree

4 files changed

+29
-36
lines changed

4 files changed

+29
-36
lines changed

app/egl_wayland.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (c *wlContext) Refresh() error {
6969
}
7070
c.eglWin = eglWin
7171
eglSurf := egl.NativeWindowType(uintptr(unsafe.Pointer(eglWin)))
72-
if err := c.Context.CreateSurface(eglSurf, width, height); err != nil {
72+
if err := c.Context.CreateSurface(eglSurf); err != nil {
7373
return err
7474
}
7575
if err := c.Context.MakeCurrent(); err != nil {

app/egl_windows.go

+12-17
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
package app
66

77
import (
8-
"golang.org/x/sys/windows"
9-
108
"gioui.org/internal/egl"
119
)
1210

@@ -24,6 +22,18 @@ func init() {
2422
if err != nil {
2523
return nil, err
2624
}
25+
win, _, _ := w.HWND()
26+
eglSurf := egl.NativeWindowType(win)
27+
if err := ctx.CreateSurface(eglSurf); err != nil {
28+
ctx.Release()
29+
return nil, err
30+
}
31+
if err := ctx.MakeCurrent(); err != nil {
32+
ctx.Release()
33+
return nil, err
34+
}
35+
defer ctx.ReleaseCurrent()
36+
ctx.EnableVSync(true)
2737
return &glContext{win: w, Context: ctx}, nil
2838
},
2939
})
@@ -37,21 +47,6 @@ func (c *glContext) Release() {
3747
}
3848

3949
func (c *glContext) Refresh() error {
40-
c.Context.ReleaseSurface()
41-
var (
42-
win windows.Handle
43-
width, height int
44-
)
45-
win, width, height = c.win.HWND()
46-
eglSurf := egl.NativeWindowType(win)
47-
if err := c.Context.CreateSurface(eglSurf, width, height); err != nil {
48-
return err
49-
}
50-
if err := c.Context.MakeCurrent(); err != nil {
51-
return err
52-
}
53-
c.Context.EnableVSync(true)
54-
c.Context.ReleaseCurrent()
5550
return nil
5651
}
5752

app/egl_x11.go

+12-11
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ func init() {
2525
if err != nil {
2626
return nil, err
2727
}
28+
win, _, _ := w.window()
29+
eglSurf := egl.NativeWindowType(uintptr(win))
30+
if err := ctx.CreateSurface(eglSurf); err != nil {
31+
ctx.Release()
32+
return nil, err
33+
}
34+
if err := ctx.MakeCurrent(); err != nil {
35+
ctx.Release()
36+
return nil, err
37+
}
38+
defer ctx.ReleaseCurrent()
39+
ctx.EnableVSync(true)
2840
return &x11Context{win: w, Context: ctx}, nil
2941
}
3042
}
@@ -37,17 +49,6 @@ func (c *x11Context) Release() {
3749
}
3850

3951
func (c *x11Context) Refresh() error {
40-
c.Context.ReleaseSurface()
41-
win, width, height := c.win.window()
42-
eglSurf := egl.NativeWindowType(uintptr(win))
43-
if err := c.Context.CreateSurface(eglSurf, width, height); err != nil {
44-
return err
45-
}
46-
if err := c.Context.MakeCurrent(); err != nil {
47-
return err
48-
}
49-
defer c.Context.ReleaseCurrent()
50-
c.Context.EnableVSync(true)
5152
return nil
5253
}
5354

internal/egl/egl.go

+4-7
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ import (
1515
)
1616

1717
type Context struct {
18-
disp _EGLDisplay
19-
eglCtx *eglContext
20-
eglSurf _EGLSurface
21-
width, height int
18+
disp _EGLDisplay
19+
eglCtx *eglContext
20+
eglSurf _EGLSurface
2221
}
2322

2423
type eglContext struct {
@@ -121,11 +120,9 @@ func (c *Context) VisualID() int {
121120
return c.eglCtx.visualID
122121
}
123122

124-
func (c *Context) CreateSurface(win NativeWindowType, width, height int) error {
123+
func (c *Context) CreateSurface(win NativeWindowType) error {
125124
eglSurf, err := createSurface(c.disp, c.eglCtx, win)
126125
c.eglSurf = eglSurf
127-
c.width = width
128-
c.height = height
129126
return err
130127
}
131128

0 commit comments

Comments
 (0)