vulkan_wayland.go 1.5 KB

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