Renamed setOffscreenRender to begin/endFrameSubscription because the name was a bit...
authorHeilig Benedek <benecene@gmail.com>
Wed, 16 Sep 2015 00:59:16 +0000 (02:59 +0200)
committerHeilig Benedek <benecene@gmail.com>
Wed, 16 Sep 2015 00:59:16 +0000 (02:59 +0200)
atom/browser/api/atom_api_window.cc
atom/browser/api/atom_api_window.h
atom/browser/native_window.cc
atom/browser/native_window.h
docs/api/browser-window.md

index b9b592a..78d9376 100644 (file)
@@ -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<uint8[]> rgb, const int size) {
   v8::Locker locker(isolate());
   v8::HandleScope handle_scope(isolate());
 
-  v8::Local<v8::ArrayBuffer> data = v8::ArrayBuffer::New(isolate(), rgb.get(), size);
-  v8::Local<v8::Uint8ClampedArray> uint_data = v8::Uint8ClampedArray::New(data, 0, size);
+  auto data = node::Buffer::New(isolate(), reinterpret_cast<const char*>(rgb.get()), static_cast<size_t>(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)
index 727cacd..b5125f9 100644 (file)
@@ -141,7 +141,8 @@ class Window : public mate::TrackableObject<Window>,
 
   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();
index a9e0631..e8a4c5a 100644 (file)
@@ -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(
index 7131894..f439962 100644 (file)
@@ -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,
index 09d38bc..c338f24 100644 (file)
@@ -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)