Commit Graph

2003 Commits

Author SHA1 Message Date
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
Elias Naur 9b5e9ae607 gpu/internal/opengl: restore BeginFrame state in EndFrame
To ease the integration with foreign OpenGL contexts, carefully save the
context state before rendering a frame and restore it afterwards. Gio
rendering can then be mixed with OpenGL code that expects exclusive
control over context state.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-06-11 21:02:18 +02:00
Elias Naur 200957f924 gpu/headless: remove macOS context preparation no longer necessary
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-06-11 09:48:25 +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 1842b61935 cmd/gogio: [wasm] add favicon and title support
Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2021-06-07 17:10:21 +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
Inkeliz b4e6d3efba internal/stroke, op/clip: remove unused variables
Fixes gio#233

Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2021-06-07 17:02:48 +02:00
Inkeliz dd86c9706f widget: add key.InputHint to widget.Editor
Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2021-06-07 17:00:40 +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
Inkeliz 965792c1a9 internal/gl: fix WebGL 1 support
Fixes gio#231

Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2021-06-04 09:28:59 +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 c21897620b .builds: upgrade OpenBSD Go version
Attempting to fix a segmentation during make.bash.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-06-01 18:16:15 +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 d5b70c439c widget/material: draw Loader completely inside its bounds
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-19 19:35:36 +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
pierre b6e9c0324d widget: make Editor implement io.Seeker, io.Reader and io.WriterTo
The WriteTo, Seek, Read methods implement a more efficient access to
the Editor content than Text.

Signed-off-by: pierre <pierre.curto@gmail.com>
2021-05-19 17:25:42 +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 a7be7cc22b .builds: bump android SDK version to fix gogio builds
Upgrade gogio's version of the gioui.org module while here.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-19 11:38:43 +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 d1f2f61ebf internal/gl: [Windows] fix two incorrect OpenGL call signatures
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
Elias Naur 06477be50f app/internal/wm: [iOS] use proper constructor for gl.Functions
We're about to load OpenGL function pointers into gl.Function structs.
Make sure iOS internally uses the NewFunctions constructor, not just
new(Functions).

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-17 20:29:41 +02:00
Elias Naur 3a0583564b app/internal/wm: [macOS] avoid NSView.isFlipped
When using Gio with ANGLE, the isFlipped coordinate system flip will
apply to rendering as well. Fortunately we're no longer using NSOpenGLView
so isFlipped only applies to mouse events. Convert them manually to avoid
isFlipped and support ANGLE.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-17 10:51:10 +02:00
Elias Naur 39775f555a gp/internal/opengl: support sRGB emulation for embedded content
Programs such as gio-example/glfw rely on Gio drawing blending with
the framebuffer background. This change makes it so when sRGB emulation
is active.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-16 18:17:00 +02:00
Elias Naur 351ede917c app: use scale independent values for default window size
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-16 18:17:00 +02:00
Elias Naur d5fc7fc8f6 app/internal/wm: [macOS] release context only if it was created
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-16 12:02:42 +02:00
Elias Naur 566b4b166b gpu/internal/opengl: remove unused type alias
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-16 11:18:42 +02:00
Elias Naur 21c319ace5 gpu/internal/opengl,internal: move sRGB emulation to OpenGL driver
There is only one driver but several backends (EGL, WebGL).

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-16 10:44:45 +02:00
Elias Naur e90c99a66c internal/egl: replace glFinish with eglWaitClient
glFinish depends on package gl which is about to require a function
pointer loader. eglWaitClient is in the EGL API and always available.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-15 11:04:06 +02:00
Elias Naur 1d4bf04aa1 app/internal/wm: [macOS] use NSView+NSOpenGLContext, not NSOpenGLContextView
NSOpenGLContextView couples the window manager logic tightly with
OpenGL. Use generic NSViews, and attach NSOpenGLContext just like the
other platforms.

This change prepares for supporting GPU contexts created by clients as
well as a future Metal port.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-14 20:23:06 +02:00
Elias Naur fcca1c11ee app/internal/wm: [iOS] don't destroy context when MakeCurrent fails
The caller should ensure the proper destruction.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-14 16:22:56 +02:00
Elias Naur d6859744ba internal/gl: unexport GetStringi
It's only used for the backwards incompatible macOS GL core profile.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-13 20:37:39 +02:00
Elias Naur 551c43b502 internal/gl: tigthen C symbol visibility from hidden to static
Apparently, Cgo can link to static C functions from the preamble.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-13 20:27:39 +02:00
Elias Naur 82fff0178b gpu: [compute] generalize sizedBuffer to cover vertex buffers
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-04 21:35:39 +02:00
Elias Naur 2c07b2dc0e headless: clear background to transparent, not white
The clear background is the most useful, and the old behaviour can
be achieved by filling the entire viewport with a white paint.ColorOp.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-03 11:31:45 +02:00
Elias Naur 23a839a29d widget: clip by most complex shape last
In the new compute renderer, clipping to a complex shape is slower than
filling it. Swap the clip shapes for drawing text so that the text shape
itself is last, and therefore used for filling.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-04-27 16:49:06 +02:00
Elias Naur f655027110 gpu: [compute] add materials and blit timers to profiling output
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-04-27 16:49:06 +02:00
Elias Naur 53aad36ac1 gpu: [compute] move encoding to Collect
Collect is for converting ops to GPU commands, Frame is for actual
rendering. There's little practical difference, but makes profiling
easier to distinguish between conversion and rendering.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-04-27 16:49:06 +02:00
Elias Naur 06ce077436 op/clip: compute bounds during Path build
The current renderer transforms and processes paths before sending them
to the GPU. It can compute bounds during processing.

The new renderer passes paths verbatim to the GPU, but needs the bounds
for constructing clip bounds.

This change computes the bounds during construction, so it is available
at use. As a bonus for storing the bounds with the path, path caches
(such as for storing text fragments) automatically reuse the bounds
calculations as well.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-04-27 16:49:06 +02:00