Merge pull request #6244 from electron/frame-subscription-cleanup
Cleanup code of beginFrameSubscription
This commit is contained in:
commit
7d38384bdd
5 changed files with 40 additions and 24 deletions
|
@ -1181,15 +1181,14 @@ void WebContents::SendInputEvent(v8::Isolate* isolate,
|
||||||
isolate, "Invalid event object")));
|
isolate, "Invalid event object")));
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContents::BeginFrameSubscription(
|
void WebContents::BeginFrameSubscription(mate::Arguments* args) {
|
||||||
mate::Arguments* args) {
|
|
||||||
FrameSubscriber::FrameCaptureCallback callback;
|
|
||||||
bool only_dirty = false;
|
bool only_dirty = false;
|
||||||
|
FrameSubscriber::FrameCaptureCallback callback;
|
||||||
|
|
||||||
if (!args->GetNext(&callback)) {
|
|
||||||
args->GetNext(&only_dirty);
|
args->GetNext(&only_dirty);
|
||||||
if (!args->GetNext(&callback))
|
if (!args->GetNext(&callback)) {
|
||||||
args->ThrowTypeError("'callback' must be defined");
|
args->ThrowError();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto view = web_contents()->GetRenderWidgetHostView();
|
const auto view = web_contents()->GetRenderWidgetHostView();
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
#include "atom/browser/api/frame_subscriber.h"
|
#include "atom/browser/api/frame_subscriber.h"
|
||||||
|
|
||||||
#include "base/bind.h"
|
#include "base/bind.h"
|
||||||
#include "atom/common/node_includes.h"
|
|
||||||
#include "atom/common/native_mate_converters/gfx_converter.h"
|
#include "atom/common/native_mate_converters/gfx_converter.h"
|
||||||
|
#include "atom/common/node_includes.h"
|
||||||
#include "content/public/browser/render_widget_host.h"
|
#include "content/public/browser/render_widget_host.h"
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
@ -17,8 +17,11 @@ FrameSubscriber::FrameSubscriber(v8::Isolate* isolate,
|
||||||
content::RenderWidgetHostView* view,
|
content::RenderWidgetHostView* view,
|
||||||
const FrameCaptureCallback& callback,
|
const FrameCaptureCallback& callback,
|
||||||
bool only_dirty)
|
bool only_dirty)
|
||||||
: isolate_(isolate), view_(view), callback_(callback),
|
: isolate_(isolate),
|
||||||
only_dirty_(only_dirty), weak_factory_(this) {
|
view_(view),
|
||||||
|
callback_(callback),
|
||||||
|
only_dirty_(only_dirty),
|
||||||
|
weak_factory_(this) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FrameSubscriber::ShouldCaptureFrame(
|
bool FrameSubscriber::ShouldCaptureFrame(
|
||||||
|
@ -48,7 +51,8 @@ bool FrameSubscriber::ShouldCaptureFrame(
|
||||||
}
|
}
|
||||||
|
|
||||||
void FrameSubscriber::OnFrameDelivered(const FrameCaptureCallback& callback,
|
void FrameSubscriber::OnFrameDelivered(const FrameCaptureCallback& callback,
|
||||||
const gfx::Rect& damage_rect, const SkBitmap& bitmap,
|
const gfx::Rect& damage_rect,
|
||||||
|
const SkBitmap& bitmap,
|
||||||
content::ReadbackResponse response) {
|
content::ReadbackResponse response) {
|
||||||
if (response != content::ReadbackResponse::READBACK_SUCCESS)
|
if (response != content::ReadbackResponse::READBACK_SUCCESS)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -35,7 +35,8 @@ class FrameSubscriber : public content::RenderWidgetHostViewFrameSubscriber {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void OnFrameDelivered(const FrameCaptureCallback& callback,
|
void OnFrameDelivered(const FrameCaptureCallback& callback,
|
||||||
const gfx::Rect& damage_rect, const SkBitmap& bitmap,
|
const gfx::Rect& damage_rect,
|
||||||
|
const SkBitmap& bitmap,
|
||||||
content::ReadbackResponse response);
|
content::ReadbackResponse response);
|
||||||
|
|
||||||
v8::Isolate* isolate_;
|
v8::Isolate* isolate_;
|
||||||
|
|
|
@ -921,7 +921,7 @@ For the `mouseWheel` event, the `event` object also have following properties:
|
||||||
|
|
||||||
### `webContents.beginFrameSubscription([onlyDirty ,]callback)`
|
### `webContents.beginFrameSubscription([onlyDirty ,]callback)`
|
||||||
|
|
||||||
* `onlyDirty` Boolean
|
* `onlyDirty` Boolean (optional) - Defaults to `false`
|
||||||
* `callback` Function
|
* `callback` Function
|
||||||
|
|
||||||
Begin subscribing for presentation events and captured frames, the `callback`
|
Begin subscribing for presentation events and captured frames, the `callback`
|
||||||
|
|
|
@ -44,7 +44,10 @@ describe('browser-window module', function () {
|
||||||
w = new BrowserWindow({
|
w = new BrowserWindow({
|
||||||
show: false,
|
show: false,
|
||||||
width: 400,
|
width: 400,
|
||||||
height: 400
|
height: 400,
|
||||||
|
webPreferences: {
|
||||||
|
backgroundThrottling: false
|
||||||
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -603,12 +606,20 @@ describe('browser-window module', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('beginFrameSubscription method', function () {
|
describe('beginFrameSubscription method', function () {
|
||||||
it('subscribes to frame updates', function (done) {
|
// This test is too slow, only test it on CI.
|
||||||
|
if (!isCI) return
|
||||||
|
|
||||||
this.timeout(20000)
|
this.timeout(20000)
|
||||||
|
|
||||||
|
it('subscribes to frame updates', function (done) {
|
||||||
|
let called = false
|
||||||
w.loadURL('file://' + fixtures + '/api/frame-subscriber.html')
|
w.loadURL('file://' + fixtures + '/api/frame-subscriber.html')
|
||||||
w.webContents.on('dom-ready', function () {
|
w.webContents.on('dom-ready', function () {
|
||||||
w.webContents.beginFrameSubscription(function (data) {
|
w.webContents.beginFrameSubscription(function (data) {
|
||||||
|
// This callback might be called twice.
|
||||||
|
if (called) return
|
||||||
|
called = true
|
||||||
|
|
||||||
assert.notEqual(data.length, 0)
|
assert.notEqual(data.length, 0)
|
||||||
w.webContents.endFrameSubscription()
|
w.webContents.endFrameSubscription()
|
||||||
done()
|
done()
|
||||||
|
@ -617,11 +628,14 @@ describe('browser-window module', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('subscribes to frame updates (only dirty rectangle)', function (done) {
|
it('subscribes to frame updates (only dirty rectangle)', function (done) {
|
||||||
this.timeout(20000)
|
let called = false
|
||||||
|
|
||||||
w.loadURL('file://' + fixtures + '/api/frame-subscriber.html')
|
w.loadURL('file://' + fixtures + '/api/frame-subscriber.html')
|
||||||
w.webContents.on('dom-ready', function () {
|
w.webContents.on('dom-ready', function () {
|
||||||
w.webContents.beginFrameSubscription(true, function (data) {
|
w.webContents.beginFrameSubscription(true, function (data) {
|
||||||
|
// This callback might be called twice.
|
||||||
|
if (called) return
|
||||||
|
called = true
|
||||||
|
|
||||||
assert.notEqual(data.length, 0)
|
assert.notEqual(data.length, 0)
|
||||||
w.webContents.endFrameSubscription()
|
w.webContents.endFrameSubscription()
|
||||||
done()
|
done()
|
||||||
|
@ -630,10 +644,8 @@ describe('browser-window module', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('throws error when subscriber is not well defined', function (done) {
|
it('throws error when subscriber is not well defined', function (done) {
|
||||||
this.timeout(20000)
|
|
||||||
|
|
||||||
w.loadURL('file://' + fixtures + '/api/frame-subscriber.html')
|
w.loadURL('file://' + fixtures + '/api/frame-subscriber.html')
|
||||||
try{
|
try {
|
||||||
w.webContents.beginFrameSubscription(true, true)
|
w.webContents.beginFrameSubscription(true, true)
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
done()
|
done()
|
||||||
|
|
Loading…
Reference in a new issue