Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: move NativeWindow tracking to OSR WCV #15585

Merged
merged 3 commits into from Nov 30, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 3 additions & 4 deletions atom/browser/api/atom_api_web_contents.h
Expand Up @@ -48,7 +48,7 @@ class WebViewGuestDelegate;
class FrameSubscriber;

#if BUILDFLAG(ENABLE_OSR)
class OffScreenWebContentsView;
class OffScreenRenderWidgetHostView;
#endif

namespace api {
Expand Down Expand Up @@ -439,9 +439,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.
Expand Down
12 changes: 6 additions & 6 deletions atom/browser/common_web_contents_delegate.cc
Expand Up @@ -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)
Expand Down Expand Up @@ -213,9 +213,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
}

Expand Down Expand Up @@ -254,8 +254,8 @@ content::WebContents* CommonWebContentsDelegate::GetDevToolsWebContents()
}

#if BUILDFLAG(ENABLE_OSR)
OffScreenRenderWidgetHostView*
CommonWebContentsDelegate::GetOffScreenRenderWidgetHostView() const {
OffScreenWebContentsView*
CommonWebContentsDelegate::GetOffScreenWebContentsView() const {
return nullptr;
}
#endif
Expand Down
5 changes: 2 additions & 3 deletions atom/browser/common_web_contents_delegate.h
Expand Up @@ -33,7 +33,7 @@ class NativeWindow;
class WebDialogHelper;

#if BUILDFLAG(ENABLE_OSR)
class OffScreenRenderWidgetHostView;
class OffScreenWebContentsView;
#endif

class CommonWebContentsDelegate : public content::WebContentsDelegate,
Expand Down Expand Up @@ -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:
Expand Down
38 changes: 3 additions & 35 deletions atom/browser/osr/osr_render_widget_host_view.cc
Expand Up @@ -256,16 +256,15 @@ 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),
scale_factor_(kDefaultScaleFactor),
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)),
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -756,7 +736,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)
Expand Down Expand Up @@ -1248,18 +1228,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);

Expand Down
13 changes: 2 additions & 11 deletions atom/browser/osr/osr_render_widget_host_view.h
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand All @@ -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(
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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_; }
float scale_factor() const { return scale_factor_; }

Expand Down Expand Up @@ -307,7 +299,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_;
Expand Down
62 changes: 41 additions & 21 deletions atom/browser/osr/osr_web_contents_view.cc
Expand Up @@ -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
Expand All @@ -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_)
return gfx::NativeView();

auto* relay = NativeWindowRelay::FromWebContents(web_contents_);
if (!relay)
if (!native_window_)
return gfx::NativeView();
return relay->GetNativeWindow()->GetNativeView();
return native_window_->GetNativeView();
}

gfx::NativeView OffScreenWebContentsView::GetContentNativeView() const {
if (!web_contents_)
return gfx::NativeView();

auto* relay = NativeWindowRelay::FromWebContents(web_contents_);
if (!relay)
if (!native_window_)
return gfx::NativeView();
return relay->GetNativeWindow()->GetNativeView();
return native_window_->GetNativeView();
}

gfx::NativeWindow OffScreenWebContentsView::GetTopLevelNativeWindow() const {
if (!web_contents_)
return gfx::NativeWindow();

auto* relay = NativeWindowRelay::FromWebContents(web_contents_);
if (!relay)
if (!native_window_)
return gfx::NativeWindow();
return relay->GetNativeWindow()->GetNativeWindow();
return native_window_->GetNativeWindow();
}
#endif

Expand Down Expand Up @@ -104,7 +124,7 @@ OffScreenWebContentsView::CreateViewForWidget(

return new OffScreenRenderWidgetHostView(
transparent_, painting_, GetFrameRate(), callback_, render_widget_host,
nullptr, nullptr);
nullptr, GetSize());
}

content::RenderWidgetHostViewBase*
Expand All @@ -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) {}
Expand Down
15 changes: 14 additions & 1 deletion atom/browser/osr/osr_web_contents_view.h
Expand Up @@ -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"
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down