From f60d791fa80e0666f6c9778b89824e381f0ba764 Mon Sep 17 00:00:00 2001 From: gellert Date: Sun, 31 Jul 2016 00:22:34 +0200 Subject: [PATCH] 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`