From 710021be159504b58130a20d27596fbf40fb4760 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Tue, 29 Jan 2019 15:52:46 -0500 Subject: [PATCH] Windows: Fix OSR rendering with shared texture enabled (issue #2559) --- .../osr/render_widget_host_view_osr.cc | 29 ++++++++----------- .../browser/osr/render_widget_host_view_osr.h | 5 ++-- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/libcef/browser/osr/render_widget_host_view_osr.cc b/libcef/browser/osr/render_widget_host_view_osr.cc index a993cf8d1..767a4c120 100644 --- a/libcef/browser/osr/render_widget_host_view_osr.cc +++ b/libcef/browser/osr/render_widget_host_view_osr.cc @@ -81,17 +81,15 @@ class CefCompositorFrameSinkClient void DidReceiveCompositorFrameAck( const std::vector& resources) override { + if (render_widget_host_view_) { + render_widget_host_view_->OnPresentCompositorFrame(); + } forward_->DidReceiveCompositorFrameAck(resources); } void OnBeginFrame(const viz::BeginFrameArgs& args, const base::flat_map& feedbacks) override { - if (render_widget_host_view_) { - for (const auto& pair : feedbacks) { - render_widget_host_view_->OnPresentCompositorFrame(pair.first); - } - } forward_->OnBeginFrame(args, feedbacks); } @@ -585,8 +583,7 @@ void CefRenderWidgetHostViewOSR::DidCreateNewRendererCompositorFrameSink( } } -void CefRenderWidgetHostViewOSR::OnPresentCompositorFrame( - uint32_t presentation_token) { +void CefRenderWidgetHostViewOSR::OnPresentCompositorFrame() { // Is Chromium rendering to a shared texture? void* shared_texture = nullptr; ui::Compositor* compositor = GetCompositor(); @@ -606,10 +603,13 @@ void CefRenderWidgetHostViewOSR::OnPresentCompositorFrame( // view size for a full redraw. base::AutoLock lock_scope(damage_rect_lock_); + // TODO: in the future we need to correlate the presentation + // notification with the sequence number from BeginFrame gfx::Rect damage; - auto const i = damage_rects_.find(presentation_token); + auto const i = damage_rects_.begin(); if (i != damage_rects_.end()) { damage = i->second; + damage_rects_.erase(i); } else { damage = GetViewBounds(); } @@ -623,7 +623,7 @@ void CefRenderWidgetHostViewOSR::OnPresentCompositorFrame( } } -void CefRenderWidgetHostViewOSR::AddDamageRect(uint32_t presentation_token, +void CefRenderWidgetHostViewOSR::AddDamageRect(uint32_t sequence, const gfx::Rect& rect) { // Associate the given damage rect with the presentation token. // For OnAcceleratedPaint we'll lookup the corresponding damage area based on @@ -636,7 +636,7 @@ void CefRenderWidgetHostViewOSR::AddDamageRect(uint32_t presentation_token, while (damage_rects_.size() >= kMaxDamageRects) { damage_rects_.erase(damage_rects_.begin()); } - damage_rects_[presentation_token] = rect; + damage_rects_[sequence] = rect; } void CefRenderWidgetHostViewOSR::SubmitCompositorFrame( @@ -700,13 +700,8 @@ void CefRenderWidgetHostViewOSR::SubmitCompositorFrame( damage_rect.Intersect(gfx::Rect(frame_size)); if (shared_texture) { - // Indicate that we want feedback every frame. - if (!++presentation_token_) - ++presentation_token_; - - AddDamageRect(presentation_token_, damage_rect); - - frame.metadata.frame_token = presentation_token_; + AddDamageRect(frame.metadata.begin_frame_ack.sequence_number, + damage_rect); } // We would normally call BrowserCompositorMac::SubmitCompositorFrame on diff --git a/libcef/browser/osr/render_widget_host_view_osr.h b/libcef/browser/osr/render_widget_host_view_osr.h index 582bf5899..b8aa22e5b 100644 --- a/libcef/browser/osr/render_widget_host_view_osr.h +++ b/libcef/browser/osr/render_widget_host_view_osr.h @@ -267,7 +267,7 @@ class CefRenderWidgetHostViewOSR : public content::RenderWidgetHostViewBase, } #endif - void OnPresentCompositorFrame(uint32_t presentation_token); + void OnPresentCompositorFrame(); private: content::DelegatedFrameHost* GetDelegatedFrameHost() const; @@ -301,7 +301,7 @@ class CefRenderWidgetHostViewOSR : public content::RenderWidgetHostViewBase, viz::FrameSinkId AllocateFrameSinkId(bool is_guest_view_hack); - void AddDamageRect(uint32_t presentation_token, const gfx::Rect& rect); + void AddDamageRect(uint32_t sequence, const gfx::Rect& rect); // Applies background color without notifying the RenderWidget about // opaqueness changes. @@ -394,7 +394,6 @@ class CefRenderWidgetHostViewOSR : public content::RenderWidgetHostViewBase, bool is_showing_; bool is_destroyed_; gfx::Rect popup_position_; - uint32_t presentation_token_ = 0; base::Lock damage_rect_lock_; std::map damage_rects_;