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