mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 15:12:45 +00:00 
			
		
		
		
	Ladybird+LibWebView: Move most of paint handling to LibWebView
Storing the backup bitmap is the same across Browser and Ladybird. Just peform that work in LibWebView, and handle only the implementation- specific nuances within the browsers.
This commit is contained in:
		
							parent
							
								
									15da77f4c4
								
							
						
					
					
						commit
						ea7e1b5f53
					
				
					 10 changed files with 34 additions and 63 deletions
				
			
		|  | @ -112,26 +112,6 @@ void WebViewBridge::notify_server_did_layout(Badge<WebView::WebContentClient>, G | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void WebViewBridge::notify_server_did_paint(Badge<WebView::WebContentClient>, i32 bitmap_id, Gfx::IntSize size) |  | ||||||
| { |  | ||||||
|     if (m_client_state.back_bitmap.id == bitmap_id) { |  | ||||||
|         m_client_state.has_usable_bitmap = true; |  | ||||||
|         m_client_state.back_bitmap.pending_paints--; |  | ||||||
|         m_client_state.back_bitmap.last_painted_size = size; |  | ||||||
|         swap(m_client_state.back_bitmap, m_client_state.front_bitmap); |  | ||||||
|         // We don't need the backup bitmap anymore, so drop it.
 |  | ||||||
|         m_backup_bitmap = nullptr; |  | ||||||
| 
 |  | ||||||
|         if (on_ready_to_paint) |  | ||||||
|             on_ready_to_paint(); |  | ||||||
| 
 |  | ||||||
|         if (m_client_state.got_repaint_requests_while_painting) { |  | ||||||
|             m_client_state.got_repaint_requests_while_painting = false; |  | ||||||
|             request_repaint(); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void WebViewBridge::notify_server_did_invalidate_content_rect(Badge<WebView::WebContentClient>, Gfx::IntRect const&) | void WebViewBridge::notify_server_did_invalidate_content_rect(Badge<WebView::WebContentClient>, Gfx::IntRect const&) | ||||||
| { | { | ||||||
|     request_repaint(); |     request_repaint(); | ||||||
|  |  | ||||||
|  | @ -50,7 +50,6 @@ public: | ||||||
|     Optional<Paintable> paintable(); |     Optional<Paintable> paintable(); | ||||||
| 
 | 
 | ||||||
|     Function<void(Gfx::IntSize)> on_layout; |     Function<void(Gfx::IntSize)> on_layout; | ||||||
|     Function<void()> on_ready_to_paint; |  | ||||||
| 
 | 
 | ||||||
|     Function<void(Gfx::IntPoint)> on_scroll; |     Function<void(Gfx::IntPoint)> on_scroll; | ||||||
| 
 | 
 | ||||||
|  | @ -63,7 +62,6 @@ private: | ||||||
|     WebViewBridge(Vector<Gfx::IntRect> screen_rects, float device_pixel_ratio, Optional<StringView> webdriver_content_ipc_path); |     WebViewBridge(Vector<Gfx::IntRect> screen_rects, float device_pixel_ratio, Optional<StringView> webdriver_content_ipc_path); | ||||||
| 
 | 
 | ||||||
|     virtual void notify_server_did_layout(Badge<WebView::WebContentClient>, Gfx::IntSize content_size) override; |     virtual void notify_server_did_layout(Badge<WebView::WebContentClient>, Gfx::IntSize content_size) override; | ||||||
|     virtual void notify_server_did_paint(Badge<WebView::WebContentClient>, i32 bitmap_id, Gfx::IntSize) override; |  | ||||||
|     virtual void notify_server_did_invalidate_content_rect(Badge<WebView::WebContentClient>, Gfx::IntRect const&) override; |     virtual void notify_server_did_invalidate_content_rect(Badge<WebView::WebContentClient>, Gfx::IntRect const&) override; | ||||||
|     virtual void notify_server_did_change_selection(Badge<WebView::WebContentClient>) override; |     virtual void notify_server_did_change_selection(Badge<WebView::WebContentClient>) override; | ||||||
|     virtual void notify_server_did_request_cursor_change(Badge<WebView::WebContentClient>, Gfx::StandardCursor cursor) override; |     virtual void notify_server_did_request_cursor_change(Badge<WebView::WebContentClient>, Gfx::StandardCursor cursor) override; | ||||||
|  |  | ||||||
|  | @ -75,6 +75,10 @@ WebContentView::WebContentView(StringView webdriver_content_ipc_path, WebView::E | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     create_client(enable_callgrind_profiling); |     create_client(enable_callgrind_profiling); | ||||||
|  | 
 | ||||||
|  |     on_ready_to_paint = [this]() { | ||||||
|  |         viewport()->update(); | ||||||
|  |     }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| WebContentView::~WebContentView() = default; | WebContentView::~WebContentView() = default; | ||||||
|  | @ -587,24 +591,6 @@ void WebContentView::create_client(WebView::EnableCallgrindProfiling enable_call | ||||||
|         client().async_connect_to_webdriver(m_webdriver_content_ipc_path); |         client().async_connect_to_webdriver(m_webdriver_content_ipc_path); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void WebContentView::notify_server_did_paint(Badge<WebContentClient>, i32 bitmap_id, Gfx::IntSize size) |  | ||||||
| { |  | ||||||
|     if (m_client_state.back_bitmap.id == bitmap_id) { |  | ||||||
|         m_client_state.has_usable_bitmap = true; |  | ||||||
|         m_client_state.back_bitmap.pending_paints--; |  | ||||||
|         m_client_state.back_bitmap.last_painted_size = size; |  | ||||||
|         swap(m_client_state.back_bitmap, m_client_state.front_bitmap); |  | ||||||
|         // We don't need the backup bitmap anymore, so drop it.
 |  | ||||||
|         m_backup_bitmap = nullptr; |  | ||||||
|         viewport()->update(); |  | ||||||
| 
 |  | ||||||
|         if (m_client_state.got_repaint_requests_while_painting) { |  | ||||||
|             m_client_state.got_repaint_requests_while_painting = false; |  | ||||||
|             request_repaint(); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void WebContentView::notify_server_did_invalidate_content_rect(Badge<WebContentClient>, [[maybe_unused]] Gfx::IntRect const& content_rect) | void WebContentView::notify_server_did_invalidate_content_rect(Badge<WebContentClient>, [[maybe_unused]] Gfx::IntRect const& content_rect) | ||||||
| { | { | ||||||
|     request_repaint(); |     request_repaint(); | ||||||
|  |  | ||||||
|  | @ -77,7 +77,6 @@ public: | ||||||
|     void update_palette(PaletteMode = PaletteMode::Default); |     void update_palette(PaletteMode = PaletteMode::Default); | ||||||
| 
 | 
 | ||||||
|     virtual void notify_server_did_layout(Badge<WebContentClient>, Gfx::IntSize content_size) override; |     virtual void notify_server_did_layout(Badge<WebContentClient>, Gfx::IntSize content_size) override; | ||||||
|     virtual void notify_server_did_paint(Badge<WebContentClient>, i32 bitmap_id, Gfx::IntSize) override; |  | ||||||
|     virtual void notify_server_did_invalidate_content_rect(Badge<WebContentClient>, Gfx::IntRect const&) override; |     virtual void notify_server_did_invalidate_content_rect(Badge<WebContentClient>, Gfx::IntRect const&) override; | ||||||
|     virtual void notify_server_did_change_selection(Badge<WebContentClient>) override; |     virtual void notify_server_did_change_selection(Badge<WebContentClient>) override; | ||||||
|     virtual void notify_server_did_request_cursor_change(Badge<WebContentClient>, Gfx::StandardCursor cursor) override; |     virtual void notify_server_did_request_cursor_change(Badge<WebContentClient>, Gfx::StandardCursor cursor) override; | ||||||
|  |  | ||||||
|  | @ -29,6 +29,10 @@ OutOfProcessWebView::OutOfProcessWebView() | ||||||
| 
 | 
 | ||||||
|     create_client(); |     create_client(); | ||||||
| 
 | 
 | ||||||
|  |     on_ready_to_paint = [this]() { | ||||||
|  |         update(); | ||||||
|  |     }; | ||||||
|  | 
 | ||||||
|     on_request_file = [this](auto const& path, auto request_id) { |     on_request_file = [this](auto const& path, auto request_id) { | ||||||
|         auto file = FileSystemAccessClient::Client::the().request_file_read_only_approved(window(), path); |         auto file = FileSystemAccessClient::Client::the().request_file_read_only_approved(window(), path); | ||||||
| 
 | 
 | ||||||
|  | @ -175,24 +179,6 @@ void OutOfProcessWebView::screen_rects_change_event(GUI::ScreenRectsChangeEvent& | ||||||
|     client().async_update_screen_rects(event.rects(), event.main_screen_index()); |     client().async_update_screen_rects(event.rects(), event.main_screen_index()); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void OutOfProcessWebView::notify_server_did_paint(Badge<WebContentClient>, i32 bitmap_id, Gfx::IntSize size) |  | ||||||
| { |  | ||||||
|     if (m_client_state.back_bitmap.id == bitmap_id) { |  | ||||||
|         m_client_state.has_usable_bitmap = true; |  | ||||||
|         m_client_state.back_bitmap.pending_paints--; |  | ||||||
|         m_client_state.back_bitmap.last_painted_size = size; |  | ||||||
|         swap(m_client_state.back_bitmap, m_client_state.front_bitmap); |  | ||||||
|         // We don't need the backup bitmap anymore, so drop it.
 |  | ||||||
|         m_backup_bitmap = nullptr; |  | ||||||
|         update(); |  | ||||||
| 
 |  | ||||||
|         if (m_client_state.got_repaint_requests_while_painting) { |  | ||||||
|             m_client_state.got_repaint_requests_while_painting = false; |  | ||||||
|             request_repaint(); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void OutOfProcessWebView::notify_server_did_invalidate_content_rect(Badge<WebContentClient>, [[maybe_unused]] Gfx::IntRect const& content_rect) | void OutOfProcessWebView::notify_server_did_invalidate_content_rect(Badge<WebContentClient>, [[maybe_unused]] Gfx::IntRect const& content_rect) | ||||||
| { | { | ||||||
|     request_repaint(); |     request_repaint(); | ||||||
|  |  | ||||||
|  | @ -83,7 +83,6 @@ private: | ||||||
|     virtual void create_client(EnableCallgrindProfiling = EnableCallgrindProfiling::No) override; |     virtual void create_client(EnableCallgrindProfiling = EnableCallgrindProfiling::No) override; | ||||||
|     virtual void update_zoom() override; |     virtual void update_zoom() override; | ||||||
|     virtual void notify_server_did_layout(Badge<WebContentClient>, Gfx::IntSize content_size) override; |     virtual void notify_server_did_layout(Badge<WebContentClient>, Gfx::IntSize content_size) override; | ||||||
|     virtual void notify_server_did_paint(Badge<WebContentClient>, i32 bitmap_id, Gfx::IntSize) override; |  | ||||||
|     virtual void notify_server_did_invalidate_content_rect(Badge<WebContentClient>, Gfx::IntRect const&) override; |     virtual void notify_server_did_invalidate_content_rect(Badge<WebContentClient>, Gfx::IntRect const&) override; | ||||||
|     virtual void notify_server_did_change_selection(Badge<WebContentClient>) override; |     virtual void notify_server_did_change_selection(Badge<WebContentClient>) override; | ||||||
|     virtual void notify_server_did_request_cursor_change(Badge<WebContentClient>, Gfx::StandardCursor cursor) override; |     virtual void notify_server_did_request_cursor_change(Badge<WebContentClient>, Gfx::StandardCursor cursor) override; | ||||||
|  |  | ||||||
|  | @ -48,6 +48,28 @@ WebContentClient const& ViewImplementation::client() const | ||||||
|     return *m_client_state.client; |     return *m_client_state.client; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void ViewImplementation::server_did_paint(Badge<WebContentClient>, i32 bitmap_id, Gfx::IntSize size) | ||||||
|  | { | ||||||
|  |     if (m_client_state.back_bitmap.id != bitmap_id) | ||||||
|  |         return; | ||||||
|  | 
 | ||||||
|  |     m_client_state.has_usable_bitmap = true; | ||||||
|  |     m_client_state.back_bitmap.pending_paints--; | ||||||
|  |     m_client_state.back_bitmap.last_painted_size = size; | ||||||
|  |     swap(m_client_state.back_bitmap, m_client_state.front_bitmap); | ||||||
|  | 
 | ||||||
|  |     // We don't need the backup bitmap anymore, so drop it.
 | ||||||
|  |     m_backup_bitmap = nullptr; | ||||||
|  | 
 | ||||||
|  |     if (on_ready_to_paint) | ||||||
|  |         on_ready_to_paint(); | ||||||
|  | 
 | ||||||
|  |     if (m_client_state.got_repaint_requests_while_painting) { | ||||||
|  |         m_client_state.got_repaint_requests_while_painting = false; | ||||||
|  |         request_repaint(); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| void ViewImplementation::load(AK::URL const& url) | void ViewImplementation::load(AK::URL const& url) | ||||||
| { | { | ||||||
|     m_url = url; |     m_url = url; | ||||||
|  |  | ||||||
|  | @ -47,6 +47,8 @@ public: | ||||||
| 
 | 
 | ||||||
|     String const& handle() const { return m_client_state.client_handle; } |     String const& handle() const { return m_client_state.client_handle; } | ||||||
| 
 | 
 | ||||||
|  |     void server_did_paint(Badge<WebContentClient>, i32 bitmap_id, Gfx::IntSize size); | ||||||
|  | 
 | ||||||
|     void load(AK::URL const&); |     void load(AK::URL const&); | ||||||
|     void load_html(StringView, AK::URL const&); |     void load_html(StringView, AK::URL const&); | ||||||
|     void load_empty_document(); |     void load_empty_document(); | ||||||
|  | @ -90,6 +92,7 @@ public: | ||||||
|     }; |     }; | ||||||
|     ErrorOr<void> take_screenshot(ScreenshotType); |     ErrorOr<void> take_screenshot(ScreenshotType); | ||||||
| 
 | 
 | ||||||
|  |     Function<void()> on_ready_to_paint; | ||||||
|     Function<String(Web::HTML::ActivateTab)> on_new_tab; |     Function<String(Web::HTML::ActivateTab)> on_new_tab; | ||||||
|     Function<void()> on_activate_tab; |     Function<void()> on_activate_tab; | ||||||
|     Function<void()> on_close; |     Function<void()> on_close; | ||||||
|  | @ -135,7 +138,6 @@ public: | ||||||
|     Function<Gfx::IntRect()> on_fullscreen_window; |     Function<Gfx::IntRect()> on_fullscreen_window; | ||||||
| 
 | 
 | ||||||
|     virtual void notify_server_did_layout(Badge<WebContentClient>, Gfx::IntSize content_size) = 0; |     virtual void notify_server_did_layout(Badge<WebContentClient>, Gfx::IntSize content_size) = 0; | ||||||
|     virtual void notify_server_did_paint(Badge<WebContentClient>, i32 bitmap_id, Gfx::IntSize) = 0; |  | ||||||
|     virtual void notify_server_did_invalidate_content_rect(Badge<WebContentClient>, Gfx::IntRect const&) = 0; |     virtual void notify_server_did_invalidate_content_rect(Badge<WebContentClient>, Gfx::IntRect const&) = 0; | ||||||
|     virtual void notify_server_did_change_selection(Badge<WebContentClient>) = 0; |     virtual void notify_server_did_change_selection(Badge<WebContentClient>) = 0; | ||||||
|     virtual void notify_server_did_request_cursor_change(Badge<WebContentClient>, Gfx::StandardCursor cursor) = 0; |     virtual void notify_server_did_request_cursor_change(Badge<WebContentClient>, Gfx::StandardCursor cursor) = 0; | ||||||
|  |  | ||||||
|  | @ -25,7 +25,7 @@ void WebContentClient::die() | ||||||
| 
 | 
 | ||||||
| void WebContentClient::did_paint(Gfx::IntRect const& rect, i32 bitmap_id) | void WebContentClient::did_paint(Gfx::IntRect const& rect, i32 bitmap_id) | ||||||
| { | { | ||||||
|     m_view.notify_server_did_paint({}, bitmap_id, rect.size()); |     m_view.server_did_paint({}, bitmap_id, rect.size()); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void WebContentClient::did_start_loading(AK::URL const& url, bool is_redirect) | void WebContentClient::did_start_loading(AK::URL const& url, bool is_redirect) | ||||||
|  |  | ||||||
|  | @ -103,7 +103,6 @@ private: | ||||||
|     HeadlessWebContentView() = default; |     HeadlessWebContentView() = default; | ||||||
| 
 | 
 | ||||||
|     void notify_server_did_layout(Badge<WebView::WebContentClient>, Gfx::IntSize) override { } |     void notify_server_did_layout(Badge<WebView::WebContentClient>, Gfx::IntSize) override { } | ||||||
|     void notify_server_did_paint(Badge<WebView::WebContentClient>, i32, Gfx::IntSize) override { } |  | ||||||
|     void notify_server_did_invalidate_content_rect(Badge<WebView::WebContentClient>, Gfx::IntRect const&) override { } |     void notify_server_did_invalidate_content_rect(Badge<WebView::WebContentClient>, Gfx::IntRect const&) override { } | ||||||
|     void notify_server_did_change_selection(Badge<WebView::WebContentClient>) override { } |     void notify_server_did_change_selection(Badge<WebView::WebContentClient>) override { } | ||||||
|     void notify_server_did_request_cursor_change(Badge<WebView::WebContentClient>, Gfx::StandardCursor) override { } |     void notify_server_did_request_cursor_change(Badge<WebView::WebContentClient>, Gfx::StandardCursor) override { } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Timothy Flynn
						Timothy Flynn