Commit Graph

44 Commits

Author SHA1 Message Date
Aliaksandr Kalenik
980b61470c LibAccelGfx+LibWeb+WebContent: Handle OpenGL Context init errors
Now, if OpenGL context fails, an error will be returned and a message
printed, instead of crashing.
2024-01-24 19:43:51 +01:00
Aliaksandr Kalenik
aac439edb1 LibAccelGfx: Add method to make context active
In the upcoming changes, the AccelGfx context will be used for WebGL, so
we can no longer assume that the WebContent process has a single global
context.
2024-01-20 18:21:56 +01:00
Aliaksandr Kalenik
bd08b1815f LibWeb: Implement border radius corner clipping in GPU painter
It is implemented in the way identical to how it works in CPU painter:
1. SampleUnderCorners command saves pixels within corners into a
   texture.
2. BlitCornerClipping command uses the texture prepared earlier to
   restore pixels within corners.
2023-12-17 23:12:48 +01:00
Aliaksandr Kalenik
38d62563b3 LibAccelGfx: Fix stack use after scope in GlyphAtlas::update() 2023-12-17 14:55:41 +01:00
Aliaksandr Kalenik
4a2a37275e LibAccelGfx: Remove ability to change target canvas in painter
It is easier to build painter assuming target canvas won't change and
we don't use this api anyway :)
2023-12-16 19:39:36 +01:00
Aliaksandr Kalenik
161082e282 LibAccelGfx+LibWeb: Explicitly pass OpenGL context to Painter
Let's not assume there is one global OpenGL context because it might
change once we will start creating >1 page inside single WebContent
process or contexts for WebGL.
2023-12-16 19:39:36 +01:00
Aliaksandr Kalenik
55c483b763 LibAccelGfx: Add missing bind_target_canvas() in Painter::clear() 2023-12-16 14:35:47 +01:00
Aliaksandr Kalenik
0d03257e69 LibGfx+LibAccelGfx+LibWeb: Use RefPtr for font in DrawGlyphOrEmoji 2023-12-10 17:32:04 +01:00
Aliaksandr Kalenik
a88807e5b3 LibAccelGfx: Update scissor test after switching between painters
Since scissor clip rect is a part of OpenGL global state we need to
update it after switching between painters.
2023-12-05 10:29:55 +01:00
Aliaksandr Kalenik
5c0cd0f484 LibAccelGfx+LibWeb: Add text shadow support in GPU painter 2023-12-05 09:09:56 +01:00
Aliaksandr Kalenik
2361ce25a0 LibAccelGfx: Set blending for alpha separately to be sum of src and dst
With this change we match blending in LibGfx and it fixes rendering on
all websites that use opacity < 1.
2023-12-04 20:51:00 +01:00
Aliaksandr Kalenik
c28f6828c9 LibAccelGfx+LibWeb: Support non-translation transforms in GPU painter
This change introduces GPU painter support for rotate(), skew(),
scale(), and other transformations that could be applied to stacking
context.
2023-12-01 09:28:10 +01:00
Aliaksandr Kalenik
24da32c884 LibAccelGfx+LibWeb: Store state of all stacking contexts in GPU painter
This change ensures that the GPU painting executor follows the pattern
of the CPU executor, where the state is stored for each stacking
context, but a painter is created only for those with opacity.

Fixes crashing on apple.com because now save() and restore() are called
on correct painters.
2023-11-29 21:48:47 +01:00
Aliaksandr Kalenik
9a66f31b64 LibAccelGfx: Deallocate VAO and VBOs in fill_rect_with_linear_gradient
Fixes memory leak in fill_rect_with_linear_gradient()
2023-11-29 21:47:43 +01:00
Aliaksandr Kalenik
707added91 LibAccelGfx: Premultiply linear gradient colors by alpha
With this change color blending for gradients matches CPU painter.
2023-11-29 13:53:23 +01:00
Aliaksandr Kalenik
17fb82d49b LibAccelGfx+LibWeb: Discard painting of commands outside of viewport 2023-11-26 21:26:26 +01:00
Aliaksandr Kalenik
c68a9b2cfe LibAccelGfx: Skip glyph atlas rebuild if all needed glyphs are present
Before this change, every repaint required a glyph atlas update, which
took 10-20% of the total painting time according to my testing on
different websites. This change improves that significantly by skipping
atlas updated when all glyphs are already present in the texture.
2023-11-26 21:26:26 +01:00
Aliaksandr Kalenik
28723d8be1 LibAccelGfx+LibWeb: Move glyph atlas into a singleton class
This is going to allow us reuse glyph texture across painters and page
repaints.
2023-11-26 21:26:26 +01:00
Aliaksandr Kalenik
a1c8fb10fa LibAccelGfx+LibWeb: Add texture cache for immutable bitmaps
This change introduces a texture cache for immutable bitmaps in the
GPU painter. The cache is persisted across page repaints, so now, on
page scroll repaint, in many cases, we won't need to upload any new
textures. Also, if the same image is painted more than once on a page,
its texture will only be uploaded once.

