Commit Graph

397 Commits

Author SHA1 Message Date
Egon Elbre f6fba73885 internal/cmd/convertshaders: add Windows comp shader compilation
Use dxc (DirectXShaderCompiler) for compiling, which is newer than fxc
and doesn't not fail compilation with dynamically uniform flows with
barriers.

Currently requires -directcompute to enable generating the shaders.

Signed-off-by: Egon Elbre <egonelbre@gmail.com>
2021-02-25 13:01:18 +01:00
Elias Naur 9d1e3370f4 app/internal/window: fix Wayland clipboard reading
The Wayland protocol implicitly dup(2)s the pipe write end descriptor passed to
wl_data_offer_receive. As long as we also have an open descriptor for the write
end, the pipe will not close and signal the completion of the clipboard read.

This change explicitly and immediately closes our write descriptor. Before this
change, reading the Wayland clipboard worked with some delay because the Go
garbage collector closed the write end of the transfer pipe after some time.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-02-21 14:36:36 +01:00
Paulo Melo 3987815469 app: change background for js
Default window background is white.
JS default background is transparent black.

Signed-off-by: Paulo Melo <paulo.durrer.melo@gmail.com>
2021-02-18 08:07:08 +01:00
pierre a581acf3fd io/pointer: added the grab cursor
Signed-off-by: pierre <pierre.curto@gmail.com>
2021-02-08 09:15:14 +01:00
pierre 1100e03c1e io/router: support cursor changes on Frame events
Add support to Router so that the cursor can be changed with CursorNameOp without any mouse movement.
Enter and Leave events are also delivered as areas change.

Signed-off-by: pierre <pierre.curto@gmail.com>
2021-01-27 22:21:27 +01:00
pierre d604455582 app: added windows.TRUE for Windows
Signed-off-by: pierre <pierre.curto@gmail.com>
2021-01-27 22:21:18 +01:00
pierre f7d1f46c1f app: make cursor support more robust on Windows
Post a dedicated message upon Window.SetCursor calls.
Make sure that the cursor is only changed if the cursor is in the window.

Signed-off-by: pierre <pierre.curto@gmail.com>
2021-01-27 17:51:45 +01:00
Elias Naur 84b586ae6c gpu: don't automatically clear screen before rendering
Gio UI may be overlaid on top of custom graphics such as in the glfw example.
That will only work if Gio doesn't clear the screen (to white).

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-22 18:33:34 +01:00
Elias Naur 4f45d9a567 io/router: rename Router.Add to the more specific Queue
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-22 16:36:14 +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
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
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
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 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 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
Inkeliz 449dda2eb3 app/internal/window: [wasm] add support for insets and cache window-size
Currently, on iOS, the keyboard can block the content since it doesn't
trigger the "resize". Now, the `insets` will provide the size of the
keyboard (on iOS) and scrollbars. It's compatible with the Android (and
desktop), but Chrome automatic resizes the windows, so the `Inset` will
be 0.

Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2020-12-19 10:32:56 +01:00
Elias Naur 40c082e949 app/internal/window: use defer for cleanup function
Avoids a vet warning about unreachable code: currently, the cleanup
function is never reached.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-12-18 10:18:21 +01:00
Inkeliz c2a66a5481 app/internal/window: fix support for Safari 11.1
Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2020-12-18 10:02:54 +01:00
Elias Naur cb075ea9cf app/headless,internal/rendertest: relax tests
The Mesa software OpenGL implementation strays enough from the
reference values that tests fail. Relax the tests to make them
pass again.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-12-17 20:48:30 +01:00
Elias Naur fac1d00c89 app/internal/egl: support EGL_KHR_no_config_context
The mesa surfaceless renderer doesn't support configs, but does
support EGL_KHR_no_config_context so no config is required. Don't
fail context creation in this setup.

With this change, the headless tests work on a headless linux with the
EGL_PLATFORM environment variable set to "surfaceless".

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-12-17 20:31:04 +01:00
Walter Werner SCHNEIDER 83d23ab507 all: sort and group imports
Signed-off-by: Walter Werner SCHNEIDER <contact@schnwalter.eu>
2020-12-17 08:55:09 +01:00
Robin Eklind f3ce6ad29a app/internal/window: fix golint issues
app/internal/window/os_wayland.go:1448:12: gioui.org/io/system.StageEvent composite literal uses unkeyed fields
	app/internal/window/os_x11.go:183:12: gioui.org/io/system.StageEvent composite literal uses unkeyed fields

Signed-off-by: Robin Eklind
2020-12-16 02:09:39 +01:00
Elias Naur 5839e3e8d5 app/internal/window: don't use C.BOOL
Apparently, darwin/arm64 cgo doesn't match the types of YES and BOOL:

os_macos.go:235:40: cannot use _Ciconst_YES (type untyped int) as type _Ctype__Bool

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-12-14 23:40:29 +01:00
Inkeliz 0dfb04eb2d app/internal/window: [windows] add icon support
That change adds the icon to the "window navbar".

Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2020-12-11 20:24:33 +01:00
Inkeliz b79c2dec79 app/internal/window: [wasm] fix on-screen-keyboard
Previously, the keyboard is open by default, even without any focus.
Now, the keyboard will remain closed, until `.focus()` is called. That
change also prevents the keyboard from reopening immediately after blur.

Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2020-12-11 16:43:31 +01:00
pierre 7c5bcd3db8 io/pointer: added CursorNameOp
The cursor can now be customized for a given area.

