Serenity Operating System
at hosted 101 lines 3.2 kB view raw
1/* 2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, this 9 * list of conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright notice, 12 * this list of conditions and the following disclaimer in the documentation 13 * and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#pragma once 28 29#include <AK/OwnPtr.h> 30#include <AK/RefPtr.h> 31#include <LibCore/Object.h> 32#include <LibGfx/DisjointRectSet.h> 33#include <LibGfx/Forward.h> 34 35namespace WindowServer { 36 37class Cursor; 38 39enum class WallpaperMode { 40 Simple, 41 Tile, 42 Center, 43 Scaled, 44 Unchecked 45}; 46 47class Compositor final : public Core::Object { 48 C_OBJECT(Compositor) 49public: 50 static Compositor& the(); 51 52 void compose(); 53 void invalidate(); 54 void invalidate(const Gfx::Rect&); 55 56 bool set_resolution(int desired_width, int desired_height); 57 58 bool set_backgound_color(const String& background_color); 59 60 bool set_wallpaper_mode(const String& mode); 61 62 bool set_wallpaper(const String& path, Function<void(bool)>&& callback); 63 String wallpaper_path() const { return m_wallpaper_path; } 64 65 void invalidate_cursor(); 66 Gfx::Rect current_cursor_rect() const; 67 68private: 69 Compositor(); 70 void init_bitmaps(); 71 void flip_buffers(); 72 void flush(const Gfx::Rect&); 73 void draw_cursor(); 74 void draw_geometry_label(); 75 void draw_menubar(); 76 void run_animations(); 77 void notify_display_links(); 78 79 RefPtr<Core::Timer> m_compose_timer; 80 RefPtr<Core::Timer> m_immediate_compose_timer; 81 bool m_flash_flush { false }; 82 bool m_buffers_are_flipped { false }; 83 bool m_screen_can_set_buffer { false }; 84 85 RefPtr<Gfx::Bitmap> m_front_bitmap; 86 RefPtr<Gfx::Bitmap> m_back_bitmap; 87 OwnPtr<Gfx::Painter> m_back_painter; 88 OwnPtr<Gfx::Painter> m_front_painter; 89 90 Gfx::DisjointRectSet m_dirty_rects; 91 92 Gfx::Rect m_last_cursor_rect; 93 Gfx::Rect m_last_dnd_rect; 94 Gfx::Rect m_last_geometry_label_rect; 95 96 String m_wallpaper_path; 97 WallpaperMode m_wallpaper_mode { WallpaperMode::Unchecked }; 98 RefPtr<Gfx::Bitmap> m_wallpaper; 99}; 100 101}