github.com/cybriq/giocore@v0.0.7-0.20210703034601-cfb9cb5f3900/app/internal/wm/egl_x11.go (about)

     1  // SPDX-License-Identifier: Unlicense OR MIT
     2  
     3  // +build linux,!android,!nox11 freebsd openbsd
     4  
     5  package wm
     6  
     7  import (
     8  	"unsafe"
     9  
    10  	"github.com/cybriq/giocore/internal/egl"
    11  )
    12  
    13  type x11Context struct {
    14  	win *x11Window
    15  	*egl.Context
    16  }
    17  
    18  func (w *x11Window) NewContext() (Context, error) {
    19  	disp := egl.NativeDisplayType(unsafe.Pointer(w.display()))
    20  	ctx, err := egl.NewContext(disp)
    21  	if err != nil {
    22  		return nil, err
    23  	}
    24  	return &x11Context{win: w, Context: ctx}, nil
    25  }
    26  
    27  func (c *x11Context) Release() {
    28  	if c.Context != nil {
    29  		c.Context.Release()
    30  		c.Context = nil
    31  	}
    32  }
    33  
    34  func (c *x11Context) Refresh() error {
    35  	return nil
    36  }
    37  
    38  func (c *x11Context) MakeCurrent() error {
    39  	c.Context.ReleaseSurface()
    40  	win, width, height := c.win.window()
    41  	eglSurf := egl.NativeWindowType(uintptr(win))
    42  	if err := c.Context.CreateSurface(eglSurf, width, height); err != nil {
    43  		return err
    44  	}
    45  	if err := c.Context.MakeCurrent(); err != nil {
    46  		return err
    47  	}
    48  	c.Context.EnableVSync(true)
    49  	return nil
    50  }
    51  
    52  func (c *x11Context) Lock() {}
    53  
    54  func (c *x11Context) Unlock() {}