graphics: Bug fix: screen flicks on Android (#229)

This commit is contained in:
Hajime Hoshi 2016-06-14 00:30:16 +09:00
parent 3f18096e95
commit 6640f60c88
2 changed files with 29 additions and 6 deletions

View File

@ -65,7 +65,7 @@ func (c *graphicsContext) needsRestoring(context *opengl.Context) (bool, error)
return c.screen.impl.isInvalidated(context), nil return c.screen.impl.isInvalidated(context), nil
} }
func (c *graphicsContext) Update() error { func (c *graphicsContext) UpdateAndDraw() error {
if !c.initialized { if !c.initialized {
if err := graphics.Initialize(ui.GLContext()); err != nil { if err := graphics.Initialize(ui.GLContext()); err != nil {
return err return err
@ -112,6 +112,22 @@ func (c *graphicsContext) Update() error {
return nil return nil
} }
func (c *graphicsContext) Draw() error {
if err := c.defaultRenderTarget.Clear(); err != nil {
return err
}
scale := float64(c.screenScale)
options := &DrawImageOptions{}
options.GeoM.Scale(scale, scale)
if err := c.defaultRenderTarget.DrawImage(c.screen, options); err != nil {
return err
}
if err := c.flush(); err != nil {
return err
}
return nil
}
func (c *graphicsContext) flush() error { func (c *graphicsContext) flush() error {
// TODO: imageM is necessary to call graphics functions. Move this to graphics package. // TODO: imageM is necessary to call graphics functions. Move this to graphics package.
imageM.Lock() imageM.Lock()

View File

@ -95,7 +95,8 @@ func (c *runContext) setRunningSlowly(isRunningSlowly bool) {
type GraphicsContext interface { type GraphicsContext interface {
SetSize(width, height, scale int) error SetSize(width, height, scale int) error
Update() error UpdateAndDraw() error
Draw() error
} }
func Run(g GraphicsContext, width, height, scale int, title string, fps int) error { func Run(g GraphicsContext, width, height, scale int, title string, fps int) error {
@ -143,10 +144,16 @@ func Run(g GraphicsContext, width, height, scale int, title string, fps int) err
if tt == 0 && (int64(time.Second)/int64(fps)-int64(5*time.Millisecond)) < t { if tt == 0 && (int64(time.Second)/int64(fps)-int64(5*time.Millisecond)) < t {
tt = 1 tt = 1
} }
for i := 0; i < tt; i++ { if 1 <= tt {
slow := i < tt-1 for i := 0; i < tt; i++ {
currentRunContext.setRunningSlowly(slow) slow := i < tt-1
if err := g.Update(); err != nil { currentRunContext.setRunningSlowly(slow)
if err := g.UpdateAndDraw(); err != nil {
return err
}
}
} else {
if err := g.Draw(); err != nil {
return err return err
} }
} }