1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:17:45 +00:00

PixelPaint: Guarantee that constructed Layer always has a Gfx::Bitmap

Hoist any allocation failures so that layer factories never return a
bitmap-less layer.
This commit is contained in:
Andreas Kling 2021-06-12 10:24:04 +02:00
parent c7f7c1f7f0
commit 9038bc675f
2 changed files with 16 additions and 20 deletions

View file

@ -18,15 +18,19 @@ RefPtr<Layer> Layer::try_create_with_size(Image& image, Gfx::IntSize const& size
if (size.width() > 16384 || size.height() > 16384)
return nullptr;
return adopt_ref(*new Layer(image, size, move(name)));
}
RefPtr<Layer> Layer::try_create_with_bitmap(Image& image, Gfx::Bitmap const& bitmap, String name)
{
if (bitmap.size().is_empty())
auto bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, size);
if (!bitmap)
return nullptr;
if (bitmap.size().width() > 16384 || bitmap.size().height() > 16384)
return adopt_ref(*new Layer(image, *bitmap, move(name)));
}
RefPtr<Layer> Layer::try_create_with_bitmap(Image& image, NonnullRefPtr<Gfx::Bitmap> bitmap, String name)
{
if (bitmap->size().is_empty())
return nullptr;
if (bitmap->size().width() > 16384 || bitmap->size().height() > 16384)
return nullptr;
return adopt_ref(*new Layer(image, bitmap, move(name)));
@ -49,17 +53,10 @@ RefPtr<Layer> Layer::try_create_snapshot(Image& image, Layer const& layer)
return snapshot;
}
Layer::Layer(Image& image, Gfx::IntSize const& size, String name)
Layer::Layer(Image& image, NonnullRefPtr<Gfx::Bitmap> bitmap, String name)
: m_image(image)
, m_name(move(name))
{
m_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, size);
}
Layer::Layer(Image& image, Gfx::Bitmap const& bitmap, String name)
: m_image(image)
, m_name(move(name))
, m_bitmap(bitmap)
, m_bitmap(move(bitmap))
{
}