mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:27:35 +00:00
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.
This commit is contained in:
parent
efdbd8238e
commit
32ea11d45c
2 changed files with 196 additions and 11 deletions
|
@ -1,18 +1,22 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2023, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/Noncopyable.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibAccelGfx/Canvas.h>
|
||||
#include <LibAccelGfx/Forward.h>
|
||||
#include <LibAccelGfx/Program.h>
|
||||
#include <LibGfx/AffineTransform.h>
|
||||
#include <LibGfx/Font/Font.h>
|
||||
#include <LibGfx/Forward.h>
|
||||
#include <LibGfx/TextLayout.h>
|
||||
|
||||
namespace AccelGfx {
|
||||
|
||||
|
@ -45,6 +49,20 @@ public:
|
|||
void draw_scaled_bitmap(Gfx::FloatRect const& dst_rect, Gfx::Bitmap const&, Gfx::FloatRect const& src_rect, ScalingMode = ScalingMode::NearestNeighbor);
|
||||
void draw_scaled_bitmap(Gfx::IntRect const& dst_rect, Gfx::Bitmap const&, Gfx::IntRect const& src_rect, ScalingMode = ScalingMode::NearestNeighbor);
|
||||
|
||||
void prepare_glyph_texture(HashMap<Gfx::Font const*, HashTable<u32>> const& unique_glyphs);
|
||||
|
||||
struct GlyphsTextureKey {
|
||||
Gfx::Font const* font;
|
||||
u32 code_point;
|
||||
|
||||
bool operator==(GlyphsTextureKey const& other) const
|
||||
{
|
||||
return font == other.font && code_point == other.code_point;
|
||||
}
|
||||
};
|
||||
|
||||
void draw_glyph_run(Vector<Gfx::DrawGlyphOrEmoji> const& glyph_run, Color const& color);
|
||||
|
||||
void set_canvas(Canvas& canvas) { m_canvas = canvas; }
|
||||
void flush();
|
||||
|
||||
|
@ -65,6 +83,22 @@ private:
|
|||
|
||||
Program m_rectangle_program;
|
||||
Program m_blit_program;
|
||||
|
||||
HashMap<GlyphsTextureKey, Gfx::IntRect> m_glyphs_texture_map;
|
||||
Gfx::IntSize m_glyphs_texture_size;
|
||||
GLuint m_glyphs_texture;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
namespace AK {
|
||||
|
||||
template<>
|
||||
struct Traits<AccelGfx::Painter::GlyphsTextureKey> : public GenericTraits<AccelGfx::Painter::GlyphsTextureKey> {
|
||||
static unsigned hash(AccelGfx::Painter::GlyphsTextureKey const& key)
|
||||
{
|
||||
return pair_int_hash(ptr_hash(key.font), key.code_point);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue