app: avoid relocking contexts every frame

Signed-off-by: Joe Julian <me@joejulian.name>
This commit is contained in:
Joe Julian
2026-04-20 16:52:33 -07:00
parent b9aa9e59f7
commit fb19cd6043
2 changed files with 59 additions and 19 deletions
+26 -4
View File
@@ -11,18 +11,40 @@ import (
"gioui.org/op"
)
func TestValidateAndProcessLocksBeforeRefresh(t *testing.T) {
func TestValidateAndProcessRelocksAfterRefresh(t *testing.T) {
ctx := &testContext{}
w := &Window{
ctx: ctx,
gpu: &testGPU{},
ctx: ctx,
gpu: &testGPU{},
ctxNeedsLock: false,
}
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"}
want := []string{"refresh", "lock", "render-target", "present"}
if got := ctx.ops; !equalStringSlices(got, want) {
t.Fatalf("unexpected call order:\n got %v\n want %v", got, want)
}
if w.ctxNeedsLock {
t.Fatalf("context should remain current after a successful frame")
}
}
func TestValidateAndProcessSkipsRedundantRelock(t *testing.T) {
ctx := &testContext{}
w := &Window{
ctx: ctx,
gpu: &testGPU{},
ctxNeedsLock: false,
}
if err := w.validateAndProcess(image.Pt(320, 240), false, new(op.Ops), nil); err != nil {
t.Fatalf("validateAndProcess returned error: %v", err)
}
want := []string{"render-target", "present"}
if got := ctx.ops; !equalStringSlices(got, want) {
t.Fatalf("unexpected call order:\n got %v\n want %v", got, want)
}