diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-03-08 12:22:55 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-03-08 12:24:05 +0100 |
commit | eda086699287dcd8f6f858a5d3c0a43009dd9e59 (patch) | |
tree | c3a125d429f5602490d9fa140610f10d36d2ab2b /SharedGraphics/GraphicsBitmap.cpp | |
parent | 0b5d5fc3c955baf3029286f2410005d652f9dc2d (diff) | |
download | serenity-eda086699287dcd8f6f858a5d3c0a43009dd9e59.zip |
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.
Diffstat (limited to 'SharedGraphics/GraphicsBitmap.cpp')
-rw-r--r-- | SharedGraphics/GraphicsBitmap.cpp | 20 |
1 files changed, 5 insertions, 15 deletions
diff --git a/SharedGraphics/GraphicsBitmap.cpp b/SharedGraphics/GraphicsBitmap.cpp index 035f17e9a4..1df228062d 100644 --- a/SharedGraphics/GraphicsBitmap.cpp +++ b/SharedGraphics/GraphicsBitmap.cpp @@ -58,23 +58,17 @@ GraphicsBitmap::GraphicsBitmap(Format format, const Size& size, RGBA32* data) { } -RetainPtr<GraphicsBitmap> GraphicsBitmap::create_with_shared_buffer(Format format, int shared_buffer_id, const Size& size, RGBA32* data) +RetainPtr<GraphicsBitmap> GraphicsBitmap::create_with_shared_buffer(Format format, Retained<SharedBuffer>&& shared_buffer, const Size& size) { - if (!data) { - void* shared_buffer = get_shared_buffer(shared_buffer_id); - if (!shared_buffer || shared_buffer == (void*)-1) - return nullptr; - data = (RGBA32*)shared_buffer; - } - return adopt(*new GraphicsBitmap(format, shared_buffer_id, size, data)); + return adopt(*new GraphicsBitmap(format, move(shared_buffer), size)); } -GraphicsBitmap::GraphicsBitmap(Format format, int shared_buffer_id, const Size& size, RGBA32* data) +GraphicsBitmap::GraphicsBitmap(Format format, Retained<SharedBuffer>&& shared_buffer, const Size& size) : m_size(size) - , m_data(data) + , m_data((RGBA32*)shared_buffer->data()) , m_pitch(size.width() * sizeof(RGBA32)) , m_format(format) - , m_shared_buffer_id(shared_buffer_id) + , m_shared_buffer(move(shared_buffer)) { } @@ -84,10 +78,6 @@ GraphicsBitmap::~GraphicsBitmap() int rc = munmap(m_data, m_size.area() * 4); ASSERT(rc == 0); } - if (m_shared_buffer_id != -1) { - int rc = release_shared_buffer(m_shared_buffer_id); - ASSERT(rc == 0); - } m_data = nullptr; } |