feat: add Wayland-free Renderer API
Renderer renders views into DMA-BUF buffers and reports release through eventfds. Render is a generic method (Go 1.27).
- commit
- e1768ca0c663a2afb225696e6532f5c1c5a03466
- author
- brice · · 2026-10-01 16:30 UTC
- parent
- f89a222
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
2 files · +456 -0
A internal/ui/renderer.go +393 -0
| @@ -0,0 +1,393 @@ | |||
| 1 | + | //go:build linux | |
| 2 | + | ||
| 3 | + | package ui | |
| 4 | + | ||
| 5 | + | import ( | |
| 6 | + | "context" | |
| 7 | + | "errors" | |
| 8 | + | "fmt" | |
| 9 | + | "math" | |
| 10 | + | "os" | |
| 11 | + | ||
| 12 | + | "github.com/bnema/nefergui/internal/css" | |
| 13 | + | "github.com/bnema/nefergui/internal/edit" | |
| 14 | + | "github.com/bnema/nefergui/internal/layout" | |
| 15 | + | "github.com/bnema/nefergui/internal/presentation/session" | |
| 16 | + | "github.com/bnema/nefergui/internal/presentation/vkdevice" | |
| 17 | + | "github.com/bnema/nefergui/internal/text" | |
| 18 | + | ) | |
| 19 | + | ||
| 20 | + | // Format is a DRM format and modifier the compositor accepts. | |
| 21 | + | type Format struct { | |
| 22 | + | FourCC uint32 | |
| 23 | + | Modifier uint64 | |
| 24 | + | } | |
| 25 | + | ||
| 26 | + | // Clipboard is the optional asynchronous clipboard; IME the optional input method. | |
| 27 | + | type ( | |
| 28 | + | Clipboard = edit.AsyncClipboard | |
| 29 | + | IME = edit.IME | |
| 30 | + | ) | |
| 31 | + | ||
| 32 | + | // Plane, Timeline and Retired are the transport-facing parts of Output. | |
| 33 | + | type ( | |
| 34 | + | Plane = session.Plane | |
| 35 | + | Timeline = session.Timeline | |
| 36 | + | Retired = session.Retired | |
| 37 | + | ) | |
| 38 | + | ||
| 39 | + | // Cursor is the pointer shape the surface wants. | |
| 40 | + | type Cursor uint8 | |
| 41 | + | ||
| 42 | + | const ( | |
| 43 | + | CursorDefault Cursor = iota | |
| 44 | + | CursorPointer | |
| 45 | + | CursorText | |
| 46 | + | CursorNotAllowed | |
| 47 | + | ) | |
| 48 | + | ||
| 49 | + | // RendererConfig configures a Wayland-free Renderer. | |
| 50 | + | type RendererConfig struct { | |
| 51 | + | MainDevice uint64 // dev_t from linux-dmabuf feedback main_device | |
| 52 | + | Formats []Format // compositor preference order, tranches flattened | |
| 53 | + | Transparent bool // ARGB8888 instead of XRGB8888 | |
| 54 | + | Styles string // optional CSS file path | |
| 55 | + | Clipboard Clipboard | |
| 56 | + | IME IME | |
| 57 | + | } | |
| 58 | + | ||
| 59 | + | // Input is one platform input event. Text is read only during the call. | |
| 60 | + | type Input struct { | |
| 61 | + | Kind InputKind | |
| 62 | + | X, Y, DX, DY float64 // logical pixels; DX, DY are scroll deltas | |
| 63 | + | Button uint32 // evdev code | |
| 64 | + | Pressed bool | |
| 65 | + | Repeat bool | |
| 66 | + | Keysym uint32 // xkb keysym | |
| 67 | + | Text []byte | |
| 68 | + | Modifiers Modifiers | |
| 69 | + | } | |
| 70 | + | ||
| 71 | + | // Output describes one frame to present, in physical pixels. Every file | |
| 72 | + | // descriptor stays owned by the Renderer. Slices are reused and valid until the | |
| 73 | + | // next Render. | |
| 74 | + | type Output struct { | |
| 75 | + | Buffer uint64 | |
| 76 | + | NewBuffer bool | |
| 77 | + | Retired []Retired | |
| 78 | + | Width, Height int32 | |
| 79 | + | FourCC uint32 | |
| 80 | + | Modifier uint64 | |
| 81 | + | Planes [4]Plane | |
| 82 | + | PlaneCount int | |
| 83 | + | Acquire, Release Timeline | |
| 84 | + | NewTimelines bool | |
| 85 | + | AcquirePoint uint64 | |
| 86 | + | ReleasePoint uint64 | |
| 87 | + | ReleaseFD int | |
| 88 | + | Damage []Rect | |
| 89 | + | Cursor Cursor | |
| 90 | + | InputRects []Rect | |
| 91 | + | InputRectsChanged bool | |
| 92 | + | } | |
| 93 | + | ||
| 94 | + | // target is the GPU seam of Renderer. *session.Target implements it. | |
| 95 | + | type target interface { | |
| 96 | + | Resize(width, height int32) | |
| 97 | + | Draw(display []layout.Command, scale float64, out *session.Output) (bool, error) | |
| 98 | + | Released(buffer uint64) error | |
| 99 | + | Close() error | |
| 100 | + | } | |
| 101 | + | ||
| 102 | + | // Renderer renders views into DMA-BUF buffers for a transport it does not | |
| 103 | + | // know. It owns no Wayland object and starts no goroutine. All methods except | |
| 104 | + | // Wake run on one owner goroutine. | |
| 105 | + | type Renderer struct { | |
| 106 | + | rt *runtime | |
| 107 | + | target target | |
| 108 | + | tout session.Output | |
| 109 | + | sized bool | |
| 110 | + | unsent bool // a built frame still waits for a free buffer | |
| 111 | + | w, h float64 | |
| 112 | + | scale float64 | |
| 113 | + | pw, ph int32 | |
| 114 | + | closed bool | |
| 115 | + | } | |
| 116 | + | ||
| 117 | + | // asyncClipboard lets an AsyncClipboard satisfy the editor's Clipboard port; | |
| 118 | + | // synchronous reads are not supported, paste uses ReadTextAsync. | |
| 119 | + | type asyncClipboard struct{ edit.AsyncClipboard } | |
| 120 | + | ||
| 121 | + | func (asyncClipboard) ReadText(int) ([]byte, error) { | |
| 122 | + | return nil, errors.New("nefergui: synchronous clipboard read not supported") | |
| 123 | + | } | |
| 124 | + | ||
| 125 | + | // NewRenderer opens the GPU for cfg.MainDevice and loads fonts and styles. It | |
| 126 | + | // allocates no images. | |
| 127 | + | func NewRenderer(cfg RendererConfig) (*Renderer, error) { | |
| 128 | + | formats := make([]vkdevice.Format, len(cfg.Formats)) | |
| 129 | + | for i, f := range cfg.Formats { | |
| 130 | + | formats[i] = vkdevice.Format{FourCC: f.FourCC, Modifier: f.Modifier} | |
| 131 | + | } | |
| 132 | + | t, err := session.NewTarget(session.TargetConfig{MainDevice: cfg.MainDevice, Formats: formats, Transparent: cfg.Transparent}) | |
| 133 | + | if err != nil { | |
| 134 | + | return nil, fmt.Errorf("nefergui: open renderer: %w", err) | |
| 135 | + | } | |
| 136 | + | r, err := newRenderer(cfg, t, text.SystemSource{}) | |
| 137 | + | if err != nil { | |
| 138 | + | _ = t.Close() | |
| 139 | + | return nil, err | |
| 140 | + | } | |
| 141 | + | return r, nil | |
| 142 | + | } | |
| 143 | + | ||
| 144 | + | func newRenderer(cfg RendererConfig, t target, fonts text.FontSource) (*Renderer, error) { | |
| 145 | + | rt := newRuntime() | |
| 146 | + | if cfg.Styles != "" { | |
| 147 | + | data, err := os.ReadFile(cfg.Styles) | |
| 148 | + | if err != nil { | |
| 149 | + | return nil, fmt.Errorf("nefergui: styles: %w", err) | |
| 150 | + | } | |
| 151 | + | rt.styles = css.Compile(css.UA(), css.Parse(string(data))) | |
| 152 | + | } | |
| 153 | + | catalog, err := text.Load(fonts) | |
| 154 | + | if err != nil { | |
| 155 | + | return nil, fmt.Errorf("nefergui: fonts: %w", err) | |
| 156 | + | } | |
| 157 | + | if len(catalog.Faces) == 0 { | |
| 158 | + | return nil, errors.New("nefergui: no usable fonts") | |
| 159 | + | } | |
| 160 | + | rt.setTextEngine(text.NewEngine(catalog)) | |
| 161 | + | ctx, cancel := context.WithCancel(context.Background()) | |
| 162 | + | rt.pasteCtx, rt.pasteCancel = ctx, cancel | |
| 163 | + | if cfg.Clipboard != nil { | |
| 164 | + | rt.clipboard = asyncClipboard{cfg.Clipboard} | |
| 165 | + | } | |
| 166 | + | if cfg.IME != nil { | |
| 167 | + | rt.ime = cfg.IME | |
| 168 | + | } | |
| 169 | + | return &Renderer{rt: rt, target: t, scale: 1}, nil | |
| 170 | + | } | |
| 171 | + | ||
| 172 | + | // Wake returns a channel signaled when work arrives from another goroutine | |
| 173 | + | // (for example a finished paste); call Render after receiving. Safe from any goroutine. | |
| 174 | + | func (r *Renderer) Wake() <-chan struct{} { return r.rt.wake } | |
| 175 | + | ||
| 176 | + | // Resize sets the logical surface size and scale. Invalid values are ignored. | |
| 177 | + | func (r *Renderer) Resize(width, height int, scale float64) { | |
| 178 | + | w, h := float64(width), float64(height) | |
| 179 | + | if width <= 0 || height <= 0 || !(scale > 0) || math.IsInf(scale, 0) { | |
| 180 | + | return | |
| 181 | + | } | |
| 182 | + | pw, ph := math.Ceil(w*scale-1e-9), math.Ceil(h*scale-1e-9) | |
| 183 | + | if pw > math.MaxInt32 || ph > math.MaxInt32 { | |
| 184 | + | return | |
| 185 | + | } | |
| 186 | + | if r.sized && r.w == w && r.h == h && r.scale == scale { | |
| 187 | + | return | |
| 188 | + | } | |
| 189 | + | r.sized, r.w, r.h, r.scale = true, w, h, scale | |
| 190 | + | r.pw, r.ph = int32(pw), int32(ph) | |
| 191 | + | r.target.Resize(r.pw, r.ph) | |
| 192 | + | r.rt.route(platformInput{Kind: "resize", Width: w, Height: h, Scale: scale}) | |
| 193 | + | } | |
| 194 | + | ||
| 195 | + | // Invalidate requests a rebuild at the next Render. | |
| 196 | + | func (r *Renderer) Invalidate() { r.rt.Redraw() } | |
| 197 | + | ||
| 198 | + | // Input routes one event and reports whether a redraw is needed. | |
| 199 | + | func (r *Renderer) Input(ev *Input) bool { | |
| 200 | + | if ev == nil { | |
| 201 | + | return false | |
| 202 | + | } | |
| 203 | + | switch ev.Kind { | |
| 204 | + | case InputReset: | |
| 205 | + | r.rt.route(platformInput{Kind: "leave"}) | |
| 206 | + | r.rt.route(platformInput{Kind: "focus-out"}) | |
| 207 | + | case InputPointerMotion: | |
| 208 | + | r.rt.route(platformInput{Kind: "motion", X: ev.X, Y: ev.Y}) | |
| 209 | + | case InputPointerPress: | |
| 210 | + | r.rt.route(platformInput{Kind: "press", X: ev.X, Y: ev.Y, Button: ev.Button, Shift: ev.Modifiers&ModShift != 0}) | |
| 211 | + | case InputPointerRelease: | |
| 212 | + | r.rt.route(platformInput{Kind: "release", X: ev.X, Y: ev.Y, Button: ev.Button}) | |
| 213 | + | case InputPointerAxis: | |
| 214 | + | if ev.DX == 0 && ev.DY == 0 { | |
| 215 | + | return false | |
| 216 | + | } | |
| 217 | + | r.rt.route(platformInput{Kind: "axis", X: ev.X, Y: ev.Y, DX: ev.DX, DY: ev.DY}) | |
| 218 | + | case InputPointerLeave: | |
| 219 | + | r.rt.route(platformInput{Kind: "leave"}) | |
| 220 | + | case InputFocusIn: | |
| 221 | + | r.rt.route(platformInput{Kind: "focus-in"}) | |
| 222 | + | case InputFocusOut: | |
| 223 | + | r.rt.route(platformInput{Kind: "focus-out"}) | |
| 224 | + | case InputKey: | |
| 225 | + | shift, ctrl := ev.Modifiers&ModShift != 0, ev.Modifiers&ModCtrl != 0 | |
| 226 | + | key := keyEvent{Name: keysymName(ev.Keysym), Pressed: ev.Pressed, Repeat: ev.Repeat, Shift: shift, Ctrl: ctrl} | |
| 227 | + | if len(ev.Text) > 0 { | |
| 228 | + | key.Text = string(ev.Text) | |
| 229 | + | } | |
| 230 | + | r.rt.route(platformInput{Kind: "key", Key: key, Shift: shift, Ctrl: ctrl}) | |
| 231 | + | default: | |
| 232 | + | return false | |
| 233 | + | } | |
| 234 | + | r.rt.mu.Lock() | |
| 235 | + | need := r.rt.redraw || len(r.rt.pending) > 0 | |
| 236 | + | r.rt.mu.Unlock() | |
| 237 | + | return need | |
| 238 | + | } | |
| 239 | + | ||
| 240 | + | // Render builds the view and, when something changed and a buffer is free, | |
| 241 | + | // draws it. It returns false without touching the GPU when nothing changed, no | |
| 242 | + | // buffer is available yet (call it again after Released) or before the first | |
| 243 | + | // Resize. When it returns true, out describes the frame to present. | |
| 244 | + | func (r *Renderer) Render[T any](out *Output, model *T, view func(*Frame, *T)) (bool, error) { | |
| 245 | + | if r.closed { | |
| 246 | + | return false, errors.New("nefergui: renderer closed") | |
| 247 | + | } | |
| 248 | + | if out == nil || model == nil || view == nil { | |
| 249 | + | return false, errors.New("nefergui: nil output, model or view") | |
| 250 | + | } | |
| 251 | + | if !r.sized { | |
| 252 | + | return false, nil | |
| 253 | + | } | |
| 254 | + | if r.rt.Build(func(f *Frame) { view(f, model) }) { | |
| 255 | + | r.unsent = true | |
| 256 | + | } | |
| 257 | + | if !r.unsent { | |
| 258 | + | return false, nil | |
| 259 | + | } | |
| 260 | + | ok, err := r.target.Draw(r.rt.output.Display, r.scale, &r.tout) | |
| 261 | + | if err != nil || !ok { | |
| 262 | + | return false, err | |
| 263 | + | } | |
| 264 | + | r.unsent = false | |
| 265 | + | r.export(out) | |
| 266 | + | return true, nil | |
| 267 | + | } | |
| 268 | + | ||
| 269 | + | // export copies the target's frame description into out and adds the parts | |
| 270 | + | // derived from the UI: damage, cursor and the staged input region. | |
| 271 | + | func (r *Renderer) export(out *Output) { | |
| 272 | + | t := &r.tout | |
| 273 | + | retired := append(out.Retired[:0], t.Retired...) | |
| 274 | + | damage := append(out.Damage[:0], Rect{Width: t.Width, Height: t.Height}) | |
| 275 | + | rects := out.InputRects | |
| 276 | + | *out = Output{ | |
| 277 | + | Buffer: t.Buffer, NewBuffer: t.NewBuffer, Retired: retired, | |
| 278 | + | Width: t.Width, Height: t.Height, FourCC: t.FourCC, Modifier: t.Modifier, | |
| 279 | + | Planes: t.Planes, PlaneCount: t.PlaneCount, Acquire: t.Acquire, Release: t.Release, | |
| 280 | + | NewTimelines: t.NewTimelines, AcquirePoint: t.AcquirePoint, ReleasePoint: t.ReleasePoint, ReleaseFD: t.ReleaseFD, | |
| 281 | + | Damage: damage, Cursor: cursorOf(r.rt.cursor()), InputRects: rects[:0], | |
| 282 | + | } | |
| 283 | + | rt := r.rt | |
| 284 | + | if rt.inputStaged { | |
| 285 | + | out.InputRectsChanged = true | |
| 286 | + | if rt.inputNil { | |
| 287 | + | out.InputRects = nil | |
| 288 | + | } else { | |
| 289 | + | if out.InputRects == nil { | |
| 290 | + | out.InputRects = []Rect{} | |
| 291 | + | } | |
| 292 | + | out.InputRects = append(out.InputRects, rt.inputRects...) | |
| 293 | + | } | |
| 294 | + | rt.inputStaged = false | |
| 295 | + | } | |
| 296 | + | } | |
| 297 | + | ||
| 298 | + | func cursorOf(k css.Keyword) Cursor { | |
| 299 | + | switch k { | |
| 300 | + | case css.KeywordPointer: | |
| 301 | + | return CursorPointer | |
| 302 | + | case css.KeywordText: | |
| 303 | + | return CursorText | |
| 304 | + | case css.KeywordNotAllowed: | |
| 305 | + | return CursorNotAllowed | |
| 306 | + | } | |
| 307 | + | return CursorDefault | |
| 308 | + | } | |
| 309 | + | ||
| 310 | + | // Released must be called when the release eventfd of an Output buffer is | |
| 311 | + | // readable. It lets the buffer be reused. | |
| 312 | + | func (r *Renderer) Released(buffer uint64) error { return r.target.Released(buffer) } | |
| 313 | + | ||
| 314 | + | // Close cancels pending pastes and frees the GPU resources. The Renderer is | |
| 315 | + | // unusable afterwards. | |
| 316 | + | func (r *Renderer) Close() error { | |
| 317 | + | if r.closed { | |
| 318 | + | return nil | |
| 319 | + | } | |
| 320 | + | r.closed = true | |
| 321 | + | if r.rt.pasteCancel != nil { | |
| 322 | + | r.rt.pasteCancel() | |
| 323 | + | } | |
| 324 | + | return r.target.Close() | |
| 325 | + | } | |
| 326 | + | ||
| 327 | + | // xkb keysym values; internal/ui never imports an xkb library. | |
| 328 | + | const ( | |
| 329 | + | keysymSpace = 0x0020 | |
| 330 | + | keysymBackspace = 0xff08 | |
| 331 | + | keysymTab = 0xff09 | |
| 332 | + | keysymReturn = 0xff0d | |
| 333 | + | keysymEscape = 0xff1b | |
| 334 | + | keysymHome = 0xff50 | |
| 335 | + | keysymLeft = 0xff51 | |
| 336 | + | keysymUp = 0xff52 | |
| 337 | + | keysymRight = 0xff53 | |
| 338 | + | keysymDown = 0xff54 | |
| 339 | + | keysymPageUp = 0xff55 | |
| 340 | + | keysymPageDown = 0xff56 | |
| 341 | + | keysymEnd = 0xff57 | |
| 342 | + | keysymKPEnter = 0xff8d | |
| 343 | + | keysymISOLeft = 0xfe20 | |
| 344 | + | keysymDelete = 0xffff | |
| 345 | + | ) | |
| 346 | + | ||
| 347 | + | // keysymName maps a keysym to the name interaction.go dispatches on; other | |
| 348 | + | // keysyms have no name because only their text matters. | |
| 349 | + | func keysymName(sym uint32) string { | |
| 350 | + | switch sym { | |
| 351 | + | case keysymSpace: | |
| 352 | + | return "space" | |
| 353 | + | case keysymTab: | |
| 354 | + | return "tab" | |
| 355 | + | case keysymISOLeft: | |
| 356 | + | return "iso_left_tab" | |
| 357 | + | case keysymLeft: | |
| 358 | + | return "left" | |
| 359 | + | case keysymRight: | |
| 360 | + | return "right" | |
| 361 | + | case keysymUp: | |
| 362 | + | return "up" | |
| 363 | + | case keysymDown: | |
| 364 | + | return "down" | |
| 365 | + | case keysymHome: | |
| 366 | + | return "home" | |
| 367 | + | case keysymEnd: | |
| 368 | + | return "end" | |
| 369 | + | case keysymPageUp: | |
| 370 | + | return "page_up" | |
| 371 | + | case keysymPageDown: | |
| 372 | + | return "page_down" | |
| 373 | + | case keysymBackspace: | |
| 374 | + | return "backspace" | |
| 375 | + | case keysymDelete: | |
| 376 | + | return "delete" | |
| 377 | + | case 'a', 'A': | |
| 378 | + | return "a" | |
| 379 | + | case 'c', 'C': | |
| 380 | + | return "c" | |
| 381 | + | case 'x', 'X': | |
| 382 | + | return "x" | |
| 383 | + | case 'v', 'V': | |
| 384 | + | return "v" | |
| 385 | + | case keysymReturn: | |
| 386 | + | return "return" | |
| 387 | + | case keysymKPEnter: | |
| 388 | + | return "kp_enter" | |
| 389 | + | case keysymEscape: | |
| 390 | + | return "escape" | |
| 391 | + | } | |
| 392 | + | return "" | |
| 393 | + | } | |
| @@ -0,0 +1,393 @@ | |||||
| 1 | + | //go:build linux | |||
| 2 | + | ||||
| 3 | + | package ui | |||
| 4 | + | ||||
| 5 | + | import ( | |||
| 6 | + | "context" | |||
| 7 | + | "errors" | |||
| 8 | + | "fmt" | |||
| 9 | + | "math" | |||
| 10 | + | "os" | |||
| 11 | + | ||||
| 12 | + | "github.com/bnema/nefergui/internal/css" | |||
| 13 | + | "github.com/bnema/nefergui/internal/edit" | |||
| 14 | + | "github.com/bnema/nefergui/internal/layout" | |||
| 15 | + | "github.com/bnema/nefergui/internal/presentation/session" | |||
| 16 | + | "github.com/bnema/nefergui/internal/presentation/vkdevice" | |||
| 17 | + | "github.com/bnema/nefergui/internal/text" | |||
| 18 | + | ) | |||
| 19 | + | ||||
| 20 | + | // Format is a DRM format and modifier the compositor accepts. | |||
| 21 | + | type Format struct { | |||
| 22 | + | FourCC uint32 | |||
| 23 | + | Modifier uint64 | |||
| 24 | + | } | |||
| 25 | + | ||||
| 26 | + | // Clipboard is the optional asynchronous clipboard; IME the optional input method. | |||
| 27 | + | type ( | |||
| 28 | + | Clipboard = edit.AsyncClipboard | |||
| 29 | + | IME = edit.IME | |||
| 30 | + | ) | |||
| 31 | + | ||||
| 32 | + | // Plane, Timeline and Retired are the transport-facing parts of Output. | |||
| 33 | + | type ( | |||
| 34 | + | Plane = session.Plane | |||
| 35 | + | Timeline = session.Timeline | |||
| 36 | + | Retired = session.Retired | |||
| 37 | + | ) | |||
| 38 | + | ||||
| 39 | + | // Cursor is the pointer shape the surface wants. | |||
| 40 | + | type Cursor uint8 | |||
| 41 | + | ||||
| 42 | + | const ( | |||
| 43 | + | CursorDefault Cursor = iota | |||
| 44 | + | CursorPointer | |||
| 45 | + | CursorText | |||
| 46 | + | CursorNotAllowed | |||
| 47 | + | ) | |||
| 48 | + | ||||
| 49 | + | // RendererConfig configures a Wayland-free Renderer. | |||
| 50 | + | type RendererConfig struct { | |||
| 51 | + | MainDevice uint64 // dev_t from linux-dmabuf feedback main_device | |||
| 52 | + | Formats []Format // compositor preference order, tranches flattened | |||
| 53 | + | Transparent bool // ARGB8888 instead of XRGB8888 | |||
| 54 | + | Styles string // optional CSS file path | |||
| 55 | + | Clipboard Clipboard | |||
| 56 | + | IME IME | |||
| 57 | + | } | |||
| 58 | + | ||||
| 59 | + | // Input is one platform input event. Text is read only during the call. | |||
| 60 | + | type Input struct { | |||
| 61 | + | Kind InputKind | |||
| 62 | + | X, Y, DX, DY float64 // logical pixels; DX, DY are scroll deltas | |||
| 63 | + | Button uint32 // evdev code | |||
| 64 | + | Pressed bool | |||
| 65 | + | Repeat bool | |||
| 66 | + | Keysym uint32 // xkb keysym | |||
| 67 | + | Text []byte | |||
| 68 | + | Modifiers Modifiers | |||
| 69 | + | } | |||
| 70 | + | ||||
| 71 | + | // Output describes one frame to present, in physical pixels. Every file | |||
| 72 | + | // descriptor stays owned by the Renderer. Slices are reused and valid until the | |||
| 73 | + | // next Render. | |||
| 74 | + | type Output struct { | |||
| 75 | + | Buffer uint64 | |||
| 76 | + | NewBuffer bool | |||
| 77 | + | Retired []Retired | |||
| 78 | + | Width, Height int32 | |||
| 79 | + | FourCC uint32 | |||
| 80 | + | Modifier uint64 | |||
| 81 | + | Planes [4]Plane | |||
| 82 | + | PlaneCount int | |||
| 83 | + | Acquire, Release Timeline | |||
| 84 | + | NewTimelines bool | |||
| 85 | + | AcquirePoint uint64 | |||
| 86 | + | ReleasePoint uint64 | |||
| 87 | + | ReleaseFD int | |||
| 88 | + | Damage []Rect | |||
| 89 | + | Cursor Cursor | |||
| 90 | + | InputRects []Rect | |||
| 91 | + | InputRectsChanged bool | |||
| 92 | + | } | |||
| 93 | + | ||||
| 94 | + | // target is the GPU seam of Renderer. *session.Target implements it. | |||
| 95 | + | type target interface { | |||
| 96 | + | Resize(width, height int32) | |||
| 97 | + | Draw(display []layout.Command, scale float64, out *session.Output) (bool, error) | |||
| 98 | + | Released(buffer uint64) error | |||
| 99 | + | Close() error | |||
| 100 | + | } | |||
| 101 | + | ||||
| 102 | + | // Renderer renders views into DMA-BUF buffers for a transport it does not | |||
| 103 | + | // know. It owns no Wayland object and starts no goroutine. All methods except | |||
| 104 | + | // Wake run on one owner goroutine. | |||
| 105 | + | type Renderer struct { | |||
| 106 | + | rt *runtime | |||
| 107 | + | target target | |||
| 108 | + | tout session.Output | |||
| 109 | + | sized bool | |||
| 110 | + | unsent bool // a built frame still waits for a free buffer | |||
| 111 | + | w, h float64 | |||
| 112 | + | scale float64 | |||
| 113 | + | pw, ph int32 | |||
| 114 | + | closed bool | |||
| 115 | + | } | |||
| 116 | + | ||||
| 117 | + | // asyncClipboard lets an AsyncClipboard satisfy the editor's Clipboard port; | |||
| 118 | + | // synchronous reads are not supported, paste uses ReadTextAsync. | |||
| 119 | + | type asyncClipboard struct{ edit.AsyncClipboard } | |||
| 120 | + | ||||
| 121 | + | func (asyncClipboard) ReadText(int) ([]byte, error) { | |||
| 122 | + | return nil, errors.New("nefergui: synchronous clipboard read not supported") | |||
| 123 | + | } | |||
| 124 | + | ||||
| 125 | + | // NewRenderer opens the GPU for cfg.MainDevice and loads fonts and styles. It | |||
| 126 | + | // allocates no images. | |||
| 127 | + | func NewRenderer(cfg RendererConfig) (*Renderer, error) { | |||
| 128 | + | formats := make([]vkdevice.Format, len(cfg.Formats)) | |||
| 129 | + | for i, f := range cfg.Formats { | |||
| 130 | + | formats[i] = vkdevice.Format{FourCC: f.FourCC, Modifier: f.Modifier} | |||
| 131 | + | } | |||
| 132 | + | t, err := session.NewTarget(session.TargetConfig{MainDevice: cfg.MainDevice, Formats: formats, Transparent: cfg.Transparent}) | |||
| 133 | + | if err != nil { | |||
| 134 | + | return nil, fmt.Errorf("nefergui: open renderer: %w", err) | |||
| 135 | + | } | |||
| 136 | + | r, err := newRenderer(cfg, t, text.SystemSource{}) | |||
| 137 | + | if err != nil { | |||
| 138 | + | _ = t.Close() | |||
| 139 | + | return nil, err | |||
| 140 | + | } | |||
| 141 | + | return r, nil | |||
| 142 | + | } | |||
| 143 | + | ||||
| 144 | + | func newRenderer(cfg RendererConfig, t target, fonts text.FontSource) (*Renderer, error) { | |||
| 145 | + | rt := newRuntime() | |||
| 146 | + | if cfg.Styles != "" { | |||
| 147 | + | data, err := os.ReadFile(cfg.Styles) | |||
| 148 | + | if err != nil { | |||
| 149 | + | return nil, fmt.Errorf("nefergui: styles: %w", err) | |||
| 150 | + | } | |||
| 151 | + | rt.styles = css.Compile(css.UA(), css.Parse(string(data))) | |||
| 152 | + | } | |||
| 153 | + | catalog, err := text.Load(fonts) | |||
| 154 | + | if err != nil { | |||
| 155 | + | return nil, fmt.Errorf("nefergui: fonts: %w", err) | |||
| 156 | + | } | |||
| 157 | + | if len(catalog.Faces) == 0 { | |||
| 158 | + | return nil, errors.New("nefergui: no usable fonts") | |||
| 159 | + | } | |||
| 160 | + | rt.setTextEngine(text.NewEngine(catalog)) | |||
| 161 | + | ctx, cancel := context.WithCancel(context.Background()) | |||
| 162 | + | rt.pasteCtx, rt.pasteCancel = ctx, cancel | |||
| 163 | + | if cfg.Clipboard != nil { | |||
| 164 | + | rt.clipboard = asyncClipboard{cfg.Clipboard} | |||
| 165 | + | } | |||
| 166 | + | if cfg.IME != nil { | |||
| 167 | + | rt.ime = cfg.IME | |||
| 168 | + | } | |||
| 169 | + | return &Renderer{rt: rt, target: t, scale: 1}, nil | |||
| 170 | + | } | |||
| 171 | + | ||||
| 172 | + | // Wake returns a channel signaled when work arrives from another goroutine | |||
| 173 | + | // (for example a finished paste); call Render after receiving. Safe from any goroutine. | |||
| 174 | + | func (r *Renderer) Wake() <-chan struct{} { return r.rt.wake } | |||
| 175 | + | ||||
| 176 | + | // Resize sets the logical surface size and scale. Invalid values are ignored. | |||
| 177 | + | func (r *Renderer) Resize(width, height int, scale float64) { | |||
| 178 | + | w, h := float64(width), float64(height) | |||
| 179 | + | if width <= 0 || height <= 0 || !(scale > 0) || math.IsInf(scale, 0) { | |||
| 180 | + | return | |||
| 181 | + | } | |||
| 182 | + | pw, ph := math.Ceil(w*scale-1e-9), math.Ceil(h*scale-1e-9) | |||
| 183 | + | if pw > math.MaxInt32 || ph > math.MaxInt32 { | |||
| 184 | + | return | |||
| 185 | + | } | |||
| 186 | + | if r.sized && r.w == w && r.h == h && r.scale == scale { | |||
| 187 | + | return | |||
| 188 | + | } | |||
| 189 | + | r.sized, r.w, r.h, r.scale = true, w, h, scale | |||
| 190 | + | r.pw, r.ph = int32(pw), int32(ph) | |||
| 191 | + | r.target.Resize(r.pw, r.ph) | |||
| 192 | + | r.rt.route(platformInput{Kind: "resize", Width: w, Height: h, Scale: scale}) | |||
| 193 | + | } | |||
| 194 | + | ||||
| 195 | + | // Invalidate requests a rebuild at the next Render. | |||
| 196 | + | func (r *Renderer) Invalidate() { r.rt.Redraw() } | |||
| 197 | + | ||||
| 198 | + | // Input routes one event and reports whether a redraw is needed. | |||
| 199 | + | func (r *Renderer) Input(ev *Input) bool { | |||
| 200 | + | if ev == nil { | |||
| 201 | + | return false | |||
| 202 | + | } | |||
| 203 | + | switch ev.Kind { | |||
| 204 | + | case InputReset: | |||
| 205 | + | r.rt.route(platformInput{Kind: "leave"}) | |||
| 206 | + | r.rt.route(platformInput{Kind: "focus-out"}) | |||
| 207 | + | case InputPointerMotion: | |||
| 208 | + | r.rt.route(platformInput{Kind: "motion", X: ev.X, Y: ev.Y}) | |||
| 209 | + | case InputPointerPress: | |||
| 210 | + | r.rt.route(platformInput{Kind: "press", X: ev.X, Y: ev.Y, Button: ev.Button, Shift: ev.Modifiers&ModShift != 0}) | |||
| 211 | + | case InputPointerRelease: | |||
| 212 | + | r.rt.route(platformInput{Kind: "release", X: ev.X, Y: ev.Y, Button: ev.Button}) | |||
| 213 | + | case InputPointerAxis: | |||
| 214 | + | if ev.DX == 0 && ev.DY == 0 { | |||
| 215 | + | return false | |||
| 216 | + | } | |||
| 217 | + | r.rt.route(platformInput{Kind: "axis", X: ev.X, Y: ev.Y, DX: ev.DX, DY: ev.DY}) | |||
| 218 | + | case InputPointerLeave: | |||
| 219 | + | r.rt.route(platformInput{Kind: "leave"}) | |||
| 220 | + | case InputFocusIn: | |||
| 221 | + | r.rt.route(platformInput{Kind: "focus-in"}) | |||
| 222 | + | case InputFocusOut: | |||
| 223 | + | r.rt.route(platformInput{Kind: "focus-out"}) | |||
| 224 | + | case InputKey: | |||
| 225 | + | shift, ctrl := ev.Modifiers&ModShift != 0, ev.Modifiers&ModCtrl != 0 | |||
| 226 | + | key := keyEvent{Name: keysymName(ev.Keysym), Pressed: ev.Pressed, Repeat: ev.Repeat, Shift: shift, Ctrl: ctrl} | |||
| 227 | + | if len(ev.Text) > 0 { | |||
| 228 | + | key.Text = string(ev.Text) | |||
| 229 | + | } | |||
| 230 | + | r.rt.route(platformInput{Kind: "key", Key: key, Shift: shift, Ctrl: ctrl}) | |||
| 231 | + | default: | |||
| 232 | + | return false | |||
| 233 | + | } | |||
| 234 | + | r.rt.mu.Lock() | |||
| 235 | + | need := r.rt.redraw || len(r.rt.pending) > 0 | |||
| 236 | + | r.rt.mu.Unlock() | |||
| 237 | + | return need | |||
| 238 | + | } | |||
| 239 | + | ||||
| 240 | + | // Render builds the view and, when something changed and a buffer is free, | |||
| 241 | + | // draws it. It returns false without touching the GPU when nothing changed, no | |||
| 242 | + | // buffer is available yet (call it again after Released) or before the first | |||
| 243 | + | // Resize. When it returns true, out describes the frame to present. | |||
| 244 | + | func (r *Renderer) Render[T any](out *Output, model *T, view func(*Frame, *T)) (bool, error) { | |||
| 245 | + | if r.closed { | |||
| 246 | + | return false, errors.New("nefergui: renderer closed") | |||
| 247 | + | } | |||
| 248 | + | if out == nil || model == nil || view == nil { | |||
| 249 | + | return false, errors.New("nefergui: nil output, model or view") | |||
| 250 | + | } | |||
| 251 | + | if !r.sized { | |||
| 252 | + | return false, nil | |||
| 253 | + | } | |||
| 254 | + | if r.rt.Build(func(f *Frame) { view(f, model) }) { | |||
| 255 | + | r.unsent = true | |||
| 256 | + | } | |||
| 257 | + | if !r.unsent { | |||
| 258 | + | return false, nil | |||
| 259 | + | } | |||
| 260 | + | ok, err := r.target.Draw(r.rt.output.Display, r.scale, &r.tout) | |||
| 261 | + | if err != nil || !ok { | |||
| 262 | + | return false, err | |||
| 263 | + | } | |||
| 264 | + | r.unsent = false | |||
| 265 | + | r.export(out) | |||
| 266 | + | return true, nil | |||
| 267 | + | } | |||
| 268 | + | ||||
| 269 | + | // export copies the target's frame description into out and adds the parts | |||
| 270 | + | // derived from the UI: damage, cursor and the staged input region. | |||
| 271 | + | func (r *Renderer) export(out *Output) { | |||
| 272 | + | t := &r.tout | |||
| 273 | + | retired := append(out.Retired[:0], t.Retired...) | |||
| 274 | + | damage := append(out.Damage[:0], Rect{Width: t.Width, Height: t.Height}) | |||
| 275 | + | rects := out.InputRects | |||
| 276 | + | *out = Output{ | |||
| 277 | + | Buffer: t.Buffer, NewBuffer: t.NewBuffer, Retired: retired, | |||
| 278 | + | Width: t.Width, Height: t.Height, FourCC: t.FourCC, Modifier: t.Modifier, | |||
| 279 | + | Planes: t.Planes, PlaneCount: t.PlaneCount, Acquire: t.Acquire, Release: t.Release, | |||
| 280 | + | NewTimelines: t.NewTimelines, AcquirePoint: t.AcquirePoint, ReleasePoint: t.ReleasePoint, ReleaseFD: t.ReleaseFD, | |||
| 281 | + | Damage: damage, Cursor: cursorOf(r.rt.cursor()), InputRects: rects[:0], | |||
| 282 | + | } | |||
| 283 | + | rt := r.rt | |||
| 284 | + | if rt.inputStaged { | |||
| 285 | + | out.InputRectsChanged = true | |||
| 286 | + | if rt.inputNil { | |||
| 287 | + | out.InputRects = nil | |||
| 288 | + | } else { | |||
| 289 | + | if out.InputRects == nil { | |||
| 290 | + | out.InputRects = []Rect{} | |||
| 291 | + | } | |||
| 292 | + | out.InputRects = append(out.InputRects, rt.inputRects...) | |||
| 293 | + | } | |||
| 294 | + | rt.inputStaged = false | |||
| 295 | + | } | |||
| 296 | + | } | |||
| 297 | + | ||||
| 298 | + | func cursorOf(k css.Keyword) Cursor { | |||
| 299 | + | switch k { | |||
| 300 | + | case css.KeywordPointer: | |||
| 301 | + | return CursorPointer | |||
| 302 | + | case css.KeywordText: | |||
| 303 | + | return CursorText | |||
| 304 | + | case css.KeywordNotAllowed: | |||
| 305 | + | return CursorNotAllowed | |||
| 306 | + | } | |||
| 307 | + | return CursorDefault | |||
| 308 | + | } | |||
| 309 | + | ||||
| 310 | + | // Released must be called when the release eventfd of an Output buffer is | |||
| 311 | + | // readable. It lets the buffer be reused. | |||
| 312 | + | func (r *Renderer) Released(buffer uint64) error { return r.target.Released(buffer) } | |||
| 313 | + | ||||
| 314 | + | // Close cancels pending pastes and frees the GPU resources. The Renderer is | |||
| 315 | + | // unusable afterwards. | |||
| 316 | + | func (r *Renderer) Close() error { | |||
| 317 | + | if r.closed { | |||
| 318 | + | return nil | |||
| 319 | + | } | |||
| 320 | + | r.closed = true | |||
| 321 | + | if r.rt.pasteCancel != nil { | |||
| 322 | + | r.rt.pasteCancel() | |||
| 323 | + | } | |||
| 324 | + | return r.target.Close() | |||
| 325 | + | } | |||
| 326 | + | ||||
| 327 | + | // xkb keysym values; internal/ui never imports an xkb library. | |||
| 328 | + | const ( | |||
| 329 | + | keysymSpace = 0x0020 | |||
| 330 | + | keysymBackspace = 0xff08 | |||
| 331 | + | keysymTab = 0xff09 | |||
| 332 | + | keysymReturn = 0xff0d | |||
| 333 | + | keysymEscape = 0xff1b | |||
| 334 | + | keysymHome = 0xff50 | |||
| 335 | + | keysymLeft = 0xff51 | |||
| 336 | + | keysymUp = 0xff52 | |||
| 337 | + | keysymRight = 0xff53 | |||
| 338 | + | keysymDown = 0xff54 | |||
| 339 | + | keysymPageUp = 0xff55 | |||
| 340 | + | keysymPageDown = 0xff56 | |||
| 341 | + | keysymEnd = 0xff57 | |||
| 342 | + | keysymKPEnter = 0xff8d | |||
| 343 | + | keysymISOLeft = 0xfe20 | |||
| 344 | + | keysymDelete = 0xffff | |||
| 345 | + | ) | |||
| 346 | + | ||||
| 347 | + | // keysymName maps a keysym to the name interaction.go dispatches on; other | |||
| 348 | + | // keysyms have no name because only their text matters. | |||
| 349 | + | func keysymName(sym uint32) string { | |||
| 350 | + | switch sym { | |||
| 351 | + | case keysymSpace: | |||
| 352 | + | return "space" | |||
| 353 | + | case keysymTab: | |||
| 354 | + | return "tab" | |||
| 355 | + | case keysymISOLeft: | |||
| 356 | + | return "iso_left_tab" | |||
| 357 | + | case keysymLeft: | |||
| 358 | + | return "left" | |||
| 359 | + | case keysymRight: | |||
| 360 | + | return "right" | |||
| 361 | + | case keysymUp: | |||
| 362 | + | return "up" | |||
| 363 | + | case keysymDown: | |||
| 364 | + | return "down" | |||
| 365 | + | case keysymHome: | |||
| 366 | + | return "home" | |||
| 367 | + | case keysymEnd: | |||
| 368 | + | return "end" | |||
| 369 | + | case keysymPageUp: | |||
| 370 | + | return "page_up" | |||
| 371 | + | case keysymPageDown: | |||
| 372 | + | return "page_down" | |||
| 373 | + | case keysymBackspace: | |||
| 374 | + | return "backspace" | |||
| 375 | + | case keysymDelete: | |||
| 376 | + | return "delete" | |||
| 377 | + | case 'a', 'A': | |||
| 378 | + | return "a" | |||
| 379 | + | case 'c', 'C': | |||
| 380 | + | return "c" | |||
| 381 | + | case 'x', 'X': | |||
| 382 | + | return "x" | |||
| 383 | + | case 'v', 'V': | |||
| 384 | + | return "v" | |||
| 385 | + | case keysymReturn: | |||
| 386 | + | return "return" | |||
| 387 | + | case keysymKPEnter: | |||
| 388 | + | return "kp_enter" | |||
| 389 | + | case keysymEscape: | |||
| 390 | + | return "escape" | |||
| 391 | + | } | |||
| 392 | + | return "" | |||
| 393 | + | } | |||
A renderer.go +63 -0
| @@ -0,0 +1,63 @@ | |||
| 1 | + | //go:build linux | |
| 2 | + | ||
| 3 | + | package nefergui | |
| 4 | + | ||
| 5 | + | import "github.com/bnema/nefergui/internal/ui" | |
| 6 | + | ||
| 7 | + | // Renderer renders views into DMA-BUF buffers for a Wayland client the | |
| 8 | + | // application owns. It imports no Wayland library, starts no goroutine and is | |
| 9 | + | // used from one owner goroutine. Typical loop: forward Wayland events with | |
| 10 | + | // Input and Resize, call Render when a redraw is needed, import and present | |
| 11 | + | // the Output buffer, and call Released when its ReleaseFD becomes readable. | |
| 12 | + | // | |
| 13 | + | // Render is generic over the model type, so it is a generic method: | |
| 14 | + | // | |
| 15 | + | // ok, err := r.Render(&out, &model, view) | |
| 16 | + | type Renderer = ui.Renderer | |
| 17 | + | ||
| 18 | + | // RendererConfig configures NewRenderer. MainDevice and Formats come from the | |
| 19 | + | // compositor's linux-dmabuf feedback. | |
| 20 | + | type RendererConfig = ui.RendererConfig | |
| 21 | + | ||
| 22 | + | // Format is a DRM format and modifier the compositor accepts. | |
| 23 | + | type Format = ui.Format | |
| 24 | + | ||
| 25 | + | // Input is one platform input event; Text is valid only during Renderer.Input. | |
| 26 | + | type Input = ui.Input | |
| 27 | + | ||
| 28 | + | // Output describes one frame to present, in physical pixels. All file | |
| 29 | + | // descriptors stay owned by the Renderer: duplicate them before handing them to | |
| 30 | + | // a transport that consumes descriptors. Slices are valid until the next Render. | |
| 31 | + | type Output = ui.Output | |
| 32 | + | ||
| 33 | + | // Plane, Timeline and Retired are parts of Output. A Timeline FD is valid only | |
| 34 | + | // when Output.NewTimelines is set. The client must stop watching and destroy | |
| 35 | + | // each Retired buffer before the next Render. | |
| 36 | + | type ( | |
| 37 | + | Plane = ui.Plane | |
| 38 | + | Timeline = ui.Timeline | |
| 39 | + | Retired = ui.Retired | |
| 40 | + | ) | |
| 41 | + | ||
| 42 | + | // Clipboard is an optional asynchronous clipboard; IME an optional input method. | |
| 43 | + | type ( | |
| 44 | + | Clipboard = ui.Clipboard | |
| 45 | + | IME = ui.IME | |
| 46 | + | ) | |
| 47 | + | ||
| 48 | + | // Cursor is the pointer shape the surface wants. | |
| 49 | + | type Cursor = ui.Cursor | |
| 50 | + | ||
| 51 | + | const ( | |
| 52 | + | CursorDefault = ui.CursorDefault | |
| 53 | + | CursorPointer = ui.CursorPointer | |
| 54 | + | CursorText = ui.CursorText | |
| 55 | + | CursorNotAllowed = ui.CursorNotAllowed | |
| 56 | + | ||
| 57 | + | ModAlt = ui.ModAlt | |
| 58 | + | ModSuper = ui.ModSuper | |
| 59 | + | ) | |
| 60 | + | ||
| 61 | + | // NewRenderer opens the GPU named by cfg.MainDevice and loads fonts and | |
| 62 | + | // styles. It allocates no images. | |
| 63 | + | func NewRenderer(cfg RendererConfig) (*Renderer, error) { return ui.NewRenderer(cfg) } | |
| @@ -0,0 +1,63 @@ | |||||
| 1 | + | //go:build linux | |||
| 2 | + | ||||
| 3 | + | package nefergui | |||
| 4 | + | ||||
| 5 | + | import "github.com/bnema/nefergui/internal/ui" | |||
| 6 | + | ||||
| 7 | + | // Renderer renders views into DMA-BUF buffers for a Wayland client the | |||
| 8 | + | // application owns. It imports no Wayland library, starts no goroutine and is | |||
| 9 | + | // used from one owner goroutine. Typical loop: forward Wayland events with | |||
| 10 | + | // Input and Resize, call Render when a redraw is needed, import and present | |||
| 11 | + | // the Output buffer, and call Released when its ReleaseFD becomes readable. | |||
| 12 | + | // | |||
| 13 | + | // Render is generic over the model type, so it is a generic method: | |||
| 14 | + | // | |||
| 15 | + | // ok, err := r.Render(&out, &model, view) | |||
| 16 | + | type Renderer = ui.Renderer | |||
| 17 | + | ||||
| 18 | + | // RendererConfig configures NewRenderer. MainDevice and Formats come from the | |||
| 19 | + | // compositor's linux-dmabuf feedback. | |||
| 20 | + | type RendererConfig = ui.RendererConfig | |||
| 21 | + | ||||
| 22 | + | // Format is a DRM format and modifier the compositor accepts. | |||
| 23 | + | type Format = ui.Format | |||
| 24 | + | ||||
| 25 | + | // Input is one platform input event; Text is valid only during Renderer.Input. | |||
| 26 | + | type Input = ui.Input | |||
| 27 | + | ||||
| 28 | + | // Output describes one frame to present, in physical pixels. All file | |||
| 29 | + | // descriptors stay owned by the Renderer: duplicate them before handing them to | |||
| 30 | + | // a transport that consumes descriptors. Slices are valid until the next Render. | |||
| 31 | + | type Output = ui.Output | |||
| 32 | + | ||||
| 33 | + | // Plane, Timeline and Retired are parts of Output. A Timeline FD is valid only | |||
| 34 | + | // when Output.NewTimelines is set. The client must stop watching and destroy | |||
| 35 | + | // each Retired buffer before the next Render. | |||
| 36 | + | type ( | |||
| 37 | + | Plane = ui.Plane | |||
| 38 | + | Timeline = ui.Timeline | |||
| 39 | + | Retired = ui.Retired | |||
| 40 | + | ) | |||
| 41 | + | ||||
| 42 | + | // Clipboard is an optional asynchronous clipboard; IME an optional input method. | |||
| 43 | + | type ( | |||
| 44 | + | Clipboard = ui.Clipboard | |||
| 45 | + | IME = ui.IME | |||
| 46 | + | ) | |||
| 47 | + | ||||
| 48 | + | // Cursor is the pointer shape the surface wants. | |||
| 49 | + | type Cursor = ui.Cursor | |||
| 50 | + | ||||
| 51 | + | const ( | |||
| 52 | + | CursorDefault = ui.CursorDefault | |||
| 53 | + | CursorPointer = ui.CursorPointer | |||
| 54 | + | CursorText = ui.CursorText | |||
| 55 | + | CursorNotAllowed = ui.CursorNotAllowed | |||
| 56 | + | ||||
| 57 | + | ModAlt = ui.ModAlt | |||
| 58 | + | ModSuper = ui.ModSuper | |||
| 59 | + | ) | |||
| 60 | + | ||||
| 61 | + | // NewRenderer opens the GPU named by cfg.MainDevice and loads fonts and | |||
| 62 | + | // styles. It allocates no images. | |||
| 63 | + | func NewRenderer(cfg RendererConfig) (*Renderer, error) { return ui.NewRenderer(cfg) } | |||