mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:18:11 +00:00
Add a C++ helper class for working with shared buffers.
This is a bit more comfortable than passing the shared buffer ID manually everywhere and keeping track of size etc.
This commit is contained in:
parent
0b5d5fc3c9
commit
eda0866992
14 changed files with 186 additions and 46 deletions
|
@ -6,6 +6,7 @@
|
|||
#include <AK/Retainable.h>
|
||||
#include <AK/RetainPtr.h>
|
||||
#include <AK/AKString.h>
|
||||
#include <SharedBuffer.h>
|
||||
|
||||
class GraphicsBitmap : public Retainable<GraphicsBitmap> {
|
||||
public:
|
||||
|
@ -14,7 +15,7 @@ public:
|
|||
static Retained<GraphicsBitmap> create(Format, const Size&);
|
||||
static Retained<GraphicsBitmap> create_wrapper(Format, const Size&, RGBA32*);
|
||||
static RetainPtr<GraphicsBitmap> load_from_file(Format, const String& path, const Size&);
|
||||
static RetainPtr<GraphicsBitmap> create_with_shared_buffer(Format, int shared_buffer_id, const Size&, RGBA32* buffer = nullptr);
|
||||
static RetainPtr<GraphicsBitmap> create_with_shared_buffer(Format, Retained<SharedBuffer>&&, const Size&);
|
||||
~GraphicsBitmap();
|
||||
|
||||
RGBA32* scanline(int y);
|
||||
|
@ -25,21 +26,21 @@ public:
|
|||
int width() const { return m_size.width(); }
|
||||
int height() const { return m_size.height(); }
|
||||
size_t pitch() const { return m_pitch; }
|
||||
int shared_buffer_id() const { return m_shared_buffer_id; }
|
||||
int shared_buffer_id() const { return m_shared_buffer ? m_shared_buffer->shared_buffer_id() : -1; }
|
||||
|
||||
bool has_alpha_channel() const { return m_format == Format::RGBA32; }
|
||||
|
||||
private:
|
||||
GraphicsBitmap(Format, const Size&);
|
||||
GraphicsBitmap(Format, const Size&, RGBA32*);
|
||||
GraphicsBitmap(Format, int shared_buffer_id, const Size&, RGBA32*);
|
||||
GraphicsBitmap(Format, Retained<SharedBuffer>&&, const Size&);
|
||||
|
||||
Size m_size;
|
||||
RGBA32* m_data { nullptr };
|
||||
size_t m_pitch { 0 };
|
||||
Format m_format { Format::Invalid };
|
||||
bool m_mmaped { false };
|
||||
int m_shared_buffer_id { -1 };
|
||||
RetainPtr<SharedBuffer> m_shared_buffer;
|
||||
};
|
||||
|
||||
inline RGBA32* GraphicsBitmap::scanline(int y)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue