diff options
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibGUI/Action.cpp | 125 | ||||
-rw-r--r-- | Libraries/LibGUI/Action.h | 4 | ||||
-rw-r--r-- | Libraries/LibGUI/DragOperation.cpp | 1 | ||||
-rw-r--r-- | Libraries/LibGUI/Menu.cpp | 6 | ||||
-rw-r--r-- | Libraries/LibGUI/Painter.cpp | 1 | ||||
-rw-r--r-- | Libraries/LibGUI/TextEditor.cpp | 1 | ||||
-rw-r--r-- | Libraries/LibGUI/Window.cpp | 6 | ||||
-rw-r--r-- | Libraries/LibGUI/Window.h | 5 | ||||
-rw-r--r-- | Libraries/LibGUI/WindowServerConnection.cpp | 2 | ||||
-rw-r--r-- | Libraries/LibGfx/Bitmap.cpp | 35 | ||||
-rw-r--r-- | Libraries/LibGfx/Bitmap.h | 93 | ||||
-rw-r--r-- | Libraries/LibGfx/Forward.h | 52 | ||||
-rw-r--r-- | Libraries/LibGfx/PNGLoader.cpp | 2 | ||||
-rw-r--r-- | Libraries/LibGfx/Painter.cpp | 44 | ||||
-rw-r--r-- | Libraries/LibGfx/Palette.cpp | 11 | ||||
-rw-r--r-- | Libraries/LibGfx/Palette.h | 5 | ||||
-rw-r--r-- | Libraries/LibGfx/SystemTheme.cpp | 1 | ||||
-rw-r--r-- | Libraries/LibGfx/SystemTheme.h | 2 |
18 files changed, 239 insertions, 157 deletions
diff --git a/Libraries/LibGUI/Action.cpp b/Libraries/LibGUI/Action.cpp index f0a34fef54..03f136642f 100644 --- a/Libraries/LibGUI/Action.cpp +++ b/Libraries/LibGUI/Action.cpp @@ -34,80 +34,80 @@ namespace GUI { namespace CommonActions { -NonnullRefPtr<Action> make_open_action(Function<void(Action&)> callback, Core::Object* parent) -{ - return Action::create("Open...", { Mod_Ctrl, Key_O }, Gfx::Bitmap::load_from_file("/res/icons/16x16/open.png"), move(callback), parent); -} + NonnullRefPtr<Action> make_open_action(Function<void(Action&)> callback, Core::Object* parent) + { + return Action::create("Open...", { Mod_Ctrl, Key_O }, Gfx::Bitmap::load_from_file("/res/icons/16x16/open.png"), move(callback), parent); + } -NonnullRefPtr<Action> make_move_to_front_action(Function<void(Action&)> callback, Core::Object* parent) -{ - return Action::create("Move to front", { Mod_Ctrl | Mod_Shift, Key_Up }, Gfx::Bitmap::load_from_file("/res/icons/16x16/move-to-front.png"), move(callback), parent); -} + NonnullRefPtr<Action> make_move_to_front_action(Function<void(Action&)> callback, Core::Object* parent) + { + return Action::create("Move to front", { Mod_Ctrl | Mod_Shift, Key_Up }, Gfx::Bitmap::load_from_file("/res/icons/16x16/move-to-front.png"), move(callback), parent); + } -NonnullRefPtr<Action> make_move_to_back_action(Function<void(Action&)> callback, Core::Object* parent) -{ - return Action::create("Move to back", { Mod_Ctrl | Mod_Shift, Key_Down }, Gfx::Bitmap::load_from_file("/res/icons/16x16/move-to-back.png"), move(callback), parent); -} + NonnullRefPtr<Action> make_move_to_back_action(Function<void(Action&)> callback, Core::Object* parent) + { + return Action::create("Move to back", { Mod_Ctrl | Mod_Shift, Key_Down }, Gfx::Bitmap::load_from_file("/res/icons/16x16/move-to-back.png"), move(callback), parent); + } -NonnullRefPtr<Action> make_undo_action(Function<void(Action&)> callback, Core::Object* parent) -{ - return Action::create("Undo", { Mod_Ctrl, Key_Z }, Gfx::Bitmap::load_from_file("/res/icons/16x16/undo.png"), move(callback), parent); -} + NonnullRefPtr<Action> make_undo_action(Function<void(Action&)> callback, Core::Object* parent) + { + return Action::create("Undo", { Mod_Ctrl, Key_Z }, Gfx::Bitmap::load_from_file("/res/icons/16x16/undo.png"), move(callback), parent); + } -NonnullRefPtr<Action> make_redo_action(Function<void(Action&)> callback, Core::Object* parent) -{ - return Action::create("Redo", { Mod_Ctrl, Key_Y }, Gfx::Bitmap::load_from_file("/res/icons/16x16/redo.png"), move(callback), parent); -} + NonnullRefPtr<Action> make_redo_action(Function<void(Action&)> callback, Core::Object* parent) + { + return Action::create("Redo", { Mod_Ctrl, Key_Y }, Gfx::Bitmap::load_from_file("/res/icons/16x16/redo.png"), move(callback), parent); + } -NonnullRefPtr<Action> make_delete_action(Function<void(Action&)> callback, Core::Object* parent) -{ - return Action::create("Delete", { Mod_None, Key_Delete }, Gfx::Bitmap::load_from_file("/res/icons/16x16/delete.png"), move(callback), parent); -} + NonnullRefPtr<Action> make_delete_action(Function<void(Action&)> callback, Core::Object* parent) + { + return Action::create("Delete", { Mod_None, Key_Delete }, Gfx::Bitmap::load_from_file("/res/icons/16x16/delete.png"), move(callback), parent); + } -NonnullRefPtr<Action> make_cut_action(Function<void(Action&)> callback, Core::Object* parent) -{ - return Action::create("Cut", { Mod_Ctrl, Key_X }, Gfx::Bitmap::load_from_file("/res/icons/cut16.png"), move(callback), parent); -} + NonnullRefPtr<Action> make_cut_action(Function<void(Action&)> callback, Core::Object* parent) + { + return Action::create("Cut", { Mod_Ctrl, Key_X }, Gfx::Bitmap::load_from_file("/res/icons/cut16.png"), move(callback), parent); + } -NonnullRefPtr<Action> make_copy_action(Function<void(Action&)> callback, Core::Object* parent) -{ - return Action::create("Copy", { Mod_Ctrl, Key_C }, Gfx::Bitmap::load_from_file("/res/icons/16x16/edit-copy.png"), move(callback), parent); -} + NonnullRefPtr<Action> make_copy_action(Function<void(Action&)> callback, Core::Object* parent) + { + return Action::create("Copy", { Mod_Ctrl, Key_C }, Gfx::Bitmap::load_from_file("/res/icons/16x16/edit-copy.png"), move(callback), parent); + } -NonnullRefPtr<Action> make_paste_action(Function<void(Action&)> callback, Core::Object* parent) -{ - return Action::create("Paste", { Mod_Ctrl, Key_V }, Gfx::Bitmap::load_from_file("/res/icons/paste16.png"), move(callback), parent); -} + NonnullRefPtr<Action> make_paste_action(Function<void(Action&)> callback, Core::Object* parent) + { + return Action::create("Paste", { Mod_Ctrl, Key_V }, Gfx::Bitmap::load_from_file("/res/icons/paste16.png"), move(callback), parent); + } -NonnullRefPtr<Action> make_fullscreen_action(Function<void(Action&)> callback, Core::Object* parent) -{ - return Action::create("Fullscreen", { Mod_None, Key_F11 }, move(callback), parent); -} + NonnullRefPtr<Action> make_fullscreen_action(Function<void(Action&)> callback, Core::Object* parent) + { + return Action::create("Fullscreen", { Mod_None, Key_F11 }, move(callback), parent); + } -NonnullRefPtr<Action> make_quit_action(Function<void(Action&)> callback) -{ - return Action::create("Quit", { Mod_Alt, Key_F4 }, move(callback)); -} + NonnullRefPtr<Action> make_quit_action(Function<void(Action&)> callback) + { + return Action::create("Quit", { Mod_Alt, Key_F4 }, move(callback)); + } -NonnullRefPtr<Action> make_go_back_action(Function<void(Action&)> callback, Core::Object* parent) -{ - return Action::create("Go back", { Mod_Alt, Key_Left }, Gfx::Bitmap::load_from_file("/res/icons/16x16/go-back.png"), move(callback), parent); -} + NonnullRefPtr<Action> make_go_back_action(Function<void(Action&)> callback, Core::Object* parent) + { + return Action::create("Go back", { Mod_Alt, Key_Left }, Gfx::Bitmap::load_from_file("/res/icons/16x16/go-back.png"), move(callback), parent); + } -NonnullRefPtr<Action> make_go_forward_action(Function<void(Action&)> callback, Core::Object* parent) -{ - return Action::create("Go forward", { Mod_Alt, Key_Right }, Gfx::Bitmap::load_from_file("/res/icons/16x16/go-forward.png"), move(callback), parent); -} + NonnullRefPtr<Action> make_go_forward_action(Function<void(Action&)> callback, Core::Object* parent) + { + return Action::create("Go forward", { Mod_Alt, Key_Right }, Gfx::Bitmap::load_from_file("/res/icons/16x16/go-forward.png"), move(callback), parent); + } -NonnullRefPtr<Action> make_go_home_action(Function<void(Action&)> callback, Core::Object* parent) -{ - return Action::create("Go home", { Mod_Alt, Key_Home }, Gfx::Bitmap::load_from_file("/res/icons/16x16/go-home.png"), move(callback), parent); -} + NonnullRefPtr<Action> make_go_home_action(Function<void(Action&)> callback, Core::Object* parent) + { + return Action::create("Go home", { Mod_Alt, Key_Home }, Gfx::Bitmap::load_from_file("/res/icons/16x16/go-home.png"), move(callback), parent); + } -NonnullRefPtr<Action> make_reload_action(Function<void(Action&)> callback, Core::Object* parent) -{ - return Action::create("Reload", { Mod_Ctrl, Key_R }, Gfx::Bitmap::load_from_file("/res/icons/16x16/reload.png"), move(callback), parent); -} + NonnullRefPtr<Action> make_reload_action(Function<void(Action&)> callback, Core::Object* parent) + { + return Action::create("Reload", { Mod_Ctrl, Key_R }, Gfx::Bitmap::load_from_file("/res/icons/16x16/reload.png"), move(callback), parent); + } } @@ -239,4 +239,9 @@ void Action::set_group(Badge<ActionGroup>, ActionGroup* group) m_action_group = group ? group->make_weak_ptr() : nullptr; } +void Action::set_icon(const Gfx::Bitmap* icon) +{ + m_icon = icon; +} + } diff --git a/Libraries/LibGUI/Action.h b/Libraries/LibGUI/Action.h index d3b7a52ceb..ba1688c0e9 100644 --- a/Libraries/LibGUI/Action.h +++ b/Libraries/LibGUI/Action.h @@ -34,7 +34,7 @@ #include <AK/String.h> #include <AK/WeakPtr.h> #include <AK/Weakable.h> -#include <LibGfx/Bitmap.h> +#include <LibGfx/Forward.h> #include <LibGUI/Shortcut.h> #include <LibGUI/Window.h> @@ -93,7 +93,7 @@ public: String text() const { return m_text; } Shortcut shortcut() const { return m_shortcut; } const Gfx::Bitmap* icon() const { return m_icon.ptr(); } - void set_icon(const Gfx::Bitmap* icon) { m_icon = icon; } + void set_icon(const Gfx::Bitmap*); const Core::Object* activator() const { return m_activator.ptr(); } Core::Object* activator() { return m_activator.ptr(); } diff --git a/Libraries/LibGUI/DragOperation.cpp b/Libraries/LibGUI/DragOperation.cpp index 81a1a8729d..bd85629126 100644 --- a/Libraries/LibGUI/DragOperation.cpp +++ b/Libraries/LibGUI/DragOperation.cpp @@ -25,6 +25,7 @@ */ #include <AK/Badge.h> +#include <AK/SharedBuffer.h> #include <LibGUI/DragOperation.h> #include <LibGUI/WindowServerConnection.h> #include <LibGfx/Bitmap.h> diff --git a/Libraries/LibGUI/Menu.cpp b/Libraries/LibGUI/Menu.cpp index eefce0c871..cc5455a6b0 100644 --- a/Libraries/LibGUI/Menu.cpp +++ b/Libraries/LibGUI/Menu.cpp @@ -25,10 +25,12 @@ */ #include <AK/HashMap.h> +#include <AK/SharedBuffer.h> #include <LibGUI/Action.h> #include <LibGUI/ActionGroup.h> #include <LibGUI/Menu.h> #include <LibGUI/WindowServerConnection.h> +#include <LibGfx/Bitmap.h> //#define MENU_DEBUG @@ -123,12 +125,12 @@ int Menu::realize_menu() auto& action = *item.action(); int icon_buffer_id = -1; if (action.icon()) { - ASSERT(action.icon()->format() == Gfx::Bitmap::Format::RGBA32); + ASSERT(action.icon()->format() == Gfx::BitmapFormat::RGBA32); ASSERT(action.icon()->size() == Gfx::Size(16, 16)); if (action.icon()->shared_buffer_id() == -1) { auto shared_buffer = SharedBuffer::create_with_size(action.icon()->size_in_bytes()); ASSERT(shared_buffer); - auto shared_icon = Gfx::Bitmap::create_with_shared_buffer(Gfx::Bitmap::Format::RGBA32, *shared_buffer, action.icon()->size()); + auto shared_icon = Gfx::Bitmap::create_with_shared_buffer(Gfx::BitmapFormat::RGBA32, *shared_buffer, action.icon()->size()); memcpy(shared_buffer->data(), action.icon()->bits(0), action.icon()->size_in_bytes()); shared_buffer->seal(); shared_buffer->share_with(WindowServerConnection::the().server_pid()); diff --git a/Libraries/LibGUI/Painter.cpp b/Libraries/LibGUI/Painter.cpp index 0dd3e3fbcb..c0c2720c40 100644 --- a/Libraries/LibGUI/Painter.cpp +++ b/Libraries/LibGUI/Painter.cpp @@ -27,6 +27,7 @@ #include <LibGUI/Painter.h> #include <LibGUI/Widget.h> #include <LibGUI/Window.h> +#include <LibGfx/Bitmap.h> namespace GUI { Painter::Painter(Gfx::Bitmap& bitmap) diff --git a/Libraries/LibGUI/TextEditor.cpp b/Libraries/LibGUI/TextEditor.cpp index 6353357869..ea106cd502 100644 --- a/Libraries/LibGUI/TextEditor.cpp +++ b/Libraries/LibGUI/TextEditor.cpp @@ -37,6 +37,7 @@ #include <LibGUI/SyntaxHighlighter.h> #include <LibGUI/TextEditor.h> #include <LibGUI/Window.h> +#include <LibGfx/Bitmap.h> #include <LibGfx/Palette.h> #include <ctype.h> #include <fcntl.h> diff --git a/Libraries/LibGUI/Window.cpp b/Libraries/LibGUI/Window.cpp index ca05ff9f17..4222de9ea1 100644 --- a/Libraries/LibGUI/Window.cpp +++ b/Libraries/LibGUI/Window.cpp @@ -493,7 +493,7 @@ void Window::flip(const Vector<Gfx::Rect, 32>& dirty_rects) m_back_bitmap->shared_buffer()->set_volatile(); } -NonnullRefPtr<Gfx::Bitmap> Window::create_shared_bitmap(Gfx::Bitmap::Format format, const Gfx::Size& size) +NonnullRefPtr<Gfx::Bitmap> Window::create_shared_bitmap(Gfx::BitmapFormat format, const Gfx::Size& size) { ASSERT(WindowServerConnection::the().server_pid()); ASSERT(!size.is_empty()); @@ -507,7 +507,7 @@ NonnullRefPtr<Gfx::Bitmap> Window::create_shared_bitmap(Gfx::Bitmap::Format form NonnullRefPtr<Gfx::Bitmap> Window::create_backing_bitmap(const Gfx::Size& size) { - auto format = m_has_alpha_channel ? Gfx::Bitmap::Format::RGBA32 : Gfx::Bitmap::Format::RGB32; + auto format = m_has_alpha_channel ? Gfx::BitmapFormat::RGBA32 : Gfx::BitmapFormat::RGB32; return create_shared_bitmap(format, size); } @@ -526,7 +526,7 @@ void Window::set_icon(const Gfx::Bitmap* icon) if (m_icon == icon) return; - m_icon = create_shared_bitmap(Gfx::Bitmap::Format::RGBA32, icon->size()); + m_icon = create_shared_bitmap(Gfx::BitmapFormat::RGBA32, icon->size()); { Painter painter(*m_icon); painter.blit({ 0, 0 }, *icon, icon->rect()); diff --git a/Libraries/LibGUI/Window.h b/Libraries/LibGUI/Window.h index 625a02d960..55b2856762 100644 --- a/Libraries/LibGUI/Window.h +++ b/Libraries/LibGUI/Window.h @@ -32,7 +32,8 @@ #include <AK/WeakPtr.h> #include <LibCore/Object.h> #include <LibGUI/WindowType.h> -#include <LibGfx/Bitmap.h> +#include <LibGfx/Color.h> +#include <LibGfx/Forward.h> #include <LibGfx/Rect.h> namespace GUI { @@ -184,7 +185,7 @@ private: virtual bool is_window() const override final { return true; } NonnullRefPtr<Gfx::Bitmap> create_backing_bitmap(const Gfx::Size&); - NonnullRefPtr<Gfx::Bitmap> create_shared_bitmap(Gfx::Bitmap::Format, const Gfx::Size&); + NonnullRefPtr<Gfx::Bitmap> create_shared_bitmap(Gfx::BitmapFormat, const Gfx::Size&); void set_current_backing_bitmap(Gfx::Bitmap&, bool flush_immediately = false); void flip(const Vector<Gfx::Rect, 32>& dirty_rects); diff --git a/Libraries/LibGUI/WindowServerConnection.cpp b/Libraries/LibGUI/WindowServerConnection.cpp index d1a17570e2..df0dab8df9 100644 --- a/Libraries/LibGUI/WindowServerConnection.cpp +++ b/Libraries/LibGUI/WindowServerConnection.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include <AK/SharedBuffer.h> #include <LibCore/MimeData.h> #include <LibGUI/Action.h> #include <LibGUI/Application.h> @@ -35,6 +36,7 @@ #include <LibGUI/Widget.h> #include <LibGUI/Window.h> #include <LibGUI/WindowServerConnection.h> +#include <LibGfx/Bitmap.h> #include <LibGfx/Palette.h> #include <LibGfx/SystemTheme.h> diff --git a/Libraries/LibGfx/Bitmap.cpp b/Libraries/LibGfx/Bitmap.cpp index 6b3a54caa4..e64913ddbf 100644 --- a/Libraries/LibGfx/Bitmap.cpp +++ b/Libraries/LibGfx/Bitmap.cpp @@ -24,7 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include <AK/MappedFile.h> +#include <AK/SharedBuffer.h> #include <LibGfx/Bitmap.h> #include <LibGfx/PNGLoader.h> #include <errno.h> @@ -35,24 +35,24 @@ namespace Gfx { -NonnullRefPtr<Bitmap> Bitmap::create(Format format, const Size& size) +NonnullRefPtr<Bitmap> Bitmap::create(BitmapFormat format, const Size& size) { return adopt(*new Bitmap(format, size, Purgeable::No)); } -NonnullRefPtr<Bitmap> Bitmap::create_purgeable(Format format, const Size& size) +NonnullRefPtr<Bitmap> Bitmap::create_purgeable(BitmapFormat format, const Size& size) { return adopt(*new Bitmap(format, size, Purgeable::Yes)); } -Bitmap::Bitmap(Format format, const Size& size, Purgeable purgeable) +Bitmap::Bitmap(BitmapFormat format, const Size& size, Purgeable purgeable) : m_size(size) , m_pitch(round_up_to_power_of_two(size.width() * sizeof(RGBA32), 16)) , m_format(format) , m_purgeable(purgeable == Purgeable::Yes) { ASSERT(!m_size.is_empty()); - if (format == Format::Indexed8) + if (format == BitmapFormat::Indexed8) m_palette = new RGBA32[256]; int map_flags = purgeable == Purgeable::Yes ? (MAP_PURGEABLE | MAP_PRIVATE) : (MAP_ANONYMOUS | MAP_PRIVATE); m_data = (RGBA32*)mmap_with_name(nullptr, size_in_bytes(), PROT_READ | PROT_WRITE, map_flags, 0, 0, String::format("GraphicsBitmap [%dx%d]", width(), height()).characters()); @@ -60,7 +60,7 @@ Bitmap::Bitmap(Format format, const Size& size, Purgeable purgeable) m_needs_munmap = true; } -NonnullRefPtr<Bitmap> Bitmap::create_wrapper(Format format, const Size& size, size_t pitch, RGBA32* data) +NonnullRefPtr<Bitmap> Bitmap::create_wrapper(BitmapFormat format, const Size& size, size_t pitch, RGBA32* data) { return adopt(*new Bitmap(format, size, pitch, data)); } @@ -70,7 +70,7 @@ RefPtr<Bitmap> Bitmap::load_from_file(const StringView& path) return load_png(path); } -RefPtr<Bitmap> Bitmap::load_from_file(Format format, const StringView& path, const Size& size) +RefPtr<Bitmap> Bitmap::load_from_file(BitmapFormat format, const StringView& path, const Size& size) { MappedFile mapped_file(path); if (!mapped_file.is_valid()) @@ -78,39 +78,39 @@ RefPtr<Bitmap> Bitmap::load_from_file(Format format, const StringView& path, con return adopt(*new Bitmap(format, size, move(mapped_file))); } -Bitmap::Bitmap(Format format, const Size& size, size_t pitch, RGBA32* data) +Bitmap::Bitmap(BitmapFormat format, const Size& size, size_t pitch, RGBA32* data) : m_size(size) , m_data(data) , m_pitch(pitch) , m_format(format) { - if (format == Format::Indexed8) + if (format == BitmapFormat::Indexed8) m_palette = new RGBA32[256]; } -Bitmap::Bitmap(Format format, const Size& size, MappedFile&& mapped_file) +Bitmap::Bitmap(BitmapFormat format, const Size& size, MappedFile&& mapped_file) : m_size(size) , m_data((RGBA32*)mapped_file.data()) , m_pitch(round_up_to_power_of_two(size.width() * sizeof(RGBA32), 16)) , m_format(format) , m_mapped_file(move(mapped_file)) { - ASSERT(format != Format::Indexed8); + ASSERT(format != BitmapFormat::Indexed8); } -NonnullRefPtr<Bitmap> Bitmap::create_with_shared_buffer(Format format, NonnullRefPtr<SharedBuffer>&& shared_buffer, const Size& size) +NonnullRefPtr<Bitmap> Bitmap::create_with_shared_buffer(BitmapFormat format, NonnullRefPtr<SharedBuffer>&& shared_buffer, const Size& size) { return adopt(*new Bitmap(format, move(shared_buffer), size)); } -Bitmap::Bitmap(Format format, NonnullRefPtr<SharedBuffer>&& shared_buffer, const Size& size) +Bitmap::Bitmap(BitmapFormat format, NonnullRefPtr<SharedBuffer>&& shared_buffer, const Size& size) : m_size(size) , m_data((RGBA32*)shared_buffer->data()) , m_pitch(round_up_to_power_of_two(size.width() * sizeof(RGBA32), 16)) , m_format(format) , m_shared_buffer(move(shared_buffer)) { - ASSERT(format != Format::Indexed8); + ASSERT(format != BitmapFormat::Indexed8); } NonnullRefPtr<Bitmap> Bitmap::to_shareable_bitmap() const @@ -141,7 +141,7 @@ void Bitmap::set_mmap_name(const StringView& name) void Bitmap::fill(Color color) { - ASSERT(m_format == Bitmap::Format::RGB32 || m_format == Bitmap::Format::RGBA32); + ASSERT(m_format == BitmapFormat::RGB32 || m_format == BitmapFormat::RGBA32); for (int y = 0; y < height(); ++y) { auto* scanline = this->scanline(y); fast_u32_fill(scanline, color.value(), width()); @@ -175,4 +175,9 @@ void Bitmap::set_volatile() return rc == 0; } +int Bitmap::shared_buffer_id() const +{ + return m_shared_buffer ? m_shared_buffer->shared_buffer_id() : -1; +} + } diff --git a/Libraries/LibGfx/Bitmap.h b/Libraries/LibGfx/Bitmap.h index 7c64eafd1b..5dec6a2f78 100644 --- a/Libraries/LibGfx/Bitmap.h +++ b/Libraries/LibGfx/Bitmap.h @@ -26,33 +26,32 @@ #pragma once -#include "Color.h" -#include "Rect.h" -#include "Size.h" +#include <AK/Forward.h> #include <AK/MappedFile.h> #include <AK/RefCounted.h> #include <AK/RefPtr.h> -#include <AK/SharedBuffer.h> #include <AK/String.h> -#include <AK/StringView.h> +#include <LibGfx/Color.h> +#include <LibGfx/Rect.h> +#include <LibGfx/Size.h> namespace Gfx { +enum class BitmapFormat { + Invalid, + RGB32, + RGBA32, + Indexed8 +}; + class Bitmap : public RefCounted<Bitmap> { public: - enum class Format { - Invalid, - RGB32, - RGBA32, - Indexed8 - }; - - static NonnullRefPtr<Bitmap> create(Format, const Size&); - static NonnullRefPtr<Bitmap> create_purgeable(Format, const Size&); - static NonnullRefPtr<Bitmap> create_wrapper(Format, const Size&, size_t pitch, RGBA32*); + static NonnullRefPtr<Bitmap> create(BitmapFormat, const Size&); + static NonnullRefPtr<Bitmap> create_purgeable(BitmapFormat, const Size&); + static NonnullRefPtr<Bitmap> create_wrapper(BitmapFormat, const Size&, size_t pitch, RGBA32*); static RefPtr<Bitmap> load_from_file(const StringView& path); - static RefPtr<Bitmap> load_from_file(Format, const StringView& path, const Size&); - static NonnullRefPtr<Bitmap> create_with_shared_buffer(Format, NonnullRefPtr<SharedBuffer>&&, const Size&); + static RefPtr<Bitmap> load_from_file(BitmapFormat, const StringView& path, const Size&); + static NonnullRefPtr<Bitmap> create_with_shared_buffer(BitmapFormat, NonnullRefPtr<SharedBuffer>&&, const Size&); NonnullRefPtr<Bitmap> to_shareable_bitmap() const; @@ -69,7 +68,7 @@ public: int width() const { return m_size.width(); } int height() const { return m_size.height(); } size_t pitch() const { return m_pitch; } - int shared_buffer_id() const { return m_shared_buffer ? m_shared_buffer->shared_buffer_id() : -1; } + int shared_buffer_id() const; SharedBuffer* shared_buffer() { return m_shared_buffer.ptr(); } const SharedBuffer* shared_buffer() const { return m_shared_buffer.ptr(); } @@ -77,22 +76,22 @@ public: unsigned bpp() const { switch (m_format) { - case Format::Indexed8: + case BitmapFormat::Indexed8: return 8; - case Format::RGB32: - case Format::RGBA32: + case BitmapFormat::RGB32: + case BitmapFormat::RGBA32: return 32; default: ASSERT_NOT_REACHED(); - case Format::Invalid: + case BitmapFormat::Invalid: return 0; } } void fill(Color); - bool has_alpha_channel() const { return m_format == Format::RGBA32; } - Format format() const { return m_format; } + bool has_alpha_channel() const { return m_format == BitmapFormat::RGBA32; } + BitmapFormat format() const { return m_format; } void set_mmap_name(const StringView&); @@ -101,7 +100,7 @@ public: Color palette_color(u8 index) const { return Color::from_rgba(m_palette[index]); } void set_palette_color(u8 index, Color color) { m_palette[index] = color.value(); } - template<Format> + template<BitmapFormat> Color get_pixel(int x, int y) const { (void)x; @@ -116,7 +115,7 @@ public: return get_pixel(position.x(), position.y()); } - template<Format> + template<BitmapFormat> void set_pixel(int x, int y, Color) { (void)x; @@ -139,16 +138,16 @@ public: private: enum class Purgeable { No, Yes }; - Bitmap(Format, const Size&, Purgeable); - Bitmap(Format, const Size&, size_t pitch, RGBA32*); - Bitmap(Format, const Size&, MappedFile&&); - Bitmap(Format, NonnullRefPtr<SharedBuffer>&&, const Size&); + Bitmap(BitmapFormat, const Size&, Purgeable); + Bitmap(BitmapFormat, const Size&, size_t pitch, RGBA32*); + Bitmap(BitmapFormat, const Size&, MappedFile&&); + Bitmap(BitmapFormat, NonnullRefPtr<SharedBuffer>&&, const Size&); Size m_size; RGBA32* m_data { nullptr }; RGBA32* m_palette { nullptr }; size_t m_pitch { 0 }; - Format m_format { Format::Invalid }; + BitmapFormat m_format { BitmapFormat::Invalid }; bool m_needs_munmap { false }; bool m_purgeable { false }; bool m_volatile { false }; @@ -177,19 +176,19 @@ inline u8* Bitmap::bits(int y) } template<> -inline Color Bitmap::get_pixel<Bitmap::Format::RGB32>(int x, int y) const +inline Color Bitmap::get_pixel<BitmapFormat::RGB32>(int x, int y) const { return Color::from_rgb(scanline(y)[x]); } template<> -inline Color Bitmap::get_pixel<Bitmap::Format::RGBA32>(int x, int y) const +inline Color Bitmap::get_pixel<BitmapFormat::RGBA32>(int x, int y) const { return Color::from_rgba(scanline(y)[x]); } template<> -inline Color Bitmap::get_pixel<Bitmap::Format::Indexed8>(int x, int y) const +inline Color Bitmap::get_pixel<BitmapFormat::Indexed8>(int x, int y) const { return Color::from_rgba(m_palette[bits(y)[x]]); } @@ -197,12 +196,12 @@ inline Color Bitmap::get_pixel<Bitmap::Format::Indexed8>(int x, int y) const inline Color Bitmap::get_pixel(int x, int y) const { switch (m_format) { - case Format::RGB32: - return get_pixel<Format::RGB32>(x, y); - case Format::RGBA32: - return get_pixel<Format::RGBA32>(x, y); - case Format::Indexed8: - return get_pixel<Format::Indexed8>(x, y); + case BitmapFormat::RGB32: + return get_pixel<BitmapFormat::RGB32>(x, y); + case BitmapFormat::RGBA32: + return get_pixel<BitmapFormat::RGBA32>(x, y); + case BitmapFormat::Indexed8: + return get_pixel<BitmapFormat::Indexed8>(x, y); default: ASSERT_NOT_REACHED(); return {}; @@ -210,13 +209,13 @@ inline Color Bitmap::get_pixel(int x, int y) const } template<> -inline void Bitmap::set_pixel<Bitmap::Format::RGB32>(int x, int y, Color color) +inline void Bitmap::set_pixel<BitmapFormat::RGB32>(int x, int y, Color color) { scanline(y)[x] = color.value(); } template<> -inline void Bitmap::set_pixel<Bitmap::Format::RGBA32>(int x, int y, Color color) +inline void Bitmap::set_pixel<BitmapFormat::RGBA32>(int x, int y, Color color) { scanline(y)[x] = color.value(); } @@ -224,13 +223,13 @@ inline void Bitmap::set_pixel<Bitmap::Format::RGBA32>(int x, int y, Color color) inline void Bitmap::set_pixel(int x, int y, Color color) { switch (m_format) { - case Format::RGB32: - set_pixel<Format::RGB32>(x, y, color); + case BitmapFormat::RGB32: + set_pixel<BitmapFormat::RGB32>(x, y, color); break; - case Format::RGBA32: - set_pixel<Format::RGBA32>(x, y, color); + case BitmapFormat::RGBA32: + set_pixel<BitmapFormat::RGBA32>(x, y, color); break; - case Format::Indexed8: + case BitmapFormat::Indexed8: ASSERT_NOT_REACHED(); default: ASSERT_NOT_REACHED(); diff --git a/Libraries/LibGfx/Forward.h b/Libraries/LibGfx/Forward.h new file mode 100644 index 0000000000..cef4ce84c7 --- /dev/null +++ b/Libraries/LibGfx/Forward.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2020, Andreas Kling <kling@serenityos.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +namespace Gfx { + +class Bitmap; +class CharacterBitmap; +class Color; +class DisjointRectSet; +class FloatPoint; +class FloatRect; +class FloatSize; +class Font; +class Painter; +class Palette; +class Point; +class Rect; +class Size; +class StylePainter; +class SystemTheme; +class Triangle; + +enum class BitmapFormat; + +} + +using Gfx::Color; diff --git a/Libraries/LibGfx/PNGLoader.cpp b/Libraries/LibGfx/PNGLoader.cpp index 863c63d806..d425f24a49 100644 --- a/Libraries/LibGfx/PNGLoader.cpp +++ b/Libraries/LibGfx/PNGLoader.cpp @@ -520,7 +520,7 @@ static bool decode_png_bitmap(PNGLoadingContext& context) } } - context.bitmap = Bitmap::create_purgeable(context.has_alpha() ? Bitmap::Format::RGBA32 : Bitmap::Format::RGB32, { context.width, context.height }); + context.bitmap = Bitmap::create_purgeable(context.has_alpha() ? BitmapFormat::RGBA32 : BitmapFormat::RGB32, { context.width, context.height }); unfilter(context); diff --git a/Libraries/LibGfx/Painter.cpp b/Libraries/LibGfx/Painter.cpp index c6b0091bc5..2e85a5184f 100644 --- a/Libraries/LibGfx/Painter.cpp +++ b/Libraries/LibGfx/Painter.cpp @@ -51,14 +51,14 @@ namespace Gfx { -template<Bitmap::Format format = Bitmap::Format::Invalid> +template<BitmapFormat format = BitmapFormat::Invalid> static ALWAYS_INLINE Color get_pixel(const Gfx::Bitmap& bitmap, int x, int y) { - if constexpr (format == Bitmap::Format::Indexed8) + if constexpr (format == BitmapFormat::Indexed8) return bitmap.palette_color(bitmap.bits(y)[x]); - if constexpr (format == Bitmap::Format::RGB32) + if constexpr (format == BitmapFormat::RGB32) return Color::from_rgb(bitmap.scanline(y)[x]); - if constexpr (format == Bitmap::Format::RGBA32) + if constexpr (format == BitmapFormat::RGBA32) return Color::from_rgba(bitmap.scanline(y)[x]); return bitmap.get_pixel(x, y); } @@ -399,7 +399,7 @@ void Painter::draw_tiled_bitmap(const Rect& a_dst_rect, const Gfx::Bitmap& sourc RGBA32* dst = m_target->scanline(clipped_rect.y()) + clipped_rect.x(); const size_t dst_skip = m_target->pitch() / sizeof(RGBA32); - if (source.format() == Bitmap::Format::RGB32 || source.format() == Bitmap::Format::RGBA32) { + if (source.format() == BitmapFormat::RGB32 || source.format() == BitmapFormat::RGBA32) { int x_start = first_column + a_dst_rect.left(); for (int row = first_row; row <= last_row; ++row) { const RGBA32* sl = source.scanline((row + a_dst_rect.top()) @@ -430,7 +430,7 @@ void Painter::blit_offset(const Point& position, RGBA32* dst = m_target->scanline(clipped_rect.y()) + clipped_rect.x(); const size_t dst_skip = m_target->pitch() / sizeof(RGBA32); - if (source.format() == Bitmap::Format::RGB32 || source.format() == Bitmap::Format::RGBA32) { + if (source.format() == BitmapFormat::RGB32 || source.format() == BitmapFormat::RGBA32) { int x_start = first_column + src_rect.left(); for (int row = first_row; row <= last_row; ++row) { int sr = row - offset.y() + src_rect.top(); @@ -502,7 +502,7 @@ void Painter::blit(const Point& position, const Gfx::Bitmap& source, const Rect& RGBA32* dst = m_target->scanline(clipped_rect.y()) + clipped_rect.x(); const size_t dst_skip = m_target->pitch() / sizeof(RGBA32); - if (source.format() == Bitmap::Format::RGB32 || source.format() == Bitmap::Format::RGBA32) { + if (source.format() == BitmapFormat::RGB32 || source.format() == BitmapFormat::RGBA32) { const RGBA32* src = source.scanline(src_rect.top() + first_row) + src_rect.left() + first_column; const size_t src_skip = source.pitch() / sizeof(RGBA32); for (int row = first_row; row <= last_row; ++row) { @@ -513,7 +513,7 @@ void Painter::blit(const Point& position, const Gfx::Bitmap& source, const Rect& return; } - if (source.format() == Bitmap::Format::Indexed8) { + if (source.format() == BitmapFormat::Indexed8) { const u8* src = source.bits(src_rect.top() + first_row) + src_rect.left() + first_column; const size_t src_skip = source.pitch(); for (int row = first_row; row <= last_row; ++row) { @@ -597,32 +597,32 @@ void Painter::draw_scaled_bitmap(const Rect& a_dst_rect, const Gfx::Bitmap& sour if (source.has_alpha_channel()) { switch (source.format()) { - case Bitmap::Format::RGB32: - do_draw_scaled_bitmap<true>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<Bitmap::Format::RGB32>); + case BitmapFormat::RGB32: + do_draw_scaled_bitmap<true>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<BitmapFormat::RGB32>); break; - case Bitmap::Format::RGBA32: - do_draw_scaled_bitmap<true>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<Bitmap::Format::RGBA32>); + case BitmapFormat::RGBA32: + do_draw_scaled_bitmap<true>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<BitmapFormat::RGBA32>); break; - case Bitmap::Format::Indexed8: - do_draw_scaled_bitmap<true>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<Bitmap::Format::Indexed8>); + case BitmapFormat::Indexed8: + do_draw_scaled_bitmap<true>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<BitmapFormat::Indexed8>); break; default: - do_draw_scaled_bitmap<true>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<Bitmap::Format::Invalid>); + do_draw_scaled_bitmap<true>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<BitmapFormat::Invalid>); break; } } else { switch (source.format()) { - case Bitmap::Format::RGB32: - do_draw_scaled_bitmap<false>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<Bitmap::Format::RGB32>); + case BitmapFormat::RGB32: + do_draw_scaled_bitmap<false>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<BitmapFormat::RGB32>); break; - case Bitmap::Format::RGBA32: - do_draw_scaled_bitmap<false>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<Bitmap::Format::RGBA32>); + case BitmapFormat::RGBA32: + do_draw_scaled_bitmap<false>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<BitmapFormat::RGBA32>); break; - case Bitmap::Format::Indexed8: - do_draw_scaled_bitmap<false>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<Bitmap::Format::Indexed8>); + case BitmapFormat::Indexed8: + do_draw_scaled_bitmap<false>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<BitmapFormat::Indexed8>); break; default: - do_draw_scaled_bitmap<false>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<Bitmap::Format::Invalid>); + do_draw_scaled_bitmap<false>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<BitmapFormat::Invalid>); break; } } diff --git a/Libraries/LibGfx/Palette.cpp b/Libraries/LibGfx/Palette.cpp index 928387cb97..904b7722ab 100644 --- a/Libraries/LibGfx/Palette.cpp +++ b/Libraries/LibGfx/Palette.cpp @@ -24,6 +24,8 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include <AK/Badge.h> +#include <AK/SharedBuffer.h> #include <LibGfx/Palette.h> namespace Gfx { @@ -73,4 +75,13 @@ void Palette::set_color(ColorRole role, Color color) theme.color[(int)role] = color; } +PaletteImpl::~PaletteImpl() +{ +} + +void PaletteImpl::replace_internal_buffer(Badge<GUI::Application>, SharedBuffer& buffer) +{ + m_theme_buffer = buffer; +} + } diff --git a/Libraries/LibGfx/Palette.h b/Libraries/LibGfx/Palette.h index 76c7db2826..c0c5ae9abe 100644 --- a/Libraries/LibGfx/Palette.h +++ b/Libraries/LibGfx/Palette.h @@ -26,7 +26,7 @@ #pragma once -#include <AK/Badge.h> +#include <AK/Forward.h> #include <AK/Noncopyable.h> #include <LibGfx/SystemTheme.h> @@ -40,13 +40,14 @@ class PaletteImpl : public RefCounted<PaletteImpl> { AK_MAKE_NONCOPYABLE(PaletteImpl) AK_MAKE_NONMOVABLE(PaletteImpl) public: + ~PaletteImpl(); static NonnullRefPtr<PaletteImpl> create_with_shared_buffer(SharedBuffer&); NonnullRefPtr<PaletteImpl> clone() const; Color color(ColorRole) const; const SystemTheme& theme() const; - void replace_internal_buffer(Badge<GUI::Application>, SharedBuffer& buffer) { m_theme_buffer = buffer; } + void replace_internal_buffer(Badge<GUI::Application>, SharedBuffer& buffer); private: explicit PaletteImpl(SharedBuffer&); diff --git a/Libraries/LibGfx/SystemTheme.cpp b/Libraries/LibGfx/SystemTheme.cpp index 49e84ea136..8ae4be8df7 100644 --- a/Libraries/LibGfx/SystemTheme.cpp +++ b/Libraries/LibGfx/SystemTheme.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include <AK/SharedBuffer.h> #include <LibCore/ConfigFile.h> #include <LibGfx/SystemTheme.h> diff --git a/Libraries/LibGfx/SystemTheme.h b/Libraries/LibGfx/SystemTheme.h index ae27b84113..4747209e52 100644 --- a/Libraries/LibGfx/SystemTheme.h +++ b/Libraries/LibGfx/SystemTheme.h @@ -26,7 +26,7 @@ #pragma once -#include <AK/SharedBuffer.h> +#include <AK/Forward.h> #include <AK/Types.h> #include <LibGfx/Color.h> |