perf: avoid redundant calls to GetView() (#43216)
* perf: avoid double-calls to GetView() There are a lot of places where we call the virtual method GetView() twice in succession: the first to check if the view exists, and the second to use. This PR holds the view in a temp variable instead, e.g.: if (auto* view = foo->GetView()) view->DoSomething(); * perf: avoid discarded GetView() call
This commit is contained in:
parent
f42331f277
commit
6293bbced0
4 changed files with 20 additions and 28 deletions
|
@ -38,13 +38,14 @@ void FrameSubscriber::AttachToHost(content::RenderWidgetHost* host) {
|
||||||
|
|
||||||
// The view can be null if the renderer process has crashed.
|
// The view can be null if the renderer process has crashed.
|
||||||
// (https://crbug.com/847363)
|
// (https://crbug.com/847363)
|
||||||
if (!host_->GetView())
|
auto* rwhv = host_->GetView();
|
||||||
|
if (!rwhv)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Create and configure the video capturer.
|
// Create and configure the video capturer.
|
||||||
gfx::Size size = GetRenderViewSize();
|
gfx::Size size = GetRenderViewSize();
|
||||||
DCHECK(!size.IsEmpty());
|
DCHECK(!size.IsEmpty());
|
||||||
video_capturer_ = host_->GetView()->CreateVideoCapturer();
|
video_capturer_ = rwhv->CreateVideoCapturer();
|
||||||
video_capturer_->SetResolutionConstraints(size, size, true);
|
video_capturer_->SetResolutionConstraints(size, size, true);
|
||||||
video_capturer_->SetAutoThrottlingEnabled(false);
|
video_capturer_->SetAutoThrottlingEnabled(false);
|
||||||
video_capturer_->SetMinSizeChangePeriod(base::TimeDelta());
|
video_capturer_->SetMinSizeChangePeriod(base::TimeDelta());
|
||||||
|
|
|
@ -565,10 +565,8 @@ OffScreenRenderWidgetHostView::CreateViewForWidget(
|
||||||
content::RenderWidgetHost* render_widget_host,
|
content::RenderWidgetHost* render_widget_host,
|
||||||
content::RenderWidgetHost* embedder_render_widget_host,
|
content::RenderWidgetHost* embedder_render_widget_host,
|
||||||
content::WebContentsView* web_contents_view) {
|
content::WebContentsView* web_contents_view) {
|
||||||
if (render_widget_host->GetView()) {
|
if (auto* rwhv = render_widget_host->GetView())
|
||||||
return static_cast<content::RenderWidgetHostViewBase*>(
|
return static_cast<content::RenderWidgetHostViewBase*>(rwhv);
|
||||||
render_widget_host->GetView());
|
|
||||||
}
|
|
||||||
|
|
||||||
OffScreenRenderWidgetHostView* embedder_host_view = nullptr;
|
OffScreenRenderWidgetHostView* embedder_host_view = nullptr;
|
||||||
if (embedder_render_widget_host) {
|
if (embedder_render_widget_host) {
|
||||||
|
|
|
@ -35,8 +35,8 @@ void OffScreenWebContentsView::SetWebContents(
|
||||||
content::WebContents* web_contents) {
|
content::WebContents* web_contents) {
|
||||||
web_contents_ = web_contents;
|
web_contents_ = web_contents;
|
||||||
|
|
||||||
if (GetView())
|
if (auto* view = GetView())
|
||||||
GetView()->InstallTransparency();
|
view->InstallTransparency();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OffScreenWebContentsView::SetNativeWindow(NativeWindow* window) {
|
void OffScreenWebContentsView::SetNativeWindow(NativeWindow* window) {
|
||||||
|
@ -53,8 +53,8 @@ void OffScreenWebContentsView::SetNativeWindow(NativeWindow* window) {
|
||||||
|
|
||||||
void OffScreenWebContentsView::OnWindowResize() {
|
void OffScreenWebContentsView::OnWindowResize() {
|
||||||
// In offscreen mode call RenderWidgetHostView's SetSize explicitly
|
// In offscreen mode call RenderWidgetHostView's SetSize explicitly
|
||||||
if (GetView())
|
if (auto* view = GetView())
|
||||||
GetView()->SetSize(GetSize());
|
view->SetSize(GetSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
void OffScreenWebContentsView::OnWindowClosed() {
|
void OffScreenWebContentsView::OnWindowClosed() {
|
||||||
|
@ -107,7 +107,9 @@ content::DropData* OffScreenWebContentsView::GetDropData() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
gfx::Rect OffScreenWebContentsView::GetViewBounds() const {
|
gfx::Rect OffScreenWebContentsView::GetViewBounds() const {
|
||||||
return GetView() ? GetView()->GetViewBounds() : gfx::Rect();
|
if (auto* view = GetView())
|
||||||
|
return view->GetViewBounds();
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void OffScreenWebContentsView::CreateView(gfx::NativeView context) {}
|
void OffScreenWebContentsView::CreateView(gfx::NativeView context) {}
|
||||||
|
@ -115,10 +117,8 @@ void OffScreenWebContentsView::CreateView(gfx::NativeView context) {}
|
||||||
content::RenderWidgetHostViewBase*
|
content::RenderWidgetHostViewBase*
|
||||||
OffScreenWebContentsView::CreateViewForWidget(
|
OffScreenWebContentsView::CreateViewForWidget(
|
||||||
content::RenderWidgetHost* render_widget_host) {
|
content::RenderWidgetHost* render_widget_host) {
|
||||||
if (render_widget_host->GetView()) {
|
if (auto* rwhv = render_widget_host->GetView())
|
||||||
return static_cast<content::RenderWidgetHostViewBase*>(
|
return static_cast<content::RenderWidgetHostViewBase*>(rwhv);
|
||||||
render_widget_host->GetView());
|
|
||||||
}
|
|
||||||
|
|
||||||
return new OffScreenRenderWidgetHostView(
|
return new OffScreenRenderWidgetHostView(
|
||||||
transparent_, painting_, GetFrameRate(), callback_, render_widget_host,
|
transparent_, painting_, GetFrameRate(), callback_, render_widget_host,
|
||||||
|
@ -144,8 +144,8 @@ OffScreenWebContentsView::CreateViewForChildWidget(
|
||||||
void OffScreenWebContentsView::SetPageTitle(const std::u16string& title) {}
|
void OffScreenWebContentsView::SetPageTitle(const std::u16string& title) {}
|
||||||
|
|
||||||
void OffScreenWebContentsView::RenderViewReady() {
|
void OffScreenWebContentsView::RenderViewReady() {
|
||||||
if (GetView())
|
if (auto* view = GetView())
|
||||||
GetView()->InstallTransparency();
|
view->InstallTransparency();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OffScreenWebContentsView::RenderViewHostChanged(
|
void OffScreenWebContentsView::RenderViewHostChanged(
|
||||||
|
@ -181,11 +181,9 @@ void OffScreenWebContentsView::UpdateDragOperation(
|
||||||
bool document_is_handling_drag) {}
|
bool document_is_handling_drag) {}
|
||||||
|
|
||||||
void OffScreenWebContentsView::SetPainting(bool painting) {
|
void OffScreenWebContentsView::SetPainting(bool painting) {
|
||||||
auto* view = GetView();
|
|
||||||
painting_ = painting;
|
painting_ = painting;
|
||||||
if (view != nullptr) {
|
if (auto* view = GetView())
|
||||||
view->SetPainting(painting);
|
view->SetPainting(painting);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OffScreenWebContentsView::IsPainting() const {
|
bool OffScreenWebContentsView::IsPainting() const {
|
||||||
|
@ -195,11 +193,9 @@ bool OffScreenWebContentsView::IsPainting() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void OffScreenWebContentsView::SetFrameRate(int frame_rate) {
|
void OffScreenWebContentsView::SetFrameRate(int frame_rate) {
|
||||||
auto* view = GetView();
|
|
||||||
frame_rate_ = frame_rate;
|
frame_rate_ = frame_rate;
|
||||||
if (view != nullptr) {
|
if (auto* view = GetView())
|
||||||
view->SetFrameRate(frame_rate);
|
view->SetFrameRate(frame_rate);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int OffScreenWebContentsView::GetFrameRate() const {
|
int OffScreenWebContentsView::GetFrameRate() const {
|
||||||
|
|
|
@ -191,11 +191,8 @@ void AutofillPopup::CreateView(content::RenderFrameHost* frame_host,
|
||||||
view_ = new AutofillPopupView(this, parent->GetWidget());
|
view_ = new AutofillPopupView(this, parent->GetWidget());
|
||||||
|
|
||||||
if (offscreen) {
|
if (offscreen) {
|
||||||
auto* rwhv = frame_host->GetView();
|
auto* rwhv = embedder_frame_host ? embedder_frame_host->GetView()
|
||||||
if (embedder_frame_host != nullptr) {
|
: frame_host->GetView();
|
||||||
rwhv = embedder_frame_host->GetView();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto* osr_rwhv = static_cast<OffScreenRenderWidgetHostView*>(rwhv);
|
auto* osr_rwhv = static_cast<OffScreenRenderWidgetHostView*>(rwhv);
|
||||||
view_->view_proxy_ = std::make_unique<OffscreenViewProxy>(view_);
|
view_->view_proxy_ = std::make_unique<OffscreenViewProxy>(view_);
|
||||||
osr_rwhv->AddViewProxy(view_->view_proxy_.get());
|
osr_rwhv->AddViewProxy(view_->view_proxy_.get());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue