speedup base
authorHeilig Benedek <benecene@gmail.com>
Tue, 5 Jul 2016 19:33:22 +0000 (21:33 +0200)
committerHeilig Benedek <benecene@gmail.com>
Tue, 5 Jul 2016 19:33:22 +0000 (21:33 +0200)
atom/app/atom_main_delegate.cc
atom/app/atom_main_delegate.h
atom/browser/api/frame_subscriber.cc
atom/browser/api/frame_subscriber.h
atom/browser/native_window_views.cc
atom/browser/native_window_views.h
atom/browser/osr_window.cc [new file with mode: 0644]
atom/browser/osr_window.h [new file with mode: 0644]
default_app/default_app.js
filenames.gypi

index f4e0b60..891cdd3 100644 (file)
-// Copyright (c) 2013 GitHub, Inc.
-// Use of this source code is governed by the MIT license that can be
-// found in the LICENSE file.
-
-#include "atom/app/atom_main_delegate.h"
-
-#include <string>
-#include <iostream>
-
-#include "atom/app/atom_content_client.h"
-#include "atom/browser/atom_browser_client.h"
-#include "atom/browser/relauncher.h"
-#include "atom/common/google_api_key.h"
-#include "atom/renderer/atom_renderer_client.h"
-#include "atom/utility/atom_content_utility_client.h"
-#include "base/command_line.h"
-#include "base/debug/stack_trace.h"
-#include "base/environment.h"
-#include "base/logging.h"
-#include "chrome/common/chrome_paths.h"
-#include "content/public/common/content_switches.h"
-#include "ui/base/l10n/l10n_util.h"
-#include "ui/base/resource/resource_bundle.h"
-
-namespace atom {
-
-namespace {
-
-const char* kRelauncherProcess = "relauncher";
-
-bool IsBrowserProcess(base::CommandLine* cmd) {
-  std::string process_type = cmd->GetSwitchValueASCII(switches::kProcessType);
-  return process_type.empty();
-}
-
-#if defined(OS_WIN)
-void InvalidParameterHandler(const wchar_t*, const wchar_t*, const wchar_t*,
-                             unsigned int, uintptr_t) {
-  // noop.
-}
-#endif
-
-}  // namespace
-
-AtomMainDelegate::AtomMainDelegate() {
-}
-
-AtomMainDelegate::~AtomMainDelegate() {
-}
-
-bool AtomMainDelegate::BasicStartupComplete(int* exit_code) {
-  auto command_line = base::CommandLine::ForCurrentProcess();
-
-  logging::LoggingSettings settings;
-#if defined(OS_WIN)
-  // On Windows the terminal returns immediately, so we add a new line to
-  // prevent output in the same line as the prompt.
-  if (IsBrowserProcess(command_line))
-    std::wcout << std::endl;
-#if defined(DEBUG)
-  // Print logging to debug.log on Windows
-  settings.logging_dest = logging::LOG_TO_ALL;
-  settings.log_file = L"debug.log";
-  settings.lock_log = logging::LOCK_LOG_FILE;
-  settings.delete_old = logging::DELETE_OLD_LOG_FILE;
-#else
-  settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
-#endif  // defined(DEBUG)
-#else  // defined(OS_WIN)
-  settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
-#endif  // !defined(OS_WIN)
-
-  // Only enable logging when --enable-logging is specified.
-  std::unique_ptr<base::Environment> env(base::Environment::Create());
-  if (!command_line->HasSwitch(switches::kEnableLogging) &&
-      !env->HasVar("ELECTRON_ENABLE_LOGGING")) {
-    settings.logging_dest = logging::LOG_NONE;
-    logging::SetMinLogLevel(logging::LOG_NUM_SEVERITIES);
-  }
-
-  logging::InitLogging(settings);
-
-  // Logging with pid and timestamp.
-  logging::SetLogItems(true, false, true, false);
-
-  // Enable convient stack printing.
-  bool enable_stack_dumping = env->HasVar("ELECTRON_ENABLE_STACK_DUMPING");
-#if defined(DEBUG) && defined(OS_LINUX)
-  enable_stack_dumping = true;
-#endif
-  if (enable_stack_dumping)
-    base::debug::EnableInProcessStackDumping();
-
-  chrome::RegisterPathProvider();
-
-#if defined(OS_MACOSX)
-  SetUpBundleOverrides();
-#endif
-
-#if defined(OS_WIN)
-  // Ignore invalid parameter errors.
-  _set_invalid_parameter_handler(InvalidParameterHandler);
-#endif
-
-  return brightray::MainDelegate::BasicStartupComplete(exit_code);
-}
-
-void AtomMainDelegate::PreSandboxStartup() {
-  brightray::MainDelegate::PreSandboxStartup();
-
-  // Set google API key.
-  std::unique_ptr<base::Environment> env(base::Environment::Create());
-  if (!env->HasVar("GOOGLE_API_KEY"))
-    env->SetVar("GOOGLE_API_KEY", GOOGLEAPIS_API_KEY);
-
-  auto command_line = base::CommandLine::ForCurrentProcess();
-  std::string process_type = command_line->GetSwitchValueASCII(
-      switches::kProcessType);
-
-  // Only append arguments for browser process.
-  if (!IsBrowserProcess(command_line))
-    return;
-
-  // Disable renderer sandbox for most of node's functions.
-  command_line->AppendSwitch(switches::kNoSandbox);
-
-  // Allow file:// URIs to read other file:// URIs by default.
-  command_line->AppendSwitch(switches::kAllowFileAccessFromFiles);
-
-#if defined(OS_MACOSX)
-  // Enable AVFoundation.
-  command_line->AppendSwitch("enable-avfoundation");
-#endif
-}
-
-content::ContentBrowserClient* AtomMainDelegate::CreateContentBrowserClient() {
-  browser_client_.reset(new AtomBrowserClient);
-  return browser_client_.get();
-}
-
-content::ContentRendererClient*
-    AtomMainDelegate::CreateContentRendererClient() {
-  renderer_client_.reset(new AtomRendererClient);
-  return renderer_client_.get();
-}
-
-content::ContentUtilityClient* AtomMainDelegate::CreateContentUtilityClient() {
-  utility_client_.reset(new AtomContentUtilityClient);
-  return utility_client_.get();
-}
-
-int AtomMainDelegate::RunProcess(
-    const std::string& process_type,
-    const content::MainFunctionParams& main_function_params) {
-  if (process_type == kRelauncherProcess)
-    return relauncher::RelauncherMain(main_function_params);
-  else
-    return -1;
-}
-
-#if defined(OS_MACOSX)
-bool AtomMainDelegate::ShouldSendMachPort(const std::string& process_type) {
-  return process_type != kRelauncherProcess;
-}
-
-bool AtomMainDelegate::DelaySandboxInitialization(
-    const std::string& process_type) {
-  return process_type == kRelauncherProcess;
-}
-#endif
-
-std::unique_ptr<brightray::ContentClient>
-AtomMainDelegate::CreateContentClient() {
-  return std::unique_ptr<brightray::ContentClient>(new AtomContentClient);
-}
-
-}  // namespace atom
+// Copyright (c) 2013 GitHub, Inc.\r
+// Use of this source code is governed by the MIT license that can be\r
+// found in the LICENSE file.\r
+\r
+#include "atom/app/atom_main_delegate.h"\r
+\r
+#include <string>\r
+#include <iostream>\r
+\r
+#include "atom/app/atom_content_client.h"\r
+#include "atom/browser/atom_browser_client.h"\r
+#include "atom/browser/relauncher.h"\r
+#include "atom/common/google_api_key.h"\r
+#include "atom/renderer/atom_renderer_client.h"\r
+#include "atom/utility/atom_content_utility_client.h"\r
+#include "base/command_line.h"\r
+#include "base/debug/stack_trace.h"\r
+#include "base/environment.h"\r
+#include "base/logging.h"\r
+#include "chrome/common/chrome_paths.h"\r
+#include "content/public/common/content_switches.h"\r
+#include "ui/base/l10n/l10n_util.h"\r
+#include "ui/base/resource/resource_bundle.h"\r
+\r
+#include "base/memory/ptr_util.h"\r
+#include "content/browser/renderer_host/render_view_host_impl.h"\r
+#include "content/browser/renderer_host/render_widget_host_impl.h"\r
+#include "atom/browser/osr_window.h"\r
+\r
+#include "content/browser/renderer_host/render_widget_host_view_aura.h"\r
+\r
+namespace atom {\r
+\r
+namespace {\r
+\r
+const char* kRelauncherProcess = "relauncher";\r
+\r
+bool IsBrowserProcess(base::CommandLine* cmd) {\r
+  std::string process_type = cmd->GetSwitchValueASCII(switches::kProcessType);\r
+  return process_type.empty();\r
+}\r
+\r
+#if defined(OS_WIN)\r
+void InvalidParameterHandler(const wchar_t*, const wchar_t*, const wchar_t*,\r
+                             unsigned int, uintptr_t) {\r
+  // noop.\r
+}\r
+#endif\r
+\r
+}  // namespace\r
+\r
+AtomMainDelegate::AtomMainDelegate() {\r
+}\r
+\r
+AtomMainDelegate::~AtomMainDelegate() {\r
+}\r
+\r
+bool AtomMainDelegate::BasicStartupComplete(int* exit_code) {\r
+  auto command_line = base::CommandLine::ForCurrentProcess();\r
+\r
+  logging::LoggingSettings settings;\r
+#if defined(OS_WIN)\r
+  // On Windows the terminal returns immediately, so we add a new line to\r
+  // prevent output in the same line as the prompt.\r
+  if (IsBrowserProcess(command_line))\r
+    std::wcout << std::endl;\r
+#if defined(DEBUG)\r
+  // Print logging to debug.log on Windows\r
+  settings.logging_dest = logging::LOG_TO_ALL;\r
+  settings.log_file = L"debug.log";\r
+  settings.lock_log = logging::LOCK_LOG_FILE;\r
+  settings.delete_old = logging::DELETE_OLD_LOG_FILE;\r
+#else\r
+  settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;\r
+#endif  // defined(DEBUG)\r
+#else  // defined(OS_WIN)\r
+  settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;\r
+#endif  // !defined(OS_WIN)\r
+\r
+  // Only enable logging when --enable-logging is specified.\r
+  std::unique_ptr<base::Environment> env(base::Environment::Create());\r
+  if (!command_line->HasSwitch(switches::kEnableLogging) &&\r
+      !env->HasVar("ELECTRON_ENABLE_LOGGING")) {\r
+    settings.logging_dest = logging::LOG_NONE;\r
+    logging::SetMinLogLevel(logging::LOG_NUM_SEVERITIES);\r
+  }\r
+\r
+  logging::InitLogging(settings);\r
+\r
+  // Logging with pid and timestamp.\r
+  logging::SetLogItems(true, false, true, false);\r
+\r
+  // Enable convient stack printing.\r
+  bool enable_stack_dumping = env->HasVar("ELECTRON_ENABLE_STACK_DUMPING");\r
+#if defined(DEBUG) && defined(OS_LINUX)\r
+  enable_stack_dumping = true;\r
+#endif\r
+  if (enable_stack_dumping)\r
+    base::debug::EnableInProcessStackDumping();\r
+\r
+  chrome::RegisterPathProvider();\r
+\r
+#if defined(OS_MACOSX)\r
+  SetUpBundleOverrides();\r
+#endif\r
+\r
+#if defined(OS_WIN)\r
+  // Ignore invalid parameter errors.\r
+  _set_invalid_parameter_handler(InvalidParameterHandler);\r
+#endif\r
+\r
+  render_view_host_factory_.reset(new AtomRenderViewHostFactory);\r
+\r
+  return brightray::MainDelegate::BasicStartupComplete(exit_code);\r
+}\r
+\r
+void AtomMainDelegate::PreSandboxStartup() {\r
+  brightray::MainDelegate::PreSandboxStartup();\r
+\r
+  // Set google API key.\r
+  std::unique_ptr<base::Environment> env(base::Environment::Create());\r
+  if (!env->HasVar("GOOGLE_API_KEY"))\r
+    env->SetVar("GOOGLE_API_KEY", GOOGLEAPIS_API_KEY);\r
+\r
+  auto command_line = base::CommandLine::ForCurrentProcess();\r
+  std::string process_type = command_line->GetSwitchValueASCII(\r
+      switches::kProcessType);\r
+\r
+  // Only append arguments for browser process.\r
+  if (!IsBrowserProcess(command_line))\r
+    return;\r
+\r
+  // Disable renderer sandbox for most of node's functions.\r
+  command_line->AppendSwitch(switches::kNoSandbox);\r
+\r
+  // Allow file:// URIs to read other file:// URIs by default.\r
+  command_line->AppendSwitch(switches::kAllowFileAccessFromFiles);\r
+\r
+#if defined(OS_MACOSX)\r
+  // Enable AVFoundation.\r
+  command_line->AppendSwitch("enable-avfoundation");\r
+#endif\r
+}\r
+\r
+content::ContentBrowserClient* AtomMainDelegate::CreateContentBrowserClient() {\r
+  browser_client_.reset(new AtomBrowserClient);\r
+  return browser_client_.get();\r
+}\r
+\r
+content::ContentRendererClient*\r
+    AtomMainDelegate::CreateContentRendererClient() {\r
+  renderer_client_.reset(new AtomRendererClient);\r
+  return renderer_client_.get();\r
+}\r
+\r
+content::ContentUtilityClient* AtomMainDelegate::CreateContentUtilityClient() {\r
+  utility_client_.reset(new AtomContentUtilityClient);\r
+  return utility_client_.get();\r
+}\r
+\r
+int AtomMainDelegate::RunProcess(\r
+    const std::string& process_type,\r
+    const content::MainFunctionParams& main_function_params) {\r
+  if (process_type == kRelauncherProcess)\r
+    return relauncher::RelauncherMain(main_function_params);\r
+  else\r
+    return -1;\r
+}\r
+\r
+#if defined(OS_MACOSX)\r
+bool AtomMainDelegate::ShouldSendMachPort(const std::string& process_type) {\r
+  return process_type != kRelauncherProcess;\r
+}\r
+\r
+bool AtomMainDelegate::DelaySandboxInitialization(\r
+    const std::string& process_type) {\r
+  return process_type == kRelauncherProcess;\r
+}\r
+#endif\r
+\r
+std::unique_ptr<brightray::ContentClient>\r
+AtomMainDelegate::CreateContentClient() {\r
+  return std::unique_ptr<brightray::ContentClient>(new AtomContentClient);\r
+}\r
+\r
+AtomRenderViewHostFactory::AtomRenderViewHostFactory() {\r
+  //std::cout << "AtomRenderViewHostFactory" << std::endl;\r
+  content::RenderViewHostFactory::UnregisterFactory();\r
+  content::RenderViewHostFactory::RegisterFactory( this );\r
+}\r
+\r
+AtomRenderViewHostFactory::~AtomRenderViewHostFactory() {\r
+  //std::cout << "~AtomRenderViewHostFactory" << std::endl;\r
+}\r
+\r
+content::RenderViewHost* AtomRenderViewHostFactory::CreateRenderViewHost(\r
+  content::SiteInstance* instance,\r
+  content::RenderViewHostDelegate* delegate,\r
+  content::RenderWidgetHostDelegate* widget_delegate,\r
+  int32_t routing_id,\r
+  int32_t main_frame_routing_id,\r
+  bool swapped_out) {\r
+\r
+  auto widget_host_impl = new content::RenderWidgetHostImpl(\r
+    widget_delegate, instance->GetProcess(), routing_id, false);\r
+\r
+  auto view_host_impl = new content::RenderViewHostImpl(instance,\r
+    base::WrapUnique(widget_host_impl), delegate, main_frame_routing_id,\r
+    swapped_out, true);\r
+\r
+  new OffScreenWindow(widget_host_impl);\r
+\r
+  return view_host_impl;\r
+}\r
+\r
+}  // namespace atom\r
index 58a380b..f9c9307 100644 (file)
@@ -1,57 +1,75 @@
-// Copyright (c) 2013 GitHub, Inc.
-// Use of this source code is governed by the MIT license that can be
-// found in the LICENSE file.
-
-#ifndef ATOM_APP_ATOM_MAIN_DELEGATE_H_
-#define ATOM_APP_ATOM_MAIN_DELEGATE_H_
-
-#include <string>
-
-#include "brightray/common/main_delegate.h"
-#include "brightray/common/content_client.h"
-
-namespace atom {
-
-class AtomMainDelegate : public brightray::MainDelegate {
- public:
-  AtomMainDelegate();
-  ~AtomMainDelegate();
-
- protected:
-  // content::ContentMainDelegate:
-  bool BasicStartupComplete(int* exit_code) override;
-  void PreSandboxStartup() override;
-  content::ContentBrowserClient* CreateContentBrowserClient() override;
-  content::ContentRendererClient* CreateContentRendererClient() override;
-  content::ContentUtilityClient* CreateContentUtilityClient() override;
-  int RunProcess(
-      const std::string& process_type,
-      const content::MainFunctionParams& main_function_params) override;
-#if defined(OS_MACOSX)
-  bool ShouldSendMachPort(const std::string& process_type) override;
-  bool DelaySandboxInitialization(const std::string& process_type) override;
-#endif
-
-  // brightray::MainDelegate:
-  std::unique_ptr<brightray::ContentClient> CreateContentClient() override;
-#if defined(OS_MACOSX)
-  void OverrideChildProcessPath() override;
-  void OverrideFrameworkBundlePath() override;
-#endif
-
- private:
-#if defined(OS_MACOSX)
-  void SetUpBundleOverrides();
-#endif
-
-  brightray::ContentClient content_client_;
-  std::unique_ptr<content::ContentBrowserClient> browser_client_;
-  std::unique_ptr<content::ContentRendererClient> renderer_client_;
-  std::unique_ptr<content::ContentUtilityClient> utility_client_;
-
-  DISALLOW_COPY_AND_ASSIGN(AtomMainDelegate);
-};
-
-}  // namespace atom
-
-#endif  // ATOM_APP_ATOM_MAIN_DELEGATE_H_
+// Copyright (c) 2013 GitHub, Inc.\r
+// Use of this source code is governed by the MIT license that can be\r
+// found in the LICENSE file.\r
+\r
+#ifndef ATOM_APP_ATOM_MAIN_DELEGATE_H_\r
+#define ATOM_APP_ATOM_MAIN_DELEGATE_H_\r
+\r
+#include <string>\r
+\r
+#include "brightray/common/main_delegate.h"\r
+#include "brightray/common/content_client.h"\r
+\r
+#include "content/browser/renderer_host/render_view_host_factory.h"\r
+\r
+namespace atom {\r
+\r
+class AtomRenderViewHostFactory : public content::RenderViewHostFactory {\r
+public:\r
+\r
+  AtomRenderViewHostFactory();\r
+  ~AtomRenderViewHostFactory();\r
+\r
+  content::RenderViewHost* CreateRenderViewHost(\r
+    content::SiteInstance* instance,\r
+    content::RenderViewHostDelegate* delegate,\r
+    content::RenderWidgetHostDelegate* widget_delegate,\r
+    int32_t routing_id,\r
+    int32_t main_frame_routing_id,\r
+    bool swapped_out);\r
+};\r
+\r
+class AtomMainDelegate : public brightray::MainDelegate {\r
+ public:\r
+  AtomMainDelegate();\r
+  ~AtomMainDelegate();\r
+\r
+ protected:\r
+  // content::ContentMainDelegate:\r
+  bool BasicStartupComplete(int* exit_code) override;\r
+  void PreSandboxStartup() override;\r
+  content::ContentBrowserClient* CreateContentBrowserClient() override;\r
+  content::ContentRendererClient* CreateContentRendererClient() override;\r
+  content::ContentUtilityClient* CreateContentUtilityClient() override;\r
+  int RunProcess(\r
+      const std::string& process_type,\r
+      const content::MainFunctionParams& main_function_params) override;\r
+#if defined(OS_MACOSX)\r
+  bool ShouldSendMachPort(const std::string& process_type) override;\r
+  bool DelaySandboxInitialization(const std::string& process_type) override;\r
+#endif\r
+\r
+  // brightray::MainDelegate:\r
+  std::unique_ptr<brightray::ContentClient> CreateContentClient() override;\r
+#if defined(OS_MACOSX)\r
+  void OverrideChildProcessPath() override;\r
+  void OverrideFrameworkBundlePath() override;\r
+#endif\r
+\r
+ private:\r
+#if defined(OS_MACOSX)\r
+  void SetUpBundleOverrides();\r
+#endif\r
+\r
+  brightray::ContentClient content_client_;\r
+  std::unique_ptr<content::ContentBrowserClient> browser_client_;\r
+  std::unique_ptr<content::ContentRendererClient> renderer_client_;\r
+  std::unique_ptr<content::ContentUtilityClient> utility_client_;\r
+  std::unique_ptr<AtomRenderViewHostFactory> render_view_host_factory_;\r
+\r
+  DISALLOW_COPY_AND_ASSIGN(AtomMainDelegate);\r
+};\r
+\r
+}  // namespace atom\r
+\r
+#endif  // ATOM_APP_ATOM_MAIN_DELEGATE_H_\r
index 91b6765..7d87c6f 100644 (file)
@@ -9,10 +9,24 @@
 #include "atom/common/native_mate_converters/gfx_converter.h"
 #include "content/public/browser/render_widget_host.h"
 
