소스 검색

LibGfx: Small improvements to fill_rect_with_checkerboard()

- Clamp the checkerboard scanline prologue length to the total width
  of the (clipped) rect we're filling.

- Use fast_u32_fill() for the prologue and epilogue as well.
Andreas Kling 4 년 전
부모
커밋
f33edd33cc
1개의 변경된 파일15개의 추가작업 그리고 8개의 파일을 삭제
  1. 15 8
      Userland/Libraries/LibGfx/Painter.cpp

+ 15 - 8
Userland/Libraries/LibGfx/Painter.cpp

@@ -178,8 +178,8 @@ void Painter::fill_rect_with_checkerboard(const IntRect& a_rect, const IntSize&
     const size_t dst_skip = m_target->pitch() / sizeof(RGBA32);
 
     int first_cell_column = rect.x() / cell_size.width();
-    int prologue_length = cell_size.width() - (rect.x() % cell_size.width());
-    int number_of_aligned_strips = ((rect.width() - prologue_length) / cell_size.width());
+    int prologue_length = min(rect.width(), cell_size.width() - (rect.x() % cell_size.width()));
+    int number_of_aligned_strips = (rect.width() - prologue_length) / cell_size.width();
 
     for (int i = 0; i < rect.height(); ++i) {
         int y = rect.y() + i;
@@ -189,9 +189,12 @@ void Painter::fill_rect_with_checkerboard(const IntRect& a_rect, const IntSize&
         // Prologue: Paint the unaligned part up to the first intersection.
         int j = 0;
         int cell_column = first_cell_column;
-        for (int p = 0; p < prologue_length; ++p) {
-            dst[j] = (odd_row ^ (cell_column % 2)) ? color_light.value() : color_dark.value();
-            ++j;
+
+        {
+            bool odd_cell = cell_column & 1;
+            auto color = (odd_row ^ odd_cell) ? color_light.value() : color_dark.value();
+            fast_u32_fill(&dst[j], color, prologue_length);
+            j += prologue_length;
         }
 
         // Aligned run: Paint the maximum number of aligned cell strips.
@@ -204,9 +207,13 @@ void Painter::fill_rect_with_checkerboard(const IntRect& a_rect, const IntSize&
         }
 
         // Epilogue: Paint the unaligned part until the end of the rect.
-        ++cell_column;
-        for (; j < rect.width(); ++j) {
-            dst[j] = (odd_row ^ (cell_column % 2)) ? color_light.value() : color_dark.value();
+        if (j != rect.width()) {
+            ++cell_column;
+            bool odd_cell = cell_column & 1;
+            auto color = (odd_row ^ odd_cell) ? color_light.value() : color_dark.value();
+            int epilogue_length = rect.width() - j;
+            fast_u32_fill(&dst[j], color, epilogue_length);
+            j += epilogue_length;
         }
 
         dst += dst_skip;