Generally, the GPU painter works much faster with this change on all
pages that have images.
2023-11-26 12:55:43 +01:00
Aliaksandr Kalenik
5f7ac559a7 LibAccelGfx+LibWeb: Add support for stacking context opacity
For each stacking context with an opacity less than 1, we create a
separate framebuffer. We then blit the texture attached to this
framebuffer with the specified opacity.

To avoid the performance overhead of reading pixels from the texture
into Gfx::Bitmap, a new method that allows for direct blitting from
the texture is introduced, named blit_scaled_texture().
2023-11-24 08:39:55 +01:00
Aliaksandr Kalenik
cb90daadc7 LibAccelGfx: Add cache for programs
Having programs cache shared between painters would allow us to create
more than one painter without worrying about shaders recompilation.
2023-11-24 08:39:55 +01:00
Aliaksandr Kalenik
d5630fedf1 LibAccelGfx+WebContent: Introduce Canvas that represents framebuffer 2023-11-24 08:39:55 +01:00
Aliaksandr Kalenik
790bfd7ef9 LibAccelGfx: Skip glyphs with missing bitmaps
Fixes crashing when we can't produce a bitmap for a glyph.
2023-11-21 17:00:56 +01:00
Aliaksandr Kalenik
48faa0e706 LibAccelGfx: Ensure capacity of vertices vector in draw_glyph_run() 2023-11-21 17:00:56 +01:00
Aliaksandr Kalenik
1b0cc67a28 LibAccelGfx+LibWeb: Add basic push/pop stacking context implementation
With basic PushStackingContext and PopStackingContext commands
implementation scrolling works again after changes being made in:
4e04f81626
2023-11-20 23:44:19 +01:00
Aliaksandr Kalenik
2579b01be8 LibAccelGfx: Add missing painter transform applications
Adds missing painter's transform to rect in:
- fill_rect_with_rounded_corners()
- fill_rect_with_linear_gradient()
- draw_glyph_run()
- set_clip_rect()
2023-11-20 23:44:19 +01:00
Aliaksandr Kalenik
53c015695e LibAccelGfx+LibWeb: Implement rounded corners rectangle painting
For now corners antialiasing is missing.
2023-11-20 19:35:25 +01:00
Aliaksandr Kalenik
f6a9f613c7 LibAccelGfx+LibWeb: Add basic support for linear gradients painting
Linear gradient painting is implemented in the following way:
1. The rectangle is divided into segments where each segment represents
   a simple linear gradient between an adjacent pair of stops.
2. Each quad is filled separately using a fragment shader that
   interpolates between two colors.

For now `angle` and `repeat_length` parameters are ignored.
2023-11-16 18:02:51 +01:00
Aliaksandr Kalenik
61a2e59d87 LibAccelGfx+WebContent: Add GPU painter support on macOS
With these changes it is now possible to create OpenGL context on macOS
and run GPU-painter. For now only QT client has a CLI param that turns
it on though.
2023-11-16 15:13:16 +01:00
Aliaksandr Kalenik
01d938c77b LibAccelGfx+LibWeb: Implement SetClipRect and ClearClipRect commands 2023-11-13 19:22:27 +01:00
Aliaksandr Kalenik
6d1a1daff9 LibAccelGfx+LibWeb: Use framebuffer object instead of EGLs PBuffer
Framebuffer object is allocated using OpenGL's API and is not platform
specific which means it could be used on both macOS and Linux unlike
EGL specific PBuffer.
2023-11-11 22:19:43 +01:00
Aliaksandr Kalenik
99caf4e649 LibAccelGfx: Switch from OpenGL ES 2.0 to OpenGL 3.3
Desktop OpenGL 3.3 is currently supported by both EGL on Linux and
macOS.
2023-11-11 22:19:43 +01:00
Aliaksandr Kalenik
2d12d1538d LibAccelGfx: Create VBO to pass vertices data to GPU
Before, we were using a feature of OpenGL that allows specifying a
pointer to allocated vertex data without creating VBO and VAO, but as
I found out, it does not work on macOS.
2023-11-11 22:19:43 +01:00
Aliaksandr Kalenik
048e179572 LibAccelGfx: Use wrapping functions with error check for OpenGL calls
This change introduces GL.h with error check wrappers for all the
OpenGL functions we used so far.

