mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-06 02:55:49 +03:00
LibDraw: Add GraphicsBitmap::to_shareable_bitmap()
This function returns the bitmap itself if it's already backed by a SharedBuffer object, otherwise it creates a shareable copy of itself and returns that.
This commit is contained in:
parent
a7f414bba7
commit
183ee5847c
Notes:
sideshowbarker
2024-07-19 10:55:19 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/183ee5847c7
@ -77,6 +77,16 @@ GraphicsBitmap::GraphicsBitmap(Format format, NonnullRefPtr<SharedBuffer>&& shar
|
||||
ASSERT(format != Format::Indexed8);
|
||||
}
|
||||
|
||||
NonnullRefPtr<GraphicsBitmap> GraphicsBitmap::to_shareable_bitmap() const
|
||||
{
|
||||
if (m_shared_buffer)
|
||||
return *this;
|
||||
auto buffer = SharedBuffer::create_with_size(size_in_bytes());
|
||||
auto bitmap = GraphicsBitmap::create_with_shared_buffer(m_format, *buffer, m_size);
|
||||
memcpy(buffer->data(), scanline(0), size_in_bytes());
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
GraphicsBitmap::~GraphicsBitmap()
|
||||
{
|
||||
if (m_needs_munmap) {
|
||||
|
@ -3,10 +3,10 @@
|
||||
#include "Color.h"
|
||||
#include "Rect.h"
|
||||
#include "Size.h"
|
||||
#include <AK/String.h>
|
||||
#include <AK/MappedFile.h>
|
||||
#include <AK/RefCounted.h>
|
||||
#include <AK/RefPtr.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <SharedBuffer.h>
|
||||
|
||||
@ -24,6 +24,9 @@ public:
|
||||
static RefPtr<GraphicsBitmap> load_from_file(const StringView& path);
|
||||
static RefPtr<GraphicsBitmap> load_from_file(Format, const StringView& path, const Size&);
|
||||
static NonnullRefPtr<GraphicsBitmap> create_with_shared_buffer(Format, NonnullRefPtr<SharedBuffer>&&, const Size&);
|
||||
|
||||
NonnullRefPtr<GraphicsBitmap> to_shareable_bitmap() const;
|
||||
|
||||
~GraphicsBitmap();
|
||||
|
||||
RGBA32* scanline(int y);
|
||||
@ -39,6 +42,9 @@ public:
|
||||
size_t pitch() const { return m_pitch; }
|
||||
int shared_buffer_id() const { return m_shared_buffer ? m_shared_buffer->shared_buffer_id() : -1; }
|
||||
|
||||
SharedBuffer* shared_buffer() { return m_shared_buffer.ptr(); }
|
||||
const SharedBuffer* shared_buffer() const { return m_shared_buffer.ptr(); }
|
||||
|
||||
unsigned bpp() const
|
||||
{
|
||||
switch (m_format) {
|
||||
@ -157,7 +163,7 @@ inline Color GraphicsBitmap::get_pixel(int x, int y) const
|
||||
return get_pixel<Format::Indexed8>(x, y);
|
||||
default:
|
||||
ASSERT_NOT_REACHED();
|
||||
return { };
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user