Commit Graph

1980 Commits

Author SHA1 Message Date
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
Elias Naur 157430a3d2 gpu: [compute] move timer initialization from Collect to Frame
GPU operations logically belong in the Frame method, and it's probably
best to keep them inside BeginFrame/EndFrame as well.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-04-27 16:49:06 +02:00
Elias Naur d43f513e63 internal/scene: add Command.String
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-04-27 16:49:06 +02:00
Elias Naur 3322e211c9 f32: handle empty rectangles in Union and Intersect
The old renderer depends on the old behaviour of Union, so change that
reference to a copy.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-04-27 16:49:06 +02:00
Inkeliz d51d8b46c3 app, app/internal: [wasm,android] new Option to set Orientation
Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2021-04-25 21:32:54 +02:00
Elias Naur a06a7a4b3c app: make Fullscreen, Windowed Options
Instead of

app.WindowMode(app.Fullscreen)

programs can now just use

app.Fullscreen

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-04-23 10:25:24 +02:00
Inkeliz 9dae29844c app, app/internal: [wasm,android] new Option to change navigation/status color
Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2021-04-22 12:15:26 +02:00
Elias Naur 2296c80d28 internal/f32color: delete unused NRGBAToRGBA_PostAlpha
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-04-21 17:17:39 +02:00
pierre 354f5b43d2 app: added missing handling of Options.Size for X11
Signed-off-by: pierre <pierre.curto@gmail.com>
2021-04-20 12:15:55 +02:00
Elias Naur 22f16d7b02 gpu/shaders: use mediump precision for kernel4 colors, areas
Improves performance on Pixel 1.

Add restrict qualifiers while we're here.

Also sync with piet-gpu.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-04-20 10:39:10 +02:00
Elias Naur ff7d224a0b gpu/shaders: use mediump precision for sRGB copy shader
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-04-20 10:39:10 +02:00
Elias Naur ee519351f7 gpu/shaders: ensure dynamically uniform barriers when malloc fails
GPU APIs require that barrier() calls are dynamically uniform, that is
for every barrier in the code, every shader invocation in a workgroup
must all call it, or all not call it.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-04-18 17:20:19 +02:00
Elias Naur f930e3f3d7 internal/gl: implement glGetProgramBinary
Useful for debugging shader compiler issues, such as those that may
cause

https://github.com/linebender/piet-gpu/issues/83

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-04-18 17:20:19 +02:00
Elias Naur 3b69b5ed05 gpu/internal/opengl: fix package name
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-04-18 17:16:03 +02:00
Elias Naur 9bf4e559bc gpu/internal/opengl: use uniform blocks on macOS
The reflected uniform names are for the shader versions that don't use uniform
buffer objects. For UBO shaders, the names won't resolve.

This change adds a panic when shader uniforms are not found, and fixes

Fixes gio#216

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-04-17 11:10:33 +02:00
Elias Naur c19ce8e1d7 gpu/internal/convertshaders: don't require GL_ARB_shading_language_420pack
It's not supported on macOS.

Updates gio#216

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-04-17 11:10:20 +02:00
Dan Kortschak 0a91858163 layout: fix spelling of Alignment
Signed-off-by: Dan Kortschak <dan@kortschak.io>
2021-04-16 11:07:21 +02:00
Elias Naur 3a94f7bf70 gpu/shaders: update piet-gpu
Changes:

- fix BeginClip bounding box
- replace continue not supported by HLSL

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-04-12 13:56:41 +02:00
Elias Naur e9a020f774 gpu/internal/convertshaders: build compute shaders in HLSL cs_5_0 profile
The recent changes to the compute shaders have fixed all errors
previously reported by fxc. Switch from dxc to fxc to target shader
model 5.0, supported by Direct3D 11.

Because we know dxc must be available, always build compute shaders even
though the result is not yet used.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-04-12 12:49:49 +02:00
Elias Naur e3bb153274 gpu/internal/convertshaders: don't wait for winepath to exit
Apparently, exec.Command.Output waits for winepath's grandchildren to
exit. However, that may take several seconds if wineserver was started
by winepath.

exec.Command.StdoutPipe works better, in that it is closed when the
winepath process exits.

A similar change may help run the fxc.exe tool under Wine, if that ever
turns out to have the same problem.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-04-12 12:44:06 +02:00
Elias Naur 8adcf25049 gpu/internal/convertshaders: batch calls to winepath
Wine tools can be slow to run, so it makes sense to batch their use.
Fortunately, winepath supports resolving multiple paths in one
execution.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-04-12 12:44:06 +02:00
Elias Naur 3b3d41a7ea gpu/internal/convertshaders: don't use Wine for the dxc tool
dxc exists for Linux, and seems to work.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-04-12 12:44:06 +02:00
Elias Naur 23e0c898ef gpu/internal/driver: use strings for generated DXIL assembly
Literal strings are a more compact than literal byte slices. A future
change will switch to go:embed to save even more space.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-04-12 12:44:06 +02:00
Elias Naur fbee13a07d gpu/internal/convertshaders,gpu: represent converted shaders with raw literals
Raw strings with linebreaks are easier to read and produce smaller
diffs.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-04-12 12:43:46 +02:00