text stringlengths 0 1.47k |
|---|
d, err := mtkdisp.Open() |
if err != nil { |
fatal("%v", err) |
} |
defer d.Close() |
fmt.Printf("display: session 0x%x, %dx%d @ %d Hz, format 0x%x, %d layers, physical %dx%d mm\n", |
d.Session(), d.Info.Width, d.Info.Height, d.Info.VsyncFPS, d.Info.Format, d.Info.MaxLayers, |
d.Info.PhysicalMM[0], d.Info.PhysicalMM[1]) |
if *info { |
return |
} |
if *mode != 0 { |
if err := d.SetMode(uint32(*mode)); err != nil { |
fatal("%v", err) |
} |
fmt.Printf("session mode set to %d\n", *mode) |
} |
if *vsync { |
for i := 0; i < 3; i++ { |
n, ts, err := d.WaitVsync() |
if err != nil { |
fatal("vsync: %v", err) |
} |
fmt.Printf("vsync %d at %v\n", n, ts) |
} |
return |
} |
if *capture != "" { |
raw, err := mtkdisp.Capture(d.Info.Width, d.Info.Height) |
if err != nil { |
fatal("%v", err) |
} |
// Rotate the portrait capture back to landscape for viewing: panel (px, py) came from |
// landscape (py, panelW-1-px). |
pw, ph := d.Info.Width, d.Info.Height |
shot := image.NewRGBA(image.Rect(0, 0, ph, pw)) |
for py := 0; py < ph; py++ { |
for px := 0; px < pw; px++ { |
o := (py*pw + px) * 4 |
x, y := py, pw-1-px |
i := shot.PixOffset(x, y) |
shot.Pix[i+0] = raw[o+2] |
shot.Pix[i+1] = raw[o+1] |
shot.Pix[i+2] = raw[o+0] |
shot.Pix[i+3] = 0xff |
} |
} |
lit := 0 |
for i := 0; i < len(raw); i += 4 { |
if raw[i] != 0 || raw[i+1] != 0 || raw[i+2] != 0 { |
lit++ |
} |
} |
f, err := os.Create(*capture) |
if err != nil { |
fatal("%v", err) |
} |
defer f.Close() |
if err := png.Encode(f, shot); err != nil { |
fatal("png: %v", err) |
} |
fmt.Printf("captured %s: %d of %d pixels not black\n", *capture, lit, len(raw)/4) |
return |
} |
pw, ph := d.Info.Width, d.Info.Height // panel, portrait |
bufs := make([]*mtkdisp.Buffer, 2) |
for i := range bufs { |
bufs[i], err = d.NewBuffer(pw, ph) |
if err != nil { |
fatal("%v", err) |
} |
defer bufs[i].Free() |
} |
fmt.Printf("buffers: %d x %d bytes\n", len(bufs), len(bufs[0].Mem)) |
for i, b := range bufs { |
mva, err := b.MVA() |
if err != nil { |
fmt.Fprintf(os.Stderr, "buffer %d mva: %v\n", i, err) |
continue |
} |
fmt.Printf("buffer %d device address (mva): 0x%08x\n", i, mva) |
} |
// Compose landscape (the way the device sits), rotate onto the portrait panel. |
w, h := ph, pw |
img := image.NewRGBA(image.Rect(0, 0, w, h)) |
bg := color.RGBA{0x1c, 0x15, 0x11, 0xff} |
if *fill != "" { |
if c, err := strconv.ParseUint(*fill, 16, 32); err == nil { |
bg = color.RGBA{uint8(c >> 16), uint8(c >> 8), uint8(c), 0xff} |
} |
} |
amber := color.RGBA{0xe9, 0xa2, 0x3b, 0xff} |
ink := color.RGBA{0xe8, 0xdc, 0xc8, 0xff} |
draw.Draw(img, img.Bounds(), image.NewUniform(bg), image.Point{}, draw.Src) |
if *fill == "" { |
bars := []color.RGBA{{0xff, 0, 0, 0xff}, {0, 0xff, 0, 0xff}, {0, 0, 0xff, 0xff}, {0xff, 0xff, 0xff, 0xff}, amber} |
bw := w / len(bars) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.