mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 20:15:17 +00:00
LibGfx: Use ErrorOr<T> for Bitmap::try_create()
Another one that was used in a fajillion places.
This commit is contained in:
parent
235f39e449
commit
0de33b3d6c
Notes:
sideshowbarker
2024-07-18 01:24:23 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/0de33b3d6c3
43 changed files with 157 additions and 141 deletions
|
@ -25,8 +25,8 @@ BENCHMARK_CASE(diagonal_lines)
|
|||
const int run_count = 50;
|
||||
const int bitmap_size = 2000;
|
||||
|
||||
auto bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { bitmap_size, bitmap_size });
|
||||
Gfx::Painter painter(*bitmap);
|
||||
auto bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { bitmap_size, bitmap_size }).release_value_but_fixme_should_propagate_errors();
|
||||
Gfx::Painter painter(bitmap);
|
||||
|
||||
for (int run = 0; run < run_count; run++) {
|
||||
for (int i = 0; i < bitmap_size; i++) {
|
||||
|
@ -41,8 +41,8 @@ BENCHMARK_CASE(fill)
|
|||
const int run_count = 1000;
|
||||
const int bitmap_size = 2000;
|
||||
|
||||
auto bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { bitmap_size, bitmap_size });
|
||||
Gfx::Painter painter(*bitmap);
|
||||
auto bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { bitmap_size, bitmap_size }).release_value_but_fixme_should_propagate_errors();
|
||||
Gfx::Painter painter(bitmap);
|
||||
|
||||
for (int run = 0; run < run_count; run++) {
|
||||
painter.fill_rect(bitmap->rect(), Color::Blue);
|
||||
|
@ -54,8 +54,8 @@ BENCHMARK_CASE(fill_with_gradient)
|
|||
const int run_count = 50;
|
||||
const int bitmap_size = 2000;
|
||||
|
||||
auto bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { bitmap_size, bitmap_size });
|
||||
Gfx::Painter painter(*bitmap);
|
||||
auto bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { bitmap_size, bitmap_size }).release_value_but_fixme_should_propagate_errors();
|
||||
Gfx::Painter painter(bitmap);
|
||||
|
||||
for (int run = 0; run < run_count; run++) {
|
||||
painter.fill_rect_with_gradient(bitmap->rect(), Color::Blue, Color::Red);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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++) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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>();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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++)
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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++) {
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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++) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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 };
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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--) {
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue