1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 09:17:35 +00:00

LibGfx: Fallback to a default scaled bitmap if the upscaled one failed

This makes cursors in a 2x Display Scale without a special upscaled
version (such as a Hand cursor) display the 1x version instead.
This commit is contained in:
Karol Kosek 2022-08-29 19:53:27 +02:00 committed by Linus Groh
parent 406dff16d1
commit 5478409025

View file

@ -105,6 +105,7 @@ ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::try_create_wrapper(BitmapFormat format, I
ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::try_load_from_file(StringView path, int scale_factor)
{
if (scale_factor > 1 && path.starts_with("/res/"sv)) {
auto load_scaled_bitmap = [](StringView path, int scale_factor) -> ErrorOr<NonnullRefPtr<Bitmap>> {
LexicalPath lexical_path { path };
StringBuilder highdpi_icon_path;
TRY(highdpi_icon_path.try_appendff("{}/{}-{}x.{}", lexical_path.dirname(), lexical_path.title(), scale_factor, lexical_path.extension()));
@ -119,6 +120,17 @@ ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::try_load_from_file(StringView path, int s
bitmap->m_size.set_height(bitmap->height() / scale_factor);
bitmap->m_scale = scale_factor;
return bitmap;
};
auto scaled_bitmap_or_error = load_scaled_bitmap(path, scale_factor);
if (!scaled_bitmap_or_error.is_error())
return scaled_bitmap_or_error.release_value();
auto error = scaled_bitmap_or_error.release_error();
if (!(error.is_syscall() && error.code() == ENOENT)) {
dbgln("Couldn't load scaled bitmap: {}", error);
dbgln("Trying base scale instead.");
}
}
auto fd = TRY(Core::System::open(path, O_RDONLY));