github.com/Seikaijyu/gio@v0.0.1/app/vulkan_wayland.go (about) 1 // SPDX-License-Identifier: Unlicense OR MIT 2 3 //go:build ((linux && !android) || freebsd) && !nowayland && !novulkan 4 // +build linux,!android freebsd 5 // +build !nowayland 6 // +build !novulkan 7 8 package app 9 10 import ( 11 "unsafe" 12 13 "github.com/Seikaijyu/gio/gpu" 14 "github.com/Seikaijyu/gio/internal/vk" 15 ) 16 17 type wlVkContext struct { 18 win *window 19 inst vk.Instance 20 surf vk.Surface 21 ctx *vkContext 22 } 23 24 func init() { 25 newWaylandVulkanContext = func(w *window) (context, error) { 26 inst, err := vk.CreateInstance("VK_KHR_surface", "VK_KHR_wayland_surface") 27 if err != nil { 28 return nil, err 29 } 30 disp := w.display() 31 wlSurf, _, _ := w.surface() 32 surf, err := vk.CreateWaylandSurface(inst, unsafe.Pointer(disp), unsafe.Pointer(wlSurf)) 33 if err != nil { 34 vk.DestroyInstance(inst) 35 return nil, err 36 } 37 ctx, err := newVulkanContext(inst, surf) 38 if err != nil { 39 vk.DestroySurface(inst, surf) 40 vk.DestroyInstance(inst) 41 return nil, err 42 } 43 c := &wlVkContext{ 44 win: w, 45 inst: inst, 46 surf: surf, 47 ctx: ctx, 48 } 49 return c, nil 50 } 51 } 52 53 func (c *wlVkContext) RenderTarget() (gpu.RenderTarget, error) { 54 return c.ctx.RenderTarget() 55 } 56 57 func (c *wlVkContext) API() gpu.API { 58 return c.ctx.api() 59 } 60 61 func (c *wlVkContext) Release() { 62 c.ctx.release() 63 vk.DestroySurface(c.inst, c.surf) 64 vk.DestroyInstance(c.inst) 65 *c = wlVkContext{} 66 } 67 68 func (c *wlVkContext) Present() error { 69 return c.ctx.present() 70 } 71 72 func (c *wlVkContext) Lock() error { 73 return nil 74 } 75 76 func (c *wlVkContext) Unlock() {} 77 78 func (c *wlVkContext) Refresh() error { 79 _, w, h := c.win.surface() 80 return c.ctx.refresh(c.surf, w, h) 81 }