OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/at_exit.h" | 5 #include "base/at_exit.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "base/timer/timer.h" | 9 #include "base/timer/timer.h" |
10 #include "ui/gfx/geometry/rect.h" | 10 #include "ui/gfx/geometry/rect.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 | 26 |
27 const char kDisableGpu[] = "disable-gpu"; | 27 const char kDisableGpu[] = "disable-gpu"; |
28 | 28 |
29 const char kWindowSize[] = "window-size"; | 29 const char kWindowSize[] = "window-size"; |
30 | 30 |
31 class DemoWindow : public ui::PlatformWindowDelegate { | 31 class DemoWindow : public ui::PlatformWindowDelegate { |
32 public: | 32 public: |
33 DemoWindow() : widget_(gfx::kNullAcceleratedWidget) { | 33 DemoWindow() : widget_(gfx::kNullAcceleratedWidget) { |
34 int width = kTestWindowWidth; | 34 int width = kTestWindowWidth; |
35 int height = kTestWindowHeight; | 35 int height = kTestWindowHeight; |
36 sscanf(CommandLine::ForCurrentProcess() | 36 sscanf(base::CommandLine::ForCurrentProcess() |
37 ->GetSwitchValueASCII(kWindowSize) | 37 ->GetSwitchValueASCII(kWindowSize) |
38 .c_str(), | 38 .c_str(), |
39 "%dx%d", &width, &height); | 39 "%dx%d", &width, &height); |
40 | 40 |
41 platform_window_ = ui::OzonePlatform::GetInstance()->CreatePlatformWindow( | 41 platform_window_ = ui::OzonePlatform::GetInstance()->CreatePlatformWindow( |
42 this, gfx::Rect(width, height)); | 42 this, gfx::Rect(width, height)); |
43 } | 43 } |
44 ~DemoWindow() override {} | 44 ~DemoWindow() override {} |
45 | 45 |
46 gfx::AcceleratedWidget GetAcceleratedWidget() { | 46 gfx::AcceleratedWidget GetAcceleratedWidget() { |
47 // TODO(spang): We should start rendering asynchronously. | 47 // TODO(spang): We should start rendering asynchronously. |
48 DCHECK_NE(widget_, gfx::kNullAcceleratedWidget) | 48 DCHECK_NE(widget_, gfx::kNullAcceleratedWidget) |
49 << "Widget not available synchronously"; | 49 << "Widget not available synchronously"; |
50 return widget_; | 50 return widget_; |
51 } | 51 } |
52 | 52 |
53 gfx::Size GetSize() { return platform_window_->GetBounds().size(); } | 53 gfx::Size GetSize() { return platform_window_->GetBounds().size(); } |
54 | 54 |
55 void Start() { | 55 void Start() { |
56 if (!CommandLine::ForCurrentProcess()->HasSwitch(kDisableGpu) && | 56 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(kDisableGpu) && |
57 gfx::GLSurface::InitializeOneOff() && StartInProcessGpu()) { | 57 gfx::GLSurface::InitializeOneOff() && StartInProcessGpu()) { |
58 if (CommandLine::ForCurrentProcess()->HasSwitch( | 58 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
59 switches::kOzoneUseSurfaceless)) { | 59 switches::kOzoneUseSurfaceless)) { |
60 renderer_.reset( | 60 renderer_.reset( |
61 new ui::SurfacelessGlRenderer(GetAcceleratedWidget(), GetSize())); | 61 new ui::SurfacelessGlRenderer(GetAcceleratedWidget(), GetSize())); |
62 } else { | 62 } else { |
63 renderer_.reset(new ui::GlRenderer(GetAcceleratedWidget(), GetSize())); | 63 renderer_.reset(new ui::GlRenderer(GetAcceleratedWidget(), GetSize())); |
64 } | 64 } |
65 } else { | 65 } else { |
66 renderer_.reset( | 66 renderer_.reset( |
67 new ui::SoftwareRenderer(GetAcceleratedWidget(), GetSize())); | 67 new ui::SoftwareRenderer(GetAcceleratedWidget(), GetSize())); |
68 } | 68 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 scoped_ptr<ui::PlatformWindow> platform_window_; | 112 scoped_ptr<ui::PlatformWindow> platform_window_; |
113 gfx::AcceleratedWidget widget_; | 113 gfx::AcceleratedWidget widget_; |
114 | 114 |
115 // Helper for applications that do GL on main thread. | 115 // Helper for applications that do GL on main thread. |
116 ui::UiThreadGpu ui_thread_gpu_; | 116 ui::UiThreadGpu ui_thread_gpu_; |
117 | 117 |
118 DISALLOW_COPY_AND_ASSIGN(DemoWindow); | 118 DISALLOW_COPY_AND_ASSIGN(DemoWindow); |
119 }; | 119 }; |
120 | 120 |
121 int main(int argc, char** argv) { | 121 int main(int argc, char** argv) { |
122 CommandLine::Init(argc, argv); | 122 base::CommandLine::Init(argc, argv); |
123 base::AtExitManager exit_manager; | 123 base::AtExitManager exit_manager; |
124 | 124 |
125 // Build UI thread message loop. This is used by platform | 125 // Build UI thread message loop. This is used by platform |
126 // implementations for event polling & running background tasks. | 126 // implementations for event polling & running background tasks. |
127 base::MessageLoopForUI message_loop; | 127 base::MessageLoopForUI message_loop; |
128 | 128 |
129 ui::OzonePlatform::InitializeForUI(); | 129 ui::OzonePlatform::InitializeForUI(); |
130 | 130 |
131 DemoWindow* window = new DemoWindow; | 131 DemoWindow* window = new DemoWindow; |
132 window->Start(); | 132 window->Start(); |
133 | 133 |
134 // Run the message loop until there's nothing left to do. | 134 // Run the message loop until there's nothing left to do. |
135 // TODO(spang): Should we use QuitClosure instead? | 135 // TODO(spang): Should we use QuitClosure instead? |
136 base::RunLoop run_loop; | 136 base::RunLoop run_loop; |
137 run_loop.RunUntilIdle(); | 137 run_loop.RunUntilIdle(); |
138 | 138 |
139 return 0; | 139 return 0; |
140 } | 140 } |
OLD | NEW |