mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-05 17:35:36 +00:00
app,app/internal/wm: create contexts on the main thread
Instead of handing the internal/wm driver a method to run code on the (blocked) main thread, just run the necessary driver methods on the main thread. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -40,11 +40,7 @@ func newContext(w *window) (*context, error) {
|
|||||||
if ctx == 0 {
|
if ctx == 0 {
|
||||||
return nil, errors.New("gl: failed to create NSOpenGLContext")
|
return nil, errors.New("gl: failed to create NSOpenGLContext")
|
||||||
}
|
}
|
||||||
// [NSOpenGLContext setView] must run on the main thread. Fortunately,
|
C.gio_setContextView(ctx, view)
|
||||||
// newContext is only called during a [NSView draw] on the main thread.
|
|
||||||
w.w.Run(func() {
|
|
||||||
C.gio_setContextView(ctx, view)
|
|
||||||
})
|
|
||||||
c := &context{
|
c := &context{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
view: view,
|
view: view,
|
||||||
|
|||||||
@@ -60,10 +60,6 @@ type FrameEvent struct {
|
|||||||
type Callbacks interface {
|
type Callbacks interface {
|
||||||
SetDriver(d Driver)
|
SetDriver(d Driver)
|
||||||
Event(e event.Event)
|
Event(e event.Event)
|
||||||
// Func runs a function during an Event. This is required for platforms
|
|
||||||
// that require coordination between the rendering goroutine and the system
|
|
||||||
// main thread.
|
|
||||||
Run(f func())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Context interface {
|
type Context interface {
|
||||||
|
|||||||
+3
-5
@@ -145,7 +145,9 @@ func (w *Window) validateAndProcess(driver wm.Driver, frameStart time.Time, size
|
|||||||
if w.loop == nil && !w.nocontext {
|
if w.loop == nil && !w.nocontext {
|
||||||
var err error
|
var err error
|
||||||
if w.ctx == nil {
|
if w.ctx == nil {
|
||||||
w.ctx, err = driver.NewContext()
|
w.driverRun(func(_ wm.Driver) {
|
||||||
|
w.ctx, err = driver.NewContext()
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -395,10 +397,6 @@ loop:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *callbacks) Run(f func()) {
|
|
||||||
c.w.Run(f)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *Window) waitAck() {
|
func (w *Window) waitAck() {
|
||||||
// Send a dummy event; when it gets through we
|
// Send a dummy event; when it gets through we
|
||||||
// know the application has processed the previous event.
|
// know the application has processed the previous event.
|
||||||
|
|||||||
Reference in New Issue
Block a user