Commit Graph

2058 Commits

Author SHA1 Message Date
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 4dd6a50670 .builds: upgrade Apple builder to Go 1.16
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-08-08 13:53:19 +02:00
Petr Karmashev 1efe68c154 op/paint: remove duplicate word
Signed-off-by: Petr Karmashev <smonkl@bk.ru>
2021-08-04 12:58:05 +02:00
Elias Naur 8cec7e04eb gpu,gpu/shaders: [compute] decode sRGB texels in shader when EXT_sRGB is missing
This change avoids the hard dependency on GPU support for sRGB encoded
textures in the compute renderer.

With this change and the previously added CPU fallback, Gio no longer
rely on any GPU functionality outside the OpenGL ES 2.0 level.

Fixes gio#49
Fixes gio#154
Fixes gio#97
Fixes gio#36
Fixes gio#172

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-07-29 09:05:55 +02:00
Elias Naur d8f8740574 gpu/internal/opengl: use the linear colorspace when EXT_sRGB is missing
The SRGBFBO emulates a framebuffer in the sRGB colorspace. However, some
low-end devices may not have EXT_sRGB support to store framebuffer content in
sRGB.

This change handles missing EXT_sRGB support by falling back to the linear RGB colorspace.
Falling back loses color precision but is better than failing.

Updates gio#49
Updates gio#154
Updates gio#97
Updates gio#36
Updates gio#172

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-07-29 08:37:59 +02:00
Elias Naur 68fa64dfd5 gpu/internal/opengl: detect sRGB triple in terms of srgbaTripleFor
Refactor in preparation for relaxing sRGB format requirements.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-07-29 08:37:59 +02:00
Elias Naur 970fadf852 gpu/internal/driver: introduce and use FeatureSRGB
No functional changes; a follow-up will implement graceful fallback in
the compute renderer.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-07-29 08:37:59 +02:00
Elias Naur b3a8c24334 gpu/internal/driver: rename TextureFormatSRGB to TextureFormatSRGBA
The format implies an alpha channel; name it accordingly.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-07-29 08:37:18 +02:00
Elias Naur 43c5082dab .builds: upgrade to FreeBSD 13
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-07-29 08:23:21 +02:00
Elias Naur 6e9bb7b91c widget,widget/material: remove Color field from Icon
Icons are meant to be shared among multiple widgets, but their Color
state may end up with unexpected values after use. Replace the state
with and explicit argument to Layout.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-07-28 14:19:39 +02:00
Elias Naur ea38195e2e gpu: [compute] add CPU fallback
This change adds a CPU fallback for devices that don't support the old
renderer nor have GPU support for compute programs.

Most of the hard work is implemented in the gioui.org/cpu module. It
uses the SwiftShader project with light modification to output
statically compiled CPU .o files for each compute program.

The CPU fallback only covers Linux and Android on arm, arm64, amd64
architectures. There is no fundamental reason support can't be extended
to other platforms:

- macOS and iOS are probably easy, but it's likely that virtually every
  device has GPU support for compute shaders.
