mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 05:37:43 +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();
|
||||
}
|
||||
|
||||
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())
|
||||
return *this;
|
||||
auto buffer_or_error = Core::AnonymousBuffer::create_with_size(round_up_to_power_of_two(size_in_bytes(), PAGE_SIZE));
|
||||
if (buffer_or_error.is_error())
|
||||
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();
|
||||
return NonnullRefPtr { *this };
|
||||
auto buffer = TRY(Core::AnonymousBuffer::create_with_size(round_up_to_power_of_two(size_in_bytes(), PAGE_SIZE)));
|
||||
auto bitmap = TRY(Bitmap::try_create_with_anonymous_buffer(m_format, move(buffer), size(), scale(), palette_to_vector()));
|
||||
memcpy(bitmap->scanline(0), scanline(0), size_in_bytes());
|
||||
return bitmap;
|
||||
}
|
||||
|
@ -612,12 +607,12 @@ void Bitmap::set_volatile()
|
|||
return true;
|
||||
}
|
||||
|
||||
ShareableBitmap Bitmap::to_shareable_bitmap() const
|
||||
Gfx::ShareableBitmap Bitmap::to_shareable_bitmap() const
|
||||
{
|
||||
auto bitmap = to_bitmap_backed_by_anonymous_buffer();
|
||||
if (!bitmap)
|
||||
auto bitmap_or_error = to_bitmap_backed_by_anonymous_buffer();
|
||||
if (bitmap_or_error.is_error())
|
||||
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)
|
||||
|
|
|
@ -116,7 +116,7 @@ public:
|
|||
ErrorOr<NonnullRefPtr<Gfx::Bitmap>> scaled(int sx, int sy) const;
|
||||
ErrorOr<NonnullRefPtr<Gfx::Bitmap>> scaled(float sx, float sy) 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]] ShareableBitmap to_shareable_bitmap() const;
|
||||
|
|
|
@ -13,11 +13,6 @@
|
|||
|
||||
namespace Gfx {
|
||||
|
||||
ShareableBitmap::ShareableBitmap(const Bitmap& bitmap)
|
||||
: m_bitmap(bitmap.to_bitmap_backed_by_anonymous_buffer())
|
||||
{
|
||||
}
|
||||
|
||||
ShareableBitmap::ShareableBitmap(NonnullRefPtr<Bitmap> bitmap, Tag)
|
||||
: m_bitmap(move(bitmap))
|
||||
{
|
||||
|
|
|
@ -15,7 +15,6 @@ namespace Gfx {
|
|||
class ShareableBitmap {
|
||||
public:
|
||||
ShareableBitmap() { }
|
||||
explicit ShareableBitmap(const Gfx::Bitmap&);
|
||||
|
||||
enum Tag { ConstructWithKnownGoodBitmap };
|
||||
ShareableBitmap(NonnullRefPtr<Gfx::Bitmap>, Tag);
|
||||
|
@ -26,6 +25,8 @@ public:
|
|||
Bitmap* bitmap() { return m_bitmap; }
|
||||
|
||||
private:
|
||||
friend class Bitmap;
|
||||
|
||||
RefPtr<Bitmap> m_bitmap;
|
||||
};
|
||||
|
||||
|
|
|
@ -119,8 +119,8 @@ void InProcessWebView::page_did_request_image_context_menu(const Gfx::IntPoint&
|
|||
return;
|
||||
Gfx::ShareableBitmap shareable_bitmap;
|
||||
if (bitmap)
|
||||
shareable_bitmap = Gfx::ShareableBitmap(*bitmap);
|
||||
on_image_context_menu_request(url, screen_relative_rect().location().translated(to_widget_position(content_position)), shareable_bitmap);
|
||||
shareable_bitmap = bitmap->to_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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue