mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-07 17:15:26 +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:
@@ -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))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ class Layer
|
||||
|
||||
public:
|
||||
static RefPtr<Layer> try_create_with_size(Image&, Gfx::IntSize const&, String name);
|
||||
static RefPtr<Layer> try_create_with_bitmap(Image&, Gfx::Bitmap const&, String name);
|
||||
static RefPtr<Layer> try_create_with_bitmap(Image&, NonnullRefPtr<Gfx::Bitmap>, String name);
|
||||
static RefPtr<Layer> try_create_snapshot(Image&, Layer const&);
|
||||
|
||||
~Layer() { }
|
||||
@@ -57,14 +57,13 @@ public:
|
||||
void set_opacity_percent(int);
|
||||
|
||||
private:
|
||||
Layer(Image&, Gfx::IntSize const&, String name);
|
||||
Layer(Image&, Gfx::Bitmap const&, String name);
|
||||
Layer(Image&, NonnullRefPtr<Gfx::Bitmap>, String name);
|
||||
|
||||
Image& m_image;
|
||||
|
||||
String m_name;
|
||||
Gfx::IntPoint m_location;
|
||||
RefPtr<Gfx::Bitmap> m_bitmap;
|
||||
NonnullRefPtr<Gfx::Bitmap> m_bitmap;
|
||||
|
||||
bool m_selected { false };
|
||||
bool m_visible { true };
|
||||
|
||||
Reference in New Issue
Block a user