From 976277ffbfb02b5478cbc244b1037bbc10395a3a Mon Sep 17 00:00:00 2001 From: gellert Date: Sat, 30 Jul 2016 20:39:17 +0200 Subject: [PATCH 1/5] webcontentsview cleanup --- atom/browser/osr_web_contents_view.cc | 104 ++++++-------------------- atom/browser/osr_web_contents_view.h | 5 +- 2 files changed, 22 insertions(+), 87 deletions(-) diff --git a/atom/browser/osr_web_contents_view.cc b/atom/browser/osr_web_contents_view.cc index 8c5a801dab2f..fde98ba9c55a 100644 --- a/atom/browser/osr_web_contents_view.cc +++ b/atom/browser/osr_web_contents_view.cc @@ -3,9 +3,7 @@ // found in the LICENSE file. #include "atom/browser/osr_web_contents_view.h" - #include "atom/browser/osr_render_widget_host_view.h" -#include namespace atom { @@ -21,138 +19,79 @@ void OffScreenWebContentsView::SetWebContents( web_contents_ = web_contents; } -// Returns the native widget that contains the contents of the tab. -gfx::NativeView OffScreenWebContentsView::GetNativeView() const{ - // std::cout << "GetNativeView" << std::endl; +gfx::NativeView OffScreenWebContentsView::GetNativeView() const { return gfx::NativeView(); } -// Returns the native widget with the main content of the tab (i.e. the main -// render view host, though there may be many popups in the tab as children of -// the container). -gfx::NativeView OffScreenWebContentsView::GetContentNativeView() const{ - // std::cout << "GetContentNativeView" << std::endl; +gfx::NativeView OffScreenWebContentsView::GetContentNativeView() const { return gfx::NativeView(); } -// Returns the outermost native view. This will be used as the parent for -// dialog boxes. -gfx::NativeWindow OffScreenWebContentsView::GetTopLevelNativeWindow() const{ - // std::cout << "GetTopLevelNativeWindow" << std::endl; +gfx::NativeWindow OffScreenWebContentsView::GetTopLevelNativeWindow() const { return gfx::NativeWindow(); } -// Computes the rectangle for the native widget that contains the contents of -// the tab in the screen coordinate system. -void OffScreenWebContentsView::GetContainerBounds(gfx::Rect* out) const{ - // std::cout << "GetContainerBounds" << std::endl; +void OffScreenWebContentsView::GetContainerBounds(gfx::Rect* out) const { *out = GetViewBounds(); } -// TODO(brettw) this is a hack. It's used in two places at the time of this -// writing: (1) when render view hosts switch, we need to size the replaced -// one to be correct, since it wouldn't have known about sizes that happened -// while it was hidden; (2) in constrained windows. -// -// (1) will be fixed once interstitials are cleaned up. (2) seems like it -// should be cleaned up or done some other way, since this works for normal -// WebContents without the special code. -void OffScreenWebContentsView::SizeContents(const gfx::Size& size){ - // std::cout << "SizeContents" << std::endl; +void OffScreenWebContentsView::SizeContents(const gfx::Size& size) { } -// Sets focus to the native widget for this tab. -void OffScreenWebContentsView::Focus(){ - // std::cout << "OffScreenWebContentsView::Focus" << std::endl; +void OffScreenWebContentsView::Focus() { } -// Sets focus to the appropriate element when the WebContents is shown the -// first time. -void OffScreenWebContentsView::SetInitialFocus(){ - // std::cout << "SetInitialFocus" << std::endl; +void OffScreenWebContentsView::SetInitialFocus() { } -// Stores the currently focused view. -void OffScreenWebContentsView::StoreFocus(){ - // std::cout << "StoreFocus" << std::endl; +void OffScreenWebContentsView::StoreFocus() { } -// Restores focus to the last focus view. If StoreFocus has not yet been -// invoked, SetInitialFocus is invoked. -void OffScreenWebContentsView::RestoreFocus(){ - // std::cout << "RestoreFocus" << std::endl; +void OffScreenWebContentsView::RestoreFocus() { } -// Returns the current drop data, if any. -content::DropData* OffScreenWebContentsView::GetDropData() const{ - // std::cout << "GetDropData" << std::endl; +content::DropData* OffScreenWebContentsView::GetDropData() const { return nullptr; } -// Get the bounds of the View, relative to the parent. -gfx::Rect OffScreenWebContentsView::GetViewBounds() const{ - // std::cout << "OffScreenWebContentsView::GetViewBounds" << std::endl; +gfx::Rect OffScreenWebContentsView::GetViewBounds() const { return view_ ? view_->GetViewBounds() : gfx::Rect(); } -void OffScreenWebContentsView::CreateView( - const gfx::Size& initial_size, gfx::NativeView context){ - std::cout << context << std::endl; - // std::cout << "CreateView" << std::endl; - // std::cout << initial_size.width() << "x" << initial_size.height() << std::endl; +void OffScreenWebContentsView::CreateView(const gfx::Size& initial_size, + gfx::NativeView context) { } -// Sets up the View that holds the rendered web page, receives messages for -// it and contains page plugins. The host view should be sized to the current -// size of the WebContents. -// -// |is_guest_view_hack| is temporary hack and will be removed once -// RenderWidgetHostViewGuest is not dependent on platform view. -// TODO(lazyboy): Remove |is_guest_view_hack| once http://crbug.com/330264 is -// fixed. content::RenderWidgetHostViewBase* OffScreenWebContentsView::CreateViewForWidget( - content::RenderWidgetHost* render_widget_host, bool is_guest_view_hack){ + content::RenderWidgetHost* render_widget_host, bool is_guest_view_hack) { auto relay = NativeWindowRelay::FromWebContents(web_contents_); view_ = new OffScreenRenderWidgetHostView(render_widget_host, relay->window.get()); return view_; } -// Creates a new View that holds a popup and receives messages for it. content::RenderWidgetHostViewBase* OffScreenWebContentsView::CreateViewForPopupWidget( - content::RenderWidgetHost* render_widget_host){ + content::RenderWidgetHost* render_widget_host) { auto relay = NativeWindowRelay::FromWebContents(web_contents_); view_ = new OffScreenRenderWidgetHostView(render_widget_host, relay->window.get()); return view_; } -// Sets the page title for the native widgets corresponding to the view. This -// is not strictly necessary and isn't expected to be displayed anywhere, but -// can aid certain debugging tools such as Spy++ on Windows where you are -// trying to find a specific window. -void OffScreenWebContentsView::SetPageTitle(const base::string16& title){ - // std::cout << "SetPageTitle" << std::endl; - // std::cout << title << std::endl; +void OffScreenWebContentsView::SetPageTitle(const base::string16& title) { } -// Invoked when the WebContents is notified that the RenderView has been -// fully created. -void OffScreenWebContentsView::RenderViewCreated(content::RenderViewHost* host){ - // std::cout << "RenderViewCreated" << std::endl; +void OffScreenWebContentsView::RenderViewCreated( + content::RenderViewHost* host) { } -// Invoked when the WebContents is notified that the RenderView has been -// swapped in. -void OffScreenWebContentsView::RenderViewSwappedIn(content::RenderViewHost* host){ - // std::cout << "RenderViewSwappedIn" << std::endl; +void OffScreenWebContentsView::RenderViewSwappedIn( + content::RenderViewHost* host) { } -// Invoked to enable/disable overscroll gesture navigation. -void OffScreenWebContentsView::SetOverscrollControllerEnabled(bool enabled){ - // std::cout << "SetOverscrollControllerEnabled" << std::endl; +void OffScreenWebContentsView::SetOverscrollControllerEnabled(bool enabled) { } #if defined(OS_MACOSX) @@ -183,5 +122,4 @@ void OffScreenWebContentsView::UpdateDragCursor( blink::WebDragOperation operation) { } - } // namespace atom diff --git a/atom/browser/osr_web_contents_view.h b/atom/browser/osr_web_contents_view.h index cbc46625203c..16774fd72027 100644 --- a/atom/browser/osr_web_contents_view.h +++ b/atom/browser/osr_web_contents_view.h @@ -20,10 +20,10 @@ public: void SetWebContents(content::WebContents*); + // content::WebContentsView gfx::NativeView GetNativeView() const override; gfx::NativeView GetContentNativeView() const override; gfx::NativeWindow GetTopLevelNativeWindow() const override; - void GetContainerBounds(gfx::Rect* out) const override; void SizeContents(const gfx::Size& size) override; void Focus() override; @@ -32,16 +32,13 @@ public: void RestoreFocus() override; content::DropData* GetDropData() const override; gfx::Rect GetViewBounds() const override; - void CreateView( const gfx::Size& initial_size, gfx::NativeView context) override; - content::RenderWidgetHostViewBase* CreateViewForWidget( content::RenderWidgetHost* render_widget_host, bool is_guest_view_hack) override; content::RenderWidgetHostViewBase* CreateViewForPopupWidget( content::RenderWidgetHost* render_widget_host) override; - void SetPageTitle(const base::string16& title) override; void RenderViewCreated(content::RenderViewHost* host) override; void RenderViewSwappedIn(content::RenderViewHost* host) override; From 916063f370392c37a8815cf2d3b561d42e69b662 Mon Sep 17 00:00:00 2001 From: gellert Date: Sat, 30 Jul 2016 21:25:49 +0200 Subject: [PATCH 2/5] handles destroyed renderer process --- atom/browser/api/atom_api_web_contents.cc | 14 -------------- atom/browser/api/atom_api_web_contents.h | 1 - atom/browser/osr_render_widget_host_view.cc | 3 ++- atom/browser/osr_render_widget_host_view_mac.mm | 13 ++++++------- 4 files changed, 8 insertions(+), 23 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 770b6b347ee4..073edf7079fb 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -402,14 +402,6 @@ void WebContents::OnCreateWindow(const GURL& target_url, Emit("new-window", target_url, frame_name, disposition); } -void WebContents::RenderViewReady() { - // if (IsOffScreen()) { - // const auto rwhv = web_contents()->GetRenderWidgetHostView(); - // auto osr_rwhv = static_cast(rwhv); - // osr_rwhv->SetPaintCallback(&paint_callback_); - // } -} - content::WebContents* WebContents::OpenURLFromTab( content::WebContents* source, const content::OpenURLParams& params) { @@ -445,12 +437,6 @@ void WebContents::MoveContents(content::WebContents* source, void WebContents::CloseContents(content::WebContents* source) { Emit("close"); - if (IsOffScreen()) { - const auto osr_rwhv = static_cast( - web_contents()->GetRenderWidgetHostView()); - osr_rwhv->SetPainting(false); - } - if ((type_ == BROWSER_WINDOW || type_ == OFF_SCREEN) && owner_window()) owner_window()->CloseContents(source); } diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index 5294277d9651..1587bec34bd4 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -278,7 +278,6 @@ class WebContents : public mate::TrackableObject, void MediaStartedPlaying(const MediaPlayerId& id) override; void MediaStoppedPlaying(const MediaPlayerId& id) override; void DidChangeThemeColor(SkColor theme_color) override; - void RenderViewReady() override; // brightray::InspectableWebContentsDelegate: void DevToolsReloadPage() override; diff --git a/atom/browser/osr_render_widget_host_view.cc b/atom/browser/osr_render_widget_host_view.cc index c73ee8ff4d5f..89023d41b3d5 100644 --- a/atom/browser/osr_render_widget_host_view.cc +++ b/atom/browser/osr_render_widget_host_view.cc @@ -619,6 +619,7 @@ void OffScreenRenderWidgetHostView::RenderProcessGone(base::TerminationStatus,in } void OffScreenRenderWidgetHostView::Destroy() { + delete this; } void OffScreenRenderWidgetHostView::SetTooltipText(const base::string16 &) { @@ -740,7 +741,7 @@ void OffScreenRenderWidgetHostView::DelegatedFrameHostSendCompositorSwapAck( } void OffScreenRenderWidgetHostView::DelegatedFrameHostSendReclaimCompositorResources( - int output_surface_id, const cc::CompositorFrameAck& ack) { + int output_surface_id, const cc::CompositorFrameAck& ack) { render_widget_host_->Send(new ViewMsg_ReclaimCompositorResources( render_widget_host_->GetRoutingID(), output_surface_id, ack)); diff --git a/atom/browser/osr_render_widget_host_view_mac.mm b/atom/browser/osr_render_widget_host_view_mac.mm index f1463ec1a7c9..6dc50d2ff0db 100644 --- a/atom/browser/osr_render_widget_host_view_mac.mm +++ b/atom/browser/osr_render_widget_host_view_mac.mm @@ -1,9 +1,12 @@ +// Copyright (c) 2013 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + #include "atom/browser/osr_render_widget_host_view.h" #include #include #include -#include #import @@ -20,7 +23,8 @@ ui::AcceleratedWidgetMac* atom::OffScreenRenderWidgetHostView::GetAcceleratedWid return nullptr; } -NSView* atom::OffScreenRenderWidgetHostView::AcceleratedWidgetGetNSView() const { +NSView* atom::OffScreenRenderWidgetHostView::AcceleratedWidgetGetNSView() + const { return [window_ contentView]; } @@ -75,13 +79,11 @@ void atom::OffScreenRenderWidgetHostView::SelectionChanged( } void atom::OffScreenRenderWidgetHostView::CreatePlatformWidget() { - // Create a borderless non-visible 1x1 window. window_ = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 1, 1) styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]; - // Create a CALayer which is used by BrowserCompositorViewMac for rendering. background_layer_ = [[[CALayer alloc] init] retain]; [background_layer_ setBackgroundColor:CGColorGetConstantColor(kCGColorClear)]; NSView* content_view = [window_ contentView]; @@ -95,9 +97,6 @@ void atom::OffScreenRenderWidgetHostView::CreatePlatformWidget() { browser_compositor_->accelerated_widget_mac()->SetNSView(this); browser_compositor_->compositor()->SetVisible(true); - // CEF needs the browser compositor to remain responsive whereas normal - // rendering on OS X does not. This effectively reverts the changes from - // https://crbug.com/463988#c6 compositor_->SetLocksWillTimeOut(true); browser_compositor_->Unsuspend(); } From e4000850cd3b83aefd32fe92d5188eead851b927 Mon Sep 17 00:00:00 2001 From: gellert Date: Sat, 30 Jul 2016 21:35:14 +0200 Subject: [PATCH 3/5] head part updates --- atom/browser/osr_output_device.cc | 15 ++++----------- atom/browser/osr_output_device.h | 3 +-- atom/browser/osr_render_widget_host_view.cc | 6 +----- atom/browser/osr_render_widget_host_view.h | 2 +- atom/browser/osr_render_widget_host_view_mac.mm | 2 +- atom/browser/osr_render_widget_host_view_win.cc | 2 +- atom/browser/osr_web_contents_view.cc | 2 +- atom/browser/osr_web_contents_view.h | 2 +- 8 files changed, 11 insertions(+), 23 deletions(-) diff --git a/atom/browser/osr_output_device.cc b/atom/browser/osr_output_device.cc index 8e6b5b02a9dd..21b7991d9c92 100644 --- a/atom/browser/osr_output_device.cc +++ b/atom/browser/osr_output_device.cc @@ -1,18 +1,17 @@ -// Copyright (c) 2013 GitHub, Inc. +// Copyright (c) 2016 GitHub, Inc. // Use of this source code is governed by the MIT license that can be // found in the LICENSE file. #include "atom/browser/osr_output_device.h" -#include #include "third_party/skia/include/core/SkDevice.h" #include "ui/gfx/skia_util.h" namespace atom { OffScreenOutputDevice::OffScreenOutputDevice(bool transparent, - const OnPaintCallback& callback) - : transparent_(transparent), + const OnPaintCallback& callback): + transparent_(transparent), callback_(callback), active_(false) { DCHECK(!callback_.is_null()); @@ -21,9 +20,7 @@ OffScreenOutputDevice::OffScreenOutputDevice(bool transparent, OffScreenOutputDevice::~OffScreenOutputDevice() { } void OffScreenOutputDevice::Resize( - const gfx::Size& pixel_size, float scale_factor) { - std::cout << pixel_size.width() << "x" << pixel_size.height() << std::endl; - + const gfx::Size& pixel_size, float scale_factor) { scale_factor_ = scale_factor; if (viewport_pixel_size_ == pixel_size) return; @@ -47,7 +44,6 @@ void OffScreenOutputDevice::Resize( } SkCanvas* OffScreenOutputDevice::BeginPaint(const gfx::Rect& damage_rect) { - // std::cout << "BeginPaint" << std::endl; DCHECK(canvas_.get()); DCHECK(bitmap_.get()); @@ -57,8 +53,6 @@ SkCanvas* OffScreenOutputDevice::BeginPaint(const gfx::Rect& damage_rect) { } void OffScreenOutputDevice::EndPaint() { - // std::cout << "EndPaint" << std::endl; - DCHECK(canvas_.get()); DCHECK(bitmap_.get()); @@ -75,7 +69,6 @@ void OffScreenOutputDevice::SetActive(bool active) { return; active_ = active; - // Call OnPaint immediately if deactivated while a damage rect is pending. if (!active_ && !pending_damage_rect_.IsEmpty()) OnPaint(pending_damage_rect_); } diff --git a/atom/browser/osr_output_device.h b/atom/browser/osr_output_device.h index 1940b417d053..a593f3a3829b 100644 --- a/atom/browser/osr_output_device.h +++ b/atom/browser/osr_output_device.h @@ -1,4 +1,4 @@ -// Copyright (c) 2013 GitHub, Inc. +// Copyright (c) 2016 GitHub, Inc. // Use of this source code is governed by the MIT license that can be // found in the LICENSE file. @@ -9,7 +9,6 @@ #include "cc/output/software_output_device.h" #include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkCanvas.h" -#include "base/callback.h" namespace atom { diff --git a/atom/browser/osr_render_widget_host_view.cc b/atom/browser/osr_render_widget_host_view.cc index 89023d41b3d5..0c1d6c27da19 100644 --- a/atom/browser/osr_render_widget_host_view.cc +++ b/atom/browser/osr_render_widget_host_view.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2013 GitHub, Inc. +// Copyright (c) 2016 GitHub, Inc. // Use of this source code is governed by the MIT license that can be // found in the LICENSE file. @@ -26,14 +26,10 @@ #include "cc/scheduler/delay_based_time_source.h" #include "content/public/browser/browser_thread.h" -#include - const float kDefaultScaleFactor = 1.0; const int kFrameRetryLimit = 2; -// const int kResizeLockTimeoutMs = 67; - namespace atom { class AtomCopyFrameGenerator { diff --git a/atom/browser/osr_render_widget_host_view.h b/atom/browser/osr_render_widget_host_view.h index feb7ec4a6ca1..3463c2b801b4 100644 --- a/atom/browser/osr_render_widget_host_view.h +++ b/atom/browser/osr_render_widget_host_view.h @@ -1,4 +1,4 @@ -// Copyright (c) 2013 GitHub, Inc. +// Copyright (c) 2016 GitHub, Inc. // Use of this source code is governed by the MIT license that can be // found in the LICENSE file. diff --git a/atom/browser/osr_render_widget_host_view_mac.mm b/atom/browser/osr_render_widget_host_view_mac.mm index 6dc50d2ff0db..d538bb6d93ec 100644 --- a/atom/browser/osr_render_widget_host_view_mac.mm +++ b/atom/browser/osr_render_widget_host_view_mac.mm @@ -1,4 +1,4 @@ -// Copyright (c) 2013 GitHub, Inc. +// Copyright (c) 2016 GitHub, Inc. // Use of this source code is governed by the MIT license that can be // found in the LICENSE file. diff --git a/atom/browser/osr_render_widget_host_view_win.cc b/atom/browser/osr_render_widget_host_view_win.cc index f90d1cf676dd..285f4212c8ff 100644 --- a/atom/browser/osr_render_widget_host_view_win.cc +++ b/atom/browser/osr_render_widget_host_view_win.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2013 GitHub, Inc. +// Copyright (c) 2016 GitHub, Inc. // Use of this source code is governed by the MIT license that can be // found in the LICENSE file. diff --git a/atom/browser/osr_web_contents_view.cc b/atom/browser/osr_web_contents_view.cc index fde98ba9c55a..4d03f5ed9e51 100644 --- a/atom/browser/osr_web_contents_view.cc +++ b/atom/browser/osr_web_contents_view.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2013 GitHub, Inc. +// Copyright (c) 2016 GitHub, Inc. // Use of this source code is governed by the MIT license that can be // found in the LICENSE file. diff --git a/atom/browser/osr_web_contents_view.h b/atom/browser/osr_web_contents_view.h index 16774fd72027..efab017fd90b 100644 --- a/atom/browser/osr_web_contents_view.h +++ b/atom/browser/osr_web_contents_view.h @@ -1,4 +1,4 @@ -// Copyright (c) 2013 GitHub, Inc. +// Copyright (c) 2016 GitHub, Inc. // Use of this source code is governed by the MIT license that can be // found in the LICENSE file. From f60d791fa80e0666f6c9778b89824e381f0ba764 Mon Sep 17 00:00:00 2001 From: gellert Date: Sun, 31 Jul 2016 00:22:34 +0200 Subject: [PATCH 4/5] adds docs for osr --- atom/browser/api/atom_api_web_contents.cc | 4 +- .../osr_render_widget_host_view_mac.mm | 7 --- atom/browser/web_contents_preferences.cc | 2 - docs/api/browser-window.md | 2 + docs/api/chrome-command-line-switches.md | 30 ++++++++++ docs/api/web-contents.md | 56 +++++++++++++++++++ 6 files changed, 90 insertions(+), 11 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 073edf7079fb..0d18e74d8e8c 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -1396,8 +1396,8 @@ void WebContents::OnPaint( v8::MaybeLocal buffer = node::Buffer::New(isolate , (char *)bitmap_pixels, sizeof(bitmap_pixels)); - Emit("paint", damage_rect, bitmap_width, bitmap_height, - buffer.ToLocalChecked()); + const gfx::Size bitmap_size = gfx::Size(bitmap_width, bitmap_height); + Emit("paint", damage_rect, buffer.ToLocalChecked(), bitmap_size); } void WebContents::StartPainting() { diff --git a/atom/browser/osr_render_widget_host_view_mac.mm b/atom/browser/osr_render_widget_host_view_mac.mm index d538bb6d93ec..1ef240027b30 100644 --- a/atom/browser/osr_render_widget_host_view_mac.mm +++ b/atom/browser/osr_render_widget_host_view_mac.mm @@ -4,17 +4,10 @@ #include "atom/browser/osr_render_widget_host_view.h" -#include -#include -#include - #import -#include "base/compiler_specific.h" #include "base/strings/utf_string_conversions.h" -#include "content/common/view_messages.h" #include "ui/accelerated_widget_mac/accelerated_widget_mac.h" -#include "ui/events/latency_info.h" ui::AcceleratedWidgetMac* atom::OffScreenRenderWidgetHostView::GetAcceleratedWidgetMac() const { diff --git a/atom/browser/web_contents_preferences.cc b/atom/browser/web_contents_preferences.cc index a019f5f12867..8ad46aaf8425 100644 --- a/atom/browser/web_contents_preferences.cc +++ b/atom/browser/web_contents_preferences.cc @@ -189,8 +189,6 @@ void WebContentsPreferences::AppendExtraCommandLineSwitches( command_line->AppendSwitch(cc::switches::kEnableBeginFrameScheduling); command_line->AppendSwitch(cc::switches::kShowFPSCounter); - // command_line->AppendSwitch("disable-gpu"); - // command_line->AppendSwitch("disable-gpu-compositing"); } // static diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 73d53ed875c3..f44a7ddeeb93 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -274,6 +274,8 @@ The `webPreferences` option is an object that can have the following properties: * `defaultEncoding` String - Defaults to `ISO-8859-1`. * `backgroundThrottling` Boolean - Whether to throttle animations and timers when the page becomes background. Defaults to `true`. +* `offscreen` Boolean - Whether to enable offscreen rendering for the browser + window. Defaults to `false`. ### Instance Events diff --git a/docs/api/chrome-command-line-switches.md b/docs/api/chrome-command-line-switches.md index 4fe6d136da2b..92b52ff00b38 100644 --- a/docs/api/chrome-command-line-switches.md +++ b/docs/api/chrome-command-line-switches.md @@ -174,6 +174,36 @@ logging level for all code in the source files under a `foo/bar` directory. This switch only works when `--enable-logging` is also passed. +## --disable-gpu + +Disables the use of the GPU in the renderer process. If this is set with the +`--disable-gpu-compositing` switch, *offscreen rendering* will use a software +output device, which has much better overall performance but lacks of WebGL +and 3D CSS support. + +## --disable-gpu-compositing + +Disables the use of the GPU compositing in the renderer process. This should be +set with the `--disable-gpu` switch for *offscreen rendering*. + +``` javascript +const {app, BrowserWindow} = require('electron'); + +app.commandLine.appendSwitch('disable-gpu'); +app.commandLine.appendSwitch('disable-gpu-compositing'); + +let win = new BrowserWindow({ + webPreferences: { + offscreen: true + } +}); +win.loadURL('http://github.com'); + +win.webContents.on('paint', (event, dirty, data) => { + updateBitmap(dirty, data); +}); +``` + [app]: app.md [append-switch]: app.md#appcommandlineappendswitchswitch-value [ready]: app.md#event-ready diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index 714d61eced95..2d7c4e1708d7 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -452,6 +452,41 @@ app.on('ready', () => { Emitted when a page's view is repainted. +#### Event: 'paint' + +Returns: + +* `event` Event +* `dirtyRect` Object + * `x` Number - the x coordinate on the bitmap + * `y` Number - the y coordinate on the bitmap + * `width` Number - the width of the dirty area + * `height` Number - the height of the dirty area +* `data` Buffer - the bitmap data of the dirty rect +* `bitmapSize` Object + * `width` Number - the width of the whole bitmap + * `height` Number - the height of the whole bitmap + +Emitted when a new frame is generated. Only the dirty area is passed in the +buffer. + +```javascript +const {BrowserWindow} = require('electron'); + +let win = new BrowserWindow({ + width: 800, + height: 1500, + webPreferences: { + offscreen: true + } +}); +win.loadURL('http://github.com'); + +win.webContents.on('paint', (event, dirty, data) => { + updateBitmap(dirty, data); +}); +``` + ### Instance Methods #### `contents.loadURL(url[, options])` @@ -1024,6 +1059,27 @@ win.webContents.on('did-finish-load', () => { Shows pop-up dictionary that searches the selected word on the page. +#### `contents.startPainting()` + +If *offscreen rendering* is enabled and not painting, start painting. + +#### `contents.stopPainting()` + +If *offscreen rendering* is enabled and painting, stop painting. + +#### `contents.isPainting()` + +If *offscreen rendering* is enabled returns whether it is currently painting. + +#### `contents.setFrameRate(fps)` + +If *offscreen rendering* is enabled sets the frame rate to the specified number. +Only values between 1 and 60 are accepted. + +#### `contents.getFrameRate()` + +If *offscreen rendering* is enabled returns the current frame rate. + ### Instance Properties #### `contents.id` From 092fc92cb89360d60ee1dd40704b6e0fc2b4c320 Mon Sep 17 00:00:00 2001 From: gellert Date: Sun, 31 Jul 2016 00:47:08 +0200 Subject: [PATCH 5/5] adds tutorial --- docs/tutorial/offscreen-rendering.md | 58 ++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 docs/tutorial/offscreen-rendering.md diff --git a/docs/tutorial/offscreen-rendering.md b/docs/tutorial/offscreen-rendering.md new file mode 100644 index 000000000000..4f0e89bb565d --- /dev/null +++ b/docs/tutorial/offscreen-rendering.md @@ -0,0 +1,58 @@ +# Offscreen Rendering + +Offscreen rendering lets you obtain the content of a browser window in a bitmap, +so it can be rendered anywhere, for example on a texture in a 3D scene. The +offscreen rendering in Electron uses a similar approach than the [Chromium +Embedded Framework](https://bitbucket.org/chromiumembedded/cef) project. + +Two modes of rendering can be used and only the dirty area is passed in the +`'paint'` event to be more efficient. The rendering can be stopped, continued +and the frame rate can be set. The specified frame rate is a top limit value, +when there is nothing happening on a webpage, no frames are generated. The +maximum frame rate is 60, because above that there is no benefit, just +performance loss. + +## Two modes of rendering + +### GPU accelerated + +GPU accelerated rendering means that the GPU is used for composition. Because of +that the frame has to be copied from the GPU which requires more performance, +thus this mode is quite a bit slower than the other one. The benefit of this +mode that WebGL and 3D CSS animations are supported. + +### Software output device + +This mode uses a software output device for rendering in the CPU, so the frame +generation is much faster, thus this mode is preferred over the GPU accelerated +one. To enable this mode GPU acceleration has to be disabled like this: +``` javascript +const {app} = require('electron'); + +app.commandLine.appendSwitch('disable-gpu'); +app.commandLine.appendSwitch('disable-gpu-compositing'); +``` + +## Usage + +``` javascript +const {app, BrowserWindow} = require('electron'); + +app.commandLine.appendSwitch('disable-gpu'); +app.commandLine.appendSwitch('disable-gpu-compositing'); + +let win = new BrowserWindow({ + width: 800, + height: 1500, + webPreferences: { + offscreen: true + } +}); +win.loadURL('http://github.com'); + +win.webContents.setFrameRate(30); + +win.webContents.on('paint', (event, dirty, data) => { + updateBitmap(dirty, data); +}); +```