Commit Graph

238 Commits

Author SHA1 Message Date
Elias Naur 65d79f295f app/internal/app: introduce runOnMain for main thread callbacks
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-17 15:43:12 +02:00
Elias Naur a3dc2d6cdc app/internal/window: [macOS] run most callbacks on the main thread
Before this change, we had a viewDo that serialized a function on a view
on a single goroutine. For better or worse, most callbacks in Cocoa
happen on the main thread, so we might as well use that.

The only exception is the frame callback from the CADisplayLink.
We could force that through the main thread as well, but for
efficiency settle with making the view-to-window map synchronized.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-17 15:43:12 +02:00
Elias Naur 3569b0f31b app/internal/window: [macOS] assume valid view in synchronous draws
Asynchronous drawing happens only in onFrameCallback, where we have to
check for disappearing views. onDraw however, is synchronous and should
always have a valid view.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-17 15:43:12 +02:00
Elias Naur bd8757e51f app/internal/window: [X11] make the notification pipe wakeup only
Before, the wakeup pipe both woke the event loop and implied a redraw.
We're going to use the notication for more, so deduce the need for redraw
from window state instead.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-17 15:43:12 +02:00
Elias Naur 4e3bc8f9aa app/clipboard: delete
The implementation was too optimistic: some platforms require a
window context for accessing the clipboard.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-17 15:43:12 +02:00
Elias Naur 53e3f0027c app: ignore incoming window events to dead windows
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-16 12:41:41 +02:00
Elias Naur e093ea28f7 app: ensure waiting window requests are stopped when a window closes
The Android RegisterFragment method would leak a goroutine if called
after the window was destroyed.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-16 12:41:41 +02:00
Elias Naur b99151c211 app/internal/window: [Wayland] make notifications wakeup-only
Before, notifying the event loop implied a redraw. Derive the need
for redrawing expliticly and use the notification pipe for wakeups
only.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-16 12:09:18 +02:00
Elias Naur 9259b8f743 app/internal/window: [Wayland] move window-specific resource checks to window
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-16 11:01:19 +02:00
Elias Naur 44aec72d42 app/internal/window: [Wayland] move cursor from display to window
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-16 11:01:19 +02:00
Elias Naur 9daf082d22 app/internal/window: defer window and display destructors
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-16 11:01:19 +02:00
Elias Naur 728c20ab4a app/internal/window: [Wayland] move event processing to wlDisplay
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-16 11:01:19 +02:00
Elias Naur 26641344bc app/internal/window: [Wayland] move notification channel to wlDisplay
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-16 11:01:19 +02:00
Elias Naur 55881fc09c app/internal/window: [Wayland] remove redundant event dispatch
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-16 11:01:19 +02:00
Elias Naur 28a3de6e32 app/internal/window: [Wayland] delete unused field
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-16 11:01:19 +02:00
Elias Naur 0181f22d01 app/internal/window: block Main until all windows are closed
With this change, the Wayland backend now supports multiple windows.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-16 11:01:19 +02:00
Elias Naur cf72e684b6 app/internal/window: use a sync.Map for callback references
Multiple Wayland windows are now separate, except for the global callback
reference map. Use a sync.Map to support multiple concurrent windows.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-16 11:01:19 +02:00
Elias Naur 0aa7d4ab3f app/internal/window: [Wayland] move outputMap and outputConfig to wlDisplay
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-16 11:01:19 +02:00
Elias Naur 1a48b5c33c app/internal/window: [Wayland] use a single callback entry for each object
The callbackMap is used to look up Go references in event callbacks. Instead
of registering one entry for each possible callback type, use a single
handle for each Go reference.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-16 11:01:19 +02:00
Elias Naur bf129ca989 app/internal/window: get rid of the global Wayland display
Instead, create a display for each window.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-16 11:01:19 +02:00
Elias Naur 3e648715db app/internal/window: rename wlConn to wlDisplay
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-16 11:01:19 +02:00
Elias Naur bc645c3ca4 app/internal/window: [Wayland] introduce wlSeat for seat-specific state
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-16 11:01:19 +02:00
Elias Naur fd6f6c4485 app: move GPU context validation and retry logic to separate method
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-16 11:01:19 +02:00
Elias Naur 56dbaf326a app: move frame waiting code out of Window.run to a separate method
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-16 11:01:19 +02:00
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