For now, the error check is simply:
`VERIFY(glGetError() == GL_NO_ERROR);`
but that is better than continuing execution after encounting an error.
2023-11-11 08:47:12 +01:00
Tim Schumacher
a2f60911fe AK: Rename GenericTraits to DefaultTraits
This feels like a more fitting name for something that provides the
default values for Traits.
2023-11-09 10:05:51 -05:00
Aliaksandr Kalenik
28118623f5 LibAccelGfx+LibWeb: Add basic line painting support
For now only solid line style is supported.
2023-11-09 10:47:31 +01:00
Aliaksandr Kalenik
f1824a524d LibAccelGfx: Add 1px padding between glyphs in prepare_glyph_texture()
This fixes bug when tiny slice of another glyph appearing along with
the required glyph.
2023-11-09 07:56:45 +01:00
Aliaksandr Kalenik
32ea11d45c LibAccelGfx: Introduce glyph run painting support
Text painting operates in two steps:

1. Preparation of a texture that contains all the glyphs required for
   text painting, along with metadata that describes the locations of
   those glyphs within texture beforehand.
2. Blitting glyphs from the prepared texture onto corresponding glyph
   quads.

Users of LibAccelGfx will need to call `prepare_glyphs_texture()`,
passing a set of all unique (font, code_paint) pairs, before painting
any text.
2023-11-06 09:53:11 +01:00
Aliaksandr Kalenik
aa6c008450 LibAccelGfx+LibWeb: Implement draw_scaled_bitmap()
Very basic implementation of command to paint bitmap. In the future we
should reuse loaded textures across repaints whenever it is possible.
2023-11-02 07:41:51 +01:00
Aliaksandr Kalenik
b7f8d7e357 LibAccelGfx: Compile all needed shaders during Painter construction
Instead of recompiling shaders on each paint command call we can
compile them once.
2023-11-02 07:41:51 +01:00
Aliaksandr Kalenik
1e85bf221d LibAccelGfx+WebContent: Use the same Painter across page repaints
In the upcoming changes, Painter will be used to store the state of
OpenGL context. For example, if Painter is aware of the shader that
have already been loaded, it will be possible to reuse them across
repaints. Also, it would be possible to manage state of loaded textures
and add/remove them depending on which ones are present in the next
sequence of painting commands.
2023-11-02 07:41:51 +01:00
Andrew Kaster
2cc6abf309 LibAccelGfx: Don't predicate using EGL/egl.h on Linux
Any platform that has OpenGL and EGL should be able to use the class.
2023-11-01 14:30:30 -06:00
Andrew Kaster
49d21619d4 CMake: Use a helper file to find GL and EGL in a platform agnostic way
Also add a flag to turn off accelerated graphics entirely.
2023-10-31 02:32:58 -06:00
Aliaksandr Kalenik
95c154d9bd LibAccelGfx+Meta: Introduce OpenGL painting library
This change introduces a new 2D graphics library that uses OpenGL to
perform painting operations. For now, it has extremely limited
functionality and supports only rectangle painting, but we have to
start somewhere.

Since this library is intended to be used by LibWeb, where the
WebContent process does not have an associated window, painting occurs
in an offscreen buffer created using EGL.

For now it is only possible to compile this library on linux.
Offscreen context creation on SerenityOS and MacOS will have to be
implemented separately in the future.

Co-Authored-By: Andreas Kling <awesomekling@gmail.com>
2023-10-29 17:13:23 +01:00