mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-05 01:15:35 +00:00
app: avoid relocking contexts every frame
Signed-off-by: Joe Julian <me@joejulian.name>
This commit is contained in:
+26
-4
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user