Commit Graph

152 Commits

Author SHA1 Message Date
Elias Naur 533bf953f9 app/internal/cocoainit: enable multithread support in Cocoa
According to

https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Multithreading/CreatingThreads/CreatingThreads.html#//apple_ref/doc/uid/20000738-125024

Cocoa is by default not multithread-safe for programs that use the posix
api for creating threads:

"
For multithreaded applications, Cocoa frameworks use locks and other
forms of internal synchronization to ensure they behave correctly. To
prevent these locks from degrading performance in the single-threaded
case, however, Cocoa does not create them until the application spawns
its first new thread using the NSThread class. If you spawn threads
using only POSIX thread routines, Cocoa does not receive the
notifications it needs to know that your application is now
multithreaded. When that happens, operations involving the Cocoa
frameworks may destabilize or crash your application.
"

That includes Go programs.

The fix, as discovered by Steeve Morin, is to create and launch
an empty NSThread.

Add a package that does that, and use it everywhere Cocoa is used.

Sigh.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-04-23 21:13:19 +02:00
Elias Naur 02d4316c56 gpu: reset to the default framebuffer on reset
The macOS backend doesn't re-create contexts, holding on to the first
created instead. Make sure the GPU leaves the default framebuffer bound,
in case the context is re-used.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-04-23 00:27:04 +02:00
Elias Naur aefc6f3625 app/internal/window: [Android] use correct JNI Call variant for registerFragment
While we're here,

- replace the registerFragment trampoline with a general variadic
CallVoidMethod trampoline.
- Use UTF-16 for passing strings to Java. Java's modified UTF-8 encoding differ
from Go's in corner cases.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-04-20 20:54:50 +02:00
Elias Naur ae77377f7b app: [Android] replace PlatformHandle with JavaVM, AppContext methods
Clearer and fewer types.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-04-20 20:21:39 +02:00
Elias Naur 30b46ded6b internal/window: [Android] remove unused C function
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-04-20 19:11:04 +02:00
Elias Naur 1ad891ff67 app/internal: fix Android build
pkg-config doesn't exist for Android.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-04-01 13:04:40 +02:00
Elias Naur 38ed6d1569 app/internal: use pkg-config for finding system headers and libraries
I've resisted relying on pkg-config in the hope that hard-coded include and
library paths would suffice. However, apart from having to work around some
distro-specific differences, building with hardcoded include paths fails when
building on a buildroot:

	x86_64-buildroot-linux-gnu-gcc: ERROR: unsafe header/library path used in cross-compilation: '-I/usr/include/wayland'

