diff options
Diffstat (limited to 'Userland')
42 files changed, 151 insertions, 135 deletions
diff --git a/Userland/Applications/3DFileViewer/main.cpp b/Userland/Applications/3DFileViewer/main.cpp index 0785a1b240..3c7b15ece5 100644 --- a/Userland/Applications/3DFileViewer/main.cpp +++ b/Userland/Applications/3DFileViewer/main.cpp @@ -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); diff --git a/Userland/Applications/DisplaySettings/MonitorWidget.cpp b/Userland/Applications/DisplaySettings/MonitorWidget.cpp index dc958bee1d..e4ba1f6387 100644 --- a/Userland/Applications/DisplaySettings/MonitorWidget.cpp +++ b/Userland/Applications/DisplaySettings/MonitorWidget.cpp @@ -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); } diff --git a/Userland/Applications/PDFViewer/PDFViewer.cpp b/Userland/Applications/PDFViewer/PDFViewer.cpp index 15b1e38d95..a5fc4bb67d 100644 --- a/Userland/Applications/PDFViewer/PDFViewer.cpp +++ b/Userland/Applications/PDFViewer/PDFViewer.cpp @@ -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); diff --git a/Userland/Applications/Piano/RollWidget.cpp b/Userland/Applications/Piano/RollWidget.cpp index 51bc56f27c..d2c6312dbd 100644 --- a/Userland/Applications/Piano/RollWidget.cpp +++ b/Userland/Applications/Piano/RollWidget.cpp @@ -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()); diff --git a/Userland/Applications/PixelPaint/Image.cpp b/Userland/Applications/PixelPaint/Image.cpp index cade0b884e..dca4e320e5 100644 --- a/Userland/Applications/PixelPaint/Image.cpp +++ b/Userland/Applications/PixelPaint/Image.cpp @@ -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; } diff --git a/Userland/Applications/PixelPaint/Layer.cpp b/Userland/Applications/PixelPaint/Layer.cpp index e0ca6ff023..134737948f 100644 --- a/Userland/Applications/PixelPaint/Layer.cpp +++ b/Userland/Applications/PixelPaint/Layer.cpp @@ -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++) { diff --git a/Userland/Applications/SystemMonitor/NetworkStatisticsWidget.cpp b/Userland/Applications/SystemMonitor/NetworkStatisticsWidget.cpp index 79f7ae7315..328f6f0fc0 100644 --- a/Userland/Applications/SystemMonitor/NetworkStatisticsWidget.cpp +++ b/Userland/Applications/SystemMonitor/NetworkStatisticsWidget.cpp @@ -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) { diff --git a/Userland/Applications/VideoPlayer/main.cpp b/Userland/Applications/VideoPlayer/main.cpp index a35d8c4318..189f03ed18 100644 --- a/Userland/Applications/VideoPlayer/main.cpp +++ b/Userland/Applications/VideoPlayer/main.cpp @@ -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>(); diff --git a/Userland/Demos/Cube/Cube.cpp b/Userland/Demos/Cube/Cube.cpp index 1a4c307c59..cf6ea1e396 100644 --- a/Userland/Demos/Cube/Cube.cpp +++ b/Userland/Demos/Cube/Cube.cpp @@ -60,7 +60,7 @@ private: Cube::Cube() { - m_bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { WIDTH, HEIGHT }); + m_bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { WIDTH, HEIGHT }).release_value_but_fixme_should_propagate_errors(); m_accumulated_time = 0; m_cycles = 0; diff --git a/Userland/Demos/Fire/Fire.cpp b/Userland/Demos/Fire/Fire.cpp index 14dff9a3dd..7e9fdbc155 100644 --- a/Userland/Demos/Fire/Fire.cpp +++ b/Userland/Demos/Fire/Fire.cpp @@ -81,7 +81,7 @@ private: Fire::Fire() { - bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::Indexed8, { FIRE_WIDTH, FIRE_HEIGHT }); + bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::Indexed8, { FIRE_WIDTH, FIRE_HEIGHT }).release_value_but_fixme_should_propagate_errors(); /* Initialize fire palette */ for (int i = 0; i < 30; i++) diff --git a/Userland/Demos/LibGfxDemo/main.cpp b/Userland/Demos/LibGfxDemo/main.cpp index b2183ba03d..d406d43ea7 100644 --- a/Userland/Demos/LibGfxDemo/main.cpp +++ b/Userland/Demos/LibGfxDemo/main.cpp @@ -36,7 +36,7 @@ private: Canvas::Canvas() { - m_bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { WIDTH, HEIGHT }); + m_bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { WIDTH, HEIGHT }).release_value_but_fixme_should_propagate_errors(); draw(); } diff --git a/Userland/Demos/LibGfxScaleDemo/main.cpp b/Userland/Demos/LibGfxScaleDemo/main.cpp index 7ff4511147..7db7859045 100644 --- a/Userland/Demos/LibGfxScaleDemo/main.cpp +++ b/Userland/Demos/LibGfxScaleDemo/main.cpp @@ -41,8 +41,8 @@ private: Canvas::Canvas() { - m_bitmap_1x = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { WIDTH, HEIGHT }, 1); - m_bitmap_2x = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { WIDTH, HEIGHT }, 2); + m_bitmap_1x = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { WIDTH, HEIGHT }, 1).release_value_but_fixme_should_propagate_errors(); + m_bitmap_2x = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { WIDTH, HEIGHT }, 2).release_value_but_fixme_should_propagate_errors(); // m_bitmap_1x and m_bitmap_2x have the same logical size, so LibGfx will try to draw them at the same physical size: // When drawing on a 2x backing store it'd scale m_bitmap_1x up 2x and paint m_bitmap_2x at its physical size. diff --git a/Userland/Demos/Mandelbrot/Mandelbrot.cpp b/Userland/Demos/Mandelbrot/Mandelbrot.cpp index 174456a084..2241e89fbf 100644 --- a/Userland/Demos/Mandelbrot/Mandelbrot.cpp +++ b/Userland/Demos/Mandelbrot/Mandelbrot.cpp @@ -35,7 +35,7 @@ public: void resize(Gfx::IntSize const& size) { - m_bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, size); + m_bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, size).release_value_but_fixme_should_propagate_errors(); correct_aspect(); calculate(); } diff --git a/Userland/Demos/Screensaver/Screensaver.cpp b/Userland/Demos/Screensaver/Screensaver.cpp index 0c09f03c0c..57b90fcace 100644 --- a/Userland/Demos/Screensaver/Screensaver.cpp +++ b/Userland/Demos/Screensaver/Screensaver.cpp @@ -35,7 +35,7 @@ private: Screensaver::Screensaver(int width, int height, int interval) { - m_bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { width, height }); + m_bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { width, height }).release_value_but_fixme_should_propagate_errors(); srand(time(nullptr)); stop_timer(); start_timer(interval); diff --git a/Userland/Demos/Starfield/Starfield.cpp b/Userland/Demos/Starfield/Starfield.cpp index aabc130225..5941d634f6 100644 --- a/Userland/Demos/Starfield/Starfield.cpp +++ b/Userland/Demos/Starfield/Starfield.cpp @@ -58,7 +58,7 @@ Starfield::Starfield(int interval) void Starfield::create_stars(int width, int height, int stars) { - m_bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { width, height }); + m_bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { width, height }).release_value_but_fixme_should_propagate_errors(); m_stars.grow_capacity(stars); for (int i = 0; i < stars; i++) { diff --git a/Userland/DevTools/Profiler/DisassemblyModel.cpp b/Userland/DevTools/Profiler/DisassemblyModel.cpp index 6ac30d28df..5daf43b425 100644 --- a/Userland/DevTools/Profiler/DisassemblyModel.cpp +++ b/Userland/DevTools/Profiler/DisassemblyModel.cpp @@ -21,7 +21,7 @@ static const Gfx::Bitmap& heat_gradient() { static RefPtr<Gfx::Bitmap> bitmap; if (!bitmap) { - bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { 101, 1 }); + bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { 101, 1 }).release_value_but_fixme_should_propagate_errors(); GUI::Painter painter(*bitmap); painter.fill_rect_with_gradient(Orientation::Horizontal, bitmap->rect(), Color::from_rgb(0xffc080), Color::from_rgb(0xff3000)); } diff --git a/Userland/Libraries/LibCards/Card.cpp b/Userland/Libraries/LibCards/Card.cpp index f60a0cd4ca..598e866e82 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::try_create(Gfx::BitmapFormat::BGRA8888, { width, height })) + , m_front(Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, { width, height }).release_value_but_fixme_should_propagate_errors()) , m_type(type) , m_value(value) { @@ -72,7 +72,7 @@ Card::Card(Type type, uint8_t value) Gfx::IntRect paint_rect({ 0, 0 }, { width, height }); if (s_background.is_null()) { - s_background = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, { width, height }); + s_background = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, { width, height }).release_value_but_fixme_should_propagate_errors(); Gfx::Painter bg_painter(*s_background); auto image = Gfx::Bitmap::try_load_from_file("/res/icons/cards/buggie-deck.png").release_value_but_fixme_should_propagate_errors(); diff --git a/Userland/Libraries/LibGL/SoftwareRasterizer.cpp b/Userland/Libraries/LibGL/SoftwareRasterizer.cpp index 0df985367f..bf561b87f7 100644 --- a/Userland/Libraries/LibGL/SoftwareRasterizer.cpp +++ b/Userland/Libraries/LibGL/SoftwareRasterizer.cpp @@ -478,7 +478,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::try_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)).release_value_but_fixme_should_propagate_errors() } , m_depth_buffer { adopt_own(*new DepthBuffer(closest_multiple(min_size, RASTERIZER_BLOCK_SIZE))) } { } @@ -547,7 +547,7 @@ void SoftwareRasterizer::resize(const Gfx::IntSize& min_size) { wait_for_all_threads(); - m_render_target = Gfx::Bitmap::try_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)).release_value_but_fixme_should_propagate_errors(); m_depth_buffer = adopt_own(*new DepthBuffer(m_render_target->size())); } diff --git a/Userland/Libraries/LibGUI/Clipboard.cpp b/Userland/Libraries/LibGUI/Clipboard.cpp index 422acbcd73..a65281af1b 100644 --- a/Userland/Libraries/LibGUI/Clipboard.cpp +++ b/Userland/Libraries/LibGUI/Clipboard.cpp @@ -94,9 +94,12 @@ RefPtr<Gfx::Bitmap> Clipboard::bitmap() const auto clipping_bitmap_or_error = Gfx::Bitmap::try_create_wrapper((Gfx::BitmapFormat)format.value(), { (int)width.value(), (int)height.value() }, scale.value(), pitch.value(), clipping.data.data()); if (clipping_bitmap_or_error.is_error()) return nullptr; - auto clipping_bitmap = clipping_bitmap_or_error.release_value(); + auto clipping_bitmap = clipping_bitmap_or_error.release_value_but_fixme_should_propagate_errors(); - auto bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, { (int)width.value(), (int)height.value() }, scale.value()); + auto bitmap_or_error = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, { (int)width.value(), (int)height.value() }, scale.value()); + if (bitmap_or_error.is_error()) + return nullptr; + auto bitmap = bitmap_or_error.release_value_but_fixme_should_propagate_errors(); 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 1f5304ec9a..3e454aeb0e 100644 --- a/Userland/Libraries/LibGUI/ColorPicker.cpp +++ b/Userland/Libraries/LibGUI/ColorPicker.cpp @@ -532,7 +532,7 @@ ColorField::ColorField(Color color) void ColorField::create_color_bitmap() { - m_color_bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { 256, 256 }); + m_color_bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { 256, 256 }).release_value_but_fixme_should_propagate_errors(); auto painter = Gfx::Painter(*m_color_bitmap); Gfx::HSV hsv; @@ -658,7 +658,7 @@ void ColorField::resize_event(ResizeEvent&) ColorSlider::ColorSlider(double value) : m_value(value) { - m_color_bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { 32, 360 }); + m_color_bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { 32, 360 }).release_value_but_fixme_should_propagate_errors(); auto painter = Gfx::Painter(*m_color_bitmap); for (int h = 0; h < 360; h++) { diff --git a/Userland/Libraries/LibGUI/FileSystemModel.cpp b/Userland/Libraries/LibGUI/FileSystemModel.cpp index 397b4d7381..014f73a99c 100644 --- a/Userland/Libraries/LibGUI/FileSystemModel.cpp +++ b/Userland/Libraries/LibGUI/FileSystemModel.cpp @@ -624,10 +624,14 @@ static RefPtr<Gfx::Bitmap> render_thumbnail(StringView const& path) double scale = min(32 / (double)bitmap->width(), 32 / (double)bitmap->height()); - auto thumbnail = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, { 32, 32 }); + auto thumbnail_or_error = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, { 32, 32 }); + if (thumbnail_or_error.is_error()) + return nullptr; + auto thumbnail = thumbnail_or_error.release_value_but_fixme_should_propagate_errors(); + auto destination = Gfx::IntRect(0, 0, (int)(bitmap->width() * scale), (int)(bitmap->height() * scale)).centered_within(thumbnail->rect()); - Painter painter(*thumbnail); + Painter painter(thumbnail); painter.draw_scaled_bitmap(destination, *bitmap, bitmap->rect()); return thumbnail; } diff --git a/Userland/Libraries/LibGUI/Window.cpp b/Userland/Libraries/LibGUI/Window.cpp index b94c51189a..b59cbc1fa6 100644 --- a/Userland/Libraries/LibGUI/Window.cpp +++ b/Userland/Libraries/LibGUI/Window.cpp @@ -903,8 +903,7 @@ void Window::set_icon(const Gfx::Bitmap* icon) Gfx::IntSize icon_size = icon ? icon->size() : Gfx::IntSize(16, 16); - m_icon = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, icon_size); - VERIFY(m_icon); + m_icon = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, icon_size).release_value_but_fixme_should_propagate_errors(); if (icon) { Painter painter(*m_icon); painter.blit({ 0, 0 }, *icon, icon->rect()); diff --git a/Userland/Libraries/LibGfx/BMPLoader.cpp b/Userland/Libraries/LibGfx/BMPLoader.cpp index 4973622a0c..92e2326185 100644 --- a/Userland/Libraries/LibGfx/BMPLoader.cpp +++ b/Userland/Libraries/LibGfx/BMPLoader.cpp @@ -1187,12 +1187,15 @@ 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::try_create(format, { static_cast<int>(width), static_cast<int>(height) }); - if (!context.bitmap) { - dbgln("BMP appears to have overly large dimensions"); + + auto bitmap_or_error = Bitmap::try_create(format, { static_cast<int>(width), static_cast<int>(height) }); + if (bitmap_or_error.is_error()) { + // FIXME: Propagate the *real* error. return false; } + context.bitmap = bitmap_or_error.release_value_but_fixme_should_propagate_errors(); + ByteBuffer rle_buffer; ReadonlyBytes bytes { context.file_bytes + context.data_offset, context.file_size - context.data_offset }; diff --git a/Userland/Libraries/LibGfx/Bitmap.cpp b/Userland/Libraries/LibGfx/Bitmap.cpp index d733fbc4f3..3c119d1b4e 100644 --- a/Userland/Libraries/LibGfx/Bitmap.cpp +++ b/Userland/Libraries/LibGfx/Bitmap.cpp @@ -67,12 +67,10 @@ static bool size_would_overflow(BitmapFormat format, IntSize const& size, int sc return Checked<size_t>::multiplication_would_overflow(pitch, size.height() * scale_factor); } -RefPtr<Bitmap> Bitmap::try_create(BitmapFormat format, IntSize const& size, int scale_factor) +ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::try_create(BitmapFormat format, IntSize const& size, int scale_factor) { - auto backing_store_or_error = Bitmap::allocate_backing_store(format, size, scale_factor); - if (backing_store_or_error.is_error()) - return nullptr; - return adopt_ref(*new Bitmap(format, size, scale_factor, backing_store_or_error.release_value())); + auto backing_store = TRY(Bitmap::allocate_backing_store(format, size, scale_factor)); + return AK::adopt_nonnull_ref_or_enomem(new (nothrow) Bitmap(format, size, scale_factor, backing_store)); } ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::try_create_shareable(BitmapFormat format, IntSize const& size, int scale_factor) @@ -250,9 +248,10 @@ RefPtr<Bitmap> Bitmap::try_create_from_serialized_byte_buffer(ByteBuffer&& buffe auto data = stream.bytes().slice(stream.offset(), actual_size); - auto bitmap = Bitmap::try_create(format, { width, height }, scale_factor); - if (!bitmap) + auto bitmap_or_error = Bitmap::try_create(format, { width, height }, scale_factor); + if (bitmap_or_error.is_error()) return {}; + auto bitmap = bitmap_or_error.release_value_but_fixme_should_propagate_errors(); bitmap->m_palette = new RGBA32[palette_size]; memcpy(bitmap->m_palette, palette.data(), palette_size * sizeof(RGBA32)); @@ -309,26 +308,17 @@ Bitmap::Bitmap(BitmapFormat format, Core::AnonymousBuffer buffer, IntSize const& ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::clone() const { - auto new_bitmap = Bitmap::try_create(format(), size(), scale()); - - if (!new_bitmap) { - // FIXME: Propagate the *real* error, once we have it. - return Error::from_errno(ENOMEM); - } + auto new_bitmap = TRY(Bitmap::try_create(format(), size(), scale())); VERIFY(size_in_bytes() == new_bitmap->size_in_bytes()); memcpy(new_bitmap->scanline(0), scanline(0), size_in_bytes()); - return new_bitmap.release_nonnull(); + return new_bitmap; } ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::rotated(Gfx::RotationDirection rotation_direction) const { - auto new_bitmap = Gfx::Bitmap::try_create(this->format(), { height(), width() }, scale()); - if (!new_bitmap) { - // FIXME: Propagate the *real* error, once we have it. - return Error::from_errno(ENOMEM); - } + auto new_bitmap = TRY(Gfx::Bitmap::try_create(this->format(), { height(), width() }, scale())); auto w = this->physical_width(); auto h = this->physical_height(); @@ -344,16 +334,12 @@ ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::rotated(Gfx::RotationDirection rotat } } - return new_bitmap.release_nonnull(); + return new_bitmap; } ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::flipped(Gfx::Orientation orientation) const { - auto new_bitmap = Gfx::Bitmap::try_create(this->format(), { width(), height() }, scale()); - if (!new_bitmap) { - // FIXME: Propagate the *real* error, once we have it. - return Error::from_errno(ENOMEM); - } + auto new_bitmap = TRY(Gfx::Bitmap::try_create(this->format(), { width(), height() }, scale())); auto w = this->physical_width(); auto h = this->physical_height(); @@ -367,7 +353,7 @@ ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::flipped(Gfx::Orientation orientation } } - return new_bitmap.release_nonnull(); + return new_bitmap; } ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::scaled(int sx, int sy) const @@ -376,11 +362,7 @@ ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::scaled(int sx, int sy) const if (sx == 1 && sy == 1) return NonnullRefPtr { *this }; - auto new_bitmap = Gfx::Bitmap::try_create(format(), { width() * sx, height() * sy }, scale()); - if (!new_bitmap) { - // FIXME: Propagate the *real* error, once we have it. - return Error::from_errno(ENOMEM); - } + auto new_bitmap = TRY(Gfx::Bitmap::try_create(format(), { width() * sx, height() * sy }, scale())); auto old_width = physical_width(); auto old_height = physical_height(); @@ -399,7 +381,7 @@ ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::scaled(int sx, int sy) const } } - return new_bitmap.release_nonnull(); + return new_bitmap; } // http://fourier.eng.hmc.edu/e161/lectures/resize/node3.html @@ -412,11 +394,7 @@ ErrorOr<NonnullRefPtr<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::try_create(format(), { scaled_width, scaled_height }, scale()); - if (!new_bitmap) { - // FIXME: Propagate the *real* error, once we have it. - return Error::from_errno(ENOMEM); - } + auto new_bitmap = TRY(Gfx::Bitmap::try_create(format(), { scaled_width, scaled_height }, scale())); auto old_width = physical_width(); auto old_height = physical_height(); @@ -483,16 +461,12 @@ ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::scaled(float sx, float sy) const // Bottom-right pixel new_bitmap->set_pixel(new_width - 1, new_height - 1, get_pixel(physical_width() - 1, physical_height() - 1)); - return new_bitmap.release_nonnull(); + return new_bitmap; } ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::cropped(Gfx::IntRect crop) const { - auto new_bitmap = Gfx::Bitmap::try_create(format(), { crop.width(), crop.height() }, 1); - if (!new_bitmap) { - // FIXME: Propagate the *real* error, once we have it. - return Error::from_errno(ENOMEM); - } + auto new_bitmap = TRY(Gfx::Bitmap::try_create(format(), { crop.width(), crop.height() }, 1)); for (int y = 0; y < crop.height(); ++y) { for (int x = 0; x < crop.width(); ++x) { @@ -505,7 +479,7 @@ ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::cropped(Gfx::IntRect crop) const } } } - return new_bitmap.release_nonnull(); + return new_bitmap; } ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::to_bitmap_backed_by_anonymous_buffer() const diff --git a/Userland/Libraries/LibGfx/Bitmap.h b/Userland/Libraries/LibGfx/Bitmap.h index 21f4182922..0290431738 100644 --- a/Userland/Libraries/LibGfx/Bitmap.h +++ b/Userland/Libraries/LibGfx/Bitmap.h @@ -90,7 +90,7 @@ enum RotationDirection { class Bitmap : public RefCounted<Bitmap> { public: - [[nodiscard]] static RefPtr<Bitmap> try_create(BitmapFormat, IntSize const&, int intrinsic_scale = 1); + [[nodiscard]] static ErrorOr<NonnullRefPtr<Bitmap>> try_create(BitmapFormat, IntSize const&, int intrinsic_scale = 1); [[nodiscard]] static ErrorOr<NonnullRefPtr<Bitmap>> try_create_shareable(BitmapFormat, IntSize const&, int intrinsic_scale = 1); [[nodiscard]] static ErrorOr<NonnullRefPtr<Bitmap>> try_create_wrapper(BitmapFormat, IntSize const&, int intrinsic_scale, size_t pitch, void*); [[nodiscard]] static ErrorOr<NonnullRefPtr<Bitmap>> try_load_from_file(String const& path, int scale_factor = 1); diff --git a/Userland/Libraries/LibGfx/DDSLoader.cpp b/Userland/Libraries/LibGfx/DDSLoader.cpp index d46aea7f7e..d94165fd4a 100644 --- a/Userland/Libraries/LibGfx/DDSLoader.cpp +++ b/Userland/Libraries/LibGfx/DDSLoader.cpp @@ -793,7 +793,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::try_create(BitmapFormat::BGRA8888, { width, height }); + context.bitmap = Bitmap::try_create(BitmapFormat::BGRA8888, { width, height }).release_value_but_fixme_should_propagate_errors(); decode_bitmap(stream, context, format, width, height); } diff --git a/Userland/Libraries/LibGfx/Filters/GenericConvolutionFilter.h b/Userland/Libraries/LibGfx/Filters/GenericConvolutionFilter.h index 0ee8ec01ad..cf0138999d 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::try_create(source.format(), source_rect.size()); + apply_cache.m_target = Gfx::Bitmap::try_create(source.format(), source_rect.size()).release_value_but_fixme_should_propagate_errors(); target_rect.translate_by(-target_rect.location()); } diff --git a/Userland/Libraries/LibGfx/GIFLoader.cpp b/Userland/Libraries/LibGfx/GIFLoader.cpp index f13c25b53e..cfb6d68c98 100644 --- a/Userland/Libraries/LibGfx/GIFLoader.cpp +++ b/Userland/Libraries/LibGfx/GIFLoader.cpp @@ -292,12 +292,18 @@ 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::try_create(BitmapFormat::BGRA8888, { context.logical_screen.width, context.logical_screen.height }); - if (!context.frame_buffer) - return false; - context.prev_frame_buffer = Bitmap::try_create(BitmapFormat::BGRA8888, { context.logical_screen.width, context.logical_screen.height }); - if (!context.prev_frame_buffer) - return false; + { + auto bitmap_or_error = Bitmap::try_create(BitmapFormat::BGRA8888, { context.logical_screen.width, context.logical_screen.height }); + if (bitmap_or_error.is_error()) + return false; + context.frame_buffer = bitmap_or_error.release_value_but_fixme_should_propagate_errors(); + } + { + auto bitmap_or_error = Bitmap::try_create(BitmapFormat::BGRA8888, { context.logical_screen.width, context.logical_screen.height }); + if (bitmap_or_error.is_error()) + return false; + context.prev_frame_buffer = bitmap_or_error.release_value_but_fixme_should_propagate_errors(); + } } else if (frame_index < context.current_frame) { start_frame = 0; } diff --git a/Userland/Libraries/LibGfx/ICOLoader.cpp b/Userland/Libraries/LibGfx/ICOLoader.cpp index 6102ea5898..1855f084e2 100644 --- a/Userland/Libraries/LibGfx/ICOLoader.cpp +++ b/Userland/Libraries/LibGfx/ICOLoader.cpp @@ -241,9 +241,10 @@ static bool load_ico_bmp(ICOLoadingContext& context, ICOImageDescriptor& desc) return false; } - desc.bitmap = Bitmap::try_create(BitmapFormat::BGRA8888, { desc.width, desc.height }); - if (!desc.bitmap) + auto bitmap_or_error = Bitmap::try_create(BitmapFormat::BGRA8888, { desc.width, desc.height }); + if (bitmap_or_error.is_error()) return false; + desc.bitmap = bitmap_or_error.release_value_but_fixme_should_propagate_errors(); Bitmap& bitmap = *desc.bitmap; const u8* image_base = context.data + desc.offset + sizeof(info); const BMP_ARGB* data_base = (const BMP_ARGB*)image_base; diff --git a/Userland/Libraries/LibGfx/JPGLoader.cpp b/Userland/Libraries/LibGfx/JPGLoader.cpp index 0784044bbe..c064908b1d 100644 --- a/Userland/Libraries/LibGfx/JPGLoader.cpp +++ b/Userland/Libraries/LibGfx/JPGLoader.cpp @@ -1063,8 +1063,11 @@ static void ycbcr_to_rgb(const JPGLoadingContext& context, Vector<Macroblock>& m static bool compose_bitmap(JPGLoadingContext& context, const Vector<Macroblock>& macroblocks) { - context.bitmap = Bitmap::try_create(BitmapFormat::BGRx8888, { context.frame.width, context.frame.height }); - if (!context.bitmap) + auto bitmap_or_error = Bitmap::try_create(BitmapFormat::BGRx8888, { context.frame.width, context.frame.height }); + if (bitmap_or_error.is_error()) + return false; + context.bitmap = bitmap_or_error.release_value_but_fixme_should_propagate_errors(); + if (bitmap_or_error.is_error()) return false; for (u32 y = context.frame.height - 1; y < context.frame.height; y--) { diff --git a/Userland/Libraries/LibGfx/PNGLoader.cpp b/Userland/Libraries/LibGfx/PNGLoader.cpp index 70f458a211..d92cbaf0a3 100644 --- a/Userland/Libraries/LibGfx/PNGLoader.cpp +++ b/Userland/Libraries/LibGfx/PNGLoader.cpp @@ -47,7 +47,7 @@ struct [[gnu::packed]] PaletteEntry { u8 r; u8 g; u8 b; - //u8 a; + // u8 a; }; template<typename T> @@ -603,13 +603,13 @@ static bool decode_png_bitmap_simple(PNGLoadingContext& context) } } - context.bitmap = Bitmap::try_create(context.has_alpha() ? BitmapFormat::BGRA8888 : BitmapFormat::BGRx8888, { context.width, context.height }); - - if (!context.bitmap) { + auto bitmap_or_error = Bitmap::try_create(context.has_alpha() ? BitmapFormat::BGRA8888 : BitmapFormat::BGRx8888, { context.width, context.height }); + if (bitmap_or_error.is_error()) { context.state = PNGLoadingContext::State::Error; return false; } + context.bitmap = bitmap_or_error.release_value(); return unfilter(context); } @@ -705,7 +705,11 @@ static bool decode_adam7_pass(PNGLoadingContext& context, Streamer& streamer, in } } - subimage_context.bitmap = Bitmap::try_create(context.bitmap->format(), { subimage_context.width, subimage_context.height }); + auto bitmap_or_error = Bitmap::try_create(context.bitmap->format(), { subimage_context.width, subimage_context.height }); + if (bitmap_or_error.is_error()) + return false; + + subimage_context.bitmap = bitmap_or_error.release_value_but_fixme_should_propagate_errors(); if (!unfilter(subimage_context)) { subimage_context.bitmap = nullptr; return false; @@ -723,9 +727,10 @@ 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::try_create(context.has_alpha() ? BitmapFormat::BGRA8888 : BitmapFormat::BGRx8888, { context.width, context.height }); - if (!context.bitmap) + auto bitmap_or_error = Bitmap::try_create(context.has_alpha() ? BitmapFormat::BGRA8888 : BitmapFormat::BGRx8888, { context.width, context.height }); + if (bitmap_or_error.is_error()) return false; + context.bitmap = bitmap_or_error.release_value_but_fixme_should_propagate_errors(); for (int pass = 1; pass <= 7; ++pass) { if (!decode_adam7_pass(context, streamer, pass)) diff --git a/Userland/Libraries/LibGfx/PortableImageLoaderCommon.h b/Userland/Libraries/LibGfx/PortableImageLoaderCommon.h index 569694fbc3..61882b6b05 100644 --- a/Userland/Libraries/LibGfx/PortableImageLoaderCommon.h +++ b/Userland/Libraries/LibGfx/PortableImageLoaderCommon.h @@ -178,11 +178,12 @@ static bool read_max_val(TContext& context, Streamer& streamer) template<typename TContext> static bool create_bitmap(TContext& context) { - context.bitmap = Bitmap::try_create(BitmapFormat::BGRx8888, { context.width, context.height }); - if (!context.bitmap) { + auto bitmap_or_error = Bitmap::try_create(BitmapFormat::BGRx8888, { context.width, context.height }); + if (bitmap_or_error.is_error()) { context.state = TContext::State::Error; return false; } + context.bitmap = bitmap_or_error.release_value_but_fixme_should_propagate_errors(); return true; } diff --git a/Userland/Libraries/LibGfx/TrueTypeFont/Glyf.cpp b/Userland/Libraries/LibGfx/TrueTypeFont/Glyf.cpp index c7d2884f5a..d819cea664 100644 --- a/Userland/Libraries/LibGfx/TrueTypeFont/Glyf.cpp +++ b/Userland/Libraries/LibGfx/TrueTypeFont/Glyf.cpp @@ -207,9 +207,10 @@ void Rasterizer::draw_path(Gfx::Path& path) RefPtr<Gfx::Bitmap> Rasterizer::accumulate() { - auto bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, m_size); - if (!bitmap) + auto bitmap_or_error = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, m_size); + if (bitmap_or_error.is_error()) return {}; + auto bitmap = bitmap_or_error.release_value_but_fixme_should_propagate_errors(); Color base_color = Color::from_rgb(0xffffff); for (int y = 0; y < m_size.height(); y++) { float accumulator = 0.0; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp index f3773c315b..3a813af475 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp @@ -80,8 +80,12 @@ bool HTMLCanvasElement::create_bitmap() m_bitmap = nullptr; return false; } - if (!m_bitmap || m_bitmap->size() != size) - m_bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, size); + if (!m_bitmap || m_bitmap->size() != size) { + auto bitmap_or_error = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, size); + if (bitmap_or_error.is_error()) + return false; + m_bitmap = bitmap_or_error.release_value_but_fixme_should_propagate_errors(); + } return m_bitmap; } diff --git a/Userland/Libraries/LibWeb/Painting/ShadowPainting.cpp b/Userland/Libraries/LibWeb/Painting/ShadowPainting.cpp index 8b5c93ed7e..91c09737d5 100644 --- a/Userland/Libraries/LibWeb/Painting/ShadowPainting.cpp +++ b/Userland/Libraries/LibWeb/Painting/ShadowPainting.cpp @@ -30,11 +30,12 @@ void paint_box_shadow(PaintContext& context, Gfx::IntRect const& content_rect, B if (bitmap_rect.is_empty()) return; - auto new_bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, bitmap_rect.size()); - if (!new_bitmap) { - dbgln("Unable to allocate temporary bitmap for box-shadow rendering"); + auto bitmap_or_error = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, bitmap_rect.size()); + if (bitmap_or_error.is_error()) { + dbgln("Unable to allocate temporary bitmap for box-shadow rendering: {}", bitmap_or_error.error()); return; } + auto new_bitmap = bitmap_or_error.release_value_but_fixme_should_propagate_errors(); Gfx::Painter painter(*new_bitmap); painter.fill_rect({ { 2 * box_shadow_data.blur_radius, 2 * box_shadow_data.blur_radius }, content_rect.size() }, box_shadow_data.color); diff --git a/Userland/Libraries/LibWeb/Painting/StackingContext.cpp b/Userland/Libraries/LibWeb/Painting/StackingContext.cpp index 4bb3d75c16..bc7945bfa7 100644 --- a/Userland/Libraries/LibWeb/Painting/StackingContext.cpp +++ b/Userland/Libraries/LibWeb/Painting/StackingContext.cpp @@ -117,14 +117,14 @@ void StackingContext::paint(PaintContext& context) return; if (opacity < 1.0f) { - auto bitmap = context.painter().target(); - auto new_bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, bitmap->size()); - if (!new_bitmap) + auto bitmap_or_error = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, context.painter().target()->size()); + if (bitmap_or_error.is_error()) return; - Gfx::Painter painter(*new_bitmap); + auto bitmap = bitmap_or_error.release_value_but_fixme_should_propagate_errors(); + Gfx::Painter painter(bitmap); PaintContext paint_context(painter, context.palette(), context.scroll_offset()); paint_internal(paint_context); - context.painter().blit(Gfx::IntPoint(m_box.absolute_position()), *new_bitmap, Gfx::IntRect(m_box.absolute_rect()), opacity); + context.painter().blit(Gfx::IntPoint(m_box.absolute_position()), bitmap, Gfx::IntRect(m_box.absolute_rect()), opacity); } else { paint_internal(context); } diff --git a/Userland/Services/SpiceAgent/ClipboardServerConnection.cpp b/Userland/Services/SpiceAgent/ClipboardServerConnection.cpp index 0d1be465e9..93dfc83ed9 100644 --- a/Userland/Services/SpiceAgent/ClipboardServerConnection.cpp +++ b/Userland/Services/SpiceAgent/ClipboardServerConnection.cpp @@ -43,8 +43,10 @@ RefPtr<Gfx::Bitmap> ClipboardServerConnection::get_bitmap() if (clipping_bitmap_or_error.is_error()) return nullptr; auto clipping_bitmap = clipping_bitmap_or_error.release_value(); - auto bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, { (int)width.value(), (int)height.value() }, scale.value()); - + auto bitmap_or_error = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, { (int)width.value(), (int)height.value() }, scale.value()); + if (bitmap_or_error.is_error()) + return nullptr; + auto bitmap = bitmap_or_error.release_value_but_fixme_should_propagate_errors(); for (int y = 0; y < clipping_bitmap->physical_height(); ++y) { for (int x = 0; x < clipping_bitmap->physical_width(); ++x) { auto pixel = clipping_bitmap->get_pixel(x, y); diff --git a/Userland/Services/WindowServer/ClientConnection.cpp b/Userland/Services/WindowServer/ClientConnection.cpp index ea4d0b28e5..85e4929ff8 100644 --- a/Userland/Services/WindowServer/ClientConnection.cpp +++ b/Userland/Services/WindowServer/ClientConnection.cpp @@ -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(); diff --git a/Userland/Services/WindowServer/Compositor.cpp b/Userland/Services/WindowServer/Compositor.cpp index 61f8ea5eba..f1b65b4a80 100644 --- a/Userland/Services/WindowServer/Compositor.cpp +++ b/Userland/Services/WindowServer/Compositor.cpp @@ -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); } diff --git a/Userland/Services/WindowServer/Overlays.cpp b/Userland/Services/WindowServer/Overlays.cpp index 46c3279ba8..c14aeac9a9 100644 --- a/Userland/Services/WindowServer/Overlays.cpp +++ b/Userland/Services/WindowServer/Overlays.cpp @@ -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); diff --git a/Userland/Services/WindowServer/Window.cpp b/Userland/Services/WindowServer/Window.cpp index d20ef03ee1..fdb5301010 100644 --- a/Userland/Services/WindowServer/Window.cpp +++ b/Userland/Services/WindowServer/Window.cpp @@ -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()); diff --git a/Userland/Services/WindowServer/WindowFrame.cpp b/Userland/Services/WindowServer/WindowFrame.cpp index ceeb6f4586..8c5e0ba9df 100644 --- a/Userland/Services/WindowServer/WindowFrame.cpp +++ b/Userland/Services/WindowServer/WindowFrame.cpp @@ -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; |