diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-02-16 12:22:00 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-02-16 12:22:52 +0100 |
commit | 09aaa41e623a0703a54d16ed2f12b3448efe83a3 (patch) | |
tree | 3184adfa44f0b62e9ccc96c03cda6ade3cac4911 /SharedGraphics | |
parent | 4ea28bf0a57ab88d3c5e3aec81c28de53c6ebc5b (diff) | |
download | serenity-09aaa41e623a0703a54d16ed2f12b3448efe83a3.zip |
SharedGraphics: Rework GraphicsBitmap::create_kernel_only() into create().
And just use mmap() to allocate the pixels.
Diffstat (limited to 'SharedGraphics')
-rw-r--r-- | SharedGraphics/GraphicsBitmap.cpp | 31 | ||||
-rw-r--r-- | SharedGraphics/GraphicsBitmap.h | 8 |
2 files changed, 17 insertions, 22 deletions
diff --git a/SharedGraphics/GraphicsBitmap.cpp b/SharedGraphics/GraphicsBitmap.cpp index 4803ecfcb1..19cdd93f56 100644 --- a/SharedGraphics/GraphicsBitmap.cpp +++ b/SharedGraphics/GraphicsBitmap.cpp @@ -14,8 +14,7 @@ #include <stdio.h> #endif -#ifdef KERNEL -RetainPtr<GraphicsBitmap> GraphicsBitmap::create_kernel_only(const Size& size) +RetainPtr<GraphicsBitmap> GraphicsBitmap::create(const Size& size) { return adopt(*new GraphicsBitmap(size)); } @@ -24,16 +23,19 @@ GraphicsBitmap::GraphicsBitmap(const Size& size) : m_size(size) , m_pitch(size.width() * sizeof(RGBA32)) { - InterruptDisabler disabler; - size_t size_in_bytes = size.width() * size.height() * sizeof(RGBA32); - auto vmo = VMObject::create_anonymous(size_in_bytes); - auto& server = WSMessageLoop::the().server_process(); - m_server_region = server.allocate_region_with_vmo(LinearAddress(), size_in_bytes, move(vmo), 0, "GraphicsBitmap (server)", true, false); - m_server_region->set_shared(true); - m_server_region->set_is_bitmap(true); - m_data = (RGBA32*)m_server_region->laddr().as_ptr(); -} +#ifdef KERNEL + Syscall::SC_mmap_params params; + memset(¶ms, 0, sizeof(params)); + params.fd = 0; + params.prot = PROT_READ | PROT_WRITE; + params.flags = MAP_ANONYMOUS | MAP_PRIVATE; + params.size = size.area() * sizeof(RGBA32); + params.offset = 0; + m_data = (RGBA32*)current->sys$mmap(¶ms); + ASSERT(m_data && m_data != (void*)-1); + m_mmaped = true; #endif +} RetainPtr<GraphicsBitmap> GraphicsBitmap::create_wrapper(const Size& size, RGBA32* data) { @@ -115,15 +117,14 @@ GraphicsBitmap::GraphicsBitmap(int shared_buffer_id, const Size& size, RGBA32* d GraphicsBitmap::~GraphicsBitmap() { + if (m_mmaped) { #ifdef KERNEL - if (m_server_region) - WSMessageLoop::the().server_process().deallocate_region(*m_server_region); + int rc = current->sys$munmap(m_data, m_size.area() * 4); #else - if (m_mmaped) { int rc = munmap(m_data, m_size.area() * 4); +#endif ASSERT(rc == 0); } -#endif if (m_shared_buffer_id != -1) { int rc; #ifdef KERNEL diff --git a/SharedGraphics/GraphicsBitmap.h b/SharedGraphics/GraphicsBitmap.h index 28d2111186..ec36b53d0f 100644 --- a/SharedGraphics/GraphicsBitmap.h +++ b/SharedGraphics/GraphicsBitmap.h @@ -11,9 +11,7 @@ class Region; class GraphicsBitmap : public Retainable<GraphicsBitmap> { public: -#ifdef KERNEL - static RetainPtr<GraphicsBitmap> create_kernel_only(const Size&); -#endif + static RetainPtr<GraphicsBitmap> create(const Size&); static RetainPtr<GraphicsBitmap> create_wrapper(const Size&, RGBA32*); static RetainPtr<GraphicsBitmap> load_from_file(const String& path, const Size&); static RetainPtr<GraphicsBitmap> create_with_shared_buffer(int shared_buffer_id, const Size&, RGBA32* buffer = nullptr); @@ -44,11 +42,7 @@ private: Size m_size; RGBA32* m_data { nullptr }; size_t m_pitch { 0 }; - -#ifdef USERLAND bool m_mmaped { false }; -#endif - int m_shared_buffer_id { -1 }; #ifdef KERNEL |