diff --git a/app/internal/gl/gl.go b/app/internal/gl/gl.go index b86bb7b5..0c5239ba 100644 --- a/app/internal/gl/gl.go +++ b/app/internal/gl/gl.go @@ -7,15 +7,6 @@ type ( Enum uint ) -type Context interface { - Functions() *Functions - Present() error - MakeCurrent() error - Release() - Lock() - Unlock() -} - const ( ARRAY_BUFFER = 0x8892 BLEND = 0xbe2 diff --git a/app/internal/window/egl_android.go b/app/internal/window/egl_android.go index f73cbfde..a1d3cbe5 100644 --- a/app/internal/window/egl_android.go +++ b/app/internal/window/egl_android.go @@ -11,7 +11,6 @@ import ( "unsafe" "gioui.org/app/internal/egl" - "gioui.org/app/internal/gl" ) type context struct { @@ -19,7 +18,7 @@ type context struct { *egl.Context } -func (w *window) NewContext() (gl.Context, error) { +func (w *window) NewContext() (Context, error) { ctx, err := egl.NewContext(nil) if err != nil { return nil, err diff --git a/app/internal/window/egl_wayland.go b/app/internal/window/egl_wayland.go index 0768a15c..aed283ee 100644 --- a/app/internal/window/egl_wayland.go +++ b/app/internal/window/egl_wayland.go @@ -9,7 +9,6 @@ import ( "unsafe" "gioui.org/app/internal/egl" - "gioui.org/app/internal/gl" ) /* @@ -27,7 +26,7 @@ type context struct { eglWin *C.struct_wl_egl_window } -func (w *window) NewContext() (gl.Context, error) { +func (w *window) NewContext() (Context, error) { disp := egl.NativeDisplayType(unsafe.Pointer(w.display())) ctx, err := egl.NewContext(disp) if err != nil { diff --git a/app/internal/window/egl_windows.go b/app/internal/window/egl_windows.go index d4ea94b4..38f88c5f 100644 --- a/app/internal/window/egl_windows.go +++ b/app/internal/window/egl_windows.go @@ -6,7 +6,6 @@ import ( "unsafe" "gioui.org/app/internal/egl" - "gioui.org/app/internal/gl" ) type context struct { @@ -14,7 +13,7 @@ type context struct { *egl.Context } -func (w *window) NewContext() (gl.Context, error) { +func (w *window) NewContext() (Context, error) { disp := egl.NativeDisplayType(unsafe.Pointer(w.HDC())) ctx, err := egl.NewContext(disp) if err != nil { diff --git a/app/internal/window/egl_x11.go b/app/internal/window/egl_x11.go index ac2360f8..c644ffea 100644 --- a/app/internal/window/egl_x11.go +++ b/app/internal/window/egl_x11.go @@ -8,7 +8,6 @@ import ( "unsafe" "gioui.org/app/internal/egl" - "gioui.org/app/internal/gl" ) type x11Context struct { @@ -16,7 +15,7 @@ type x11Context struct { *egl.Context } -func (w *x11Window) NewContext() (gl.Context, error) { +func (w *x11Window) NewContext() (Context, error) { disp := egl.NativeDisplayType(unsafe.Pointer(w.display())) ctx, err := egl.NewContext(disp) if err != nil { diff --git a/app/internal/window/gl_ios.go b/app/internal/window/gl_ios.go index c84de1d2..ef5c3b9b 100644 --- a/app/internal/window/gl_ios.go +++ b/app/internal/window/gl_ios.go @@ -121,6 +121,6 @@ func (c *context) MakeCurrent() error { return nil } -func (w *window) NewContext() (gl.Context, error) { +func (w *window) NewContext() (Context, error) { return newContext(w) } diff --git a/app/internal/window/gl_js.go b/app/internal/window/gl_js.go index 798ff4ae..45a47df5 100644 --- a/app/internal/window/gl_js.go +++ b/app/internal/window/gl_js.go @@ -90,6 +90,6 @@ func (c *context) MakeCurrent() error { return nil } -func (w *window) NewContext() (gl.Context, error) { +func (w *window) NewContext() (Context, error) { return newContext(w) } diff --git a/app/internal/window/gl_macos.go b/app/internal/window/gl_macos.go index 58194730..bf03befe 100644 --- a/app/internal/window/gl_macos.go +++ b/app/internal/window/gl_macos.go @@ -71,6 +71,6 @@ func (c *context) MakeCurrent() error { return nil } -func (w *window) NewContext() (gl.Context, error) { +func (w *window) NewContext() (Context, error) { return newContext(w) } diff --git a/app/internal/window/window.go b/app/internal/window/window.go index ab3321bb..5cca6bda 100644 --- a/app/internal/window/window.go +++ b/app/internal/window/window.go @@ -31,6 +31,15 @@ type Callbacks interface { Event(e event.Event) } +type Context interface { + Functions() *gl.Functions + Present() error + MakeCurrent() error + Release() + Lock() + Unlock() +} + // Driver is the interface for the platform implementation // of a window. type Driver interface { @@ -39,7 +48,7 @@ type Driver interface { SetAnimating(anim bool) // ShowTextInput updates the virtual keyboard state. ShowTextInput(show bool) - NewContext() (gl.Context, error) + NewContext() (Context, error) } type windowRendezvous struct { diff --git a/app/loop.go b/app/loop.go index 1dc81c05..175675a7 100644 --- a/app/loop.go +++ b/app/loop.go @@ -6,8 +6,8 @@ import ( "image" "runtime" - "gioui.org/app/internal/gl" "gioui.org/app/internal/gpu" + "gioui.org/app/internal/window" "gioui.org/op" ) @@ -36,7 +36,7 @@ type frameResult struct { err error } -func newLoop(ctx gl.Context) (*renderLoop, error) { +func newLoop(ctx window.Context) (*renderLoop, error) { l := &renderLoop{ frames: make(chan frame), results: make(chan frameResult), @@ -54,7 +54,7 @@ func newLoop(ctx gl.Context) (*renderLoop, error) { return l, nil } -func (l *renderLoop) renderLoop(glctx gl.Context) error { +func (l *renderLoop) renderLoop(glctx window.Context) error { // GL Operations must happen on a single OS thread, so // pass initialization result through a channel. initErr := make(chan error) diff --git a/app/window.go b/app/window.go index c5d173b4..751cee6e 100644 --- a/app/window.go +++ b/app/window.go @@ -8,7 +8,6 @@ import ( "image" "time" - "gioui.org/app/internal/gl" "gioui.org/app/internal/input" "gioui.org/app/internal/window" "gioui.org/io/event" @@ -285,7 +284,7 @@ func (w *Window) run(opts *window.Options) { w.loop = nil } } else { - var ctx gl.Context + var ctx window.Context ctx, err = w.driver.NewContext() if err == nil { w.loop, err = newLoop(ctx)