mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 23:57:34 +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:
parent
c7f7c1f7f0
commit
9038bc675f
2 changed files with 16 additions and 20 deletions
|
@ -18,15 +18,19 @@ RefPtr<Layer> Layer::try_create_with_size(Image& image, Gfx::IntSize const& size
|
||||||
if (size.width() > 16384 || size.height() > 16384)
|
if (size.width() > 16384 || size.height() > 16384)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
return adopt_ref(*new Layer(image, size, move(name)));
|
auto bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, size);
|
||||||
}
|
if (!bitmap)
|
||||||
|
|
||||||
RefPtr<Layer> Layer::try_create_with_bitmap(Image& image, Gfx::Bitmap const& bitmap, String name)
|
|
||||||
{
|
|
||||||
if (bitmap.size().is_empty())
|
|
||||||
return nullptr;
|
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 nullptr;
|
||||||
|
|
||||||
return adopt_ref(*new Layer(image, bitmap, move(name)));
|
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;
|
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_image(image)
|
||||||
, m_name(move(name))
|
, m_name(move(name))
|
||||||
{
|
, m_bitmap(move(bitmap))
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ class Layer
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static RefPtr<Layer> try_create_with_size(Image&, Gfx::IntSize const&, String name);
|
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&);
|
static RefPtr<Layer> try_create_snapshot(Image&, Layer const&);
|
||||||
|
|
||||||
~Layer() { }
|
~Layer() { }
|
||||||
|
@ -57,14 +57,13 @@ public:
|
||||||
void set_opacity_percent(int);
|
void set_opacity_percent(int);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Layer(Image&, Gfx::IntSize const&, String name);
|
Layer(Image&, NonnullRefPtr<Gfx::Bitmap>, String name);
|
||||||
Layer(Image&, Gfx::Bitmap const&, String name);
|
|
||||||
|
|
||||||
Image& m_image;
|
Image& m_image;
|
||||||
|
|
||||||
String m_name;
|
String m_name;
|
||||||
Gfx::IntPoint m_location;
|
Gfx::IntPoint m_location;
|
||||||
RefPtr<Gfx::Bitmap> m_bitmap;
|
NonnullRefPtr<Gfx::Bitmap> m_bitmap;
|
||||||
|
|
||||||
bool m_selected { false };
|
bool m_selected { false };
|
||||||
bool m_visible { true };
|
bool m_visible { true };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue