summaryrefslogtreecommitdiff
path: root/Userland/Services/WindowServer/Overlays.h
diff options
context:
space:
mode:
authorTom <tomut@yahoo.com>2021-06-20 13:23:43 -0600
committerAndreas Kling <kling@serenityos.org>2021-06-25 20:38:13 +0200
commit41859ad3feda56463ce0f73b898714ae17670ca6 (patch)
tree2592325a640c338620870c27fd16aee3174ef9ca /Userland/Services/WindowServer/Overlays.h
parent42cb38b71a469c5b68280f9bc4b54a895781159d (diff)
downloadserenity-41859ad3feda56463ce0f73b898714ae17670ca6.zip
WindowServer: Add an Overlay class for flicker-free overlay rendering
An Overlay is similar to a transparent window, but has less overhead and does not get rendered within the window stack. Basically, the area that an Overlay occupies forces transparency rendering for any window underneath, which allows us to render them flicker-free. This also adds a new API that allows displaying the screen numbers, e.g. while the user configures the screen layout in DisplaySettings Because other things like drag&drop or the window-size label are not yet converted to use this new mechanism, they will be drawn over the screen-number currently.
Diffstat (limited to 'Userland/Services/WindowServer/Overlays.h')
-rw-r--r--Userland/Services/WindowServer/Overlays.h127
1 files changed, 127 insertions, 0 deletions
diff --git a/Userland/Services/WindowServer/Overlays.h b/Userland/Services/WindowServer/Overlays.h
new file mode 100644
index 0000000000..8514b1e6b5
--- /dev/null
+++ b/Userland/Services/WindowServer/Overlays.h
@@ -0,0 +1,127 @@
+/*
+ * Copyright (c) 2021, the SerenityOS developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/IntrusiveList.h>
+#include <AK/Vector.h>
+#include <LibGfx/Painter.h>
+#include <WindowServer/MultiScaleBitmaps.h>
+#include <WindowServer/Screen.h>
+
+namespace WindowServer {
+
+class Screen;
+
+class Overlay {
+ friend class Compositor;
+
+public:
+ virtual ~Overlay();
+
+ enum class ZOrder {
+ WindowGeometry,
+ ScreenNumber,
+ };
+ [[nodiscard]] virtual ZOrder zorder() const = 0;
+ virtual void render(Gfx::Painter&, Screen const&) = 0;
+
+ Gfx::IntRect const& rect() const { return m_rect; }
+ Gfx::IntRect const& current_render_rect() const { return m_current_rect; }
+
+ void set_enabled(bool);
+ bool is_enabled() const { return m_list_node.is_in_list(); }
+
+ virtual void theme_changed()
+ {
+ rect_changed();
+ }
+
+ bool invalidate();
+
+protected:
+ Overlay() = default;
+
+ void set_rect(Gfx::IntRect const&);
+
+ virtual void rect_changed() {};
+
+private:
+ void clear_invalidated() { m_invalidated = false; }
+ void did_recompute_occlusions()
+ {
+ m_invalidated = false;
+ m_current_rect = m_rect;
+ }
+
+ Gfx::IntRect m_rect;
+ Gfx::IntRect m_current_rect;
+ Vector<Screen*, default_screen_count> m_screens;
+ IntrusiveListNode<Overlay> m_list_node;
+ bool m_invalidated { false };
+};
+
+class BitmapOverlay : public Overlay {
+public:
+ virtual RefPtr<Gfx::Bitmap> create_bitmap(int) = 0;
+
+ virtual void render(Gfx::Painter&, Screen const&) override;
+
+protected:
+ BitmapOverlay();
+
+ void clear_bitmaps();
+ virtual void rect_changed() override;
+
+private:
+ RefPtr<MultiScaleBitmaps> m_bitmaps;
+};
+
+class RectangularOverlay : public Overlay {
+public:
+ static constexpr int default_minimum_size = 10;
+ static constexpr int default_frame_thickness = 5;
+
+ virtual void render(Gfx::Painter&, Screen const&) override;
+ virtual void render_overlay_bitmap(Gfx::Painter&) = 0;
+
+protected:
+ RectangularOverlay();
+
+ static Gfx::IntRect calculate_frame_rect(Gfx::IntRect const&);
+ void set_content_rect(Gfx::IntRect const&);
+
+ void clear_bitmaps();
+ virtual void rect_changed() override;
+
+private:
+ RefPtr<MultiScaleBitmaps> m_rendered_bitmaps;
+};
+
+class ScreenNumberOverlay : public RectangularOverlay {
+public:
+ static constexpr int default_offset = 20;
+ static constexpr int default_size = 120;
+ static constexpr int screen_number_padding = 10;
+
+ ScreenNumberOverlay(Screen&);
+
+ static Gfx::IntRect calculate_content_rect_for_screen(Screen&);
+
+ virtual ZOrder zorder() const override { return ZOrder::ScreenNumber; }
+ virtual void render_overlay_bitmap(Gfx::Painter&) override;
+
+ static void pick_font();
+
+private:
+ Gfx::Font const& font();
+
+ Screen& m_screen;
+
+ static Gfx::Font const* s_font;
+};
+
+}