Pārlūkot izejas kodu

Keep back and front painters around in WindowManager.

The internal state never changes in some meaningful way for these (at this time.)
Andreas Kling 6 gadi atpakaļ
vecāks
revīzija
cc0be2e78a
3 mainītis faili ar 26 papildinājumiem un 28 dzēšanām
  1. 1 1
      Widgets/AbstractScreen.cpp
  2. 20 26
      Widgets/WindowManager.cpp
  3. 5 1
      Widgets/WindowManager.h

+ 1 - 1
Widgets/AbstractScreen.cpp

@@ -61,7 +61,7 @@ void AbstractScreen::on_receive_mouse_data(int dx, int dy, bool left_button, boo
         EventLoop::main().postEvent(&WindowManager::the(), move(event));
     }
     if (m_cursor_location != prev_location || prev_left_button != left_button)
-        WindowManager::the().redraw_cursor();
+        WindowManager::the().draw_cursor();
 }
 
 void AbstractScreen::on_key_pressed(Keyboard::Key key)

+ 20 - 26
Widgets/WindowManager.cpp

@@ -113,6 +113,9 @@ WindowManager::WindowManager()
     auto* region = current->allocate_region(LinearAddress(), size.width() * size.height() * sizeof(RGBA32), "BackBitmap", true, true, true);
     m_back_bitmap = GraphicsBitmap::create_wrapper(m_screen_rect.size(), (RGBA32*)region->linearAddress.get());
 
+    m_front_painter = make<Painter>(*m_front_bitmap);
+    m_back_painter = make<Painter>(*m_back_bitmap);
+
     m_activeWindowBorderColor = Color(0, 64, 192);
     m_activeWindowTitleColor = Color::White;
 
@@ -132,8 +135,6 @@ WindowManager::~WindowManager()
 
 void WindowManager::paintWindowFrame(Window& window)
 {
-    Painter p(*m_back_bitmap);
-
     //printf("[WM] paintWindowFrame {%p}, rect: %d,%d %dx%d\n", &window, window.rect().x(), window.rect().y(), window.rect().width(), window.rect().height());
 
     auto titleBarRect = titleBarRectForWindow(window.rect());
@@ -151,14 +152,11 @@ void WindowManager::paintWindowFrame(Window& window)
     auto titleColor = &window == activeWindow() ? m_activeWindowTitleColor : m_inactiveWindowTitleColor;
     auto borderColor = &window == activeWindow() ? m_activeWindowBorderColor : m_inactiveWindowBorderColor;
 
-    p.draw_rect(borderRect, Color::MidGray);
-    p.draw_rect(outerRect, borderColor);
-
-    p.fill_rect(titleBarRect, borderColor);
-
-    p.draw_rect(inner_border_rect, borderColor);
-
-    p.draw_text(titleBarTitleRect, window.title(), Painter::TextAlignment::CenterLeft, titleColor);
+    m_back_painter->draw_rect(borderRect, Color::MidGray);
+    m_back_painter->draw_rect(outerRect, borderColor);
+    m_back_painter->fill_rect(titleBarRect, borderColor);
+    m_back_painter->draw_rect(inner_border_rect, borderColor);
+    m_back_painter->draw_text(titleBarTitleRect, window.title(), Painter::TextAlignment::CenterLeft, titleColor);
 }
 
 void WindowManager::addWindow(Window& window)
@@ -280,39 +278,36 @@ void WindowManager::compose()
         }
         return false;
     };
-    Painter painter(*m_back_bitmap);
-    {
-        for (auto& r : m_invalidated_rects) {
-            if (any_window_contains_rect(r))
-                continue;
-            //dbgprintf("Repaint root %d,%d %dx%d\n", r.x(), r.y(), r.width(), r.height());
-            painter.fill_rect(r, Color(0, 72, 96));
-        }
+
+    for (auto& r : m_invalidated_rects) {
+        if (any_window_contains_rect(r))
+            continue;
+        //dbgprintf("Repaint root %d,%d %dx%d\n", r.x(), r.y(), r.width(), r.height());
+        m_back_painter->fill_rect(r, Color(0, 72, 96));
     }
     for (auto* window = m_windows_in_order.head(); window; window = window->next()) {
         if (!window->backing())
             continue;
         paintWindowFrame(*window);
-        painter.blit(window->position(), *window->backing());
+        m_back_painter->blit(window->position(), *window->backing());
     }
     for (auto& r : m_invalidated_rects)
         flush(r);
-    redraw_cursor();
+    draw_cursor();
     m_invalidated_rects.clear_with_capacity();
 }
 
-void WindowManager::redraw_cursor()
+void WindowManager::draw_cursor()
 {
     auto cursor_location = m_framebuffer.cursor_location();
-    Painter painter(*m_front_bitmap);
     Rect cursor_rect { cursor_location.x(), cursor_location.y(), (int)m_cursor_bitmap_inner->width(), (int)m_cursor_bitmap_inner->height() };
     flush(m_last_cursor_rect.united(cursor_rect));
     Color inner_color = Color::White;
     Color outer_color = Color::Black;
     if (m_framebuffer.left_mouse_button_pressed())
         swap(inner_color, outer_color);
-    painter.draw_bitmap(cursor_location, *m_cursor_bitmap_inner, inner_color);
-    painter.draw_bitmap(cursor_location, *m_cursor_bitmap_outer, outer_color);
+    m_front_painter->draw_bitmap(cursor_location, *m_cursor_bitmap_inner, inner_color);
+    m_front_painter->draw_bitmap(cursor_location, *m_cursor_bitmap_outer, outer_color);
     m_last_cursor_rect = cursor_rect;
 }
 
@@ -402,8 +397,7 @@ void WindowManager::flush(const Rect& a_rect)
     size_t pitch = m_back_bitmap->pitch();
 
 #ifdef DEBUG_FLUSH_YELLOW
-    Painter p(*m_front_bitmap);
-    p.fill_rect(rect, Color::Yellow);
+    m_front_painter->fill_rect(rect, Color::Yellow);
 #endif
 
     for (int y = 0; y < rect.height(); ++y) {

+ 5 - 1
Widgets/WindowManager.h

@@ -3,6 +3,7 @@
 #include "Object.h"
 #include "Rect.h"
 #include "Color.h"
+#include "Painter.h"
 #include <AK/HashTable.h>
 #include <AK/InlineLinkedList.h>
 #include <AK/WeakPtr.h>
@@ -35,7 +36,7 @@ public:
 
     static void initialize();
 
-    void redraw_cursor();
+    void draw_cursor();
 
     void invalidate(const Window&);
     void invalidate(const Rect&);
@@ -89,4 +90,7 @@ private:
 
     RetainPtr<CharacterBitmap> m_cursor_bitmap_inner;
     RetainPtr<CharacterBitmap> m_cursor_bitmap_outer;
+
+    OwnPtr<Painter> m_back_painter;
+    OwnPtr<Painter> m_front_painter;
 };