Truly independent web browser
Compositor: Keep how backing stores are published in their manager
Aliaksandr Kalenik4a66ba748f14
diff --git a/Services/Compositor/BackingStoreManager.cpp b/Services/Compositor/BackingStoreManager.cppindex 9b29091ac9f..337d4814dc5 100644--- a/Services/Compositor/BackingStoreManager.cpp+++ b/Services/Compositor/BackingStoreManager.cpp@@ -119,19 +119,17 @@ static ErrorOr<GpuBackingStore> create_shared_gpu_backing_store(Gfx::IntSize siz// A published store is released by the UI when it presents the next one, but on macOS the UI hands the// surface itself to the window server, which keeps reading it until it has composited the replacement.// A third store lets the compositor keep rendering through that window instead of waiting for it.-static size_t backing_store_count_for(bool should_publish)+static size_t backing_store_count_for([[maybe_unused]] BackingStoreManager::PublicationMode publication_mode){#ifdef AK_OS_MACOS- if (should_publish)+ if (publication_mode == BackingStoreManager::PublicationMode::Published)return 3;-#else- (void)should_publish;#endifreturn 2;}Optional<BackingStoreManager::Allocation> BackingStoreManager::resize_backing_stores_if_needed(- Gfx::IntSize viewport_size, Compositing::WindowResizingInProgress window_resize_in_progress, bool should_publish)+ Gfx::IntSize viewport_size, Compositing::WindowResizingInProgress window_resize_in_progress, PublicationMode publication_mode){if (viewport_size.is_empty())return {};@@ -150,7 +148,7 @@ Optional<BackingStoreManager::Allocation> BackingStoreManager::resize_backing_stif (needs_allocation) {m_allocated_size = allocation_size;- auto buffer_count = backing_store_count_for(should_publish);+ auto buffer_count = backing_store_count_for(publication_mode);Vector<i32> bitmap_ids;bitmap_ids.ensure_capacity(buffer_count);for (size_t i = 0; i < buffer_count; ++i)@@ -161,11 +159,12 @@ Optional<BackingStoreManager::Allocation> BackingStoreManager::resize_backing_streturn {};}-Optional<BackingStoreManager::Publication> BackingStoreManager::allocate_backing_stores(Allocation const& allocation, RefPtr<Gfx::SkiaBackendContext> const& skia_backend_context, bool should_publish, [[maybe_unused]] GpuSharing gpu_sharing)+Optional<BackingStoreManager::Publication> BackingStoreManager::allocate_backing_stores(Allocation const& allocation, RefPtr<Gfx::SkiaBackendContext> const& skia_backend_context, PublicationMode publication_mode, [[maybe_unused]] GpuSharing gpu_sharing){m_backing_stores.clear();m_rendering_store_index.clear();m_latest_rendered_store_index.clear();+ m_publication_mode = publication_mode;if (Gfx::Bitmap::size_would_overflow(Gfx::BitmapFormat::BGRA8888, allocation.size))return {};@@ -175,7 +174,7 @@ Optional<BackingStoreManager::Publication> BackingStoreManager::allocate_backingm_initial_backing_store_count = buffer_count;m_backing_stores.ensure_capacity(buffer_count);- if (!should_publish) {+ if (publication_mode == PublicationMode::Unpublished) {for (size_t i = 0; i < buffer_count; ++i) {m_backing_stores.append({.surface = Gfx::PaintingSurface::create_with_size(allocation.size, Gfx::BitmapFormat::BGRA8888, Gfx::AlphaType::Premultiplied, skia_backend_context),@@ -372,18 +371,19 @@ Optional<BackingStoreManager::RenderTarget> BackingStoreManager::acquire_render_return {};}-void BackingStoreManager::complete_rendering(i32 bitmap_id, bool wait_for_release)+void BackingStoreManager::complete_rendering(i32 bitmap_id){VERIFY(m_rendering_store_index.has_value());auto& store = m_backing_stores[*m_rendering_store_index];VERIFY(store.state == BufferState::Rendering);VERIFY(store.bitmap_id == bitmap_id);- if (!wait_for_release && m_latest_rendered_store_index.has_value())+ bool client_releases_presented_stores = m_publication_mode == PublicationMode::Published;+ if (!client_releases_presented_stores && m_latest_rendered_store_index.has_value())m_backing_stores[*m_latest_rendered_store_index].state = BufferState::Available;store.state = BufferState::Presented;- if (wait_for_release)+ if (client_releases_presented_stores)store.was_presented_to_client = true;m_latest_rendered_store_index = m_rendering_store_index;m_rendering_store_index.clear();diff --git a/Services/Compositor/BackingStoreManager.h b/Services/Compositor/BackingStoreManager.hindex 5fa223f4661..b8441af9dda 100644--- a/Services/Compositor/BackingStoreManager.h+++ b/Services/Compositor/BackingStoreManager.h@@ -57,8 +57,8 @@ public:static void set_presentation_drm_format_modifiers(Vector<u64>);Optional<Allocation> resize_backing_stores_if_needed(- Gfx::IntSize viewport_size, Compositing::WindowResizingInProgress, bool should_publish);- Optional<Publication> allocate_backing_stores(Allocation const&, RefPtr<Gfx::SkiaBackendContext> const&, bool should_publish, GpuSharing);+ Gfx::IntSize viewport_size, Compositing::WindowResizingInProgress, PublicationMode);+ Optional<Publication> allocate_backing_stores(Allocation const&, RefPtr<Gfx::SkiaBackendContext> const&, PublicationMode, GpuSharing);void invalidate() { m_allocated_size = {}; }@@ -66,7 +66,7 @@ public:bool is_rendering() const { return m_rendering_store_index.has_value(); }bool has_available_buffer() const;Optional<RenderTarget> acquire_render_target(Gfx::IntRect frame_damage);- void complete_rendering(i32 bitmap_id, bool release_to_external);+ void complete_rendering(i32 bitmap_id);bool release_buffer(i32 bitmap_id);void release_all_presented_buffers();RefPtr<Gfx::PaintingSurface> latest_rendered_surface() const;@@ -104,6 +104,7 @@ private:Gfx::IntSize m_allocated_size;Gfx::IntSize m_backing_store_size;+ PublicationMode m_publication_mode { PublicationMode::Unpublished };size_t m_initial_backing_store_count { 0 };Vector<BackingStore> m_backing_stores;Optional<size_t> m_rendering_store_index;diff --git a/Services/Compositor/ContextPresenter.cpp b/Services/Compositor/ContextPresenter.cppindex fcfbf8ecfe0..2be029756ab 100644--- a/Services/Compositor/ContextPresenter.cpp+++ b/Services/Compositor/ContextPresenter.cpp@@ -134,13 +134,14 @@ Optional<BackingStoreManager::Publication> ContextPresenter::resize_backing_storm_last_rasterized_frame.clear();}}- auto should_publish = presents_to_client() && publication_mode == BackingStoreManager::PublicationMode::Published;- auto allocation = m_backing_store_manager.resize_backing_stores_if_needed(raster_size(), m_window_resize_in_progress, should_publish);+ if (!presents_to_client())+ publication_mode = BackingStoreManager::PublicationMode::Unpublished;+ auto allocation = m_backing_store_manager.resize_backing_stores_if_needed(raster_size(), m_window_resize_in_progress, publication_mode);if (!allocation.has_value())return {};m_latest_rendered_surface = nullptr;m_last_rasterized_frame.clear();- return m_backing_store_manager.allocate_backing_stores(*allocation, skia_backend_context, should_publish, gpu_sharing);+ return m_backing_store_manager.allocate_backing_stores(*allocation, skia_backend_context, publication_mode, gpu_sharing);}void ContextPresenter::invalidate_backing_stores()@@ -170,7 +171,7 @@ bool ContextPresenter::acknowledge_presented_bitmap(i32 bitmap_id)void ContextPresenter::did_finish_gpu_present(i32 bitmap_id){- m_backing_store_manager.complete_rendering(bitmap_id, presents_to_client());+ m_backing_store_manager.complete_rendering(bitmap_id);m_latest_rendered_surface = m_backing_store_manager.latest_rendered_surface();}@@ -360,7 +361,7 @@ bool ContextPresenter::present_synchronously(DisplayListPlayerSkia& display_listpaint_current_display_list(display_list_player, back_store, *frame_inputs, composited_context_resolver, render_target->damage_rect);remember_rasterized_frame(pending_frame->viewport_rect.size(), frame_inputs.release_value());display_list_player.flush(back_store);- m_backing_store_manager.complete_rendering(render_target->bitmap_id, false);+ m_backing_store_manager.complete_rendering(render_target->bitmap_id);m_latest_rendered_surface = m_backing_store_manager.latest_rendered_surface();m_presented_frame = pending_frame->viewport_rect;m_pending_present_frame.clear();