From 88f6ce152ff60d2773561959c6ab0eed54748a2d Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 9 Mar 2019 16:54:41 +0100 Subject: [PATCH] SharedGraphics: Add PainterStateSaver RAII helper and Point::operator-(). Two little things to help tidy up a bit in WSWindowManager. --- SharedGraphics/Painter.h | 17 +++++++++++++++++ SharedGraphics/Point.h | 2 ++ WindowServer/WSWindowManager.cpp | 10 +++------- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/SharedGraphics/Painter.h b/SharedGraphics/Painter.h index 6964f814c29..4e528e9835b 100644 --- a/SharedGraphics/Painter.h +++ b/SharedGraphics/Painter.h @@ -80,3 +80,20 @@ private: Retained m_target; Vector m_state_stack; }; + +class PainterStateSaver { +public: + PainterStateSaver(Painter& painter) + : m_painter(painter) + { + m_painter.save(); + } + + ~PainterStateSaver() + { + m_painter.restore(); + } + +private: + Painter& m_painter; +}; diff --git a/SharedGraphics/Point.h b/SharedGraphics/Point.h index cf5fd11ef68..e49d6cb49d7 100644 --- a/SharedGraphics/Point.h +++ b/SharedGraphics/Point.h @@ -48,6 +48,8 @@ public: return !(*this == other); } + Point operator-() const { return { -m_x, -m_y }; } + operator WSAPI_Point() const; String to_string() const { return String::format("[%d,%d]", x(), y()); } diff --git a/WindowServer/WSWindowManager.cpp b/WindowServer/WSWindowManager.cpp index 7f6dffc617b..4590b80446d 100644 --- a/WindowServer/WSWindowManager.cpp +++ b/WindowServer/WSWindowManager.cpp @@ -876,24 +876,20 @@ void WSWindowManager::compose() if (!any_dirty_rect_intersects_window(window)) return; for (auto& dirty_rect : dirty_rects.rects()) { + PainterStateSaver saver(*m_back_painter); m_back_painter->set_clip_rect(dirty_rect); paint_window_frame(window); Rect dirty_rect_in_window_coordinates = Rect::intersection(dirty_rect, window.rect()); - if (dirty_rect_in_window_coordinates.is_empty()) { - m_back_painter->clear_clip_rect(); + if (dirty_rect_in_window_coordinates.is_empty()) continue; - } - dirty_rect_in_window_coordinates.set_x(dirty_rect_in_window_coordinates.x() - window.x()); - dirty_rect_in_window_coordinates.set_y(dirty_rect_in_window_coordinates.y() - window.y()); + dirty_rect_in_window_coordinates.move_by(-window.position()); auto dst = window.position(); dst.move_by(dirty_rect_in_window_coordinates.location()); if (window.opacity() == 1.0f) m_back_painter->blit(dst, *backing_store, dirty_rect_in_window_coordinates); else m_back_painter->blit_with_opacity(dst, *backing_store, dirty_rect_in_window_coordinates, window.opacity()); - m_back_painter->clear_clip_rect(); } - m_back_painter->clear_clip_rect(); }; for_each_visible_window_from_back_to_front([&] (WSWindow& window) {