github.com/Seikaijyu/gio@v0.0.1/app/egl_x11.go (about)

     1  // SPDX-License-Identifier: Unlicense OR MIT
     2  
     3  //go:build ((linux && !android) || freebsd || openbsd) && !nox11 && !noopengl
     4  // +build linux,!android freebsd openbsd
     5  // +build !nox11
     6  // +build !noopengl
     7  
     8  package app
     9  
    10  import (
    11  	"unsafe"
    12  
    13  	"github.com/Seikaijyu/gio/internal/egl"
    14  )
    15  
    16  type x11Context struct {
    17  	win *x11Window
    18  	*egl.Context
    19  }
    20  
    21  func init() {
    22  	newX11EGLContext = func(w *x11Window) (context, error) {
    23  		disp := egl.NativeDisplayType(unsafe.Pointer(w.display()))
    24  		ctx, err := egl.NewContext(disp)
    25  		if err != nil {
    26  			return nil, err
    27  		}
    28  		return &x11Context{win: w, Context: ctx}, nil
    29  	}
    30  }
    31  
    32  func (c *x11Context) Release() {
    33  	if c.Context != nil {
    34  		c.Context.Release()
    35  		c.Context = nil
    36  	}
    37  }
    38  
    39  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  	c.Context.EnableVSync(true)
    50  	c.Context.ReleaseCurrent()
    51  	return nil
    52  }
    53  
    54  func (c *x11Context) Lock() error {
    55  	return c.Context.MakeCurrent()
    56  }
    57  
    58  func (c *x11Context) Unlock() {
    59  	c.Context.ReleaseCurrent()
    60  }