Explorar el Código

LibWeb: Implement draw_glyph_run in PaintingCommandExecutorGPU

Aliaksandr Kalenik hace 1 año
padre
commit
b6da9abfb2

+ 3 - 0
Userland/Libraries/LibWeb/Painting/PaintingCommandExecutorCPU.h

@@ -48,6 +48,9 @@ public:
 
     bool would_be_fully_clipped_by_painter(Gfx::IntRect) const override;
 
+    bool needs_prepare_glyphs_texture() const override { return false; }
+    void prepare_glyph_texture(HashMap<Gfx::Font const*, HashTable<u32>> const&) override {};
+
     PaintingCommandExecutorCPU(Gfx::Bitmap& bitmap);
 
 private:

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

@@ -18,9 +18,9 @@ PaintingCommandExecutorGPU::~PaintingCommandExecutorGPU()
     m_painter.flush();
 }
 
-CommandResult PaintingCommandExecutorGPU::draw_glyph_run(Vector<Gfx::DrawGlyphOrEmoji> const&, Color const&)
+CommandResult PaintingCommandExecutorGPU::draw_glyph_run(Vector<Gfx::DrawGlyphOrEmoji> const& glyph_run, Color const& color)
 {
-    // FIXME
+    painter().draw_glyph_run(glyph_run, color);
     return CommandResult::Continue;
 }
 
@@ -238,4 +238,9 @@ bool PaintingCommandExecutorGPU::would_be_fully_clipped_by_painter(Gfx::IntRect)
     return false;
 }
 
+void PaintingCommandExecutorGPU::prepare_glyph_texture(HashMap<Gfx::Font const*, HashTable<u32>> const& unique_glyphs)
+{
+    m_painter.prepare_glyph_texture(unique_glyphs);
+}
+
 }

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

@@ -50,6 +50,9 @@ public:
 
     bool would_be_fully_clipped_by_painter(Gfx::IntRect) const override;
 
+    virtual bool needs_prepare_glyphs_texture() const override { return true; }
+    void prepare_glyph_texture(HashMap<Gfx::Font const*, HashTable<u32>> const&) override;
+
     PaintingCommandExecutorGPU(AccelGfx::Painter& painter);
     ~PaintingCommandExecutorGPU() override;
 

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

@@ -417,6 +417,21 @@ static Optional<Gfx::IntRect> command_bounding_rectangle(PaintingCommand const&
 
 void RecordingPainter::execute(PaintingCommandExecutor& executor)
 {
+    if (executor.needs_prepare_glyphs_texture()) {
+        HashMap<Gfx::Font const*, HashTable<u32>> unique_glyphs;
+        for (auto& command : m_painting_commands) {
+            if (command.has<DrawGlyphRun>()) {
+                for (auto const& glyph_or_emoji : command.get<DrawGlyphRun>().glyph_run) {
+                    if (glyph_or_emoji.has<Gfx::DrawGlyph>()) {
+                        auto const& glyph = glyph_or_emoji.get<Gfx::DrawGlyph>();
+                        unique_glyphs.ensure(glyph.font, [] { return HashTable<u32> {}; }).set(glyph.code_point);
+                    }
+                }
+            }
+        }
+        executor.prepare_glyph_texture(unique_glyphs);
+    }
+
     size_t next_command_index = 0;
     while (next_command_index < m_painting_commands.size()) {
         auto& command = m_painting_commands[next_command_index++];

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

@@ -376,6 +376,9 @@ public:
     virtual CommandResult blit_corner_clipping(BorderRadiusCornerClipper&) = 0;
 
     virtual bool would_be_fully_clipped_by_painter(Gfx::IntRect) const = 0;
+
+    virtual bool needs_prepare_glyphs_texture() const { return false; }
+    virtual void prepare_glyph_texture(HashMap<Gfx::Font const*, HashTable<u32>> const& unique_glyphs) = 0;
 };
 
 class RecordingPainter {