mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
graphicsdriver/opengl: Use context.Context when possible
This commit is contained in:
parent
9c283d45b4
commit
1e93d9c699
@ -17,6 +17,7 @@
|
||||
package opengl
|
||||
|
||||
import (
|
||||
stdcontext "context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
@ -76,7 +77,7 @@ type contextImpl struct {
|
||||
// doWork consumes the queued GL tasks.
|
||||
//
|
||||
// doWork is called only on gomobile-bind.
|
||||
func (c *context) doWork(done <-chan struct{}) error {
|
||||
func (c *context) doWork(context stdcontext.Context) {
|
||||
if c.worker == nil {
|
||||
panic("opengl: worker must be initialized but not")
|
||||
}
|
||||
@ -87,11 +88,10 @@ loop:
|
||||
select {
|
||||
case <-workAvailable:
|
||||
c.worker.DoWork()
|
||||
case <-done:
|
||||
case <-context.Done():
|
||||
break loop
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *context) reset() error {
|
||||
|
@ -17,11 +17,13 @@
|
||||
package opengl
|
||||
|
||||
import (
|
||||
stdcontext "context"
|
||||
|
||||
"golang.org/x/mobile/gl"
|
||||
)
|
||||
|
||||
func (d *Driver) DoWork(done <-chan struct{}) error {
|
||||
return d.context.doWork(done)
|
||||
func (d *Driver) DoWork(context stdcontext.Context) {
|
||||
d.context.doWork(context)
|
||||
}
|
||||
|
||||
func (d *Driver) Init() {
|
||||
|
@ -17,6 +17,7 @@
|
||||
package mobile
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"image"
|
||||
"runtime"
|
||||
@ -71,7 +72,13 @@ func (u *UserInterface) Render(chError <-chan error) error {
|
||||
}
|
||||
|
||||
renderCh <- struct{}{}
|
||||
return opengl.Get().DoWork(renderEndCh)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
go func() {
|
||||
<-renderEndCh
|
||||
cancel()
|
||||
}()
|
||||
opengl.Get().DoWork(ctx)
|
||||
return nil
|
||||
}
|
||||
|
||||
type UserInterface struct {
|
||||
|
Loading…
Reference in New Issue
Block a user