From ceef06b344895edeb7d3770edcf64e387f0203f5 Mon Sep 17 00:00:00 2001 From: Heilig Benedek Date: Wed, 16 Sep 2015 02:59:16 +0200 Subject: [PATCH] Renamed setOffscreenRender to begin/endFrameSubscription because the name was a bit misleading, and replaced the ArrayBuffer creation with a node::Buffer::New call. --- atom/browser/api/atom_api_window.cc | 17 +++++++++++------ atom/browser/api/atom_api_window.h | 3 ++- atom/browser/native_window.cc | 4 ++-- atom/browser/native_window.h | 2 +- docs/api/browser-window.md | 14 ++++++++++---- 5 files changed, 26 insertions(+), 14 deletions(-) diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index b9b592a283a..78d93761652 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -8,6 +8,7 @@ #include "atom/browser/api/atom_api_web_contents.h" #include "atom/browser/browser.h" #include "atom/browser/native_window.h" +#include "atom/common/node_includes.h" #include "atom/common/options_switches.h" #include "atom/common/event_types.h" #include "atom/common/native_mate_converters/callback.h" @@ -99,10 +100,9 @@ void Window::OnFrameRendered(scoped_ptr rgb, const int size) { v8::Locker locker(isolate()); v8::HandleScope handle_scope(isolate()); - v8::Local data = v8::ArrayBuffer::New(isolate(), rgb.get(), size); - v8::Local uint_data = v8::Uint8ClampedArray::New(data, 0, size); + auto data = node::Buffer::New(isolate(), reinterpret_cast(rgb.get()), static_cast(size)); - Emit("frame-rendered", uint_data, size); + Emit("frame-rendered", data, size); } void Window::OnWindowClosed() { @@ -442,8 +442,12 @@ void Window::CapturePage(mate::Arguments* args) { rect, base::Bind(&OnCapturePageDone, args->isolate(), callback)); } -void Window::SetOffscreenRender(bool isOffscreen) { - window_->SetOffscreenRender(isOffscreen); +void Window::BeginFrameSubscription() { + window_->SetFrameSubscription(true); +} + +void Window::EndFrameSubscription() { + window_->SetFrameSubscription(false); } void Window::SetProgressBar(double progress) { @@ -728,7 +732,8 @@ void Window::BuildPrototype(v8::Isolate* isolate, &Window::IsVisibleOnAllWorkspaces) .SetMethod("sendMouseEvent", &Window::SendMouseEvent) .SetMethod("sendKeyboardEvent", &Window::SendKeyboardEvent) - .SetMethod("setOffscreenRender", &Window::SetOffscreenRender) + .SetMethod("beginFrameSubscription", &Window::BeginFrameSubscription) + .SetMethod("endFrameSubscription", &Window::EndFrameSubscription) #if defined(OS_MACOSX) .SetMethod("showDefinitionForSelection", &Window::ShowDefinitionForSelection) diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index 727cacd3d6e..b5125f9c1f5 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -141,7 +141,8 @@ class Window : public mate::TrackableObject, void SendKeyboardEvent(v8::Isolate* isolate, const mate::Dictionary& data); void SendMouseEvent(v8::Isolate* isolate, const mate::Dictionary& data); - void SetOffscreenRender(bool isOffscreen); + void BeginFrameSubscription(); + void EndFrameSubscription(); #if defined(OS_MACOSX) void ShowDefinitionForSelection(); diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index a9e0631489a..e8a4c5a9ea5 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -333,7 +333,7 @@ void NativeWindow::CapturePage(const gfx::Rect& rect, kBGRA_8888_SkColorType); } -void NativeWindow::SetOffscreenRender(bool isOffscreen) { +void NativeWindow::SetFrameSubscription(bool isOffscreen) { if (!isOffscreen && !offscreen_) return; const auto view = web_contents()->GetRenderWidgetHostView(); @@ -637,7 +637,7 @@ void NativeWindow::SendMouseWheelEvent(int modifiers, int x, int y, bool precise } void NativeWindow::DidFinishLoad(content::RenderFrameHost* render_frame_host, const GURL& validated_url) { - SetOffscreenRender(offscreen_); + SetFrameSubscription(offscreen_); } void NativeWindow::RenderViewCreated( diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 7131894a1f1..f439962e7cc 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -242,7 +242,7 @@ class NativeWindow : public content::WebContentsObserver, void SendMouseEvent(blink::WebInputEvent::Type type, int modifiers, blink::WebMouseEvent::Button button, int x, int y, int movementX, int movementY, int clickCount); void SendMouseWheelEvent(int modifiers, int x, int y, bool clickCount); - void SetOffscreenRender(bool isOffscreen); + void SetFrameSubscription(bool isOffscreen); protected: NativeWindow(brightray::InspectableWebContents* inspectable_web_contents, diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 09d38bc9ad9..c338f247072 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -75,7 +75,8 @@ You can also create a window without chrome by using * `standard-window` Boolean - Uses the OS X's standard window instead of the textured window. Defaults to `true`. * `offscreen-render` Boolean - The frame of the window will be accessible - through the `frame-rendered` event in a buffer. Defaults to `false`. + through the `frame-rendered` event in a buffer (Uint8, BGRA). Defaults to + `false`. * `web-preferences` Object - Settings of web page's features * `javascript` Boolean * `web-security` Boolean - When setting `false`, it will disable the same-origin @@ -732,10 +733,15 @@ Returns whether the window is visible on all workspaces. **Note:** This API always returns false on Windows. -### BrowserWindow.setOffscreenRender(isOffscreen) +### BrowserWindow.beginFrameSubscription() -Sets the offscreen rendering, if `true` the `frame-rendered` event will fire, -when the frame changes. +Enables offscreen rendering, after this call `frame-rendered` events will be +fired when the window receives a new frame from the renderer. + +### BrowserWindow.endFrameSubscription() + +Enables offscreen rendering, after this call `frame-rendered` events will +no longer be fired if offscreen rendering was enabled before. ### BrowserWindow.sendMouseEvent(options)