- Windows needs a Cgo-less port, or a build constraint to require a C
  compiler (Gio core doesn't).
- FreeBSD and OpenBSD are probably also easy to do because they're so
  similar to Linux.
- The 386 binaries didn't work properly in my tests, so fixes to
  SwiftShader is probably needed. However, I expect virtually every
  Intel device can run amd64 binaries.

Updates gio#49
Fixes gio#228

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-07-27 14:56:50 +02:00
Elias Naur f14c151883 gpu,gpu/internal: generate hashes of compute programs
The CPU fallback for the compute renderer is contained in a separate
module for space reasons, but the CPU binaries must exactly match the
compute programs. However, there is no way to express that constraint
in go.mod.

This change generates hashes of every compute program so that a
following change can verify the CPU binaries match the programs.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-07-27 14:34:18 +02:00
Elias Naur 5197f637a7 gpu: [compute] compute and store clipping path hashes during construction
The hash of the clipping paths that affect drawing operations are computed
and used to quickly determine that two operations are not equal, the
most likely outcome of a comparison.

However, for paths that are constructed once and cached computing the
hash at every frame is wasteful. This is especially true for text, which
is both cached and also among the largest paths in a frame.

This change moves the hashing to op/clip.Path construction time, and
stores the hash in the ops list so it won't be re-computed at every use.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-07-27 14:34:18 +02:00
Elias Naur 88fb798cca gpu: [compute] speed up path comparisons with op keys
To re-use previously cached layers, the compute renderer must know
whether two drawing operations are equal. In the case two operations are
not equal, a fast hash comparison will most likely fail. In the case two
equal operations with complicated clipping paths, the comparison of the
path data is expensive.

This change adds support for fast ops.Key comparisons, where two paths
are equal if their ops.Key are. This is an optimization that kicks in
for text rendering, where glyph clipping shapes are re-used across
frames.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-07-27 14:34:18 +02:00
Elias Naur 4ab872e36a gpu: [compute] re-use layers that differ only in integer offsets
To re-use drawing operations common to two layers, every operation must
exactly match, including their transformations. However, layers that
differ only by an integer offset can be re-used because rendering does
not depend on the absolute integer offset. This is important in the very
common case of scrolling otherwise static UI content.

This change separate the integer offset from drawing operations and
relaxes the layer cache to match layers that differ only in integer
offsets.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-07-27 14:34:18 +02:00
Elias Naur 318ddd0644 gpu: [compute] add function for separating integer offsets from transforms
Refactor only; separateTransform is needed in the following change.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-07-27 14:34:18 +02:00
Elias Naur e6c31a02fd gpu: [compute] cache and re-use drawing operations from the previous frame
The compute renderer is more expensive to run than the old renderer on
low-end GPUs, and even more so on CPUs. To ensure good performance
regardless of the end-user device, this change implements automatic
re-use of content rendered in the frame before the current.

The basic idea is that every drawing operation (PaintOp), along with its
transform and clipping, can be hashed and efficiently looked up. A naïve
caching approach is then to rasterize every operation to separate
sections of several large texture atlases, turning a cache hit into a
very cheap texture copy.

However, for scenes with lots of overlapping operations, the resulting
texture memory from separating the operations would be much larger than
the memory for just the window framebuffer.

So instead of caching individual operations, this change caches layers,
which are sequences of drawing operations. It starts by putting all
operations into a single layer. Then, if the subsequent frame re-uses a
sub-sequence of that larger layer, it is split.

For example, consider a UI similar to the kitchen sample:

Hello, Gio

<Editor>

<Line Editor>

<Button> <Button> <Button>

<ProgressBar>

<Checkbox> <Toggle>

In the first frame, all of the drawing operations comprising the UI will
be stored and cached in a single layer. In the second frame the
progress bar will have moved and the renderer splits the UI into three
layers: layer A for everything up to (but not including) the progress
bar, layer B with just the progress bar, and layer C for the rest. Note
that nothing has been re-used yet. In the third frame, the progress bar
moves again, and this time layer A and C can be copied from the cache
only the progress bar needs redrawing through the compute programs.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-07-27 14:34:18 +02:00
Elias Naur 938e51f111 gpu: [compute] clear viewport through glClear, not through compute
The performance difference is negligible, but is useful when the compute
pipeline can skip rendering to empty tiles.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-07-27 14:34:18 +02:00
Elias Naur 89ab5ebf4f gpu: [compute] unify resource cleanup
Rename all resource release methods to "Release", and release all
resources with a slice and loop.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-07-27 14:34:18 +02:00
Elias Naur b87cbc04f3 gpu: [compute] add compute renderer specific decoding of ops
Until now, the two renderers have shared structures and code for
decoding drawing ops and convert them to GPU-friendly structures.

However, the decoder is tailored to the old renderer and use
structures that poorly fits the new compute renderer.

This change copies the decoder and specializes the copy for the compute
renderer, avoiding a round-trip through the old renderer decoder.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-07-27 14:34:18 +02:00
Elias Naur 60a47e7de5 gpu/internal,internal/gl: add support for strided texture uploads
The CPU fallback of the compute renderer needs to upload subtextures
from a larger image.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-07-27 14:34:18 +02:00
Elias Naur abfbeb87cc gpu/internal/d3d11: stub BlitFramebuffer for D3D11
The compute renderer doesn't run on Windows yet, but the d3d11 backend needs
the method to satisfy the driver interface.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-07-27 14:34:18 +02:00
Elias Naur b7a983d7ff go.*: update dependencies, bump go.mod Go version to 1.16
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-07-27 14:33:52 +02:00
Elias Naur 9188690e9e gpu: [compute] don't leak a texture if its framebuffer allocation fails
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-07-27 12:57:53 +02:00
Elias Naur a77d74f20a .builds: disable go.local.mod test for gogio
I gave up figuring out how to run it under Go 1.17.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-07-27 12:23:20 +02:00
Elias Naur 17e9896e58 .builds: upgrade to Go 1.16.6
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-07-27 12:23:20 +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 152a30f468 cmd/gogio: bump minimum Android SDK version to 17 (Android 4.2)
The CPU fallback renderer relies on posix_memalign, which was exposed in
Android 4.2. Support for Android 4.1 could be restored by writing
posix_memalign outselves, but this change is easier.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-07-26 16:43:29 +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 4f40b58e0d gpu/shaders: fix GPU hang
This is a port of https://github.com/linebender/piet-gpu/pull/108.

Updates gio#214
Updates gio#219

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-07-19 19:20:05 +02:00
Elias Naur 62a8b80c81 internal/ops,gpu: remove transform fields from ops.Key
The transformation information in ops.Key is a layer violation.
Introduce a key type specific to package gpu and use that instead.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-07-19 16:37:06 +02:00
Elias Naur e4fe56c456 gpu: release all resources in resourceCache.release
Fixes gio#245

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-07-18 17:57:39 +01: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
Chris Waldon b3918ce40f widget/material: ensure List accounts for scrollbar size in dims
This commit ensures that the dimensions returned by material.List
include the size of the scrollbar when the scrollbar is set to
the Occupy AnchorStrategy.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2021-07-13 16:43:38 +02:00
Chris Waldon 78235baaa5 widget/material: ensure List handles zero minimum constraints
This change ensures that the scrollbar anchors to the proper edge of the
content even when the list was drawn with a zero minimum constraint.

Without this, the layout.Direction used to anchor the scrollbar will choose
to use the minimum size and anchor it to the opposite edge of the content.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2021-07-13 15:09:26 +02:00
Elias Naur d9a0b4be76 gpu: refresh shaders.go
For some reason, commit d331f63d20 didn't
update the generated code for material.vert properly. The outdated
version is equivalent to the new, so I only discovered this discrepancy
while changing some other shader.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-07-13 09:57:36 +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
Chris Waldon 0e60935856 widget/material: ensure scrollbars can be dragged from list end
The scrollbar implementation prior to this change only adjusted
list.Position.Offset. This works in all circumstances except when
list.Position.BeforeEnd=false. If the position indicates that the
scroll position is at the end of the list, the offset is ignored.

This change ensures that manually dragging the scrollbar always
causes BeforeEnd to be set to true. If the drag ends with the
scrollbar at the end of the list, BeforeEnd will be set
automatically by the next list.Layout call, so this doesn't
prevent the list from optimizing for that case in general.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2021-07-07 15:51:00 +02:00
Chris Waldon 941aeaae91 widget{,/material}: add List types with scrollbars
To use these lists instead of layout.List, callers simply need to
change declarations of layout.List to widget.List, and to change
calls to layout.List.Layout to material.List(th,&list).Layout.

So this:

    var list layout.List
    list.Layout(gtx, 10, func(gtx C, index int) D {
        return material.Body1(th, fmt.Sprintf("%d", index)).Layout(gtx)
    })

Becomes:

    var list widget.List
    material.List(th, &list).Layout(gtx, 10, func(gtx C, index int) D {
        return material.Body1(th, fmt.Sprintf("%d", index)).Layout(gtx)
    })

Naturally, the material.ListStyle type supports tweaking the scrollbar's
appearance and behavior.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2021-07-05 16:08:30 +02:00
Chris Waldon 990029985a layout: make List approximate its length in Position
This commit adds a Length field to the
layout.Position. This field contains an approximation
of the overall length of the list's contents.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2021-07-05 16:08:30 +02:00
pierre 2e991f31be widget: make Icon honour its constraints
This is a breaking change as Icon.Layout no longer requests a size.

Before:
  sz := unit.Dp(20)
  ic.Layout(gtx, sz)

After:
  sz := gtx.Metric.Px(unit.Dp(20))
  gtx.Constraints.Min = image.Pt(sz, 0)
  ic.Layout(gtx)

Fixes gio#240

Signed-off-by: pierre <pierre.curto@gmail.com>
2021-07-01 13:15:08 +02:00
Chris Waldon cf778ecd06 layout: add Axis.FConvert for f32.Points
This creates a floating-point analog to layout.Axis.Convert
for converting from (x,y) coordinate space to (main,cross)
coordinate space.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2021-06-29 09:06:15 +02:00
Elias Naur d331f63d20 gpu: [compute] move material clip space transformation to the GPU
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-06-28 08:35:41 +02:00
Elias Naur a87206c364 widget/material: add ProgressCircle
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-06-26 18:05:34 +02:00
Elias Naur bc7f7f6706 cmd/gogio: enable iPad support
Found by Christophe Meessen.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-06-25 14:44:26 +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