Commit Graph

532 Commits

Author SHA1 Message Date
Pierre Curto ebb7f40e9d app: implement Window.Close for Wayland
This is a followup from a question sent to the mailing list.

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
2021-11-26 22:28:47 +01:00
Pierre Curto a699f771c6 app: add Maximize and Center methods support for macOS and X11
Commit 9835cd59 added support for the Window.Maximize and
Window.Center methods for Windows only.
This patch also adds support for macOS and X11.

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
2021-11-16 18:41:22 +01:00
Inkeliz f4c82adeff app/internal/windows: don't crash on app.Fullscreen on windows/386
Before this patch, use of `app.Fullscreen` would result in "Failed to
find SetWindowLongPtrW procedure in user32.dll" when running on 32 bit
Windows.

Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2021-11-16 16:31:13 +01:00
Inkeliz 40bc2e1f88 app: [iOS] implement ViewEvent
ViewEvent exposes native window handle for platform specific uses. This
change implements ViewEvent for iOS.

Fixes gio#305

Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2021-11-13 10:36:44 +01:00
Jan Kåre Vatne 9835cd5996 app: add Window.Maximize and Center, add Windows implementation
Signed-off-by: Jan Kare Vatne <jkvatne@online.no>
2021-11-10 17:03:23 +01:00
Elias Naur 1d0769ae89 app: use tabs consistently in GioView.java
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-11-03 14:12:31 +01:00
Dylan Staley 4d22a926a9 app: [android] handle touch events from stylus
Fixes gio#291

Signed-off-by: Dylan Staley <88163+dstaley@users.noreply.github.com>
2021-10-16 08:43:51 +02:00
Elias Naur ebad5afdf3 app: [Vulkan] don't exit early on VK_SUBOPTIMAL_KHR
The mapErr helper may map the error to nil, in which case the caller
should continue, not exit.

This change split up error mapping into mapErr which never maps to nil,
and mapSurfaceErr which handles the VK_KHR_swapchain errors and may map
to nil.

Maybe fixes gio#287

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-10-09 10:46:37 +02:00
Elias Naur d6e6ca848a app: don't miss driver defers
Fixes gio#281

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-30 18:21:18 +02:00
Elias Naur 6c1f9c19f5 app,internal/vk: [Vulkan] skip frame with stale window dimensions
While here, add a missing nil check.

Updates gio#280

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-30 17:46:23 +02:00
Elias Naur 868ea76acf app: [X11] avoid deadlock when sending initial ConfigEvent
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-24 12:48:10 +02:00
Elias Naur bdafb3564f gpu,app: [Metal] don't store CFTypeRef values in pointer types
CFTypeRefs may not always contain valid pointers, so they must not be
stored in pointer types lest the Go runtime treats them as such.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-23 15:32:58 +02:00
Elias Naur 8c6e3c5fdf app: [Metal] don't wait for completion of presentation command
There's no need to wait; the Metal backend performs the required
synchronization.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-23 15:26:56 +02:00
Elias Naur 94f7fa3218 app: [Vulkan] keep VkSurfaceKHR ownership to platforms
Before this change, it was unclear who owned the platform specific
VkSurfaceKHR object, leading to a double-free in the error path for
devices with no Vulkan support. This change moves the ownership to the
platform specific code.

Add vk.EnumeratePhysicalDevices while here (refactor was part of
debugging of the double-free).

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-23 12:35:26 +02:00
Elias Naur 6665e0ef0f app: [Windows] don't redraw zero-sized windows
Fixes gio#270

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-22 18:55:22 +02:00
Elias Naur 8999747ad2 app,gpu,internal/vk: add Vulkan port for Wayland, X11, Android
This change implements a Vulkan port for the two renderers, old and
compute. Run with GIORENDERER=forcecompute to test the compute renderer.

To shake out bugs faster, it is also made the default on systems that
support it. To disable Vulkan and force the use of OpenGL, use the
`novulkan` tag:

$ go run -tags novulkan gioui.org/example/kitchen

Don't forget to file an issue describing the issue that prompted the use
of the tag.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-21 18:40:05 +02:00
Elias Naur bdd0893dd0 app,gpu: move errDeviceLost from package app to package gpu
The Vulkan backend can return device lost error from more than just
Present.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-21 17:53:58 +02:00
Elias Naur af6770de18 app: add error result to context.RenderTarget
Vulkan may report VK_ERROR_OUT_OF_DATE_KHR which is not a fatal error.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-20 15:13:00 +02:00
Elias Naur 18c2ba8e20 app: replace Window.Config with ConfigEvent
Unlike Raise, Close and other fire-and-forget methods on Window,
Config calls driverRun because it needs to wait for the result.
However, driverRun isn't guaranteed to block in all contexts.