+#include <iostream>
+#include "content/browser/compositor/image_transport_factory.h"
+#include "cc/surfaces/surface_manager.h"
+#include "cc/surfaces/surface.h"
+#include "cc/output/copy_output_request.h"
+
 namespace atom {
 
 namespace api {
 
+FrameSubscriberRenderWidgetHostView::FrameSubscriberRenderWidgetHostView() {
+  std::cout << "FrameSubscriberRenderWidgetHostView" << std::endl;
+}
+
+FrameSubscriberRenderWidgetHostView::~FrameSubscriberRenderWidgetHostView() {
+  std::cout << "~FrameSubscriberRenderWidgetHostView" << std::endl;
+}
+
 FrameSubscriber::FrameSubscriber(v8::Isolate* isolate,
                                  content::RenderWidgetHostView* view,
                                  const FrameCaptureCallback& callback,
@@ -27,26 +41,51 @@ bool FrameSubscriber::ShouldCaptureFrame(
     scoped_refptr<media::VideoFrame>* storage,
     DeliverFrameCallback* callback) {
   const auto host = view_ ? view_->GetRenderWidgetHost() : nullptr;
+
   if (!view_ || !host)
     return false;
 
-  if (dirty_rect.IsEmpty())
-    return false;
+  /*if (dirty_rect.IsEmpty())
+    return false;*/
 
   gfx::Rect rect = gfx::Rect(view_->GetVisibleViewportSize());
   if (only_dirty_)
     rect = dirty_rect;
 
-  host->CopyFromBackingStore(
+  /*host->CopyFromBackingStore(
       rect,
       rect.size(),
       base::Bind(&FrameSubscriber::OnFrameDelivered,
                  weak_factory_.GetWeakPtr(), callback_, rect),
-      kBGRA_8888_SkColorType);
+      kBGRA_8888_SkColorType);*/
 
+  const auto base = reinterpret_cast<content::RenderWidgetHostViewBase*>(
+    view_);
+  content::ImageTransportFactory* itf =
+    content::ImageTransportFactory::GetInstance();
+  cc::SurfaceManager* sfm = itf->GetSurfaceManager();
+  cc::Surface* surface = sfm->GetSurfaceForId(base->SurfaceIdForTesting());
+
+  std::unique_ptr<cc::CopyOutputRequest> request =
+    cc::CopyOutputRequest::CreateBitmapRequest(
+      base::Bind(&FrameSubscriber::ReadbackResultAsBitmap,
+      base::Unretained(this)));
+
+  surface->RequestCopyOfOutput(std::move(request));
   return false;
 }
 
+void FrameSubscriber::ReadbackResultAsBitmap(
+  std::unique_ptr<cc::CopyOutputResult> result) {
+  std::unique_ptr<SkBitmap> bitmap = result->TakeBitmap();
+
+  SkAutoPixmapUnlock res;
+  if (!bitmap->requestLock(&res))
+    return;
+
+  std::cout << res.pixmap().addr() << std::endl;
+}
+
 void FrameSubscriber::OnFrameDelivered(const FrameCaptureCallback& callback,
   const gfx::Rect& damage_rect, const SkBitmap& bitmap,
   content::ReadbackResponse response) {
index b6cff3d..6f2f7fc 100644 (file)
 #include "ui/gfx/geometry/size.h"
 #include "v8/include/v8.h"
 
+#include "content/browser/renderer_host/render_widget_host_view_base.h"
+#include "cc/surfaces/surface_id.h"
+#include "cc/output/copy_output_result.h"
+
 namespace atom {
 
 namespace api {
 
+class FrameSubscriberRenderWidgetHostView
+ : public content::RenderWidgetHostViewBase {
+ public:
+
+  FrameSubscriberRenderWidgetHostView();
+  ~FrameSubscriberRenderWidgetHostView();
+
+  cc::SurfaceId SurfaceId();
+};
+
 class FrameSubscriber : public content::RenderWidgetHostViewFrameSubscriber {
  public:
   using FrameCaptureCallback =
@@ -34,6 +48,9 @@ class FrameSubscriber : public content::RenderWidgetHostViewFrameSubscriber {
                           DeliverFrameCallback* callback) override;
 
  private:
+  void ReadbackResultAsBitmap(
+    std::unique_ptr<cc::CopyOutputResult> result);
+
   void OnFrameDelivered(const FrameCaptureCallback& callback,
     const gfx::Rect& damage_rect, const SkBitmap& bitmap,
     content::ReadbackResponse response);
index 1feb961..568a21c 100644 (file)
 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
 #endif
 
+#include <iostream>
+#include "atom/browser/osr_window.h"
+#include "content/public/browser/render_widget_host.h"
+#include "content/public/browser/render_view_host.h"
+#include "content/public/browser/context_factory.h"
+#include "base/single_thread_task_runner.h"
+#include "base/threading/thread.h"
+#include "ui/gfx/native_widget_types.h"
+
 namespace atom {
 
 namespace {
@@ -321,6 +330,21 @@ NativeWindowViews::~NativeWindowViews() {
   window_->RemoveObserver(this);
 }
 
+void NativeWindowViews::RenderViewCreated(
+    content::RenderViewHost* render_view_host) {
+  std::cout << "NativeWindowViews::RenderViewCreated" << std::endl;
+  NativeWindow::RenderViewCreated(render_view_host);
+
+  content::RenderWidgetHostImpl* impl = content::RenderWidgetHostImpl::FromID(
+      render_view_host->GetProcess()->GetID(),
+      render_view_host->GetRoutingID());
+  if (impl) {
+    ui::Layer* layer = widget()->GetCompositor()->root_layer();
+    ui::Compositor* compositor_ = widget()->GetCompositor();
+    compositor_->RequestNewOutputSurface();
+  }
+}
+
 void NativeWindowViews::Close() {
   if (!IsClosable()) {
     WindowList::WindowCloseCancelled(this);
index 69d3d27..921cb11 100644 (file)
@@ -49,6 +49,7 @@ class NativeWindowViews : public NativeWindow,
   ~NativeWindowViews() override;
 
   // NativeWindow:
+  void RenderViewCreated(content::RenderViewHost*) override;
   void Close() override;
   void CloseImmediately() override;
   void Focus(bool focus) override;
diff --git a/atom/browser/osr_window.cc b/atom/browser/osr_window.cc
new file mode 100644 (file)
index 0000000..98e4b47
--- /dev/null
@@ -0,0 +1,623 @@
+// Copyright (c) 2013 GitHub, Inc.
+// Use of this source code is governed by the MIT license that can be
+// found in the LICENSE file.
+
+#include "atom/browser/osr_window.h"
+#include "third_party/WebKit/public/platform/WebScreenInfo.h"
+#include "content/browser/renderer_host/render_widget_host_impl.h"
+#include "content/browser/renderer_host/render_widget_host_delegate.h"
+#include "content/public/browser/render_widget_host_view_frame_subscriber.h"
+#include "ui/events/latency_info.h"
+#include "content/common/view_messages.h"
+#include "ui/gfx/geometry/dip_util.h"
+#include "base/memory/ptr_util.h"
+#include "content/public/browser/context_factory.h"
+#include "base/single_thread_task_runner.h"
+#include "ui/compositor/layer.h"
+#include "ui/compositor/layer_type.h"
+#include "base/location.h"
+#include "ui/gfx/native_widget_types.h"
+#include <iostream>
+#include <chrono>
+#include <thread>
+
+#include "third_party/skia/include/core/SkSurface.h"
+#include "third_party/skia/include/core/SkPixmap.h"
+#include "cc/output/output_surface_client.h"
+
+#include "content/browser/compositor/software_browser_compositor_output_surface.h"
+
+namespace atom {
+
+OffScreenOutputSurface::OffScreenOutputSurface(
+  std::unique_ptr<cc::SoftwareOutputDevice> device)
+: OutputSurface(nullptr, nullptr, std::move(device)) {
+  std::cout << "OffScreenOutputSurface" << std::endl;
+}
+
+OffScreenOutputSurface::~OffScreenOutputSurface() {
+  std::cout << "~OffScreenOutputSurface" << std::endl;
+}
+
+void OffScreenOutputSurface::SwapBuffers(cc::CompositorFrame* frame) {
+  std::cout << "SwapBuffers" << std::endl;
+
+  base::TimeTicks swap_time = base::TimeTicks::Now();
+  for (auto& latency : frame->metadata.latency_info) {
+    latency.AddLatencyNumberWithTimestamp(
+      ui::INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT, 0, 0, swap_time, 1);
+    latency.AddLatencyNumberWithTimestamp(
+      ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 0, 0,
+      swap_time, 1);
+  }
+
+  base::ThreadTaskRunnerHandle::Get()->PostTask(
+    FROM_HERE, base::Bind(&content::RenderWidgetHostImpl::CompositorFrameDrawn,
+      frame->metadata.latency_info));
+
+  client_->DidSwapBuffers();
+  PostSwapBuffersComplete();
+}
+
+bool OffScreenOutputSurface::BindToClient(cc::OutputSurfaceClient* client) {
+  client_ = client;
+  return true;
+}
+
+OffScreenOutputDevice::OffScreenOutputDevice() {
+  std::cout << "OffScreenOutputDevice" << std::endl;
+}
+
+OffScreenOutputDevice::~OffScreenOutputDevice() {
+  std::cout << "~OffScreenOutputDevice" << std::endl;
+}
+
+// Discards any pre-existing backing buffers and allocates memory for a
+// software device of |size|. This must be called before the
+// |SoftwareOutputDevice| can be used in other ways.
+void OffScreenOutputDevice::Resize(
+  const gfx::Size& pixel_size, float scale_factor) {
+  std::cout << "Resize" << std::endl;
+
+  std::cout << pixel_size.width() << "x" << pixel_size.height() << std::endl;
+
+  scale_factor_ = scale_factor;
+  if (viewport_pixel_size_ == pixel_size)
+    return;
+  viewport_pixel_size_ = pixel_size;
+
+  surface_ = SkSurface::MakeRasterN32Premul(
+    viewport_pixel_size_.width(), viewport_pixel_size_.height());
+}
+
+// Called on BeginDrawingFrame. The compositor will draw into the returned
+// SkCanvas. The |SoftwareOutputDevice| implementation needs to provide a
+// valid SkCanvas of at least size |damage_rect|. This class retains ownership
+// of the SkCanvas.
+SkCanvas* OffScreenOutputDevice::BeginPaint(const gfx::Rect& damage_rect) {
+  std::cout << "BeginPaint" << std::endl;
+  damage_rect_ = damage_rect;
+  if (surface_.get())
+    return surface_->getCanvas();
+
+  return nullptr;
+}
+
+// Called on FinishDrawingFrame. The compositor will no longer mutate the the
+// SkCanvas instance returned by |BeginPaint| and should discard any reference
+// that it holds to it.
+void OffScreenOutputDevice::EndPaint() {
+  std::cout << "EndPaint" << std::endl;
+  SkPixmap pixmap;
+  if (surface_->peekPixels(&pixmap)) {
+    std::cout << "OK" << std::endl;
+    for(int i = 0; i < 10; i++) {
+      const uint8_t* addr = reinterpret_cast<const uint8_t*>(pixmap.addr(50,i));
+      for(int j = 0; j < 4; j++)
+        std::cout << std::hex << static_cast<int>(*(addr + j)) << std::dec << " ";
+      std::cout << std::endl;
+    }
+  }
+}
+
+// Discard the backing buffer in the surface provided by this instance.
+void OffScreenOutputDevice::DiscardBackbuffer() {
+  std::cout << "DiscardBackbuffer" << std::endl;
+}
+
+// Ensures that there is a backing buffer available on this instance.
+void OffScreenOutputDevice::EnsureBackbuffer() {
+  std::cout << "EnsureBackbuffer" << std::endl;
+}
+
+// VSyncProvider used to update the timer used to schedule draws with the
+// hardware vsync. Return NULL if a provider doesn't exist.
+gfx::VSyncProvider* OffScreenOutputDevice::GetVSyncProvider() {
+  std::cout << "GetVSyncProvider" << std::endl;
+  return nullptr;
+}
+
+OffScreenWindow::OffScreenWindow(
+  content::RenderWidgetHost* host)
+  : host_(content::RenderWidgetHostImpl::From(host)),
+    delegated_frame_host_(new content::DelegatedFrameHost(this)),
+    focus_(false),
+    size_(gfx::Size(0,0)),
+    scale_(0.0) {
+  std::cout << "OffScreenWindow" << std::endl;
+  //std::this_thread::sleep_for(std::chrono::milliseconds(5000));
+  host_->SetView(this);
+
+  SetLayer(new ui::Layer(ui::LayerType::LAYER_SOLID_COLOR));
+  layer()->SetVisible(true);
+  layer()->set_delegate(this);
+  layer()->set_name("OffScreenWindowLayer");
+  layer()->SetFillsBoundsOpaquely(false);
+
+  ui::ContextFactory* factory = content::GetContextFactory();
+  thread_ = new base::Thread("Compositor");
+  thread_->Start();
+
+  //compositor_ = new ui::Compositor(factory, thread_->task_runner());
+  compositor_ = new ui::Compositor(
+    factory, base::ThreadTaskRunnerHandle::Get());
+  delegated_frame_host_->ResetCompositor();
+  delegated_frame_host_->SetCompositor(compositor_);
+  compositor_->SetRootLayer(layer());
+
+  set_layer_owner_delegate(delegated_frame_host_);
+
+  std::unique_ptr<cc::SoftwareOutputDevice> device(new OffScreenOutputDevice());
+  std::unique_ptr<cc::OutputSurface> output_surface(
+    new OffScreenOutputSurface(
+      std::move(device)));
+
+  std::unique_ptr<gfx::WindowImpl> window_(new AtomCompositorHostWin());
+
+  compositor_->SetOutputSurface(std::move(output_surface));
+  compositor_->SetAcceleratedWidget(window_->hwnd());
+  std::cout << compositor_ << std::endl;
+}
+
+OffScreenWindow::~OffScreenWindow() {
+  std::cout << "~OffScreenWindow" << std::endl;
+}
+
+bool OffScreenWindow::OnMessageReceived(const IPC::Message& message) {
+  std::cout << "OnMessageReceived" << std::endl;
+  std::cout << message.type() << std::endl;
+
+  bool handled = true;
+  IPC_BEGIN_MESSAGE_MAP(OffScreenWindow, message)
+    IPC_MESSAGE_HANDLER(ViewHostMsg_SetNeedsBeginFrames,
+                        OnSetNeedsBeginFrames)
+    IPC_MESSAGE_UNHANDLED(handled = false)
+  IPC_END_MESSAGE_MAP()
+  return handled;
+}
+
+void OffScreenWindow::InitAsChild(gfx::NativeView) {
+  std::cout << "InitAsChild" << std::endl;
+}
+
+content::RenderWidgetHost* OffScreenWindow::GetRenderWidgetHost() const {
+  std::cout << "GetRenderWidgetHost" << std::endl;
+  return host_;
+}
+
+void OffScreenWindow::SetSize(const gfx::Size& new_size) {
+  std::cout << "SetSize" << std::endl;
+  std::cout << new_size.width() << "x" << new_size.height() << std::endl;
+  size_ = new_size;
+  compositor_->SetScaleAndSize(scale_, size_);
+}
+
+void OffScreenWindow::SetBounds(const gfx::Rect& new_bounds) {
+  std::cout << "SetBounds" << std::endl;
+  std::cout << new_bounds.width() << "x" << new_bounds.height() << std::endl;
+}
+
+gfx::Vector2dF OffScreenWindow::GetLastScrollOffset() const {
+  std::cout << "GetLastScrollOffset" << std::endl;
+  return last_scroll_offset_;
+}
+
+gfx::NativeView OffScreenWindow::GetNativeView() const {
+  std::cout << "GetNativeView" << std::endl;
+  return static_cast<gfx::NativeView>(NULL);
+}
+
+gfx::NativeViewId OffScreenWindow::GetNativeViewId() const {
+  std::cout << "GetNativeViewId" << std::endl;
+  return static_cast<gfx::NativeViewId>(NULL);
+}
+
+gfx::NativeViewAccessible OffScreenWindow::GetNativeViewAccessible() {
+  std::cout << "GetNativeViewAccessible" << std::endl;
+  return static_cast<gfx::NativeViewAccessible>(NULL);
+}
+
+ui::TextInputClient* OffScreenWindow::GetTextInputClient() {
+  std::cout << "GetTextInputClient" << std::endl;
+  return nullptr;
+}
+
+void OffScreenWindow::Focus() {
+  std::cout << "Focus" << std::endl;
+  focus_ = true;
+}
+
+bool OffScreenWindow::HasFocus() const {
+  std::cout << "HasFocus" << std::endl;
+  return focus_;
+}
+
+bool OffScreenWindow::IsSurfaceAvailableForCopy() const {
+  std::cout << "IsSurfaceAvailableForCopy" << std::endl;
+  return delegated_frame_host_->CanCopyToBitmap();
+}
+
+void OffScreenWindow::Show() {
+  std::cout << "Show" << std::endl;
+  ui::LatencyInfo latency_info;
+
+  if (delegated_frame_host_->HasSavedFrame())
+    latency_info.AddLatencyNumber(
+      ui::TAB_SHOW_COMPONENT, host_->GetLatencyComponentId(), 0);
+
+  delegated_frame_host_->WasShown(latency_info);
+}
+
+void OffScreenWindow::Hide() {
+  std::cout << "Hide" << std::endl;
+  if (host_ && !host_->is_hidden())
+    delegated_frame_host_->WasHidden();
+}
+
+bool OffScreenWindow::IsShowing() {
+  std::cout << "IsShowing" << std::endl;
+  return true;
+}
+
+gfx::Rect OffScreenWindow::GetViewBounds() const {
+  std::cout << "GetViewBounds" << std::endl;
+  return gfx::Rect(size_);
+}
+
+gfx::Size OffScreenWindow::GetVisibleViewportSize() const {
+  std::cout << "GetVisibleViewportSize" << std::endl;
+  return size_;
+}
+
+void OffScreenWindow::SetInsets(const gfx::Insets& insets) {
+  std::cout << "SetInsets" << std::endl;
+  host_->WasResized();
+}
+
+bool OffScreenWindow::LockMouse() {
+  std::cout << "LockMouse" << std::endl;
+  return false;
+}
+
+void OffScreenWindow::UnlockMouse() {
+  std::cout << "UnlockMouse" << std::endl;
+}
+
+bool OffScreenWindow::GetScreenColorProfile(std::vector<char>*) {
+  std::cout << "GetScreenColorProfile" << std::endl;
+  return false;
+}
+
+void OffScreenWindow::ClearCompositorFrame() {
+  std::cout << "ClearCompositorFrame" << std::endl;
+  delegated_frame_host_->ClearDelegatedFrame();
+}
+
+void OffScreenWindow::InitAsPopup(content::RenderWidgetHostView *, const gfx::Rect &) {
+  std::cout << "InitAsPopup" << std::endl;
+}
+
+void OffScreenWindow::InitAsFullscreen(content::RenderWidgetHostView *) {
+  std::cout << "InitAsFullscreen" << std::endl;
+}
+
+void OffScreenWindow::UpdateCursor(const content::WebCursor &) {
+  std::cout << "UpdateCursor" << std::endl;
+}
+
+void OffScreenWindow::SetIsLoading(bool loading) {
+  std::cout << "SetIsLoading" << std::endl;
+  if (!loading) {
+    std::cout << "IsDrawn" << std::endl;
+    std::cout << layer()->IsDrawn() << std::endl;
+    layer()->SchedulePaint(gfx::Rect(size_));
+  }
+}
+
+void OffScreenWindow::TextInputStateChanged(const ViewHostMsg_TextInputState_Params &) {
+  std::cout << "TextInputStateChanged" << std::endl;
+}
+
+void OffScreenWindow::ImeCancelComposition() {
+  std::cout << "ImeCancelComposition" << std::endl;
+}
+
+void OffScreenWindow::RenderProcessGone(base::TerminationStatus,int) {
+  std::cout << "RenderProcessGone" << std::endl;
+  Destroy();
+}
+
+void OffScreenWindow::Destroy() {
+  std::cout << "Destroy" << std::endl;
+  thread_->Stop();
+}
+
+void OffScreenWindow::SetTooltipText(const base::string16 &) {
+  std::cout << "SetTooltipText" << std::endl;
+}
+
+void OffScreenWindow::SelectionBoundsChanged(const ViewHostMsg_SelectionBounds_Params &) {
+  std::cout << "SelectionBoundsChanged" << std::endl;
+}
+
+void OffScreenWindow::CopyFromCompositingSurface(const gfx::Rect& src_subrect,
+  const gfx::Size& dst_size,
+  const content::ReadbackRequestCallback& callback,
+  const SkColorType preferred_color_type) {
+  delegated_frame_host_->CopyFromCompositingSurface(
+    src_subrect, dst_size, callback, preferred_color_type);
+  std::cout << "CopyFromCompositingSurface" << std::endl;
+  delegated_frame_host_->CopyFromCompositingSurface(
+    src_subrect, dst_size, callback, preferred_color_type);
+}
+
+void OffScreenWindow::CopyFromCompositingSurfaceToVideoFrame(
+  const gfx::Rect& src_subrect,
+  const scoped_refptr<media::VideoFrame>& target,
+  const base::Callback<void (const gfx::Rect&, bool)>& callback) {
+  delegated_frame_host_->CopyFromCompositingSurfaceToVideoFrame(
+    src_subrect, target, callback);
+  std::cout << "CopyFromCompositingSurfaceToVideoFrame" << std::endl;
+  delegated_frame_host_->CopyFromCompositingSurfaceToVideoFrame(
+    src_subrect, target, callback);
+}
+
+bool OffScreenWindow::CanCopyToVideoFrame() const {
+  std::cout << "CanCopyToVideoFrame" << std::endl;
+  return delegated_frame_host_->CanCopyToVideoFrame();
+}
+
+void OffScreenWindow::BeginFrameSubscription(
+  std::unique_ptr<content::RenderWidgetHostViewFrameSubscriber> subscriber) {
+  std::cout << "BeginFrameSubscription" << std::endl;
+  delegated_frame_host_->BeginFrameSubscription(std::move(subscriber));
+}
+
+void OffScreenWindow::EndFrameSubscription() {
+  std::cout << "EndFrameSubscription" << std::endl;
+  delegated_frame_host_->EndFrameSubscription();
+}
+
+bool OffScreenWindow::HasAcceleratedSurface(const gfx::Size &) {
+  std::cout << "HasAcceleratedSurface" << std::endl;
+  return false;
+}
+
+void OffScreenWindow::GetScreenInfo(blink::WebScreenInfo* results) {
+  std::cout << "GetScreenInfo" << std::endl;
+
+  results->rect = gfx::Rect(size_);
+  results->availableRect = gfx::Rect(size_);
+  results->depth = 24;
+  results->depthPerComponent = 8;
+  results->deviceScaleFactor = scale_;
+  results->orientationAngle = 0;
+  results->orientationType = blink::WebScreenOrientationLandscapePrimary;
+}
+
+bool OffScreenWindow::GetScreenColorProfile(blink::WebVector<char>*) {
+  std::cout << "GetScreenColorProfile" << std::endl;
+  return false;
+}
+
+gfx::Rect OffScreenWindow::GetBoundsInRootWindow() {
+  std::cout << "GetBoundsInRootWindow" << std::endl;
+  return gfx::Rect(size_);
+}
+
+void OffScreenWindow::LockCompositingSurface() {
+  std::cout << "LockCompositingSurface" << std::endl;
+}
+
+void OffScreenWindow::UnlockCompositingSurface() {
+  std::cout << "UnlockCompositingSurface" << std::endl;
+}
+
+void OffScreenWindow::ImeCompositionRangeChanged(
+  const gfx::Range &, const std::vector<gfx::Rect>&) {
+  std::cout << "ImeCompositionRangeChanged" << std::endl;
+}
+
+int OffScreenWindow::DelegatedFrameHostGetGpuMemoryBufferClientId() const {
+  std::cout << "DelegatedFrameHostGetGpuMemoryBufferClientId" << std::endl;
+  return host_->GetProcess()->GetID();
+}
+
+ui::Layer* OffScreenWindow::DelegatedFrameHostGetLayer() const {
+  std::cout << "DelegatedFrameHostGetLayer" << std::endl;
+  return const_cast<ui::Layer*>(layer());
+}
+
+bool OffScreenWindow::DelegatedFrameHostIsVisible() const {
+  std::cout << "DelegatedFrameHostIsVisible" << std::endl;
+  std::cout << !host_->is_hidden() << std::endl;
+  return !host_->is_hidden();
+}
+
+SkColor OffScreenWindow::DelegatedFrameHostGetGutterColor(SkColor color) const {
+  std::cout << "DelegatedFrameHostGetGutterColor" << std::endl;
+  return color;
+}
+
+gfx::Size OffScreenWindow::DelegatedFrameHostDesiredSizeInDIP() const {
+  std::cout << "DelegatedFrameHostDesiredSizeInDIP" << std::endl;
+  return size_;
+}
+
+bool OffScreenWindow::DelegatedFrameCanCreateResizeLock() const {
+  std::cout << "DelegatedFrameCanCreateResizeLock" << std::endl;
+  return false;
+}
+
+std::unique_ptr<content::ResizeLock>
+  OffScreenWindow::DelegatedFrameHostCreateResizeLock(bool) {
+  std::cout << "DelegatedFrameHostCreateResizeLock" << std::endl;
+  return nullptr;
+}
+
+void OffScreenWindow::DelegatedFrameHostResizeLockWasReleased() {
+  std::cout << "DelegatedFrameHostResizeLockWasReleased" << std::endl;
+  host_->WasResized();
+}
+
+void OffScreenWindow::DelegatedFrameHostSendCompositorSwapAck(
+  int output_surface_id, const cc::CompositorFrameAck& ack) {
+  std::cout << "DelegatedFrameHostSendCompositorSwapAck" << std::endl;
+  host_->Send(new ViewMsg_SwapCompositorFrameAck(host_->GetRoutingID(),
+    output_surface_id, ack));
+}
+
+void OffScreenWindow::DelegatedFrameHostSendReclaimCompositorResources(
+  int output_surface_id, const cc::CompositorFrameAck& ack) {
+  std::cout << "DelegatedFrameHostSendReclaimCompositorResources" << std::endl;
+  host_->Send(new ViewMsg_ReclaimCompositorResources(host_->GetRoutingID(),
+    output_surface_id, ack));
+}
+
+void OffScreenWindow::DelegatedFrameHostOnLostCompositorResources() {
+  std::cout << "DelegatedFrameHostOnLostCompositorResources" << std::endl;
+  host_->ScheduleComposite();
+}
+
+void OffScreenWindow::DelegatedFrameHostUpdateVSyncParameters(
+  const base::TimeTicks& timebase, const base::TimeDelta& interval) {
+  std::cout << "DelegatedFrameHostUpdateVSyncParameters" << std::endl;
+  host_->UpdateVSyncParameters(timebase, interval);
+}
+
+
+
+void OffScreenWindow::OnBeginFrame(const cc::BeginFrameArgs& args) {
+  std::cout << "OnBeginFrame" << std::endl;
+
+  delegated_frame_host_->SetVSyncParameters(args.frame_time, args.interval);
+  host_->Send(new ViewMsg_BeginFrame(host_->GetRoutingID(), args));
+  last_begin_frame_args_ = args;
+}
+
+const cc::BeginFrameArgs& OffScreenWindow::LastUsedBeginFrameArgs() const {
+  std::cout << "LastUsedBeginFrameArgs" << std::endl;
+  return last_begin_frame_args_;
+}
+
+void OffScreenWindow::OnBeginFrameSourcePausedChanged(bool) {
+  std::cout << "OnBeginFrameSourcePausedChanged" << std::endl;
+}
+
+void OffScreenWindow::AsValueInto(base::trace_event::TracedValue *) const {
+  std::cout << "AsValueInto" << std::endl;
+}
+
+gfx::Size OffScreenWindow::GetPhysicalBackingSize() const {
+  std::cout << "GetPhysicalBackingSize" << std::endl;
+  return size_;
+}
+
+void OffScreenWindow::UpdateScreenInfo(gfx::NativeView view) {
+  std::cout << "UpdateScreenInfo" << std::endl;
+  content::RenderWidgetHostImpl* impl = NULL;
+  if (GetRenderWidgetHost())
+    impl = content::RenderWidgetHostImpl::From(GetRenderWidgetHost());
+
+  if (impl && impl->delegate())
+    impl->delegate()->SendScreenRects();
+
+  if (HasDisplayPropertyChanged(view) && impl)
+    impl->NotifyScreenInfoChanged();
+}
+
+gfx::Size OffScreenWindow::GetRequestedRendererSize() const {
+  std::cout << "GetRequestedRendererSize" << std::endl;
+  gfx::Size size = delegated_frame_host_->GetRequestedRendererSize();
+
+  std::cout << size.width() << "x" << size.height() << std::endl;
+
+  return size;
+}
+
+void OffScreenWindow::OnSwapCompositorFrame(uint32_t output_surface_id,
+  cc::CompositorFrame frame) {
+  std::cout << "OnSwapCompositorFrame" << std::endl;
+
+  last_scroll_offset_ = frame.metadata.root_scroll_offset;
+  if (!frame.delegated_frame_data) return;
+
+  delegated_frame_host_->SwapDelegatedFrame(
+    output_surface_id, base::WrapUnique(&frame));
+}
+
+uint32_t OffScreenWindow::SurfaceIdNamespaceAtPoint(
+  cc::SurfaceHittestDelegate* delegate,
+  const gfx::Point& point,
+  gfx::Point* transformed_point) {
+  std::cout << "SurfaceIdNamespaceAtPoint" << std::endl;
+
+  gfx::Point point_in_pixels = gfx::ConvertPointToPixel(scale_, point);
+  cc::SurfaceId id = delegated_frame_host_->SurfaceIdAtPoint(
+      delegate, point_in_pixels, transformed_point);
+  *transformed_point = gfx::ConvertPointToDIP(scale_, *transformed_point);
+
+  if (id.is_null())
+    return GetSurfaceIdNamespace();
+  return id.id_namespace();
+}
+
+uint32_t OffScreenWindow::GetSurfaceIdNamespace() {
+  std::cout << "GetSurfaceIdNamespace" << std::endl;
+  return delegated_frame_host_->GetSurfaceIdNamespace();
+}
+
+void OffScreenWindow::OnPaintLayer(const ui::PaintContext &) {
+  std::cout << "OnPaintLayer" << std::endl;
+}
+
+void OffScreenWindow::OnDelegatedFrameDamage(const gfx::Rect &) {
+  std::cout << "OnDelegatedFrameDamage" << std::endl;
+}
+
+void OffScreenWindow::OnDeviceScaleFactorChanged(float scale) {
+  std::cout << "OnDeviceScaleFactorChanged" << std::endl;
+  scale_ = scale;
+}
+
+base::Closure OffScreenWindow::PrepareForLayerBoundsChange() {
+  std::cout << "PrepareForLayerBoundsChange" << std::endl;
+  return base::Bind(&OffScreenWindow::OnBoundsChanged, base::Unretained(this));
+}
+
+void OffScreenWindow::OnBoundsChanged() {
+  std::cout << "OnBoundsChanged" << std::endl;
+}
+
+void OffScreenWindow::OnSetNeedsBeginFrames(bool needs_begin_frames) {
+  std::cout << "OnSetNeedsBeginFrames" << std::endl;
+}
+
+void OffScreenWindow::SendSwapCompositorFrame(cc::CompositorFrame* frame) {
+  std::cout << "SendSwapCompositorFrame" << std::endl;
+  std::vector<IPC::Message> messages_to_deliver_with_frame;
+  /*host_->Send(new ViewHostMsg_SwapCompositorFrame(host_->GetRoutingID(),
+    10, *frame, messages_to_deliver_with_frame));*/
+}
+
+}  // namespace atom
diff --git a/atom/browser/osr_window.h b/atom/browser/osr_window.h
new file mode 100644 (file)
index 0000000..ac5545f
--- /dev/null
@@ -0,0 +1,206 @@
+// Copyright (c) 2013 GitHub, Inc.
+// Use of this source code is governed by the MIT license that can be
+// found in the LICENSE file.
+
+#ifndef ATOM_BROWSER_OSR_WINDOW_H_
+#define ATOM_BROWSER_OSR_WINDOW_H_
+
+#include "content/browser/renderer_host/render_widget_host_view_base.h"
+#include "content/browser/renderer_host/delegated_frame_host.h"
+#include "content/browser/renderer_host/resize_lock.h"
+#include "third_party/WebKit/public/platform/WebVector.h"
+#include "cc/scheduler/begin_frame_source.h"
+#include "content/browser/renderer_host/render_widget_host_impl.h"
+#include "cc/output/compositor_frame.h"
+#include "ui/gfx/geometry/point.h"
+#include "base/threading/thread.h"
+#include "ui/compositor/compositor.h"
+#include "ui/compositor/layer_delegate.h"
+#include "ui/compositor/layer_owner.h"
+#include "ui/base/ime/text_input_client.h"
+#include "base/process/kill.h"
+
+#include "cc/output/software_output_device.h"
+#include "cc/output/output_surface.h"
+#include "cc/output/output_surface_client.h"
+#include "cc/scheduler/begin_frame_source.h"
+
+#include <windows.h>
+#include "ui/gfx/win/window_impl.h"
+
+namespace atom {
+
+class AtomCompositorHostWin : public gfx::WindowImpl {
+ public:
+  AtomCompositorHostWin() {
+    // Create a hidden 1x1 borderless window.
+    set_window_style(WS_POPUP | WS_SYSMENU);
+    Init(NULL, gfx::Rect(0, 0, 1, 1));
+  }
+
+  ~AtomCompositorHostWin() override {
+    DestroyWindow(hwnd());
+  }
+
+ private:
+  CR_BEGIN_MSG_MAP_EX(CompositorHostWin)
+    CR_MSG_WM_PAINT(OnPaint)
+  CR_END_MSG_MAP()
+
+  void OnPaint(HDC dc) {
+    ValidateRect(hwnd(), NULL);
+  }
+};
+
+class OffScreenWindow
+    : public content::RenderWidgetHostViewBase,
+      public content::DelegatedFrameHostClient,
+      public cc::BeginFrameObserver,
+      public ui::LayerDelegate,
+      public ui::LayerOwner {
+public:
+  OffScreenWindow(content::RenderWidgetHost*);
+  ~OffScreenWindow();
+
+//content::RenderWidgetHostView
+  bool OnMessageReceived(const IPC::Message&) override;
+  void InitAsChild(gfx::NativeView);\r
+  content::RenderWidgetHost* GetRenderWidgetHost(void) const;\r
+  void SetSize(const gfx::Size &);\r
+  void SetBounds(const gfx::Rect &);\r
+  gfx::Vector2dF GetLastScrollOffset(void) const;\r
+  gfx::NativeView GetNativeView(void) const;\r
+  gfx::NativeViewId GetNativeViewId(void) const;\r
+  gfx::NativeViewAccessible GetNativeViewAccessible(void);\r
+  ui::TextInputClient* GetTextInputClient() override;\r
+  void Focus(void);\r
+  bool HasFocus(void) const;\r
+  bool IsSurfaceAvailableForCopy(void) const;\r
+  void Show(void);\r
+  void Hide(void);\r
+  bool IsShowing(void);\r
+  gfx::Rect GetViewBounds(void) const;\r
+  gfx::Size GetVisibleViewportSize() const override;\r
+  void SetInsets(const gfx::Insets&) override;\r
+  bool LockMouse(void);\r
+  void UnlockMouse(void);\r
+  bool GetScreenColorProfile(std::vector<char>*);\r
+\r
+//content::RenderWidgetHostViewBase\r
+  void ClearCompositorFrame(void);\r
+  void InitAsPopup(content::RenderWidgetHostView *, const gfx::Rect &);\r
+  void InitAsFullscreen(content::RenderWidgetHostView *);\r
+  void UpdateCursor(const content::WebCursor &);\r
+  void SetIsLoading(bool);\r
+  void TextInputStateChanged(const ViewHostMsg_TextInputState_Params &);\r
+  void ImeCancelComposition(void);\r
+  void RenderProcessGone(base::TerminationStatus,int);\r
+  void Destroy(void);\r
+  void SetTooltipText(const base::string16 &);\r
+  void SelectionBoundsChanged(const ViewHostMsg_SelectionBounds_Params &);\r
+  void CopyFromCompositingSurface(const gfx::Rect &,\r
+    const gfx::Size &,\r
+    const content::ReadbackRequestCallback &,\r
+    const SkColorType);\r
+  void CopyFromCompositingSurfaceToVideoFrame(\r
+    const gfx::Rect &,\r
+    const scoped_refptr<media::VideoFrame> &,\r
+    const base::Callback<void (const gfx::Rect &, bool),\r
+    base::internal::CopyMode::Copyable> &);\r
+  bool CanCopyToVideoFrame(void) const;\r
+  void BeginFrameSubscription(\r
+    std::unique_ptr<content::RenderWidgetHostViewFrameSubscriber>);\r
+  void EndFrameSubscription();\r
+  bool HasAcceleratedSurface(const gfx::Size &);\r
+  void GetScreenInfo(blink::WebScreenInfo *);\r
+  bool GetScreenColorProfile(blink::WebVector<char>*);\r
+  gfx::Rect GetBoundsInRootWindow(void);\r
+  void LockCompositingSurface(void);\r
+  void UnlockCompositingSurface(void);\r
+  void ImeCompositionRangeChanged(
+    const gfx::Range &, const std::vector<gfx::Rect>&);
+
+//content::DelegatedFrameHostClient
+  int DelegatedFrameHostGetGpuMemoryBufferClientId(void) const;
+  ui::Layer *DelegatedFrameHostGetLayer(void) const;
+  bool DelegatedFrameHostIsVisible(void) const;
+  SkColor DelegatedFrameHostGetGutterColor(SkColor) const;
+  gfx::Size DelegatedFrameHostDesiredSizeInDIP(void) const;
+  bool DelegatedFrameCanCreateResizeLock(void) const;
+  std::unique_ptr<content::ResizeLock> DelegatedFrameHostCreateResizeLock(bool);
+  void DelegatedFrameHostResizeLockWasReleased(void);
+  void DelegatedFrameHostSendCompositorSwapAck(
+    int, const cc::CompositorFrameAck &);
+  void DelegatedFrameHostSendReclaimCompositorResources(
+    int, const cc::CompositorFrameAck &);
+  void DelegatedFrameHostOnLostCompositorResources(void);
+  void DelegatedFrameHostUpdateVSyncParameters(
+    const base::TimeTicks &, const base::TimeDelta &);
+
+//cc::BeginFrameObserver
+  void OnBeginFrame(const cc::BeginFrameArgs &);
+  const cc::BeginFrameArgs & LastUsedBeginFrameArgs(void) const;
+  void OnBeginFrameSourcePausedChanged(bool);
+  void AsValueInto(base::trace_event::TracedValue *) const;
+
+  gfx::Size GetPhysicalBackingSize() const;
+  void UpdateScreenInfo(gfx::NativeView view);
+  gfx::Size GetRequestedRendererSize() const;
+  void OnSwapCompositorFrame(uint32_t, cc::CompositorFrame);
+  uint32_t SurfaceIdNamespaceAtPoint(
+    cc::SurfaceHittestDelegate* delegate,
+    const gfx::Point& point,
+    gfx::Point* transformed_point);
+  uint32_t GetSurfaceIdNamespace();
+
+  void OnPaintLayer(const ui::PaintContext &);
+  void OnDelegatedFrameDamage(const gfx::Rect &);
+  void OnDeviceScaleFactorChanged(float);
+  base::Closure PrepareForLayerBoundsChange();
+  void OnBoundsChanged();
+
+  void OnSetNeedsBeginFrames(bool);
+  void SendSwapCompositorFrame(cc::CompositorFrame *);
+private:
+  content::RenderWidgetHostImpl* host_;
+  content::DelegatedFrameHost* delegated_frame_host_;
+  gfx::Vector2dF last_scroll_offset_;
+  bool focus_;
+  gfx::Size size_;
+  float scale_;
+
+  cc::BeginFrameSource* begin_frame_source_;
+  cc::BeginFrameArgs last_begin_frame_args_;
+  bool needs_begin_frames_;
+
+  base::Thread* thread_;
+  ui::Compositor* compositor_;
+};
+
+class OffScreenOutputSurface : public cc::OutputSurface {
+public:
+  OffScreenOutputSurface(
+    std::unique_ptr<cc::SoftwareOutputDevice>);
+  ~OffScreenOutputSurface();
+
+  void SwapBuffers(cc::CompositorFrame *);
+  bool BindToClient(cc::OutputSurfaceClient *);
+};
+
+class OffScreenOutputDevice : public cc::SoftwareOutputDevice {
+public:
+  OffScreenOutputDevice();
+  ~OffScreenOutputDevice();
+
+  void Resize(const gfx::Size& pixel_size, float scale_factor);
+  SkCanvas* BeginPaint(const gfx::Rect& damage_rect);
+  void EndPaint();
+  void DiscardBackbuffer();
+  void EnsureBackbuffer();
+  gfx::VSyncProvider* GetVSyncProvider();
+};
+
+
+}  // namespace atom
+
+#endif  // ATOM_BROWSER_OSR_WINDOW_H_
index a72675e..9f28872 100644 (file)
@@ -18,5 +18,10 @@ exports.load = (appUrl) => {
     })
     mainWindow.loadURL(appUrl)
     mainWindow.focus()
+    mainWindow.webContents.on('dom-ready', () => {
+      mainWindow.webContents.beginFrameSubscription(() => {
+        console.log("asd")
+      })
+    })
   })
 }
index af70808..7c655b8 100644 (file)
       'atom/browser/native_window_mac.h',
       'atom/browser/native_window_mac.mm',
       'atom/browser/native_window_observer.h',
+      'atom/browser/osr_window.cc',
+      'atom/browser/osr_window.h',
       'atom/browser/net/asar/asar_protocol_handler.cc',
       'atom/browser/net/asar/asar_protocol_handler.h',
       'atom/browser/net/asar/url_request_asar_job.cc',