Skip to content

Commit

Permalink
reduced input lag while dragging, added frame dumping
Browse files Browse the repository at this point in the history
  • Loading branch information
aarzilli committed Sep 18, 2018
1 parent 0849e87 commit 44e883e
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions shiny.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"image"
"image/draw"
"image/png"
"io"
"os"
"sync"
Expand All @@ -31,6 +32,9 @@ import (
//go:generate go-bindata -o internal/assets/assets.go -pkg assets DroidSansMono.ttf

const perfUpdate = false
const dumpFrame = false

var frameCnt = 0

var UnknownCommandErr = errors.New("unknown command")

Expand Down Expand Up @@ -313,8 +317,13 @@ func (ctx *context) processKeyEvent(e key.Event, textbuffer *bytes.Buffer) {
}

func (w *masterWindow) updater() {
var down bool
for {
time.Sleep(20 * time.Millisecond)
if down {
time.Sleep(10 * time.Millisecond)
} else {
time.Sleep(20 * time.Millisecond)
}
func() {
w.uilock.Lock()
defer w.uilock.Unlock()
Expand All @@ -326,7 +335,7 @@ func (w *masterWindow) updater() {
atomic.AddInt32(&w.ctx.changed, -1)
w.updateLocked()
} else {
down := false
down = false
for _, btn := range w.ctx.Input.Mouse.Buttons {
if btn.Down {
down = true
Expand Down Expand Up @@ -357,6 +366,10 @@ func (w *masterWindow) updateLocked() {
t0 = time.Now()
}

if dumpFrame && !perfUpdate {
panic("dumpFrame")
}

w.ctx.Update()

if perfUpdate || w.Perf {
Expand Down Expand Up @@ -391,6 +404,20 @@ func (w *masterWindow) updateLocked() {
d.Dot = fixed.P(bounds.Min.X, bounds.Min.Y+w.ctx.Style.Font.Metrics().Ascent.Ceil())
d.DrawString(s)
}
if dumpFrame && frameCnt < 1000 && nprimitives > 0 {
wimg := w.wndb.RGBA()

bounds := image.Rect(w.ctx.Input.Mouse.Pos.X, w.ctx.Input.Mouse.Pos.Y, w.ctx.Input.Mouse.Pos.X+10, w.ctx.Input.Mouse.Pos.Y+10)

draw.Draw(wimg, bounds, image.White, bounds.Min, draw.Src)

fh, err := os.Create(fmt.Sprintf("framedump/frame%d.png", frameCnt))
if err == nil {
png.Encode(fh, wimg)
fh.Close()
}
frameCnt++
}
if nprimitives > 0 {
w.wnd.Upload(w.bounds.Min, w.wndb, w.bounds)
w.wnd.Publish()
Expand Down

0 comments on commit 44e883e

Please sign in to comment.