LibWeb: Make sure painter's context is active before executing commands

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.
This commit is contained in:
Aliaksandr Kalenik 2024-01-18 20:26:31 +01:00 committed by Andreas Kling
parent aac439edb1
commit c6289fad49
4 changed files with 13 additions and 0 deletions

View file

@ -14,6 +14,7 @@ PaintingCommandExecutorGPU::PaintingCommandExecutorGPU(AccelGfx::Context& contex
: m_target_bitmap(bitmap)
, m_context(context)
{
m_context.activate();
auto canvas = AccelGfx::Canvas::create(bitmap.size());
auto painter = AccelGfx::Painter::create(m_context, canvas);
m_stacking_contexts.append({ .canvas = canvas,
@ -25,6 +26,7 @@ PaintingCommandExecutorGPU::PaintingCommandExecutorGPU(AccelGfx::Context& contex
PaintingCommandExecutorGPU::~PaintingCommandExecutorGPU()
{
m_context.activate();
VERIFY(m_stacking_contexts.size() == 1);
painter().flush(m_target_bitmap);
}
@ -418,6 +420,11 @@ void PaintingCommandExecutorGPU::prepare_glyph_texture(HashMap<Gfx::Font const*,
AccelGfx::GlyphAtlas::the().update(unique_glyphs);
}
void PaintingCommandExecutorGPU::prepare_to_execute()
{
m_context.activate();
}
void PaintingCommandExecutorGPU::update_immutable_bitmap_texture_cache(HashMap<u32, Gfx::ImmutableBitmap const*>& immutable_bitmaps)
{
painter().update_immutable_bitmap_texture_cache(immutable_bitmaps);

View file

@ -52,6 +52,8 @@ public:
virtual bool needs_prepare_glyphs_texture() const override { return true; }
void prepare_glyph_texture(HashMap<Gfx::Font const*, HashTable<u32>> const&) override;
virtual void prepare_to_execute() override;
bool needs_update_immutable_bitmap_texture_cache() const override { return true; }
void update_immutable_bitmap_texture_cache(HashMap<u32, Gfx::ImmutableBitmap const*>&) override;

View file

@ -448,6 +448,8 @@ void RecordingPainter::apply_scroll_offsets(Vector<Gfx::IntPoint> const& offsets
void RecordingPainter::execute(PaintingCommandExecutor& executor)
{
executor.prepare_to_execute();
if (executor.needs_prepare_glyphs_texture()) {
HashMap<Gfx::Font const*, HashTable<u32>> unique_glyphs;
for (auto& command_with_scroll_id : m_painting_commands) {

View file

@ -486,6 +486,8 @@ public:
virtual bool needs_prepare_glyphs_texture() const { return false; }
virtual void prepare_glyph_texture(HashMap<Gfx::Font const*, HashTable<u32>> const& unique_glyphs) = 0;
virtual void prepare_to_execute() { }
virtual bool needs_update_immutable_bitmap_texture_cache() const = 0;
virtual void update_immutable_bitmap_texture_cache(HashMap<u32, Gfx::ImmutableBitmap const*>&) = 0;
};