app/internal/egl: don't exit if EGL dlls fails to load

We want a useful error instead of a hard exit for headless windows.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-12-01 23:39:02 +01:00
parent 06a2228798
commit 9df3c76aa2
3 changed files with 31 additions and 9 deletions
+3
View File
@@ -87,6 +87,9 @@ func (c *Context) Present() error {
}
func NewContext(disp NativeDisplayType) (*Context, error) {
if err := loadEGL(); err != nil {
return nil, err
}
eglDisp := eglGetDisplay(disp)
if eglDisp == nilEGLDisplay {
return nil, fmt.Errorf("eglGetDisplay failed: 0x%x", eglGetError())
+4
View File
@@ -26,6 +26,10 @@ type (
NativeWindowType = C.EGLNativeWindowType
)
func loadEGL() error {
return nil
}
func eglChooseConfig(disp _EGLDisplay, attribs []_EGLint) (_EGLConfig, bool) {
var cfg C.EGLConfig
var ncfg C.EGLint
+24 -9
View File
@@ -3,8 +3,9 @@
package egl
import (
"os"
"fmt"
"runtime"
"sync"
"unsafe"
syscall "golang.org/x/sys/windows"
@@ -41,22 +42,36 @@ var (
_eglQueryString = libEGL.NewProc("eglQueryString")
)
func init() {
mustLoadDLL(libEGL, "libEGL.dll")
mustLoadDLL(gl.LibGLESv2, "libGLESv2.dll")
// d3dcompiler_47.dll is needed internally for shader compilation to function.
mustLoadDLL(syscall.NewLazyDLL("d3dcompiler_47.dll"), "d3dcompiler_47.dll")
var loadOnce sync.Once
func loadEGL() error {
var err error
loadOnce.Do(func() {
err = loadDLLs()
})
return err
}
func mustLoadDLL(dll *syscall.LazyDLL, name string) {
func loadDLLs() error {
if err := loadDLL(libEGL, "libEGL.dll"); err != nil {
return err
}
if err := loadDLL(gl.LibGLESv2, "libGLESv2.dll"); err != nil {
return err
}
// d3dcompiler_47.dll is needed internally for shader compilation to function.
return loadDLL(syscall.NewLazyDLL("d3dcompiler_47.dll"), "d3dcompiler_47.dll")
}
func loadDLL(dll *syscall.LazyDLL, name string) error {
loadErr := dll.Load()
if loadErr == nil {
return
return nil
}
pmsg := syscall.StringToUTF16Ptr("Failed to load " + name + ". Gio requires the ANGLE OpenGL ES driver to run. A prebuilt version can be downloaded from https://gioui.org/doc/install.")
ptitle := syscall.StringToUTF16Ptr("Error")
syscall.MessageBox(0 /* HWND */, pmsg, ptitle, syscall.MB_ICONERROR|syscall.MB_SYSTEMMODAL)
os.Exit(1)
return fmt.Errorf("egl: failed to load %s", name)
}
func eglChooseConfig(disp _EGLDisplay, attribs []_EGLint) (_EGLConfig, bool) {