1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 21:57:35 +00:00

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.
This commit is contained in:
Aliaksandr Kalenik 2023-11-15 20:39:15 +01:00 committed by Andreas Kling
parent 61a2e59d87
commit f6a9f613c7
3 changed files with 119 additions and 2 deletions

View file

@ -17,6 +17,7 @@
#include <LibGfx/AffineTransform.h>
#include <LibGfx/Font/Font.h>
#include <LibGfx/Forward.h>
#include <LibGfx/Gradients.h>
#include <LibGfx/TextLayout.h>
namespace AccelGfx {
@ -73,6 +74,9 @@ public:
void set_target_bitmap(Gfx::Bitmap&);
void flush();
void fill_rect_with_linear_gradient(Gfx::IntRect const&, ReadonlySpan<Gfx::ColorStop>, float angle, Optional<float> repeat_length = {});
void fill_rect_with_linear_gradient(Gfx::FloatRect const&, ReadonlySpan<Gfx::ColorStop>, float angle, Optional<float> repeat_length = {});
private:
Context& m_context;
@ -89,6 +93,7 @@ private:
Program m_rectangle_program;
Program m_blit_program;
Program m_linear_gradient_program;
HashMap<GlyphsTextureKey, Gfx::IntRect> m_glyphs_texture_map;
Gfx::IntSize m_glyphs_texture_size;