ソースを参照

LibGfx: Add early bounds checking to `accumulate_non_zero_scanline()`

Nonzero fills are much more common (as the default fill rule), so if
this does result in any speed-up it makes sense to do it here too.
MacDue 1 年間 前
コミット
8988dce93d
1 ファイル変更6 行追加4 行削除
  1. 6 4
      Userland/Libraries/LibGfx/EdgeFlagPathRasterizer.cpp

+ 6 - 4
Userland/Libraries/LibGfx/EdgeFlagPathRasterizer.cpp

@@ -323,13 +323,15 @@ template<unsigned SamplesPerPixel>
 auto EdgeFlagPathRasterizer<SamplesPerPixel>::accumulate_non_zero_scanline(EdgeExtent edge_extent, auto init, auto sample_callback)
 {
     NonZeroAcc acc = init;
+    VERIFY(edge_extent.min_x >= 0);
+    VERIFY(edge_extent.max_x < static_cast<int>(m_scanline.size()));
     for (int x = edge_extent.min_x; x <= edge_extent.max_x; x += 1) {
-        if (auto edges = m_scanline[x]) {
+        if (auto edges = m_scanline.data()[x]) {
             // We only need to process the windings when we hit some edges.
             for (auto y_sub = 0u; y_sub < SamplesPerPixel; y_sub++) {
                 auto subpixel_bit = 1 << y_sub;
                 if (edges & subpixel_bit) {
-                    auto winding = m_windings[x].counts[y_sub];
+                    auto winding = m_windings.data()[x].counts[y_sub];
                     auto previous_winding_count = acc.winding.counts[y_sub];
                     acc.winding.counts[y_sub] += winding;
                     // Toggle fill on change to/from zero.
@@ -339,8 +341,8 @@ auto EdgeFlagPathRasterizer<SamplesPerPixel>::accumulate_non_zero_scanline(EdgeE
             }
         }
         sample_callback(x, acc.sample);
-        m_scanline[x] = 0;
-        m_windings[x] = {};
+        m_scanline.data()[x] = 0;
+        m_windings.data()[x] = {};
     }
     return acc;
 }