When building GPU vertices from paths, we call stroke.SplitCubic once
per OpCubic. Before this change, each call to stroke.SplitCubic would
allocate a slice, which we would only use to iterate over.
This allocation can be easily avoided by reusing the slice. We can
conveniently store it in gpu.quadSplitter.
In a real application that renders hundreds of paths with tens of
rounded rectangles per path, this saved roughly 4500 allocations (or 1
MB worth) per frame.
Signed-off-by: Dominik Honnef <dominik@honnef.co>
When the line overlaps itself backtracking exactly, e.g.
path.MoveTo(0, 100)
path.LineTo(100, 0)
path.LineTo(0, 100)
then acos calculation is relatively unstable. By using atan2 it avoids
some of such problems in the calculation. Additionally, it simpliflies
the round join calculation.
Fixes: https://todo.sr.ht/~eliasnaur/gio/474
Signed-off-by: Egon Elbre <egonelbre@gmail.com>
Apparently, alphaClose has been overflowing and giving the wrong answer
for a while and hence some of the tests are broken. I currently disabled
those tests, because I'm not quite sure where and how they broke.
Also, bumped alpha tolerance to 8, to ignore false positives.
Signed-off-by: Egon Elbre <egonelbre@gmail.com>
All GPU APIs except OpenGL ES 2 can generate mipmaps for textures.
This trades 33% more GPU memory use for improved rendering quality
and speed for downscaled images.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit switches the priority of EGL and Vulkan so that EGL is always
tried first. This is because our EGL backend performs significantly better
than the Vulkan one, and we want the most performant experience to be the
default.
Our hypothesis is that the EGL backend is benefitting from lots of optimization
within the OpenGL driver that Vulkan drivers expect applications to perform
themselves. Rather than invest a bunch of time optimizing the Vulkan backend
right now, this change lets us focus on other priorities.
Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
The Nix version of the macOS toolchain has difficulties compiling
Objective-C modules; disable modules instead of figuring out why.
It also doesn't include any frameworks automatically; add them explicitly.
While here, move suppression of OpenGL deprecation to a GL-specific
file.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
By keeping all the information in a single map, we avoid multiple
lookups and can switch between frames more easily.
Before ~35us, after ~20us for adding 50 new+old and switching
the frame.
Signed-off-by: Egon Elbre <egonelbre@gmail.com>
splitTransform func was creating multiple copies of f32.Affine2D
due to not having access to the internal and passing around non-pointer.
This makes splitTransform from ~8ns to .Split ~2ns.
It seems that the non-pointer receiver was ~0.6ns slower in this case.
Signed-off-by: Egon Elbre <egonelbre@gmail.com>
Apparently, there is a rounding error somewhere in the pipeline
from clearing a FBO to downloading its contents on at least one Apple
M1 machine. Tweak the test colors a bit to make it pass.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Direct3D requires GPU vertex attribute structs sizes be a multiple
16. A cleanup commit removed an unusued field, and broke that
assumption.
Fixes: https://todo.sr.ht/~eliasnaur/gio/422
Signed-off-by: Elias Naur <mail@eliasnaur.com>
There are no public API that uses f32.Rectangle anymore. Move Rectangle
to an internal package for internal use.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Like the change to op.Offset before this, clip.RRect and UniformRRect
is usually used with integer coordinates. Change to integer coordinates
to eliminate many useless conversions to float32.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
op.Offset is a convenience function most often used by layouts. Layouts
usually operate in integer coordinates, and the float32 version of op.Offset
needlessly force conversions from int to float32. This change makes op.Offset
take integer coordinates, to better match its intended use.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
OpenGL ES 2.0 doesn't support GL_PACK_ROW_LENGTH, so this change implements
a fallback using a temporary buffer.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Creating an image.Rectangle from a f32.Rectangle is used by two packages in Gio
and about to be used for a third. Add a Round method to f32.Rectangle to avoid
duplicating the implementation.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
vkDeviceWaitIdle and vkQueueWaitIdle are expensive; a vkFence is cheaper
and the usual way to ensure a previous frame has completed before starting
another.
References: https://todo.sr.ht/~eliasnaur/gio/375
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Backend.queryState sets GL_ACTIVE_TEXTURE to access texture bindings; this change
makes sure GL_ACTIVE_TEXTURE is restored.
Also, make sure GL state changes made in Backend.restoreState is reflected
in Backend.glstate. Backend.glstate is not used after restoreState, so this
is just for clarity.
This is an alternative to https://github.com/gioui/gio/pull/77.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Multiple operations Op, such as clip.Path, cannot
be interleaved with other ops. This patch adds a
mechanism to ensure that is the case by starting
multi ops with ops.BeginMulti and ending them with
ops.EndMulti while operations are written to op.Ops
with ops.WriteMulti.
This mechanism is applied to clip.Path.
Fixes: https://todo.sr.ht/~eliasnaur/gio/336
Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
For some reason, the Android emulator OpenGL implementation needs the output
framebuffer current when eglSwapBuffers is called; otherwise sRGB emulation
breaks. We used to restore the default FBO explicitly, 9b5e9ae607
restored it implicitly through automatic state restoring, but 30ecf75a0f
broke that by only saving and restoring shared context state. This change
restores the explicit behaviour for non-shared contexts.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
OpenGL stores the current context in thread-local memory, but commit
4f5baa9a51 removed a runtime.LockOSThread from app.Window that ensured
the goroutine that drives the context stays on the operating thread that
has the context current. This change restores the thread lock.
As a bonus, this change makes the OpenGL contexts responsible for locking
the thread at MakeCurrent, thereby removing LockOSThread calls from GPU
backend-agnostic code.
Fixes: https://todo.sr.ht/~eliasnaur/gio/334
Signed-off-by: Elias Naur <mail@eliasnaur.com>
When extracting headless.Window's content via screenshots,
it can be useful to keep reusing the same image for output,
as well as specify which area of the Window is to be
extracted.
The updated Screenshot method does this by using the supplied
image.
API change: users must pass an existing image to Window.Screenshot.
Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
Ever since commit 8ff654628, the headless implementation has used two
GPU backend (not renderer) instances, one for the renderer and one for
creating the offscreen texture to render into. This arrangment leaks
resources because the backends only clear temporary storage at
BeginFrame, which is not called when reading pixel data from renders.
This change adds an internal constructor, gpu.NewWithDevice, to allow
headless.Window to share its device with the renderer, fixing the leak.
It also makes the code simpler (took me a while to debug this issue); in
fact I'm surprised it even works.
This is not a great fix: it adds an exported yet internal constructor,
and the ownership transfer of the device is surprising enough to warrant
two comments.
Fixes gio#322
Signed-off-by: Elias Naur <mail@eliasnaur.com>
The novulkan tag didn't completely disable the Vulkan backend, and
the backend wouldn't register on FreeBSD. This change fixes both
issues.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This change is a follow-up to bcf3ff77ff, fixing the two renderers to
properly render images with non-zero origins.
Signed-off-by: Pierre Curto <pierre.curto@gmail.com>