1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 04:17:34 +00:00

LibGfx: Use ErrorOr<T> for Bitmap::try_create()

Another one that was used in a fajillion places.
This commit is contained in:
Andreas Kling 2021-11-06 19:30:59 +01:00
parent 235f39e449
commit 0de33b3d6c
43 changed files with 157 additions and 141 deletions

View file

@ -57,7 +57,7 @@ private:
GLContextWidget()
: m_mesh_loader(adopt_own(*new WavefrontOBJLoader()))
{
m_bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { RENDER_WIDTH, RENDER_HEIGHT });
m_bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { RENDER_WIDTH, RENDER_HEIGHT }).release_value_but_fixme_should_propagate_errors();
m_context = GL::create_context(*m_bitmap);
start_timer(20);

View file

@ -20,7 +20,7 @@ MonitorWidget::MonitorWidget()
{
m_desktop_resolution = GUI::Desktop::the().rect().size();
m_monitor_bitmap = Gfx::Bitmap::try_load_from_file("/res/graphics/monitor.png").release_value_but_fixme_should_propagate_errors();
m_desktop_bitmap = Gfx::Bitmap::try_create(m_monitor_bitmap->format(), { 280, 158 });
m_desktop_bitmap = Gfx::Bitmap::try_create(m_monitor_bitmap->format(), { 280, 158 }).release_value_but_fixme_should_propagate_errors();
m_monitor_rect = { { 12, 13 }, m_desktop_bitmap->size() };
set_fixed_size(304, 201);
}

View file

@ -145,7 +145,7 @@ RefPtr<Gfx::Bitmap> PDFViewer::render_page(const PDF::Page& page)
auto height = static_cast<float>(this->height() - 2 * frame_thickness() - PAGE_PADDING * 2) * zoom_scale_factor;
auto width = height / page_scale_factor;
auto bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, { width, height });
auto bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, { width, height }).release_value_but_fixme_should_propagate_errors();
PDF::Renderer::render(*m_document, page, bitmap);

View file

@ -72,7 +72,7 @@ void RollWidget::paint_event(GUI::PaintEvent& event)
// Draw the background, if necessary.
if (viewport_changed() || paint_area != m_background->height()) {
m_background = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, Gfx::IntSize(m_roll_width, paint_area));
m_background = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, Gfx::IntSize(m_roll_width, paint_area)).release_value_but_fixme_should_propagate_errors();
Gfx::Painter background_painter(*m_background);
background_painter.translate(frame_thickness(), frame_thickness());

View file

@ -168,10 +168,11 @@ Result<void, String> Image::write_to_file(const String& file_path) const
RefPtr<Gfx::Bitmap> Image::try_compose_bitmap(Gfx::BitmapFormat format) const
{
auto bitmap = Gfx::Bitmap::try_create(format, m_size);
if (!bitmap)
auto bitmap_or_error = Gfx::Bitmap::try_create(format, m_size);
if (bitmap_or_error.is_error())
return nullptr;
GUI::Painter painter(*bitmap);
auto bitmap = bitmap_or_error.release_value_but_fixme_should_propagate_errors();
GUI::Painter painter(bitmap);
paint_into(painter, { 0, 0, m_size.width(), m_size.height() });
return bitmap;
}

View file

@ -19,11 +19,11 @@ RefPtr<Layer> Layer::try_create_with_size(Image& image, Gfx::IntSize const& size
if (size.width() > 16384 || size.height() > 16384)
return nullptr;
auto bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, size);
if (!bitmap)
auto bitmap_or_error = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, size);
if (bitmap_or_error.is_error())
return nullptr;
return adopt_ref(*new Layer(image, *bitmap, move(name)));
return adopt_ref(*new Layer(image, bitmap_or_error.release_value_but_fixme_should_propagate_errors(), move(name)));
}
RefPtr<Layer> Layer::try_create_with_bitmap(Image& image, NonnullRefPtr<Gfx::Bitmap> bitmap, String name)
@ -101,7 +101,10 @@ RefPtr<Gfx::Bitmap> Layer::try_copy_bitmap(Selection const& selection) const
}
auto selection_rect = selection.bounding_rect();
auto result = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, selection_rect.size());
auto bitmap_or_error = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, selection_rect.size());
if (bitmap_or_error.is_error())
return nullptr;
auto result = bitmap_or_error.release_value_but_fixme_should_propagate_errors();
VERIFY(result->has_alpha_channel());
for (int y = selection_rect.top(); y <= selection_rect.bottom(); y++) {

View file

@ -22,7 +22,7 @@ NetworkStatisticsWidget::NetworkStatisticsWidget()
m_network_connected_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/16x16/network-connected.png").release_value_but_fixme_should_propagate_errors();
m_network_disconnected_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/16x16/network-disconnected.png").release_value_but_fixme_should_propagate_errors();
m_network_link_down_bitmap = Gfx::Bitmap::try_create(m_network_connected_bitmap->format(), m_network_connected_bitmap->size());
m_network_link_down_bitmap = Gfx::Bitmap::try_create(m_network_connected_bitmap->format(), m_network_connected_bitmap->size()).release_value_but_fixme_should_propagate_errors();
{
Gfx::Painter painter(*m_network_link_down_bitmap);
painter.blit_filtered({}, *m_network_connected_bitmap, m_network_connected_bitmap->rect(), [](Color color) {

View file

@ -25,7 +25,7 @@ int main(int argc, char** argv)
auto const& track = optional_track.value();
auto const video_track = track.video_track().value();
auto image = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, Gfx::IntSize(video_track.pixel_height, video_track.pixel_width));
auto image = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, Gfx::IntSize(video_track.pixel_height, video_track.pixel_width)).release_value_but_fixme_should_propagate_errors();
auto& main_widget = window->set_main_widget<GUI::Widget>();
main_widget.set_fill_with_background_color(true);
main_widget.set_layout<GUI::VerticalBoxLayout>();