mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-07 18:35:34 +00:00
app: lock GPU context during present
The OpenGL backend needs it, but I keep forgetting to test it when rearranging the window rendering code. The gogio X11 end-to-end test tests this issue, but unfortunately it is disabled because of flakiness. Fixes: https://todo.sr.ht/~eliasnaur/gio/412 Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+9
-8
@@ -204,14 +204,16 @@ func (w *Window) validateAndProcess(d driver, size image.Point, sync bool, frame
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if w.gpu == nil && !w.nocontext {
|
if w.ctx != nil {
|
||||||
if err := w.ctx.Lock(); err != nil {
|
if err := w.ctx.Lock(); err != nil {
|
||||||
w.destroyGPU()
|
w.destroyGPU()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if w.gpu == nil && !w.nocontext {
|
||||||
gpu, err := gpu.New(w.ctx.API())
|
gpu, err := gpu.New(w.ctx.API())
|
||||||
w.ctx.Unlock()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
w.ctx.Unlock()
|
||||||
w.destroyGPU()
|
w.destroyGPU()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -219,6 +221,7 @@ func (w *Window) validateAndProcess(d driver, size image.Point, sync bool, frame
|
|||||||
}
|
}
|
||||||
if w.gpu != nil {
|
if w.gpu != nil {
|
||||||
if err := w.frame(frame, size); err != nil {
|
if err := w.frame(frame, size); err != nil {
|
||||||
|
w.ctx.Unlock()
|
||||||
if errors.Is(err, errOutOfDate) {
|
if errors.Is(err, errOutOfDate) {
|
||||||
// GPU surface needs refreshing.
|
// GPU surface needs refreshing.
|
||||||
sync = true
|
sync = true
|
||||||
@@ -236,18 +239,16 @@ func (w *Window) validateAndProcess(d driver, size image.Point, sync bool, frame
|
|||||||
if signal != nil {
|
if signal != nil {
|
||||||
signal <- struct{}{}
|
signal <- struct{}{}
|
||||||
}
|
}
|
||||||
|
var err error
|
||||||
if w.gpu != nil {
|
if w.gpu != nil {
|
||||||
return w.ctx.Present()
|
err = w.ctx.Present()
|
||||||
|
w.ctx.Unlock()
|
||||||
}
|
}
|
||||||
return nil
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Window) frame(frame *op.Ops, viewport image.Point) error {
|
func (w *Window) frame(frame *op.Ops, viewport image.Point) error {
|
||||||
if err := w.ctx.Lock(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer w.ctx.Unlock()
|
|
||||||
if runtime.GOOS == "js" {
|
if runtime.GOOS == "js" {
|
||||||
// Use transparent black when Gio is embedded, to allow mixing of Gio and
|
// Use transparent black when Gio is embedded, to allow mixing of Gio and
|
||||||
// foreign content below.
|
// foreign content below.
|
||||||
|
|||||||
Reference in New Issue
Block a user