diff options
author | Andreas Kling <kling@serenityos.org> | 2021-07-21 18:02:15 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-21 18:02:15 +0200 |
commit | c7d891765cc87ec04f8d332b93fc7c3f82521d7f (patch) | |
tree | 9d414d3ad62e0193b1b6fb0d12079e11e96e69b1 /Userland/Libraries | |
parent | f0409081f562b635de3a23d7babbc7348cbb970c (diff) | |
download | serenity-c7d891765cc87ec04f8d332b93fc7c3f82521d7f.zip |
LibGfx: Use "try_" prefix for static factory functions
Also mark them as [[nodiscard]].
Diffstat (limited to 'Userland/Libraries')
41 files changed, 120 insertions, 119 deletions
diff --git a/Userland/Libraries/LibCards/Card.cpp b/Userland/Libraries/LibCards/Card.cpp index 2a88e45e82..2c27912d86 100644 --- a/Userland/Libraries/LibCards/Card.cpp +++ b/Userland/Libraries/LibCards/Card.cpp @@ -64,7 +64,7 @@ static RefPtr<Gfx::Bitmap> s_background_inverted; Card::Card(Type type, uint8_t value) : m_rect(Gfx::IntRect({}, { width, height })) - , m_front(*Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, { width, height })) + , m_front(*Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, { width, height })) , m_type(type) , m_value(value) { @@ -72,10 +72,10 @@ Card::Card(Type type, uint8_t value) Gfx::IntRect paint_rect({ 0, 0 }, { width, height }); if (s_background.is_null()) { - s_background = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, { width, height }); + s_background = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, { width, height }); Gfx::Painter bg_painter(*s_background); - auto image = Gfx::Bitmap::load_from_file("/res/icons/cards/buggie-deck.png"); + auto image = Gfx::Bitmap::try_load_from_file("/res/icons/cards/buggie-deck.png"); VERIFY(!image.is_null()); float aspect_ratio = image->width() / static_cast<float>(image->height()); diff --git a/Userland/Libraries/LibGL/SoftwareRasterizer.cpp b/Userland/Libraries/LibGL/SoftwareRasterizer.cpp index 41f4a48b1b..8ef38b1a24 100644 --- a/Userland/Libraries/LibGL/SoftwareRasterizer.cpp +++ b/Userland/Libraries/LibGL/SoftwareRasterizer.cpp @@ -409,7 +409,7 @@ static Gfx::IntSize closest_multiple(const Gfx::IntSize& min_size, size_t step) } SoftwareRasterizer::SoftwareRasterizer(const Gfx::IntSize& min_size) - : m_render_target { Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, closest_multiple(min_size, RASTERIZER_BLOCK_SIZE)) } + : m_render_target { Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, closest_multiple(min_size, RASTERIZER_BLOCK_SIZE)) } , m_depth_buffer { adopt_own(*new DepthBuffer(closest_multiple(min_size, RASTERIZER_BLOCK_SIZE))) } { } @@ -446,7 +446,7 @@ void SoftwareRasterizer::resize(const Gfx::IntSize& min_size) { wait_for_all_threads(); - m_render_target = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, closest_multiple(min_size, RASTERIZER_BLOCK_SIZE)); + m_render_target = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, closest_multiple(min_size, RASTERIZER_BLOCK_SIZE)); m_depth_buffer = adopt_own(*new DepthBuffer(m_render_target->size())); } diff --git a/Userland/Libraries/LibGUI/Action.cpp b/Userland/Libraries/LibGUI/Action.cpp index 98abcaa415..53da395f4d 100644 --- a/Userland/Libraries/LibGUI/Action.cpp +++ b/Userland/Libraries/LibGUI/Action.cpp @@ -30,71 +30,71 @@ NonnullRefPtr<Action> make_about_action(const String& app_name, const Icon& app_ NonnullRefPtr<Action> make_open_action(Function<void(Action&)> callback, Core::Object* parent) { - auto action = Action::create("&Open...", { Mod_Ctrl, Key_O }, Gfx::Bitmap::load_from_file("/res/icons/16x16/open.png"), move(callback), parent); + auto action = Action::create("&Open...", { Mod_Ctrl, Key_O }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/open.png"), move(callback), parent); action->set_status_tip("Open an existing file"); return action; } NonnullRefPtr<Action> make_save_action(Function<void(Action&)> callback, Core::Object* parent) { - auto action = Action::create("&Save", { Mod_Ctrl, Key_S }, Gfx::Bitmap::load_from_file("/res/icons/16x16/save.png"), move(callback), parent); + auto action = Action::create("&Save", { Mod_Ctrl, Key_S }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/save.png"), move(callback), parent); action->set_status_tip("Save the current file"); return action; } NonnullRefPtr<Action> make_save_as_action(Function<void(Action&)> callback, Core::Object* parent) { - auto action = Action::create("Save &As...", { Mod_Ctrl | Mod_Shift, Key_S }, Gfx::Bitmap::load_from_file("/res/icons/16x16/save.png"), move(callback), parent); + auto action = Action::create("Save &As...", { Mod_Ctrl | Mod_Shift, Key_S }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/save.png"), move(callback), parent); action->set_status_tip("Save the current file with a new name"); return action; } NonnullRefPtr<Action> make_move_to_front_action(Function<void(Action&)> callback, Core::Object* parent) { - auto action = 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); + auto action = Action::create("Move to &Front", { Mod_Ctrl | Mod_Shift, Key_Up }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/move-to-front.png"), move(callback), parent); action->set_status_tip("Move to the top of the stack"); return action; } NonnullRefPtr<Action> make_move_to_back_action(Function<void(Action&)> callback, Core::Object* parent) { - auto action = 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); + auto action = Action::create("Move to &Back", { Mod_Ctrl | Mod_Shift, Key_Down }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/move-to-back.png"), move(callback), parent); action->set_status_tip("Move to the bottom of the stack"); return action; } 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); + return Action::create("&Undo", { Mod_Ctrl, Key_Z }, Gfx::Bitmap::try_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); + return Action::create("&Redo", { Mod_Ctrl, Key_Y }, Gfx::Bitmap::try_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); + return Action::create("&Delete", { Mod_None, Key_Delete }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/delete.png"), move(callback), parent); } NonnullRefPtr<Action> make_cut_action(Function<void(Action&)> callback, Core::Object* parent) { - auto action = Action::create("Cu&t", { Mod_Ctrl, Key_X }, Gfx::Bitmap::load_from_file("/res/icons/16x16/edit-cut.png"), move(callback), parent); + auto action = Action::create("Cu&t", { Mod_Ctrl, Key_X }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/edit-cut.png"), move(callback), parent); action->set_status_tip("Cut to clipboard"); return action; } NonnullRefPtr<Action> make_copy_action(Function<void(Action&)> callback, Core::Object* parent) { - auto action = Action::create("&Copy", { Mod_Ctrl, Key_C }, Gfx::Bitmap::load_from_file("/res/icons/16x16/edit-copy.png"), move(callback), parent); + auto action = Action::create("&Copy", { Mod_Ctrl, Key_C }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/edit-copy.png"), move(callback), parent); action->set_status_tip("Copy to clipboard"); return action; } NonnullRefPtr<Action> make_paste_action(Function<void(Action&)> callback, Core::Object* parent) { - auto action = Action::create("&Paste", { Mod_Ctrl, Key_V }, Gfx::Bitmap::load_from_file("/res/icons/16x16/paste.png"), move(callback), parent); + auto action = Action::create("&Paste", { Mod_Ctrl, Key_V }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/paste.png"), move(callback), parent); action->set_status_tip("Paste from clipboard"); return action; } @@ -115,63 +115,63 @@ NonnullRefPtr<Action> make_quit_action(Function<void(Action&)> callback) NonnullRefPtr<Action> make_help_action(Function<void(Action&)> callback, Core::Object* parent) { - auto action = Action::create("&Contents", { Mod_None, Key_F1 }, Gfx::Bitmap::load_from_file("/res/icons/16x16/app-help.png"), move(callback), parent); + auto action = Action::create("&Contents", { Mod_None, Key_F1 }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-help.png"), move(callback), parent); action->set_status_tip("Show help contents"); return action; } NonnullRefPtr<Action> make_go_back_action(Function<void(Action&)> callback, Core::Object* parent) { - auto action = Action::create("Go &Back", { Mod_Alt, Key_Left }, Gfx::Bitmap::load_from_file("/res/icons/16x16/go-back.png"), move(callback), parent); + auto action = Action::create("Go &Back", { Mod_Alt, Key_Left }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-back.png"), move(callback), parent); action->set_status_tip("Move one step backward in history"); return action; } NonnullRefPtr<Action> make_go_forward_action(Function<void(Action&)> callback, Core::Object* parent) { - auto action = Action::create("Go &Forward", { Mod_Alt, Key_Right }, Gfx::Bitmap::load_from_file("/res/icons/16x16/go-forward.png"), move(callback), parent); + auto action = Action::create("Go &Forward", { Mod_Alt, Key_Right }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-forward.png"), move(callback), parent); action->set_status_tip("Move one step forward in history"); return action; } 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); + return Action::create("Go &Home", { Mod_Alt, Key_Home }, Gfx::Bitmap::try_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 }, Key_F5, Gfx::Bitmap::load_from_file("/res/icons/16x16/reload.png"), move(callback), parent); + return Action::create("&Reload", { Mod_Ctrl, Key_R }, Key_F5, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/reload.png"), move(callback), parent); } NonnullRefPtr<Action> make_select_all_action(Function<void(Action&)> callback, Core::Object* parent) { - return Action::create("Select &All", { Mod_Ctrl, Key_A }, Gfx::Bitmap::load_from_file("/res/icons/16x16/select-all.png"), move(callback), parent); + return Action::create("Select &All", { Mod_Ctrl, Key_A }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/select-all.png"), move(callback), parent); } NonnullRefPtr<Action> make_rename_action(Function<void(Action&)> callback, Core::Object* parent) { - return Action::create("Re&name", Key_F2, Gfx::Bitmap::load_from_file("/res/icons/16x16/rename.png"), move(callback), parent); + return Action::create("Re&name", Key_F2, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/rename.png"), move(callback), parent); } NonnullRefPtr<Action> make_properties_action(Function<void(Action&)> callback, Core::Object* parent) { - return Action::create("P&roperties", { Mod_Alt, Key_Return }, Gfx::Bitmap::load_from_file("/res/icons/16x16/properties.png"), move(callback), parent); + return Action::create("P&roperties", { Mod_Alt, Key_Return }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/properties.png"), move(callback), parent); } NonnullRefPtr<Action> make_zoom_in_action(Function<void(Action&)> callback, Core::Object* parent) { - return GUI::Action::create("Zoom &In", { Mod_Ctrl, Key_Equal }, Gfx::Bitmap::load_from_file("/res/icons/16x16/zoom-in.png"), move(callback), parent); + return GUI::Action::create("Zoom &In", { Mod_Ctrl, Key_Equal }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/zoom-in.png"), move(callback), parent); } NonnullRefPtr<Action> make_reset_zoom_action(Function<void(Action&)> callback, Core::Object* parent) { - return GUI::Action::create("&Reset Zoom", { Mod_Ctrl, Key_0 }, Gfx::Bitmap::load_from_file("/res/icons/16x16/zoom-reset.png"), move(callback), parent); + return GUI::Action::create("&Reset Zoom", { Mod_Ctrl, Key_0 }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/zoom-reset.png"), move(callback), parent); } NonnullRefPtr<Action> make_zoom_out_action(Function<void(Action&)> callback, Core::Object* parent) { - return GUI::Action::create("Zoom &Out", { Mod_Ctrl, Key_Minus }, Gfx::Bitmap::load_from_file("/res/icons/16x16/zoom-out.png"), move(callback), parent); + return GUI::Action::create("Zoom &Out", { Mod_Ctrl, Key_Minus }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/zoom-out.png"), move(callback), parent); } } diff --git a/Userland/Libraries/LibGUI/AutocompleteProvider.cpp b/Userland/Libraries/LibGUI/AutocompleteProvider.cpp index c5c129d1a7..63e5ab18d7 100644 --- a/Userland/Libraries/LibGUI/AutocompleteProvider.cpp +++ b/Userland/Libraries/LibGUI/AutocompleteProvider.cpp @@ -47,13 +47,13 @@ public: if (index.column() == Column::Icon) { if (suggestion.language == GUI::AutocompleteProvider::Language::Cpp) { if (!s_cpp_identifier_icon) { - s_cpp_identifier_icon = Gfx::Bitmap::load_from_file("/res/icons/16x16/completion/cpp-identifier.png"); + s_cpp_identifier_icon = Gfx::Bitmap::try_load_from_file("/res/icons/16x16/completion/cpp-identifier.png"); } return *s_cpp_identifier_icon; } if (suggestion.language == GUI::AutocompleteProvider::Language::Unspecified) { if (!s_unspecified_identifier_icon) { - s_unspecified_identifier_icon = Gfx::Bitmap::load_from_file("/res/icons/16x16/completion/unspecified-identifier.png"); + s_unspecified_identifier_icon = Gfx::Bitmap::try_load_from_file("/res/icons/16x16/completion/unspecified-identifier.png"); } return *s_unspecified_identifier_icon; } diff --git a/Userland/Libraries/LibGUI/Clipboard.cpp b/Userland/Libraries/LibGUI/Clipboard.cpp index 2c7c557744..b41a435d98 100644 --- a/Userland/Libraries/LibGUI/Clipboard.cpp +++ b/Userland/Libraries/LibGUI/Clipboard.cpp @@ -113,8 +113,8 @@ RefPtr<Gfx::Bitmap> Clipboard::bitmap() const if (!format.has_value() || format.value() == 0) return nullptr; - auto clipping_bitmap = Gfx::Bitmap::create_wrapper((Gfx::BitmapFormat)format.value(), { (int)width.value(), (int)height.value() }, scale.value(), pitch.value(), clipping.data.data()); - auto bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, { (int)width.value(), (int)height.value() }, scale.value()); + auto clipping_bitmap = Gfx::Bitmap::try_create_wrapper((Gfx::BitmapFormat)format.value(), { (int)width.value(), (int)height.value() }, scale.value(), pitch.value(), clipping.data.data()); + auto bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, { (int)width.value(), (int)height.value() }, scale.value()); for (int y = 0; y < clipping_bitmap->physical_height(); ++y) { for (int x = 0; x < clipping_bitmap->physical_width(); ++x) { diff --git a/Userland/Libraries/LibGUI/ColorPicker.cpp b/Userland/Libraries/LibGUI/ColorPicker.cpp index 780cdff359..5eba8fdab9 100644 --- a/Userland/Libraries/LibGUI/ColorPicker.cpp +++ b/Userland/Libraries/LibGUI/ColorPicker.cpp @@ -129,7 +129,7 @@ ColorPicker::ColorPicker(Color color, Window* parent_window, String title) : Dialog(parent_window) , m_color(color) { - set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/color-chooser.png")); + set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/color-chooser.png")); set_title(title); set_resizable(false); resize(458, 326); @@ -459,7 +459,7 @@ ColorField::ColorField(Color color) void ColorField::create_color_bitmap() { - m_color_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, { 256, 256 }); + m_color_bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { 256, 256 }); auto painter = Gfx::Painter(*m_color_bitmap); Gfx::HSV hsv; @@ -585,7 +585,7 @@ void ColorField::resize_event(ResizeEvent&) ColorSlider::ColorSlider(double value) : m_value(value) { - m_color_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, { 32, 360 }); + m_color_bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { 32, 360 }); auto painter = Gfx::Painter(*m_color_bitmap); for (int h = 0; h < 360; h++) { diff --git a/Userland/Libraries/LibGUI/ComboBox.cpp b/Userland/Libraries/LibGUI/ComboBox.cpp index bb03e42acb..e759fab601 100644 --- a/Userland/Libraries/LibGUI/ComboBox.cpp +++ b/Userland/Libraries/LibGUI/ComboBox.cpp @@ -75,7 +75,7 @@ ComboBox::ComboBox() }; m_open_button = add<Button>(); - m_open_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/downward-triangle.png")); + m_open_button->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/downward-triangle.png")); m_open_button->set_focus_policy(GUI::FocusPolicy::NoFocus); m_open_button->on_click = [this](auto) { if (m_list_window->is_visible()) diff --git a/Userland/Libraries/LibGUI/DragOperation.cpp b/Userland/Libraries/LibGUI/DragOperation.cpp index d0aa5c76d6..62157f5b6c 100644 --- a/Userland/Libraries/LibGUI/DragOperation.cpp +++ b/Userland/Libraries/LibGUI/DragOperation.cpp @@ -33,7 +33,7 @@ DragOperation::Outcome DragOperation::exec() Gfx::ShareableBitmap drag_bitmap; if (m_mime_data->has_format("image/x-raw-bitmap")) { auto data = m_mime_data->data("image/x-raw-bitmap"); - auto bitmap = Gfx::Bitmap::create_from_serialized_byte_buffer(move(data)); + auto bitmap = Gfx::Bitmap::try_create_from_serialized_byte_buffer(move(data)); drag_bitmap = bitmap->to_shareable_bitmap(); } diff --git a/Userland/Libraries/LibGUI/FileIconProvider.cpp b/Userland/Libraries/LibGUI/FileIconProvider.cpp index d4209c89d3..d06c8d0a50 100644 --- a/Userland/Libraries/LibGUI/FileIconProvider.cpp +++ b/Userland/Libraries/LibGUI/FileIconProvider.cpp @@ -56,8 +56,8 @@ static void initialize_if_needed() auto config = Core::ConfigFile::open("/etc/FileIconProvider.ini"); - s_symlink_emblem = Gfx::Bitmap::load_from_file("/res/icons/symlink-emblem.png"); - s_symlink_emblem_small = Gfx::Bitmap::load_from_file("/res/icons/symlink-emblem-small.png"); + s_symlink_emblem = Gfx::Bitmap::try_load_from_file("/res/icons/symlink-emblem.png"); + s_symlink_emblem_small = Gfx::Bitmap::try_load_from_file("/res/icons/symlink-emblem-small.png"); s_hard_disk_icon = Icon::default_icon("hard-disk"); s_directory_icon = Icon::default_icon("filetype-folder"); diff --git a/Userland/Libraries/LibGUI/FilePicker.cpp b/Userland/Libraries/LibGUI/FilePicker.cpp index c8cf52bcbe..fee2f76185 100644 --- a/Userland/Libraries/LibGUI/FilePicker.cpp +++ b/Userland/Libraries/LibGUI/FilePicker.cpp @@ -72,11 +72,11 @@ FilePicker::FilePicker(Window* parent_window, Mode mode, const StringView& filen case Mode::OpenMultiple: case Mode::OpenFolder: set_title("Open"); - set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/open.png")); + set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/open.png")); break; case Mode::Save: set_title("Save as"); - set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/save.png")); + set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/save.png")); break; } resize(560, 320); @@ -109,7 +109,7 @@ FilePicker::FilePicker(Window* parent_window, Mode mode, const StringView& filen }; auto open_parent_directory_action = Action::create( - "Open parent directory", { Mod_Alt, Key_Up }, Gfx::Bitmap::load_from_file("/res/icons/16x16/open-parent-directory.png"), [this](const Action&) { + "Open parent directory", { Mod_Alt, Key_Up }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/open-parent-directory.png"), [this](const Action&) { set_path(String::formatted("{}/..", m_model->root_path())); }, this); @@ -123,7 +123,7 @@ FilePicker::FilePicker(Window* parent_window, Mode mode, const StringView& filen toolbar.add_separator(); auto mkdir_action = Action::create( - "New directory...", Gfx::Bitmap::load_from_file("/res/icons/16x16/mkdir.png"), [this](const Action&) { + "New directory...", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/mkdir.png"), [this](const Action&) { String value; if (InputBox::show(this, value, "Enter name:", "New directory") == InputBox::ExecOK && !value.is_empty()) { auto new_dir_path = LexicalPath::canonicalized_path(String::formatted("{}/{}", m_model->root_path(), value)); diff --git a/Userland/Libraries/LibGUI/FileSystemModel.cpp b/Userland/Libraries/LibGUI/FileSystemModel.cpp index 6e0a9530be..dfe7b37185 100644 --- a/Userland/Libraries/LibGUI/FileSystemModel.cpp +++ b/Userland/Libraries/LibGUI/FileSystemModel.cpp @@ -550,13 +550,13 @@ static HashMap<String, RefPtr<Gfx::Bitmap>> s_thumbnail_cache; static RefPtr<Gfx::Bitmap> render_thumbnail(const StringView& path) { - auto png_bitmap = Gfx::Bitmap::load_from_file(path); + auto png_bitmap = Gfx::Bitmap::try_load_from_file(path); if (!png_bitmap) return nullptr; double scale = min(32 / (double)png_bitmap->width(), 32 / (double)png_bitmap->height()); - auto thumbnail = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, { 32, 32 }); + auto thumbnail = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, { 32, 32 }); Gfx::IntRect destination = Gfx::IntRect(0, 0, (int)(png_bitmap->width() * scale), (int)(png_bitmap->height() * scale)); destination.center_within(thumbnail->rect()); diff --git a/Userland/Libraries/LibGUI/FontPicker.cpp b/Userland/Libraries/LibGUI/FontPicker.cpp index a2e0b66709..4dce0fb203 100644 --- a/Userland/Libraries/LibGUI/FontPicker.cpp +++ b/Userland/Libraries/LibGUI/FontPicker.cpp @@ -24,7 +24,7 @@ FontPicker::FontPicker(Window* parent_window, const Gfx::Font* current_font, boo { set_title("Font picker"); resize(430, 280); - set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-font-editor.png")); + set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-font-editor.png")); auto& widget = set_main_widget<GUI::Widget>(); if (!widget.load_from_gml(font_picker_dialog_gml)) diff --git a/Userland/Libraries/LibGUI/Icon.cpp b/Userland/Libraries/LibGUI/Icon.cpp index c31d6d6180..2d686b9f9e 100644 --- a/Userland/Libraries/LibGUI/Icon.cpp +++ b/Userland/Libraries/LibGUI/Icon.cpp @@ -74,8 +74,8 @@ void IconImpl::set_bitmap_for_size(int size, RefPtr<Gfx::Bitmap>&& bitmap) Icon Icon::default_icon(const StringView& name) { - auto bitmap16 = Gfx::Bitmap::load_from_file(String::formatted("/res/icons/16x16/{}.png", name)); - auto bitmap32 = Gfx::Bitmap::load_from_file(String::formatted("/res/icons/32x32/{}.png", name)); + auto bitmap16 = Gfx::Bitmap::try_load_from_file(String::formatted("/res/icons/16x16/{}.png", name)); + auto bitmap32 = Gfx::Bitmap::try_load_from_file(String::formatted("/res/icons/32x32/{}.png", name)); return Icon(move(bitmap16), move(bitmap32)); } diff --git a/Userland/Libraries/LibGUI/LinkLabel.cpp b/Userland/Libraries/LibGUI/LinkLabel.cpp index 06f2e2a489..31706aeefc 100644 --- a/Userland/Libraries/LibGUI/LinkLabel.cpp +++ b/Userland/Libraries/LibGUI/LinkLabel.cpp @@ -29,7 +29,7 @@ LinkLabel::LinkLabel(String text) void LinkLabel::setup_actions() { - m_open_action = GUI::Action::create("Show in File Manager", {}, Gfx::Bitmap::load_from_file("/res/icons/16x16/app-file-manager.png"), [&](const GUI::Action&) { + m_open_action = GUI::Action::create("Show in File Manager", {}, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-file-manager.png"), [&](const GUI::Action&) { if (on_click) on_click(); }); diff --git a/Userland/Libraries/LibGUI/MessageBox.cpp b/Userland/Libraries/LibGUI/MessageBox.cpp index 3d366abbcb..2b0a59a5e0 100644 --- a/Userland/Libraries/LibGUI/MessageBox.cpp +++ b/Userland/Libraries/LibGUI/MessageBox.cpp @@ -45,13 +45,13 @@ RefPtr<Gfx::Bitmap> MessageBox::icon() const { switch (m_type) { case Type::Information: - return Gfx::Bitmap::load_from_file("/res/icons/32x32/msgbox-information.png"); + return Gfx::Bitmap::try_load_from_file("/res/icons/32x32/msgbox-information.png"); case Type::Warning: - return Gfx::Bitmap::load_from_file("/res/icons/32x32/msgbox-warning.png"); + return Gfx::Bitmap::try_load_from_file("/res/icons/32x32/msgbox-warning.png"); case Type::Error: - return Gfx::Bitmap::load_from_file("/res/icons/32x32/msgbox-error.png"); + return Gfx::Bitmap::try_load_from_file("/res/icons/32x32/msgbox-error.png"); case Type::Question: - return Gfx::Bitmap::load_from_file("/res/icons/32x32/msgbox-question.png"); + return Gfx::Bitmap::try_load_from_file("/res/icons/32x32/msgbox-question.png"); default: return nullptr; } diff --git a/Userland/Libraries/LibGUI/MultiView.cpp b/Userland/Libraries/LibGUI/MultiView.cpp index ffa03c25a3..c44854ce85 100644 --- a/Userland/Libraries/LibGUI/MultiView.cpp +++ b/Userland/Libraries/LibGUI/MultiView.cpp @@ -104,17 +104,17 @@ void MultiView::set_column_visible(int column_index, bool visible) void MultiView::build_actions() { m_view_as_table_action = Action::create_checkable( - "Table view", Gfx::Bitmap::load_from_file("/res/icons/16x16/table-view.png"), [this](auto&) { + "Table view", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/table-view.png"), [this](auto&) { set_view_mode(ViewMode::Table); }); m_view_as_icons_action = Action::create_checkable( - "Icon view", Gfx::Bitmap::load_from_file("/res/icons/16x16/icon-view.png"), [this](auto&) { + "Icon view", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/icon-view.png"), [this](auto&) { set_view_mode(ViewMode::Icon); }); m_view_as_columns_action = Action::create_checkable( - "Columns view", Gfx::Bitmap::load_from_file("/res/icons/16x16/columns-view.png"), [this](auto&) { + "Columns view", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/columns-view.png"), [this](auto&) { set_view_mode(ViewMode::Columns); }); diff --git a/Userland/Libraries/LibGUI/SpinBox.cpp b/Userland/Libraries/LibGUI/SpinBox.cpp index 71590307b6..59a5647398 100644 --- a/Userland/Libraries/LibGUI/SpinBox.cpp +++ b/Userland/Libraries/LibGUI/SpinBox.cpp @@ -33,12 +33,12 @@ SpinBox::SpinBox() }; m_increment_button = add<Button>(); - m_increment_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/upward-triangle.png")); + m_increment_button->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/upward-triangle.png")); m_increment_button->set_focus_policy(GUI::FocusPolicy::NoFocus); m_increment_button->on_click = [this](auto) { set_value(m_value + 1); }; m_increment_button->set_auto_repeat_interval(150); m_decrement_button = add<Button>(); - m_decrement_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/downward-triangle.png")); + m_decrement_button->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/downward-triangle.png")); m_decrement_button->set_focus_policy(GUI::FocusPolicy::NoFocus); m_decrement_button->on_click = [this](auto) { set_value(m_value - 1); }; m_decrement_button->set_auto_repeat_interval(150); diff --git a/Userland/Libraries/LibGUI/TextEditor.cpp b/Userland/Libraries/LibGUI/TextEditor.cpp index eeafb357bf..65891732ea 100644 --- a/Userland/Libraries/LibGUI/TextEditor.cpp +++ b/Userland/Libraries/LibGUI/TextEditor.cpp @@ -86,7 +86,7 @@ void TextEditor::create_actions() m_delete_action = CommonActions::make_delete_action([&](auto&) { do_delete(); }, this); if (is_multi_line()) { m_go_to_line_action = Action::create( - "Go to line...", { Mod_Ctrl, Key_L }, Gfx::Bitmap::load_from_file("/res/icons/16x16/go-forward.png"), [this](auto&) { + "Go to line...", { Mod_Ctrl, Key_L }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-forward.png"), [this](auto&) { String value; if (InputBox::show(window(), value, "Line:", "Go to line") == InputBox::ExecOK) { auto line_target = value.to_uint(); diff --git a/Userland/Libraries/LibGUI/TreeView.cpp b/Userland/Libraries/LibGUI/TreeView.cpp index 0d2929373a..21ab9dd632 100644 --- a/Userland/Libraries/LibGUI/TreeView.cpp +++ b/Userland/Libraries/LibGUI/TreeView.cpp @@ -39,8 +39,8 @@ TreeView::TreeView() set_background_role(ColorRole::Base); set_foreground_role(ColorRole::BaseText); set_column_headers_visible(false); - m_expand_bitmap = Gfx::Bitmap::load_from_file("/res/icons/serenity/treeview-expand.png"); - m_collapse_bitmap = Gfx::Bitmap::load_from_file("/res/icons/serenity/treeview-collapse.png"); + m_expand_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/serenity/treeview-expand.png"); + m_collapse_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/serenity/treeview-collapse.png"); } TreeView::~TreeView() diff --git a/Userland/Libraries/LibGUI/Window.cpp b/Userland/Libraries/LibGUI/Window.cpp index d021eafc0b..083a36e2e8 100644 --- a/Userland/Libraries/LibGUI/Window.cpp +++ b/Userland/Libraries/LibGUI/Window.cpp @@ -826,7 +826,7 @@ OwnPtr<WindowBackingStore> Window::create_backing_store(const Gfx::IntSize& size } // FIXME: Plumb scale factor here eventually. - auto bitmap = Gfx::Bitmap::create_with_anonymous_buffer(format, move(buffer), size, 1, {}); + auto bitmap = Gfx::Bitmap::try_create_with_anonymous_buffer(format, move(buffer), size, 1, {}); if (!bitmap) { VERIFY(size.width() <= INT16_MAX); VERIFY(size.height() <= INT16_MAX); @@ -856,7 +856,7 @@ void Window::set_icon(const Gfx::Bitmap* icon) Gfx::IntSize icon_size = icon ? icon->size() : Gfx::IntSize(16, 16); - m_icon = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, icon_size); + m_icon = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, icon_size); VERIFY(m_icon); if (icon) { Painter painter(*m_icon); diff --git a/Userland/Libraries/LibGfx/BMPLoader.cpp b/Userland/Libraries/LibGfx/BMPLoader.cpp index 059ebd246d..9e13aad455 100644 --- a/Userland/Libraries/LibGfx/BMPLoader.cpp +++ b/Userland/Libraries/LibGfx/BMPLoader.cpp @@ -1185,7 +1185,7 @@ static bool decode_bmp_pixel_data(BMPLoadingContext& context) const u32 width = abs(context.dib.core.width); const u32 height = abs(context.dib.core.height); - context.bitmap = Bitmap::create_purgeable(format, { static_cast<int>(width), static_cast<int>(height) }); + context.bitmap = Bitmap::try_create_purgeable(format, { static_cast<int>(width), static_cast<int>(height) }); if (!context.bitmap) { dbgln("BMP appears to have overly large dimensions"); return false; diff --git a/Userland/Libraries/LibGfx/Bitmap.cpp b/Userland/Libraries/LibGfx/Bitmap.cpp index 52d3b30900..a9c43dfed9 100644 --- a/Userland/Libraries/LibGfx/Bitmap.cpp +++ b/Userland/Libraries/LibGfx/Bitmap.cpp @@ -65,7 +65,7 @@ static bool size_would_overflow(BitmapFormat format, const IntSize& size, int sc return Checked<size_t>::multiplication_would_overflow(pitch, size.height() * scale_factor); } -RefPtr<Bitmap> Bitmap::create(BitmapFormat format, const IntSize& size, int scale_factor) +RefPtr<Bitmap> Bitmap::try_create(BitmapFormat format, const IntSize& size, int scale_factor) { auto backing_store = Bitmap::allocate_backing_store(format, size, scale_factor, Purgeable::No); if (!backing_store.has_value()) @@ -73,7 +73,7 @@ RefPtr<Bitmap> Bitmap::create(BitmapFormat format, const IntSize& size, int scal return adopt_ref(*new Bitmap(format, size, scale_factor, Purgeable::No, backing_store.value())); } -RefPtr<Bitmap> Bitmap::create_purgeable(BitmapFormat format, const IntSize& size, int scale_factor) +RefPtr<Bitmap> Bitmap::try_create_purgeable(BitmapFormat format, const IntSize& size, int scale_factor) { auto backing_store = Bitmap::allocate_backing_store(format, size, scale_factor, Purgeable::Yes); if (!backing_store.has_value()) @@ -81,7 +81,7 @@ RefPtr<Bitmap> Bitmap::create_purgeable(BitmapFormat format, const IntSize& size return adopt_ref(*new Bitmap(format, size, scale_factor, Purgeable::Yes, backing_store.value())); } -RefPtr<Bitmap> Bitmap::create_shareable(BitmapFormat format, const IntSize& size, int scale_factor) +RefPtr<Bitmap> Bitmap::try_create_shareable(BitmapFormat format, const IntSize& size, int scale_factor) { if (size_would_overflow(format, size, scale_factor)) return nullptr; @@ -92,7 +92,7 @@ RefPtr<Bitmap> Bitmap::create_shareable(BitmapFormat format, const IntSize& size auto buffer = Core::AnonymousBuffer::create_with_size(round_up_to_power_of_two(data_size, PAGE_SIZE)); if (!buffer.is_valid()) return nullptr; - return Bitmap::create_with_anonymous_buffer(format, buffer, size, scale_factor, {}); + return Bitmap::try_create_with_anonymous_buffer(format, buffer, size, scale_factor, {}); } Bitmap::Bitmap(BitmapFormat format, const IntSize& size, int scale_factor, Purgeable purgeable, const BackingStore& backing_store) @@ -111,14 +111,14 @@ Bitmap::Bitmap(BitmapFormat format, const IntSize& size, int scale_factor, Purge m_needs_munmap = true; } -RefPtr<Bitmap> Bitmap::create_wrapper(BitmapFormat format, const IntSize& size, int scale_factor, size_t pitch, void* data) +RefPtr<Bitmap> Bitmap::try_create_wrapper(BitmapFormat format, const IntSize& size, int scale_factor, size_t pitch, void* data) { if (size_would_overflow(format, size, scale_factor)) return nullptr; return adopt_ref(*new Bitmap(format, size, scale_factor, pitch, data)); } -RefPtr<Bitmap> Bitmap::load_from_file(String const& path, int scale_factor) +RefPtr<Bitmap> Bitmap::try_load_from_file(String const& path, int scale_factor) { if (scale_factor > 1 && path.starts_with("/res/")) { LexicalPath lexical_path { path }; @@ -188,7 +188,7 @@ static bool check_size(const IntSize& size, int scale_factor, BitmapFormat forma return true; } -RefPtr<Bitmap> Bitmap::create_with_anonymous_buffer(BitmapFormat format, Core::AnonymousBuffer buffer, const IntSize& size, int scale_factor, const Vector<RGBA32>& palette) +RefPtr<Bitmap> Bitmap::try_create_with_anonymous_buffer(BitmapFormat format, Core::AnonymousBuffer buffer, const IntSize& size, int scale_factor, const Vector<RGBA32>& palette) { if (size_would_overflow(format, size, scale_factor)) return nullptr; @@ -205,7 +205,7 @@ RefPtr<Bitmap> Bitmap::create_with_anonymous_buffer(BitmapFormat format, Core::A /// - palette count /// - palette data (= palette count * BGRA8888) /// - image data (= actual size * u8) -RefPtr<Bitmap> Bitmap::create_from_serialized_byte_buffer(ByteBuffer&& buffer) +RefPtr<Bitmap> Bitmap::try_create_from_serialized_byte_buffer(ByteBuffer&& buffer) { InputMemoryStream stream { buffer }; unsigned actual_size; @@ -242,7 +242,7 @@ RefPtr<Bitmap> Bitmap::create_from_serialized_byte_buffer(ByteBuffer&& buffer) auto data = stream.bytes().slice(stream.offset(), actual_size); - auto bitmap = Bitmap::create(format, { width, height }, scale_factor); + auto bitmap = Bitmap::try_create(format, { width, height }, scale_factor); if (!bitmap) return {}; @@ -303,9 +303,9 @@ RefPtr<Gfx::Bitmap> Bitmap::clone() const { RefPtr<Gfx::Bitmap> new_bitmap {}; if (m_purgeable) { - new_bitmap = Bitmap::create_purgeable(format(), size(), scale()); + new_bitmap = Bitmap::try_create_purgeable(format(), size(), scale()); } else { - new_bitmap = Bitmap::create(format(), size(), scale()); + new_bitmap = Bitmap::try_create(format(), size(), scale()); } if (!new_bitmap) { @@ -320,7 +320,7 @@ RefPtr<Gfx::Bitmap> Bitmap::clone() const RefPtr<Gfx::Bitmap> Bitmap::rotated(Gfx::RotationDirection rotation_direction) const { - auto new_bitmap = Gfx::Bitmap::create(this->format(), { height(), width() }, scale()); + auto new_bitmap = Gfx::Bitmap::try_create(this->format(), { height(), width() }, scale()); if (!new_bitmap) return nullptr; @@ -343,7 +343,7 @@ RefPtr<Gfx::Bitmap> Bitmap::rotated(Gfx::RotationDirection rotation_direction) c RefPtr<Gfx::Bitmap> Bitmap::flipped(Gfx::Orientation orientation) const { - auto new_bitmap = Gfx::Bitmap::create(this->format(), { width(), height() }, scale()); + auto new_bitmap = Gfx::Bitmap::try_create(this->format(), { width(), height() }, scale()); if (!new_bitmap) return nullptr; @@ -368,7 +368,7 @@ RefPtr<Gfx::Bitmap> Bitmap::scaled(int sx, int sy) const if (sx == 1 && sy == 1) return this; - auto new_bitmap = Gfx::Bitmap::create(format(), { width() * sx, height() * sy }, scale()); + auto new_bitmap = Gfx::Bitmap::try_create(format(), { width() * sx, height() * sy }, scale()); if (!new_bitmap) return nullptr; @@ -402,7 +402,7 @@ RefPtr<Gfx::Bitmap> Bitmap::scaled(float sx, float sy) const int scaled_width = (int)ceilf(sx * (float)width()); int scaled_height = (int)ceilf(sy * (float)height()); - auto new_bitmap = Gfx::Bitmap::create(format(), { scaled_width, scaled_height }, scale()); + auto new_bitmap = Gfx::Bitmap::try_create(format(), { scaled_width, scaled_height }, scale()); if (!new_bitmap) return nullptr; @@ -476,7 +476,7 @@ RefPtr<Gfx::Bitmap> Bitmap::scaled(float sx, float sy) const RefPtr<Gfx::Bitmap> Bitmap::cropped(Gfx::IntRect crop) const { - auto new_bitmap = Gfx::Bitmap::create(format(), { crop.width(), crop.height() }, 1); + auto new_bitmap = Gfx::Bitmap::try_create(format(), { crop.width(), crop.height() }, 1); if (!new_bitmap) return nullptr; @@ -501,7 +501,7 @@ RefPtr<Bitmap> Bitmap::to_bitmap_backed_by_anonymous_buffer() const auto buffer = Core::AnonymousBuffer::create_with_size(round_up_to_power_of_two(size_in_bytes(), PAGE_SIZE)); if (!buffer.is_valid()) return nullptr; - auto bitmap = Bitmap::create_with_anonymous_buffer(m_format, move(buffer), size(), scale(), palette_to_vector()); + auto bitmap = Bitmap::try_create_with_anonymous_buffer(m_format, move(buffer), size(), scale(), palette_to_vector()); if (!bitmap) return nullptr; memcpy(bitmap->scanline(0), scanline(0), size_in_bytes()); diff --git a/Userland/Libraries/LibGfx/Bitmap.h b/Userland/Libraries/LibGfx/Bitmap.h index 87f2499f18..2fc2247486 100644 --- a/Userland/Libraries/LibGfx/Bitmap.h +++ b/Userland/Libraries/LibGfx/Bitmap.h @@ -90,13 +90,14 @@ enum RotationDirection { class Bitmap : public RefCounted<Bitmap> { public: - static RefPtr<Bitmap> create(BitmapFormat, const IntSize&, int intrinsic_scale = 1); - static RefPtr<Bitmap> create_shareable(BitmapFormat, const IntSize&, int intrinsic_scale = 1); - static RefPtr<Bitmap> create_purgeable(BitmapFormat, const IntSize&, int intrinsic_scale = 1); - static RefPtr<Bitmap> create_wrapper(BitmapFormat, const IntSize&, int intrinsic_scale, size_t pitch, void*); - static RefPtr<Bitmap> load_from_file(String const& path, int scale_factor = 1); - static RefPtr<Bitmap> create_with_anonymous_buffer(BitmapFormat, Core::AnonymousBuffer, const IntSize&, int intrinsic_scale, const Vector<RGBA32>& palette); - static RefPtr<Bitmap> create_from_serialized_byte_buffer(ByteBuffer&& buffer); + [[nodiscard]] static RefPtr<Bitmap> try_create(BitmapFormat, const IntSize&, int intrinsic_scale = 1); + [[nodiscard]] static RefPtr<Bitmap> try_create_shareable(BitmapFormat, const IntSize&, int intrinsic_scale = 1); + [[nodiscard]] static RefPtr<Bitmap> try_create_purgeable(BitmapFormat, const IntSize&, int intrinsic_scale = 1); + [[nodiscard]] static RefPtr<Bitmap> try_create_wrapper(BitmapFormat, const IntSize&, int intrinsic_scale, size_t pitch, void*); + [[nodiscard]] static RefPtr<Bitmap> try_load_from_file(String const& path, int scale_factor = 1); + [[nodiscard]] static RefPtr<Bitmap> try_create_with_anonymous_buffer(BitmapFormat, Core::AnonymousBuffer, const IntSize&, int intrinsic_scale, const Vector<RGBA32>& palette); + [[nodiscard]] static RefPtr<Bitmap> try_create_from_serialized_byte_buffer(ByteBuffer&& buffer); + static bool is_path_a_supported_image_format(const StringView& path) { #define __ENUMERATE_IMAGE_FORMAT(Name, Ext) \ diff --git a/Userland/Libraries/LibGfx/ClassicStylePainter.cpp b/Userland/Libraries/LibGfx/ClassicStylePainter.cpp index 6509350f58..ecbf0bb4c0 100644 --- a/Userland/Libraries/LibGfx/ClassicStylePainter.cpp +++ b/Userland/Libraries/LibGfx/ClassicStylePainter.cpp @@ -344,10 +344,10 @@ static const Gfx::Bitmap& circle_bitmap(bool checked, bool changing) void ClassicStylePainter::paint_radio_button(Painter& painter, const IntRect& rect, const Palette&, bool is_checked, bool is_being_pressed) { if (!s_unfilled_circle_bitmap) { - s_unfilled_circle_bitmap = Bitmap::load_from_file("/res/icons/serenity/unfilled-radio-circle.png"); - s_filled_circle_bitmap = Bitmap::load_from_file("/res/icons/serenity/filled-radio-circle.png"); - s_changing_filled_circle_bitmap = Bitmap::load_from_file("/res/icons/serenity/changing-filled-radio-circle.png"); - s_changing_unfilled_circle_bitmap = Bitmap::load_from_file("/res/icons/serenity/changing-unfilled-radio-circle.png"); + s_unfilled_circle_bitmap = Bitmap::try_load_from_file("/res/icons/serenity/unfilled-radio-circle.png"); + s_filled_circle_bitmap = Bitmap::try_load_from_file("/res/icons/serenity/filled-radio-circle.png"); + s_changing_filled_circle_bitmap = Bitmap::try_load_from_file("/res/icons/serenity/changing-filled-radio-circle.png"); + s_changing_unfilled_circle_bitmap = Bitmap::try_load_from_file("/res/icons/serenity/changing-unfilled-radio-circle.png"); } auto& bitmap = circle_bitmap(is_checked, is_being_pressed); diff --git a/Userland/Libraries/LibGfx/DDSLoader.cpp b/Userland/Libraries/LibGfx/DDSLoader.cpp index d83721ef9a..43a28d9d4d 100644 --- a/Userland/Libraries/LibGfx/DDSLoader.cpp +++ b/Userland/Libraries/LibGfx/DDSLoader.cpp @@ -792,7 +792,7 @@ static bool decode_dds(DDSLoadingContext& context) dbgln_if(DDS_DEBUG, "There are {} bytes remaining, we need {} for mipmap level {} of the image", stream.remaining(), needed_bytes, mipmap_level); VERIFY(stream.remaining() >= needed_bytes); - context.bitmap = Bitmap::create_purgeable(BitmapFormat::BGRA8888, { width, height }); + context.bitmap = Bitmap::try_create_purgeable(BitmapFormat::BGRA8888, { width, height }); decode_bitmap(stream, context, format, width, height); diff --git a/Userland/Libraries/LibGfx/Emoji.cpp b/Userland/Libraries/LibGfx/Emoji.cpp index 665557083c..b29c9c0839 100644 --- a/Userland/Libraries/LibGfx/Emoji.cpp +++ b/Userland/Libraries/LibGfx/Emoji.cpp @@ -19,7 +19,7 @@ const Bitmap* Emoji::emoji_for_code_point(u32 code_point) if (it != s_emojis.end()) return (*it).value.ptr(); - auto bitmap = Bitmap::load_from_file(String::formatted("/res/emoji/U+{:X}.png", code_point)); + auto bitmap = Bitmap::try_load_from_file(String::formatted("/res/emoji/U+{:X}.png", code_point)); if (!bitmap) { s_emojis.set(code_point, nullptr); return nullptr; diff --git a/Userland/Libraries/LibGfx/Filters/GenericConvolutionFilter.h b/Userland/Libraries/LibGfx/Filters/GenericConvolutionFilter.h index b82a4cd0be..0ee8ec01ad 100644 --- a/Userland/Libraries/LibGfx/Filters/GenericConvolutionFilter.h +++ b/Userland/Libraries/LibGfx/Filters/GenericConvolutionFilter.h @@ -94,7 +94,7 @@ public: if (&target == &source && (!apply_cache.m_target || !apply_cache.m_target->size().contains(source_rect.size()))) { // TODO: We probably don't need the entire source_rect, we could inflate // the target_rect appropriately - apply_cache.m_target = Gfx::Bitmap::create(source.format(), source_rect.size()); + apply_cache.m_target = Gfx::Bitmap::try_create(source.format(), source_rect.size()); target_rect.translate_by(-target_rect.location()); } diff --git a/Userland/Libraries/LibGfx/GIFLoader.cpp b/Userland/Libraries/LibGfx/GIFLoader.cpp index 233fbac0ed..2db9ec6060 100644 --- a/Userland/Libraries/LibGfx/GIFLoader.cpp +++ b/Userland/Libraries/LibGfx/GIFLoader.cpp @@ -299,10 +299,10 @@ static bool decode_frame(GIFLoadingContext& context, size_t frame_index) size_t start_frame = context.current_frame + 1; if (context.state < GIFLoadingContext::State::FrameComplete) { start_frame = 0; - context.frame_buffer = Bitmap::create_purgeable(BitmapFormat::BGRA8888, { context.logical_screen.width, context.logical_screen.height }); + context.frame_buffer = Bitmap::try_create_purgeable(BitmapFormat::BGRA8888, { context.logical_screen.width, context.logical_screen.height }); if (!context.frame_buffer) return false; - context.prev_frame_buffer = Bitmap::create_purgeable(BitmapFormat::BGRA8888, { context.logical_screen.width, context.logical_screen.height }); + context.prev_frame_buffer = Bitmap::try_create_purgeable(BitmapFormat::BGRA8888, { context.logical_screen.width, context.logical_screen.height }); if (!context.prev_frame_buffer) return false; } else if (frame_index < context.current_frame) { diff --git a/Userland/Libraries/LibGfx/ICOLoader.cpp b/Userland/Libraries/LibGfx/ICOLoader.cpp index dd6b27e5ca..e9d458c345 100644 --- a/Userland/Libraries/LibGfx/ICOLoader.cpp +++ b/Userland/Libraries/LibGfx/ICOLoader.cpp @@ -246,7 +246,7 @@ static bool load_ico_bmp(ICOLoadingContext& context, ICOImageDescriptor& desc) return false; } - desc.bitmap = Bitmap::create_purgeable(BitmapFormat::BGRA8888, { desc.width, desc.height }); + desc.bitmap = Bitmap::try_create_purgeable(BitmapFormat::BGRA8888, { desc.width, desc.height }); if (!desc.bitmap) return false; Bitmap& bitmap = *desc.bitmap; diff --git a/Userland/Libraries/LibGfx/JPGLoader.cpp b/Userland/Libraries/LibGfx/JPGLoader.cpp index c6c2b46508..3d784f85c2 100644 --- a/Userland/Libraries/LibGfx/JPGLoader.cpp +++ b/Userland/Libraries/LibGfx/JPGLoader.cpp @@ -1064,7 +1064,7 @@ static void ycbcr_to_rgb(const JPGLoadingContext& context, Vector<Macroblock>& m static bool compose_bitmap(JPGLoadingContext& context, const Vector<Macroblock>& macroblocks) { - context.bitmap = Bitmap::create_purgeable(BitmapFormat::BGRx8888, { context.frame.width, context.frame.height }); + context.bitmap = Bitmap::try_create_purgeable(BitmapFormat::BGRx8888, { context.frame.width, context.frame.height }); if (!context.bitmap) return false; diff --git a/Userland/Libraries/LibGfx/PNGLoader.cpp b/Userland/Libraries/LibGfx/PNGLoader.cpp index 7174b6d50d..d40ba7591f 100644 --- a/Userland/Libraries/LibGfx/PNGLoader.cpp +++ b/Userland/Libraries/LibGfx/PNGLoader.cpp @@ -606,7 +606,7 @@ static bool decode_png_bitmap_simple(PNGLoadingContext& context) } } - context.bitmap = Bitmap::create_purgeable(context.has_alpha() ? BitmapFormat::BGRA8888 : BitmapFormat::BGRx8888, { context.width, context.height }); + context.bitmap = Bitmap::try_create_purgeable(context.has_alpha() ? BitmapFormat::BGRA8888 : BitmapFormat::BGRx8888, { context.width, context.height }); if (!context.bitmap) { context.state = PNGLoadingContext::State::Error; @@ -708,7 +708,7 @@ static bool decode_adam7_pass(PNGLoadingContext& context, Streamer& streamer, in } } - subimage_context.bitmap = Bitmap::create(context.bitmap->format(), { subimage_context.width, subimage_context.height }); + subimage_context.bitmap = Bitmap::try_create(context.bitmap->format(), { subimage_context.width, subimage_context.height }); if (!unfilter(subimage_context)) { subimage_context.bitmap = nullptr; return false; @@ -726,7 +726,7 @@ static bool decode_adam7_pass(PNGLoadingContext& context, Streamer& streamer, in static bool decode_png_adam7(PNGLoadingContext& context) { Streamer streamer(context.decompression_buffer->data(), context.decompression_buffer->size()); - context.bitmap = Bitmap::create_purgeable(context.has_alpha() ? BitmapFormat::BGRA8888 : BitmapFormat::BGRx8888, { context.width, context.height }); + context.bitmap = Bitmap::try_create_purgeable(context.has_alpha() ? BitmapFormat::BGRA8888 : BitmapFormat::BGRx8888, { context.width, context.height }); if (!context.bitmap) return false; diff --git a/Userland/Libraries/LibGfx/PortableImageLoaderCommon.h b/Userland/Libraries/LibGfx/PortableImageLoaderCommon.h index bc3d1d3cee..ac1793b25d 100644 --- a/Userland/Libraries/LibGfx/PortableImageLoaderCommon.h +++ b/Userland/Libraries/LibGfx/PortableImageLoaderCommon.h @@ -178,7 +178,7 @@ static bool read_max_val(TContext& context, Streamer& streamer) template<typename TContext> static bool create_bitmap(TContext& context) { - context.bitmap = Bitmap::create_purgeable(BitmapFormat::BGRx8888, { context.width, context.height }); + context.bitmap = Bitmap::try_create_purgeable(BitmapFormat::BGRx8888, { context.width, context.height }); if (!context.bitmap) { context.state = TContext::State::Error; return false; diff --git a/Userland/Libraries/LibGfx/ShareableBitmap.cpp b/Userland/Libraries/LibGfx/ShareableBitmap.cpp index 76783d5e6c..b1b789b64b 100644 --- a/Userland/Libraries/LibGfx/ShareableBitmap.cpp +++ b/Userland/Libraries/LibGfx/ShareableBitmap.cpp @@ -76,7 +76,7 @@ bool decode(Decoder& decoder, Gfx::ShareableBitmap& shareable_bitmap) auto buffer = Core::AnonymousBuffer::create_from_anon_fd(anon_file.take_fd(), Gfx::Bitmap::size_in_bytes(Gfx::Bitmap::minimum_pitch(size.width(), bitmap_format), size.height())); if (!buffer.is_valid()) return false; - auto bitmap = Gfx::Bitmap::create_with_anonymous_buffer(bitmap_format, buffer, size, scale, palette); + auto bitmap = Gfx::Bitmap::try_create_with_anonymous_buffer(bitmap_format, buffer, size, scale, palette); if (!bitmap) return false; shareable_bitmap = Gfx::ShareableBitmap { bitmap.release_nonnull(), Gfx::ShareableBitmap::ConstructWithKnownGoodBitmap }; diff --git a/Userland/Libraries/LibTTF/Glyf.cpp b/Userland/Libraries/LibTTF/Glyf.cpp index 9ec8e6f586..cfc60eb7f5 100644 --- a/Userland/Libraries/LibTTF/Glyf.cpp +++ b/Userland/Libraries/LibTTF/Glyf.cpp @@ -207,7 +207,7 @@ void Rasterizer::draw_path(Gfx::Path& path) RefPtr<Gfx::Bitmap> Rasterizer::accumulate() { - auto bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, m_size); + auto bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, m_size); if (!bitmap) return {}; Color base_color = Color::from_rgb(0xffffff); diff --git a/Userland/Libraries/LibVT/TerminalWidget.cpp b/Userland/Libraries/LibVT/TerminalWidget.cpp index 780496296e..c79f002924 100644 --- a/Userland/Libraries/LibVT/TerminalWidget.cpp +++ b/Userland/Libraries/LibVT/TerminalWidget.cpp @@ -123,12 +123,12 @@ TerminalWidget::TerminalWidget(int ptm_fd, bool automatic_size_policy, RefPtr<Co m_terminal.set_size(m_config->read_num_entry("Window", "Width", 80), m_config->read_num_entry("Window", "Height", 25)); - m_copy_action = GUI::Action::create("&Copy", { Mod_Ctrl | Mod_Shift, Key_C }, Gfx::Bitmap::load_from_file("/res/icons/16x16/edit-copy.png"), [this](auto&) { + m_copy_action = GUI::Action::create("&Copy", { Mod_Ctrl | Mod_Shift, Key_C }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/edit-copy.png"), [this](auto&) { copy(); }); m_copy_action->set_swallow_key_event_when_disabled(true); - m_paste_action = GUI::Action::create("&Paste", { Mod_Ctrl | Mod_Shift, Key_V }, Gfx::Bitmap::load_from_file("/res/icons/16x16/paste.png"), [this](auto&) { + m_paste_action = GUI::Action::create("&Paste", { Mod_Ctrl | Mod_Shift, Key_V }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/paste.png"), [this](auto&) { paste(); }); m_paste_action->set_swallow_key_event_when_disabled(true); diff --git a/Userland/Libraries/LibWeb/DOMTreeJSONModel.cpp b/Userland/Libraries/LibWeb/DOMTreeJSONModel.cpp index 78b8dbf81d..a4a9300bc9 100644 --- a/Userland/Libraries/LibWeb/DOMTreeJSONModel.cpp +++ b/Userland/Libraries/LibWeb/DOMTreeJSONModel.cpp @@ -15,9 +15,9 @@ namespace Web { DOMTreeJSONModel::DOMTreeJSONModel(JsonObject dom_tree) : m_dom_tree(move(dom_tree)) { - m_document_icon.set_bitmap_for_size(16, Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-html.png")); - m_element_icon.set_bitmap_for_size(16, Gfx::Bitmap::load_from_file("/res/icons/16x16/inspector-object.png")); - m_text_icon.set_bitmap_for_size(16, Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-unknown.png")); + m_document_icon.set_bitmap_for_size(16, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/filetype-html.png")); + m_element_icon.set_bitmap_for_size(16, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/inspector-object.png")); + m_text_icon.set_bitmap_for_size(16, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/filetype-unknown.png")); map_dom_nodes_to_parent(nullptr, &m_dom_tree); } diff --git a/Userland/Libraries/LibWeb/DOMTreeModel.cpp b/Userland/Libraries/LibWeb/DOMTreeModel.cpp index 5857c78445..35a2799cc0 100644 --- a/Userland/Libraries/LibWeb/DOMTreeModel.cpp +++ b/Userland/Libraries/LibWeb/DOMTreeModel.cpp @@ -17,9 +17,9 @@ namespace Web { DOMTreeModel::DOMTreeModel(DOM::Document& document) : m_document(document) { - m_document_icon.set_bitmap_for_size(16, Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-html.png")); - m_element_icon.set_bitmap_for_size(16, Gfx::Bitmap::load_from_file("/res/icons/16x16/inspector-object.png")); - m_text_icon.set_bitmap_for_size(16, Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-unknown.png")); + m_document_icon.set_bitmap_for_size(16, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/filetype-html.png")); + m_element_icon.set_bitmap_for_size(16, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/inspector-object.png")); + m_text_icon.set_bitmap_for_size(16, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/filetype-unknown.png")); } DOMTreeModel::~DOMTreeModel() diff --git a/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp index 0b0f2561c3..63e42b8b8d 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp @@ -80,7 +80,7 @@ bool HTMLCanvasElement::create_bitmap() return false; } if (!m_bitmap || m_bitmap->size() != size) - m_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, size); + m_bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, size); return m_bitmap; } diff --git a/Userland/Libraries/LibWeb/HTML/ImageData.cpp b/Userland/Libraries/LibWeb/HTML/ImageData.cpp index e9044829ed..bab3aa2b21 100644 --- a/Userland/Libraries/LibWeb/HTML/ImageData.cpp +++ b/Userland/Libraries/LibWeb/HTML/ImageData.cpp @@ -26,7 +26,7 @@ RefPtr<ImageData> ImageData::create_with_size(JS::GlobalObject& global_object, i auto data_handle = JS::make_handle(data); - auto bitmap = Gfx::Bitmap::create_wrapper(Gfx::BitmapFormat::RGBA8888, Gfx::IntSize(width, height), 1, width * sizeof(u32), data->data().data()); + auto bitmap = Gfx::Bitmap::try_create_wrapper(Gfx::BitmapFormat::RGBA8888, Gfx::IntSize(width, height), 1, width * sizeof(u32), data->data().data()); if (!bitmap) return nullptr; return adopt_ref(*new ImageData(bitmap.release_nonnull(), move(data_handle))); diff --git a/Userland/Libraries/LibWeb/LayoutTreeModel.cpp b/Userland/Libraries/LibWeb/LayoutTreeModel.cpp index 8832e4ce2a..85dc029617 100644 --- a/Userland/Libraries/LibWeb/LayoutTreeModel.cpp +++ b/Userland/Libraries/LibWeb/LayoutTreeModel.cpp @@ -19,9 +19,9 @@ namespace Web { LayoutTreeModel::LayoutTreeModel(DOM::Document& document) : m_document(document) { - m_document_icon.set_bitmap_for_size(16, Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-html.png")); - m_element_icon.set_bitmap_for_size(16, Gfx::Bitmap::load_from_file("/res/icons/16x16/inspector-object.png")); - m_text_icon.set_bitmap_for_size(16, Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-unknown.png")); + m_document_icon.set_bitmap_for_size(16, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/filetype-html.png")); + m_element_icon.set_bitmap_for_size(16, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/inspector-object.png")); + m_text_icon.set_bitmap_for_size(16, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/filetype-unknown.png")); } LayoutTreeModel::~LayoutTreeModel() diff --git a/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp b/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp index 9d78de522c..8485992626 100644 --- a/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp +++ b/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp @@ -145,13 +145,13 @@ void OutOfProcessWebView::handle_resize() if (available_size().is_empty()) return; - if (auto new_bitmap = Gfx::Bitmap::create_shareable(Gfx::BitmapFormat::BGRx8888, available_size())) { + if (auto new_bitmap = Gfx::Bitmap::try_create_shareable(Gfx::BitmapFormat::BGRx8888, available_size())) { m_client_state.front_bitmap = move(new_bitmap); m_client_state.front_bitmap_id = m_client_state.next_bitmap_id++; client().async_add_backing_store(m_client_state.front_bitmap_id, m_client_state.front_bitmap->to_shareable_bitmap()); } - if (auto new_bitmap = Gfx::Bitmap::create_shareable(Gfx::BitmapFormat::BGRx8888, available_size())) { + if (auto new_bitmap = Gfx::Bitmap::try_create_shareable(Gfx::BitmapFormat::BGRx8888, available_size())) { m_client_state.back_bitmap = move(new_bitmap); m_client_state.back_bitmap_id = m_client_state.next_bitmap_id++; client().async_add_backing_store(m_client_state.back_bitmap_id, m_client_state.back_bitmap->to_shareable_bitmap()); |