mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 01:47:36 +00:00
LibGfx: Use ErrorOr<T> for Bitmap infrastructure used by ShareableBitmap
This also allows us to get rid of the ShareableBitmap(Bitmap) constructor which was easy to misuse. Everyone now uses Bitmap's to_shareable_bitmap() helper instead.
This commit is contained in:
parent
8262bbf624
commit
09cba7c780
5 changed files with 13 additions and 22 deletions
|
@ -533,17 +533,12 @@ ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::cropped(Gfx::IntRect crop) const
|
||||||
return new_bitmap.release_nonnull();
|
return new_bitmap.release_nonnull();
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<Bitmap> Bitmap::to_bitmap_backed_by_anonymous_buffer() const
|
ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::to_bitmap_backed_by_anonymous_buffer() const
|
||||||
{
|
{
|
||||||
if (m_buffer.is_valid())
|
if (m_buffer.is_valid())
|
||||||
return *this;
|
return NonnullRefPtr { *this };
|
||||||
auto buffer_or_error = Core::AnonymousBuffer::create_with_size(round_up_to_power_of_two(size_in_bytes(), PAGE_SIZE));
|
auto buffer = TRY(Core::AnonymousBuffer::create_with_size(round_up_to_power_of_two(size_in_bytes(), PAGE_SIZE)));
|
||||||
if (buffer_or_error.is_error())
|
auto bitmap = TRY(Bitmap::try_create_with_anonymous_buffer(m_format, move(buffer), size(), scale(), palette_to_vector()));
|
||||||
return nullptr;
|
|
||||||
auto bitmap_or_error = Bitmap::try_create_with_anonymous_buffer(m_format, buffer_or_error.release_value(), size(), scale(), palette_to_vector());
|
|
||||||
if (bitmap_or_error.is_error())
|
|
||||||
return nullptr;
|
|
||||||
auto bitmap = bitmap_or_error.release_value();
|
|
||||||
memcpy(bitmap->scanline(0), scanline(0), size_in_bytes());
|
memcpy(bitmap->scanline(0), scanline(0), size_in_bytes());
|
||||||
return bitmap;
|
return bitmap;
|
||||||
}
|
}
|
||||||
|
@ -612,12 +607,12 @@ void Bitmap::set_volatile()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ShareableBitmap Bitmap::to_shareable_bitmap() const
|
Gfx::ShareableBitmap Bitmap::to_shareable_bitmap() const
|
||||||
{
|
{
|
||||||
auto bitmap = to_bitmap_backed_by_anonymous_buffer();
|
auto bitmap_or_error = to_bitmap_backed_by_anonymous_buffer();
|
||||||
if (!bitmap)
|
if (bitmap_or_error.is_error())
|
||||||
return {};
|
return {};
|
||||||
return ShareableBitmap(*bitmap);
|
return Gfx::ShareableBitmap { bitmap_or_error.release_value_but_fixme_should_propagate_errors(), Gfx::ShareableBitmap::ConstructWithKnownGoodBitmap };
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<BackingStore> Bitmap::allocate_backing_store(BitmapFormat format, IntSize const& size, int scale_factor)
|
ErrorOr<BackingStore> Bitmap::allocate_backing_store(BitmapFormat format, IntSize const& size, int scale_factor)
|
||||||
|
|
|
@ -116,7 +116,7 @@ public:
|
||||||
ErrorOr<NonnullRefPtr<Gfx::Bitmap>> scaled(int sx, int sy) const;
|
ErrorOr<NonnullRefPtr<Gfx::Bitmap>> scaled(int sx, int sy) const;
|
||||||
ErrorOr<NonnullRefPtr<Gfx::Bitmap>> scaled(float sx, float sy) const;
|
ErrorOr<NonnullRefPtr<Gfx::Bitmap>> scaled(float sx, float sy) const;
|
||||||
ErrorOr<NonnullRefPtr<Gfx::Bitmap>> cropped(Gfx::IntRect) const;
|
ErrorOr<NonnullRefPtr<Gfx::Bitmap>> cropped(Gfx::IntRect) const;
|
||||||
[[nodiscard]] RefPtr<Bitmap> to_bitmap_backed_by_anonymous_buffer() const;
|
ErrorOr<NonnullRefPtr<Gfx::Bitmap>> to_bitmap_backed_by_anonymous_buffer() const;
|
||||||
[[nodiscard]] ByteBuffer serialize_to_byte_buffer() const;
|
[[nodiscard]] ByteBuffer serialize_to_byte_buffer() const;
|
||||||
|
|
||||||
[[nodiscard]] ShareableBitmap to_shareable_bitmap() const;
|
[[nodiscard]] ShareableBitmap to_shareable_bitmap() const;
|
||||||
|
|
|
@ -13,11 +13,6 @@
|
||||||
|
|
||||||
namespace Gfx {
|
namespace Gfx {
|
||||||
|
|
||||||
ShareableBitmap::ShareableBitmap(const Bitmap& bitmap)
|
|
||||||
: m_bitmap(bitmap.to_bitmap_backed_by_anonymous_buffer())
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
ShareableBitmap::ShareableBitmap(NonnullRefPtr<Bitmap> bitmap, Tag)
|
ShareableBitmap::ShareableBitmap(NonnullRefPtr<Bitmap> bitmap, Tag)
|
||||||
: m_bitmap(move(bitmap))
|
: m_bitmap(move(bitmap))
|
||||||
{
|
{
|
||||||
|
|
|
@ -15,7 +15,6 @@ namespace Gfx {
|
||||||
class ShareableBitmap {
|
class ShareableBitmap {
|
||||||
public:
|
public:
|
||||||
ShareableBitmap() { }
|
ShareableBitmap() { }
|
||||||
explicit ShareableBitmap(const Gfx::Bitmap&);
|
|
||||||
|
|
||||||
enum Tag { ConstructWithKnownGoodBitmap };
|
enum Tag { ConstructWithKnownGoodBitmap };
|
||||||
ShareableBitmap(NonnullRefPtr<Gfx::Bitmap>, Tag);
|
ShareableBitmap(NonnullRefPtr<Gfx::Bitmap>, Tag);
|
||||||
|
@ -26,6 +25,8 @@ public:
|
||||||
Bitmap* bitmap() { return m_bitmap; }
|
Bitmap* bitmap() { return m_bitmap; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
friend class Bitmap;
|
||||||
|
|
||||||
RefPtr<Bitmap> m_bitmap;
|
RefPtr<Bitmap> m_bitmap;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -119,8 +119,8 @@ void InProcessWebView::page_did_request_image_context_menu(const Gfx::IntPoint&
|
||||||
return;
|
return;
|
||||||
Gfx::ShareableBitmap shareable_bitmap;
|
Gfx::ShareableBitmap shareable_bitmap;
|
||||||
if (bitmap)
|
if (bitmap)
|
||||||
shareable_bitmap = Gfx::ShareableBitmap(*bitmap);
|
shareable_bitmap = bitmap->to_shareable_bitmap();
|
||||||
on_image_context_menu_request(url, screen_relative_rect().location().translated(to_widget_position(content_position)), shareable_bitmap);
|
on_image_context_menu_request(url, screen_relative_rect().location().translated(to_widget_position(content_position)), move(shareable_bitmap));
|
||||||
}
|
}
|
||||||
|
|
||||||
void InProcessWebView::page_did_click_link(const AK::URL& url, const String& target, unsigned modifiers)
|
void InProcessWebView::page_did_click_link(const AK::URL& url, const String& target, unsigned modifiers)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue