aboutsummaryrefslogtreecommitdiff
path: root/vendor/gioui.org/app/vulkan_wayland.go
blob: 7bf066280e32fa4e927986f43594975d44210f5d (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// SPDX-License-Identifier: Unlicense OR MIT

//go:build ((linux && !android) || freebsd) && !nowayland && !novulkan
// +build linux,!android freebsd
// +build !nowayland
// +build !novulkan

package app

import (
	"unsafe"

	"gioui.org/gpu"
	"gioui.org/internal/vk"
)

type wlVkContext struct {
	win  *window
	inst vk.Instance
	surf vk.Surface
	ctx  *vkContext
}

func init() {
	newWaylandVulkanContext = func(w *window) (context, error) {
		inst, err := vk.CreateInstance("VK_KHR_surface", "VK_KHR_wayland_surface")
		if err != nil {
			return nil, err
		}
		disp := w.display()
		wlSurf, _, _ := w.surface()
		surf, err := vk.CreateWaylandSurface(inst, unsafe.Pointer(disp), unsafe.Pointer(wlSurf))
		if err != nil {
			vk.DestroyInstance(inst)
			return nil, err
		}
		ctx, err := newVulkanContext(inst, surf)
		if err != nil {
			vk.DestroySurface(inst, surf)
			vk.DestroyInstance(inst)
			return nil, err
		}
		c := &wlVkContext{
			win:  w,
			inst: inst,
			surf: surf,
			ctx:  ctx,
		}
		return c, nil
	}
}

func (c *wlVkContext) RenderTarget() (gpu.RenderTarget, error) {
	return c.ctx.RenderTarget()
}

func (c *wlVkContext) API() gpu.API {
	return c.ctx.api()
}

func (c *wlVkContext) Release() {
	c.ctx.release()
	vk.DestroySurface(c.inst, c.surf)
	vk.DestroyInstance(c.inst)
	*c = wlVkContext{}
}

func (c *wlVkContext) Present() error {
	return c.ctx.present()
}

func (c *wlVkContext) Lock() error {
	return nil
}

func (c *wlVkContext) Unlock() {}

func (c *wlVkContext) Refresh() error {
	_, w, h := c.win.surface()
	return c.ctx.refresh(c.surf, w, h)
}