1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 15:17:36 +00:00

LibGfx: Use "try_" prefix for static factory functions

Also mark them as [[nodiscard]].
This commit is contained in:
Andreas Kling 2021-07-21 18:02:15 +02:00
parent f0409081f5
commit c7d891765c
131 changed files with 422 additions and 421 deletions

View file

@ -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());

View file

@ -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()));
}

View file

@ -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);
}
}

View file

@ -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;
}

View file

@ -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) {

View file

@ -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++) {

View file

@ -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())

View file

@ -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();
}

View file

@ -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");

View file

@ -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));

View file

@ -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());

View file

@ -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))

View file

@ -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));
}

View file

@ -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();
});

View file

@ -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;
}

View file

@ -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);
});

View file

@ -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);

View file

@ -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();

View file

@ -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()

View file

@ -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);

View file

@ -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;

View file

@ -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());

View file

@ -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) \

View file

@ -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);

View file

@ -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);

View file

@ -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;

View file

@ -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());
}

View file

@ -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) {

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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 };

View file

@ -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);

View file

@ -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);

View file

@ -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);
}

View file

@ -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()

View file

@ -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;
}

View file

@ -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)));

View file

@ -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()

View file

@ -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());