Skip to content

Truly independent web browser

Compositor: Show a context through its presentation if its stores fail

Aliaksandr Kalenikdf0de2d518d2
diff --git a/Services/Compositor/BackingStoreManager.cpp b/Services/Compositor/BackingStoreManager.cpp
index a7c4afc3991..f67c6c9bd85 100644
--- a/Services/Compositor/BackingStoreManager.cpp
+++ b/Services/Compositor/BackingStoreManager.cpp
@@ -159,7 +159,7 @@ Optional<BackingStoreManager::Allocation> BackingStoreManager::resize_backing_st
return {};
}
-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, RefPtr<WindowServer> window_server_showing_stores)
+ErrorOr<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, RefPtr<WindowServer> window_server_showing_stores)
{
m_backing_stores.clear();
m_rendering_store_index.clear();
@@ -168,7 +168,7 @@ Optional<BackingStoreManager::Publication> BackingStoreManager::allocate_backing
m_window_server_showing_stores = publication_mode == PublicationMode::ShownInRemoteLayer ? move(window_server_showing_stores) : nullptr;
if (Gfx::Bitmap::size_would_overflow(Gfx::BitmapFormat::BGRA8888, allocation.size))
- return {};
+ return Optional<Publication> {};
auto buffer_count = allocation.bitmap_ids.size();
m_backing_store_size = allocation.size;
@@ -186,20 +186,20 @@ Optional<BackingStoreManager::Publication> BackingStoreManager::allocate_backing
.accumulated_damage = { {}, allocation.size },
});
}
- return {};
+ return Optional<Publication> {};
}
if (publication_mode == PublicationMode::ShownInRemoteLayer) {
for (size_t i = 0; i < buffer_count; ++i) {
auto store = create_backing_store_shown_by_window_server(allocation.size, allocation.bitmap_ids[i], skia_backend_context);
if (store.is_error()) {
- dbgln("Failed to allocate a backing store that the window server can show: {}", store.error());
m_backing_stores.clear();
- return {};
+ invalidate();
+ return store.release_error();
}
m_backing_stores.append(store.release_value());
}
- return Publication { .bitmap_ids = allocation.bitmap_ids, .shared_images = {} };
+ return Optional<Publication> { Publication { .bitmap_ids = allocation.bitmap_ids, .shared_images = {} } };
}
// The UI installs the first published buffer as its initial front buffer.
@@ -238,10 +238,10 @@ Optional<BackingStoreManager::Publication> BackingStoreManager::allocate_backing
}
if (allocation_succeeded) {
- return Publication {
+ return Optional<Publication> { Publication {
.bitmap_ids = allocation.bitmap_ids,
.shared_images = move(shared_images),
- };
+ } };
}
m_backing_stores.clear();
@@ -255,10 +255,10 @@ Optional<BackingStoreManager::Publication> BackingStoreManager::allocate_backing
shared_images.append(m_backing_stores.last().shared_image_buffer->export_shared_image());
}
- return Publication {
+ return Optional<Publication> { Publication {
.bitmap_ids = allocation.bitmap_ids,
.shared_images = move(shared_images),
- };
+ } };
}
BackingStoreManager::BackingStore BackingStoreManager::create_shareable_backing_store(Gfx::IntSize size, i32 bitmap_id, BufferState state, RefPtr<Gfx::SkiaBackendContext> const& skia_backend_context)
diff --git a/Services/Compositor/BackingStoreManager.h b/Services/Compositor/BackingStoreManager.h
index 761de8c58c3..a1db5061767 100644
--- a/Services/Compositor/BackingStoreManager.h
+++ b/Services/Compositor/BackingStoreManager.h
@@ -64,7 +64,7 @@ public:
Optional<Allocation> resize_backing_stores_if_needed(
Gfx::IntSize viewport_size, Compositing::WindowResizingInProgress, PublicationMode);
- Optional<Publication> allocate_backing_stores(Allocation const&, RefPtr<Gfx::SkiaBackendContext> const&, PublicationMode, GpuSharing, RefPtr<WindowServer> window_server_showing_stores);
+ ErrorOr<Optional<Publication>> allocate_backing_stores(Allocation const&, RefPtr<Gfx::SkiaBackendContext> const&, PublicationMode, GpuSharing, RefPtr<WindowServer> window_server_showing_stores);
void invalidate() { m_allocated_size = {}; }
diff --git a/Services/Compositor/CompositorState.cpp b/Services/Compositor/CompositorState.cpp
index 54d6aaef632..5e180c2417e 100644
--- a/Services/Compositor/CompositorState.cpp
+++ b/Services/Compositor/CompositorState.cpp
@@ -1800,7 +1800,7 @@ CompositedContextSurface CompositorState::resolve_composited_context(Web::Compos
return {};
if (child_context->presenter.update_composited_raster_transform(destination_rect, canvas_transform)) {
- auto publication = child_context->presenter.resize_backing_stores_if_needed(m_skia_backend_context, BackingStoreManager::GpuSharing::Disallowed, BackingStoreManager::PublicationMode::Unpublished);
+ auto publication = MUST(child_context->presenter.resize_backing_stores_if_needed(m_skia_backend_context, BackingStoreManager::GpuSharing::Disallowed, BackingStoreManager::PublicationMode::Unpublished));
VERIFY(!publication.has_value());
}
@@ -1830,9 +1830,16 @@ void CompositorState::resize_backing_stores_if_needed(Web::CompositorContextId c
auto window_server_may_show_media = remote_layer_showing_context && m_skia_backend_context && !context.presents_from_cpu_memory;
context.presenter.set_remote_layer_that_may_show_media(window_server_may_show_media ? remote_layer_showing_context->layer.ptr() : nullptr);
auto window_server_showing_stores = remote_layer_showing_context ? RefPtr<WindowServer> { remote_layer_showing_context->window_server } : nullptr;
- if (auto publication = context.presenter.resize_backing_stores_if_needed(m_skia_backend_context, gpu_sharing_for_context(context_id), publication_mode, move(window_server_showing_stores)); publication.has_value()) {
+ auto publication = context.presenter.resize_backing_stores_if_needed(m_skia_backend_context, gpu_sharing_for_context(context_id), publication_mode, move(window_server_showing_stores));
+ if (publication.is_error()) {
+ VERIFY(context.remote_layer_id.has_value());
+ dbgln("Compositor: Failed to allocate the stores of context {} that remote layer {} shows, which its presentation shows again: {}", context_id, *context.remote_layer_id, publication.error());
+ show_context_in_remote_layer(*context.remote_layer_id, {});
+ return;
+ }
+ if (publication.value().has_value()) {
if (publication_mode == BackingStoreManager::PublicationMode::Published)
- publish_backing_stores(context_id, context, publication.release_value());
+ publish_backing_stores(context_id, context, publication.release_value().release_value());
present_current_frame(context_id, context);
}
}
diff --git a/Services/Compositor/ContextPresenter.cpp b/Services/Compositor/ContextPresenter.cpp
index eaf7544b987..ed6b2ef1897 100644
--- a/Services/Compositor/ContextPresenter.cpp
+++ b/Services/Compositor/ContextPresenter.cpp
@@ -129,10 +129,10 @@ Optional<Gfx::IntRect> ContextPresenter::viewport_rect_for_ui_overlay() const
return viewport_rect;
}
-Optional<BackingStoreManager::Publication> ContextPresenter::resize_backing_stores_if_needed(RefPtr<Gfx::SkiaBackendContext> const& skia_backend_context, BackingStoreManager::GpuSharing gpu_sharing, BackingStoreManager::PublicationMode publication_mode, RefPtr<WindowServer> window_server_showing_stores)
+ErrorOr<Optional<BackingStoreManager::Publication>> ContextPresenter::resize_backing_stores_if_needed(RefPtr<Gfx::SkiaBackendContext> const& skia_backend_context, BackingStoreManager::GpuSharing gpu_sharing, BackingStoreManager::PublicationMode publication_mode, RefPtr<WindowServer> window_server_showing_stores)
{
if (m_backing_store_manager.is_rendering())
- return {};
+ return Optional<BackingStoreManager::Publication> {};
if (!presents_to_client()) {
// A resize can arrive before the parent's next replay supplies the new embedding transform.
// Bound the existing embedding's scale for the new viewport before allocating backing stores. Bounding the
@@ -148,7 +148,7 @@ Optional<BackingStoreManager::Publication> ContextPresenter::resize_backing_stor
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 {};
+ return Optional<BackingStoreManager::Publication> {};
m_latest_rendered_surface = nullptr;
m_last_rasterized_frame.clear();
return m_backing_store_manager.allocate_backing_stores(*allocation, skia_backend_context, publication_mode, gpu_sharing, move(window_server_showing_stores));
diff --git a/Services/Compositor/ContextPresenter.h b/Services/Compositor/ContextPresenter.h
index b91ca3551b9..4429f9ae0ed 100644
--- a/Services/Compositor/ContextPresenter.h
+++ b/Services/Compositor/ContextPresenter.h
@@ -94,7 +94,7 @@ public:
bool ui_overlay_fades_need_frame() const { return m_picture_in_picture_controls_fade.is_fading(); }
Optional<PendingFrame> advance_ui_overlay_fades(MonotonicTime frame_time);
- Optional<BackingStoreManager::Publication> resize_backing_stores_if_needed(RefPtr<Gfx::SkiaBackendContext> const&, BackingStoreManager::GpuSharing, BackingStoreManager::PublicationMode, RefPtr<WindowServer> window_server_showing_stores = {});
+ ErrorOr<Optional<BackingStoreManager::Publication>> resize_backing_stores_if_needed(RefPtr<Gfx::SkiaBackendContext> const&, BackingStoreManager::GpuSharing, BackingStoreManager::PublicationMode, RefPtr<WindowServer> window_server_showing_stores = {});
void invalidate_backing_stores();
Optional<BackingStoreManager::Publication> add_backing_store_for_pending_frame_if_needed(RefPtr<Gfx::SkiaBackendContext> const&);
bool has_surplus_backing_stores() const { return m_backing_store_manager.has_surplus_backing_stores(); }