From b4c220613f7ecb78dec01f64fa5f448f6e65d640 Mon Sep 17 00:00:00 2001 From: gellert Date: Thu, 1 Sep 2016 19:25:12 +0200 Subject: [PATCH 1/5] adds invalidate method and proper resizing --- atom/browser/api/atom_api_web_contents.cc | 10 ++++++++++ atom/browser/api/atom_api_web_contents.h | 1 + atom/browser/native_window.cc | 4 ++++ atom/browser/osr/osr_output_device.cc | 2 ++ atom/browser/osr/osr_render_widget_host_view.cc | 17 ++++++++++++----- atom/browser/osr/osr_render_widget_host_view.h | 2 ++ 6 files changed, 31 insertions(+), 5 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index d9b47d055528..9418162840da 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -1418,6 +1418,15 @@ int WebContents::GetFrameRate() const { return osr_rwhv ? osr_rwhv->GetFrameRate() : 0; } +void WebContents::Invalidate() { + if (!IsOffScreen()) + return; + + auto* osr_rwhv = static_cast( + web_contents()->GetRenderWidgetHostView()); + if (osr_rwhv) + osr_rwhv->Invalidate(); +} v8::Local WebContents::GetWebPreferences(v8::Isolate* isolate) { WebContentsPreferences* web_preferences = @@ -1527,6 +1536,7 @@ void WebContents::BuildPrototype(v8::Isolate* isolate, .SetMethod("isPainting", &WebContents::IsPainting) .SetMethod("setFrameRate", &WebContents::SetFrameRate) .SetMethod("getFrameRate", &WebContents::GetFrameRate) + .SetMethod("invalidate", &WebContents::Invalidate) .SetMethod("getType", &WebContents::GetType) .SetMethod("getWebPreferences", &WebContents::GetWebPreferences) .SetMethod("getOwnerBrowserWindow", &WebContents::GetOwnerBrowserWindow) diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index aa78ec9ae80d..a6b3fd3fd78e 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -164,6 +164,7 @@ class WebContents : public mate::TrackableObject, bool IsPainting() const; void SetFrameRate(int frame_rate); int GetFrameRate() const; + void Invalidate(); // Callback triggered on permission response. void OnEnterFullscreenModeForTab(content::WebContents* source, diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 8dbed6d33df1..1e71a39795a7 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -205,6 +205,10 @@ void NativeWindow::InitFromOptions(const mate::Dictionary& options) { void NativeWindow::SetSize(const gfx::Size& size, bool animate) { SetBounds(gfx::Rect(GetPosition(), size), animate); + + const auto view = web_contents()->GetRenderWidgetHostView(); + if (view) + view->SetSize(size); } gfx::Size NativeWindow::GetSize() { diff --git a/atom/browser/osr/osr_output_device.cc b/atom/browser/osr/osr_output_device.cc index dd806136338e..6245271792ae 100644 --- a/atom/browser/osr/osr_output_device.cc +++ b/atom/browser/osr/osr_output_device.cc @@ -24,6 +24,8 @@ void OffScreenOutputDevice::Resize( const gfx::Size& pixel_size, float scale_factor) { scale_factor_ = scale_factor; + printf("OffScreenOutputDevice::Resize\n"); + if (viewport_pixel_size_ == pixel_size) return; viewport_pixel_size_ = pixel_size; diff --git a/atom/browser/osr/osr_render_widget_host_view.cc b/atom/browser/osr/osr_render_widget_host_view.cc index 606aba3ddd50..bddb604878e2 100644 --- a/atom/browser/osr/osr_render_widget_host_view.cc +++ b/atom/browser/osr/osr_render_widget_host_view.cc @@ -439,11 +439,7 @@ content::RenderWidgetHost* OffScreenRenderWidgetHostView::GetRenderWidgetHost() void OffScreenRenderWidgetHostView::SetSize(const gfx::Size& size) { size_ = size; - const gfx::Size& size_in_pixels = - gfx::ConvertSizeToPixel(scale_factor_, size); - - GetRootLayer()->SetBounds(gfx::Rect(size)); - GetCompositor()->SetScaleAndSize(scale_factor_, size_in_pixels); + ResizeRootLayer(); } void OffScreenRenderWidgetHostView::SetBounds(const gfx::Rect& new_bounds) { @@ -892,6 +888,17 @@ void OffScreenRenderWidgetHostView::SetupFrameRate(bool force) { } } +void OffScreenRenderWidgetHostView::Invalidate() { + const gfx::Rect& bounds_in_pixels = GetViewBounds(); + + printf("Invalidate\n"); + if (software_output_device_) { + software_output_device_->OnPaint(bounds_in_pixels); + } else if (copy_frame_generator_.get()) { + copy_frame_generator_->GenerateCopyFrame(true, bounds_in_pixels); + } +} + void OffScreenRenderWidgetHostView::ResizeRootLayer() { SetupFrameRate(false); diff --git a/atom/browser/osr/osr_render_widget_host_view.h b/atom/browser/osr/osr_render_widget_host_view.h index c6641ec06afb..4ca2685603ed 100644 --- a/atom/browser/osr/osr_render_widget_host_view.h +++ b/atom/browser/osr/osr_render_widget_host_view.h @@ -193,6 +193,8 @@ class OffScreenRenderWidgetHostView ui::Layer* GetRootLayer() const; content::DelegatedFrameHost* GetDelegatedFrameHost() const; + void Invalidate(); + content::RenderWidgetHostImpl* render_widget_host() const { return render_widget_host_; } NativeWindow* window() const { return native_window_; } From 10ea0268e5865e331c5e97c0209ddafa29a9d049 Mon Sep 17 00:00:00 2001 From: gellert Date: Thu, 1 Sep 2016 23:42:40 +0200 Subject: [PATCH 2/5] calling setsize only on osr windows --- atom/browser/native_window.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 1e71a39795a7..a4c8ba57a007 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -11,6 +11,7 @@ #include "atom/browser/atom_browser_context.h" #include "atom/browser/atom_browser_main_parts.h" #include "atom/browser/browser.h" +#include "atom/browser/osr/osr_render_widget_host_view.h" #include "atom/browser/unresponsive_suppressor.h" #include "atom/browser/window_list.h" #include "atom/common/api/api_messages.h" @@ -207,8 +208,11 @@ void NativeWindow::SetSize(const gfx::Size& size, bool animate) { SetBounds(gfx::Rect(GetPosition(), size), animate); const auto view = web_contents()->GetRenderWidgetHostView(); - if (view) - view->SetSize(size); + if (view) { + auto old_size = view->GetViewBounds().size(); + if (old_size != size) + view->SetSize(size); + } } gfx::Size NativeWindow::GetSize() { From 8baaad4e0d80269ab8dfe6c911a3f286c4621acd Mon Sep 17 00:00:00 2001 From: gellert Date: Fri, 2 Sep 2016 00:18:16 +0200 Subject: [PATCH 3/5] cleanup and adds docs --- atom/browser/native_window.cc | 1 + atom/browser/osr/osr_output_device.cc | 2 -- atom/browser/osr/osr_render_widget_host_view.cc | 1 - docs/api/web-contents.md | 5 +++++ 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index a4c8ba57a007..a889f552619c 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -207,6 +207,7 @@ void NativeWindow::InitFromOptions(const mate::Dictionary& options) { void NativeWindow::SetSize(const gfx::Size& size, bool animate) { SetBounds(gfx::Rect(GetPosition(), size), animate); + // In offscreen mode call RenderWidgetHostView's SetSize explicitly const auto view = web_contents()->GetRenderWidgetHostView(); if (view) { auto old_size = view->GetViewBounds().size(); diff --git a/atom/browser/osr/osr_output_device.cc b/atom/browser/osr/osr_output_device.cc index 6245271792ae..dd806136338e 100644 --- a/atom/browser/osr/osr_output_device.cc +++ b/atom/browser/osr/osr_output_device.cc @@ -24,8 +24,6 @@ void OffScreenOutputDevice::Resize( const gfx::Size& pixel_size, float scale_factor) { scale_factor_ = scale_factor; - printf("OffScreenOutputDevice::Resize\n"); - if (viewport_pixel_size_ == pixel_size) return; viewport_pixel_size_ = pixel_size; diff --git a/atom/browser/osr/osr_render_widget_host_view.cc b/atom/browser/osr/osr_render_widget_host_view.cc index bddb604878e2..da41ac4c88a4 100644 --- a/atom/browser/osr/osr_render_widget_host_view.cc +++ b/atom/browser/osr/osr_render_widget_host_view.cc @@ -891,7 +891,6 @@ void OffScreenRenderWidgetHostView::SetupFrameRate(bool force) { void OffScreenRenderWidgetHostView::Invalidate() { const gfx::Rect& bounds_in_pixels = GetViewBounds(); - printf("Invalidate\n"); if (software_output_device_) { software_output_device_->OnPaint(bounds_in_pixels); } else if (copy_frame_generator_.get()) { diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index 55cbfc63c33f..289b0e4b0903 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -1146,6 +1146,11 @@ Only values between 1 and 60 are accepted. If *offscreen rendering* is enabled returns the current frame rate. +#### `contents.invalidate()` + +If *offscreen rendering* is enabled invalidates the frame and generates a new +one through the `'paint'` event. + ### Instance Properties #### `contents.id` From fec5a7d67a3376f26178fe2f7d22345ada101a05 Mon Sep 17 00:00:00 2001 From: gellert Date: Fri, 2 Sep 2016 00:22:27 +0200 Subject: [PATCH 4/5] removes extra header --- atom/browser/native_window.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index a889f552619c..4fa853ca13fa 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -11,7 +11,6 @@ #include "atom/browser/atom_browser_context.h" #include "atom/browser/atom_browser_main_parts.h" #include "atom/browser/browser.h" -#include "atom/browser/osr/osr_render_widget_host_view.h" #include "atom/browser/unresponsive_suppressor.h" #include "atom/browser/window_list.h" #include "atom/common/api/api_messages.h" From 37de2301f7ff09f10c619b46d632098d07aa623e Mon Sep 17 00:00:00 2001 From: gellert Date: Fri, 16 Sep 2016 20:43:07 +0200 Subject: [PATCH 5/5] moves setsize call to osr renderwidgethostview --- atom/browser/native_window.cc | 8 -------- atom/browser/osr/osr_render_widget_host_view.cc | 8 ++++++++ atom/browser/osr/osr_render_widget_host_view.h | 7 ++++++- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 4fa853ca13fa..8dbed6d33df1 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -205,14 +205,6 @@ void NativeWindow::InitFromOptions(const mate::Dictionary& options) { void NativeWindow::SetSize(const gfx::Size& size, bool animate) { SetBounds(gfx::Rect(GetPosition(), size), animate); - - // In offscreen mode call RenderWidgetHostView's SetSize explicitly - const auto view = web_contents()->GetRenderWidgetHostView(); - if (view) { - auto old_size = view->GetViewBounds().size(); - if (old_size != size) - view->SetSize(size); - } } gfx::Size NativeWindow::GetSize() { diff --git a/atom/browser/osr/osr_render_widget_host_view.cc b/atom/browser/osr/osr_render_widget_host_view.cc index da41ac4c88a4..918fced5036b 100644 --- a/atom/browser/osr/osr_render_widget_host_view.cc +++ b/atom/browser/osr/osr_render_widget_host_view.cc @@ -371,6 +371,8 @@ OffScreenRenderWidgetHostView::OffScreenRenderWidgetHostView( compositor_->SetRootLayer(root_layer_.get()); #endif + native_window_->AddObserver(this); + ResizeRootLayer(); } @@ -916,4 +918,10 @@ void OffScreenRenderWidgetHostView::ResizeRootLayer() { GetCompositor()->SetScaleAndSize(scale_factor_, size_in_pixels); } +void OffScreenRenderWidgetHostView::OnWindowResize() { + // In offscreen mode call RenderWidgetHostView's SetSize explicitly + auto size = native_window_->GetSize(); + SetSize(size); +} + } // namespace atom diff --git a/atom/browser/osr/osr_render_widget_host_view.h b/atom/browser/osr/osr_render_widget_host_view.h index 4ca2685603ed..8ea3003a4e5c 100644 --- a/atom/browser/osr/osr_render_widget_host_view.h +++ b/atom/browser/osr/osr_render_widget_host_view.h @@ -13,6 +13,7 @@ #endif #include "atom/browser/native_window.h" +#include "atom/browser/native_window_observer.h" #include "atom/browser/osr/osr_output_device.h" #include "base/process/kill.h" #include "base/threading/thread.h" @@ -60,7 +61,8 @@ class MacHelper; class OffScreenRenderWidgetHostView : public content::RenderWidgetHostViewBase, public ui::CompositorDelegate, - public content::DelegatedFrameHostClient { + public content::DelegatedFrameHostClient, + public NativeWindowObserver { public: OffScreenRenderWidgetHostView(bool transparent, const OnPaintCallback& callback, @@ -172,6 +174,9 @@ class OffScreenRenderWidgetHostView bool IsAutoResizeEnabled() const; void OnSetNeedsBeginFrames(bool enabled); + // NativeWindowObserver: + void OnWindowResize() override; + void OnBeginFrameTimerTick(); void SendBeginFrame(base::TimeTicks frame_time, base::TimeDelta vsync_period);