diff --git a/atom/browser/api/frame_subscriber.cc b/atom/browser/api/frame_subscriber.cc index b729a1cf6efc..5c49e688976a 100644 --- a/atom/browser/api/frame_subscriber.cc +++ b/atom/browser/api/frame_subscriber.cc @@ -13,6 +13,8 @@ #include "ui/gfx/geometry/rect_conversions.h" #include "ui/gfx/skbitmap_operations.h" +#include "atom/common/node_includes.h" + namespace atom { namespace api { @@ -70,17 +72,26 @@ void FrameSubscriber::Done(const gfx::Rect& damage, const SkBitmap& frame) { if (frame.drawsNothing()) return; + v8::Locker locker(isolate_); + v8::HandleScope handle_scope(isolate_); + const_cast(frame).setAlphaType(kPremul_SkAlphaType); + const SkBitmap& bitmap = only_dirty_ ? SkBitmapOperations::CreateTiledBitmap( + frame, damage.x(), damage.y(), + damage.width(), damage.height()) + : frame; + + size_t rgb_row_size = bitmap.width() * bitmap.bytesPerPixel(); + auto source = static_cast(bitmap.getPixels()); + + v8::MaybeLocal buffer = + node::Buffer::Copy(isolate_, source, rgb_row_size * bitmap.height()); + auto local_buffer = buffer.ToLocalChecked(); + v8::Local damage_rect = mate::Converter::ToV8(isolate_, damage); - if (only_dirty_) { - const SkBitmap& damageFrame = SkBitmapOperations::CreateTiledBitmap( - frame, damage.x(), damage.y(), damage.width(), damage.height()); - callback_.Run(gfx::Image::CreateFrom1xBitmap(damageFrame), damage_rect); - } else { - callback_.Run(gfx::Image::CreateFrom1xBitmap(frame), damage_rect); - } + callback_.Run(local_buffer, damage_rect); } } // namespace api diff --git a/atom/browser/api/frame_subscriber.h b/atom/browser/api/frame_subscriber.h index 1e43bae60357..390b54f58cc9 100644 --- a/atom/browser/api/frame_subscriber.h +++ b/atom/browser/api/frame_subscriber.h @@ -22,7 +22,7 @@ class WebContents; class FrameSubscriber : public content::WebContentsObserver { public: using FrameCaptureCallback = - base::Callback)>; + base::Callback, v8::Local)>; FrameSubscriber(v8::Isolate* isolate, content::WebContents* web_contents, diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index c3eaad66aefb..31064b00b76f 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -2058,9 +2058,7 @@ describe('BrowserWindow module', () => { }) }) - // TODO(alexeykuzmin): [Ch66] Crashes the app. - // Fix and enable the test. - xdescribe('beginFrameSubscription method', () => { + describe('beginFrameSubscription method', () => { before(function () { // This test is too slow, only test it on CI. if (!isCI) {