Commit Graph

1763 Commits

Author SHA1 Message Date
Elias Naur cd47a158a2 op/clip: move Rect to shapes.go
It's a specialized shape like the others.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-19 20:31:29 +01:00
Chris Waldon d93874005c op/clip: document dimensions of Border.
Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2021-01-19 20:30:51 +01:00
Chris Waldon 9231ff47ef widget: make border draw within widget dims as documented
Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2021-01-19 20:22:11 +01:00
Elias Naur d6886737a5 op: change Defer to only restore transformation state
It turns out restoring all operation state from the moment Defer
is executed is too much; for example, a right-click pop-up needs
the transformation, but not the current clip.

Change Defer to only restore the transformation, and reset all
other state.

Other combinations may be needed in future; we'll deal with them then,
possibly by exposing the load state mask.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-19 20:04:30 +01:00
Egon Elbre eea1dbc176 widget/material: add hover to Switch
Signed-off-by: Egon Elbre <egonelbre@gmail.com>
2021-01-18 10:57:10 +01:00
Egon Elbre bc6798c4ca widget/material: add hovered to RadioButton
Signed-off-by: Egon Elbre <egonelbre@gmail.com>
2021-01-18 10:57:06 +01:00
Egon Elbre 0b736990a9 widget/material: add hover to CheckBox
Signed-off-by: Egon Elbre <egonelbre@gmail.com>
2021-01-18 10:57:01 +01:00
Egon Elbre 468bd6f53a widget/material: add hover to Button
Signed-off-by: Egon Elbre <egonelbre@gmail.com>
2021-01-18 10:56:57 +01:00
Egon Elbre 93ebd51531 gesture,widget: add hovered property
Signed-off-by: Egon Elbre <egonelbre@gmail.com>
2021-01-18 10:56:52 +01:00
Elias Naur 99bfa6a33c internal/f32color: revert incorrect NRGBA to linear color change
Egon Elbre convinced me commit 01d5e72291 was incorrect, because
in the NRGBA colorspace the alpha value is linear, not gamma adjusted.

Updates gio#192

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-16 09:58:04 +01:00
Elias Naur 01d5e72291 internal/f32color: correct pre-multipled color conversion
Tweak a test color to avoid an off-by-1 rounding error after changing
the conversion formula.

Fixes gio#192

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-15 16:02:39 +01:00
pierre 85c0a7d803 widget/material: added support for Vertical axis to Slider
Adding an axis to the Float widget, allows positioning the Slider one not only horizontally but also vertically.
Also update the fill ops while there.

Signed-off-by: pierre <pierre.curto@gmail.com>
2021-01-14 17:42:58 +01:00
Elias Naur f86703e4b0 op: introduce Defer for deferring CallOps
Updates gio#164

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-14 15:53:49 +01:00
pierre e088833caf layout: simplified Axis methods
Removed the Main and Cross Axis methods in favor of Convert.

Signed-off-by: pierre <pierre.curto@gmail.com>
2021-01-14 11:04:06 +01:00
Elias Naur d331dd2de8 op: rename StackOp/Push/Pop to StateOp/Save/Load
The semantics were relaxed in a previous commit; this change renames
to operations accordingly.

API change. Use gofmt to adjust your code accordingly:

gofmt -r 'op.Push(a).Pop() -> op.Save(a).Load()'
gofmt -r 'op.Push(a) -> op.Save(a)'
gofmt -r 'v.Pop() -> v.Load()'
gofmt -r 'op.StackOp -> op.StateOp'

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-12 21:28:59 +01:00
Elias Naur ae2c74ec13 op: relax Push/Pop to Save/Restore semantics
A previous change implemented save/restore semantics where a saved
state can be restored anywhere, not just in a stack-like manner.

This change similarly relaxes the exported Push/Pop operations; the next
change will rename them accordingly.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-12 20:53:47 +01:00
Elias Naur f7902f299b op: implement StackOp in terms of general save/load of state
Push/Pop only allows saving and restoring operation state in a
stack-like manner. We're going to need restoring arbitrary state
for implementing deferred operations.

Generalize state save/restore and implement Push and Pop on top of
that.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-12 20:53:25 +01:00
Egon Elbre f114acdb02 widget: use correct color in Icon
iconvg seems to expect a linear premultiplied color.

Fixes gio#132

Signed-off-by: Egon Elbre <egonelbre@gmail.com>
2021-01-11 14:32:28 +01:00
pierre 0e3e446393 layout: added Axis methods
Signed-off-by: pierre <pierre.curto@gmail.com>
2021-01-11 14:32:28 +01:00
Elias Naur f7f94c93fe app/internal/window: [android] re-apply view state lost on rotate etc.
Android can re-create our Activity and GioView at any time, losing view
and activity state such as the current cursor. Further, setting state
while there is no GioView attached is lost.

