ref: dc62058bcefc51bd138d12668bba5a11dfed3e3f gio/ui/app/egl_wayland.go -rw-r--r-- 1.2 KiB View raw
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// SPDX-License-Identifier: Unlicense OR MIT

// +build linux,!android

package app

import (
	"errors"
	"unsafe"
)

/*
#cgo LDFLAGS: -lwayland-egl

#include <wayland-client.h>
#include <wayland-egl.h>
#include <EGL/egl.h>
*/
import "C"

type (
	_EGLNativeDisplayType = C.EGLNativeDisplayType
	_EGLNativeWindowType  = C.EGLNativeWindowType
)

type eglWindow struct {
	w *C.struct_wl_egl_window
}

func newEGLWindow(w _EGLNativeWindowType, width, height int) (*eglWindow, error) {
	surf := (*C.struct_wl_surface)(unsafe.Pointer(w))
	win := C.wl_egl_window_create(surf, C.int(width), C.int(height))
	if win == nil {
		return nil, errors.New("wl_egl_create_window failed")
	}
	return &eglWindow{win}, nil
}

func (w *eglWindow) window() _EGLNativeWindowType {
	return w.w
}

func (w *eglWindow) resize(width, height int) {
	C.wl_egl_window_resize(w.w, C.int(width), C.int(height), 0, 0)
}

func (w *eglWindow) destroy() {
	C.wl_egl_window_destroy(w.w)
}

func eglGetDisplay(disp _EGLNativeDisplayType) _EGLDisplay {
	return C.eglGetDisplay(disp)
}

func eglCreateWindowSurface(disp _EGLDisplay, conf _EGLConfig, win _EGLNativeWindowType, attribs []_EGLint) _EGLSurface {
	eglSurf := C.eglCreateWindowSurface(disp, conf, win, &attribs[0])
	return eglSurf
}