Signed-off-by: pierre <pierre.curto@gmail.com>
2020-12-09 09:38:31 +01:00
Inkeliz a76f816ae9 io/clipboard,app: add WriteOp, ReadOp
Previously, the only way to manipulate the clipboard (read or write) is
using the `app.Window`.

The new `clipboard.ReadOp` and `clipboard.WriteOp`makes possible to
read/write from the widget.

Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2020-12-06 22:15:16 +01:00
Inkeliz fb5e2ee9ec app/internal/window: [wasm] add support for StageEvent
Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2020-12-06 09:12:22 +01:00
Inkeliz 828f19304b app: move system.ClipboardEvent to its own package
API change. Update your code with gofmt rule and goimports:

gofmt -r "system.ClipboardEvent -> clipboard.Event"
goimports

Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-12-05 10:20:55 +01:00
Walter Werner SCHNEIDER feb93baee0 app/internal/window: use unsafe pointer to array
Signed-off-by: Walter Werner SCHNEIDER <contact@schnwalter.eu>
2020-12-05 09:46:12 +01:00
Elias Naur ffe5ab51a2 gpu/gl: remove OpenGL functions parameter from NewBackend
As a consequence, most API is gone from gpu/gl, and embedding Gio in
foreign frameworks don't need to provide an OpenGL implementation.

The next change simplifies the GLFW embedding example accordingly.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-12-04 20:50:22 +01:00
Elias Naur b8e33bb420 app/internal/glimpl: derive version parameter in Functions.Init
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-12-04 20:41:34 +01:00
Elias Naur 8c9466e03e app/internal/window: [iOS] disable cursor support
Building an iOS results in errors about missing NSCursor:

$ gogio -target ios -o app.app ./kitchen
gogio: go build -ldflags=-s -w -X gioui.org/app/internal/log.appID=org.gioui.kitchen -buildmode=c-archive -o /var/folders/_7/lnt35k555hl2bs7fjygkhgx00000gp/T/gogio-770783182/gio-amd64 -tags  ./kitchen failed: # gioui.org/app/internal/window
os_darwin.m:26:10: error: use of undeclared identifier 'NSCursor'
os_darwin.m:32:10: error: use of undeclared identifier 'NSCursor'
os_darwin.m:40:14: error: use of undeclared identifier 'NSCursor'
os_darwin.m:43:14: error: use of undeclared identifier 'NSCursor'
os_darwin.m:46:14: error: use of undeclared identifier 'NSCursor'
os_darwin.m:49:14: error: use of undeclared identifier 'NSCursor'
os_darwin.m:52:14: error: use of undeclared identifier 'NSCursor'
os_darwin.m:55:14: error: use of undeclared identifier 'NSCursor'
os_darwin.m:58:14: error: use of undeclared identifier 'NSCursor'

NSCursor is supported under mac catalyst; disable NSCursor support while
figuring out how.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-12-04 20:38:53 +01:00
Elias Naur 7ef591d0ec app/internal/window: [Android] ignore setCursor when not supported
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-12-04 12:13:07 +01:00
Elias Naur d29cf52595 app/internal/window: fix missing Windows cursor
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-12-04 10:08:37 +01:00
pierre 69cc2c795c app: add support for system cursors
Signed-off-by: pierre <pierre.curto@gmail.com>
2020-12-03 16:45:17 +01:00
Inkeliz b9846b48b8 app/internal/glimpl: [wasm] remove slow getError calls
The removal of getError significantly improves performance on js/wasm:

Opera 72 (w/ AMD Ryzen 3900X): ~12.29ms per frame to ~8.09ms;
Chrome 87 (w/ Snapdragon 435): ~156.34ms per frame to ~94.31ms;

Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2020-12-01 08:19:45 +01:00
Pierre Curto 4c3de5f5d2 app: support horizontal scrolling on Windows and Linux
Fixes #181.

Signed-off-by: pierre <pierre.curto@gmail.com>
2020-11-27 09:24:48 +01:00
Inkeliz 689b317de9 app/internal/window: add support for system.CommandBack on wasm
To get the `popstate` we need to create a new entry into
the browser history. Then, Gio will handle the "back" and
"forward" of the page.

In some browsers (Chrome 87/Edge 87): The user must
click inside the window/page at least one time. It will not
work if the user leaves the page  (clicking back button)
without interaction with Gio.

Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2020-11-21 16:52:48 +01:00
Raffaele Sena 8a3ff4abcb app/internal/window: implement key.Press and key.Release on macOS
Update key.State documentation and add State.String while here. Also
update Event.String to include State.

Signed-off-by: Raffaele Sena <raff367@gmail.com>
2020-11-21 09:10:14 +01:00
Inkeliz e195309d55 app/internal/window: mitigate keyboard issue on WASM iOS
That change mitigates the issue gio#150 and gio#166. The
iOS can only `focus()` as a response to touchstart/click
events. We can't `focus()` at random, without user interaction.

The `w.requestFocus` will try to focus on the next `touchstart`,
which may need some "double click" in some cases. That mitigates
the issue, but doesn't fixes completely, but open the keyboard. (:

I didn't notice any side-effect of that change on Android and on
Windows.

Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2020-11-21 09:09:47 +01:00
Inkeliz fb15547b7a app/internal/window: remove context-menu (right-click) for wasm
The context-menu seems useless. The only action available, on the
context-menu is to "Save image": which gives a black image.

I think it's better to remove it. The right-click still work and still
provide `pointer.Event`.

Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2020-11-21 09:09:35 +01:00
Inkeliz 7ca00d5d34 app/internal/window: fix enter-key for android
Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2020-11-19 20:54:19 +01:00