From 55bfe19bf886ccf84f9f2d561b94d0d6c1240d99 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 4 Jul 2016 01:25:35 +0900 Subject: [PATCH] opengl: Add context.DoWork (mobile) --- internal/graphics/opengl/context_mobile.go | 24 ++++++++++++++++++---- internal/ui/ui_mobile.go | 23 +-------------------- 2 files changed, 21 insertions(+), 26 deletions(-) diff --git a/internal/graphics/opengl/context_mobile.go b/internal/graphics/opengl/context_mobile.go index 253b99a77..20bf1a871 100644 --- a/internal/graphics/opengl/context_mobile.go +++ b/internal/graphics/opengl/context_mobile.go @@ -71,6 +71,26 @@ func NewContext() (*Context, error) { return c, nil } +func (c *Context) DoWork(chError <-chan error, chDone <-chan struct{}) error { + // TODO: Check this is called on the rendering thread +loop: + for { + select { + case err := <-chError: + return err + case <-c.worker.WorkAvailable(): + c.worker.DoWork() + default: + select { + case <-chDone: + break loop + default: + } + } + } + return nil +} + func (c *Context) Reset() error { c.locationCache = newLocationCache() c.lastFramebuffer = invalidFramebuffer @@ -85,10 +105,6 @@ func (c *Context) Reset() error { return nil } -func (c *Context) Worker() mgl.Worker { - return c.worker -} - func (c *Context) BlendFunc(mode CompositeMode) { gl := c.gl if c.lastCompositeMode == mode { diff --git a/internal/ui/ui_mobile.go b/internal/ui/ui_mobile.go index 7ea5fae39..e9fdfdc7f 100644 --- a/internal/ui/ui_mobile.go +++ b/internal/ui/ui_mobile.go @@ -42,34 +42,13 @@ func Render(chError <-chan error) error { // TODO: Check this is called on the rendering thread select { case chRender <- struct{}{}: - return doGLWorks(chError, chRenderEnd) + return glContext.DoWork(chError, chRenderEnd) case <-time.After(500 * time.Millisecond): // This function must not be blocked. We need to break for timeout. return nil } } -func doGLWorks(chError <-chan error, chDone <-chan struct{}) error { - // TODO: Check this is called on the rendering thread - worker := glContext.Worker() -loop: - for { - select { - case err := <-chError: - return err - case <-worker.WorkAvailable(): - worker.DoWork() - default: - select { - case <-chDone: - break loop - default: - } - } - } - return nil -} - type userInterface struct { width int height int