mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
app,app/internal/wm: fold context MakeCurrent/ReleaseCurrent into Lock/Unlock
While here, make context Refresh useful and remove the redundant MakeCurrent from the window loop. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -72,16 +72,9 @@ func (c *d3d11Context) Present() error {
|
||||
}
|
||||
|
||||
func (c *d3d11Context) Refresh() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *d3d11Context) MakeCurrent() error {
|
||||
var width, height int
|
||||
c.win.w.Run(func() {
|
||||
_, width, height = c.win.HWND()
|
||||
})
|
||||
_, width, height = c.win.HWND()
|
||||
if c.renderTarget != nil && width == c.width && height == c.height {
|
||||
c.ctx.OMSetRenderTargets(c.renderTarget, c.depthView)
|
||||
return nil
|
||||
}
|
||||
c.releaseFBO()
|
||||
@@ -112,14 +105,13 @@ func (c *d3d11Context) MakeCurrent() error {
|
||||
}
|
||||
c.renderTarget = renderTarget
|
||||
c.depthView = depthView
|
||||
|
||||
c.ctx.OMSetRenderTargets(c.renderTarget, c.depthView)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *d3d11Context) ReleaseCurrent() {}
|
||||
|
||||
func (c *d3d11Context) Lock() {}
|
||||
func (c *d3d11Context) Lock() error {
|
||||
c.ctx.OMSetRenderTargets(c.renderTarget, c.depthView)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *d3d11Context) Unlock() {}
|
||||
|
||||
|
||||
@@ -35,33 +35,23 @@ func (c *context) Release() {
|
||||
}
|
||||
|
||||
func (c *context) Refresh() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *context) MakeCurrent() error {
|
||||
c.Context.ReleaseSurface()
|
||||
var (
|
||||
win *C.ANativeWindow
|
||||
width, height int
|
||||
)
|
||||
// Run on main thread. Deadlock is avoided because MakeCurrent is only
|
||||
// called during a FrameEvent.
|
||||
c.win.callbacks.Run(func() {
|
||||
win, width, height = c.win.nativeWindow(c.Context.VisualID())
|
||||
})
|
||||
win, width, height = c.win.nativeWindow(c.Context.VisualID())
|
||||
if win == nil {
|
||||
return nil
|
||||
}
|
||||
eglSurf := egl.NativeWindowType(unsafe.Pointer(win))
|
||||
if err := c.Context.CreateSurface(eglSurf, width, height); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := c.Context.MakeCurrent(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return c.Context.CreateSurface(eglSurf, width, height)
|
||||
}
|
||||
|
||||
func (c *context) Lock() {}
|
||||
func (c *context) Lock() error {
|
||||
return c.Context.MakeCurrent()
|
||||
}
|
||||
|
||||
func (c *context) Unlock() {}
|
||||
func (c *context) Unlock() {
|
||||
c.Context.ReleaseCurrent()
|
||||
}
|
||||
|
||||
@@ -50,10 +50,6 @@ func (c *context) Release() {
|
||||
}
|
||||
|
||||
func (c *context) Refresh() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *context) MakeCurrent() error {
|
||||
c.Context.ReleaseSurface()
|
||||
if c.eglWin != nil {
|
||||
C.wl_egl_window_destroy(c.eglWin)
|
||||
@@ -69,12 +65,13 @@ func (c *context) MakeCurrent() error {
|
||||
}
|
||||
c.eglWin = eglWin
|
||||
eglSurf := egl.NativeWindowType(uintptr(unsafe.Pointer(eglWin)))
|
||||
if err := c.Context.CreateSurface(eglSurf, width, height); err != nil {
|
||||
return err
|
||||
}
|
||||
return c.Context.CreateSurface(eglSurf, width, height)
|
||||
}
|
||||
|
||||
func (c *context) Lock() error {
|
||||
return c.Context.MakeCurrent()
|
||||
}
|
||||
|
||||
func (c *context) Lock() {}
|
||||
|
||||
func (c *context) Unlock() {}
|
||||
func (c *context) Unlock() {
|
||||
c.Context.ReleaseCurrent()
|
||||
}
|
||||
|
||||
@@ -35,18 +35,12 @@ func (c *glContext) Release() {
|
||||
}
|
||||
|
||||
func (c *glContext) Refresh() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *glContext) MakeCurrent() error {
|
||||
c.Context.ReleaseSurface()
|
||||
var (
|
||||
win windows.Handle
|
||||
width, height int
|
||||
)
|
||||
c.win.w.Run(func() {
|
||||
win, width, height = c.win.HWND()
|
||||
})
|
||||
win, width, height = c.win.HWND()
|
||||
eglSurf := egl.NativeWindowType(win)
|
||||
if err := c.Context.CreateSurface(eglSurf, width, height); err != nil {
|
||||
return err
|
||||
@@ -55,9 +49,14 @@ func (c *glContext) MakeCurrent() error {
|
||||
return err
|
||||
}
|
||||
c.Context.EnableVSync(true)
|
||||
c.Context.ReleaseCurrent()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *glContext) Lock() {}
|
||||
func (c *glContext) Lock() error {
|
||||
return c.Context.MakeCurrent()
|
||||
}
|
||||
|
||||
func (c *glContext) Unlock() {}
|
||||
func (c *glContext) Unlock() {
|
||||
c.Context.ReleaseCurrent()
|
||||
}
|
||||
|
||||
@@ -33,10 +33,6 @@ func (c *x11Context) Release() {
|
||||
}
|
||||
|
||||
func (c *x11Context) Refresh() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *x11Context) MakeCurrent() error {
|
||||
c.Context.ReleaseSurface()
|
||||
win, width, height := c.win.window()
|
||||
eglSurf := egl.NativeWindowType(uintptr(win))
|
||||
@@ -47,9 +43,14 @@ func (c *x11Context) MakeCurrent() error {
|
||||
return err
|
||||
}
|
||||
c.Context.EnableVSync(true)
|
||||
c.Context.ReleaseCurrent()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *x11Context) Lock() {}
|
||||
func (c *x11Context) Lock() error {
|
||||
return c.Context.MakeCurrent()
|
||||
}
|
||||
|
||||
func (c *x11Context) Unlock() {}
|
||||
func (c *x11Context) Unlock() {
|
||||
c.Context.ReleaseCurrent()
|
||||
}
|
||||
|
||||
@@ -97,15 +97,18 @@ func (c *context) Present() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *context) Lock() {}
|
||||
|
||||
func (c *context) Unlock() {}
|
||||
|
||||
func (c *context) Refresh() error {
|
||||
func (c *context) Lock() error {
|
||||
if C.gio_makeCurrent(c.ctx) == 0 {
|
||||
return errors.New("[EAGLContext setCurrentContext] failed")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *context) MakeCurrent() error {
|
||||
func (c *context) Unlock() {
|
||||
C.gio_makeCurrent(0)
|
||||
}
|
||||
|
||||
func (c *context) Refresh() error {
|
||||
if C.gio_makeCurrent(c.ctx) == 0 {
|
||||
return errors.New("[EAGLContext setCurrentContext] failed")
|
||||
}
|
||||
@@ -139,10 +142,6 @@ func (c *context) MakeCurrent() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *context) ReleaseCurrent() {
|
||||
C.gio_makeCurrent(0)
|
||||
}
|
||||
|
||||
func (w *window) NewContext() (Context, error) {
|
||||
return newContext(w)
|
||||
}
|
||||
|
||||
@@ -50,7 +50,9 @@ func (c *context) Present() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *context) Lock() {}
|
||||
func (c *context) Lock() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *context) Unlock() {}
|
||||
|
||||
@@ -58,12 +60,6 @@ func (c *context) Refresh() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *context) MakeCurrent() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *context) ReleaseCurrent() {}
|
||||
|
||||
func (w *window) NewContext() (Context, error) {
|
||||
return newContext(w)
|
||||
}
|
||||
|
||||
@@ -68,11 +68,14 @@ func (c *context) Present() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *context) Lock() {
|
||||
func (c *context) Lock() error {
|
||||
C.gio_lockContext(c.ctx)
|
||||
C.gio_makeCurrentContext(c.ctx)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *context) Unlock() {
|
||||
C.gio_clearCurrentContext()
|
||||
C.gio_unlockContext(c.ctx)
|
||||
}
|
||||
|
||||
@@ -83,17 +86,6 @@ func (c *context) Refresh() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *context) MakeCurrent() error {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
C.gio_makeCurrentContext(c.ctx)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *context) ReleaseCurrent() {
|
||||
C.gio_clearCurrentContext()
|
||||
}
|
||||
|
||||
func (w *window) NewContext() (Context, error) {
|
||||
return newContext(w)
|
||||
}
|
||||
|
||||
@@ -69,11 +69,9 @@ type Callbacks interface {
|
||||
type Context interface {
|
||||
API() gpu.API
|
||||
Present() error
|
||||
MakeCurrent() error
|
||||
ReleaseCurrent()
|
||||
Refresh() error
|
||||
Release()
|
||||
Lock()
|
||||
Lock() error
|
||||
Unlock()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user