Skip to content

Commit

Permalink
fix: offscreen rendering does not paint after gpu process crashed (#4…
Browse files Browse the repository at this point in the history
…1925)

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: zhangqi.67 <zhangqi.67@bytedance.com>
  • Loading branch information
trop[bot] and zhangqi.67 committed Apr 22, 2024
1 parent d800684 commit 8fd8757
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
15 changes: 15 additions & 0 deletions shell/browser/osr/osr_render_widget_host_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<OffScreenVideoConsumer>(
Expand All @@ -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_)
Expand Down
17 changes: 14 additions & 3 deletions shell/browser/osr/osr_render_widget_host_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ typedef base::RepeatingCallback<void(const gfx::Rect&, const SkBitmap&)>
OnPaintCallback;
typedef base::RepeatingCallback<void(const gfx::Rect&)> 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,
Expand Down Expand Up @@ -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<viz::HostDisplayClient> CreateHostDisplayClient(
Expand Down

0 comments on commit 8fd8757

Please sign in to comment.