mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 00:32:45 +00:00 
			
		
		
		
	SharedGraphics: Rework GraphicsBitmap::create_kernel_only() into create().
And just use mmap() to allocate the pixels.
This commit is contained in:
		
							parent
							
								
									4ea28bf0a5
								
							
						
					
					
						commit
						09aaa41e62
					
				
					 3 changed files with 19 additions and 24 deletions
				
			
		|  | @ -14,8 +14,7 @@ | ||||||
| #include <stdio.h> | #include <stdio.h> | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| #ifdef KERNEL | RetainPtr<GraphicsBitmap> GraphicsBitmap::create(const Size& size) | ||||||
| RetainPtr<GraphicsBitmap> GraphicsBitmap::create_kernel_only(const Size& size) |  | ||||||
| { | { | ||||||
|     return adopt(*new GraphicsBitmap(size)); |     return adopt(*new GraphicsBitmap(size)); | ||||||
| } | } | ||||||
|  | @ -24,16 +23,19 @@ GraphicsBitmap::GraphicsBitmap(const Size& size) | ||||||
|     : m_size(size) |     : m_size(size) | ||||||
|     , m_pitch(size.width() * sizeof(RGBA32)) |     , m_pitch(size.width() * sizeof(RGBA32)) | ||||||
| { | { | ||||||
|     InterruptDisabler disabler; | #ifdef KERNEL | ||||||
|     size_t size_in_bytes = size.width() * size.height() * sizeof(RGBA32); |     Syscall::SC_mmap_params params; | ||||||
|     auto vmo = VMObject::create_anonymous(size_in_bytes); |     memset(¶ms, 0, sizeof(params)); | ||||||
|     auto& server = WSMessageLoop::the().server_process(); |     params.fd = 0; | ||||||
|     m_server_region = server.allocate_region_with_vmo(LinearAddress(), size_in_bytes, move(vmo), 0, "GraphicsBitmap (server)", true, false); |     params.prot = PROT_READ | PROT_WRITE; | ||||||
|     m_server_region->set_shared(true); |     params.flags = MAP_ANONYMOUS | MAP_PRIVATE; | ||||||
|     m_server_region->set_is_bitmap(true); |     params.size = size.area() * sizeof(RGBA32); | ||||||
|     m_data = (RGBA32*)m_server_region->laddr().as_ptr(); |     params.offset = 0; | ||||||
| } |     m_data = (RGBA32*)current->sys$mmap(¶ms); | ||||||
|  |     ASSERT(m_data && m_data != (void*)-1); | ||||||
|  |     m_mmaped = true; | ||||||
| #endif | #endif | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| RetainPtr<GraphicsBitmap> GraphicsBitmap::create_wrapper(const Size& size, RGBA32* data) | 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() | GraphicsBitmap::~GraphicsBitmap() | ||||||
| { | { | ||||||
| #ifdef KERNEL |  | ||||||
|     if (m_server_region) |  | ||||||
|         WSMessageLoop::the().server_process().deallocate_region(*m_server_region); |  | ||||||
| #else |  | ||||||
|     if (m_mmaped) { |     if (m_mmaped) { | ||||||
|  | #ifdef KERNEL | ||||||
|  |         int rc = current->sys$munmap(m_data, m_size.area() * 4); | ||||||
|  | #else | ||||||
|         int rc = munmap(m_data, m_size.area() * 4); |         int rc = munmap(m_data, m_size.area() * 4); | ||||||
|  | #endif | ||||||
|         ASSERT(rc == 0); |         ASSERT(rc == 0); | ||||||
|     } |     } | ||||||
| #endif |  | ||||||
|     if (m_shared_buffer_id != -1) { |     if (m_shared_buffer_id != -1) { | ||||||
|         int rc; |         int rc; | ||||||
| #ifdef KERNEL | #ifdef KERNEL | ||||||
|  |  | ||||||
|  | @ -11,9 +11,7 @@ class Region; | ||||||
| 
 | 
 | ||||||
| class GraphicsBitmap : public Retainable<GraphicsBitmap> { | class GraphicsBitmap : public Retainable<GraphicsBitmap> { | ||||||
| public: | public: | ||||||
| #ifdef KERNEL |     static RetainPtr<GraphicsBitmap> create(const Size&); | ||||||
|     static RetainPtr<GraphicsBitmap> create_kernel_only(const Size&); |  | ||||||
| #endif |  | ||||||
|     static RetainPtr<GraphicsBitmap> create_wrapper(const Size&, RGBA32*); |     static RetainPtr<GraphicsBitmap> create_wrapper(const Size&, RGBA32*); | ||||||
|     static RetainPtr<GraphicsBitmap> load_from_file(const String& path, const Size&); |     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); |     static RetainPtr<GraphicsBitmap> create_with_shared_buffer(int shared_buffer_id, const Size&, RGBA32* buffer = nullptr); | ||||||
|  | @ -44,11 +42,7 @@ private: | ||||||
|     Size m_size; |     Size m_size; | ||||||
|     RGBA32* m_data { nullptr }; |     RGBA32* m_data { nullptr }; | ||||||
|     size_t m_pitch { 0 }; |     size_t m_pitch { 0 }; | ||||||
| 
 |  | ||||||
| #ifdef USERLAND |  | ||||||
|     bool m_mmaped { false }; |     bool m_mmaped { false }; | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
|     int m_shared_buffer_id { -1 }; |     int m_shared_buffer_id { -1 }; | ||||||
| 
 | 
 | ||||||
| #ifdef KERNEL | #ifdef KERNEL | ||||||
|  |  | ||||||
|  | @ -45,7 +45,7 @@ void WSWindow::set_rect(const Rect& rect) | ||||||
|     m_rect = rect; |     m_rect = rect; | ||||||
|     if (!m_backing || old_rect.size() != rect.size()) { |     if (!m_backing || old_rect.size() != rect.size()) { | ||||||
|         if (m_menu) |         if (m_menu) | ||||||
|             m_backing = GraphicsBitmap::create_kernel_only(m_rect.size()); |             m_backing = GraphicsBitmap::create(m_rect.size()); | ||||||
|         else if (client) |         else if (client) | ||||||
|             m_backing = client->create_bitmap(m_rect.size()); |             m_backing = client->create_bitmap(m_rect.size()); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling