gioui.org/ui@v0.0.0-20190926171558-ce74bc0cbaea/app/egl_wayland.go (about)

     1  // SPDX-License-Identifier: Unlicense OR MIT
     2  
     3  // +build linux,!android
     4  
     5  package app
     6  
     7  import (
     8  	"errors"
     9  	"unsafe"
    10  )
    11  
    12  /*
    13  #cgo LDFLAGS: -lwayland-egl
    14  #cgo CFLAGS: -DWL_EGL_PLATFORM
    15  
    16  #include <wayland-client.h>
    17  #include <wayland-egl.h>
    18  #include <EGL/egl.h>
    19  */
    20  import "C"
    21  
    22  type (
    23  	_EGLNativeDisplayType = C.EGLNativeDisplayType
    24  	_EGLNativeWindowType  = C.EGLNativeWindowType
    25  )
    26  
    27  type eglWindow struct {
    28  	w *C.struct_wl_egl_window
    29  }
    30  
    31  func newEGLWindow(w _EGLNativeWindowType, width, height int) (*eglWindow, error) {
    32  	surf := (*C.struct_wl_surface)(unsafe.Pointer(w))
    33  	win := C.wl_egl_window_create(surf, C.int(width), C.int(height))
    34  	if win == nil {
    35  		return nil, errors.New("wl_egl_create_window failed")
    36  	}
    37  	return &eglWindow{win}, nil
    38  }
    39  
    40  func (w *eglWindow) window() _EGLNativeWindowType {
    41  	return w.w
    42  }
    43  
    44  func (w *eglWindow) resize(width, height int) {
    45  	C.wl_egl_window_resize(w.w, C.int(width), C.int(height), 0, 0)
    46  }
    47  
    48  func (w *eglWindow) destroy() {
    49  	C.wl_egl_window_destroy(w.w)
    50  }
    51  
    52  func eglGetDisplay(disp _EGLNativeDisplayType) _EGLDisplay {
    53  	return C.eglGetDisplay(disp)
    54  }
    55  
    56  func eglCreateWindowSurface(disp _EGLDisplay, conf _EGLConfig, win _EGLNativeWindowType, attribs []_EGLint) _EGLSurface {
    57  	eglSurf := C.eglCreateWindowSurface(disp, conf, win, &attribs[0])
    58  	return eglSurf
    59  }