Revert of aura: Require explicit ownership of the Env instance. (patchset #7 id:12000...
[chromium-blink-merge.git] / ui / views / examples / examples_main.cc
blob1802d0efee55621993dd6e606ce9298d9d4ef8aa
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.
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/power_monitor/power_monitor.h"
12 #include "base/power_monitor/power_monitor_device_source.h"
13 #include "base/run_loop.h"
14 #include "ui/base/ime/input_method_initializer.h"
15 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/base/ui_base_paths.h"
17 #include "ui/compositor/test/in_process_context_factory.h"
18 #include "ui/gfx/screen.h"
19 #include "ui/gl/gl_surface.h"
20 #include "ui/views/examples/example_base.h"
21 #include "ui/views/examples/examples_window.h"
22 #include "ui/views/test/desktop_test_views_delegate.h"
24 #if defined(USE_AURA)
25 #include "ui/aura/env.h"
26 #include "ui/wm/core/wm_state.h"
27 #endif
29 #if !defined(OS_CHROMEOS) && defined(USE_AURA)
30 #include "ui/views/widget/desktop_aura/desktop_screen.h"
31 #endif
33 #if defined(OS_WIN)
34 #include "ui/base/win/scoped_ole_initializer.h"
35 #include "ui/gfx/win/direct_write.h"
36 #endif
38 #if defined(USE_X11)
39 #include "ui/gfx/x/x11_connection.h"
40 #endif
42 int main(int argc, char** argv) {
43 #if defined(OS_WIN)
44 ui::ScopedOleInitializer ole_initializer_;
45 #endif
47 base::CommandLine::Init(argc, argv);
49 base::AtExitManager at_exit;
51 #if defined(USE_X11)
52 // This demo uses InProcessContextFactory which uses X on a separate Gpu
53 // thread.
54 gfx::InitializeThreadedX11();
55 #endif
57 gfx::GLSurface::InitializeOneOff();
59 // The ContextFactory must exist before any Compositors are created.
60 bool context_factory_for_test = false;
61 scoped_ptr<ui::InProcessContextFactory> context_factory(
62 new ui::InProcessContextFactory(context_factory_for_test, nullptr));
63 context_factory->set_use_test_surface(false);
65 base::MessageLoopForUI message_loop;
67 base::i18n::InitializeICU();
69 ui::RegisterPathProvider();
71 base::FilePath ui_test_pak_path;
72 DCHECK(PathService::Get(ui::UI_TEST_PAK, &ui_test_pak_path));
73 ui::ResourceBundle::InitSharedInstanceWithPakPath(ui_test_pak_path);
75 base::PowerMonitor power_monitor(make_scoped_ptr(
76 new base::PowerMonitorDeviceSource));
78 #if defined(OS_WIN)
79 gfx::win::MaybeInitializeDirectWrite();
80 #endif
82 #if defined(USE_AURA)
83 aura::Env::CreateInstance(true);
84 aura::Env::GetInstance()->set_context_factory(context_factory.get());
85 #endif
86 ui::InitializeInputMethodForTesting();
89 views::DesktopTestViewsDelegate views_delegate;
90 #if defined(USE_AURA)
91 wm::WMState wm_state;
92 #endif
93 #if !defined(OS_CHROMEOS) && defined(USE_AURA)
94 scoped_ptr<gfx::Screen> desktop_screen(views::CreateDesktopScreen());
95 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE,
96 desktop_screen.get());
97 #endif
99 views::examples::ShowExamplesWindow(
100 views::examples::QUIT_ON_CLOSE,
101 NULL,
102 scoped_ptr<ScopedVector<views::examples::ExampleBase> >());
104 base::RunLoop().Run();
106 ui::ResourceBundle::CleanupSharedInstance();
109 ui::ShutdownInputMethod();
111 #if defined(USE_AURA)
112 aura::Env::DeleteInstance();
113 #endif
115 return 0;