Commit Graph

423 Commits

Author SHA1 Message Date
pierre e0262c20e3 io/key: add NameSpace, report it on Linux
Fixes gio#204.

Signed-off-by: pierre <pierre.curto@gmail.com>
2021-03-12 13:18:08 +01:00
Peter Sanford 2aa1cc8112 Add new permission: networkstate
For android this provides ACCESS_NETWORK_STATE

Signed-off-by: Peter Sanford <psanford@sanford.io>
2021-03-08 08:19:22 +01:00
Elias Naur 7059b6284a app/internal/wm: rename confusing app/internal/window
Package wm (for "window manager") is a better fit for the package, and
distinguishes it from the low-level package windows for the Windows API.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-06 14:28:57 +01:00
Elias Naur 91a14c7fa2 app/internal/window: rename "backends" to "drivers"
"driver" is the new more specific name for gpu backends.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-06 14:27:44 +01:00
Elias Naur 7bc0603d7e internal/gl: rename internal/glimpl
Now that the OpenGL driver package is named "opengl", we can finally get
rid of the ugly "glimpl" name.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-06 14:27:44 +01:00
Elias Naur 2a66bfb2b4 gpu/headless: move package app/headless
Package headless is more about rendering that windows. Move it
accordingly.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-06 14:26:47 +01:00
Elias Naur 18a6dcf571 gpu/internal/d3d11: make the Direct3D backend internal to package gpu
The package app/internal/d3d11 now contains only the GPU backend on
Direct3D. Move it below package gpu to reflect that.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-06 14:26:47 +01:00
Elias Naur 5a9edc9af8 internal/cocoainit: move app/internal/cocoainit
We're about to move app/headless to gpu/headless, and it imports
cocoainit.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-06 14:26:47 +01:00
Elias Naur 3af4e6accf internal/egl: move app/internal/egl
We're about to move package app/headless to gpu/headless, and it needs
the egl package.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-06 14:26:47 +01:00
Elias Naur 86d17efc2c internal/srgb: move app/internal/srgb
We're about to move app/headless to gpu/headless, and it imports
package srgb indirectly.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-06 14:26:47 +01:00
Elias Naur e17dd5bd30 internal/d3d11: extract Direct3D API to separate package
We're about the merge the Direct3D backend into package gpu. Extract the
raw Direct3D API to its own package, just like package glimpl.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-06 14:26:25 +01:00
Elias Naur 8ff6546285 gpu,gpu/backend: implement generic backend.NewDevice
NewDevice creates a Device given an API, which is the necessary GPU
resources for a backend.

Convert gpu.New to take an API instead of a backend.Device directly.

In turn, this frees us to later unexport the backend package along with
the backend implementations (for now just gioui.org/gpu/gl for OpenGL).
It also allows programs that embed Gio (such as gioui.org/example/glfw)
to freely choose a backend, not just OpenGL.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-06 14:24:09 +01:00
Elias Naur 0e723fa192 app/internal/d3d11: change NewBackend to only require a ID3D11Device
Completing the goal of allowing foreign Direct3D contexts for our
D3D backend, slim down the constructor to take only the device handle.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-06 14:23:45 +01:00
Elias Naur c3dde562df app/internal/d3d11: only use passed in ID3D11Device in NewBackend
We're about to enable drawing into foreign Direct3D contexts. In
preparation, NewBackend should only need a device handle.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-06 14:22:58 +01:00
Elias Naur 932465d891 app/internal/d3d11: move features from Device to Backend
Continuing the previous change to minimize Device, in preparation
for supporting foreign Direct3D contexts.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-06 14:21:51 +01:00
Elias Naur 840b9ffa9b gpu/backend,gpu,app/internal/d3d11: move device state to backend
We'd like to allow Gio to share a Direct3D context with an embedding
program like the GLFW example does for OpenGL. To do that, d3d11.Device
needs to carry only the minimal information needed (ID3D11Device).

This change moves the caches of ID3D11DepthStencilState and
ID3D11BlendState from from d3d11.Device to d3d11.Backend. It also adds a
Release method for freeing them.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-06 14:21:51 +01:00
Elias Naur 44991f355c app/internal/d3d11: include depth buffer in current framebuffer query
Fixes rendering on Windows. Thanks to Egon Elbre for noticing.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-06 14:21:15 +01:00
Elias Naur 3627df7efa app/internal/d3d11,gpu/gl: simplify BeginFrame implementations
BeginFrame returns the output framebuffer, and need not be as general
as the newly unexported currentFramebuffer methods.

No functional change.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-04 14:08:39 +01:00
Elias Naur be04dfae83 app/headless: bind output framebuffer at render, not creation
Bind the framebuffer as late as possible to lessen the risk of
confusing global state (current framebuffer). Commit
25a19481e3 removed the assumption
that the framebuffer current at gpu.New would always be the output
framebuffer

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-04 14:08:39 +01:00
Elias Naur b1dfc94a9b app/internal/window: use golang.org/x/window UTF-16 routines
Less code, no functional change.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-04 14:08:39 +01:00
Elias Naur ffb26b0e17 io/pointer: rename button names to reflect their meaning, not placement
For example, ButtonLeft may be the right-most button for a left-handed user.
Rename the button names to match their intended use.

This is an API change. Use the following commands to update your
projects:

    $ gofmt -r 'pointer.ButtonLeft -> pointer.ButtonPrimary' -w .
    $ gofmt -r 'pointer.ButtonRight -> pointer.ButtonSecondary' -w .
    $ gofmt -r 'pointer.ButtonMiddle -> pointer.ButtonTertiary' -w .

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-03 11:08:41 +01:00
Elias Naur f36ed04380 app/headless,app/internal/window: unexport embedded Device fields
There is no need for the fields to be embedded nor exported.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-02 20:51:28 +01:00
Elias Naur fc56d438f3 app/internal/d3d11: don't track the Backend for a Device
A previous commit removed the assumption that the output framebuffer
is constant across frames. Thus it is no longer necessary to track
and update a backend's current framebuffer when the window is resized.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-02 20:44:56 +01:00
Elias Naur 25a19481e3 gpu,gpu/backend: don't assume constant output framebuffer
Return the output framebuffer from BeginFrame, to make it clear that
it may change between frames. Delete CurrentFramebuffer which is no
longer needed.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-02 20:43:59 +01:00
Elias Naur 3d3ff575e3 app/internal/windows,app/internal/d3d11: ensure error is returned
d3d11Context.Present would return a nil error if the underlying error
d3d11.ErrorCode.

While here, use defer for a resource cleanup.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-02 20:02:59 +01:00
Chris Waldon 54cddf5ca3 app/permission: update doc to reference app.ViewEvent
Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2021-03-01 08:24:06 +01:00
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