mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-08 02:45:38 +00:00
app: implement CustomRenderer option
CustomRenderer disables the construction and binding of a GPU context to the Window. Combined with ViewEvent and gpu.New, a Gio client can mix Gio UI and custom rendering. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -29,6 +29,7 @@ type Options struct {
|
|||||||
StatusColor *color.NRGBA
|
StatusColor *color.NRGBA
|
||||||
NavigationColor *color.NRGBA
|
NavigationColor *color.NRGBA
|
||||||
Orientation *Orientation
|
Orientation *Orientation
|
||||||
|
CustomRenderer bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type WindowMode uint8
|
type WindowMode uint8
|
||||||
|
|||||||
+22
-4
@@ -53,6 +53,8 @@ type Window struct {
|
|||||||
cursor pointer.CursorName
|
cursor pointer.CursorName
|
||||||
|
|
||||||
callbacks callbacks
|
callbacks callbacks
|
||||||
|
|
||||||
|
nocontext bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type callbacks struct {
|
type callbacks struct {
|
||||||
@@ -104,6 +106,7 @@ func NewWindow(options ...Option) *Window {
|
|||||||
frameAck: make(chan struct{}),
|
frameAck: make(chan struct{}),
|
||||||
driverFuncs: make(chan func()),
|
driverFuncs: make(chan func()),
|
||||||
dead: make(chan struct{}),
|
dead: make(chan struct{}),
|
||||||
|
nocontext: opts.CustomRenderer,
|
||||||
}
|
}
|
||||||
w.callbacks.funcs = make(chan func())
|
w.callbacks.funcs = make(chan func())
|
||||||
w.callbacks.w = w
|
w.callbacks.w = w
|
||||||
@@ -136,7 +139,7 @@ func (w *Window) validateAndProcess(frameStart time.Time, size image.Point, sync
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if w.loop == nil {
|
if w.loop == nil && !w.nocontext {
|
||||||
var err error
|
var err error
|
||||||
w.ctx, err = w.driver.NewContext()
|
w.ctx, err = w.driver.NewContext()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -149,7 +152,7 @@ func (w *Window) validateAndProcess(frameStart time.Time, size image.Point, sync
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
w.processFrame(frameStart, size, frame)
|
w.processFrame(frameStart, size, frame)
|
||||||
if sync {
|
if sync && w.loop != nil {
|
||||||
if err := w.loop.Flush(); err != nil {
|
if err := w.loop.Flush(); err != nil {
|
||||||
w.destroyGPU()
|
w.destroyGPU()
|
||||||
if err == wm.ErrDeviceLost {
|
if err == wm.ErrDeviceLost {
|
||||||
@@ -163,7 +166,14 @@ func (w *Window) validateAndProcess(frameStart time.Time, size image.Point, sync
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *Window) processFrame(frameStart time.Time, size image.Point, frame *op.Ops) {
|
func (w *Window) processFrame(frameStart time.Time, size image.Point, frame *op.Ops) {
|
||||||
sync := w.loop.Draw(size, frame)
|
var sync <-chan struct{}
|
||||||
|
if w.loop != nil {
|
||||||
|
sync = w.loop.Draw(size, frame)
|
||||||
|
} else {
|
||||||
|
s := make(chan struct{}, 1)
|
||||||
|
s <- struct{}{}
|
||||||
|
sync = s
|
||||||
|
}
|
||||||
w.queue.q.Frame(frame)
|
w.queue.q.Frame(frame)
|
||||||
switch w.queue.q.TextInputState() {
|
switch w.queue.q.TextInputState() {
|
||||||
case router.TextInputOpen:
|
case router.TextInputOpen:
|
||||||
@@ -177,7 +187,7 @@ func (w *Window) processFrame(frameStart time.Time, size image.Point, frame *op.
|
|||||||
if w.queue.q.ReadClipboard() {
|
if w.queue.q.ReadClipboard() {
|
||||||
go w.ReadClipboard()
|
go w.ReadClipboard()
|
||||||
}
|
}
|
||||||
if w.queue.q.Profiling() {
|
if w.queue.q.Profiling() && w.loop != nil {
|
||||||
frameDur := time.Since(frameStart)
|
frameDur := time.Since(frameStart)
|
||||||
frameDur = frameDur.Truncate(100 * time.Microsecond)
|
frameDur = frameDur.Truncate(100 * time.Microsecond)
|
||||||
q := 100 * time.Microsecond
|
q := 100 * time.Microsecond
|
||||||
@@ -571,4 +581,12 @@ func NavigationColor(color color.NRGBA) Option {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CustomRenderer controls whether the the window contents is
|
||||||
|
// rendered by the client. If true, no GPU context is created.
|
||||||
|
func CustomRenderer(custom bool) Option {
|
||||||
|
return func(opts *wm.Options) {
|
||||||
|
opts.CustomRenderer = custom
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (driverEvent) ImplementsEvent() {}
|
func (driverEvent) ImplementsEvent() {}
|
||||||
|
|||||||
Reference in New Issue
Block a user