~eliasnaur/gio

79f037f983a76cb8ee67722681e03a049305ef8b — Elias Naur 1 year, 11 months ago 0e2e02a
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>
1 files changed, 9 insertions(+), 8 deletions(-)

M app/window.go
M app/window.go => app/window.go +9 -8
@@ 204,14 204,16 @@ func (w *Window) validateAndProcess(d driver, size image.Point, sync bool, frame
				return err
			}
		}
		if w.gpu == nil && !w.nocontext {
		if w.ctx != nil {
			if err := w.ctx.Lock(); err != nil {
				w.destroyGPU()
				return err
			}
		}
		if w.gpu == nil && !w.nocontext {
			gpu, err := gpu.New(w.ctx.API())
			w.ctx.Unlock()
			if err != nil {
				w.ctx.Unlock()
				w.destroyGPU()
				return err
			}


@@ 219,6 221,7 @@ func (w *Window) validateAndProcess(d driver, size image.Point, sync bool, frame
		}
		if w.gpu != nil {
			if err := w.frame(frame, size); err != nil {
				w.ctx.Unlock()
				if errors.Is(err, errOutOfDate) {
					// GPU surface needs refreshing.
					sync = true


@@ 236,18 239,16 @@ func (w *Window) validateAndProcess(d driver, size image.Point, sync bool, frame
		if signal != nil {
			signal <- struct{}{}
		}
		var err error
		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 {
	if err := w.ctx.Lock(); err != nil {
		return err
	}
	defer w.ctx.Unlock()
	if runtime.GOOS == "js" {
		// Use transparent black when Gio is embedded, to allow mixing of Gio and
		// foreign content below.