-From 96fed9654a748cb09b19431732b420753b6ff21f Mon Sep 17 00:00:00 2001
-From: Kondapally Kalyan <kalyan.kondapally@intel.com>
+From 4fc6ff1a10f685537508581f0a49b6dc5ed3c049 Mon Sep 17 00:00:00 2001
+From: Tiago Vignatti <tiago.vignatti@intel.com>
 Date: Mon, 23 Sep 2013 20:40:42 +0300
 Subject: [PATCH] Set Wayland as the implementation for SurfaceFactoryOzone
 

     },
     {
diff --git a/ui/aura/demo/demo_main.cc b/ui/aura/demo/demo_main.cc
index abdd514..c4d6a63 100644
--- a/ui/aura/demo/demo_main.cc
+++ b/ui/aura/demo/demo_main.cc
@@ -24,6 +24,8 @@
 #include "ui/gfx/canvas.h"
 #include "ui/gfx/rect.h"
 
+#include "ozone/impl/ozone_display.h"
+
 #if defined(USE_X11)
 #include "base/message_loop/message_pump_x11.h"
 #endif
@@ -108,6 +110,10 @@ class DemoStackingClient : public aura::client::StackingClient {
 };
 
 int DemoMain() {
+  /* TODO: Implementation specific. Has to go away */
+  gfx::SurfaceFactoryOzone *o_factory = new ozonewayland::OzoneDisplay();
+  gfx::SurfaceFactoryOzone::SetInstance(o_factory);
+
   // Create the message-loop here before creating the root window.
   base::MessageLoop message_loop(base::MessageLoop::TYPE_UI);
 
@@ -153,6 +159,9 @@ int DemoMain() {
   root_window->ShowRootWindow();
   base::MessageLoopForUI::current()->Run();
 
+  o_factory->ShutdownHardware();
+  delete o_factory;
+
   return 0;
 }
 

           ['OS=="mac" or chromeos==1', {
             'enable_hidpi%': 1,
diff --git a/chrome/app/chrome_main_delegate.cc b/chrome/app/chrome_main_delegate.cc
index ae7cdaa..013072c 100644
--- a/chrome/app/chrome_main_delegate.cc
+++ b/chrome/app/chrome_main_delegate.cc
@@ -101,6 +101,11 @@
 #include "components/breakpad/app/breakpad_linux.h"
 #endif
 
+#if defined(USE_OZONE)
+#include "ozone/impl/ozone_display.h"
+#include "ozone/impl/desktop_factory_wayland.h"
+#endif
+
 #if !defined(CHROME_MULTIPLE_DLL_CHILD)
 base::LazyInstance<chrome::ChromeContentBrowserClient>
     g_chrome_content_browser_client = LAZY_INSTANCE_INITIALIZER;
@@ -590,6 +595,14 @@ void ChromeMainDelegate::PreSandboxStartup() {
   std::string process_type =
       command_line.GetSwitchValueASCII(switches::kProcessType);
 
+#if defined(USE_OZONE)
+  /* TODO: Implementation specific. Has to go away */
+  gfx::SurfaceFactoryOzone *o_factory = new ozonewayland::OzoneDisplay();
+  gfx::SurfaceFactoryOzone::SetInstance(o_factory);
+  views::DesktopFactoryOzone *d_factory = new ozonewayland::DesktopFactoryWayland();
+  views::DesktopFactoryOzone::SetInstance(d_factory);
+#endif
+
 #if defined(OS_POSIX)
   breakpad::SetBreakpadClient(g_chrome_breakpad_client.Pointer());
 #endif
diff --git a/content/shell/app/shell_main_delegate.cc b/content/shell/app/shell_main_delegate.cc
index d0db696..9112f6d 100644
--- a/content/shell/app/shell_main_delegate.cc
+++ b/content/shell/app/shell_main_delegate.cc
@@ -29,6 +29,11 @@
 #include "ui/gfx/switches.h"
 #include "ui/gl/gl_switches.h"
 
+#if defined(USE_OZONE)
+#include "ozone/impl/desktop_factory_wayland.h"
+#include "ozone/impl/ozone_display.h"
+#endif
+
 #include "ipc/ipc_message.h"  // For IPC_MESSAGE_LOG_ENABLED.
 
 #if defined(IPC_MESSAGE_LOG_ENABLED)
@@ -96,6 +101,14 @@ ShellMainDelegate::ShellMainDelegate() {
 }
 
 ShellMainDelegate::~ShellMainDelegate() {
+#if defined(USE_OZONE)
+  gfx::SurfaceFactoryOzone* surface_factory = gfx::SurfaceFactoryOzone::GetInstance();
+  if (surface_factory) {
+    surface_factory->ShutdownHardware();
+    gfx::SurfaceFactoryOzone::SetInstance(NULL);
+    delete surface_factory;
+  }
+#endif
 }
 
 bool ShellMainDelegate::BasicStartupComplete(int* exit_code) {
@@ -185,6 +198,14 @@ void ShellMainDelegate::PreSandboxStartup() {
     breakpad::SetBreakpadClient(g_shell_breakpad_client.Pointer());
   }
   InitializeResourceBundle();
+
+#if defined(USE_OZONE)
+  /* TODO: Implementation specific. Has to go away */
+  gfx::SurfaceFactoryOzone *o_factory = new ozonewayland::OzoneDisplay();
+  gfx::SurfaceFactoryOzone::SetInstance(o_factory);
+  views::DesktopFactoryOzone *d_factory = new ozonewayland::DesktopFactoryWayland();
+  views::DesktopFactoryOzone::SetInstance(d_factory);
+#endif
 }
 
 int ShellMainDelegate::RunProcess(
