Home /Modules/ballum/surface-demo.sleela

surface-demo.sleela

lib/ballum/surface-demo.sleela · 120 line(s) · sleela

#sleela 2.5
material;
< surface-demo.sleela -- the runnable demo of Ballum's fullscreen surface: the >
< total, owned, fast per-pixel path. Self-contained over the uiBallum* VM >
< bridge (the house demo style; mirrors SLBallumScreen.claimFullScreen / >
< present / releaseFullScreen). It opens the primary display, claims a >
< fullscreen framebuffer surface, draws a batch of pixels into it, presents the >
< whole frame in one native image transfer, then releases the surface. On a >
< headless host the backend is the unavailable fallback and every op reports an >
< honest status, never a false success. >
<  >
< Status codes: 0 ok, 2 backend-unavailable, 4 display-not-found, 7 unsupported. >
< Capability bits: 1 per-pixel, 128 fullscreen-surface. >
class SurfaceDemo {
  < ---- Descriptive metadata (version 1.11 nested-friendly accessors) ---- >
  << Eleven catalogued attributes with getter/setter pairs, so a GUI, loader,
     or catalog can read and (where appropriate) override this record.
     Values are faithful to the real origin of the subject where publicly known. >>
  String metaVersion = "1.0.0";
  int metaId = 11551;
  String metaAuthor = "Kiro Agent";
  String metaDate = "2026-10-31";
  String metaCopyright = "SLeeLa project";
  String metaTrademark = "none";
  String metaCorporation = "none";
  < metaOrigin: National | <nation> | International | Galactic >
  String metaOrigin = "International";
  String metaBirthDate = "2026-10-31";
  < metaScienceRating: maturity/robustness on a 1..10 scale >
  int metaScienceRating = 8;
  < metaNationalSchedule: a real, citable instrument or "none" >
  String metaNationalSchedule = "none";

  String getMetaVersion() { return metaVersion; }
  void setMetaVersion(String v) { metaVersion = v; }
  int getMetaId() { return metaId; }
  void setMetaId(int v) { metaId = v; }
  String getAuthor() { return metaAuthor; }
  void setAuthor(String v) { metaAuthor = v; }
  String getDate() { return metaDate; }
  void setDate(String v) { metaDate = v; }
  String getCopyright() { return metaCopyright; }
  void setCopyright(String v) { metaCopyright = v; }
  String getTrademark() { return metaTrademark; }
  void setTrademark(String v) { metaTrademark = v; }
  String getCorporation() { return metaCorporation; }
  void setCorporation(String v) { metaCorporation = v; }
  String getOrigin() { return metaOrigin; }
  void setOrigin(String v) { metaOrigin = v; }
  String getBirthDate() { return metaBirthDate; }
  void setBirthDate(String v) { metaBirthDate = v; }
  int getScienceRating() { return metaScienceRating; }
  void setScienceRating(int v) { metaScienceRating = v; }
  String getNationalSchedule() { return metaNationalSchedule; }
  void setNationalSchedule(String v) { metaNationalSchedule = v; }

  int boundId;
  int w;
  int h;
  int caps;

  boolean capHas(int bit) { return (caps / bit) % 2 == 1; }

  String statusText(int code) {
    if (code == 0) { return "ok"; }
    if (code == 2) { return "backend unavailable"; }
    if (code == 4) { return "display not found"; }
    if (code == 7) { return "unsupported"; }
    return uiBallumStatusName(code);
  }

  int open() {
    int st = uiBallumEnumerate();
    if (st != 0) { return st; }
    int n = uiBallumDisplayCount();
    if (n == 0) { return 4; }
    int idx = 0;
    int i = 0;
    while (i < n) { if (uiBallumDisplayPrimary(i) == 1) { idx = i; } i = i + 1; }
    boundId = uiBallumDisplayId(idx);
    w = uiBallumDisplayWidth(idx);
    h = uiBallumDisplayHeight(idx);
    caps = uiBallumDisplayCaps(idx);
    return 0;
  }

  void main() {
    print("=== Ballum fullscreen surface (total per-pixel control) ===");
    print("backend: " + uiBallumBackendName());

    int st = open();
    print("open primary: " + statusText(st));

    if (st == 0) {
      print("screen id=" + boundId + " size " + w + "x" + h
            + " perPixel=" + capHas(1) + " fullscreen=" + capHas(128));
      print("has surface: " + uiBallumHasSurface(boundId));

      < Claim the owned fullscreen surface. >
      print("claim:   " + statusText(uiBallumClaimSurface(boundId)));

      < Draw a batch into the framebuffer (no device round-trips until present). >
      int y = 0;
      while (y < h) {
        uiBallumSetPixel(boundId, 0, y, 0, 128, 255, 255);
        y = y + 1;
      }

      < Push the whole frame to the screen in one native image transfer. >
      print("present: " + statusText(uiBallumPresent(boundId)));
      print("release: " + statusText(uiBallumReleaseSurface(boundId)));
    } else {
      < Headless: prove the surface calls refuse cleanly and precisely. >
      print("no screen; claim refuses:   " + statusText(uiBallumClaimSurface(0)));
      print("no screen; present refuses: " + statusText(uiBallumPresent(0)));
    }
    print("done");
  }
}