Home | History | Annotate | Download | only in examples
      1 // Copyright 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "base/at_exit.h"
      6 #include "base/command_line.h"
      7 #include "base/files/file_path.h"
      8 #include "base/i18n/icu_util.h"
      9 #include "base/message_loop/message_loop.h"
     10 #include "base/path_service.h"
     11 #include "base/run_loop.h"
     12 #include "ui/aura/env.h"
     13 #include "ui/base/ime/input_method_initializer.h"
     14 #include "ui/base/resource/resource_bundle.h"
     15 #include "ui/base/ui_base_paths.h"
     16 #include "ui/compositor/test/in_process_context_factory.h"
     17 #include "ui/gfx/screen.h"
     18 #include "ui/gl/gl_surface.h"
     19 #include "ui/views/examples/example_base.h"
     20 #include "ui/views/examples/examples_window.h"
     21 #include "ui/views/test/desktop_test_views_delegate.h"
     22 #include "ui/wm/core/wm_state.h"
     23 
     24 #if !defined(OS_CHROMEOS)
     25 #include "ui/views/widget/desktop_aura/desktop_screen.h"
     26 #endif
     27 
     28 #if defined(OS_WIN)
     29 #include "ui/base/win/scoped_ole_initializer.h"
     30 #endif
     31 
     32 #if defined(USE_X11)
     33 #include "ui/gfx/x/x11_connection.h"
     34 #endif
     35 
     36 int main(int argc, char** argv) {
     37 #if defined(OS_WIN)
     38   ui::ScopedOleInitializer ole_initializer_;
     39 #endif
     40 
     41   CommandLine::Init(argc, argv);
     42 
     43   base::AtExitManager at_exit;
     44 
     45 #if defined(USE_X11)
     46   // This demo uses InProcessContextFactory which uses X on a separate Gpu
     47   // thread.
     48   gfx::InitializeThreadedX11();
     49 #endif
     50 
     51   gfx::GLSurface::InitializeOneOff();
     52 
     53   // The ContextFactory must exist before any Compositors are created.
     54   scoped_ptr<ui::InProcessContextFactory> context_factory(
     55       new ui::InProcessContextFactory());
     56 
     57   base::MessageLoopForUI message_loop;
     58 
     59   base::i18n::InitializeICU();
     60 
     61   ui::RegisterPathProvider();
     62 
     63   base::FilePath ui_test_pak_path;
     64   DCHECK(PathService::Get(ui::UI_TEST_PAK, &ui_test_pak_path));
     65   ui::ResourceBundle::InitSharedInstanceWithPakPath(ui_test_pak_path);
     66 
     67   aura::Env::CreateInstance(true);
     68   aura::Env::GetInstance()->set_context_factory(context_factory.get());
     69 
     70   ui::InitializeInputMethodForTesting();
     71 
     72   {
     73     views::DesktopTestViewsDelegate views_delegate;
     74     wm::WMState wm_state;
     75 
     76 #if !defined(OS_CHROMEOS)
     77     scoped_ptr<gfx::Screen> desktop_screen(views::CreateDesktopScreen());
     78     gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE,
     79                                    desktop_screen.get());
     80 #endif
     81 
     82     views::examples::ShowExamplesWindow(
     83         views::examples::QUIT_ON_CLOSE,
     84         NULL,
     85         scoped_ptr<ScopedVector<views::examples::ExampleBase> >());
     86 
     87     base::RunLoop().Run();
     88 
     89     ui::ResourceBundle::CleanupSharedInstance();
     90   }
     91 
     92   ui::ShutdownInputMethod();
     93 
     94   aura::Env::DeleteInstance();
     95 
     96   return 0;
     97 }
     98