Commit Graph

184 Commits

Author SHA1 Message Date
Andy Balholm 6d9db2b13c internal/stroke: properly calculate maxDist
The calculated value for maxDist (the maximum allowable error when
converting cubic Beziers to quadratics) was way too small when the
first control point was very close to the starting point of the segment.

(f32.Rectangle.Add does not expand the rectangle to include the new point;
it moves the rectangle by the point's X and Y coordinates.)

Splitting the curve into such small pieces was resulting in very ugly
output.

Fixes: https://todo.sr.ht/~eliasnaur/gio/331
Signed-off-by: Andy Balholm <andy@balholm.com>
2022-01-04 17:28:37 +01:00
Pierre Curto 11bb86166a op/clip: automatically close Path in Outlines
Unclosed path segments in Path will be automatically
closed by a line.

Fixes: https://todo.sr.ht/~eliasnaur/gio/320
Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
2021-12-21 10:13:20 +01:00
Pierre Curto 03016f0c69 widget: add drag and drop support
This patch adds internal Drag and Drop support to app.Windows.

The new package io/transfer adds the ability to
define draggable and droppable targets, which
are leveraged by the new widget.Draggable type.

The API is generic and could handle future use
cases, such as external Drag and Drop.

Updates gio#153

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
2021-12-07 12:45:53 +01:00
Elias Naur 8a90074d04 io/semantic: add package for adding semantic descriptions to UI components
Software such as screen readers require semantic descriptions of user
interfaces to effectively present and interact with them. Package
semantic, combined with the existing package clip provide the operations
for Gio programs to describe themselves.

This change implements the semantic package and the routing changes for
accessing semantic trees; follow-ups add semantic information to widgets
and implement mapping semantic tree to platform representations.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-12-01 17:23:54 +01:00
Pierre Curto 74490b4dfc internal/stroke: separate more the circle special case in ArcTransform
Avoid calculations not relevant for a circle.

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
2021-11-26 22:31:23 +01:00
Pierre Curto 321512d8a5 internal/stroke: tidy up ArcTransform
Fix comments and rename variables to avoid confusing
de facto ellipse constant names.

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
2021-11-26 22:31:19 +01:00
Pierre Curto 218a9588d6 io/router, internal/ops: minor refactoring
Rename the assertEventSequence helper to assertEventPointerTypeSequence.
Fix typos.

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
2021-11-26 22:26:38 +01:00
Elias Naur 8613d81a94 gpu/headless: accept the lavapipe Vulkan driver
On headless setups such as sr.ht CI machines, lavapipe is the only
available Vulkan driver. This change accepts the lavapipe software
driver for headless contexts, so that CI won't fall back to OpenGL.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-11-10 15:39:37 +01:00
Elias Naur 29cea1db49 io/pointer,io/router: replace AreaOp with clip.Op
Pointer hit areas and paint clip areas are separate concepts, but
similar enough to warrant merging. This change replaces pointer hit
areas with clip areas, so Gio is left with just one area concept (in
package op/clip).

The reason for separating the concepts in the original Gio release was
because of my being unsure general path/stroke hit areas would ever be
implemented, let alone efficient.

This change represents a change of mind, in the sense that it's better
to have an incomplete API than two separate area concepts.

Leave the deprecated pointer.Rect, pointer.Ellipse for temporary
backwards compatibility.

This is an API change. Most existing programs should continue to build
with this change, but may have to adjust to having all clip.Ops participate
in InputOp hit areas.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-11-03 14:12:31 +01:00
Elias Naur 1eab4b84a6 gpu,internal/ops: move gpu.clipOp to ops.ClipOp
We're about to use clip.Ops for pointer areas; this change makes the
decoding accessible from the router package.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-10-26 12:13:11 +02:00
Elias Naur 9548dbe901 internal/ops: rename StateOP to StateOp
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-10-26 12:13:11 +02:00
Elias Naur e14e33b87e op/clip: remove Op.Add
The Add method was a compatibility stop-gap.

API change. Use clip.Op.Push and Pop the return value to explicitly mark
the region affected by the clip operation.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-10-26 12:13:11 +02:00
Pierre Curto 6b0e00b9aa io/pointer: change Type to uint
This is to allow for future new Types.

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
2021-10-20 10:09:58 +02:00
Elias Naur 0048f7be1d internal/ops: hide Ops methods by converting them to package functions
Ops is in the internal package ops, but external clients can reach its
method through op.Ops.Internal. Hide them by converting them to internal
package functions.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-10-12 14:50:15 +02:00
Elias Naur 87d050bcc7 internal/ops: remove Data, Version, Refs methods from Ops
They're only used internally.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-10-12 14:28:05 +02:00
Elias Naur 960f3068a1 io/pointer: re-introduce PassOp
A previous change merged PassOp with AreaOp under the assumption that
the pass mode would be set on a particular area. That assumption turns
out not to hold, so this change brings back PassOp as an independent
stack operation.

This is an API change: replace AreaOp{Pass: true} with a separate
pointer.PassOp operation.

Fixes gio#288

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-10-09 16:31:54 +02:00
Elias Naur 61a3395879 internal/vk: ignore software Vulkan implementations
It's better to fall back on OpenGL than to accept a software Vulkan
implementation. More importantly, some software implementations such as
lavapipe doesn't even work[0].

[0] https://gitlab.freedesktop.org/mesa/mesa/-/issues/5473

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-10-09 16:31:47 +02:00
Elias Naur bd1ef92dc4 op/clip: remove complex stroke support
In a discussion with Raph Levien, the author of our compute renderer
implementation, it became clear to me that it's not at all certain that
complex strokes will ever be efficiently supported by a GPU renderer.

At the same time, the machinery for converting a complex stroke to a
GPU-friendly outline has a significant maintenance cost. Further, it is
surprising to users that complex strokes are significantly slower and
allocate memory.

This change removes support for complex strokes, leaving only
round-capped, round-joined strokes supported by the compute renderer.
The default renderer still converts all strokes to outline, but it also
caches the result.

This is an API change. The complex stroke conversion code has been moved
to the external gioui.org/x/stroke package, with a similar API.

Updats gio#282 (Inkeliz brought up the allocation issue)

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-10-08 18:10:47 +02:00
Elias Naur 391725b9d0 op: move Ops internal methods and state to internal package ops
Merge package opconsts into ops as well; it only existed to break
import cycles.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-10-08 17:21:56 +02:00
Elias Naur 936c266b03 all: [API] split operation stack into per-state stacks
The op.Save and Load methods exist to support the need for
transformation, clip, pointer area state to behave as stacks. For
example, layout needs to apply an offset to its children but not
subsequent operations.

Before this change, op.Save and Load were used to save and restore the
state:

    ops := new(op.Ops)
    // Save state.
    state := op.Save(ops)
    // Apply offset.
    op.Offset(...).Add(ops)
    // Draw with offset applied.
    draw(ops)
    // Restore state.
    state.Load()

A drawback with the op.Save mechanism is that there is no direct
connection between the state change and the saving and loading of state.
This causes confusion as to when a Save/Load is needed and who is
responsible for performing them, which leads to subtle bugs and over-use
of Save/Loads.

This change gets rid of the general state stack and replaces it with
per-state stacks. There is now a stack for transformation, clip, pointer
areas, and they can only be restored by the code pushing state to them.
The example above now becomes:

    ops := new(op.Ops)
    // Push offset to the transformation stack.
    stack := op.Offset(...).Push(ops)
    // Draw with offset applied.
    draw(ops)
    // Restore state.
    stack.Pop()

For convenience, transformation also be Add'ed if the stack operation is
not required.

Simple state such as the current material no longer has a way to be
restored; it is assumed the client of a PaintOp adds their desired
material operation before it.

API change: replace op.Save/Load with explicit Push/Pop scopes for
op.TransformOps, pointer.AreaOps, clip.Ops.

To ease porting, this change retains a version of op.Save/Load that
saves and restores the transformation and clip stacks. It also retains
an Add method for clip.Op.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-10-08 17:21:56 +02:00
Elias Naur 6f80b94b4a io/pointer,io/router: [API] make pass-through a property of AreaOp
We're about to make operation scopes explicit, which would result in
both AreaOp and PassOp be scoped. However, PassOp seems to light to have
its separate stack, so this change instead makes pass-through a property
of an area. We're assuming that clients that want pass-through are also
aware of the affected hit area.

API change: replace PassOps with the AreaOp.PassThrough field.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-10-08 15:54:50 +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 3434bf8af1 internal/ops: don't run deferred macros twice
Discovered while debugging #277.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-24 15:14:45 +02:00
Elias Naur 72c67ff180 internal/opconst: add OpType.String
For gio#277

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-24 14:57:48 +02:00
Elias Naur 8b4758947f internal/scene: add color to OpFillColor String representation
For gio#277

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-24 14:57:41 +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 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 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 dd6b379c74 internal/gl: explicitly state RTLD_LOCAL to dlopen
RTLD_LOCAL is the default on Linux, whereas RTLD_GLOBAL is default on
macOS. Be explicit.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-14 09:24:53 +02:00
Elias Naur bde046de54 gpu/internal/opengl: avoid PACK/UNPACK_ROW_LENGTH on WebGL 1
Fixes gio#259

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-09-05 13:58:19 +02:00
Elias Naur fe52357141 internal/egl: remove unused field
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-08-29 19:35:49 +02:00
Elias Naur 1362acb85a gpu/internal/d3d11,internal/d3d11: add DirectCompute support
This change implements support for compute programs in the Direct3D 11
driver. The compute renderer doesn't work for me yet; my NVIDIA GTX 970
and Intel GPUs both display corrupted output and hangs.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-08-28 16:13:06 +02:00
Elias Naur 7f6e376424 gpu,gpu/internal: support variable strides in ReadPixels
It saves a roundtrip to scratch memory when the CPU fallback renderer
downloads rendered materials.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-08-27 12:59:01 +02:00
Elias Naur 06ffa42d16 gpu: [compute] support unlimited number of materials and images
This change extends the atlas allocation machinery to images and
materials.

Updates gio#219

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-08-27 12:59:01 +02:00
Elias Naur b9ede6d735 gpu/internal/opengl,internal/gl: avoid glBufferSubData after glBufferData
On my Fedora Intel GPU, issuing a glBufferSubData immediately after a
glBufferData with no data may leave the buffer cleared.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-08-25 14:29:09 +02:00
Elias Naur c9970cb8e3 gpu,gpu/internal,internal/gl: replace BlitFramebuffer with CopyTexture
OpenGL ES 2.0 doesn't support glBlitFramebuffer, but does support
glCopyTexSubImage2D. Fortunately, we don't need the extra features of
glBlitFramebuffer anyway.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-08-21 11:16:28 +02:00
Elias Naur afaa31eca8 gpu: introduce pipeline abstraction
Modern API such as Metal and Vulkan want clients to compile expensive
state changes into pipeline objects. Change our GPU driver abstraction
to match, thereby paving the way for future drivers.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-08-21 08:31:46 +02:00
Elias Naur c49fe63d56 internal/gl: use libGLESv2.so.2 for Unix platforms
The unprefixed library names are for development, and Android.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-08-08 15:54:00 +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 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 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 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 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 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 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 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 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
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 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
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