Procházet zdrojové kódy

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.
Aliaksandr Kalenik před 1 rokem
rodič
revize
c6289fad49

+ 7 - 0
Userland/Libraries/LibWeb/Painting/PaintingCommandExecutorGPU.cpp

@@ -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);

+ 2 - 0
Userland/Libraries/LibWeb/Painting/PaintingCommandExecutorGPU.h

@@ -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;
 

+ 2 - 0
Userland/Libraries/LibWeb/Painting/RecordingPainter.cpp

@@ -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) {

+ 2 - 0
Userland/Libraries/LibWeb/Painting/RecordingPainter.h

@@ -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;
 };