This change avoids the synchronization dance altogether by removing the
Config method and introducing a ConfigEvent event. The event also makes
it clear when the configuration changes.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-20 08:18:03 +02:00
Elias Naur d1b35bf1d7 app: [macOS] trigger redraw on resize for context-less windows
Switching to using a CAMetalLayer as the layer backing our NSView
implementation broke programs such as the opengl example. Somehow, using
ANGLE on top of a CAMetalLayer (but not a CAEAGLLayer) stops resizes
from triggering redraws.

This change invalidates the view in setFrameSize, to force a redraw
and no longer rely on the implicit redraws.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-19 09:16:11 +02:00
Elias Naur c9d85c97e1 app: process driver funcs before queueing more
Window.driverFunc says it can be run from any context. However, running
it from the Window.run event loop may deadlock, at least until an
unrelated event arrives from the driver (e.g. a mouse move).

Example:
Window.Invalidate is called, which caused Window.run to queue a driver
func, and notify the Window.wakeups channel. However, another
Window.Invalidate arrives just in time for Window.run to process that
before Window.wakeups, leading to a deadlock because only one driver
func can be queued.

This change fixes the problem by processing wakeups before potentially
queueing more driver functions.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-16 10:49:42 +02:00
Elias Naur f896a72ea1 app,gpu/internal/opengl: move glFlush to macOS context present
A previous change[0] moved all OpenGL function calls to the internal
opengl package, so that Gio can use desktop OpenGL and OpenGL ES (ANGLE)
in the same program without confusing the function pointers.

However the change also moved the glFlush that constitutes a buffer
swap, or present, on macOS. Other platforms don't need the flush, so
this change moves it back to macOS-specific code, in glContext.Present
where it belongs. It also uses dlopen and dlsym to avoid symbol
confusion between Apple's OpenGL framework and ANGLE's libGLESv2.dylib.

The motivation is that we're getting rid of the desktop OpenGL backend
on macOS in favor of Metal, and so should reduce the number of global
special-cases catering to that platform.

[0] https://gioui.org/commit/476d2269a

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-15 21:12:29 +02:00
Elias Naur d5d0a75a9b app: fix build on FreeBSD
Somehow, the explicit include and library directories needed for OpenBSD
are required for FreeBSD as well.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-10 08:24:18 +02:00
Pierre Curto e92ca233f5 app: ignore app.Size when in fullscreen mode
Setting the window size while in fulscreen mode does not make sense.

Fixes gio#220

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
2021-09-09 16:24:23 +02:00
Pierre Curto 2f66ed1dc8 app: add Window.Raise to bring a window to the front
Fixes gio#252

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
2021-09-09 07:46:09 +02:00
Elias Naur c5d4e01e3d app: [X11] honour _NET_WM_STATE protocol
The _NET_WM_STATE protocol description[0] states that to change the
window mode for an X11,

"To change the state of a mapped window, a Client MUST send a
_NET_WM_STATE client message to the root window."

and that the window manager in turn

"The Window Manager MUST keep this property updated to reflect the
current state of the window."

However, our X11 implementation did both: send the message _and_ set or
deleted the property.

This change makes it so only the message is sent. It also replaces
toggling the property by setting or clearing, to ensure our mode and the
window manager's mode never gets out of sync.

Maybe fixes gio#265

[0] https://specifications.freedesktop.org/wm-spec/wm-spec-latest.html#idm46515148826720

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-08 13:25:17 +02:00
Pierre Curto b3751dd9ab app: fix invalid NewWindow config on X11
Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
2021-09-08 08:20:39 +02:00
Pierre Curto bdc2f3f4e8 app: add Window.Config, export app.Config
A Window configuration with its current option values can now be fetched during a FrameEvent.

The WindowMode and Orientation options have moved to methods on their corresponding types.

Fixes #260

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
2021-09-07 08:06:56 +02:00
Elias Naur 74464f64dc app: use driver defer mechanism for changing animation flag
Now that Window.driverDefer can be run in any context, the special case
of setting the animation flag can use that mechanism instead of a
special purpose channel.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-05 13:58:19 +02:00
Elias Naur 9ffe43bc3a app: delete workarounds for driver callback deadlocks
Driver methods are invoked during event processing, but some of them may
generate events that would in turn deadlock because event processing is
not re-entrant. However, a previous change moved all such calls outside
event processing and so chained events can no longer deadlock.

This change deletes the workarounds.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-05 09:30:47 +02:00
Elias Naur 1796f24a38 app: introduce Window.driverDefer for blocking functions
Window.driverRun is designed to run functions on the driver event
goroutine, to avoid race conditions with internal driver state and,
more importantly, to run on the designated main or UI thread for
platforms that require that.

However, driverRun runs functions during the processing of a driver
event, so if a function in turn triggers another driver event,
deadlock occurs.

This change introduces Window.driverDefer for functions that don't need
to block event processing. Functions passed to driverDefer may
themselves trigger new events.

A few callers of driverRun remain; they need the result of their
functions but are guaranteed not to trigger new events.

Fixes gio#263

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-05 09:27:50 +02:00
Felix Lange 23f6dcb868 app: [Android] simplify invalidate in onFrameCallback
Since onFrameCallback runs on the app UI thread, using plain
invalidate() can be used instead of postInvalidate(). The latter just
schedules a call to invalidate() on the UI thread.

Also, since onFrameCallback is directly called by JNI, there is no need
to set up a new JNI environment to call back into Java.

Signed-off-by: Felix Lange <fjl@twurst.com>
2021-09-04 07:26:47 +02:00
Elias Naur d03f618660 app: [Windows] avoid deadlock when changing window configuration
Some window configurations lead to WM_SIZE messages when changed, which
leads to deadlock because our window proc is not re-entrant. Avoid the
issues by ignoring redundant messages.

Fixes gio#262

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-03 12:11:55 +02:00
Elias Naur 12aa9defe7 app: fix build constraints for nowayland,nox11 on OpenBSD, FreeBSD
While here, add new-style //go:build constraints to generated wayland
glue files.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-08-30 15:28:44 +02:00
Elias Naur 4f198b3f87 app: render on event loop thread
Before this change, the renderLoop type implemented a rendering
goroutine for rendering off the event thread. However, it's not worth
the complexity, so remove it and render on the event thread.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-08-29 22:00:24 +02:00
Elias Naur fd008f39af app: [Android] work around broken EGL surfaces on the emulator
The Android emulator creates a broken EGL surface if it is not created
on the same thread as the context is made current.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-08-29 22:00:24 +02:00
Elias Naur 07e1df3676 app: [Android] detach previous View when another is created
The Android system can in some cases replace the GioView of our Android
Activity before destroying the previous one. This change makes sure the
previous view is ignored, in particular its destroy event.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-08-29 22:00:24 +02:00
Elias Naur b86928ceec app: [Android] use simpler postInvalidate instead of Choreographer
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-08-29 22:00:24 +02:00
Elias Naur 45da52cee7 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>
2021-08-29 22:00:16 +02:00
Pierre Curto 8aac73458a app: set the type of the orientation and Windowed/Fullscreen options
Those variables didn't make it clear that they were Options.

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
2021-08-29 08:54:40 +02:00
Pierre Curto 4c2087d375 app: update comments for Options
Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
2021-08-29 08:53:52 +02:00
Elias Naur baa98e7737 app/internal/wm: [macOS] avoid crash in window.Wakeup
window.Wakeup assumes the window.w field is never reset to nil. Avoid
doing that in gio_onClose.

While here, ensure a valid window handle in window.Close by calling
the checked window.runOnMain method, not the bare runOnMain function.

Fixes gio#258

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-08-27 06:01:21 +02:00
Elias Naur 414be0a0b3 gpu: Merge GPU.Collect and GPU.Frame
There's no meaningful reason to have them separate. The intention was to
enable rendering concurrent with other processing, but that's gaining
framerate at the expense of input latency and complicating ImageOp
semantics.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-08-24 08:30:52 +02:00
Elias Naur a4a2d517e7 app/internal/wm: [Metal] don't limit CAMetalDrawable count
We shouldn't need more than 2 drawables, but changing the count from the
default of 3 introduces framerate lags in fullscreen mode.

This changes leaves the drawable count alone. No good deed goes
unpunished.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-08-22 10:48:55 +02:00
Elias Naur 3b2992c37e gpu,app/internal/wm: add Metal port
The OpenGL (ES) implementations on Apple platforms are deprecated and
don't support GPU compute programs. This change adds support for the
replacement, the Metal GPU API.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-08-21 08:31:46 +02:00
Chris Waldon ae3103e180 app/internal/wm: implement ViewEvent for X11
Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2021-08-20 06:59:17 +02:00
Elias Naur 71f834d26f app/internal/wm: remove superfluous main thread switching
The affected code paths are guaranteed to be run on the main thread by
the app.Window callers.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-08-16 15:45:46 +02:00
Elias Naur 23640ec38f app,app/internal/wm: create contexts on the main thread
Instead of handing the internal/wm driver a method to run code on the
(blocked) main thread, just run the necessary driver methods on the main
thread.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-08-12 15:21:37 +02:00
Elias Naur 811e2b53e0 app: ensure context is nil after release
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-08-11 16:49:37 +02:00
Elias Naur 06556986c5 app/internal/wm: remove gio_ prefixes from static (local) C functions
Static C functions don't pollute the global namespace.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-08-08 15:36:49 +02:00