github.com/gop9/olt@v0.0.0-20200202132135-d956aad50b08/gio/app/internal/window/egl_android.go (about)

     1  // SPDX-License-Identifier: Unlicense OR MIT
     2  
     3  package window
     4  
     5  /*
     6  #include <EGL/egl.h>
     7  */
     8  import "C"
     9  
    10  import (
    11  	"unsafe"
    12  
    13  	"github.com/gop9/olt/gio/app/internal/egl"
    14  )
    15  
    16  type context struct {
    17  	win *window
    18  	*egl.Context
    19  }
    20  
    21  func (w *window) NewContext() (Context, error) {
    22  	ctx, err := egl.NewContext(nil)
    23  	if err != nil {
    24  		return nil, err
    25  	}
    26  	return &context{win: w, Context: ctx}, nil
    27  }
    28  
    29  func (c *context) Release() {
    30  	if c.Context != nil {
    31  		c.Context.Release()
    32  		c.Context = nil
    33  	}
    34  }
    35  
    36  func (c *context) MakeCurrent() error {
    37  	c.Context.ReleaseSurface()
    38  	win, width, height := c.win.nativeWindow(c.Context.VisualID())
    39  	if win == nil {
    40  		return nil
    41  	}
    42  	eglSurf := egl.NativeWindowType(unsafe.Pointer(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  	return nil
    50  }
    51  
    52  func (c *context) Lock() {}
    53  
    54  func (c *context) Unlock() {}