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));
}
}
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) {
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
#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 {
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);
const SkBitmap& bitmap,
content::ReadbackResponse response);
+ v8::Isolate* isolate_;
content::RenderWidgetHostView* view_;
FrameCaptureCallback callback_;
bool only_dirty_;
* `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()`
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()
})
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()
})