mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-07 18:35:34 +00:00
app: lock explicitly before refreshing contexts
Signed-off-by: Joe Julian <me@joejulian.name>
This commit is contained in:
@@ -115,9 +115,6 @@ func (c *context) Unlock() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *context) Refresh() error {
|
func (c *context) Refresh() error {
|
||||||
if C.gio_makeCurrent(c.ctx) == 0 {
|
|
||||||
return errors.New("[EAGLContext setCurrentContext] failed")
|
|
||||||
}
|
|
||||||
if !c.init {
|
if !c.init {
|
||||||
c.init = true
|
c.init = true
|
||||||
c.frameBuffer = c.c.CreateFramebuffer()
|
c.frameBuffer = c.c.CreateFramebuffer()
|
||||||
|
|||||||
@@ -169,6 +169,7 @@ type context interface {
|
|||||||
API() gpu.API
|
API() gpu.API
|
||||||
RenderTarget() (gpu.RenderTarget, error)
|
RenderTarget() (gpu.RenderTarget, error)
|
||||||
Present() error
|
Present() error
|
||||||
|
// Refresh assumes the context is already locked and current.
|
||||||
Refresh() error
|
Refresh() error
|
||||||
Release()
|
Release()
|
||||||
Lock() error
|
Lock() error
|
||||||
|
|||||||
+6
-6
@@ -149,6 +149,12 @@ func (w *Window) validateAndProcess(size image.Point, sync bool, frame *op.Ops,
|
|||||||
sync = true
|
sync = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if w.ctx != nil {
|
||||||
|
if err := w.ctx.Lock(); err != nil {
|
||||||
|
w.destroyGPU()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
if sync && w.ctx != nil {
|
if sync && w.ctx != nil {
|
||||||
if err := w.ctx.Refresh(); err != nil {
|
if err := w.ctx.Refresh(); err != nil {
|
||||||
if errors.Is(err, errOutOfDate) {
|
if errors.Is(err, errOutOfDate) {
|
||||||
@@ -163,12 +169,6 @@ func (w *Window) validateAndProcess(size image.Point, sync bool, frame *op.Ops,
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if w.ctx != nil {
|
|
||||||
if err := w.ctx.Lock(); err != nil {
|
|
||||||
w.destroyGPU()
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if w.gpu == nil && !w.nocontext {
|
if w.gpu == nil && !w.nocontext {
|
||||||
gpu, err := gpu.New(w.ctx.API())
|
gpu, err := gpu.New(w.ctx.API())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -0,0 +1,85 @@
|
|||||||
|
// SPDX-License-Identifier: Unlicense OR MIT
|
||||||
|
|
||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"image"
|
||||||
|
"image/color"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"gioui.org/gpu"
|
||||||
|
"gioui.org/op"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestValidateAndProcessLocksBeforeRefresh(t *testing.T) {
|
||||||
|
ctx := &testContext{}
|
||||||
|
w := &Window{
|
||||||
|
ctx: ctx,
|
||||||
|
gpu: &testGPU{},
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := w.validateAndProcess(image.Pt(320, 240), true, new(op.Ops), nil); err != nil {
|
||||||
|
t.Fatalf("validateAndProcess returned error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
want := []string{"lock", "refresh", "render-target", "present", "unlock"}
|
||||||
|
if got := ctx.ops; !equalStringSlices(got, want) {
|
||||||
|
t.Fatalf("unexpected call order:\n got %v\n want %v", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type testContext struct {
|
||||||
|
ops []string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *testContext) API() gpu.API {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *testContext) RenderTarget() (gpu.RenderTarget, error) {
|
||||||
|
c.ops = append(c.ops, "render-target")
|
||||||
|
return gpu.OpenGLRenderTarget{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *testContext) Present() error {
|
||||||
|
c.ops = append(c.ops, "present")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *testContext) Refresh() error {
|
||||||
|
c.ops = append(c.ops, "refresh")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *testContext) Release() {}
|
||||||
|
|
||||||
|
func (c *testContext) Lock() error {
|
||||||
|
c.ops = append(c.ops, "lock")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *testContext) Unlock() {
|
||||||
|
c.ops = append(c.ops, "unlock")
|
||||||
|
}
|
||||||
|
|
||||||
|
type testGPU struct{}
|
||||||
|
|
||||||
|
func (g *testGPU) Release() {}
|
||||||
|
|
||||||
|
func (g *testGPU) Clear(color.NRGBA) {}
|
||||||
|
|
||||||
|
func (g *testGPU) Frame(*op.Ops, gpu.RenderTarget, image.Point) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func equalStringSlices(a, b []string) bool {
|
||||||
|
if len(a) != len(b) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for i := range a {
|
||||||
|
if a[i] != b[i] {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user