github.com/gop9/olt@v0.0.0-20200202132135-d956aad50b08/gio/app/internal/window/egl_x11.go (about) 1 // SPDX-License-Identifier: Unlicense OR MIT 2 3 // +build linux,!android,!nox11 freebsd 4 5 package window 6 7 import ( 8 "unsafe" 9 10 "github.com/gop9/olt/gio/app/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) MakeCurrent() error { 35 c.Context.ReleaseSurface() 36 win, width, height := c.win.window() 37 eglSurf := egl.NativeWindowType(uintptr(win)) 38 if err := c.Context.CreateSurface(eglSurf, width, height); err != nil { 39 return err 40 } 41 if err := c.Context.MakeCurrent(); err != nil { 42 return err 43 } 44 c.Context.EnableVSync(true) 45 return nil 46 } 47 48 func (c *x11Context) Lock() {} 49 50 func (c *x11Context) Unlock() {}