Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ui / aura / demo / demo_main.cc
index 7739ed5..53b87f6 100644 (file)
 #include "ui/aura/client/default_capture_client.h"
 #include "ui/aura/client/window_tree_client.h"
 #include "ui/aura/env.h"
-#include "ui/aura/root_window.h"
 #include "ui/aura/test/test_focus_client.h"
 #include "ui/aura/test/test_screen.h"
 #include "ui/aura/window.h"
 #include "ui/aura/window_delegate.h"
+#include "ui/aura/window_tree_host.h"
 #include "ui/base/hit_test.h"
-#include "ui/compositor/test/context_factories_for_test.h"
+#include "ui/compositor/test/in_process_context_factory.h"
 #include "ui/events/event.h"
 #include "ui/gfx/canvas.h"
 #include "ui/gfx/rect.h"
 #include "ui/gl/gl_surface.h"
 
 #if defined(USE_X11)
-#include "base/message_loop/message_pump_x11.h"
+#include "ui/gfx/x/x11_connection.h"
+#endif
+
+#if defined(OS_WIN)
+#include "ui/gfx/win/dpi.h"
 #endif
 
 namespace {
@@ -35,40 +39,34 @@ class DemoWindowDelegate : public aura::WindowDelegate {
   explicit DemoWindowDelegate(SkColor color) : color_(color) {}
 
   // Overridden from WindowDelegate:
-  virtual gfx::Size GetMinimumSize() const OVERRIDE {
-    return gfx::Size();
-  }
+  gfx::Size GetMinimumSize() const override { return gfx::Size(); }
 
-  virtual gfx::Size GetMaximumSize() const OVERRIDE {
-    return gfx::Size();
-  }
+  gfx::Size GetMaximumSize() const override { return gfx::Size(); }
 
-  virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
-                               const gfx::Rect& new_bounds) OVERRIDE {}
-  virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE {
+  void OnBoundsChanged(const gfx::Rect& old_bounds,
+                       const gfx::Rect& new_bounds) override {}
+  gfx::NativeCursor GetCursor(const gfx::Point& point) override {
     return gfx::kNullCursor;
   }
-  virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE {
+  int GetNonClientComponent(const gfx::Point& point) const override {
     return HTCAPTION;
   }
-  virtual bool ShouldDescendIntoChildForEventHandling(
+  bool ShouldDescendIntoChildForEventHandling(
       aura::Window* child,
-      const gfx::Point& location) OVERRIDE {
+      const gfx::Point& location) override {
     return true;
   }
-  virtual bool CanFocus() OVERRIDE { return true; }
-  virtual void OnCaptureLost() OVERRIDE {}
-  virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
+  bool CanFocus() override { return true; }
+  void OnCaptureLost() override {}
+  void OnPaint(gfx::Canvas* canvas) override {
     canvas->DrawColor(color_, SkXfermode::kSrc_Mode);
   }
-  virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE {}
-  virtual void OnWindowDestroying() OVERRIDE {}
-  virtual void OnWindowDestroyed() OVERRIDE {}
-  virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE {}
-  virtual bool HasHitTestMask() const OVERRIDE { return false; }
-  virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE {}
-  virtual void DidRecreateLayer(ui::Layer* old_layer,
-                                ui::Layer* new_layer) OVERRIDE {}
+  void OnDeviceScaleFactorChanged(float device_scale_factor) override {}
+  void OnWindowDestroying(aura::Window* window) override {}
+  void OnWindowDestroyed(aura::Window* window) override {}
+  void OnWindowTargetVisibilityChanged(bool visible) override {}
+  bool HasHitTestMask() const override { return false; }
+  void GetHitTestMask(gfx::Path* mask) const override {}
 
  private:
   SkColor color_;
@@ -82,14 +80,14 @@ class DemoWindowTreeClient : public aura::client::WindowTreeClient {
     aura::client::SetWindowTreeClient(window_, this);
   }
 
-  virtual ~DemoWindowTreeClient() {
+  ~DemoWindowTreeClient() override {
     aura::client::SetWindowTreeClient(window_, NULL);
   }
 
   // Overridden from aura::client::WindowTreeClient:
-  virtual aura::Window* GetDefaultParent(aura::Window* context,
-                                         aura::Window* window,
-                                         const gfx::Rect& bounds) OVERRIDE {
+  aura::Window* GetDefaultParent(aura::Window* context,
+                                 aura::Window* window,
+                                 const gfx::Rect& bounds) override {
     if (!capture_client_) {
       capture_client_.reset(
           new aura::client::DefaultCaptureClient(window_->GetRootWindow()));
@@ -106,24 +104,36 @@ class DemoWindowTreeClient : public aura::client::WindowTreeClient {
 };
 
 int DemoMain() {
-  // Create the message-loop here before creating the root window.
-  base::MessageLoopForUI message_loop;
+#if defined(USE_X11)
+  // This demo uses InProcessContextFactory which uses X on a separate Gpu
+  // thread.
+  gfx::InitializeThreadedX11();
+#endif
 
   gfx::GLSurface::InitializeOneOff();
 
+#if defined(OS_WIN)
+  gfx::InitDeviceScaleFactor(1.0f);
+#endif
+
   // The ContextFactory must exist before any Compositors are created.
-  bool allow_test_contexts = false;
-  ui::InitializeContextFactoryForTests(allow_test_contexts);
+  scoped_ptr<ui::InProcessContextFactory> context_factory(
+      new ui::InProcessContextFactory());
+
+  // Create the message-loop here before creating the root window.
+  base::MessageLoopForUI message_loop;
 
-  aura::Env::CreateInstance();
-  scoped_ptr<aura::TestScreen> test_screen(aura::TestScreen::Create());
+  aura::Env::CreateInstance(true);
+  aura::Env::GetInstance()->set_context_factory(context_factory.get());
+  scoped_ptr<aura::TestScreen> test_screen(
+      aura::TestScreen::Create(gfx::Size()));
   gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen.get());
-  scoped_ptr<aura::RootWindow> root_window(
-      test_screen->CreateRootWindowForPrimaryDisplay());
-  scoped_ptr<DemoWindowTreeClient> window_tree_client(new DemoWindowTreeClient(
-      root_window->window()));
+  scoped_ptr<aura::WindowTreeHost> host(
+      test_screen->CreateHostForPrimaryDisplay());
+  scoped_ptr<DemoWindowTreeClient> window_tree_client(
+      new DemoWindowTreeClient(host->window()));
   aura::test::TestFocusClient focus_client;
-  aura::client::SetFocusClient(root_window->window(), &focus_client);
+  aura::client::SetFocusClient(host->window(), &focus_client);
 
   // Create a hierarchy of test windows.
   DemoWindowDelegate window_delegate1(SK_ColorBLUE);
@@ -132,8 +142,7 @@ int DemoMain() {
   window1.Init(aura::WINDOW_LAYER_TEXTURED);
   window1.SetBounds(gfx::Rect(100, 100, 400, 400));
   window1.Show();
-  aura::client::ParentWindowWithContext(
-      &window1, root_window->window(), gfx::Rect());
+  aura::client::ParentWindowWithContext(&window1, host->window(), gfx::Rect());
 
   DemoWindowDelegate window_delegate2(SK_ColorRED);
   aura::Window window2(&window_delegate2);
@@ -141,8 +150,7 @@ int DemoMain() {
   window2.Init(aura::WINDOW_LAYER_TEXTURED);
   window2.SetBounds(gfx::Rect(200, 200, 350, 350));
   window2.Show();
-  aura::client::ParentWindowWithContext(
-      &window2, root_window->window(), gfx::Rect());
+  aura::client::ParentWindowWithContext(&window2, host->window(), gfx::Rect());
 
   DemoWindowDelegate window_delegate3(SK_ColorGREEN);
   aura::Window window3(&window_delegate3);
@@ -152,7 +160,7 @@ int DemoMain() {
   window3.Show();
   window2.AddChild(&window3);
 
-  root_window->host()->Show();
+  host->Show();
   base::MessageLoopForUI::current()->Run();
 
   return 0;