app: confine the eglWindow indirection to the Wayland backend

Only the Wayland backend needs an wl_egl_window between the wl_surface
and EGL. Move code dealing with the indirection to Wayland specific
code.

Then, introduce the eglDriver interface instead of referencing the
native window type directly. This will help when multiple backends are
supported at runtime (e.g. Wayland+X11).

Finally, move the eglDriver implementation methods from GOOS-specific
code to separate EGL-specific files, allowing EGL types to be used
directly instead of unsafe.Pointer and uinptr.

The result is simpler generic EGL code, and easier path towards X11
support.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-10-02 23:07:54 +02:00
parent 32bda106e7
commit 2dcbf6fe3c
8 changed files with 97 additions and 85 deletions
+27 -34
View File
@@ -15,16 +15,21 @@ import (
type context struct {
c *gl.Functions
driver *window
driver eglDriver
eglCtx *eglContext
nwindow _EGLNativeWindowType
eglWin *eglWindow
eglWin _EGLNativeWindowType
eglSurf _EGLSurface
width, height int
// For sRGB emulation.
srgbFBO *gl.SRGBFBO
}
type eglDriver interface {
eglDisplay() _EGLNativeDisplayType
eglWindow(visID int) (_EGLNativeWindowType, int, int, error)
eglDestroy()
}
type eglContext struct {
disp _EGLDisplay
config _EGLConfig
@@ -62,27 +67,28 @@ const (
func (c *context) Release() {
if c.srgbFBO != nil {
c.srgbFBO.Release()
c.srgbFBO = nil
}
if c.eglSurf != nilEGLSurface {
eglMakeCurrent(c.eglCtx.disp, nilEGLSurface, nilEGLSurface, nilEGLContext)
eglDestroySurface(c.eglCtx.disp, c.eglSurf)
c.eglSurf = nilEGLSurface
}
if c.eglWin != nil {
c.eglWin.destroy()
c.eglWin = nil
}
c.eglWin = nilEGLNativeWindowType
if c.eglCtx != nil {
eglDestroyContext(c.eglCtx.disp, c.eglCtx.ctx)
eglTerminate(c.eglCtx.disp)
eglReleaseThread()
c.eglCtx = nil
}
c.driver = nil
if c.driver != nil {
c.driver.eglDestroy()
c.driver = nil
}
}
func (c *context) Present() error {
if c.eglWin == nil {
if c.eglWin == nilEGLNativeWindowType {
panic("context is not active")
}
if c.srgbFBO != nil {
@@ -97,13 +103,13 @@ func (c *context) Present() error {
return nil
}
func newContext(w *window) (*context, error) {
eglCtx, err := createContext(_EGLNativeDisplayType(w.display()))
func newContext(d eglDriver) (*context, error) {
eglCtx, err := createContext(d.eglDisplay())
if err != nil {
return nil, err
}
c := &context{
driver: w,
driver: d,
eglCtx: eglCtx,
c: new(gl.Functions),
}
@@ -119,9 +125,11 @@ func (c *context) Lock() {}
func (c *context) Unlock() {}
func (c *context) MakeCurrent() error {
w, width, height := c.driver.nativeWindow(int(c.eglCtx.visualID))
win := _EGLNativeWindowType(w)
if c.nwindow == win && width == c.width && height == c.height {
win, width, height, err := c.driver.eglWindow(int(c.eglCtx.visualID))
if err != nil {
return err
}
if c.eglWin == win && width == c.width && height == c.height {
return nil
}
if win == nilEGLNativeWindowType {
@@ -138,29 +146,14 @@ func (c *context) MakeCurrent() error {
c.eglSurf = nilEGLSurface
}
c.width, c.height = width, height
c.nwindow = win
if c.nwindow == nilEGLNativeWindowType {
if c.eglWin != nil {
c.eglWin.destroy()
c.eglWin = nil
}
c.eglWin = win
if c.eglWin == nilEGLNativeWindowType {
return nil
}
if c.eglWin == nil {
var err error
c.eglWin, err = newEGLWindow(win, width, height)
if err != nil {
return err
}
} else {
c.eglWin.resize(width, height)
}
eglSurf, err := createSurfaceAndMakeCurrent(c.eglCtx, c.eglWin.window())
eglSurf, err := createSurfaceAndMakeCurrent(c.eglCtx, win)
c.eglSurf = eglSurf
if err != nil {
c.eglWin.destroy()
c.eglWin = nil
c.nwindow = nilEGLNativeWindowType
c.eglWin = nilEGLNativeWindowType
return err
}
if c.eglCtx.srgb {