Files
openchamber-android-native/third_party/mygo/internal/gpu/metal/canvas_test.go
T
OpenChamber 6c0ee61750 feat: port the client to MyGo native UI (0.3.0)
Switch from Asuka to MyGo, keeping the API client and the feature set:

- servers: saved servers, passwordless and password login, proxy,
  self-signed certificates, per-server device tokens (Keystore), connect
  form, instance list sheet with switch/disconnect
- sessions: virtualized list, search, new session, rename/archive/delete,
  running indicator, event stream keeps it live
- chat: pushed window with system back bar, streaming Markdown via
  ui/markdown, reasoning and tool rows with image previews, footer menu
  (read aloud via a Kotlin TTS plugin, copy, fork), user message menu
  (copy, revert, fork), context usage ring and detail sheet, attachments
  (photos/files via the document picker), permissions
- release builds allow plain http:// LAN servers (Go's net/http dials
  directly, no cleartext manifest needed)
- a local fork of MyGo (third_party/mygo) lowers the Android host's
  minSdk to 24 (Android 7.0); Go 1.27.4 via mise

Version 0.3.0.
2026-11-18 13:22:59 +08:00

65 lines
1.7 KiB
Go

//go:build darwin && !ios
package metal
import (
"runtime"
"testing"
"github.com/egoist/mygo/internal/gpu/gputest"
"github.com/egoist/mygo/internal/scene"
)
// Canvases draw into textures as the CPU renderer draws them into pixels,
// once each: the second frame draws none anew, and shows them the same.
func TestCanvases(t *testing.T) {
r, err := newRenderer()
if err != nil {
t.Skip("no Metal:", err)
}
defer r.Release()
s := gputest.CanvasScene()
for frame := range 2 {
pix, err := r.renderOffscreen(s)
if err != nil {
t.Fatal(err)
}
gputest.Compare(t, "metal-canvas", pix, s.Width*4, s)
if frame == 0 {
s.Canvases = nil // drawn: only shown from now on
}
}
if len(r.canvases) != 3 {
t.Errorf("%d canvas textures, want 3", len(r.canvases))
}
}
// A transient canvas's texture stays while frames draw it, and goes once
// they stop, though the canvas is still about; another canvas's stays
// until it is collected.
func TestTransientCanvas(t *testing.T) {
r, err := newRenderer()
if err != nil {
t.Skip("no Metal:", err)
}
defer r.Release()
layer, kept := scene.NewCanvas(64, 64), scene.NewCanvas(64, 64)
layer.Transient = true
s := &scene.Scene{Width: 64, Height: 64}
s.Canvases = []*scene.Image{layer, kept}
if _, err := r.renderOffscreen(s); err != nil {
t.Fatal(err)
}
r.sweep()
if r.canvases[layer.ID()] == nil || r.canvases[kept.ID()] == nil {
t.Fatal("a sweep after the frame that drew them freed a canvas's texture")
}
r.frame++ // a frame that draws neither
r.sweep()
if r.canvases[layer.ID()] != nil || r.canvases[kept.ID()] == nil {
t.Errorf("transient canvas kept %v, other kept %v", r.canvases[layer.ID()] != nil, r.canvases[kept.ID()] != nil)
}
runtime.KeepAlive(layer)
runtime.KeepAlive(kept)
}