Commit Graph

214 Commits

Author SHA1 Message Date
Elias Naur db0af521d0 app/internal/window: move Wayland callback structs into function scope
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-15 12:14:17 +02:00
Elias Naur f16e8fd122 app: update package documentation
Reflect the move of Queue from Window to FrameEvent.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-14 10:11:18 +02:00
Elias Naur 2e25a28a54 app: fix typo in Main documentation
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-14 10:08:28 +02:00
Elias Naur 05dfceb7e7 app/clipboard: implement clipboard for Android
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-13 17:14:58 +02:00
Elias Naur a6dd70b2dc app: add license header to app_android.go
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-13 15:18:07 +02:00
Wagner Riffel 4bbc6379ed doc: rewrite references to preivous api to current
Signed-off-by: Wagner Riffel <wgrriffel@gmail.com>
2020-05-13 12:59:33 +02:00
Elias Naur 630e0b494d app/internal/windows: remove extra empty line
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-07 16:03:22 +02:00
Elias Naur 3957be37c8 app: [Android] tweak environment for os.UserHomeDir and os.UserConfigDir
Set the fallback environment variables XDG_CONFIG_HOME and HOME to
make os.UserConfigDir and os.UserHomeDir report useful paths.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-06 16:54:55 +02:00
Elias Naur 2395659be3 app: [Android] set XDG_CACHE_HOME to make os.UserCacheDir work
os.UserCacheDir can't work on Android because it doesn't have
access to the Java app context. Gio programs do have access, so set
up UserCacheDir's fallback, the XDG_CACHE_HOME environment variable.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-06 16:39:21 +02:00
Daniel Martí e97adeedd9 app/internal/log: use the app ID as the Android log tag
This way, a Gio app's logs can be filtered uniquely, which wasn't
possible before since the tag "gio" would be the same between gio apps.

Since the app ID is supplied at build time, inject it via a variable
with the linker's help. The variable is only used on Android for now,
but that's OK. It might be useful for other platforms or other internal
packages in the future.

Fixes #84.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
2020-05-06 08:41:04 +02:00
Elias Naur 33493501a6 app/internal/headless: [Android] expose Java initialization method
Android apps may want to run Go code independent of the Gio Android Activity.
Expose a Gio.init Java method public for early loading and initialization of
the Go library.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-05 19:22:11 +02:00
Elias Naur cde651db60 app/internal/window: [Android] remove JNI_OnLoad JNI callback
There can only be one JNI_OnLoad callback per JNI library, and the
Gio program may need it for its own purposes.

Gio only used JNI_OnLoad for explicitly registering native methods. Switch
to implicit name based registration and get rid of JNI_OnLoad.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-05 19:01:12 +02:00
Elias Naur 0c0a22bee7 app/internal/window: don't rely on JNI_OnCreate for getting the JavaVM
We're about to remove the global JNI_OnLoad constructor, and the
JavaVM singleton is just as easily fetched from a Java JNI callback.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-05 18:55:14 +02:00
Elias Naur c7c5b87264 app/internal/window: remove unused #includes
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-05 18:29:25 +02:00
Elias Naur 7301ebe0ef app/internal/window: removed unused function
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-05 18:23:31 +02:00
Elias Naur 8d9612f9aa layout,app,io/system: move Queue from app.Window to FrameEvent
Change gioui.org/commit/0e70fbc1262920a69c60409285795b6bb8701b09
added a note that app.Window.Queue must only be used during the
processing of a FrameEvent. The change was added because a Gio
user took the existence of app.Window.Queue to mean it was always
available.

This change reduces the scope of window Queues by moving it from Window
to FrameEvent, and minimizes the risk of misuse by not offering
Window.Queue at all.

Note that the gioui.org/commit/a937a7653439333b8c6fc30c7a6039b717339766
change moved Window's Frame method (named Update) to FrameEvent for the
same reason.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-03 21:04:52 +02:00
Elias Naur 0e70fbc126 app: add note about the safe use of Window.Queue.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-04-29 10:22:02 +02:00
Elias Naur 4bde9fbcaa app/internal/log: add synchronized logger on Android
By default, the standard library log package outputs to stderr.
However, stderr is redirected through a pipe to the Android logger,
so recent writes may be not have been sent when os.Exit is called.

The log.Fatal family of functions does just that: write to the log
and call os.Exit.

To ensure all messages are sent, register a synchronized logger at
startup.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-04-29 10:03:07 +02:00
Elias Naur 51e4df7707 app/internal/log: fix typo
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-04-29 09:08:11 +02:00
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 10f932137c app: fix NewWindow comment
Window options are a list now, not a struct.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-04-20 20:08:01 +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 61529c2cb6 gpu: fix clip intersection with the D3D backend
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-03-11 16:23:35 +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 b194a0ce58 internal/cmd/convertshaders: target 9.1 compatibility shader model
Direct3D 11 supports Direct3D 9.1 level hardware, but only if the shaders are
compiled for target 4_0_level_9_1.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-28 15:22:58 +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 d65bfdc275 internal/cmd/convertshaders: use gofmt to format output
In particular, the simplifying "-s" flag to gofmt ensures that the automatic
test for unformatted Go source files won't complain.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 21:41:31 +01:00
Elias Naur 3043c4243a gpu/backend: add support for GLSL 1.50
Apple's OpenGL 3.2 Core implementation doesn't accept 1.30.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 21:22:59 +01:00
Elias Naur dd6a247326 gpu/backend: add support for desktop OpenGL 3
In particular, add the GLSL 1.30 shader variant. Sigh.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 21:22:59 +01:00
Elias Naur a0c4688d0c app/headless,gpu/gl: make ReadPixels y-flipping backend specific
The Direct3D backend doesn't need y-flipping, so don't do it unconditionally in
package app/headless.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 21:22:59 +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 7ff2f60412 app/headless: add lower-level backend tests
Add a series of low level gpu.Backend tests to assure the correct behaviour of
Backends. The immediate use is debugging of the Direct3D port, in the future
for developing new backends.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 21:22:59 +01:00