fix: move NativeWindow tracking to OSR WCV (#15585)
* fix: move NativeWindow tracking to OSR WCV * fix oops
This commit is contained in:
parent
78b88a70bb
commit
8cca1c987b
7 changed files with 71 additions and 81 deletions
|
@ -53,7 +53,7 @@ class WebViewGuestDelegate;
|
|||
class FrameSubscriber;
|
||||
|
||||
#if BUILDFLAG(ENABLE_OSR)
|
||||
class OffScreenWebContentsView;
|
||||
class OffScreenRenderWidgetHostView;
|
||||
#endif
|
||||
|
||||
namespace api {
|
||||
|
@ -457,9 +457,8 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
|||
uint32_t GetNextRequestId() { return ++request_id_; }
|
||||
|
||||
#if BUILDFLAG(ENABLE_OSR)
|
||||
OffScreenWebContentsView* GetOffScreenWebContentsView() const;
|
||||
OffScreenRenderWidgetHostView* GetOffScreenRenderWidgetHostView()
|
||||
const override;
|
||||
OffScreenWebContentsView* GetOffScreenWebContentsView() const override;
|
||||
OffScreenRenderWidgetHostView* GetOffScreenRenderWidgetHostView() const;
|
||||
#endif
|
||||
|
||||
// Called when we receive a CursorChange message from chromium.
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
#include "storage/browser/fileapi/isolated_context.h"
|
||||
|
||||
#if BUILDFLAG(ENABLE_OSR)
|
||||
#include "atom/browser/osr/osr_render_widget_host_view.h"
|
||||
#include "atom/browser/osr/osr_web_contents_view.h"
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(ENABLE_PRINTING)
|
||||
|
@ -215,9 +215,9 @@ void CommonWebContentsDelegate::SetOwnerWindow(
|
|||
NativeWindowRelay::kNativeWindowRelayUserDataKey);
|
||||
}
|
||||
#if BUILDFLAG(ENABLE_OSR)
|
||||
auto* osr_rwhv = GetOffScreenRenderWidgetHostView();
|
||||
if (osr_rwhv)
|
||||
osr_rwhv->SetNativeWindow(owner_window);
|
||||
auto* osr_wcv = GetOffScreenWebContentsView();
|
||||
if (osr_wcv)
|
||||
osr_wcv->SetNativeWindow(owner_window);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -256,8 +256,8 @@ content::WebContents* CommonWebContentsDelegate::GetDevToolsWebContents()
|
|||
}
|
||||
|
||||
#if BUILDFLAG(ENABLE_OSR)
|
||||
OffScreenRenderWidgetHostView*
|
||||
CommonWebContentsDelegate::GetOffScreenRenderWidgetHostView() const {
|
||||
OffScreenWebContentsView*
|
||||
CommonWebContentsDelegate::GetOffScreenWebContentsView() const {
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -33,7 +33,7 @@ class NativeWindow;
|
|||
class WebDialogHelper;
|
||||
|
||||
#if BUILDFLAG(ENABLE_OSR)
|
||||
class OffScreenRenderWidgetHostView;
|
||||
class OffScreenWebContentsView;
|
||||
#endif
|
||||
|
||||
class CommonWebContentsDelegate : public content::WebContentsDelegate,
|
||||
|
@ -70,8 +70,7 @@ class CommonWebContentsDelegate : public content::WebContentsDelegate,
|
|||
|
||||
protected:
|
||||
#if BUILDFLAG(ENABLE_OSR)
|
||||
virtual OffScreenRenderWidgetHostView* GetOffScreenRenderWidgetHostView()
|
||||
const;
|
||||
virtual OffScreenWebContentsView* GetOffScreenWebContentsView() const;
|
||||
#endif
|
||||
|
||||
// content::WebContentsDelegate:
|
||||
|
|
|
@ -257,15 +257,14 @@ OffScreenRenderWidgetHostView::OffScreenRenderWidgetHostView(
|
|||
const OnPaintCallback& callback,
|
||||
content::RenderWidgetHost* host,
|
||||
OffScreenRenderWidgetHostView* parent_host_view,
|
||||
NativeWindow* native_window)
|
||||
gfx::Size initial_size)
|
||||
: content::RenderWidgetHostViewBase(host),
|
||||
render_widget_host_(content::RenderWidgetHostImpl::From(host)),
|
||||
parent_host_view_(parent_host_view),
|
||||
native_window_(native_window),
|
||||
transparent_(transparent),
|
||||
callback_(callback),
|
||||
frame_rate_(frame_rate),
|
||||
size_(native_window ? native_window->GetSize() : gfx::Size()),
|
||||
size_(initial_size),
|
||||
painting_(painting),
|
||||
is_showing_(!render_widget_host_->is_hidden()),
|
||||
cursor_manager_(new content::CursorManager(this)),
|
||||
|
@ -312,18 +311,12 @@ OffScreenRenderWidgetHostView::OffScreenRenderWidgetHostView(
|
|||
#endif
|
||||
GetCompositor()->SetDelegate(this);
|
||||
|
||||
if (native_window_)
|
||||
native_window_->AddObserver(this);
|
||||
|
||||
ResizeRootLayer(false);
|
||||
render_widget_host_->SetView(this);
|
||||
InstallTransparency();
|
||||
}
|
||||
|
||||
OffScreenRenderWidgetHostView::~OffScreenRenderWidgetHostView() {
|
||||
if (native_window_)
|
||||
native_window_->RemoveObserver(this);
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
if (is_showing_)
|
||||
browser_compositor_->SetRenderWidgetHostIsHidden(true);
|
||||
|
@ -354,19 +347,6 @@ OffScreenRenderWidgetHostView::CreateBrowserAccessibilityManager(
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
void OffScreenRenderWidgetHostView::OnWindowResize() {
|
||||
// In offscreen mode call RenderWidgetHostView's SetSize explicitly
|
||||
auto size = native_window_ ? native_window_->GetSize() : gfx::Size();
|
||||
SetSize(size);
|
||||
}
|
||||
|
||||
void OffScreenRenderWidgetHostView::OnWindowClosed() {
|
||||
if (native_window_) {
|
||||
native_window_->RemoveObserver(this);
|
||||
native_window_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void OffScreenRenderWidgetHostView::OnBeginFrameTimerTick() {
|
||||
const base::TimeTicks frame_time = base::TimeTicks::Now();
|
||||
const base::TimeDelta vsync_period =
|
||||
|
@ -757,7 +737,7 @@ OffScreenRenderWidgetHostView::CreateViewForWidget(
|
|||
|
||||
return new OffScreenRenderWidgetHostView(
|
||||
transparent_, true, embedder_host_view->GetFrameRate(), callback_,
|
||||
render_widget_host, embedder_host_view, native_window_);
|
||||
render_widget_host, embedder_host_view, size());
|
||||
}
|
||||
|
||||
#if !defined(OS_MACOSX)
|
||||
|
@ -1259,18 +1239,6 @@ void OffScreenRenderWidgetHostView::InvalidateBounds(const gfx::Rect& bounds) {
|
|||
}
|
||||
}
|
||||
|
||||
void OffScreenRenderWidgetHostView::SetNativeWindow(NativeWindow* window) {
|
||||
if (native_window_)
|
||||
native_window_->RemoveObserver(this);
|
||||
|
||||
native_window_ = window;
|
||||
|
||||
if (native_window_)
|
||||
native_window_->AddObserver(this);
|
||||
|
||||
OnWindowResize();
|
||||
}
|
||||
|
||||
void OffScreenRenderWidgetHostView::ResizeRootLayer(bool force) {
|
||||
SetupFrameRate(false);
|
||||
|
||||
|
|
|
@ -14,8 +14,6 @@
|
|||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "atom/browser/native_window.h"
|
||||
#include "atom/browser/native_window_observer.h"
|
||||
#include "atom/browser/osr/osr_output_device.h"
|
||||
#include "atom/browser/osr/osr_view_proxy.h"
|
||||
#include "base/process/kill.h"
|
||||
|
@ -75,7 +73,6 @@ class OffScreenRenderWidgetHostView : public content::RenderWidgetHostViewBase,
|
|||
#if !defined(OS_MACOSX)
|
||||
public content::DelegatedFrameHostClient,
|
||||
#endif
|
||||
public NativeWindowObserver,
|
||||
public OffscreenViewProxyObserver {
|
||||
public:
|
||||
OffScreenRenderWidgetHostView(bool transparent,
|
||||
|
@ -84,7 +81,7 @@ class OffScreenRenderWidgetHostView : public content::RenderWidgetHostViewBase,
|
|||
const OnPaintCallback& callback,
|
||||
content::RenderWidgetHost* render_widget_host,
|
||||
OffScreenRenderWidgetHostView* parent_host_view,
|
||||
NativeWindow* native_window);
|
||||
gfx::Size initial_size);
|
||||
~OffScreenRenderWidgetHostView() override;
|
||||
|
||||
content::BrowserAccessibilityManager* CreateBrowserAccessibilityManager(
|
||||
|
@ -205,10 +202,6 @@ class OffScreenRenderWidgetHostView : public content::RenderWidgetHostViewBase,
|
|||
|
||||
bool InstallTransparency();
|
||||
|
||||
// NativeWindowObserver:
|
||||
void OnWindowResize() override;
|
||||
void OnWindowClosed() override;
|
||||
|
||||
void OnBeginFrameTimerTick();
|
||||
void SendBeginFrame(base::TimeTicks frame_time, base::TimeDelta vsync_period);
|
||||
|
||||
|
@ -268,8 +261,7 @@ class OffScreenRenderWidgetHostView : public content::RenderWidgetHostViewBase,
|
|||
content::RenderWidgetHostImpl* render_widget_host() const {
|
||||
return render_widget_host_;
|
||||
}
|
||||
void SetNativeWindow(NativeWindow* window);
|
||||
NativeWindow* window() const { return native_window_; }
|
||||
|
||||
gfx::Size size() const { return size_; }
|
||||
|
||||
void set_popup_host_view(OffScreenRenderWidgetHostView* popup_view) {
|
||||
|
@ -306,7 +298,6 @@ class OffScreenRenderWidgetHostView : public content::RenderWidgetHostViewBase,
|
|||
std::set<OffScreenRenderWidgetHostView*> guest_host_views_;
|
||||
std::set<OffscreenViewProxy*> proxy_views_;
|
||||
|
||||
NativeWindow* native_window_;
|
||||
OffScreenOutputDevice* software_output_device_ = nullptr;
|
||||
|
||||
const bool transparent_;
|
||||
|
|
|
@ -15,13 +15,16 @@ namespace atom {
|
|||
OffScreenWebContentsView::OffScreenWebContentsView(
|
||||
bool transparent,
|
||||
const OnPaintCallback& callback)
|
||||
: transparent_(transparent), callback_(callback) {
|
||||
: native_window_(nullptr), transparent_(transparent), callback_(callback) {
|
||||
#if defined(OS_MACOSX)
|
||||
PlatformCreate();
|
||||
#endif
|
||||
}
|
||||
|
||||
OffScreenWebContentsView::~OffScreenWebContentsView() {
|
||||
if (native_window_)
|
||||
native_window_->RemoveObserver(this);
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
PlatformDestroy();
|
||||
#endif
|
||||
|
@ -34,35 +37,52 @@ void OffScreenWebContentsView::SetWebContents(
|
|||
RenderViewCreated(web_contents_->GetRenderViewHost());
|
||||
}
|
||||
|
||||
void OffScreenWebContentsView::SetNativeWindow(NativeWindow* window) {
|
||||
if (native_window_)
|
||||
native_window_->RemoveObserver(this);
|
||||
|
||||
native_window_ = window;
|
||||
|
||||
if (native_window_)
|
||||
native_window_->AddObserver(this);
|
||||
|
||||
OnWindowResize();
|
||||
}
|
||||
|
||||
void OffScreenWebContentsView::OnWindowResize() {
|
||||
// In offscreen mode call RenderWidgetHostView's SetSize explicitly
|
||||
if (GetView())
|
||||
GetView()->SetSize(GetSize());
|
||||
}
|
||||
|
||||
void OffScreenWebContentsView::OnWindowClosed() {
|
||||
if (native_window_) {
|
||||
native_window_->RemoveObserver(this);
|
||||
native_window_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
gfx::Size OffScreenWebContentsView::GetSize() {
|
||||
return native_window_ ? native_window_->GetSize() : gfx::Size();
|
||||
}
|
||||
|
||||
#if !defined(OS_MACOSX)
|
||||
gfx::NativeView OffScreenWebContentsView::GetNativeView() const {
|
||||
if (!web_contents_)
|
||||
if (!native_window_)
|
||||
return gfx::NativeView();
|
||||
|
||||
auto* relay = NativeWindowRelay::FromWebContents(web_contents_);
|
||||
if (!relay)
|
||||
return gfx::NativeView();
|
||||
return relay->GetNativeWindow()->GetNativeView();
|
||||
return native_window_->GetNativeView();
|
||||
}
|
||||
|
||||
gfx::NativeView OffScreenWebContentsView::GetContentNativeView() const {
|
||||
if (!web_contents_)
|
||||
if (!native_window_)
|
||||
return gfx::NativeView();
|
||||
|
||||
auto* relay = NativeWindowRelay::FromWebContents(web_contents_);
|
||||
if (!relay)
|
||||
return gfx::NativeView();
|
||||
return relay->GetNativeWindow()->GetNativeView();
|
||||
return native_window_->GetNativeView();
|
||||
}
|
||||
|
||||
gfx::NativeWindow OffScreenWebContentsView::GetTopLevelNativeWindow() const {
|
||||
if (!web_contents_)
|
||||
if (!native_window_)
|
||||
return gfx::NativeWindow();
|
||||
|
||||
auto* relay = NativeWindowRelay::FromWebContents(web_contents_);
|
||||
if (!relay)
|
||||
return gfx::NativeWindow();
|
||||
return relay->GetNativeWindow()->GetNativeWindow();
|
||||
return native_window_->GetNativeWindow();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -104,7 +124,7 @@ OffScreenWebContentsView::CreateViewForWidget(
|
|||
|
||||
return new OffScreenRenderWidgetHostView(
|
||||
transparent_, painting_, GetFrameRate(), callback_, render_widget_host,
|
||||
nullptr, nullptr);
|
||||
nullptr, GetSize());
|
||||
}
|
||||
|
||||
content::RenderWidgetHostViewBase*
|
||||
|
@ -122,7 +142,7 @@ OffScreenWebContentsView::CreateViewForPopupWidget(
|
|||
|
||||
return new OffScreenRenderWidgetHostView(transparent_, true,
|
||||
view->GetFrameRate(), callback_,
|
||||
render_widget_host, view, nullptr);
|
||||
render_widget_host, view, GetSize());
|
||||
}
|
||||
|
||||
void OffScreenWebContentsView::SetPageTitle(const base::string16& title) {}
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
#ifndef ATOM_BROWSER_OSR_OSR_WEB_CONTENTS_VIEW_H_
|
||||
#define ATOM_BROWSER_OSR_OSR_WEB_CONTENTS_VIEW_H_
|
||||
|
||||
#include "atom/browser/native_window.h"
|
||||
#include "atom/browser/native_window_observer.h"
|
||||
|
||||
#include "atom/browser/osr/osr_render_widget_host_view.h"
|
||||
#include "content/browser/renderer_host/render_view_host_delegate_view.h"
|
||||
#include "content/browser/web_contents/web_contents_view.h"
|
||||
|
@ -21,12 +24,20 @@ class OffScreenView;
|
|||
namespace atom {
|
||||
|
||||
class OffScreenWebContentsView : public content::WebContentsView,
|
||||
public content::RenderViewHostDelegateView {
|
||||
public content::RenderViewHostDelegateView,
|
||||
public NativeWindowObserver {
|
||||
public:
|
||||
OffScreenWebContentsView(bool transparent, const OnPaintCallback& callback);
|
||||
~OffScreenWebContentsView() override;
|
||||
|
||||
void SetWebContents(content::WebContents*);
|
||||
void SetNativeWindow(NativeWindow* window);
|
||||
|
||||
// NativeWindowObserver:
|
||||
void OnWindowResize() override;
|
||||
void OnWindowClosed() override;
|
||||
|
||||
gfx::Size GetSize();
|
||||
|
||||
// content::WebContentsView:
|
||||
gfx::NativeView GetNativeView() const override;
|
||||
|
@ -84,6 +95,8 @@ class OffScreenWebContentsView : public content::WebContentsView,
|
|||
|
||||
OffScreenRenderWidgetHostView* GetView() const;
|
||||
|
||||
NativeWindow* native_window_;
|
||||
|
||||
const bool transparent_;
|
||||
bool painting_ = true;
|
||||
int frame_rate_ = 60;
|
||||
|
|
Loading…
Reference in a new issue