adds invalidate method and proper resizing

This commit is contained in:
gellert 2016-09-01 19:25:12 +02:00
parent d1274bb79f
commit b4c220613f
6 changed files with 31 additions and 5 deletions

View file

@ -1418,6 +1418,15 @@ int WebContents::GetFrameRate() const {
return osr_rwhv ? osr_rwhv->GetFrameRate() : 0; 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) { v8::Local<v8::Value> WebContents::GetWebPreferences(v8::Isolate* isolate) {
WebContentsPreferences* web_preferences = WebContentsPreferences* web_preferences =
@ -1527,6 +1536,7 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
.SetMethod("isPainting", &WebContents::IsPainting) .SetMethod("isPainting", &WebContents::IsPainting)
.SetMethod("setFrameRate", &WebContents::SetFrameRate) .SetMethod("setFrameRate", &WebContents::SetFrameRate)
.SetMethod("getFrameRate", &WebContents::GetFrameRate) .SetMethod("getFrameRate", &WebContents::GetFrameRate)
.SetMethod("invalidate", &WebContents::Invalidate)
.SetMethod("getType", &WebContents::GetType) .SetMethod("getType", &WebContents::GetType)
.SetMethod("getWebPreferences", &WebContents::GetWebPreferences) .SetMethod("getWebPreferences", &WebContents::GetWebPreferences)
.SetMethod("getOwnerBrowserWindow", &WebContents::GetOwnerBrowserWindow) .SetMethod("getOwnerBrowserWindow", &WebContents::GetOwnerBrowserWindow)

View file

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

View file

@ -205,6 +205,10 @@ void NativeWindow::InitFromOptions(const mate::Dictionary& options) {
void NativeWindow::SetSize(const gfx::Size& size, bool animate) { void NativeWindow::SetSize(const gfx::Size& size, bool animate) {
SetBounds(gfx::Rect(GetPosition(), size), animate); SetBounds(gfx::Rect(GetPosition(), size), animate);
const auto view = web_contents()->GetRenderWidgetHostView();
if (view)
view->SetSize(size);
} }
gfx::Size NativeWindow::GetSize() { gfx::Size NativeWindow::GetSize() {

View file

@ -24,6 +24,8 @@ void OffScreenOutputDevice::Resize(
const gfx::Size& pixel_size, float scale_factor) { const gfx::Size& pixel_size, float scale_factor) {
scale_factor_ = scale_factor; scale_factor_ = scale_factor;
printf("OffScreenOutputDevice::Resize\n");
if (viewport_pixel_size_ == pixel_size) return; if (viewport_pixel_size_ == pixel_size) return;
viewport_pixel_size_ = pixel_size; viewport_pixel_size_ = pixel_size;

View file

@ -439,11 +439,7 @@ content::RenderWidgetHost* OffScreenRenderWidgetHostView::GetRenderWidgetHost()
void OffScreenRenderWidgetHostView::SetSize(const gfx::Size& size) { void OffScreenRenderWidgetHostView::SetSize(const gfx::Size& size) {
size_ = size; size_ = size;
const gfx::Size& size_in_pixels = ResizeRootLayer();
gfx::ConvertSizeToPixel(scale_factor_, size);
GetRootLayer()->SetBounds(gfx::Rect(size));
GetCompositor()->SetScaleAndSize(scale_factor_, size_in_pixels);
} }
void OffScreenRenderWidgetHostView::SetBounds(const gfx::Rect& new_bounds) { 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() { void OffScreenRenderWidgetHostView::ResizeRootLayer() {
SetupFrameRate(false); SetupFrameRate(false);

View file

@ -193,6 +193,8 @@ class OffScreenRenderWidgetHostView
ui::Layer* GetRootLayer() const; ui::Layer* GetRootLayer() const;
content::DelegatedFrameHost* GetDelegatedFrameHost() const; content::DelegatedFrameHost* GetDelegatedFrameHost() const;
void Invalidate();
content::RenderWidgetHostImpl* render_widget_host() const content::RenderWidgetHostImpl* render_widget_host() const
{ return render_widget_host_; } { return render_widget_host_; }
NativeWindow* window() const { return native_window_; } NativeWindow* window() const { return native_window_; }