aboutsummaryrefslogtreecommitdiff
path: root/vendor/gioui.org/app/internal/window/egl_android.go
blob: 19c8d63e7e4d552ccd6bd1a92adb36638e173650 (plain)
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
// SPDX-License-Identifier: Unlicense OR MIT

package window

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

import (
	"unsafe"

	"gioui.org/app/internal/egl"
)

type context struct {
	win *window
	*egl.Context
}

func (w *window) NewContext() (Context, error) {
	ctx, err := egl.NewContext(nil)
	if err != nil {
		return nil, err
	}
	return &context{win: w, Context: ctx}, nil
}

func (c *context) Release() {
	if c.Context != nil {
		c.Context.Release()
		c.Context = nil
	}
}

func (c *context) MakeCurrent() error {
	c.Context.ReleaseSurface()
	win, width, height := c.win.nativeWindow(c.Context.VisualID())
	if win == nil {
		return nil
	}
	eglSurf := egl.NativeWindowType(unsafe.Pointer(win))
	if err := c.Context.CreateSurface(eglSurf, width, height); err != nil {
		return err
	}
	if err := c.Context.MakeCurrent(); err != nil {
		return err
	}
	return nil
}

func (c *context) Lock() {}

func (c *context) Unlock() {}