app: merge app/internal/wm into package app

The app and app/internal/wm packages are tightly coupled, requiring
quite a bit of forwarding types, values and constants from the internal
package to export it. Further, no other package imports package wm.

This change merges the two packages.

While here, drop the pre-Go 1.14 SIGPIPE workaround.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2021-08-29 22:00:16 +02:00
parent fe52357141
commit 45da52cee7
46 changed files with 325 additions and 400 deletions
+69
View File
@@ -0,0 +1,69 @@
// SPDX-License-Identifier: Unlicense OR MIT
package app
import (
"errors"
"syscall/js"
"gioui.org/gpu"
"gioui.org/internal/gl"
)
type glContext struct {
ctx js.Value
cnv js.Value
}
func newContext(w *window) (*glContext, error) {
args := map[string]interface{}{
// Enable low latency rendering.
// See https://developers.google.com/web/updates/2019/05/desynchronized.
"desynchronized": true,
"preserveDrawingBuffer": true,
}
ctx := w.cnv.Call("getContext", "webgl2", args)
if ctx.IsNull() {
ctx = w.cnv.Call("getContext", "webgl", args)
}
if ctx.IsNull() {
return nil, errors.New("app: webgl is not supported")
}
c := &glContext{
ctx: ctx,
cnv: w.cnv,
}
return c, nil
}
func (c *glContext) RenderTarget() gpu.RenderTarget {
return gpu.OpenGLRenderTarget{}
}
func (c *glContext) API() gpu.API {
return gpu.OpenGL{Context: gl.Context(c.ctx)}
}
func (c *glContext) Release() {
}
func (c *glContext) Present() error {
if c.ctx.Call("isContextLost").Bool() {
return errors.New("context lost")
}
return nil
}
func (c *glContext) Lock() error {
return nil
}
func (c *glContext) Unlock() {}
func (c *glContext) Refresh() error {
return nil
}
func (w *window) NewContext() (context, error) {
return newContext(w)
}