reverts subscriber api
This commit is contained in:
parent
2435f1b660
commit
64e53a17bd
5 changed files with 38 additions and 15 deletions
|
@ -1242,7 +1242,7 @@ void WebContents::BeginFrameSubscription(mate::Arguments* args) {
|
|||
const auto view = web_contents()->GetRenderWidgetHostView();
|
||||
if (view) {
|
||||
std::unique_ptr<FrameSubscriber> frame_subscriber(new FrameSubscriber(
|
||||
view, callback, only_dirty));
|
||||
isolate(), view, callback, only_dirty));
|
||||
view->BeginFrameSubscription(std::move(frame_subscriber));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,10 +15,12 @@ namespace atom {
|
|||
|
||||
namespace api {
|
||||
|
||||
FrameSubscriber::FrameSubscriber(content::RenderWidgetHostView* view,
|
||||
FrameSubscriber::FrameSubscriber(v8::Isolate* isolate,
|
||||
content::RenderWidgetHostView* view,
|
||||
const FrameCaptureCallback& callback,
|
||||
bool only_dirty)
|
||||
: view_(view),
|
||||
: isolate_(isolate),
|
||||
view_(view),
|
||||
callback_(callback),
|
||||
only_dirty_(only_dirty),
|
||||
weak_factory_(this) {
|
||||
|
@ -68,7 +70,23 @@ void FrameSubscriber::OnFrameDelivered(const FrameCaptureCallback& callback,
|
|||
if (response != content::ReadbackResponse::READBACK_SUCCESS)
|
||||
return;
|
||||
|
||||
callback.Run(gfx::Image::CreateFrom1xBitmap(bitmap), damage_rect);
|
||||
v8::Locker locker(isolate_);
|
||||
v8::HandleScope handle_scope(isolate_);
|
||||
|
||||
size_t rgb_arr_size = bitmap.width() * bitmap.height() *
|
||||
bitmap.bytesPerPixel();
|
||||
v8::MaybeLocal<v8::Object> buffer = node::Buffer::New(isolate_, rgb_arr_size);
|
||||
if (buffer.IsEmpty())
|
||||
return;
|
||||
|
||||
bitmap.copyPixelsTo(
|
||||
reinterpret_cast<uint8_t*>(node::Buffer::Data(buffer.ToLocalChecked())),
|
||||
rgb_arr_size);
|
||||
|
||||
v8::Local<v8::Value> damage =
|
||||
mate::Converter<gfx::Rect>::ToV8(isolate_, damage_rect);
|
||||
|
||||
callback_.Run(buffer.ToLocalChecked(), damage);
|
||||
}
|
||||
|
||||
} // namespace api
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include "content/public/browser/render_widget_host_view_frame_subscriber.h"
|
||||
#include "third_party/skia/include/core/SkBitmap.h"
|
||||
#include "ui/gfx/geometry/size.h"
|
||||
#include "ui/gfx/image/image.h"
|
||||
#include "v8/include/v8.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
|
@ -21,9 +21,10 @@ namespace api {
|
|||
class FrameSubscriber : public content::RenderWidgetHostViewFrameSubscriber {
|
||||
public:
|
||||
using FrameCaptureCallback =
|
||||
base::Callback<void(const gfx::Image&, const gfx::Rect&)>;
|
||||
base::Callback<void(v8::Local<v8::Value>, v8::Local<v8::Value>)>;
|
||||
|
||||
FrameSubscriber(content::RenderWidgetHostView* view,
|
||||
FrameSubscriber(v8::Isolate* isolate,
|
||||
content::RenderWidgetHostView* view,
|
||||
const FrameCaptureCallback& callback,
|
||||
bool only_dirty);
|
||||
|
||||
|
@ -38,6 +39,7 @@ class FrameSubscriber : public content::RenderWidgetHostViewFrameSubscriber {
|
|||
const SkBitmap& bitmap,
|
||||
content::ReadbackResponse response);
|
||||
|
||||
v8::Isolate* isolate_;
|
||||
content::RenderWidgetHostView* view_;
|
||||
FrameCaptureCallback callback_;
|
||||
bool only_dirty_;
|
||||
|
|
|
@ -1063,15 +1063,18 @@ For the `mouseWheel` event, the `event` object also have following properties:
|
|||
* `callback` Function
|
||||
|
||||
Begin subscribing for presentation events and captured frames, the `callback`
|
||||
will be called with `callback(image, dirtyRect)` when there is a
|
||||
will be called with `callback(frameBuffer, dirtyRect)` when there is a
|
||||
presentation event.
|
||||
|
||||
The `image` is a [NativeImage](native-image.md) that contains the image data of
|
||||
the frame.
|
||||
The `frameBuffer` is a `Buffer` that contains raw pixel data. On most machines,
|
||||
the pixel data is effectively stored in 32bit BGRA format, but the actual
|
||||
representation depends on the endianness of the processor (most modern
|
||||
processors are little-endian, on machines with big-endian processors the data
|
||||
is in 32bit ARGB format).
|
||||
|
||||
The `dirtyRect` is an object with `x, y, width, height` properties that
|
||||
describes which part of the page was repainted. If `onlyDirty` is set to
|
||||
`true`, `image` will only contain the repainted area. `onlyDirty`
|
||||
`true`, `frameBuffer` will only contain the repainted area. `onlyDirty`
|
||||
defaults to `false`.
|
||||
|
||||
#### `contents.endFrameSubscription()`
|
||||
|
|
|
@ -670,12 +670,12 @@ describe('browser-window module', function () {
|
|||
let called = false
|
||||
w.loadURL('file://' + fixtures + '/api/frame-subscriber.html')
|
||||
w.webContents.on('dom-ready', function () {
|
||||
w.webContents.beginFrameSubscription(function (image) {
|
||||
w.webContents.beginFrameSubscription(function (data) {
|
||||
// This callback might be called twice.
|
||||
if (called) return
|
||||
called = true
|
||||
|
||||
assert.equal(image.isEmpty(), false)
|
||||
assert.notEqual(data.length, 0)
|
||||
w.webContents.endFrameSubscription()
|
||||
done()
|
||||
})
|
||||
|
@ -686,12 +686,12 @@ describe('browser-window module', function () {
|
|||
let called = false
|
||||
w.loadURL('file://' + fixtures + '/api/frame-subscriber.html')
|
||||
w.webContents.on('dom-ready', function () {
|
||||
w.webContents.beginFrameSubscription(true, function (image) {
|
||||
w.webContents.beginFrameSubscription(true, function (data) {
|
||||
// This callback might be called twice.
|
||||
if (called) return
|
||||
called = true
|
||||
|
||||
assert.equal(image.isEmpty(), false)
|
||||
assert.notEqual(data.length, 0)
|
||||
w.webContents.endFrameSubscription()
|
||||
done()
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue