Class PixelCanvas

java.lang.Object
protocols.apps.canvas.PixelCanvas

public final class PixelCanvas extends Object
The shared pixel grid: one PaintOp winner per cell under last-writer-wins (see PaintOp.isNewerThan(protocols.apps.canvas.PaintOp)). All mutation goes through apply(protocols.apps.canvas.PaintOp); reads (snapshotArgb(), snapshotOps(), digest()) are used by the web UI thread and the periodic digest timer, so every method is synchronized on this instance.

digest() is the convergence oracle: a stable 64-bit hash over the winning colour of every painted cell in row-major order. Two nodes that have applied the same set of ops produce the same digest — the experiments harness asserts all live nodes agree once gossip quiesces.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Colour reported for a cell nobody has painted yet (transparent).
  • Constructor Summary

    Constructors
    Constructor
    Description
    PixelCanvas(int width, int height)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Apply an op under last-writer-wins.
    long
    Stable 64-bit digest of the visible canvas: FNV-1a over (index, argb) for every painted cell in row-major order.
    int
     
    int
     
    int
    Merge a peer's snapshot into this canvas under LWW.
    int
    Number of cells that have been painted at least once.
    int[]
    The grid as a row-major array of ARGB colours, EMPTY for unpainted cells.
    All current winning ops (one per painted cell) — used to seed a joining peer.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • EMPTY

      public static final int EMPTY
      Colour reported for a cell nobody has painted yet (transparent).
      See Also:
  • Constructor Details

    • PixelCanvas

      public PixelCanvas(int width, int height)
  • Method Details

    • getWidth

      public int getWidth()
    • getHeight

      public int getHeight()
    • apply

      public boolean apply(PaintOp op)
      Apply an op under last-writer-wins. Returns true if it became (or remained the basis of) the new winner for its cell — i.e. the visible colour may have changed; false if an out-of-bounds op or an op superseded by what the cell already holds. Idempotent and order-independent: applying the same op twice, or applying ops in any order, yields the same grid.
    • paintedCount

      public int paintedCount()
      Number of cells that have been painted at least once.
    • snapshotArgb

      public int[] snapshotArgb()
      The grid as a row-major array of ARGB colours, EMPTY for unpainted cells. A copy — safe to hand to the UI thread.
    • snapshotOps

      public List<PaintOp> snapshotOps()
      All current winning ops (one per painted cell) — used to seed a joining peer.
    • mergeSnapshot

      public int mergeSnapshot(List<PaintOp> ops)
      Merge a peer's snapshot into this canvas under LWW. Returns how many cells changed.
    • digest

      public long digest()
      Stable 64-bit digest of the visible canvas: FNV-1a over (index, argb) for every painted cell in row-major order. Equal across nodes that have applied the same set of ops; the convergence oracle for the experiments harness.