app,gpu,internal/egl: lock OS thread when making OpenGL context current

OpenGL stores the current context in thread-local memory, but commit
4f5baa9a51 removed a runtime.LockOSThread from app.Window that ensured
the goroutine that drives the context stays on the operating thread that
has the context current. This change restores the thread lock.

As a bonus, this change makes the OpenGL contexts responsible for locking
the thread at MakeCurrent, thereby removing LockOSThread calls from GPU
backend-agnostic code.

Fixes: https://todo.sr.ht/~eliasnaur/gio/334
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2022-01-05 11:42:31 +01:00
parent 7751d73740
commit 8d8aeef66b
5 changed files with 13 additions and 6 deletions
-1
View File
@@ -165,7 +165,6 @@ func newDriver(t *testing.T) driver.Device {
if err != nil {
t.Skipf("no context available: %v", err)
}
runtime.LockOSThread()
if err := ctx.MakeCurrent(); err != nil {
t.Fatal(err)
}
-3
View File
@@ -8,7 +8,6 @@ import (
"errors"
"image"
"image/color"
"runtime"
"gioui.org/gpu"
"gioui.org/gpu/internal/driver"
@@ -146,8 +145,6 @@ func (w *Window) Screenshot(img *image.RGBA) error {
func contextDo(ctx context, f func() error) error {
errCh := make(chan error)
go func() {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
if err := ctx.MakeCurrent(); err != nil {
errCh <- err
return