mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-05 09:25:38 +00:00
app: move ownership of GPU context to app.Window
The Window creates the context, and should also be responsible for destroying it. As a bonus, the wrong release ordering of loop.renderLoop is fixed. Before this change, the context would be destroyed before the renderer got a chance to destroy its resources. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -77,7 +77,6 @@ func (l *renderLoop) renderLoop(ctx window.Context) error {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer g.Release()
|
defer g.Release()
|
||||||
defer ctx.Release()
|
|
||||||
initErr <- nil
|
initErr <- nil
|
||||||
loop:
|
loop:
|
||||||
for {
|
for {
|
||||||
|
|||||||
+9
-4
@@ -25,6 +25,7 @@ type Option func(opts *window.Options)
|
|||||||
// Window represents an operating system window.
|
// Window represents an operating system window.
|
||||||
type Window struct {
|
type Window struct {
|
||||||
driver window.Driver
|
driver window.Driver
|
||||||
|
ctx window.Context
|
||||||
loop *renderLoop
|
loop *renderLoop
|
||||||
|
|
||||||
// driverFuncs is a channel of functions to run when
|
// driverFuncs is a channel of functions to run when
|
||||||
@@ -132,14 +133,14 @@ func (w *Window) validateAndProcess(frameStart time.Time, size image.Point, sync
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if w.loop == nil {
|
if w.loop == nil {
|
||||||
var ctx window.Context
|
var err error
|
||||||
ctx, err := w.driver.NewContext()
|
w.ctx, err = w.driver.NewContext()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
w.loop, err = newLoop(ctx)
|
w.loop, err = newLoop(w.ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Release()
|
w.ctx.Release()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -295,6 +296,10 @@ func (w *Window) destroyGPU() {
|
|||||||
w.loop.Release()
|
w.loop.Release()
|
||||||
w.loop = nil
|
w.loop = nil
|
||||||
}
|
}
|
||||||
|
if w.ctx != nil {
|
||||||
|
w.ctx.Release()
|
||||||
|
w.ctx = nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// waitFrame waits for the client to either call FrameEvent.Frame
|
// waitFrame waits for the client to either call FrameEvent.Frame
|
||||||
|
|||||||
Reference in New Issue
Block a user