~eliasnaur/gio

e90c99a66c1e7e2ff548b6b2a9db2f328b136c2a — Elias Naur 2 hours ago 1d4bf04 main
internal/egl: replace glFinish with eglWaitClient

glFinish depends on package gl which is about to require a function
pointer loader. eglWaitClient is in the EGL API and always available.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
3 files changed, 11 insertions(+), 8 deletions(-)

M internal/egl/egl.go
M internal/egl/egl_unix.go
M internal/egl/egl_windows.go
M internal/egl/egl.go => internal/egl/egl.go +1 -8
@@ 11,12 11,10 @@ import (
	"strings"

	"gioui.org/gpu"
	"gioui.org/internal/gl"
	"gioui.org/internal/srgb"
)

type Context struct {
	c             *gl.Functions
	disp          _EGLDisplay
	eglCtx        *eglContext
	eglSurf       _EGLSurface


@@ 105,14 103,9 @@ func NewContext(disp NativeDisplayType) (*Context, error) {
	if err != nil {
		return nil, err
	}
	f, err := gl.NewFunctions(nil)
	if err != nil {
		return nil, err
	}
	c := &Context{
		disp:   eglDisp,
		eglCtx: eglCtx,
		c:      f,
	}
	return c, nil
}


@@ 126,7 119,7 @@ func (c *Context) ReleaseSurface() {
		return
	}
	// Make sure any in-flight GL commands are complete.
	c.c.Finish()
	eglWaitClient()
	c.ReleaseCurrent()
	eglDestroySurface(c.disp, c.eglSurf)
	c.eglSurf = nilEGLSurface

M internal/egl/egl_unix.go => internal/egl/egl_unix.go +4 -0
@@ 102,3 102,7 @@ func eglCreateWindowSurface(disp _EGLDisplay, conf _EGLConfig, win NativeWindowT
	eglSurf := C.eglCreateWindowSurface(disp, conf, win, &attribs[0])
	return eglSurf
}

func eglWaitClient() bool {
	return C.eglWaitClient() == C.EGL_TRUE
}

M internal/egl/egl_windows.go => internal/egl/egl_windows.go +6 -0
@@ 40,6 40,7 @@ var (
	_eglSwapBuffers         = libEGL.NewProc("eglSwapBuffers")
	_eglTerminate           = libEGL.NewProc("eglTerminate")
	_eglQueryString         = libEGL.NewProc("eglQueryString")
	_eglWaitClient          = libEGL.NewProc("eglWaitClient")
)

var loadOnce sync.Once


@@ 156,6 157,11 @@ func eglQueryString(disp _EGLDisplay, name _EGLint) string {
	return syscall.BytePtrToString((*byte)(unsafe.Pointer(r)))
}

func eglWaitClient() bool {
	r, _, _ := _eglWaitClient.Call()
	return r != 0
}

// issue34474KeepAlive calls runtime.KeepAlive as a
// workaround for golang.org/issue/34474.
func issue34474KeepAlive(v interface{}) {