Track the current and unapplied state, and apply it when a GioView is
available.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-10 14:48:01 +01:00
Elias Naur acef4e6e2d app/internal/window: [android] move switching to main thread to Go
There's runOnMain alread; use that for show|hideTextInput instead
of an ad-hoc switch.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-10 13:14:43 +01:00
Elias Naur f311a54ffb app/internal/window: [android] remove redundant context argument
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-10 12:42:10 +01:00
Elias Naur 5155893781 app: drop return value from Window.driverDo
It's not used anymore.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-10 11:35:22 +01:00
Elias Naur beb046ac42 ap/internal/window: make cached JNI method descriptors global
We're about to remove all references to window from runOnMain callbacks.
The JNI methods are constant and can be moved out of window.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-10 11:22:42 +01:00
Elias Naur 759b796283 app: treat Invalidate more like InvalidateOp
Using Window.Invalidate for animation with, say

var w Window
var e FrameEvent

w.Invalidate()
e.Frame(...)

stops and immediately starts animation mode which is inefficient
and may cause jitter in the redraw timing.

InvalidateOp is the efficient and sure way to achieve smooth animation,
and Invalidate only exists for external events where there is nowhere to
add an InvalidateOp.

We can do better, so this change makes Invalidate almost as efficient as
InvalidateOp by checking for Invalidates at the same time we check for
InvalidateOps.

Note that we can't avoid the inefficiency in all cases, for example
when the calls above are swapped,

e.Frame(...)
w.Invalidate()

the Invalidate may not be registered before the check during Frame.

While here, add a note to Invalidate that it's meant for externally
triggered redraws.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-08 20:17:08 +01:00
Elias Naur 5f6fa25209 app/internal/window: [wasm] have at most one animation callback in flight
Track whether requestAnimationCallback has been called when SetAnimating
changes the animated state of the window. Multiple callbacks result in wasteful
redraws.

Without this change, my browser becomes unresponsive when Window.Invalidate
is called every frame. Calling Invalidate every frame is a misuse (InvalidateOp
should be used for animation), but it's nice to have reasonable behaviour.

This change might also fix the issues described in
https://github.com/gioui/gio/pull/7.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-08 10:41:07 +01:00
Inkeliz b430786f9b app/internal/window: [wasm] fix insets on Firefox
Insets must not be included if the `visualViewport` isn't available.

Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2021-01-07 09:51:46 +01:00
Inkeliz 07715a8125 cmd/gogio: remove windres dependency
Now, it's possible to compile to Windows (`-target windows`) without
having `windres`. The PNG icon, manifest and version info will be
generated and include using `gogio`.

Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2021-01-07 09:49:26 +01:00
pierre c030065af7 app: fixed swapped horizontal scrolling directions on Windows
Signed-off-by: pierre <pierre.curto@gmail.com>
2021-01-06 09:42:11 +01:00
Sebastien Binet 7bfdafb7b1 gpu: handle closure test for stroked path
Signed-off-by: Sebastien Binet <s@sbinet.org>
2021-01-03 14:03:23 +01:00
Elias Naur 72a3248041 gpu: implement GPU profiling for compute
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-03 13:27:59 +01:00
Elias Naur 8662790f10 gpu: remove unused field
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-03 13:05:10 +01:00
Elias Naur bb9252f9d4 gpu: cache path data for compute
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-02 20:18:05 +01:00
Elias Naur 23f710910f gpu: reclaim stale images in atlas texture before resizing
Issue found by Anthony Starks.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-02 18:28:41 +01:00
Sebastien Binet 5045a9e877 gpu: handle rounding errors when splitting quads
This CL handles rounding errors arising when splitting quads into linear
segments.
Rounding errors would lead to a pair of quad triplets (from,ctl,to) not
exactly matching.
ie: to(n-1) wouldn't exactly match from(n).

Signed-off-by: Sebastien Binet <s@sbinet.org>
2021-01-02 12:54:32 +01:00
Sebastien Binet 8676a73a91 internal/rendertest: use a YIQ-based algorithm to compare images
This PR implements an image comparison algorithm in the NTSC YIQ color
space, as described in:

  Measuring perceived color difference using YIQ NTSC
  transmission color space in mobile applications.
  Yuriy Kotsarenko, Fernando Ramos.

An electronic version is available at:

- http://www.progmat.uaem.mx:8080/artVol2Num2/Articulo3Vol2Num2.pdf

This should allow the image comparison to be a tad more robust than
comparing plain uint8 pixel values.

Signed-off-by: Sebastien Binet <s@sbinet.org>
2021-01-02 12:54:29 +01:00
Elias Naur 79016bcc4a gpu: close outline paths if not already closed
The new compute renderer is much less tolerant of discontinuous paths.
In particular, it requires that clip outlines form a closed loop.

Fixes TestPaintArc when GIORENDERER=forcecompute.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-02 12:40:54 +01:00
pierre 62a1d8ae6e layout: avoid copying whole constraints in Stack
Signed-off-by: pierre <pierre.curto@gmail.com>
2021-01-01 12:19:35 +01:00
Elias Naur d23514fd58 gpu: add compute implementation
The old renderer is still the default, so the new compute renderer will only be
used in the rare case the old renderer is not supported but the new is. That
happens on the Samsung J2 Prime and Moto C Android phones. Or set the
GIORENDERER environment variable to "forcecompute" to disable the old renderer:

$ GIORENDERER=forcecompute go run ...

Missing features:
- Gradients are not supported yet, and render as a solid color.
- Draw timers are not added, and profile.Events are not emitted.
- Stroked paths may in some cases appear corrupted because their clip
  outlines are not continuous when generated by Gio. Sebastien is
  working on a fix.
- The new renderer shares most CPU-side logic with the old renderer,
  resulting in several inefficient conversion steps between the old
  operations representation and the new. This is slower, but minimizes
  divergence in features and bugs between the two renderers.

Roadmap:
- The compute renderer supports features that Gio does not yet
exploit: stroked paths with round caps, transformations, lines,
cubic beziér curves.
- More stroke styles and maybe dashed strokes natively in shaders.
- Metal and Direct3D ports.

The most important feature is porting the renderer to run on the CPU. A
CPU renderer will both support Gio on devices with insufficient GPU
support, and allow us to remove the old renderer. Two renderers is twice
the maintenance but the feature set of the weakest implementation.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-12-31 17:21:35 +01:00
Elias Naur 0218546161 gpu/shaders: import compute programs from github.com/linebender/piet-gpu
The piet-gpu project is dual licensed under the Apache 2.0 and MIT, and the
shaders themselves are also offered under the UNLICENSE terms. See

https://github.com/linebender/piet-gpu#license-and-contributions, as of commit
72e2dfab3da8ae1adf7a0fb056b71ccbc4cfa29a:

"The piet-gpu project is dual-licensed under both Apache 2.0 and MIT licenses.

In addition, the shaders are provided under the terms of the Unlicense. The
intent is for this research to be used in as broad a context as possible."

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-12-31 17:21:35 +01:00
Elias Naur 6f2a98c667 gpu: make GPU an interface to prepare for second implementation
While here, merge BeginFrame and EndFrame; the split was done for
performance reasons, yet never measured.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-12-31 17:21:35 +01:00
Elias Naur b1ff179aa0 gpu,app,internal/glimpl: update GL backend for the compute renderer
Modern graphics APIs have immutable objects, with mutable data. For example,
a texture's dimensions are immutable, while the texture contents is not.
Change the GPU API abstraction to match.

Clearing a Texture is convenient to do with a plain []byte. Generalize
Texture.Upload to take a plain byte slice and introduce a helper function for
uploading *image.RGBA data.

Add TextureFormatRGBA8, a format for the linear RGB colorspace.

Add OpenGL ES 3.1 functions for compute programs.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-12-31 17:21:35 +01:00
Elias Naur e9403d8b18 internal/unsafe: add StructView
Needed by the compute renderer.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-12-31 17:21:35 +01:00
Elias Naur 269e7e0d7b internal/cmd/convertshaders: add support for compute shaders
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-12-31 17:21:35 +01:00
Elias Naur bfe2d04c60 gpu,app,internal/glimpl: update GL backend for the compute renderer
Modern graphics APIs have immutable objects, with mutable data. For example,
a texture's dimensions are immutable, while the texture contents is not.
Change the GPU API abstraction to match.

Clearing a Texture is convenient to do with a plain []byte. Generalize
Texture.Upload to take a plain byte slice and introduce a helper function for
uploading *image.RGBA data.

Add TextureFormatRGBA8 a format for the linear RGB colorspace.

Add OpenGL ES 3.1 functions for compute programs.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-12-31 17:21:35 +01:00
Elias Naur 7d24b790a2 gpu: add and track fields needed by the compute renderer
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-12-31 17:21:35 +01:00
Elias Naur 0a56609769 gpu: update definition of path vertex size
The size is unchanged, but a corner is no longer encoded as two
16-bit ints (2*2 bytes); it is encoded as a float32 (1*4 bytes).

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-12-31 17:21:35 +01:00
Elias Naur e012c3f393 internal/glimpl: [wasm] pass correctly sized buffers to WebGL functions
Before this change, the entire byte buffer would be passed to WebGL, even
though its size may be (much) larger than the source data.
Remakably, this hasn't resulted in any problems until the use of
glBufferSubData, which require the passed data fits the buffer size.

As a bonus, this fix should speed up the wasm port by virtue of passing
much less data across the wasm<->js barrier.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-12-31 12:31:57 +01:00
Elias Naur 7b1783056f app/internal/window: fix iOS context creation
NewBackend was recently changed to take a context, which must only
be specified on GOOS=js.

Fixes gio#189

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-12-30 18:38:21 +01:00
pierre 33103593a1 layout: updated comment, avoid copying whole context in Flex
Signed-off-by: pierre <pierre.curto@gmail.com>
2020-12-29 01:00:53 +01:00