(see #91)

Andri mentions a workaround (prefixing paths with "="), but that doesn't seem
to work on the BSDs.

Let's see how pkg-config fares. It's an extra dependency, but it promises to keep
us isolated from the varying paths on Linux distrobutions.

Updates #91

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-03-23 12:03:38 +01:00
Elias Naur a3101c9454 app/internal/window,app/internal/egl: avoid X11 dependency in EGL
EGL is window system agnostic, but its egl.h header includex X11
headers by default. Use the MESA_EGL_NO_X11_HEADERS define to avoid
it, fixing the "nox11" build for systems without X11 headers installed.

Fixes #91

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-03-20 20:58:17 +01:00
Egon Elbre acd32c31a2 app/internal/d3d11: enable VSync
Signed-off-by: Egon Elbre <egonelbre@gmail.com>
2020-03-15 20:58:30 +01:00
Elias Naur 7fba3bb8fe gpu/backend: remove clear color and depth state
Specifying the clear color and depth at the time of clearing is
less error prone and a better for modern GPU APIs. As a bonus, we
can get rid of the BufferAttachment type.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-03-15 12:25:56 +01:00
Egon Elbre 7c1a21ce56 add f32color.RGBA
Signed-off-by: Egon Elbre <egonelbre@gmail.com>
2020-03-12 13:21:34 +01:00
Elias Naur 7024a0e691 gpu: fix depth buffer on direct3d and headless opengl
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-03-11 17:45:16 +01:00
Elias Naur bd7c7a108a app/internal/window: (Windows) don't send zero-sized draw requests
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-29 16:15:55 +01:00
Elias Naur 22e15da67c app/internal/window: (Windows) return all errors from NewContext
Instead of just returning the first error (from Direct3D), return
the errors from all attempts.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-29 15:39:04 +01:00
Elias Naur 0ceccf3c93 app/internal/d3d11: try more floating point formats
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-29 13:01:48 +01:00
Elias Naur b3a3c34088 app/internal/d3d11: detect hardware floating point support
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-29 10:52:04 +01:00
Elias Naur 1d3a9fb2d6 internal/cmd/convertshaders: replace fxc.exe with D3DCompile
D3DCompile successfully compiles shaders fxc.exe doesn't. As a bonus
the DirectX SDK is no longer required (it includes fxc.exe).

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-28 15:14:54 +01:00
Elias Naur a448825d48 app/internal/d3d11: only clear depth buffer if it exists
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-28 14:50:39 +00:00
Elias Naur 73fc5e1482 app/internal/d3d11: return structured ErrorCode errors from d3d functions
While here, change the ErrorCode.Code field type to uint32 to better reflect
its native counterpart.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-28 13:49:56 +01:00
Elias Naur 2fd7e2dd9b app/internal/d3d11: fix GOOS=windows GOARCH=386 build
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-28 09:58:23 +01:00
Elias Naur bfb50cef5d all: remove unused fields, functions and add missing error handling
Credit to staticcheck.io.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 22:26:54 +01:00
Elias Naur e03b3cd808 app/internal/d3d11: add Direct3D backend
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 21:41:35 +01:00
Elias Naur 6213daa3e9 app: recover from transient Present errors
Some GPU APIs such as Direct3D can return an error after drawing
a frame indicating a transient device error. Recreate device and
retry if it happens.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 21:22:59 +01:00
Elias Naur 0d266c413d gpu,gpu/backend: implement GLSL 300 es shader variants
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 20:34:58 +01:00
Elias Naur 3a5a2cff6b app/internal/glimpl: add gl functions for uniform buffers
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 20:34:37 +01:00
Elias Naur 5cd5d49108 gpu/backend: move backend interface types to a separate package
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 20:34:22 +01:00
Elias Naur 1f43bfa0e4 app/internal/egl: remove Windows error message dialog when EGL fails to load
The error message is not appropriate where there are multiple backends,
and there's a much better chance Gio will run with the direct3d backend
where no external DLLs are required.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 20:34:22 +01:00
Elias Naur cf7d702a39 app/internal/window: remove unsafe cast
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 20:34:22 +01:00
Elias Naur 05485a79a6 app/internal/srgb: rename NewSRGBFBO to New and SRGBFBO to FBO
The srgb package was recently created to contain just the sRGB
emulation, but the names weren't shortened accordingly.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 20:34:22 +01:00
Elias Naur 94fdc26cb5 app,app/headless: expose Backends from window and headless contexts
This is a refactoring change to prepare for another gpu.Backend
implementations.

Notably, app/loop.go no longer imports gpu/gl.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 20:34:21 +01:00
Elias Naur e3f8d1a1af app/internal/window: (Windows) report pressed buttons for Move events
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-26 10:57:30 +01:00
Roy Lee ae6161dfb6 app/internal/wayland: Added header dir for wayland in openSUSE
Added a cflag -I to provide wayland header files in openSUSE.

Fixes gio#76

Signed-off-by: Roy Lee <royyhlee@gmail.com>
2020-02-16 21:44:29 +01:00
Elias Naur adb950cbf3 app/internal/srgb: move sRGB emulation to new internal package
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-10 18:22:58 +01:00
Elias Naur 3ae5a37c24 gpu,gpu/gl: introduce Backend
A recent change made the OpenGL functions an interface of the functions
required for the implementation of GPU, a renderer for Gio operations.
That allowed for running Gio on external systems where OpenGL is
available.

However, to allow for non-OpenGL flavored backends such as Vulkan,
Metal and Direct3D, this change introduces Backend for the high-level
operations required by GPU. This change also adds a concrete backend
to package gl.

Type Backend is a first cut heavily based on OpenGL. Future changes will add
more backends, where the Backend interface quite possibly will need refinement.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-10 18:22:57 +01:00
Elias Naur 1f422ef960 all: gofmt
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-08 00:04:15 +01:00
Elias Naur 3b6646933d gpu: expose the rendering implementation
The rendering implementation is needed for using Gio UI with external
window libraries such as GLFW. Expose it in the new package gpu.

Updates #26

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-07 21:21:38 +01:00
Elias Naur 34c6a2f735 io/router: expose the event router
For integrating with external window implementations (replacing
package app), access to the event router is required. Extract it
and put it into the new package router.

Router may belong in package io/event, but can't without introducing
import cycles.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-07 20:41:04 +01:00
Elias Naur 6e98132ebb app/internal/gpu: extract profile in separate method, Profile
Updates #26

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-07 20:08:50 +01:00
Elias Naur 81f958fc70 app/internal/gpu: remove profile flag
Automatically determine whether to profile GPU operations from
the existence of a profiling op.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-07 20:00:52 +01:00
Elias Naur 320535a978 app/internal/input: remove AddProfile method
Merge it into the general Add method.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-07 19:41:39 +01:00
Elias Naur 251c075093 app/internal/gl/impl: extract platform dependent opengl bindings
We'd like to support Gio using a different renderer binding than
the builtin. A first step is to define the Functions interface
in package gl, and extract the concrete implementations to a
separate package.

Updates #26

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-07 19:22:30 +01:00
Greg Pomerantz 72cb36c5f9 app/internal/gpu: make the zero value of paint.ImageOp useful
Do not panic when drawing the zero value of paint.ImageOp.

Signed-off-by: Greg Pomerantz <gmp.gio@wow.st>
2020-01-29 15:58:45 +01:00
Daniel Martí 54ed198cb0 app: don't discard android touch events of unknown tool type
This is the kind of event one gets when using 'adb shell input tap x y',
which I am trying to use for the end-to-end tests.

Right now, we only have two pointer source types: mouse and touch.
On Android, emulated touch events tend to simulate the touchscreen, not
a mouse, so let's go with that as a fallback.

Perhaps in the future we will have another special pointer source for
this kind of event, such as "unknown" or "virtual".

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
2020-01-27 11:17:47 +01:00
Aaron Bieber fdaf891732 app: Enable building on OpenBSD
Currently the golang.org/x/sys package is missing the Pipe2 call for OpenBSD.
The call exists on OpenBSD, it just isn't exposed.

This diff was tested buy adding the Pipe2 call and setting:

   go mod edit -replace=golang.org/x/sys=/pat/to/modified/sys

Signed-off-by: Aaron Bieber <aaron@bolddaemon.com>
2020-01-24 14:32:54 +01:00
mural a7dc7c01c0 app/internal/log: add logger for Windows DebugView
Signed-off-by: mural <mural@ctli.io>
2020-01-13 21:48:13 +01:00
Elias Naur f176cbfe88 app/internal/egl: try EGL_DEFAULT_DISPLAY is eglGetDisplay fails
Fixes #77

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-01-11 23:21:27 +01:00
Elias Naur bc30683588 Revert "app/internal/egl: accept zero EGLDisplay values as valid"
This reverts commit 66138e7890.

Reason: According to #77, it didn't work and the proposed fix
(retry when EGL_NO_DISPLAY is returned) is correct.
2020-01-11 23:15:23 +01:00
Elias Naur 66138e7890 app/internal/egl: accept zero EGLDisplay values as valid
Issue #77 seems to be caused by eglGetDisplay returning a zero
EGLDisplay, yet eglGetError returns EGL_SUCCESS. Since EGLDisplay
is not necessary a pointer type, the zero value may be valid.

Updates #77

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-01-08 13:28:12 +01:00
Elias Naur 95903aafda app/internal/window: add errno to wl_display_connect errors
Updates #40

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-01-03 11:28:53 +01:00
Elias Naur 9114dbe759 app/internal/gl: gofmt -w -s
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-12-12 00:45:36 +01:00