1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 00:07:35 +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

@ -986,7 +986,8 @@ Messages::WindowServer::GetScreenBitmapResponse ClientConnection::get_screen_bit
}
// TODO: Mixed scale setups at what scale? Lowest? Highest? Configurable?
auto bitmap_size = rect.value_or(Screen::bounding_rect()).size();
if (auto bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, bitmap_size, 1)) {
if (auto bitmap_or_error = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, bitmap_size, 1); !bitmap_or_error.is_error()) {
auto bitmap = bitmap_or_error.release_value_but_fixme_should_propagate_errors();
Gfx::Painter painter(*bitmap);
Screen::for_each([&](auto& screen) {
auto screen_rect = screen.rect();
@ -1034,7 +1035,8 @@ Messages::WindowServer::GetScreenBitmapAroundCursorResponse ClientConnection::ge
return bitmap_or_error.release_value()->to_shareable_bitmap();
}
if (auto bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, rect.size(), 1)) {
if (auto bitmap_or_error = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, rect.size(), 1); !bitmap_or_error.is_error()) {
auto bitmap = bitmap_or_error.release_value_but_fixme_should_propagate_errors();
auto bounding_screen_src_rect = Screen::bounding_rect().intersected(rect);
Gfx::Painter painter(*bitmap);
auto& screen_with_cursor = ScreenInput::the().cursor_location_screen();

View file

@ -112,12 +112,12 @@ void CompositorScreenData::init_bitmaps(Compositor& compositor, Screen& screen)
if (m_screen_can_set_buffer)
m_back_bitmap = Gfx::Bitmap::try_create_wrapper(Gfx::BitmapFormat::BGRx8888, size, screen.scale_factor(), screen.pitch(), screen.scanline(1, 0)).release_value_but_fixme_should_propagate_errors();
else
m_back_bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, size, screen.scale_factor());
m_back_bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, size, screen.scale_factor()).release_value_but_fixme_should_propagate_errors();
m_back_painter = make<Gfx::Painter>(*m_back_bitmap);
m_back_painter->translate(-screen.rect().location());
m_temp_bitmap = nullptr;
m_temp_bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, size, screen.scale_factor());
m_temp_bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, size, screen.scale_factor()).release_value_but_fixme_should_propagate_errors();
m_temp_painter = make<Gfx::Painter>(*m_temp_bitmap);
m_temp_painter->translate(-screen.rect().location());
}
@ -949,7 +949,7 @@ void CompositorScreenData::draw_cursor(Screen& screen, const Gfx::IntRect& curso
auto& wm = WindowManager::the();
if (!m_cursor_back_bitmap || m_cursor_back_bitmap->size() != cursor_rect.size() || m_cursor_back_bitmap->scale() != screen.scale_factor()) {
m_cursor_back_bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, cursor_rect.size(), screen.scale_factor());
m_cursor_back_bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, cursor_rect.size(), screen.scale_factor()).release_value_but_fixme_should_propagate_errors();
m_cursor_back_painter = make<Gfx::Painter>(*m_cursor_back_bitmap);
}

View file

@ -107,9 +107,10 @@ void RectangularOverlay::render(Gfx::Painter& painter, Screen const& screen)
auto scale_factor = screen.scale_factor();
auto* bitmap = m_rendered_bitmaps->find_bitmap(scale_factor);
if (!bitmap) {
auto new_bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, rect().size(), scale_factor);
if (!new_bitmap)
auto bitmap_or_error = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, rect().size(), scale_factor);
if (bitmap_or_error.is_error())
return;
auto new_bitmap = bitmap_or_error.release_value_but_fixme_should_propagate_errors();
bitmap = new_bitmap.ptr();
Gfx::Painter bitmap_painter(*new_bitmap);
@ -119,7 +120,7 @@ void RectangularOverlay::render(Gfx::Painter& painter, Screen const& screen)
bitmap_painter.fill_rect(new_bitmap->rect(), Color(Color::Black).with_alpha(0xcc));
}
render_overlay_bitmap(bitmap_painter);
m_rendered_bitmaps->add_bitmap(scale_factor, new_bitmap.release_nonnull());
m_rendered_bitmaps->add_bitmap(scale_factor, move(new_bitmap));
}
painter.blit({}, *bitmap, bitmap->rect());
@ -291,9 +292,10 @@ void DndOverlay::update_rect()
RefPtr<Gfx::Bitmap> DndOverlay::create_bitmap(int scale_factor)
{
auto new_bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, rect().size(), scale_factor);
if (!new_bitmap)
auto bitmap_or_error = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, rect().size(), scale_factor);
if (bitmap_or_error.is_error())
return {};
auto new_bitmap = bitmap_or_error.release_value_but_fixme_should_propagate_errors();
auto& wm = WindowManager::the();
Gfx::Painter bitmap_painter(*new_bitmap);

View file

@ -147,7 +147,7 @@ void Window::set_rect(const Gfx::IntRect& rect)
if (rect.is_empty()) {
m_backing_store = nullptr;
} else if (!m_client && (!m_backing_store || old_rect.size() != rect.size())) {
m_backing_store = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, m_rect.size());
m_backing_store = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, m_rect.size()).release_value_but_fixme_should_propagate_errors();
}
invalidate(true, old_rect.size() != rect.size());

View file

@ -409,17 +409,18 @@ void WindowFrame::PerScaleRenderedCache::render(WindowFrame& frame, Screen& scre
if (tmp_it != s_tmp_bitmap_cache.end())
tmp_it->value = nullptr;
auto bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, frame_rect_including_shadow.size(), scale);
if (!bitmap) {
auto bitmap_or_error = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, frame_rect_including_shadow.size(), scale);
if (bitmap_or_error.is_error()) {
s_tmp_bitmap_cache.remove(scale);
dbgln("Could not create bitmap of size {}", frame_rect_including_shadow.size());
dbgln("Could not create bitmap of size {}: {}", frame_rect_including_shadow.size(), bitmap_or_error.error());
return;
}
auto bitmap = bitmap_or_error.release_value();
tmp_bitmap = bitmap.ptr();
if (tmp_it != s_tmp_bitmap_cache.end())
tmp_it->value = bitmap.release_nonnull();
tmp_it->value = move(bitmap);
else
s_tmp_bitmap_cache.set(scale, bitmap.release_nonnull());
s_tmp_bitmap_cache.set(scale, move(bitmap));
} else {
tmp_bitmap = tmp_it->value.ptr();
}
@ -432,14 +433,14 @@ void WindowFrame::PerScaleRenderedCache::render(WindowFrame& frame, Screen& scre
if (!m_top_bottom || m_top_bottom->width() != frame_rect_including_shadow.width() || m_top_bottom->height() != top_bottom_height || m_top_bottom->scale() != scale) {
if (top_bottom_height > 0)
m_top_bottom = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, { frame_rect_including_shadow.width(), top_bottom_height }, scale);
m_top_bottom = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, { frame_rect_including_shadow.width(), top_bottom_height }, scale).release_value_but_fixme_should_propagate_errors();
else
m_top_bottom = nullptr;
m_shadow_dirty = true;
}
if (!m_left_right || m_left_right->height() != frame_rect_including_shadow.height() || m_left_right->width() != left_right_width || m_left_right->scale() != scale) {
if (left_right_width > 0)
m_left_right = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, { left_right_width, frame_rect_including_shadow.height() }, scale);
m_left_right = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, { left_right_width, frame_rect_including_shadow.height() }, scale).release_value_but_fixme_should_propagate_errors();
else
m_left_right = nullptr;
m_shadow_dirty = true;