From 8fd8757248756a0c7c64ee4d6783f57cac17f098 Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Mon, 22 Apr 2024 17:04:39 -0500 Subject: [PATCH] fix: offscreen rendering does not paint after gpu process crashed (#41925) Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: zhangqi.67 --- .../browser/osr/osr_render_widget_host_view.cc | 15 +++++++++++++++ shell/browser/osr/osr_render_widget_host_view.h | 17 ++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/shell/browser/osr/osr_render_widget_host_view.cc b/shell/browser/osr/osr_render_widget_host_view.cc index efeecef96127..afe4c5ee5656 100644 --- a/shell/browser/osr/osr_render_widget_host_view.cc +++ b/shell/browser/osr/osr_render_widget_host_view.cc @@ -230,6 +230,7 @@ OffScreenRenderWidgetHostView::OffScreenRenderWidgetHostView( ResizeRootLayer(false); render_widget_host_->SetView(this); + render_widget_host_->render_frame_metadata_provider()->AddObserver(this); if (content::GpuDataManager::GetInstance()->HardwareAccelerationEnabled()) { video_consumer_ = std::make_unique( @@ -240,7 +241,21 @@ OffScreenRenderWidgetHostView::OffScreenRenderWidgetHostView( } } +void OffScreenRenderWidgetHostView::OnLocalSurfaceIdChanged( + const cc::RenderFrameMetadata& metadata) { + if (metadata.local_surface_id) { + bool changed = delegated_frame_host_allocator_.UpdateFromChild( + *metadata.local_surface_id); + + if (changed) { + ResizeRootLayer(true); + } + } +} + OffScreenRenderWidgetHostView::~OffScreenRenderWidgetHostView() { + render_widget_host_->render_frame_metadata_provider()->RemoveObserver(this); + // Marking the DelegatedFrameHost as removed from the window hierarchy is // necessary to remove all connections to its old ui::Compositor. if (is_showing_) diff --git a/shell/browser/osr/osr_render_widget_host_view.h b/shell/browser/osr/osr_render_widget_host_view.h index fec8525118c5..b674f7cfbcf6 100644 --- a/shell/browser/osr/osr_render_widget_host_view.h +++ b/shell/browser/osr/osr_render_widget_host_view.h @@ -59,9 +59,11 @@ typedef base::RepeatingCallback OnPaintCallback; typedef base::RepeatingCallback OnPopupPaintCallback; -class OffScreenRenderWidgetHostView : public content::RenderWidgetHostViewBase, - public ui::CompositorDelegate, - public OffscreenViewProxyObserver { +class OffScreenRenderWidgetHostView + : public content::RenderWidgetHostViewBase, + public content::RenderFrameMetadataProvider::Observer, + public ui::CompositorDelegate, + public OffscreenViewProxyObserver { public: OffScreenRenderWidgetHostView(bool transparent, bool painting, @@ -175,6 +177,15 @@ class OffScreenRenderWidgetHostView : public content::RenderWidgetHostViewBase, RenderWidgetHostViewBase* target_view, gfx::PointF* transformed_point) override; + // RenderFrameMetadataProvider::Observer: + void OnRenderFrameMetadataChangedBeforeActivation( + const cc::RenderFrameMetadata& metadata) override {} + void OnRenderFrameMetadataChangedAfterActivation( + base::TimeTicks activation_time) override {} + void OnRenderFrameSubmission() override {} + void OnLocalSurfaceIdChanged( + const cc::RenderFrameMetadata& metadata) override; + // ui::CompositorDelegate: bool IsOffscreen() const override; std::unique_ptr CreateHostDisplayClient(