Pārlūkot izejas kodu

WindowServer+LibGUI: Yank out window-global opacity

From what I can tell, this facility was added to WSWindow/GWindow in
2019 in 9b71307. I only found a single place in the codebase still using
this facility: `WindowServer::Menu::start_activation_animation()`. A
subtle fade-out animation that happens when a menu item is selected, and
the menu disappears.
I think our compositing facilities have improved enough to make this
facility redundant. The remaining use mentioned above was ported to just
directly blit the fade-out animation instead of requesting it from
WindowServer.
Valtteri Koskivuori 2 gadi atpakaļ
vecāks
revīzija
6931a5a0a8

+ 0 - 9
Userland/Libraries/LibGUI/Window.cpp

@@ -159,7 +159,6 @@ void Window::show()
         m_fullscreen,
         m_frameless,
         m_forced_shadow,
-        m_opacity_when_windowless,
         m_alpha_hit_threshold,
         m_base_size,
         m_size_increment,
@@ -895,14 +894,6 @@ void Window::set_double_buffering_enabled(bool value)
     m_double_buffering_enabled = value;
 }
 
-void Window::set_opacity(float opacity)
-{
-    m_opacity_when_windowless = opacity;
-    if (!is_visible())
-        return;
-    ConnectionToWindowServer::the().async_set_window_opacity(m_window_id, opacity);
-}
-
 void Window::set_alpha_hit_threshold(float threshold)
 {
     if (threshold < 0.0f)

+ 0 - 3
Userland/Libraries/LibGUI/Window.h

@@ -75,8 +75,6 @@ public:
     void set_double_buffering_enabled(bool);
     void set_has_alpha_channel(bool);
     bool has_alpha_channel() const { return m_has_alpha_channel; }
-    void set_opacity(float);
-    float opacity() const { return m_opacity_when_windowless; }
 
     void set_alpha_hit_threshold(float);
     float alpha_hit_threshold() const { return m_alpha_hit_threshold; }
@@ -291,7 +289,6 @@ private:
 
     RefPtr<Gfx::Bitmap const> m_icon;
     int m_window_id { 0 };
-    float m_opacity_when_windowless { 1.0f };
     float m_alpha_hit_threshold { 0.0f };
     RefPtr<Widget> m_main_widget;
     WeakPtr<Widget> m_default_return_key_widget;

+ 5 - 17
Userland/Services/WindowServer/Compositor.cpp

@@ -393,10 +393,7 @@ void Compositor::compose()
                 return;
 
             auto clear_window_rect = [&](const Gfx::IntRect& clear_rect) {
-                auto fill_color = wm.palette().window();
-                if (!window.is_opaque())
-                    fill_color.set_alpha(255 * window.opacity());
-                painter.fill_rect(clear_rect, fill_color);
+                painter.fill_rect(clear_rect, wm.palette().window());
             };
 
             if (!backing_store) {
@@ -447,20 +444,11 @@ void Compositor::compose()
                 auto dst = backing_rect.location().translated(dirty_rect_in_backing_coordinates.location());
 
                 if (window.client() && window.client()->is_unresponsive()) {
-                    if (window.is_opaque()) {
-                        painter.blit_filtered(dst, *backing_store, dirty_rect_in_backing_coordinates, [](Color src) {
-                            return src.to_grayscale().darkened(0.75f);
-                        });
-                    } else {
-                        u8 alpha = 255 * window.opacity();
-                        painter.blit_filtered(dst, *backing_store, dirty_rect_in_backing_coordinates, [&](Color src) {
-                            auto color = src.to_grayscale().darkened(0.75f);
-                            color.set_alpha(alpha);
-                            return color;
-                        });
-                    }
+                    painter.blit_filtered(dst, *backing_store, dirty_rect_in_backing_coordinates, [](Color src) {
+                        return src.to_grayscale().darkened(0.75f);
+                    });
                 } else {
-                    painter.blit(dst, *backing_store, dirty_rect_in_backing_coordinates, window.opacity());
+                    painter.blit(dst, *backing_store, dirty_rect_in_backing_coordinates);
                 }
             }
 

+ 1 - 12
Userland/Services/WindowServer/ConnectionFromClient.cpp

@@ -322,16 +322,6 @@ void ConnectionFromClient::set_forced_shadow(i32 window_id, bool shadow)
     Compositor::the().invalidate_occlusions();
 }
 
-void ConnectionFromClient::set_window_opacity(i32 window_id, float opacity)
-{
-    auto it = m_windows.find(window_id);
-    if (it == m_windows.end()) {
-        did_misbehave("SetWindowOpacity: Bad window ID");
-        return;
-    }
-    it->value->set_opacity(opacity);
-}
-
 Messages::WindowServer::SetWallpaperResponse ConnectionFromClient::set_wallpaper(Gfx::ShareableBitmap const& bitmap)
 {
     return Compositor::the().set_wallpaper(bitmap.bitmap());
@@ -613,7 +603,7 @@ Window* ConnectionFromClient::window_from_id(i32 window_id)
 
 void ConnectionFromClient::create_window(i32 window_id, Gfx::IntRect const& rect,
     bool auto_position, bool has_alpha_channel, bool minimizable, bool closeable, bool resizable,
-    bool fullscreen, bool frameless, bool forced_shadow, float opacity,
+    bool fullscreen, bool frameless, bool forced_shadow,
     float alpha_hit_threshold, Gfx::IntSize base_size, Gfx::IntSize size_increment,
     Gfx::IntSize minimum_size, Optional<Gfx::IntSize> const& resize_aspect_ratio, i32 type, i32 mode,
     DeprecatedString const& title, i32 parent_window_id, Gfx::IntRect const& launch_origin_rect)
@@ -675,7 +665,6 @@ void ConnectionFromClient::create_window(i32 window_id, Gfx::IntRect const& rect
         window->set_rect(Screen::bounding_rect());
         window->recalculate_rect();
     }
-    window->set_opacity(opacity);
     window->set_alpha_hit_threshold(alpha_hit_threshold);
     window->set_size_increment(size_increment);
     window->set_base_size(base_size);

+ 1 - 2
Userland/Services/WindowServer/ConnectionFromClient.h

@@ -103,7 +103,7 @@ private:
     virtual void remove_menu_item(i32 menu_id, i32 identifier) override;
     virtual void flash_menubar_menu(i32, i32) override;
     virtual void create_window(i32, Gfx::IntRect const&, bool, bool, bool,
-        bool, bool, bool, bool, bool, float, float, Gfx::IntSize, Gfx::IntSize, Gfx::IntSize,
+        bool, bool, bool, bool, bool, float, Gfx::IntSize, Gfx::IntSize, Gfx::IntSize,
         Optional<Gfx::IntSize> const&, i32, i32, DeprecatedString const&, i32, Gfx::IntRect const&) override;
     virtual Messages::WindowServer::DestroyWindowResponse destroy_window(i32) override;
     virtual void set_window_title(i32, DeprecatedString const&) override;
@@ -121,7 +121,6 @@ private:
     virtual void invalidate_rect(i32, Vector<Gfx::IntRect> const&, bool) override;
     virtual void did_finish_painting(i32, Vector<Gfx::IntRect> const&) override;
     virtual void set_global_mouse_tracking(bool) override;
-    virtual void set_window_opacity(i32, float) override;
     virtual void set_window_backing_store(i32, i32, i32, IPC::File const&, i32, bool, Gfx::IntSize, Gfx::IntSize, bool) override;
     virtual void set_window_has_alpha_channel(i32, bool) override;
     virtual void set_window_alpha_hit_threshold(i32, float) override;

+ 10 - 4
Userland/Services/WindowServer/Menu.cpp

@@ -501,7 +501,7 @@ void Menu::start_activation_animation(MenuItem& item)
     auto window = Window::construct(*this, WindowType::Menu);
     window->set_frameless(true);
     window->set_hit_testing_enabled(false);
-    window->set_opacity(0.8f); // start out transparent so we don't have to recompute occlusions
+    window->set_has_alpha_channel(true);
     window->set_rect(item.rect().translated(m_menu_window->rect().location()));
     window->set_event_filter([](Core::Event&) {
         // ignore all events
@@ -509,8 +509,11 @@ void Menu::start_activation_animation(MenuItem& item)
     });
 
     VERIFY(window->backing_store());
+
+    NonnullRefPtr<Gfx::Bitmap> original_bitmap = *menu_window()->backing_store();
+    Gfx::IntRect item_rect = item.rect();
     Gfx::Painter painter(*window->backing_store());
-    painter.blit({}, *menu_window()->backing_store(), item.rect(), 1.0f, false);
+    painter.blit({}, original_bitmap, item_rect, 0.8f, true); // start out transparent so we don't have to recompute occlusions
     window->invalidate();
 
     struct AnimationInfo {
@@ -525,7 +528,7 @@ void Menu::start_activation_animation(MenuItem& item)
     };
     auto animation = adopt_own(*new AnimationInfo(move(window)));
     auto& timer = animation->timer;
-    timer = Core::Timer::create_repeating(50, [animation = animation.ptr(), animation_ref = move(animation)] {
+    timer = Core::Timer::create_repeating(50, [animation = animation.ptr(), animation_ref = move(animation), original_bitmap, item_rect] {
         VERIFY(animation->step % 2 == 0);
         animation->step -= 2;
         if (animation->step == 0) {
@@ -536,7 +539,10 @@ void Menu::start_activation_animation(MenuItem& item)
         }
 
         float opacity = (float)animation->step / 10.0f;
-        animation->window->set_opacity(opacity);
+        Gfx::Painter painter(*animation->window->backing_store());
+        painter.clear_rect({ {}, animation->window->rect().size() }, Color::Transparent);
+        painter.blit({}, original_bitmap, item_rect, opacity, true);
+        animation->window->invalidate();
     }).release_value_but_fixme_should_propagate_errors();
     timer->start();
 }

+ 0 - 12
Userland/Services/WindowServer/Window.cpp

@@ -380,18 +380,6 @@ void Window::start_launch_animation(Gfx::IntRect const& launch_origin_rect)
     m_animation->start();
 }
 
-void Window::set_opacity(float opacity)
-{
-    if (m_opacity == opacity)
-        return;
-    bool was_opaque = is_opaque();
-    m_opacity = opacity;
-    if (was_opaque != is_opaque())
-        Compositor::the().invalidate_occlusions();
-    invalidate(false);
-    WindowManager::the().notify_opacity_changed(*this);
-}
-
 void Window::set_has_alpha_channel(bool value)
 {
     if (m_has_alpha_channel == value)

+ 1 - 9
Userland/Services/WindowServer/Window.h

@@ -153,9 +153,6 @@ public:
 
     DeprecatedString computed_title() const;
 
-    float opacity() const { return m_opacity; }
-    void set_opacity(float);
-
     void set_hit_testing_enabled(bool value)
     {
         m_hit_testing_enabled = value;
@@ -327,11 +324,7 @@ public:
 
     bool is_opaque() const
     {
-        if (opacity() < 1.0f)
-            return false;
-        if (has_alpha_channel())
-            return false;
-        return true;
+        return !has_alpha_channel();
     }
 
     Gfx::DisjointIntRectSet& opaque_rects() { return m_opaque_rects; }
@@ -444,7 +437,6 @@ private:
     i32 m_last_backing_store_serial { -1 };
     int m_window_id { -1 };
     i32 m_client_id { -1 };
-    float m_opacity { 1 };
     float m_alpha_hit_threshold { 0.0f };
     Gfx::IntSize m_size_increment;
     Gfx::IntSize m_base_size;

+ 0 - 2
Userland/Services/WindowServer/WindowServer.ipc

@@ -53,7 +53,6 @@ endpoint WindowServer
         bool fullscreen,
         bool frameless,
         bool forced_shadow,
-        float opacity,
         float alpha_hit_threshold,
         Gfx::IntSize base_size,
         Gfx::IntSize size_increment,
@@ -95,7 +94,6 @@ endpoint WindowServer
     did_finish_painting(i32 window_id, Vector<Gfx::IntRect> rects) =|
 
     set_global_mouse_tracking(bool enabled) =|
-    set_window_opacity(i32 window_id, float opacity) =|
 
     set_window_alpha_hit_threshold(i32 window_id, float threshold) =|