github.com/Seikaijyu/gio@v0.0.1/app/vulkan_x11.go (about) 1 // SPDX-License-Identifier: Unlicense OR MIT 2 3 //go:build ((linux && !android) || freebsd) && !nox11 && !novulkan 4 // +build linux,!android freebsd 5 // +build !nox11 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 x11VkContext struct { 18 win *x11Window 19 inst vk.Instance 20 surf vk.Surface 21 ctx *vkContext 22 } 23 24 func init() { 25 newX11VulkanContext = func(w *x11Window) (context, error) { 26 inst, err := vk.CreateInstance("VK_KHR_surface", "VK_KHR_xlib_surface") 27 if err != nil { 28 return nil, err 29 } 30 disp := w.display() 31 window, _, _ := w.window() 32 surf, err := vk.CreateXlibSurface(inst, unsafe.Pointer(disp), uintptr(window)) 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 := &x11VkContext{ 44 win: w, 45 inst: inst, 46 surf: surf, 47 ctx: ctx, 48 } 49 return c, nil 50 } 51 } 52 53 func (c *x11VkContext) RenderTarget() (gpu.RenderTarget, error) { 54 return c.ctx.RenderTarget() 55 } 56 57 func (c *x11VkContext) API() gpu.API { 58 return c.ctx.api() 59 } 60 61 func (c *x11VkContext) Release() { 62 c.ctx.release() 63 vk.DestroySurface(c.inst, c.surf) 64 vk.DestroyInstance(c.inst) 65 *c = x11VkContext{} 66 } 67 68 func (c *x11VkContext) Present() error { 69 return c.ctx.present() 70 } 71 72 func (c *x11VkContext) Lock() error { 73 return nil 74 } 75 76 func (c *x11VkContext) Unlock() {} 77 78 func (c *x11VkContext) Refresh() error { 79 _, w, h := c.win.window() 80 return c.ctx.refresh(c.surf, w, h) 81 }