Merge pull request #7062 from MaxWhere/osr-sizing-fix

Offscreen invalidate and sizing fix
This commit is contained in:
Cheng Zhao 2016-09-19 15:38:11 +09:00 committed by GitHub
commit a260647b4f
5 changed files with 43 additions and 6 deletions

View file

@ -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<OffScreenRenderWidgetHostView*>(
web_contents()->GetRenderWidgetHostView());
if (osr_rwhv)
osr_rwhv->Invalidate();
}
v8::Local<v8::Value> 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)

View file

@ -164,6 +164,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
bool IsPainting() const;
void SetFrameRate(int frame_rate);
int GetFrameRate() const;
void Invalidate();
// Callback triggered on permission response.
void OnEnterFullscreenModeForTab(content::WebContents* source,

View file

@ -371,6 +371,8 @@ OffScreenRenderWidgetHostView::OffScreenRenderWidgetHostView(
compositor_->SetRootLayer(root_layer_.get());
#endif
native_window_->AddObserver(this);
ResizeRootLayer();
}
@ -439,11 +441,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 +890,16 @@ void OffScreenRenderWidgetHostView::SetupFrameRate(bool force) {
}
}
void OffScreenRenderWidgetHostView::Invalidate() {
const gfx::Rect& bounds_in_pixels = GetViewBounds();
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);
@ -910,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

View file

@ -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);
@ -193,6 +198,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_; }

View file

@ -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`