Commit Graph

496 Commits

Author SHA1 Message Date
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
Elias Naur 18b4442393 all: remove Z buffer support
It is no longer needed by any rendering backend.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-08-08 13:47:37 +01:00
Elias Naur 2059862416 all: merge .m files with their .go counterparts
The only reason for separate files is Objective-C callbacks into Go,
or when the Go side is common, yet the Objective-C side differs from
macOS to iOS.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-08-08 13:46:16 +01:00
Elias Naur 7d84e419c9 gpu,gpu/headless,app/internal/wm: add explicit RenderTarget API
Both the OpenGL and the Direct3D API are stateful and gpu.GPU renders to
the render target current when Frame is called.

Modern GPU API such as Metal don't have a concept of a current render
target, and the target even changes each frame.

Add RenderTarget and add an explicit target argument to GPU.Frame as
well as the underlying driver.Device.BeginFrame.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-08-08 13:45:23 +01:00
Elias Naur 0bdc2e0432 app,app/internal/wm: fold context MakeCurrent/ReleaseCurrent into Lock/Unlock
While here, make context Refresh useful and remove the redundant
MakeCurrent from the window loop.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-08-08 13:53:19 +02:00
Elias Naur 7da315eb2b app,app/internal/wm: release OpenGL context after use
Otherwise, making a context current on another thread may result in
an EGL_BAD_ACCESS error.

Fixes gio#248

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-07-27 09:42:34 +02:00
Elias Naur 060ae1cdf9 all: add //go:build lines
They're automatically added by Go 1.17 source formatters. This change
adds them all now.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-07-26 15:17:51 +02:00
Elias Naur ca5a05bb35 internal/d3d11,app/internal/wm: add Direct3D11 leak reporting
Updates gio#245

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-07-18 17:57:38 +01:00
Elias Naur 13d7a8d760 app: don't release GPU context when minimized
Releasing the renderer is fine, but releasing the underlying context
introduces flicker when restoring a Gio window on macOS.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-07-15 16:15:47 +02:00
Inkeliz ca722508ce app/internal/wm: refactor Samsung keyboard fix
Move the code from Java to Go.

Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2021-07-12 08:43:07 +02:00
Inkeliz 5b8da35a79 app/internal/wm: [android] fix Samsung keyboard
That change makes the Samsung Keyboard compatible with Gio, with minimal
changes.

Fixes gio#116

Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2021-06-23 11:19:00 +02:00
Elias Naur 9df56f44e9 app: avoid deadlock on context refresh
The platform GPU context must be Refreshed on the window event thread,
but our rendering loop must not, because it may also want access to the
window event thread.

Fixes gio#236

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-06-22 19:35:00 +02:00
Elias Naur f24232dac5 app/internal/wm: [X11] ignore zero-sized FrameEvents
Updates gio#235

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-06-16 12:01:42 +02:00
Elias Naur 3fc8f55350 app/internal/wm: [macOS] close display link after window close
The app.Window owner may run SetAnimating just before window close,
which in turn rely on an active display link. This change makes sure
the link is stopped after window close where no more driver calls
can occur.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-06-14 23:29:58 +02:00
Elias Naur 4c8aa4c3ca app/internal/wm: [macOS] make app emnu responsive on launch
The macOS app menu would respond to clicks, only to shotcuts (Cmd-Q,
Cmd-H). Moving setActivationPolicy to applicationDidFinishLaunching
seems to fix that, although I can't explain why.

Move a SetDriver call after initialization while here.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-06-14 23:16:41 +02:00
Elias Naur e256d52409 app/internal/wm: reformat os_macos.m
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-06-13 15:39:48 +02:00
Elias Naur 0e592f8bc6 app,app/internal/wm: [macOS] refresh context on display change
The NSViewGlobalFrameDidChangeNotification notification is documented to
be fired every time [NSOpenGLContext update] needs to be called.
However, the notification fails to fire on my setup when a window is
moved to a display with a different pixel scale, which leads to
incorrectly sized output.

This change gets rid of the notification and updates the context before
every frame.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-06-12 20:07:52 +02:00
Inkeliz 39eeaaff94 app/internal/wm: [android] fix key.Event and key.EditEvent conflict
Fixes gio#224

Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2021-06-10 11:37:12 +02:00
Inkeliz 910fa30edf app/internal/wm: [android] add Fullscreen support
Now, it's possible to use `app.Fullscreen` on Android devices. It uses
the "Fullscreen Sticky Immersive" mode.

Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2021-06-07 17:43:42 +02:00
Inkeliz c92a75948d internal/wm: [wasm] add Title support
Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2021-06-07 17:07:31 +02:00
Elias Naur b0b469d540 app/internal/wm: [Android] set up view handle before callbacks
Fixes gio#230 (again)

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-06-07 14:20:24 +02:00
Inkeliz 9b4b91fec0 app, io: [wasm, android] add support for numeric/email keyboard mode
Previously, the on-screen keyboard always displays the text keyboard,
(QWERTY or equivalent).

For optimal user experience, it's possible to specify the keyboard type
using `InputHint`. The on-screen keyboard will provide shortcuts or
restrict what the user can input.

Due to some limitations (gio#116), only numeric and text keyboards are
supported on Android.

Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2021-06-05 17:49:08 +02:00
Elias Naur e68ee35c86 app: don't run driver functions if there's no driver
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-06-04 17:39:39 +02:00
Elias Naur d95e6f2a15 app: avoid race condition on the underlying driver
Instead of a single racy window.driver field, maintain a driver
reference for each goroutine that needs it: the window.run event loop
and the callbacks structure.

Fixes gio#230

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-06-04 10:04:23 +02:00
Elias Naur 476d2269a6 gpu/internal/opengl,app/internal/wm: generalize desktop OpenGL support
This changes moves the macOS specific setup for desktop OpenGL to the
portable opengl package. The opengl package already takes care of the
desktop OpenGL setup for sRGB framebuffers, and by moving the code we
avoid calling the wrong OpenGL functions in case both OpenGL.framework
and ANGLE libGLESv2.dylib is linked into the program.

Remove the interface casting expressions for gl.Functions; it wasn't
worth the trouble to keep updated.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-06-01 18:26:11 +02:00
Elias Naur 5f631209ea app/internal/wm: merge os_android.c into os_android.go
The C functions can then be static, and we save a set of declarations.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-20 10:59:48 +02:00
Elias Naur f8d201b7c2 app: don't deadlock on wakeup arriving after window closure
The previous change wasn't enough, because the `dead` channel wasn't
being closed in an orderly window close.

Add a close of the event output channel in the premature close code path
to match the orderly close.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-19 22:46:53 +02:00
Elias Naur 039b4c4bca app: tolerate delayed WakeupEvents
The event input channel is closed after receiving a DestroyEvent, to
catch any events erronously delivered after window close. However,
the recently introduced WakeupEvent *may* be delivered after window
close. This change leaves the even channel open even after closure,
which effectively ignores such events.

Fixes #227 (again)

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-19 18:29:36 +02:00
Elias Naur df0e058ea6 app/internal/wm: [macOS] avoid deadlock in Window.Close
Native window callbacks now run in the same context as the event loop.
However, a call to Close immediately calls onClose which in turn wants
to send events. Break the deadlock by deferring the Close call.

Fixes gio#227

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-19 17:22:24 +02:00
Elias Naur 9ad492e93b app/internal/wm: [Android] make GioView delegate methods public
GioActivity is final to avoid the brittle base class problem. However,
to permit replacement of GioActivity the GioView delegate methods must
be public.

While here fix a function signature, rename lowMemory to onLowMemory and make it
static. Also move view specific setup to GioView, simplifying the host
activity further.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-19 15:30:42 +02:00
Elias Naur 8611894b4b app,app/internal/wm: introduce app.Window.Run and use it internally
app.Window implements a method for safely running functions against the
underlying native window through the driverFuncs channel. However, the
functions still run in a different goroutine than the one driving the
native event loop, which forces the implementations in package wm to do
complicated synchronization.

A previous change added a mechanism to run functions in the native event
loop thread. The macOS port needed this functionality, but with some
care it can be generalized. That's what this change does through the
new Run method.

The advantage is that the thread switch dance is now confined to
app.Window, with the help of a generic wm.Driver.Wakeup method. All
other Driver methods can then assume they run on their event loop
threads.

Run is exported because it is also needed for programs that use
Windows configured with CustomRenderer to control their own rendering.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-18 19:59:01 +01:00
Elias Naur c914935169 app/internal/wm: implement ViewEvent for Windows
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-18 14:27:51 +01:00
Elias Naur 1ec408280e app,app/internal/wm: implement ViewEvent for macOS
Move the deprecated setWantsBestResolutionOpenGLSurface to GL-specific
code while we're here.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-18 14:26:46 +01:00
Elias Naur 413bff8766 app: implement CustomRenderer option
CustomRenderer disables the construction and binding of a GPU
context to the Window. Combined with ViewEvent and gpu.New, a Gio
client can mix Gio UI and custom rendering.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-18 14:26:45 +01:00
Elias Naur 03ee75fd72 gpu/internal/opengl: support sRGB emulation for desktop OpenGL
Desktop OpenGL implements a GL_FRAMEBUFFER_SRGB setting; query that instead
of the frambuffer color encoding.

With this change it is no longer necessary to enable FRAMEBUFFER_SRGB
in the macOS setup; remove it.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-18 14:26:45 +01:00
Elias Naur b622412ac6 gpu: support forced OpenGL ES mode, for ANGLE on macOS
macOS is the only platform where desktop OpenGL is used. To support
foreign ANGLE contexts add a setting to override Gio's selection of
OpenGL implementation.

The bulk of this change is making all function pointers per-context
instead of global, and loading the OpenGL library dynamically. As a side
effect we're closer to Gio tolerating a platform without any OpenGL
implementation. For example, Apple has deprecated OpenGL and OpenGL ES
on its platforms and may remove them in the future.

Note that as a side-effect of this change, Gio needs Go 1.16 or newer to
run on iOS.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-18 14:26:45 +01:00
Elias Naur 163be2ffd4 app/internal/wm: [Windows] handle WM_DESTROY properly
After handling WM_DESTROY, the system will destroy the window for us.
This change makes sure destroy events are sent and handled before the
window can no longer be used.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-18 14:25:12 +01:00